From d13be4ea572b03609c7a48b8dfd2af6c92e4a798 Mon Sep 17 00:00:00 2001 From: Jaroslav Beran Date: Thu, 3 Jun 2021 11:37:54 +0200 Subject: [PATCH] samv7/spi: Allow 16-bit word size in spi_send Signed-off-by: Jaroslav Beran --- 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 5ffc20593e..99e05a2900 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); - 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; - spiinfo("Sent %02x received %02x\n", txbyte, rxbyte); - return (uint32_t)rxbyte; + txword = (uint16_t)wd; + rxword = (uint16_t)0; + spi_exchange(dev, &txword, &rxword, 1); + + spiinfo("Sent %02x received %02x\n", txword, rxword); + return (uint32_t)rxword; + } } /****************************************************************************