summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/arch/msp430fr5994lp/driver/gpio.h108
-rw-r--r--src/arch/msp430fr5994lp/driver/spi_b.cc56
2 files changed, 122 insertions, 42 deletions
diff --git a/include/arch/msp430fr5994lp/driver/gpio.h b/include/arch/msp430fr5994lp/driver/gpio.h
index ef681db..aa32e7e 100644
--- a/include/arch/msp430fr5994lp/driver/gpio.h
+++ b/include/arch/msp430fr5994lp/driver/gpio.h
@@ -71,8 +71,16 @@ class GPIO {
P2DIR &= ~(1 << (pin - p2_0));
} else if (pin < p4_0) {
P3DIR &= ~(1 << (pin - p3_0));
- } else if (pin < pj_0) {
+ } else if (pin < p5_0) {
P4DIR &= ~(1 << (pin - p4_0));
+ } else if (pin < p6_0) {
+ P5DIR &= ~(1 << (pin - p5_0));
+ } else if (pin < p7_0) {
+ P6DIR &= ~(1 << (pin - p6_0));
+ } else if (pin < p8_0) {
+ P7DIR &= ~(1 << (pin - p7_0));
+ } else if (pin < pj_0) {
+ P8DIR &= ~(1 << (pin - p8_0));
} else if (pin < PIN_INVALID) {
PJDIR &= ~(1 << (pin - pj_0));
}
@@ -90,10 +98,26 @@ class GPIO {
P3DIR &= ~(1 << (pin - p3_0));
P3OUT = pull ? (P3OUT | (1 << (pin - p3_0))) : (P3OUT & ~(1 << (pin - p3_0)));
P3REN |= (1 << (pin - p3_0));
- } else if (pin < pj_0) {
+ } else if (pin < p5_0) {
P4DIR &= ~(1 << (pin - p4_0));
P4OUT = pull ? (P4OUT | (1 << (pin - p4_0))) : (P4OUT & ~(1 << (pin - p4_0)));
P4REN |= (1 << (pin - p4_0));
+ } else if (pin < p6_0) {
+ P5DIR &= ~(1 << (pin - pj_0));
+ P5OUT = pull ? (P5OUT | (1 << (pin - p5_0))) : (P5OUT & ~(1 << (pin - p5_0)));
+ P5REN |= (1 << (pin - pj_0));
+ } else if (pin < p7_0) {
+ P6DIR &= ~(1 << (pin - p2_0));
+ P6OUT = pull ? (P6OUT | (1 << (pin - p6_0))) : (P6OUT & ~(1 << (pin - p6_0)));
+ P6REN |= (1 << (pin - p2_0));
+ } else if (pin < p8_0) {
+ P7DIR &= ~(1 << (pin - p3_0));
+ P7OUT = pull ? (P7OUT | (1 << (pin - p7_0))) : (P7OUT & ~(1 << (pin - p7_0)));
+ P7REN |= (1 << (pin - p3_0));
+ } else if (pin < pj_0) {
+ P8DIR &= ~(1 << (pin - p4_0));
+ P8OUT = pull ? (P8OUT | (1 << (pin - p8_0))) : (P8OUT & ~(1 << (pin - p8_0)));
+ P8REN |= (1 << (pin - p4_0));
} else if (pin < PIN_INVALID) {
PJDIR &= ~(1 << (pin - pj_0));
PJOUT = pull ? (PJOUT | (1 << (pin - pj_0))) : (PJOUT & ~(1 << (pin - pj_0)));
@@ -107,8 +131,16 @@ class GPIO {
P2DIR |= (1 << (pin - p2_0));
} else if (pin < p4_0) {
P3DIR |= (1 << (pin - p3_0));
- } else if (pin < pj_0) {
+ } else if (pin < p5_0) {
P4DIR |= (1 << (pin - p4_0));
+ } else if (pin < p6_0) {
+ P5DIR |= (1 << (pin - p5_0));
+ } else if (pin < p7_0) {
+ P6DIR |= (1 << (pin - p6_0));
+ } else if (pin < p8_0) {
+ P7DIR |= (1 << (pin - p7_0));
+ } else if (pin < pj_0) {
+ P8DIR |= (1 << (pin - p8_0));
} else if (pin < PIN_INVALID) {
PJDIR |= (1 << (pin - pj_0));
}
@@ -123,9 +155,21 @@ class GPIO {
} else if (pin < p4_0) {
P3OUT = value ? (P3OUT | (1 << (pin - p3_0))) : (P3OUT & ~(1 << (pin - p3_0)));
P3DIR |= (1 << (pin - p3_0));
- } else if (pin < pj_0) {
+ } else if (pin < p5_0) {
P4OUT = value ? (P4OUT | (1 << (pin - p4_0))) : (P4OUT & ~(1 << (pin - p4_0)));
P4DIR |= (1 << (pin - p4_0));
+ } else if (pin < p6_0) {
+ P5OUT = value ? (P5OUT | (1 << (pin - p5_0))) : (P5OUT & ~(1 << (pin - p5_0)));
+ P5DIR |= (1 << (pin - p5_0));
+ } else if (pin < p7_0) {
+ P6OUT = value ? (P6OUT | (1 << (pin - p6_0))) : (P6OUT & ~(1 << (pin - p6_0)));
+ P6DIR |= (1 << (pin - p6_0));
+ } else if (pin < p8_0) {
+ P7OUT = value ? (P7OUT | (1 << (pin - p7_0))) : (P7OUT & ~(1 << (pin - p7_0)));
+ P7DIR |= (1 << (pin - p7_0));
+ } else if (pin < pj_0) {
+ P8OUT = value ? (P8OUT | (1 << (pin - p8_0))) : (P8OUT & ~(1 << (pin - p8_0)));
+ P8DIR |= (1 << (pin - p8_0));
} else if (pin < PIN_INVALID) {
PJOUT = value ? (PJOUT | (1 << (pin - pj_0))) : (PJOUT & ~(1 << (pin - pj_0)));
PJDIR |= (1 << (pin - pj_0));
@@ -138,8 +182,16 @@ class GPIO {
return P2IN & (1 << (pin - p2_0));
} else if (pin < p4_0) {
return P3IN & (1 << (pin - p3_0));
- } else if (pin < pj_0) {
+ } else if (pin < p5_0) {
return P4IN & (1 << (pin - p4_0));
+ } else if (pin < p6_0) {
+ return P5IN & (1 << (pin - p5_0));
+ } else if (pin < p7_0) {
+ return P6IN & (1 << (pin - p6_0));
+ } else if (pin < p8_0) {
+ return P7IN & (1 << (pin - p7_0));
+ } else if (pin < pj_0) {
+ return P8IN & (1 << (pin - p8_0));
} else if (pin < PIN_INVALID) {
return PJIN & (1 << (pin - pj_0));
}
@@ -164,12 +216,36 @@ class GPIO {
} else {
P3OUT &= ~(1 << (pin - p3_0));
}
- } else if (pin < pj_0) {
+ } else if (pin < p5_0) {
if (value) {
P4OUT |= (1 << (pin - p4_0));
} else {
P4OUT &= ~(1 << (pin - p4_0));
}
+ } else if (pin < p6_0) {
+ if (value) {
+ P5OUT |= (1 << (pin - p5_0));
+ } else {
+ P5OUT &= ~(1 << (pin - p5_0));
+ }
+ } else if (pin < p7_0) {
+ if (value) {
+ P6OUT |= (1 << (pin - p6_0));
+ } else {
+ P6OUT &= ~(1 << (pin - p6_0));
+ }
+ } else if (pin < p8_0) {
+ if (value) {
+ P7OUT |= (1 << (pin - p7_0));
+ } else {
+ P7OUT &= ~(1 << (pin - p7_0));
+ }
+ } else if (pin < pj_0) {
+ if (value) {
+ P8OUT |= (1 << (pin - p8_0));
+ } else {
+ P8OUT &= ~(1 << (pin - p8_0));
+ }
} else if (pin < PIN_INVALID) {
if (value) {
PJOUT |= (1 << (pin - pj_0));
@@ -181,17 +257,21 @@ class GPIO {
inline void write_mask(unsigned char const pin_base, unsigned char set_mask, unsigned char clear_mask) {
if (pin_base < p2_0) {
P1OUT = (P1OUT | set_mask) & ~clear_mask;
- }
- if (pin_base < p3_0) {
+ } else if (pin_base < p3_0) {
P2OUT = (P2OUT | set_mask) & ~clear_mask;
- }
- if (pin_base < p4_0) {
+ } else if (pin_base < p4_0) {
P3OUT = (P3OUT | set_mask) & ~clear_mask;
- }
- if (pin_base < pj_0) {
+ } else if (pin_base < p5_0) {
P4OUT = (P4OUT | set_mask) & ~clear_mask;
- }
- if (pin_base < PIN_INVALID) {
+ } else if (pin_base < p6_0) {
+ P5OUT = (P5OUT | set_mask) & ~clear_mask;
+ } else if (pin_base < p7_0) {
+ P6OUT = (P6OUT | set_mask) & ~clear_mask;
+ } else if (pin_base < p8_0) {
+ P7OUT = (P7OUT | set_mask) & ~clear_mask;
+ } else if (pin_base < pj_0) {
+ P8OUT = (P8OUT | set_mask) & ~clear_mask;
+ } else if (pin_base < PIN_INVALID) {
PJOUT = (PJOUT | set_mask) & ~clear_mask;
}
}
diff --git a/src/arch/msp430fr5994lp/driver/spi_b.cc b/src/arch/msp430fr5994lp/driver/spi_b.cc
index 0fa71da..8624a40 100644
--- a/src/arch/msp430fr5994lp/driver/spi_b.cc
+++ b/src/arch/msp430fr5994lp/driver/spi_b.cc
@@ -7,33 +7,33 @@
void SPI::setup()
{
- UCB0CTLW0 |= UCSWRST;
+ UCB1CTLW0 |= UCSWRST;
- /* UCB0CLK Pin 2.2 */
- P2SEL0 &= ~BIT2;
- P2SEL1 |= BIT2;
- P2DIR |= BIT2;
+ /* UCB1CLK Pin 5.2 */
+ P5SEL1 &= ~BIT2;
+ P5SEL0 |= BIT2;
+ P5DIR |= BIT2;
- /* UCB0SIMO Pin 1.6 */
- P1SEL0 &= ~BIT6;
- P1SEL1 |= BIT6;
- P1DIR |= BIT6;
+ /* UCB1SIMO Pin 5.0 */
+ P5SEL1 &= ~BIT0;
+ P5SEL0 |= BIT0;
+ P5DIR |= BIT0;
- /* UCB0SOMI Pin 1.7 */
- P1SEL0 &= ~BIT7;
- P1SEL1 |= BIT7;
- P1DIR &= ~BIT7;
+ /* UCB1SOMI Pin 5.1 */
+ P5SEL1 &= ~BIT1;
+ P5SEL0 |= BIT1;
+ P5DIR &= ~BIT1;
//P1REN |= BIT6;
- UCB0CTLW0 = UCCKPH | UCMSB | UCMST | UCSYNC | UCMODE_0 | UCSSEL__SMCLK | UCSWRST;
- UCB0BRW = (F_CPU/F_I2C)-1; // /16 -> 1MHz
- // UCB0BRW = (F_CPU / F_I2C) - 1
- UCB0CTLW0 &= ~UCSWRST;
+ UCB1CTLW0 = UCCKPH | UCMSB | UCMST | UCSYNC | UCMODE_0 | UCSSEL__SMCLK | UCSWRST;
+ UCB1BRW = (F_CPU/F_I2C)-1; // /16 -> 1MHz
+ // UCB1BRW = (F_CPU / F_I2C) - 1
+ UCB1CTLW0 &= ~UCSWRST;
}
static inline unsigned char clean_rxbuf()
{
- return UCB0RXBUF;
+ return UCB1RXBUF;
}
signed char SPI::xmit(unsigned char tx_len, unsigned char *tx_buf,
@@ -43,32 +43,32 @@ signed char SPI::xmit(unsigned char tx_len, unsigned char *tx_buf,
return -1;
}
- while (UCB0STATW & UCBUSY) ;
+ while (UCB1STATW & UCBUSY) ;
- if (!(UCB0IFG & UCTXIFG)) {
+ if (!(UCB1IFG & UCTXIFG)) {
return -1;
}
- UCB0IFG &= ~UCRXIFG;
- UCB0TXBUF = tx_buf[0];
+ UCB1IFG &= ~UCRXIFG;
+ UCB1TXBUF = tx_buf[0];
unsigned char tx_pos = 1;
unsigned char rx_pos = 0;
while (tx_pos < tx_len || rx_pos < rx_len) {
- if ((tx_pos < tx_len) && (UCB0IFG & UCTXIFG)) {
- UCB0TXBUF = tx_buf[tx_pos++];
+ if ((tx_pos < tx_len) && (UCB1IFG & UCTXIFG)) {
+ UCB1TXBUF = tx_buf[tx_pos++];
}
- if (UCB0IFG & UCRXIFG) {
+ if (UCB1IFG & UCRXIFG) {
if (rx_pos < rx_len) {
- rx_buf[rx_pos] = UCB0RXBUF;
+ rx_buf[rx_pos] = UCB1RXBUF;
} else {
- UCB0IFG &= ~UCRXIFG;
+ UCB1IFG &= ~UCRXIFG;
}
rx_pos++;
}
}
- while (UCB0STATW & UCBUSY) ;
+ while (UCB1STATW & UCBUSY) ;
return 0;
}