From dc1702e54abe686f9285a4288a278e8743f3e905 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 19 Dec 2022 12:41:50 -0800 Subject: [PATCH] altos/lpc: Allow USB pull-up to be inverted The lpcxpresso board has an external transistor for the USB pull-up. Signed-off-by: Keith Packard --- src/lpc/ao_usb_lpc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lpc/ao_usb_lpc.c b/src/lpc/ao_usb_lpc.c index 04469916..8c4a8c3b 100644 --- a/src/lpc/ao_usb_lpc.c +++ b/src/lpc/ao_usb_lpc.c @@ -24,6 +24,15 @@ #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(); -- 2.47.2