You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/06/04 02:34:03 UTC
[incubator-nuttx] 01/02: samv7/spi: Allow 16-bit word size in
spi_send
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit d13be4ea572b03609c7a48b8dfd2af6c92e4a798
Author: Jaroslav Beran <ja...@gmail.com>
AuthorDate: Thu Jun 3 11:37:54 2021 +0200
samv7/spi: Allow 16-bit word size in spi_send
Signed-off-by: Jaroslav Beran <ja...@gmail.com>
---
arch/arm/src/samv7/sam_spi.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/arch/arm/src/samv7/sam_spi.c b/arch/arm/src/samv7/sam_spi.c
index 5ffc205..99e05a2 100644
--- a/arch/arm/src/samv7/sam_spi.c
+++ b/arch/arm/src/samv7/sam_spi.c
@@ -1421,20 +1421,31 @@ static void spi_setbits(struct spi_dev_s *dev, int nbits)
static uint32_t spi_send(struct spi_dev_s *dev, uint32_t wd)
{
- uint8_t txbyte;
- uint8_t rxbyte;
+ struct sam_spics_s *spics = (struct sam_spics_s *)dev;
+ if (spics->nbits <= 8)
+ {
+ uint8_t txbyte;
+ uint8_t rxbyte;
- /* spi_exchange can do this. Note: right now, this only deals with 8-bit
- * words. If the SPI interface were configured for words of other sizes,
- * this would fail.
- */
+ txbyte = (uint8_t)wd;
+ rxbyte = (uint8_t)0;
+ spi_exchange(dev, &txbyte, &rxbyte, 1);
+
+ spiinfo("Sent %02x received %02x\n", txbyte, rxbyte);
+ return (uint32_t)rxbyte;
+ }
+ else
+ {
+ uint16_t txword;
+ uint16_t rxword;
- txbyte = (uint8_t)wd;
- rxbyte = (uint8_t)0;
- spi_exchange(dev, &txbyte, &rxbyte, 1);
+ txword = (uint16_t)wd;
+ rxword = (uint16_t)0;
+ spi_exchange(dev, &txword, &rxword, 1);
- spiinfo("Sent %02x received %02x\n", txbyte, rxbyte);
- return (uint32_t)rxbyte;
+ spiinfo("Sent %02x received %02x\n", txword, rxword);
+ return (uint32_t)rxword;
+ }
}
/****************************************************************************