diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-08-07 10:18:25 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-08-07 10:18:25 +0200 |
commit | f6a842b1b064c83d42dfd626e888f79e4c1633e8 (patch) | |
tree | 5fb6088e10bd7fec2855a4c2a4914812e33a1be3 /include | |
parent | 353aa77910b3a9eeb8282539b17c76c7c7ec0dc7 (diff) |
Support optional SoftI2C pullups on MSP430
Diffstat (limited to 'include')
-rw-r--r-- | include/arch/msp430fr5969lp/driver/gpio.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/arch/msp430fr5969lp/driver/gpio.h b/include/arch/msp430fr5969lp/driver/gpio.h index caed74a..71dab88 100644 --- a/include/arch/msp430fr5969lp/driver/gpio.h +++ b/include/arch/msp430fr5969lp/driver/gpio.h @@ -63,6 +63,29 @@ class GPIO { PJDIR &= ~(1 << (pin - pj_0)); } } + inline void input(unsigned char const pin, unsigned char const pull) { + if (pin < p2_0) { + P1DIR &= ~(1 << pin); + P1OUT = pull ? (P1OUT | (1 << pin)) : (P1OUT & ~(1 << pin)); + P1REN |= (1 << pin); + } else if (pin < p3_0) { + P2DIR &= ~(1 << (pin - p2_0)); + P2OUT = pull ? (P2OUT | (1 << (pin - p2_0))) : (P2OUT & ~(1 << (pin - p2_0))); + P2REN |= (1 << (pin - p2_0)); + } else if (pin < p4_0) { + 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) { + 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 < PIN_INVALID) { + PJDIR &= ~(1 << (pin - pj_0)); + PJOUT = pull ? (PJOUT | (1 << (pin - pj_0))) : (PJOUT & ~(1 << (pin - pj_0))); + PJREN |= (1 << (pin - pj_0)); + } + } inline void output(unsigned char const pin) { if (pin < p2_0) { P1DIR |= (1 << pin); @@ -76,6 +99,24 @@ class GPIO { PJDIR |= (1 << (pin - pj_0)); } } + inline void output(unsigned char const pin, unsigned char const value) { + if (pin < p2_0) { + P1OUT = value ? (P1OUT | (1 << pin)) : (P1OUT & ~(1 << pin)); + P1DIR |= (1 << pin); + } else if (pin < p3_0) { + P2OUT = value ? (P2OUT | (1 << (pin - p2_0))) : (P2OUT & ~(1 << (pin - p2_0))); + P2DIR |= (1 << (pin - p2_0)); + } 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) { + P4OUT = value ? (P4OUT | (1 << (pin - p4_0))) : (P4OUT & ~(1 << (pin - p4_0))); + P4DIR |= (1 << (pin - p4_0)); + } else if (pin < PIN_INVALID) { + PJOUT = value ? (PJOUT | (1 << (pin - pj_0))) : (PJOUT & ~(1 << (pin - pj_0))); + PJDIR |= (1 << (pin - pj_0)); + } + } inline unsigned char read(unsigned char const pin) { if (pin < p2_0) { return P1IN & (1 << pin); |