From 6680caddf2a16ef662a158defbb2320d57a5e5ba Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 30 Apr 2020 12:30:53 +0200 Subject: MSP430 gpio.setup: Avoid unintentional short circuits --- include/arch/msp430fr5969lp/driver/gpio.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'include/arch/msp430fr5969lp') diff --git a/include/arch/msp430fr5969lp/driver/gpio.h b/include/arch/msp430fr5969lp/driver/gpio.h index 84ce820..e137462 100644 --- a/include/arch/msp430fr5969lp/driver/gpio.h +++ b/include/arch/msp430fr5969lp/driver/gpio.h @@ -19,17 +19,28 @@ class GPIO { PIN_INVALID }; + /* + * Set all non-standard GPIOs to input with pull-down. + * This avoids excessive current draw due to floating inputs. + * Note that we do not set GPIOs to output low, as that might + * short-circuit other peripherals. + */ inline void setup() { + PIDIR = BIT0; // green led + P2DIR = 0; + P3DIR = 0; + P4DIR = BIT6; // red LED + PJDIR = 0; P1OUT = 0; P2OUT = 0; P3OUT = 0; P4OUT = 0; PJOUT = 0; - P1DIR = BIT0 | 0xff; // green LED - P2DIR = 0xff ^ (BIT0 | BIT1); // UART - P3DIR = 0xff; - P4DIR = BIT6 | 0xff; // red LED - PJDIR = BIT6 | BIT7; // HFXT (not populated) + P1REN = 0xff & ~BIT0; // green LED + P2REN = 0xff & ~(BIT0 | BIT1); // UART + P3REN = 0xff; + P4REN = 0xff & ~BIT6; // red LED + PJREN = BIT6 | BIT7; // HFXT (not populated) } inline void led_on(unsigned char id) { if (id == 0) { -- cgit v1.2.3