Skip to content

Commit 11647f5

Browse files
authored
Merge pull request #6034 from tannewt/i2c_power
Tweak I2C and TFT power pin defaults
2 parents 0d6a27c + 65af10c commit 11647f5

File tree

4 files changed

+17
-8
lines changed
  • ports/espressif

4 files changed

+17
-8
lines changed

ports/espressif/boards/adafruit_feather_esp32s2/board.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@
3232
#include "common-hal/microcontroller/Pin.h"
3333

3434
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();
3936
}
4037

4138
bool board_requests_safe_mode(void) {

ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ uint8_t display_init_sequence[] = {
7171

7272

7373
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.
7578
common_hal_never_reset_pin(&pin_GPIO21);
7679

77-
// Turn on TFT and I2C
78-
gpio_set_direction(21, GPIO_MODE_DEF_OUTPUT);
79-
gpio_set_level(21, true);
80+
reset_board();
8081

8182
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
8283
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
@@ -138,8 +139,13 @@ bool board_requests_safe_mode(void) {
138139
}
139140

140141
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);
141145

146+
free_pin_number(21);
142147
}
143148

144149
void board_deinit(void) {
150+
// TODO: Should we turn off the display when asleep?
145151
}

ports/espressif/common-hal/microcontroller/Pin.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ void claim_pin(const mcu_pin_obj_t *pin) {
133133
in_use[pin->number / 32] |= (1 << (pin->number % 32));
134134
}
135135

136+
void free_pin_number(gpio_num_t pin_number) {
137+
in_use[pin_number / 32] &= ~(1 << (pin_number % 32));
138+
}
139+
136140
void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) {
137141
claim_pin(pin);
138142
}

ports/espressif/common-hal/microcontroller/Pin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ void common_hal_reset_pin(const mcu_pin_obj_t *pin);
3939
void common_hal_never_reset_pin(const mcu_pin_obj_t *pin);
4040
void claim_pin(const mcu_pin_obj_t *pin);
4141
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);
4244
bool pin_number_is_free(gpio_num_t pin_number);
4345
void never_reset_pin_number(gpio_num_t pin_number);
4446

0 commit comments

Comments
 (0)