1
|
/* SPI Potentiometer AD 7367 Driver for OpenPICC
|
2
|
* (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
|
3
|
*
|
4
|
* This program is free software; you can redistribute it and/or modify
|
5
|
* it under the terms of the GNU General Public License as published by
|
6
|
* the Free Software Foundation; either version 2 of the License, or
|
7
|
* (at your option) any later version.
|
8
|
*
|
9
|
* This program is distributed in the hope that it will be useful,
|
10
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
* GNU General Public License for more details.
|
13
|
*
|
14
|
* You should have received a copy of the GNU General Public License
|
15
|
* along with this program; if not, write to the Free Software
|
16
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
*
|
18
|
*/
|
19
|
|
20
|
|
21
|
|
22
|
#include <sys/types.h>
|
23
|
#include <lib_AT91SAM7.h>
|
24
|
#include "../openpcd.h"
|
25
|
|
26
|
static const AT91PS_SPI spi = AT91C_BASE_SPI;
|
27
|
|
28
|
void poti_comp_carr(uint8_t position)
|
29
|
{
|
30
|
volatile int i;
|
31
|
|
32
|
while (!(spi->SPI_SR & AT91C_SPI_TDRE)) { }
|
33
|
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
|
34
|
/* shift one left, since it is a seven-bit value written as 8 bit xfer */
|
35
|
spi->SPI_TDR = position & 0x7f;
|
36
|
while (!(spi->SPI_SR & AT91C_SPI_TDRE)) { }
|
37
|
for (i = 0; i < 0xff; i++) { }
|
38
|
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
|
39
|
}
|
40
|
|
41
|
void poti_reset(void)
|
42
|
{
|
43
|
volatile int i;
|
44
|
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_nSLAVE_RESET);
|
45
|
for (i = 0; i < 0xff; i++) { }
|
46
|
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_nSLAVE_RESET);
|
47
|
}
|
48
|
|
49
|
void poti_init(void)
|
50
|
{
|
51
|
AT91F_SPI_CfgPMC();
|
52
|
AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA,
|
53
|
AT91C_PA13_MOSI | AT91C_PA14_SPCK, 0);
|
54
|
|
55
|
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
|
56
|
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_SS2_DT_THRESH);
|
57
|
|
58
|
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC_PIO_nSLAVE_RESET);
|
59
|
poti_reset();
|
60
|
|
61
|
#if 0
|
62
|
AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_SPI,
|
63
|
OPENPCD_IRQ_PRIO_SPI,
|
64
|
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, &spi_irq);
|
65
|
AT91G_AIC_EnableIt(AT9C_BASE_AIC, AT91C_ID_SPI);
|
66
|
#endif
|
67
|
AT91F_SPI_CfgMode(spi, AT91C_SPI_MSTR |
|
68
|
AT91C_SPI_PS_FIXED | AT91C_SPI_MODFDIS);
|
69
|
/* CPOL = 0, NCPHA = 1, CSAAT = 0, BITS = 0000, SCBR = 13 (3.69MHz),
|
70
|
* DLYBS = 6 (125nS), DLYBCT = 0 */
|
71
|
AT91F_SPI_CfgCs(spi, 0, AT91C_SPI_BITS_8 | AT91C_SPI_NCPHA |
|
72
|
(13 << 8) | (6 << 16));
|
73
|
AT91F_SPI_Enable(spi);
|
74
|
}
|