From b13f470d5c5947ab19362b187ae6849c3143de35 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 27 Jan 2025 12:32:04 -0600 Subject: [PATCH] metro rp2350: Enable USB host by default Testing performed: This allows a plugged-in USB keyboard to be used to enter the repl with ctrl-c & type text. --- .../boards/adafruit_metro_rp2350/board.c | 27 +++++++++++++++++++ .../adafruit_metro_rp2350/mpconfigboard.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/ports/raspberrypi/boards/adafruit_metro_rp2350/board.c b/ports/raspberrypi/boards/adafruit_metro_rp2350/board.c index e6a868ab21226..111fc5175139c 100644 --- a/ports/raspberrypi/boards/adafruit_metro_rp2350/board.c +++ b/ports/raspberrypi/boards/adafruit_metro_rp2350/board.c @@ -4,6 +4,33 @@ // // SPDX-License-Identifier: MIT +#include "common-hal/microcontroller/Pin.h" +#include "hardware/gpio.h" +#include "shared-bindings/usb_host/Port.h" #include "supervisor/board.h" // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. + + +#if defined(DEFAULT_USB_HOST_5V_POWER) +bool board_reset_pin_number(uint8_t pin_number) { + if (pin_number == DEFAULT_USB_HOST_5V_POWER->number) { + // doing this (rather than gpio_init) in this specific order ensures no + // glitch if pin was already configured as a high output. gpio_init() temporarily + // configures the pin as an input, so the power enable value would potentially + // glitch. + gpio_put(pin_number, 1); + gpio_set_dir(pin_number, GPIO_OUT); + gpio_set_function(pin_number, GPIO_FUNC_SIO); + + return true; + } + return false; +} +#endif + +#if defined(DEFAULT_USB_HOST_DATA_PLUS) +void board_init(void) { + common_hal_usb_host_port_construct(DEFAULT_USB_HOST_DATA_PLUS, DEFAULT_USB_HOST_DATA_MINUS); +} +#endif diff --git a/ports/raspberrypi/boards/adafruit_metro_rp2350/mpconfigboard.h b/ports/raspberrypi/boards/adafruit_metro_rp2350/mpconfigboard.h index d1b7056867900..c8e73600d07df 100644 --- a/ports/raspberrypi/boards/adafruit_metro_rp2350/mpconfigboard.h +++ b/ports/raspberrypi/boards/adafruit_metro_rp2350/mpconfigboard.h @@ -22,4 +22,7 @@ // #define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX // #define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX +#define DEFAULT_USB_HOST_DATA_PLUS (&pin_GPIO32) +#define DEFAULT_USB_HOST_DATA_MINUS (&pin_GPIO33) +#define DEFAULT_USB_HOST_5V_POWER (&pin_GPIO29) #define CIRCUITPY_PSRAM_CHIP_SELECT (&pin_GPIO47)