aboutsummaryrefslogtreecommitdiff
path: root/src/spi_usi.c
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-03-22 14:05:00 +0100
committerKarel Kočí <cynerd@email.cz>2015-03-22 14:05:00 +0100
commita5bb06281011f4f0edd6f7b9331f149bd256d495 (patch)
tree7b576d3b3a737e94a601a236523612369152f52b /src/spi_usi.c
parent9447247c1ab0b0a02c5ec87c138135953986975c (diff)
downloadavr-ioe-a5bb06281011f4f0edd6f7b9331f149bd256d495.tar.gz
avr-ioe-a5bb06281011f4f0edd6f7b9331f149bd256d495.tar.bz2
avr-ioe-a5bb06281011f4f0edd6f7b9331f149bd256d495.zip
SPI moved from src subfolder and mode changes
SPI USI should now work. SPI USI is now documented. Removing architecture specific folders in src.
Diffstat (limited to 'src/spi_usi.c')
-rw-r--r--src/spi_usi.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/spi_usi.c b/src/spi_usi.c
new file mode 100644
index 0000000..7bdb5c2
--- /dev/null
+++ b/src/spi_usi.c
@@ -0,0 +1,54 @@
+#include "../spi_usi.h"
+#include "../mcu/mcu.h"
+
+#ifdef IOE_SPI_USI_MASTER
+
+// TODO counter settings with interups
+inline void ioe_spi_usi_init(void) {
+ // Set USCK and DO as output
+ DDR_USI |= _BV(DD_USCK) | _BV(DD_DO);
+ // Set DI pull up resistor
+ PORT_USI |= _BV(PORT_DI);
+
+ USICR |= _BV(USIWM0) | _BV(USICS1) | _BV(USICLK);
+}
+
+inline int8_t ioe_spi_usi_transfer(int8_t d) {
+ USISR |= _BV(USIOIF);
+ USIDR = d;
+ do {
+ USICR |= _BV(USITC);
+ } while (!(USISR & _BV(USIOIF)));
+ return USIDR;
+}
+
+#else /* IOE_SPI_USI_MASTER */
+
+inline void ioe_spi_usi_init(void) {
+ // Set DO as output
+ DDR_USI |= _BV(DD_DO);
+ // Set USCK and DI pull up resistor
+ PORT_USI |= _BV(PORT_USCK) | _BV(PORT_DI);
+
+ USICR |= _BV(USIWM0) | _BV(USICS1) | _BV(USIOIE);
+}
+
+inline void ioe_spi_usi_expose(int8_t data) {
+ USIDR = data;
+}
+
+inline uint8_t ioe_spi_usi_busy(void) {
+ return USISR & 0x0F;
+}
+
+inline void ioe_spi_usi_join(void) {
+ while (ioe_spi_usi_busy()) {
+ }
+}
+
+SIGNAL(USI_OVF_vect) {
+ ioe_spi_usi_retrieve(USIDR);
+ USISR |= _BV(USIOIF);
+}
+
+#endif /* IOE_SPI_USI_MASTER */