From 0d84f5e512c4148bc45dd26eea177e09c0a21b56 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 11 Jan 2018 14:23:07 +0100 Subject: Add Sharp96 display driver, split up msp430 SPI into a1 / b --- src/arch/msp430fr5969lp/driver/spi_b.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/arch/msp430fr5969lp/driver/spi_b.cc') diff --git a/src/arch/msp430fr5969lp/driver/spi_b.cc b/src/arch/msp430fr5969lp/driver/spi_b.cc index eafb94e..2eb3a79 100644 --- a/src/arch/msp430fr5969lp/driver/spi_b.cc +++ b/src/arch/msp430fr5969lp/driver/spi_b.cc @@ -1,8 +1,10 @@ -#include "driver/spi.h" +#include "driver/spi_b.h" #include -signed char SPI::setup() +void SPI::setup() { + UCB0CTLW0 |= UCSWRST; + /* UCB0CLK Pin 2.2 */ P2SEL0 &= ~BIT2; P2SEL1 |= BIT2; @@ -24,19 +26,25 @@ signed char SPI::setup() UCB0CTLW0 &= ~UCSWRST; } +static inline unsigned char clean_rxbuf() +{ + return UCB0RXBUF; +} + signed char SPI::xmit(unsigned char tx_len, unsigned char *tx_buf, unsigned char rx_len, unsigned char *rx_buf) { - volatile char rxbuf_cache; if (tx_len < 1) { return -1; } - UCB0IE &= ~(UCTXIE | UCRXIE); - while (UCB0STATW & UCBUSY) ; - rxbuf_cache = UCB0RXBUF; + if (!(UCB0IFG & UCTXIFG)) { + return -1; + } + + UCB0IFG &= ~UCRXIFG; UCB0TXBUF = tx_buf[0]; unsigned char tx_pos = 1; @@ -50,9 +58,13 @@ signed char SPI::xmit(unsigned char tx_len, unsigned char *tx_buf, if (rx_pos < rx_len) { rx_buf[rx_pos] = UCB0RXBUF; } else { - rxbuf_cache = UCB0RXBUF; + UCB0IFG &= ~UCRXIFG; } rx_pos++; } } + while (UCB0STATW & UCBUSY) ; + return 0; } + +SPI spi; -- cgit v1.2.3