samv7/spi: Allow 16-bit word size in spi_send

Signed-off-by: Jaroslav Beran <jara.beran@gmail.com>
This commit is contained in:
Jaroslav Beran 2021-06-03 11:37:54 +02:00 committed by Xiang Xiao
parent 69b3f034a4
commit d13be4ea57

View File

@ -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) static uint32_t spi_send(struct spi_dev_s *dev, uint32_t wd)
{ {
uint8_t txbyte; struct sam_spics_s *spics = (struct sam_spics_s *)dev;
uint8_t rxbyte; if (spics->nbits <= 8)
{
uint8_t txbyte;
uint8_t rxbyte;
/* spi_exchange can do this. Note: right now, this only deals with 8-bit txbyte = (uint8_t)wd;
* words. If the SPI interface were configured for words of other sizes, rxbyte = (uint8_t)0;
* this would fail. spi_exchange(dev, &txbyte, &rxbyte, 1);
*/
txbyte = (uint8_t)wd; spiinfo("Sent %02x received %02x\n", txbyte, rxbyte);
rxbyte = (uint8_t)0; return (uint32_t)rxbyte;
spi_exchange(dev, &txbyte, &rxbyte, 1); }
else
{
uint16_t txword;
uint16_t rxword;
spiinfo("Sent %02x received %02x\n", txbyte, rxbyte); txword = (uint16_t)wd;
return (uint32_t)rxbyte; rxword = (uint16_t)0;
spi_exchange(dev, &txword, &rxword, 1);
spiinfo("Sent %02x received %02x\n", txword, rxword);
return (uint32_t)rxword;
}
} }
/**************************************************************************** /****************************************************************************