altos/lpc: Disable JTAG when using pins for GPIO
authorKeith Packard <keithp@keithp.com>
Fri, 7 Nov 2014 00:04:56 +0000 (16:04 -0800)
committerKeith Packard <keithp@keithp.com>
Fri, 7 Nov 2014 00:04:56 +0000 (16:04 -0800)
JTAG is enabled by default, making those pins not support GPIO unless
specifically configured.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/lpc/ao_arch_funcs.h
src/lpc/ao_led_lpc.c

index ff8a184d28198252bbff6787456d9cb9491f9fee..69f2cbfbf971fc9ea671dc4b8bb377e3582eeb7f 100644 (file)
 
 #define ao_gpio_get(port, bit, pin)    (lpc_gpio.byte[lpc_all_bit(port,bit)])
 
+#define PORT0_JTAG_REGS        ((1 << 11) | (1 << 12) | (1 << 14))
+
+static inline void lpc_set_gpio(int port, int bit) {
+       if (port == 0 && (1 << bit) & (PORT0_JTAG_REGS)) {
+               vuint32_t *_ioconf = &lpc_ioconf.pio0_0 + ((port)*24+(bit));
+
+               *_ioconf = (*_ioconf & ~LPC_IOCONF_FUNC_MASK) | LPC_IOCONF_FUNC_PIO0_11;
+       }
+}
+
 #define ao_enable_output(port,bit,pin,v) do {                  \
                ao_enable_port(port);                           \
+               lpc_set_gpio(port,bit);                         \
                ao_gpio_set(port, bit, pin, v);                 \
                lpc_gpio.dir[port] |= (1 << bit);               \
        } while (0)
@@ -52,6 +63,7 @@
 
 #define ao_enable_input(port,bit,mode) do {                            \
                ao_enable_port(port);                                   \
+               lpc_set_gpio(port,bit);                                 \
                lpc_gpio.dir[port] &= ~(1 << bit);                      \
                ao_gpio_set_mode(port,bit,mode);                        \
        } while (0)
index d983437cd4c4549c0a64886b434d8e61f2aebe7b..a0b293b923a8a3b39a683f7566a49da0cb35fabd 100644 (file)
@@ -59,6 +59,15 @@ void
 ao_led_init(AO_PORT_TYPE enable)
 {
        ao_led_enable = enable;
-       lpc_scb.sysahbclkctrl |= (1 << LPC_SCB_SYSAHBCLKCTRL_GPIO);
+       ao_enable_port(LED_PORT);
+       if (LED_PORT == 0) {
+               if (enable & (1 << 11))
+                       lpc_ioconf.pio0_11 = LPC_IOCONF_FUNC_PIO0_11 | (1 << LPC_IOCONF_ADMODE);
+               if (enable & (1 << 12))
+                       lpc_ioconf.pio0_12 = LPC_IOCONF_FUNC_PIO0_12 | (1 << LPC_IOCONF_ADMODE);
+               if (enable & (1 << 14))
+                       lpc_ioconf.pio0_14 = LPC_IOCONF_FUNC_PIO0_14 | (1 << LPC_IOCONF_ADMODE);
+       }
        lpc_gpio.dir[LED_PORT] |= enable;
+       ao_led_off(enable);
 }