summaryrefslogtreecommitdiff
path: root/spi
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2013-02-20 21:09:15 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2013-02-20 21:09:15 +0100
commitc982426fd492b8645a04698f5a2b24e242902100 (patch)
tree37316c5a41136df94314b7737bdadb49770b2b81 /spi
parent423ceb116c118ce657818eabe3d8c66275ce97a3 (diff)
Add SPI_t::transfer_byte().
Diffstat (limited to 'spi')
-rw-r--r--spi/spi.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/spi/spi.h b/spi/spi.h
index 9f9cf63..b6b0a90 100644
--- a/spi/spi.h
+++ b/spi/spi.h
@@ -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)