summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucian Copeland <hierophect@gmail.com>2020-05-19 15:33:34 -0400
committerLucian Copeland <hierophect@gmail.com>2020-05-19 15:33:34 -0400
commit38fd9c25f22ec68920afcf736cb75d4d316ba8bb (patch)
treec9f0f99d23794b67f489206903efff0989ad009f
parentb310b040073d636ead04d3c9c3a4338e18e1627d (diff)
Re-add APA102
-rw-r--r--ports/mimxrt10xx/common-hal/microcontroller/Pin.c37
-rw-r--r--ports/mimxrt10xx/common-hal/microcontroller/Pin.h4
2 files changed, 39 insertions, 2 deletions
diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Pin.c b/ports/mimxrt10xx/common-hal/microcontroller/Pin.c
index 4989a9186..e75df6e60 100644
--- a/ports/mimxrt10xx/common-hal/microcontroller/Pin.c
+++ b/ports/mimxrt10xx/common-hal/microcontroller/Pin.c
@@ -31,8 +31,10 @@
#ifdef MICROPY_HW_NEOPIXEL
bool neopixel_in_use;
#endif
-
-#define GPIO_PORT_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT / 32 + 1)
+#ifdef MICROPY_HW_APA102_MOSI
+bool apa102_sck_in_use;
+bool apa102_mosi_in_use;
+#endif
STATIC bool claimed_pins[IOMUXC_SW_PAD_CTL_PAD_COUNT];
STATIC bool never_reset_pins[IOMUXC_SW_PAD_CTL_PAD_COUNT];
@@ -55,6 +57,10 @@ void reset_all_pins(void) {
#ifdef MICROPY_HW_NEOPIXEL
neopixel_in_use = false;
#endif
+ #ifdef MICROPY_HW_APA102_MOSI
+ apa102_sck_in_use = false;
+ apa102_mosi_in_use = false;
+ #endif
}
// 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) {
return;
}
#endif
+ #ifdef MICROPY_HW_APA102_MOSI
+ if (pin->mux_idx == MICROPY_HW_APA102_MOSI->mux_idx ||
+ pin->mux_idx == MICROPY_HW_APA102_SCK->mux_idx) {
+ apa102_mosi_in_use = apa102_mosi_in_use && pin->mux_idx != MICROPY_HW_APA102_MOSI->mux_idx;
+ apa102_sck_in_use = apa102_sck_in_use && pin->mux_idx != MICROPY_HW_APA102_SCK->mux_idx;
+ if (!apa102_sck_in_use && !apa102_mosi_in_use) {
+ rgb_led_status_init();
+ }
+ return;
+ }
+ #endif
}
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) {
return !neopixel_in_use;
}
#endif
+ #ifdef MICROPY_HW_APA102_MOSI
+ if (pin == MICROPY_HW_APA102_MOSI) {
+ return !apa102_mosi_in_use;
+ }
+ if (pin == MICROPY_HW_APA102_SCK) {
+ return !apa102_sck_in_use;
+ }
+ #endif
return !claimed_pins[pin->mux_idx];
}
@@ -100,6 +125,14 @@ void common_hal_mcu_pin_claim(const mcu_pin_obj_t* pin) {
neopixel_in_use = true;
}
#endif
+ #ifdef MICROPY_HW_APA102_MOSI
+ if (pin == MICROPY_HW_APA102_MOSI) {
+ apa102_mosi_in_use = true;
+ }
+ if (pin == MICROPY_HW_APA102_SCK) {
+ apa102_sck_in_use = true;
+ }
+ #endif
}
void claim_pin(const mcu_pin_obj_t* pin) {
diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Pin.h b/ports/mimxrt10xx/common-hal/microcontroller/Pin.h
index 59ca83082..2f1aaa895 100644
--- a/ports/mimxrt10xx/common-hal/microcontroller/Pin.h
+++ b/ports/mimxrt10xx/common-hal/microcontroller/Pin.h
@@ -35,6 +35,10 @@
#ifdef MICROPY_HW_NEOPIXEL
extern bool neopixel_in_use;
#endif
+#ifdef MICROPY_HW_APA102_MOSI
+extern bool apa102_sck_in_use;
+extern bool apa102_mosi_in_use;
+#endif
void reset_all_pins(void);
void claim_pin(const mcu_pin_obj_t* pin);