mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 05:42:05 +08:00
ADS7843E driver is code complete
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4018 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+188
-22
@@ -120,13 +120,21 @@ struct sam3u_spidev_s
|
||||
#ifndef CONFIG_SPI_OWNBUS
|
||||
static int spi_lock(FAR struct spi_dev_s *dev, bool lock);
|
||||
#endif
|
||||
static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected);
|
||||
static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency);
|
||||
static void spi_setmode(FAR struct spi_dev_s *dev, enum spi_mode_e mode);
|
||||
static void spi_select(FAR struct spi_dev_s *dev, enum spi_dev_e devid,
|
||||
bool selected);
|
||||
static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev,
|
||||
uint32_t frequency);
|
||||
static void spi_setmode(FAR struct spi_dev_s *dev,
|
||||
enum spi_mode_e mode);
|
||||
static void spi_setbits(FAR struct spi_dev_s *dev, int nbits);
|
||||
static uint16_t spi_send(FAR struct spi_dev_s *dev, uint16_t ch);
|
||||
#ifdef CONFIG_SPI_EXCHANGE
|
||||
static void spi_exchange(FAR struct spi_dev_s *dev,
|
||||
FAR const void *txbuffer, FAR void *rxbuffer, size_t nwords);
|
||||
#else
|
||||
static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size_t nwords);
|
||||
static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer, size_t nwords);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@@ -148,8 +156,12 @@ static const struct spi_ops_s g_spiops =
|
||||
.cmddata = sam3u_spicmddata,
|
||||
#endif
|
||||
.send = spi_send,
|
||||
#ifdef CONFIG_SPI_EXCHANGE
|
||||
.exchange = spi_exchange,
|
||||
#else
|
||||
.sndblock = spi_sndblock,
|
||||
.recvblock = spi_recvblock,
|
||||
#endif
|
||||
.registercallback = 0, /* Not implemented */
|
||||
};
|
||||
|
||||
@@ -300,7 +312,9 @@ static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency)
|
||||
{
|
||||
FAR struct sam3u_spidev_s *priv = (FAR struct sam3u_spidev_s *)dev;
|
||||
uint32_t actual;
|
||||
uint32_t divisor;
|
||||
uint32_t scbr;
|
||||
uint32_t dlybs;
|
||||
uint32_t dlybct;
|
||||
uint32_t regval;
|
||||
uint32_t regaddr;
|
||||
|
||||
@@ -317,33 +331,65 @@ static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Configure SPI to a frequency as close as possible to the requested frequency. */
|
||||
/* Configure SPI to a frequency as close as possible to the requested frequency.
|
||||
*
|
||||
* SPCK frequency = MCK / SCBR, or SCBR = MCK / frequency
|
||||
*/
|
||||
|
||||
/* frequency = SPI_CLOCK / divisor, or divisor = SPI_CLOCK / frequency */
|
||||
scbr = SAM3U_MCK_FREQUENCY / frequency;
|
||||
|
||||
divisor = SAM3U_MCK_FREQUENCY / frequency;
|
||||
|
||||
if (divisor < 8)
|
||||
if (scbr < 8)
|
||||
{
|
||||
divisor = 8;
|
||||
scbr = 8;
|
||||
}
|
||||
else if (divisor > 254)
|
||||
else if (scbr > 254)
|
||||
{
|
||||
divisor = 254;
|
||||
scbr = 254;
|
||||
}
|
||||
|
||||
divisor = (divisor + 1) & ~1;
|
||||
scbr = (scbr + 1) & ~1;
|
||||
|
||||
/* Save the new divisor value */
|
||||
/* Save the new scbr value */
|
||||
|
||||
regaddr = g_csraddr[priv->cs];
|
||||
regval = getreg32(regaddr);
|
||||
regval &= ~SPI_CSR_SCBR_MASK;
|
||||
putreg32(divisor << SPI_CSR_SCBR_SHIFT, regaddr);
|
||||
regval &= ~(SPI_CSR_SCBR_MASK|SPI_CSR_DLYBS_MASK|SPI_CSR_DLYBCT_MASK);
|
||||
regval |= scbr << SPI_CSR_SCBR_SHIFT;
|
||||
|
||||
/* Calculate the new actual */
|
||||
/* DLYBS: Delay Before SPCK. This field defines the delay from NPCS valid to the
|
||||
* first valid SPCK transition. When DLYBS equals zero, the NPCS valid to SPCK
|
||||
* transition is 1/2 the SPCK clock period. Otherwise, the following equations
|
||||
* determine the delay:
|
||||
*
|
||||
* Delay Before SPCK = DLYBS / MCK
|
||||
*
|
||||
* For a 2uS delay
|
||||
*
|
||||
* DLYBS = MCK * 0.000002 = MCK / 500000
|
||||
*/
|
||||
|
||||
actual = SAM3U_MCK_FREQUENCY / divisor;
|
||||
dlybs = SAM3U_MCK_FREQUENCY / 500000;
|
||||
regval |= dlybs << SPI_CSR_DLYBS_SHIFT;
|
||||
|
||||
/* DLYBCT: Delay Between Consecutive Transfers. This field defines the delay
|
||||
* between two consecutive transfers with the same peripheral without removing
|
||||
* the chip select. The delay is always inserted after each transfer and
|
||||
* before removing the chip select if needed.
|
||||
*
|
||||
* Delay Between Consecutive Transfers = (32 x DLYBCT) / MCK
|
||||
*
|
||||
* For a 5uS delay:
|
||||
*
|
||||
* DLYBCT = MCK * 0.000005 / 32 = MCK / 200000 / 32
|
||||
*/
|
||||
|
||||
dlybct = SAM3U_MCK_FREQUENCY / 200000 / 32;
|
||||
regval |= dlybct << SPI_CSR_DLYBCT_SHIFT;
|
||||
putreg32(regval, regaddr);
|
||||
|
||||
/* Calculate the new actual frequency */
|
||||
|
||||
actual = SAM3U_MCK_FREQUENCY / scbr;
|
||||
|
||||
/* Save the frequency setting */
|
||||
|
||||
@@ -487,6 +533,11 @@ static void spi_setbits(FAR struct spi_dev_s *dev, int nbits)
|
||||
|
||||
static uint16_t spi_send(FAR struct spi_dev_s *dev, uint16_t wd)
|
||||
{
|
||||
#ifdef CONFIG_SPI_VARSELECT
|
||||
FAR struct sam3u_spidev_s *priv = (FAR struct sam3u_spidev_s *)dev;
|
||||
uint32_t tdr = (uint32_t)priv->cs << SPI_TDR_PCS_SHIFT;
|
||||
#endif
|
||||
|
||||
/* Wait for any previous data written to the TDR to be transferred to the
|
||||
* serializer.
|
||||
*/
|
||||
@@ -495,7 +546,11 @@ static uint16_t spi_send(FAR struct spi_dev_s *dev, uint16_t wd)
|
||||
|
||||
/* Write the data to transmitted to the Transmit Data Register (TDR) */
|
||||
|
||||
#ifdef CONFIG_SPI_VARSELECT
|
||||
putreg32((uint32_t)wd | tdr | SPI_TDR_LASTXFER, SAM3U_SPI_TDR);
|
||||
#else
|
||||
putreg32((uint32_t)wd, SAM3U_SPI_TDR);
|
||||
#endif
|
||||
|
||||
/* Wait for the read data to be available in the RDR */
|
||||
|
||||
@@ -506,7 +561,91 @@ static uint16_t spi_send(FAR struct spi_dev_s *dev, uint16_t wd)
|
||||
return (uint16_t)getreg32(SAM3U_SPI_RDR);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: spi_exchange
|
||||
*
|
||||
* Description:
|
||||
* Exahange a block of data from SPI. Required.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* txbuffer - A pointer to the buffer of data to be sent
|
||||
* rxbuffer - A pointer to the buffer in which to recieve data
|
||||
* nwords - the length of data that to be exchanged in units of words.
|
||||
* The wordsize is determined by the number of bits-per-word
|
||||
* selected for the SPI interface. If nbits <= 8, the data is
|
||||
* packed into uint8_t's; if nbits >8, the data is packed into
|
||||
* uint16_t's
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SPI_EXCHANGE
|
||||
static void spi_exchange(FAR struct spi_dev_s *dev,
|
||||
FAR const void *txbuffer, FAR void *rxbuffer,
|
||||
size_t nwords)
|
||||
{
|
||||
#ifdef CONFIG_SPI_VARSELECT
|
||||
FAR struct sam3u_spidev_s *priv = (FAR struct sam3u_spidev_s *)dev;
|
||||
uint32_t tdr = (uint32_t)priv->cs << SPI_TDR_PCS_SHIFT;
|
||||
#endif
|
||||
FAR uint8_t *rxptr = (FAR uint8_t*)rxbuffer;
|
||||
FAR uint8_t *txptr = (FAR uint8_t*)txbuffer;
|
||||
uint8_t data;
|
||||
|
||||
spidbg("nwords: %d\n", nwords);
|
||||
|
||||
/* Loop, sending each word in the user-provied data buffer */
|
||||
|
||||
for ( ; nwords > 0; nwords--)
|
||||
{
|
||||
/* Wait for any previous data written to the TDR to be transferred
|
||||
* to the serializer.
|
||||
*/
|
||||
|
||||
while ((getreg32(SAM3U_SPI_SR) & SPI_INT_TDRE) == 0);
|
||||
|
||||
/* Get the data to send (0xff if there is no data source) */
|
||||
|
||||
if (rxptr)
|
||||
{
|
||||
data = *txptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = 0xff;
|
||||
}
|
||||
|
||||
/* Write the data to transmitted to the Transmit Data Register (TDR) */
|
||||
|
||||
#ifdef CONFIG_SPI_VARSELECT
|
||||
if (nwords == 1)
|
||||
{
|
||||
tdr |= SPI_TDR_LASTXFER;
|
||||
}
|
||||
putreg32((uint32_t)data | tdr, SAM3U_SPI_TDR);
|
||||
#else
|
||||
putreg32((uint32_t)data, SAM3U_SPI_TDR);
|
||||
#endif
|
||||
|
||||
/* Wait for the read data to be available in the RDR */
|
||||
|
||||
while ((getreg32(SAM3U_SPI_SR) & SPI_INT_RDRF) == 0);
|
||||
|
||||
/* Read the received data from the SPI Data Register */
|
||||
|
||||
data = (uint8_t)getreg32(SAM3U_SPI_RDR);
|
||||
if (rxptr)
|
||||
{
|
||||
*txptr++ = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************************************************************
|
||||
* Name: spi_sndblock
|
||||
*
|
||||
* Description:
|
||||
@@ -525,8 +664,13 @@ static uint16_t spi_send(FAR struct spi_dev_s *dev, uint16_t wd)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_SPI_EXCHANGE
|
||||
static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size_t nwords)
|
||||
{
|
||||
#ifdef CONFIG_SPI_VARSELECT
|
||||
FAR struct sam3u_spidev_s *priv = (FAR struct sam3u_spidev_s *)dev;
|
||||
uint32_t tdr = (uint32_t)priv->cs << SPI_TDR_PCS_SHIFT;
|
||||
#endif
|
||||
FAR uint8_t *ptr = (FAR uint8_t*)buffer;
|
||||
uint8_t data;
|
||||
|
||||
@@ -545,9 +689,18 @@ static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size
|
||||
/* Write the data to transmitted to the Transmit Data Register (TDR) */
|
||||
|
||||
data = *ptr++;
|
||||
#ifdef CONFIG_SPI_VARSELECT
|
||||
if (nwords == 1)
|
||||
{
|
||||
tdr |= SPI_TDR_LASTXFER;
|
||||
}
|
||||
putreg32((uint32_t)data | tdr, SAM3U_SPI_TDR);
|
||||
#else
|
||||
putreg32((uint32_t)data, SAM3U_SPI_TDR);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: spi_recvblock
|
||||
@@ -568,8 +721,13 @@ static void spi_sndblock(FAR struct spi_dev_s *dev, FAR const void *buffer, size
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_SPI_EXCHANGE
|
||||
static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer, size_t nwords)
|
||||
{
|
||||
#ifdef CONFIG_SPI_VARSELECT
|
||||
FAR struct sam3u_spidev_s *priv = (FAR struct sam3u_spidev_s *)dev;
|
||||
uint32_t tdr = (uint32_t)priv->cs << SPI_TDR_PCS_SHIFT;
|
||||
#endif
|
||||
FAR uint8_t *ptr = (FAR uint8_t*)buffer;
|
||||
|
||||
spidbg("nwords: %d\n", nwords);
|
||||
@@ -588,8 +746,15 @@ static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer, size_t nw
|
||||
* to clock the read data.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_SPI_VARSELECT
|
||||
if (nwords == 1)
|
||||
{
|
||||
tdr |= SPI_TDR_LASTXFER;
|
||||
}
|
||||
putreg32(0xff | tdr, SAM3U_SPI_TDR);
|
||||
#else
|
||||
putreg32(0xff, SAM3U_SPI_TDR);
|
||||
|
||||
#endif
|
||||
/* Wait for the read data to be available in the RDR */
|
||||
|
||||
while ((getreg32(SAM3U_SPI_SR) & SPI_INT_RDRF) == 0);
|
||||
@@ -599,6 +764,7 @@ static void spi_recvblock(FAR struct spi_dev_s *dev, FAR void *buffer, size_t nw
|
||||
*ptr++ = (uint8_t)getreg32(SAM3U_SPI_RDR);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@@ -657,8 +823,8 @@ FAR struct spi_dev_s *up_spiinitialize(int port)
|
||||
irqrestore(flags);
|
||||
|
||||
/* Configure the SPI mode register */
|
||||
#warning "Need to review this -- what other settngs are necessary"
|
||||
putreg32(SPI_MR_MSTR, SAM3U_SPI_MR);
|
||||
|
||||
putreg32(SPI_MR_MSTR | SPI_MR_MODFDIS, SAM3U_SPI_MR);
|
||||
|
||||
/* And enable the SPI */
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <arch/irq.h>
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
/************************************************************************************
|
||||
@@ -138,8 +139,10 @@
|
||||
|
||||
/* Touchscreen controller (TSC) */
|
||||
|
||||
#define GPIO_TCS_IRQ (PIO_INPUT|GPIO_CFG_PULLUP|GPIO_PORT_PIOA|GPIO_PIN6)
|
||||
#define GPIO_TCS_BUSY (PIO_INPUT|GPIO_CFG_PULLUP|GPIO_PORT_PIOA|GPIO_PIN6)
|
||||
#define GPIO_TCS_IRQ (GPIO_INPUT|GPIO_CFG_PULLUP|GPIO_PORT_PIOA|GPIO_PIN24)
|
||||
#define GPIO_TCS_BUSY (GPIO_INPUT|GPIO_CFG_PULLUP|GPIO_PORT_PIOA|GPIO_PIN2)
|
||||
|
||||
#define SAM3U_TCS_IRQ SAM3U_IRQ_PA24
|
||||
|
||||
/* LEDs */
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/spi.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/sdio.h>
|
||||
#include <nuttx/spi.h>
|
||||
#include <nuttx/input/touchscreen.h>
|
||||
#include <nuttx/input/ads7843e.h>
|
||||
|
||||
@@ -66,6 +66,26 @@
|
||||
# error "Touchscreen support requires CONFIG_SAM3U_SPI"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_GPIOA_IRQ
|
||||
# error "Touchscreen support requires CONFIG_GPIOA_IRQ"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ADS7843E_FREQUENCY
|
||||
# define CONFIG_ADS7843E_FREQUENCY 500000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ADS7843E_SPIDEV
|
||||
# define CONFIG_ADS7843E_SPIDEV 0
|
||||
#endif
|
||||
|
||||
#if CONFIG_ADS7843E_SPIDEV != 0
|
||||
# error "CONFIG_ADS7843E_SPIDEV must be zero"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ADS7843E_DEVMINOR
|
||||
# define CONFIG_ADS7843E_DEVMINOR 0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Static Function Prototypes
|
||||
****************************************************************************/
|
||||
@@ -85,6 +105,7 @@
|
||||
static int tsc_attach(FAR struct ads7843e_config_s *state, xcpt_t isr);
|
||||
static void tsc_enable(FAR struct ads7843e_config_s *state, bool enable);
|
||||
static void tsc_clear(FAR struct ads7843e_config_s *state);
|
||||
static bool tsc_busy(FAR struct ads7843e_config_s *state);
|
||||
static bool tsc_pendown(FAR struct ads7843e_config_s *state);
|
||||
|
||||
/****************************************************************************
|
||||
@@ -103,12 +124,12 @@ static bool tsc_pendown(FAR struct ads7843e_config_s *state);
|
||||
|
||||
static struct ads7843e_config_s g_tscinfo =
|
||||
{
|
||||
.calib = CONFIG_INPUT_TSCCALIB,
|
||||
.frequency = CONFIG_INPUT_TSCFREQUENCY,
|
||||
.frequency = CONFIG_ADS7843E_FREQUENCY,
|
||||
|
||||
.attach = tsc_attach,
|
||||
.enable = tsc_enable,
|
||||
.clear = tsc_clear,
|
||||
.busy = tsc_busy,
|
||||
.pendown = tsc_pendown,
|
||||
};
|
||||
|
||||
@@ -130,22 +151,24 @@ static struct ads7843e_config_s g_tscinfo =
|
||||
|
||||
static int tsc_attach(FAR struct ads7843e_config_s *state, xcpt_t isr)
|
||||
{
|
||||
#warning "Missing logic"
|
||||
return OK;
|
||||
/* Attach the ADS7843E interrupt */
|
||||
|
||||
ivdbg("Attaching %p to IRQ %d\n", isr, SAM3U_TCS_IRQ);
|
||||
return irq_attach(SAM3U_TCS_IRQ, isr);
|
||||
}
|
||||
|
||||
static void tsc_enable(FAR struct ads7843e_config_s *state, bool enable)
|
||||
{
|
||||
/* Attach and enable, or detach and disable */
|
||||
|
||||
if (enable && g_tschandler)
|
||||
ivdbg("IRQ:%d enable:%d\n", SAM3U_TCS_IRQ, enable);
|
||||
if (enable)
|
||||
{
|
||||
/* Configure and enable the ADS7843E interrupt */
|
||||
#warning "Missing logic"
|
||||
sam3u_gpioirqenable(SAM3U_TCS_IRQ);
|
||||
}
|
||||
else
|
||||
{
|
||||
#warning "Missing logic"
|
||||
sam3u_gpioirqdisable(SAM3U_TCS_IRQ);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,11 +177,22 @@ static void tsc_clear(FAR struct ads7843e_config_s *state)
|
||||
/* Does nothing */
|
||||
}
|
||||
|
||||
static bool tsc_busy(FAR struct ads7843e_config_s *state)
|
||||
{
|
||||
/* REVISIT: This might need to be inverted */
|
||||
|
||||
bool busy = sam3u_gpioread(GPIO_TCS_BUSY);
|
||||
ivdbg("busy:%d\n", busy);
|
||||
return busy;
|
||||
}
|
||||
|
||||
static bool tsc_pendown(FAR struct ads7843e_config_s *state)
|
||||
{
|
||||
/* REVISIT: This might need to be inverted */
|
||||
|
||||
return sam3u_gpioread(GPIO_ADS7843E);
|
||||
bool pendown = sam3u_gpioread(GPIO_TCS_IRQ);
|
||||
ivdbg("pendown:%d\n", pendown);
|
||||
return pendown;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -178,26 +212,32 @@ int up_tcinitialize(void)
|
||||
FAR struct spi_dev_s *dev;
|
||||
int ret;
|
||||
|
||||
ivdbg("Initializing\n");
|
||||
|
||||
/* Configure and enable the ADS7843E interrupt pin as an input */
|
||||
|
||||
(void)sam3u_configgpio(GPIO_ADS7843E_BUY);
|
||||
(void)sam3u_configgpio(GPIO_ADS7843E_IRQ);
|
||||
(void)sam3u_configgpio(GPIO_TCS_BUSY);
|
||||
(void)sam3u_configgpio(GPIO_TCS_IRQ);
|
||||
|
||||
/* Configure the PIO interrupt */
|
||||
|
||||
sam3u_gpioirq(GPIO_TCS_IRQ);
|
||||
|
||||
/* Get an instance of the SPI interface */
|
||||
|
||||
dev = up_spiinitialize(CONFIG_INPUT_TSCSPIDEV);
|
||||
dev = up_spiinitialize(CONFIG_ADS7843E_SPIDEV);
|
||||
if (!dev)
|
||||
{
|
||||
dbg("Failed to initialize SPI bus %d\n", CONFIG_INPUT_TSCSPIDEV);
|
||||
idbg("Failed to initialize SPI bus %d\n", CONFIG_ADS7843E_SPIDEV);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Initialize and register the SPI touschscreen device */
|
||||
|
||||
ret = ads7843e_register(dev, &g_tscinfo, CONFIG_INPUT_TSCMINOR);
|
||||
ret = ads7843e_register(dev, &g_tscinfo, CONFIG_ADS7843E_DEVMINOR);
|
||||
if (ret < 0)
|
||||
{
|
||||
dbg("Failed to initialize SPI bus %d\n", CONFIG_INPUT_TSCSPIDEV);
|
||||
idbg("Failed to initialize SPI bus %d\n", CONFIG_ADS7843E_SPIDEV);
|
||||
/* up_spiuninitialize(dev); */
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ CONFIG_SAM3U_USART3=n
|
||||
# The drivers need to know how to configure the subsystem.
|
||||
#
|
||||
|
||||
CONFIG_GPIOA_IRQ=n
|
||||
CONFIG_GPIOA_IRQ=y
|
||||
CONFIG_GPIOB_IRQ=n
|
||||
CONFIG_GPIOC_IRQ=n
|
||||
CONFIG_USART0_ISUART=y
|
||||
|
||||
Executable → Regular
+217
-212
File diff suppressed because it is too large
Load Diff
@@ -44,14 +44,115 @@
|
||||
* Included Files
|
||||
********************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <semaphore.h>
|
||||
#include <poll.h>
|
||||
#include <wdog.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
|
||||
#include <nuttx/spi.h>
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/input/ads7843e.h>
|
||||
|
||||
/********************************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
********************************************************************************************/
|
||||
/* Configuration ****************************************************************************/
|
||||
/* Reference counting is partially implemented, but not needed in the
|
||||
* current design.
|
||||
*/
|
||||
|
||||
#undef CONFIG_ADS7843E_REFCNT
|
||||
|
||||
/* ADS7843E Interfaces *********************************************************************/
|
||||
/* ADS7843E command bit settings */
|
||||
|
||||
#define ADS7843E_CMD_PD0 (1 << 0) /* PD0 */
|
||||
#define ADS7843E_CMD_PD1 (1 << 1) /* PD1 */
|
||||
#define ADS7843E_CMD_DFR (1 << 2) /* SER/DFR */
|
||||
#define ADS7843E_CMD_EIGHT_BITS_MOD (1 << 3) /* Mode */
|
||||
#define ADS7843E_CMD_START (1 << 7) /* Start Bit */
|
||||
#define ADS7843E_CMD_SWITCH_SHIFT 4 /* Address setting */
|
||||
|
||||
/* ADS7843E Commands */
|
||||
|
||||
#define ADS7843_CMD_YPOSITION \
|
||||
((1 << ADS7843E_CMD_SWITCH_SHIFT)|ADS7843E_CMD_START|ADS7843E_CMD_PD0|ADS7843E_CMD_PD1)
|
||||
#define ADS7843_CMD_XPOSITION \
|
||||
((5 << ADS7843E_CMD_SWITCH_SHIFT)|ADS7843E_CMD_START|ADS7843E_CMD_PD0|ADS7843E_CMD_PD1)
|
||||
#define ADS7843_CMD_ENABPINIRQ \
|
||||
((1 << ADS7843E_CMD_SWITCH_SHIFT)|ADS7843E_CMD_START)
|
||||
|
||||
/* Driver support **************************************************************************/
|
||||
/* This format is used to construct the /dev/input[n] device driver path. It
|
||||
* defined here so that it will be used consistently in all places.
|
||||
*/
|
||||
|
||||
#define DEV_FORMAT "/dev/input%d"
|
||||
#define DEV_NAMELEN 16
|
||||
|
||||
/* Poll the pen position while the pen is down at this rate (50MS): */
|
||||
|
||||
#define ADS7843E_WDOG_DELAY ((50 + (MSEC_PER_TICK-1))/ MSEC_PER_TICK)
|
||||
|
||||
/********************************************************************************************
|
||||
* Public Types
|
||||
********************************************************************************************/
|
||||
|
||||
/* This describes the state of one contact */
|
||||
|
||||
enum ads7843e_contact_3
|
||||
{
|
||||
CONTACT_NONE = 0, /* No contact */
|
||||
CONTACT_DOWN, /* First contact */
|
||||
CONTACT_MOVE, /* Same contact, possibly different position */
|
||||
CONTACT_UP, /* Contact lost */
|
||||
};
|
||||
|
||||
/* This structure describes the results of one ADS7843E sample */
|
||||
|
||||
struct ads7843e_sample_s
|
||||
{
|
||||
uint8_t id; /* Sampled touch point ID */
|
||||
uint8_t contact; /* Contact state (see enum ads7843e_contact_e) */
|
||||
uint16_t x; /* Measured X position */
|
||||
uint16_t y; /* Measured Y position */
|
||||
};
|
||||
|
||||
/* This structure describes the state of one ADS7843E driver instance */
|
||||
|
||||
struct ads7843e_dev_s
|
||||
{
|
||||
#ifdef CONFIG_ADS7843E_MULTIPLE
|
||||
FAR struct ads7843e_dev_s *flink; /* Supports a singly linked list of drivers */
|
||||
#endif
|
||||
#ifdef CONFIG_ADS7843E_REFCNT
|
||||
uint8_t crefs; /* Number of times the device has been opened */
|
||||
#endif
|
||||
uint8_t nwaiters; /* Number of threads waiting for ADS7843E data */
|
||||
uint8_t id; /* Current touch point ID */
|
||||
volatile bool penchange; /* An unreported event is buffered */
|
||||
sem_t devsem; /* Manages exclusive access to this structure */
|
||||
sem_t waitsem; /* Used to wait for the availability of data */
|
||||
|
||||
FAR struct ads7843e_config_s *config; /* Board configuration data */
|
||||
FAR struct spi_dev_s *spi; /* Saved SPI driver instance */
|
||||
struct work_s work; /* Supports the interrupt handling "bottom half" */
|
||||
struct ads7843e_sample_s sample; /* Last sampled touch point data */
|
||||
WDOG_ID wdog; /* Poll the position while the pen is down */
|
||||
|
||||
/* The following is a list if poll structures of threads waiting for
|
||||
* driver events. The 'struct pollfd' reference for each open is also
|
||||
* retained in the f_priv field of the 'struct file'.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
struct pollfd *fds[CONFIG_ADS7843E_NPOLLWAITERS];
|
||||
#endif
|
||||
};
|
||||
|
||||
/********************************************************************************************
|
||||
* Public Function Prototypes
|
||||
********************************************************************************************/
|
||||
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
@@ -61,10 +61,10 @@
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ADS7843E_SPIMODE
|
||||
# define CONFIG_ADS7843E_SPIMODE SPIDEV_MODE0
|
||||
# define CONFIG_ADS7843E_SPIMODE SPIDEV_MODE1
|
||||
#endif
|
||||
|
||||
/* Check for some required settings. This can save the user a lot of time
|
||||
/* Check for some required settings. This can save the user a lot of time
|
||||
* in getting the right configuration.
|
||||
*/
|
||||
|
||||
@@ -94,7 +94,6 @@ struct ads7843e_config_s
|
||||
{
|
||||
/* Device characterization */
|
||||
|
||||
uint16_t calib; /* Calibration resistance */
|
||||
uint32_t frequency; /* SPI frequency */
|
||||
|
||||
/* If multiple ADS7843E devices are supported, then an IRQ number must
|
||||
@@ -120,6 +119,7 @@ struct ads7843e_config_s
|
||||
int (*attach)(FAR struct ads7843e_config_s *state, xcpt_t isr);
|
||||
void (*enable)(FAR struct ads7843e_config_s *state, bool enable);
|
||||
void (*clear)(FAR struct ads7843e_config_s *state);
|
||||
bool (*busy)(FAR struct ads7843e_config_s *state);
|
||||
bool (*pendown)(FAR struct ads7843e_config_s *state);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user