File tree Expand file tree Collapse file tree 3 files changed +31
-4
lines changed
boards/adafruit_feather_rp2040_usb_host
common-hal/microcontroller Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Original file line number Diff line number Diff line change 28
28
29
29
#include "shared-bindings/digitalio/DigitalInOut.h"
30
30
#include "shared-bindings/usb_host/Port.h"
31
+ #include "hardware/gpio.h"
31
32
32
33
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
33
34
34
35
digitalio_digitalinout_obj_t _host_power ;
35
36
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 );
40
46
47
+ return true;
48
+ }
49
+ return false;
50
+ }
51
+ void board_init (void ) {
41
52
common_hal_usb_host_port_construct (& pin_GPIO16 , & pin_GPIO17 );
42
53
}
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ void never_reset_pin_number(uint8_t pin_number) {
73
73
never_reset_pins |= 1 << pin_number ;
74
74
}
75
75
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
+
76
81
void reset_pin_number (uint8_t pin_number ) {
77
82
if (pin_number >= NUM_BANK0_GPIOS ) {
78
83
return ;
@@ -81,6 +86,11 @@ void reset_pin_number(uint8_t pin_number) {
81
86
gpio_bank0_pin_claimed &= ~(1 << pin_number );
82
87
never_reset_pins &= ~(1 << pin_number );
83
88
89
+ // Allow the board to override the reset state of any pin
90
+ if (board_reset_pin_number (pin_number )) {
91
+ return ;
92
+ }
93
+
84
94
// We are very aggressive in shutting down the pad fully. Both pulls are
85
95
// disabled and both buffers are as well.
86
96
gpio_init (pin_number );
Original file line number Diff line number Diff line change 34
34
35
35
#include "peripherals/pins.h"
36
36
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
+
37
43
void reset_all_pins (void );
38
44
// reset_pin_number takes the pin number instead of the pointer so that objects don't
39
45
// need to store a full pointer.
You can’t perform that action at this time.
0 commit comments