mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 17:48:54 +08:00
SAM3U SPI debug changes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4031 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -125,7 +125,9 @@ static void spi_dumpregs(FAR const char *msg);
|
|||||||
#else
|
#else
|
||||||
# define spi_dumpregs(msg)
|
# define spi_dumpregs(msg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline void spi_flush(void);
|
static inline void spi_flush(void);
|
||||||
|
static inline uint32_t spi_cs2pcs(FAR struct sam3u_spidev_s *priv);
|
||||||
|
|
||||||
/* SPI methods */
|
/* SPI methods */
|
||||||
|
|
||||||
@@ -222,7 +224,7 @@ static void spi_dumpregs(FAR const char *msg)
|
|||||||
spivdbg(" CSR0:%08x CSR1:%08x CSR2:%08x CSR3:%08x\n",
|
spivdbg(" CSR0:%08x CSR1:%08x CSR2:%08x CSR3:%08x\n",
|
||||||
getreg32(SAM3U_SPI_CSR0), getreg32(SAM3U_SPI_CSR1),
|
getreg32(SAM3U_SPI_CSR0), getreg32(SAM3U_SPI_CSR1),
|
||||||
getreg32(SAM3U_SPI_CSR2), getreg32(SAM3U_SPI_CSR3));
|
getreg32(SAM3U_SPI_CSR2), getreg32(SAM3U_SPI_CSR3));
|
||||||
spivdbg(" WPCR:%08x WPSR:%08x IMR:%08x\n",
|
spivdbg(" WPCR:%08x WPSR:%08x\n",
|
||||||
getreg32(SAM3U_SPI_WPCR), getreg32(SAM3U_SPI_WPSR));
|
getreg32(SAM3U_SPI_WPCR), getreg32(SAM3U_SPI_WPSR));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -257,6 +259,37 @@ static inline void spi_flush(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: spi_cs2pcs
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Map the chip select number to the bit-set PCS field used in the SPI
|
||||||
|
* registers. A chip select number is used for indexing and identifying
|
||||||
|
* chip selects. However, the chip select information is represented by
|
||||||
|
* a bit set in the SPI regsisters. This function maps those chip select
|
||||||
|
* numbers to the correct bit set:
|
||||||
|
*
|
||||||
|
* CS Returned Spec Effective
|
||||||
|
* No. PCS Value NPCS
|
||||||
|
* ---- -------- -------- --------
|
||||||
|
* 0 0000 xxx0 1110
|
||||||
|
* 1 0001 xx01 1101
|
||||||
|
* 2 0011 x011 1011
|
||||||
|
* 3 0111 0111 0111
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* priv - Device-specific state data
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static inline uint32_t spi_cs2pcs(FAR struct sam3u_spidev_s *priv)
|
||||||
|
{
|
||||||
|
return ((uint32_t)1 << (priv->cs)) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: spi_lock
|
* Name: spi_lock
|
||||||
*
|
*
|
||||||
@@ -348,7 +381,7 @@ static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
|
|||||||
|
|
||||||
regval = getreg32(SAM3U_SPI_MR);
|
regval = getreg32(SAM3U_SPI_MR);
|
||||||
regval &= ~SPI_MR_PCS_MASK;
|
regval &= ~SPI_MR_PCS_MASK;
|
||||||
regval |= (priv->cs << SPI_MR_PCS_SHIFT);
|
regval |= (spi_cs2pcs(priv) << SPI_MR_PCS_SHIFT);
|
||||||
putreg32(regval, SAM3U_SPI_MR);
|
putreg32(regval, SAM3U_SPI_MR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -660,16 +693,18 @@ static void spi_exchange(FAR struct spi_dev_s *dev,
|
|||||||
FAR const void *txbuffer, FAR void *rxbuffer,
|
FAR const void *txbuffer, FAR void *rxbuffer,
|
||||||
size_t nwords)
|
size_t nwords)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SPI_VARSELECT
|
|
||||||
FAR struct sam3u_spidev_s *priv = (FAR struct sam3u_spidev_s *)dev;
|
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 *rxptr = (FAR uint8_t*)rxbuffer;
|
||||||
FAR uint8_t *txptr = (FAR uint8_t*)txbuffer;
|
FAR uint8_t *txptr = (FAR uint8_t*)txbuffer;
|
||||||
|
uint32_t pcs;
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
|
|
||||||
spivdbg("txbuffer=%p rxbuffer=%p nwords=%d\n", txbuffer, rxbuffer, nwords);
|
spivdbg("txbuffer=%p rxbuffer=%p nwords=%d\n", txbuffer, rxbuffer, nwords);
|
||||||
|
|
||||||
|
/* Set up PCS bits */
|
||||||
|
|
||||||
|
pcs = spi_cs2pcs(priv) << SPI_TDR_PCS_SHIFT;
|
||||||
|
|
||||||
/* Make sure that any previous transfer is flushed from the hardware */
|
/* Make sure that any previous transfer is flushed from the hardware */
|
||||||
|
|
||||||
spi_flush();
|
spi_flush();
|
||||||
@@ -718,13 +753,13 @@ static void spi_exchange(FAR struct spi_dev_s *dev,
|
|||||||
data = 0xffff;
|
data = 0xffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the chip select in the value written to the TDR */
|
/* Set the PCS field in the value written to the TDR */
|
||||||
|
|
||||||
#ifdef CONFIG_SPI_VARSELECT
|
data |= pcs;
|
||||||
data |= tdr;
|
|
||||||
|
|
||||||
/* Do we need to set the LASTXFER bit in the TDR value too? */
|
/* Do we need to set the LASTXFER bit in the TDR value too? */
|
||||||
|
|
||||||
|
#ifdef CONFIG_SPI_VARSELECT
|
||||||
if (nwords == 1)
|
if (nwords == 1)
|
||||||
{
|
{
|
||||||
data |= SPI_TDR_LASTXFER;
|
data |= SPI_TDR_LASTXFER;
|
||||||
@@ -750,7 +785,7 @@ static void spi_exchange(FAR struct spi_dev_s *dev,
|
|||||||
data = getreg32(SAM3U_SPI_RDR);
|
data = getreg32(SAM3U_SPI_RDR);
|
||||||
if (rxptr)
|
if (rxptr)
|
||||||
{
|
{
|
||||||
*txptr++ = (uint8_t)data;
|
*rxptr++ = (uint8_t)data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* arch/arm/src/stm32/chip/stm32_i2c.h
|
* arch/arm/src/stm32/chip/stm32_i2c.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -991,7 +991,7 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv)
|
|||||||
/* \todo Finish 10-bit mode addressing */
|
/* \todo Finish 10-bit mode addressing */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Was address sent, continue with ether sending or reading data */
|
/* Was address sent, continue with either sending or reading data */
|
||||||
|
|
||||||
else if ((priv->flags & I2C_M_READ) == 0 && (status & (I2C_SR1_ADDR | I2C_SR1_TXE)) != 0)
|
else if ((priv->flags & I2C_M_READ) == 0 && (status & (I2C_SR1_ADDR | I2C_SR1_TXE)) != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* arm/arm/src/stm32/stm32_spi.c
|
* arm/arm/src/stm32/stm32_spi.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009-2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2009-2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* include/arch/board/board.h
|
* include/arch/board/board.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009-2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2009-2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* arch/arm/src/board/up_lcd.c
|
* arch/arm/src/board/up_lcd.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -192,9 +192,7 @@ static void ads7843e_select(FAR struct spi_dev_s *spi)
|
|||||||
|
|
||||||
SPI_SETMODE(spi, CONFIG_ADS7843E_SPIMODE);
|
SPI_SETMODE(spi, CONFIG_ADS7843E_SPIMODE);
|
||||||
SPI_SETBITS(spi, 8);
|
SPI_SETBITS(spi, 8);
|
||||||
#ifdef CONFIG_ADS7843E_FREQUENCY
|
|
||||||
SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY);
|
SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -256,12 +254,8 @@ static void ads7843e_deselect(FAR struct spi_dev_s *spi)
|
|||||||
|
|
||||||
static inline void ads7843e_configspi(FAR struct spi_dev_s *spi)
|
static inline void ads7843e_configspi(FAR struct spi_dev_s *spi)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_ADS7843E_FREQUENCY
|
|
||||||
idbg("Mode: %d Bits: 8 Frequency: %d\n",
|
idbg("Mode: %d Bits: 8 Frequency: %d\n",
|
||||||
CONFIG_ADS7843E_SPIMODE, CONFIG_ADS7843E_FREQUENCY);
|
CONFIG_ADS7843E_SPIMODE, CONFIG_ADS7843E_FREQUENCY);
|
||||||
#else
|
|
||||||
idbg("Mode: %d Bits: 8\n", CONFIG_ADS7843E_SPIMODE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Configure SPI for the P14201. But only if we own the SPI bus. Otherwise, don't
|
/* Configure SPI for the P14201. But only if we own the SPI bus. Otherwise, don't
|
||||||
* bother because it might change.
|
* bother because it might change.
|
||||||
@@ -271,9 +265,7 @@ static inline void ads7843e_configspi(FAR struct spi_dev_s *spi)
|
|||||||
SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true);
|
SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true);
|
||||||
SPI_SETMODE(spi, CONFIG_ADS7843E_SPIMODE);
|
SPI_SETMODE(spi, CONFIG_ADS7843E_SPIMODE);
|
||||||
SPI_SETBITS(spi, 8);
|
SPI_SETBITS(spi, 8);
|
||||||
#ifdef CONFIG_ADS7843E_FREQUENCY
|
|
||||||
SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY)
|
SPI_SETFREQUENCY(spi, CONFIG_ADS7843E_FREQUENCY)
|
||||||
#endif
|
|
||||||
SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false);
|
SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -1110,10 +1102,6 @@ int ads7843e_register(FAR struct spi_dev_s *dev,
|
|||||||
sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
|
sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
|
||||||
sem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
|
sem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
|
||||||
|
|
||||||
/* Set the SPI frequency (saving the actual frequency) */
|
|
||||||
|
|
||||||
config->frequency = SPI_SETFREQUENCY(dev, config->frequency);
|
|
||||||
|
|
||||||
/* Make sure that interrupts are disabled */
|
/* Make sure that interrupts are disabled */
|
||||||
|
|
||||||
config->clear(config);
|
config->clear(config);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* drivers/input/ads7843e.h
|
* drivers/input/ads7843e.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* References:
|
* References:
|
||||||
* "Touch Screen Controller, ADS7843," Burr-Brown Products from Texas
|
* "Touch Screen Controller, ADS7843," Burr-Brown Products from Texas
|
||||||
@@ -60,9 +60,7 @@
|
|||||||
* Pre-Processor Definitions
|
* Pre-Processor Definitions
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
/* Configuration ****************************************************************************/
|
/* Configuration ****************************************************************************/
|
||||||
/* Reference counting is partially implemented, but not needed in the
|
/* Reference counting is partially implemented, but not needed in the current design. */
|
||||||
* current design.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#undef CONFIG_ADS7843E_REFCNT
|
#undef CONFIG_ADS7843E_REFCNT
|
||||||
|
|
||||||
|
|||||||
@@ -445,7 +445,7 @@ static int tsc2007_transfer(FAR struct tsc2007_dev_s *priv, uint8_t cmd)
|
|||||||
|
|
||||||
msg.addr = priv->config->address; /* 7-bit address */
|
msg.addr = priv->config->address; /* 7-bit address */
|
||||||
msg.flags = I2C_M_READ; /* Read transaction, beginning with START */
|
msg.flags = I2C_M_READ; /* Read transaction, beginning with START */
|
||||||
msg.buffer = data12; /* Transfer two this address */
|
msg.buffer = data12; /* Transfer to this address */
|
||||||
msg.length = 2; /* Read two bytes following the address */
|
msg.length = 2; /* Read two bytes following the address */
|
||||||
|
|
||||||
ret = I2C_TRANSFER(priv->i2c, &msg, 1);
|
ret = I2C_TRANSFER(priv->i2c, &msg, 1);
|
||||||
|
|||||||
@@ -54,6 +54,12 @@
|
|||||||
* Pre-Processor Definitions
|
* Pre-Processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/* Configuration ************************************************************/
|
/* Configuration ************************************************************/
|
||||||
|
/* SPI Frequency. Default: 100KHz */
|
||||||
|
|
||||||
|
#ifndef CONFIG_ADS7843E_FREQUENCY
|
||||||
|
# define CONFIG_ADS7843E_FREQUENCY 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Maximum number of threads than can be waiting for POLL events */
|
/* Maximum number of threads than can be waiting for POLL events */
|
||||||
|
|
||||||
#ifndef CONFIG_ADS7843E_NPOLLWAITERS
|
#ifndef CONFIG_ADS7843E_NPOLLWAITERS
|
||||||
|
|||||||
Reference in New Issue
Block a user