File tree Expand file tree Collapse file tree 4 files changed +17
-8
lines changed
adafruit_feather_esp32s2_tft
common-hal/microcontroller Expand file tree Collapse file tree 4 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 32
32
#include "common-hal/microcontroller/Pin.h"
33
33
34
34
void board_init (void ) {
35
- // Turn on I2C
36
- common_hal_never_reset_pin (& pin_GPIO7 );
37
- gpio_set_direction (7 , GPIO_MODE_DEF_OUTPUT );
38
- gpio_set_level (7 , false);
35
+ reset_board ();
39
36
}
40
37
41
38
bool board_requests_safe_mode (void ) {
Original file line number Diff line number Diff line change @@ -71,12 +71,13 @@ uint8_t display_init_sequence[] = {
71
71
72
72
73
73
void board_init (void ) {
74
- // I2C/TFT power pin
74
+ // Never reset the I2C/TFT power pin because doing so will reset the display.
75
+ // Instead, on reset set the default value and free the pin for user use.
76
+ // Relying on the normal pin reset would briefly float/pull the pin that
77
+ // could lead to a power brownout.
75
78
common_hal_never_reset_pin (& pin_GPIO21 );
76
79
77
- // Turn on TFT and I2C
78
- gpio_set_direction (21 , GPIO_MODE_DEF_OUTPUT );
79
- gpio_set_level (21 , true);
80
+ reset_board ();
80
81
81
82
busio_spi_obj_t * spi = common_hal_board_create_spi (0 );
82
83
displayio_fourwire_obj_t * bus = & displays [0 ].fourwire_bus ;
@@ -138,8 +139,13 @@ bool board_requests_safe_mode(void) {
138
139
}
139
140
140
141
void reset_board (void ) {
142
+ // Turn on TFT and I2C
143
+ gpio_set_direction (21 , GPIO_MODE_DEF_OUTPUT );
144
+ gpio_set_level (21 , true);
141
145
146
+ free_pin_number (21 );
142
147
}
143
148
144
149
void board_deinit (void ) {
150
+ // TODO: Should we turn off the display when asleep?
145
151
}
Original file line number Diff line number Diff line change @@ -133,6 +133,10 @@ void claim_pin(const mcu_pin_obj_t *pin) {
133
133
in_use [pin -> number / 32 ] |= (1 << (pin -> number % 32 ));
134
134
}
135
135
136
+ void free_pin_number (gpio_num_t pin_number ) {
137
+ in_use [pin_number / 32 ] &= ~(1 << (pin_number % 32 ));
138
+ }
139
+
136
140
void common_hal_mcu_pin_claim (const mcu_pin_obj_t * pin ) {
137
141
claim_pin (pin );
138
142
}
Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ void common_hal_reset_pin(const mcu_pin_obj_t *pin);
39
39
void common_hal_never_reset_pin (const mcu_pin_obj_t * pin );
40
40
void claim_pin (const mcu_pin_obj_t * pin );
41
41
void claim_pin_number (gpio_num_t pin_number );
42
+ // Free the pin without resetting it.
43
+ void free_pin_number (gpio_num_t pin_number );
42
44
bool pin_number_is_free (gpio_num_t pin_number );
43
45
void never_reset_pin_number (gpio_num_t pin_number );
44
46
You can’t perform that action at this time.
0 commit comments