diff options
author | Perry Hung <iperry@alum.mit.edu> | 2010-04-27 18:30:46 -0400 |
---|---|---|
committer | Perry Hung <iperry@alum.mit.edu> | 2010-04-27 18:30:46 -0400 |
commit | 28feb18a8f6d3dd2d0d78a40d4213407fb54e5dd (patch) | |
tree | 9bffb2da20492ceafd83101cbdff817870b92b1b /libmaple | |
parent | 434e223114b0398b92f3c027747f82bd7187569a (diff) | |
download | librambutan-28feb18a8f6d3dd2d0d78a40d4213407fb54e5dd.tar.gz librambutan-28feb18a8f6d3dd2d0d78a40d4213407fb54e5dd.zip |
Added a spi send block function
Diffstat (limited to 'libmaple')
-rw-r--r-- | libmaple/spi.c | 28 | ||||
-rw-r--r-- | libmaple/spi.h | 3 |
2 files changed, 28 insertions, 3 deletions
diff --git a/libmaple/spi.c b/libmaple/spi.c index ddc8346..4f34d1a 100644 --- a/libmaple/spi.c +++ b/libmaple/spi.c @@ -112,7 +112,7 @@ void spi_init(uint32 spi_num, * @param spi_num which spi to send on * @return data shifted back from the slave */ -void spi_tx(uint32 spi_num, uint8 data) { +uint8 spi_tx_byte(uint32 spi_num, uint8 data) { SPI *spi; ASSERT(spi_num == 1 || spi_num == 2); @@ -121,8 +121,32 @@ void spi_tx(uint32 spi_num, uint8 data) { spi->DR = data; - while (!(spi->SR & SR_TXE) || (spi->SR & SR_BSY)) + while (!(spi->SR & SR_TXE) || + (spi->SR & SR_BSY)) ; + + return spi->DR; +} + +uint8 spi_tx(uint32 spi_num, uint8 *buf, uint32 len) { + SPI *spi; + uint32 i; + + ASSERT(spi_num == 1 || spi_num == 2); + spi = (spi_num == 1) ? (SPI*)SPI1_BASE : (SPI*)SPI2_BASE; + + if (!len) { + return 0; + } + + while (i < len) { + spi->DR = buf[len]; + while (!(spi->SR & SR_TXE) || + (spi->SR & SR_BSY)) + ; + i++; + } + return spi->DR; } static void spi_gpio_cfg(const spi_dev *dev) { diff --git a/libmaple/spi.h b/libmaple/spi.h index cde3b42..25c2c6b 100644 --- a/libmaple/spi.h +++ b/libmaple/spi.h @@ -96,7 +96,8 @@ void spi_init(uint32 spi_num, uint32 prescale, uint32 endian, uint32 mode); -void spi_tx(uint32 spi_num, uint8 data); +uint8 spi_tx_byte(uint32 spi_num, uint8 data); +uint8 spi_tx(uint32 spi_num, uint8 *buf, uint32 len); static inline uint8 spi_rx(uint32 spi_num) { SPI *spi; |