Skip to content

Commit 38fd9c2

Browse files
committed
Re-add APA102
1 parent b310b04 commit 38fd9c2

File tree

2 files changed

+39
-2
lines changed
  • ports/mimxrt10xx/common-hal/microcontroller

2 files changed

+39
-2
lines changed

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
#ifdef MICROPY_HW_NEOPIXEL
3232
bool neopixel_in_use;
3333
#endif
34-
35-
#define GPIO_PORT_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT / 32 + 1)
34+
#ifdef MICROPY_HW_APA102_MOSI
35+
bool apa102_sck_in_use;
36+
bool apa102_mosi_in_use;
37+
#endif
3638

3739
STATIC bool claimed_pins[IOMUXC_SW_PAD_CTL_PAD_COUNT];
3840
STATIC bool never_reset_pins[IOMUXC_SW_PAD_CTL_PAD_COUNT];
@@ -55,6 +57,10 @@ void reset_all_pins(void) {
5557
#ifdef MICROPY_HW_NEOPIXEL
5658
neopixel_in_use = false;
5759
#endif
60+
#ifdef MICROPY_HW_APA102_MOSI
61+
apa102_sck_in_use = false;
62+
apa102_mosi_in_use = false;
63+
#endif
5864
}
5965

6066
// Since i.MX pins need extra register and reset information to reset properly,
@@ -72,6 +78,17 @@ void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
7278
return;
7379
}
7480
#endif
81+
#ifdef MICROPY_HW_APA102_MOSI
82+
if (pin->mux_idx == MICROPY_HW_APA102_MOSI->mux_idx ||
83+
pin->mux_idx == MICROPY_HW_APA102_SCK->mux_idx) {
84+
apa102_mosi_in_use = apa102_mosi_in_use && pin->mux_idx != MICROPY_HW_APA102_MOSI->mux_idx;
85+
apa102_sck_in_use = apa102_sck_in_use && pin->mux_idx != MICROPY_HW_APA102_SCK->mux_idx;
86+
if (!apa102_sck_in_use && !apa102_mosi_in_use) {
87+
rgb_led_status_init();
88+
}
89+
return;
90+
}
91+
#endif
7592
}
7693

7794
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
@@ -84,6 +101,14 @@ bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) {
84101
return !neopixel_in_use;
85102
}
86103
#endif
104+
#ifdef MICROPY_HW_APA102_MOSI
105+
if (pin == MICROPY_HW_APA102_MOSI) {
106+
return !apa102_mosi_in_use;
107+
}
108+
if (pin == MICROPY_HW_APA102_SCK) {
109+
return !apa102_sck_in_use;
110+
}
111+
#endif
87112

88113
return !claimed_pins[pin->mux_idx];
89114
}
@@ -100,6 +125,14 @@ void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin) {
100125
neopixel_in_use = true;
101126
}
102127
#endif
128+
#ifdef MICROPY_HW_APA102_MOSI
129+
if (pin == MICROPY_HW_APA102_MOSI) {
130+
apa102_mosi_in_use = true;
131+
}
132+
if (pin == MICROPY_HW_APA102_SCK) {
133+
apa102_sck_in_use = true;
134+
}
135+
#endif
103136
}
104137

105138
void claim_pin(const mcu_pin_obj_t* pin) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#ifdef MICROPY_HW_NEOPIXEL
3636
extern bool neopixel_in_use;
3737
#endif
38+
#ifdef MICROPY_HW_APA102_MOSI
39+
extern bool apa102_sck_in_use;
40+
extern bool apa102_mosi_in_use;
41+
#endif
3842

3943
void reset_all_pins(void);
4044
void claim_pin(const mcu_pin_obj_t* pin);

0 commit comments

Comments
 (0)