diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2013-02-20 21:09:15 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2013-02-20 21:09:15 +0100 |
commit | c982426fd492b8645a04698f5a2b24e242902100 (patch) | |
tree | 37316c5a41136df94314b7737bdadb49770b2b81 /spi | |
parent | 423ceb116c118ce657818eabe3d8c66275ce97a3 (diff) |
Add SPI_t::transfer_byte().
Diffstat (limited to 'spi')
-rw-r--r-- | spi/spi.h | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -1,6 +1,8 @@ #ifndef SPI_H #define SPI_H +#include <os/thread.h> + struct SPI_reg_t { volatile uint32_t CR1; volatile uint32_t CR2; @@ -18,6 +20,16 @@ class SPI_t { SPI_reg_t& reg; SPI_t(uint32_t reg_addr) : reg(*(SPI_reg_t*)reg_addr) {} + + uint8_t transfer_byte(uint8_t out = 0) { + reg.DR = out; + + while(!(reg.SR & 0x01)) { + Thread::yield(); + } + + return reg.DR; + } }; #if defined(STM32F1) |