From bf4fc3bf6bc02342ae508b52fb4515d361d626f6 Mon Sep 17 00:00:00 2001 From: Perry Hung Date: Sat, 24 Apr 2010 03:16:35 -0400 Subject: Upper level libmaple interface Added a C++ HardwareSPI class to access the SPI interface. See HardwareSPI.cpp and HardwareSPI.h for documentation. --- libmaple/spi.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'libmaple/spi.h') diff --git a/libmaple/spi.h b/libmaple/spi.h index 457f39b..cde3b42 100644 --- a/libmaple/spi.h +++ b/libmaple/spi.h @@ -48,7 +48,7 @@ extern "C" { #define CR1_BR_PRESCALE_128 0x00000030 #define CR1_BR_PRESCALE_256 0x00000038 -#define CR1_LSBFIRST BIT(7 // data frame format +#define CR1_LSBFIRST BIT(7) // data frame format #define CR1_MSTR BIT(2) // master selection #define CR1_SSM BIT(9) // software slave management #define CR1_SSI BIT(8) // internal slave select @@ -98,6 +98,15 @@ void spi_init(uint32 spi_num, uint32 mode); void spi_tx(uint32 spi_num, uint8 data); +static inline uint8 spi_rx(uint32 spi_num) { + SPI *spi; + + ASSERT(spi_num == 1 || spi_num == 2); + spi = (spi_num == 1) ? (SPI*)SPI1_BASE : (SPI*)SPI2_BASE; + + return spi->DR; +} + #ifdef __cplusplus } #endif -- cgit v1.2.3