File tree Expand file tree Collapse file tree
boards/adafruit_feather_rp2040_usb_host
common-hal/microcontroller Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828
2929#include "shared-bindings/digitalio/DigitalInOut.h"
3030#include "shared-bindings/usb_host/Port.h"
31+ #include "hardware/gpio.h"
3132
3233// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
3334
3435digitalio_digitalinout_obj_t _host_power ;
3536
36- void board_init (void ) {
37- common_hal_digitalio_digitalinout_construct (& _host_power , & pin_GPIO18 );
38- common_hal_digitalio_digitalinout_never_reset (& _host_power );
39- common_hal_digitalio_digitalinout_switch_to_output (& _host_power , true, DRIVE_MODE_PUSH_PULL );
37+ bool board_reset_pin_number (uint8_t pin_number ) {
38+ if (pin_number == 18 ) {
39+ // doing this (rather than gpio_init) in this specific order ensures no
40+ // glitch if pin was already configured as a high output. gpio_init() temporarily
41+ // configures the pin as an input, so the power enable value would potentially
42+ // glitch.
43+ gpio_put (pin_number , 1 );
44+ gpio_set_dir (pin_number , GPIO_OUT );
45+ gpio_set_function (pin_number , GPIO_FUNC_SIO );
4046
47+ return true;
48+ }
49+ return false;
50+ }
51+ void board_init (void ) {
4152 common_hal_usb_host_port_construct (& pin_GPIO16 , & pin_GPIO17 );
4253}
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ void never_reset_pin_number(uint8_t pin_number) {
7373 never_reset_pins |= 1 << pin_number ;
7474}
7575
76+ // By default, all pins get reset in the same way
77+ MP_WEAK bool board_reset_pin_number (uint8_t pin_number ) {
78+ return false;
79+ }
80+
7681void reset_pin_number (uint8_t pin_number ) {
7782 if (pin_number >= NUM_BANK0_GPIOS ) {
7883 return ;
@@ -81,6 +86,11 @@ void reset_pin_number(uint8_t pin_number) {
8186 gpio_bank0_pin_claimed &= ~(1 << pin_number );
8287 never_reset_pins &= ~(1 << pin_number );
8388
89+ // Allow the board to override the reset state of any pin
90+ if (board_reset_pin_number (pin_number )) {
91+ return ;
92+ }
93+
8494 // We are very aggressive in shutting down the pad fully. Both pulls are
8595 // disabled and both buffers are as well.
8696 gpio_init (pin_number );
Original file line number Diff line number Diff line change 3434
3535#include "peripherals/pins.h"
3636
37+ // If a board needs a different reset state for one or more pins, implement
38+ // board_reset_pin_number so that it sets this state and returns `true` for those
39+ // pin numbers, `false` for others.
40+ // A default weak implementation always returns `false`.
41+ bool board_reset_pin_number (uint8_t pin_number );
42+
3743void reset_all_pins (void );
3844// reset_pin_number takes the pin number instead of the pointer so that objects don't
3945// need to store a full pointer.
You can’t perform that action at this time.
0 commit comments