From de5691acf5060d6e2182da4c84095a007f6da606 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Fri, 15 Nov 2019 12:47:00 -0500 Subject: [PATCH 1/4] Add never_reset and reset to pin common hal, adjust files --- ports/atmel-samd/common-hal/microcontroller/Pin.c | 8 ++++++++ ports/nrf/common-hal/microcontroller/Pin.c | 8 ++++++++ ports/stm32f4/common-hal/microcontroller/Pin.c | 8 ++++++++ shared-bindings/microcontroller/Pin.h | 2 ++ shared-module/displayio/Display.c | 2 +- shared-module/displayio/EPaperDisplay.c | 2 +- shared-module/displayio/FourWire.c | 13 +++++++------ shared-module/displayio/I2CDisplay.c | 5 +++-- supervisor/shared/rgb_led_status.c | 8 ++++---- 9 files changed, 42 insertions(+), 14 deletions(-) diff --git a/ports/atmel-samd/common-hal/microcontroller/Pin.c b/ports/atmel-samd/common-hal/microcontroller/Pin.c index 6f3cbc7598..9719ea5b11 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Pin.c +++ b/ports/atmel-samd/common-hal/microcontroller/Pin.c @@ -158,6 +158,14 @@ void reset_pin_number(uint8_t pin_number) { #endif } +void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) { + never_reset_pin_number(pin->number); +} + +void common_hal_reset_pin(const mcu_pin_obj_t* pin) { + reset_pin_number(pin->number); +} + void claim_pin(const mcu_pin_obj_t* pin) { #ifdef MICROPY_HW_NEOPIXEL if (pin == MICROPY_HW_NEOPIXEL) { diff --git a/ports/nrf/common-hal/microcontroller/Pin.c b/ports/nrf/common-hal/microcontroller/Pin.c index ce55317e54..b7931a2e16 100644 --- a/ports/nrf/common-hal/microcontroller/Pin.c +++ b/ports/nrf/common-hal/microcontroller/Pin.c @@ -125,6 +125,14 @@ void never_reset_pin_number(uint8_t pin_number) { never_reset_pins[nrf_pin_port(pin_number)] |= 1 << nrf_relative_pin_number(pin_number); } +void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) { + never_reset_pin_number(pin->number); +} + +void common_hal_reset_pin(const mcu_pin_obj_t* pin) { + reset_pin_number(pin->number); +} + void claim_pin(const mcu_pin_obj_t* pin) { // Set bit in claimed_pins bitmask. claimed_pins[nrf_pin_port(pin->number)] |= 1 << nrf_relative_pin_number(pin->number); diff --git a/ports/stm32f4/common-hal/microcontroller/Pin.c b/ports/stm32f4/common-hal/microcontroller/Pin.c index 5761d7fb15..7e737e21b4 100644 --- a/ports/stm32f4/common-hal/microcontroller/Pin.c +++ b/ports/stm32f4/common-hal/microcontroller/Pin.c @@ -72,6 +72,14 @@ void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) { never_reset_pins[pin_port] |= 1<port, pin->number); +} + +void common_hal_reset_pin(const mcu_pin_obj_t* pin) { + reset_pin_number(pin->port, pin->number); +} + void claim_pin(const mcu_pin_obj_t* pin) { // Set bit in claimed_pins bitmask. claimed_pins[pin->port] |= 1<number; diff --git a/shared-bindings/microcontroller/Pin.h b/shared-bindings/microcontroller/Pin.h index ed831b2589..2d15dd5c58 100644 --- a/shared-bindings/microcontroller/Pin.h +++ b/shared-bindings/microcontroller/Pin.h @@ -37,5 +37,7 @@ void assert_pin(mp_obj_t obj, bool none_ok); void assert_pin_free(const mcu_pin_obj_t* pin); bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin); +void common_hal_never_reset_pin(const mcu_pin_obj_t* pin); +void common_hal_reset_pin(const mcu_pin_obj_t* pin); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 06b81f2f84..862d2cf598 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -113,7 +113,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, if (result != PWMOUT_OK) { self->backlight_inout.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&self->backlight_inout, backlight_pin); - never_reset_pin_number(backlight_pin->number); + common_hal_never_reset_pin(backlight_pin); } else { self->backlight_pwm.base.type = &pulseio_pwmout_type; common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm); diff --git a/shared-module/displayio/EPaperDisplay.c b/shared-module/displayio/EPaperDisplay.c index efbd9f3ddb..df1d5162b7 100644 --- a/shared-module/displayio/EPaperDisplay.c +++ b/shared-module/displayio/EPaperDisplay.c @@ -82,7 +82,7 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t* if (busy_pin != NULL) { self->busy.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&self->busy, busy_pin); - never_reset_pin_number(busy_pin->number); + common_hal_never_reset_pin(busy_pin); } // Clear the color memory if it isn't in use. diff --git a/shared-module/displayio/FourWire.c b/shared-module/displayio/FourWire.c index fcc4c1a20a..92d4507dde 100644 --- a/shared-module/displayio/FourWire.c +++ b/shared-module/displayio/FourWire.c @@ -31,6 +31,7 @@ #include "py/gc.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/time/__init__.h" #include "shared-module/displayio/display_core.h" @@ -61,12 +62,12 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self, self->reset.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&self->reset, reset); common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); - never_reset_pin_number(reset->number); + common_hal_never_reset_pin(reset); common_hal_displayio_fourwire_reset(self); } - never_reset_pin_number(command->number); - never_reset_pin_number(chip_select->number); + common_hal_never_reset_pin(command); + common_hal_never_reset_pin(chip_select); } void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self) { @@ -74,9 +75,9 @@ void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self) { common_hal_busio_spi_deinit(self->bus); } - reset_pin_number(self->command.pin->number); - reset_pin_number(self->chip_select.pin->number); - reset_pin_number(self->reset.pin->number); + common_hal_reset_pin(self->command.pin); + common_hal_reset_pin(self->chip_select.pin); + common_hal_reset_pin(self->reset.pin); } bool common_hal_displayio_fourwire_reset(mp_obj_t obj) { diff --git a/shared-module/displayio/I2CDisplay.c b/shared-module/displayio/I2CDisplay.c index 0307410d14..280476f195 100644 --- a/shared-module/displayio/I2CDisplay.c +++ b/shared-module/displayio/I2CDisplay.c @@ -33,6 +33,7 @@ #include "py/runtime.h" #include "shared-bindings/busio/I2C.h" #include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/time/__init__.h" #include "shared-module/displayio/display_core.h" @@ -48,7 +49,7 @@ void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self, self->reset.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&self->reset, reset); common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); - never_reset_pin_number(reset->number); + common_hal_never_reset_pin(reset); common_hal_displayio_i2cdisplay_reset(self); } @@ -72,7 +73,7 @@ void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) { common_hal_busio_i2c_deinit(self->bus); } - reset_pin_number(self->reset.pin->number); + common_hal_reset_pin(self->reset.pin); } bool common_hal_displayio_i2cdisplay_reset(mp_obj_t obj) { diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 05df4c628a..90c78fbbe7 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -117,7 +117,7 @@ void rgb_led_status_init() { mp_const_none); #else if (!common_hal_busio_spi_deinited(&status_apa102)) { - // This may call us recursively if reset_pin_number() is called, + // This may call us recursively if common_hal_reset_pin() is called, // The rgb_led_status_init_in_progress guard will prevent further recursion. common_hal_busio_spi_deinit(&status_apa102); } @@ -181,11 +181,11 @@ void rgb_led_status_init() { void reset_status_led() { #ifdef MICROPY_HW_NEOPIXEL - reset_pin_number(MICROPY_HW_NEOPIXEL->number); + common_hal_reset_pin(MICROPY_HW_NEOPIXEL); #endif #if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK) - reset_pin_number(MICROPY_HW_APA102_MOSI->number); - reset_pin_number(MICROPY_HW_APA102_SCK->number); + common_hal_reset_pin(MICROPY_HW_APA102_MOSI); + common_hal_reset_pin(MICROPY_HW_APA102_SCK); #endif #if defined(CP_RGB_STATUS_LED) // TODO: Support sharing status LED with user. From 8ff1bc0132bafe4b81adb8fce4e4d2f7844e12ef Mon Sep 17 00:00:00 2001 From: Hierophect Date: Fri, 15 Nov 2019 12:49:47 -0500 Subject: [PATCH 2/4] add missing include --- supervisor/shared/rgb_led_status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 90c78fbbe7..940cbf1f27 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -25,7 +25,7 @@ */ #include "mphalport.h" -#include "common-hal/microcontroller/Pin.h" +#include "shared-bindings/microcontroller/Pin.h" #include "rgb_led_status.h" #ifdef MICROPY_HW_NEOPIXEL From 2c6781f74d0c8b53c0bdcd7f0b954ac831167937 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Fri, 15 Nov 2019 12:59:52 -0500 Subject: [PATCH 3/4] move neopixel_in_use flag to shared-bindings --- ports/atmel-samd/common-hal/microcontroller/Pin.h | 3 --- ports/nrf/common-hal/microcontroller/Pin.h | 3 --- shared-bindings/microcontroller/Pin.h | 4 ++++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ports/atmel-samd/common-hal/microcontroller/Pin.h b/ports/atmel-samd/common-hal/microcontroller/Pin.h index 14887207aa..090d7a512a 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Pin.h +++ b/ports/atmel-samd/common-hal/microcontroller/Pin.h @@ -31,9 +31,6 @@ #include "peripherals/samd/pins.h" -#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; diff --git a/ports/nrf/common-hal/microcontroller/Pin.h b/ports/nrf/common-hal/microcontroller/Pin.h index 735ed90cca..5a1fd39616 100644 --- a/ports/nrf/common-hal/microcontroller/Pin.h +++ b/ports/nrf/common-hal/microcontroller/Pin.h @@ -31,9 +31,6 @@ #include "peripherals/nrf/pins.h" -#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; diff --git a/shared-bindings/microcontroller/Pin.h b/shared-bindings/microcontroller/Pin.h index 2d15dd5c58..8762e44127 100644 --- a/shared-bindings/microcontroller/Pin.h +++ b/shared-bindings/microcontroller/Pin.h @@ -30,6 +30,10 @@ #include "common-hal/microcontroller/Pin.h" #include "py/obj.h" +#ifdef MICROPY_HW_NEOPIXEL +extern bool neopixel_in_use; +#endif + // Type object used in Python. Should be shared between ports. extern const mp_obj_type_t mcu_pin_type; From 81223c76bd0c9be22032c09f034dccd84c7c74f7 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Fri, 15 Nov 2019 13:04:25 -0500 Subject: [PATCH 4/4] revert error --- ports/atmel-samd/common-hal/microcontroller/Pin.h | 3 +++ ports/nrf/common-hal/microcontroller/Pin.h | 3 +++ shared-bindings/microcontroller/Pin.h | 4 ---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ports/atmel-samd/common-hal/microcontroller/Pin.h b/ports/atmel-samd/common-hal/microcontroller/Pin.h index 090d7a512a..14887207aa 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Pin.h +++ b/ports/atmel-samd/common-hal/microcontroller/Pin.h @@ -31,6 +31,9 @@ #include "peripherals/samd/pins.h" +#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; diff --git a/ports/nrf/common-hal/microcontroller/Pin.h b/ports/nrf/common-hal/microcontroller/Pin.h index 5a1fd39616..735ed90cca 100644 --- a/ports/nrf/common-hal/microcontroller/Pin.h +++ b/ports/nrf/common-hal/microcontroller/Pin.h @@ -31,6 +31,9 @@ #include "peripherals/nrf/pins.h" +#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; diff --git a/shared-bindings/microcontroller/Pin.h b/shared-bindings/microcontroller/Pin.h index 8762e44127..2d15dd5c58 100644 --- a/shared-bindings/microcontroller/Pin.h +++ b/shared-bindings/microcontroller/Pin.h @@ -30,10 +30,6 @@ #include "common-hal/microcontroller/Pin.h" #include "py/obj.h" -#ifdef MICROPY_HW_NEOPIXEL -extern bool neopixel_in_use; -#endif - // Type object used in Python. Should be shared between ports. extern const mp_obj_type_t mcu_pin_type;