summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)