altos/lpc: Allow USB pull-up to be inverted
authorKeith Packard <keithp@keithp.com>
Mon, 19 Dec 2022 20:41:50 +0000 (12:41 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 19 Dec 2022 20:41:50 +0000 (12:41 -0800)
The lpcxpresso board has an external transistor for the USB
pull-up.

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

index 044699168bae42aac3858a8d2f6105ff4035de45..8c4a8c3bae20787e19635020cbfdf531dad75d4b 100644 (file)
 #define USE_USB_STDIO  1
 #endif
 
+#ifdef HAS_USB_PULLUP_INVERT
+#define USB_CONNECT_VAL                0
+#define USB_DISCONNECT_VAL     1
+#else
+#define USB_CONNECT_VAL                1
+#define USB_DISCONNECT_VAL     0
+#endif
+
+
 #if USE_USB_STDIO
 #define AO_USB_OUT_SLEEP_ADDR  (&ao_stdin_ready)
 #else
@@ -855,7 +864,7 @@ ao_usb_disable(void)
        ao_arch_block_interrupts();
 
 #if HAS_USB_PULLUP
-       ao_gpio_set(AO_USB_PULLUP_PORT, AO_USB_PULLUP_PIN, 0);
+       ao_gpio_set(AO_USB_PULLUP_PORT, AO_USB_PULLUP_PIN, USB_DISCONNECT_VAL);
 #endif
        /* Disable interrupts */
        lpc_usb.inten = 0;
@@ -973,7 +982,7 @@ ao_usb_enable(void)
        ao_usb_set_ep0();
 
 #if HAS_USB_PULLUP
-       ao_gpio_set(AO_USB_PULLUP_PORT, AO_USB_PULLUP_PIN, 1);
+       ao_gpio_set(AO_USB_PULLUP_PORT, AO_USB_PULLUP_PIN, USB_CONNECT_VAL);
 #endif
 }
 
@@ -1012,7 +1021,7 @@ ao_usb_init(void)
 {
 #if HAS_USB_PULLUP
        int     i;
-       ao_enable_output(AO_USB_PULLUP_PORT, AO_USB_PULLUP_PIN, 0);
+       ao_enable_output(AO_USB_PULLUP_PORT, AO_USB_PULLUP_PIN, USB_DISCONNECT_VAL);
 
        for (i = 0; i < 40000; i++)
                ao_arch_nop();