Skip to content

Commit 3a7755b

Browse files
authored
Merge pull request #3930 from jerryneedell/jerryn_feathers2_led
UMFEATHERS2 - implement use of DotStar for status led
2 parents 9124529 + de5b138 commit 3a7755b

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

ports/esp32s2/boards/unexpectedmaker_feathers2/board.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "supervisor/board.h"
2828
#include "mpconfigboard.h"
2929
#include "shared-bindings/microcontroller/Pin.h"
30+
#include "components/driver/include/driver/gpio.h"
31+
#include "components/soc/include/hal/gpio_hal.h"
3032

3133
void board_init(void) {
3234
// USB
@@ -47,6 +49,12 @@ void board_init(void) {
4749
common_hal_never_reset_pin(&pin_GPIO30);
4850
common_hal_never_reset_pin(&pin_GPIO31);
4951
common_hal_never_reset_pin(&pin_GPIO32);
52+
53+
54+
// Add LDO2 to never reset list, set to output and enable
55+
common_hal_never_reset_pin(&pin_GPIO21);
56+
gpio_set_direction(pin_GPIO21.number, GPIO_MODE_DEF_OUTPUT);
57+
gpio_set_level(pin_GPIO21.number, true);
5058
}
5159

5260
bool board_requests_safe_mode(void) {

ports/esp32s2/boards/unexpectedmaker_feathers2/mpconfigboard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
#define AUTORESET_DELAY_MS 500
3636

37-
// #define MICROPY_HW_APA102_MOSI (&pin_GPIO40)
38-
// #define MICROPY_HW_APA102_SCK (&pin_GPIO45)
37+
#define MICROPY_HW_APA102_MOSI (&pin_GPIO40)
38+
#define MICROPY_HW_APA102_SCK (&pin_GPIO45)
3939

4040
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO9)
4141
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO8)

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737
#ifdef MICROPY_HW_NEOPIXEL
3838
bool neopixel_in_use;
3939
#endif
40+
#ifdef MICROPY_HW_APA102_MOSI
41+
bool apa102_sck_in_use;
42+
bool apa102_mosi_in_use;
43+
#endif
4044

4145
STATIC uint32_t never_reset_pins[2];
4246
STATIC uint32_t in_use[2];
4347

44-
bool apa102_mosi_in_use;
45-
bool apa102_sck_in_use;
46-
4748
STATIC void floating_gpio_reset(gpio_num_t pin_number) {
4849
// This is the same as gpio_reset_pin(), but without the pullup.
4950
// Note that gpio_config resets the iomatrix to GPIO_FUNC as well.
@@ -86,6 +87,20 @@ void reset_pin_number(gpio_num_t pin_number) {
8687
return;
8788
}
8889
#endif
90+
#ifdef MICROPY_HW_APA102_MOSI
91+
if (pin_number == MICROPY_HW_APA102_MOSI->number ||
92+
pin_number == MICROPY_HW_APA102_SCK->number) {
93+
apa102_mosi_in_use = apa102_mosi_in_use && pin_number != MICROPY_HW_APA102_MOSI->number;
94+
apa102_sck_in_use = apa102_sck_in_use && pin_number != MICROPY_HW_APA102_SCK->number;
95+
if (!apa102_sck_in_use && !apa102_mosi_in_use) {
96+
rgb_led_status_init();
97+
}
98+
return;
99+
}
100+
#endif
101+
102+
103+
89104
}
90105

91106
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
@@ -110,6 +125,11 @@ void reset_all_pins(void) {
110125
#ifdef MICROPY_HW_NEOPIXEL
111126
neopixel_in_use = false;
112127
#endif
128+
#ifdef MICROPY_HW_APA102_MOSI
129+
apa102_sck_in_use = false;
130+
apa102_mosi_in_use = false;
131+
#endif
132+
113133
}
114134

115135
void claim_pin(const mcu_pin_obj_t* pin) {
@@ -119,6 +139,15 @@ void claim_pin(const mcu_pin_obj_t* pin) {
119139
neopixel_in_use = true;
120140
}
121141
#endif
142+
#ifdef MICROPY_HW_APA102_MOSI
143+
if (pin == MICROPY_HW_APA102_MOSI) {
144+
apa102_mosi_in_use = true;
145+
}
146+
if (pin == MICROPY_HW_APA102_SCK) {
147+
apa102_sck_in_use = true;
148+
}
149+
#endif
150+
122151
}
123152

124153
void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin) {
@@ -131,10 +160,18 @@ bool pin_number_is_free(gpio_num_t pin_number) {
131160
return !neopixel_in_use;
132161
}
133162
#endif
163+
#ifdef MICROPY_HW_APA102_MOSI
164+
if (pin_number == MICROPY_HW_APA102_MOSI->number) {
165+
return !apa102_mosi_in_use;
166+
}
167+
if (pin_number == MICROPY_HW_APA102_SCK->number) {
168+
return !apa102_sck_in_use;
169+
}
170+
#endif
134171

135172
uint8_t offset = pin_number / 32;
136173
uint32_t mask = 1 << (pin_number % 32);
137-
return (never_reset_pins[offset] & mask) == 0 && (in_use[offset] & mask) == 0;
174+
return (in_use[offset] & mask) == 0;
138175
}
139176

140177
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131

3232
#include "peripherals/pins.h"
3333

34-
extern bool apa102_mosi_in_use;
34+
#ifdef MICROPY_HW_APA102_MOSI
3535
extern bool apa102_sck_in_use;
36+
extern bool apa102_mosi_in_use;
37+
#endif
3638

3739
#ifdef MICROPY_HW_NEOPIXEL
3840
extern bool neopixel_in_use;

0 commit comments

Comments
 (0)