Merge pull request #2290 from hierophect/pin-commonhal-additions
Add pin reset and never reset to common-hal
This commit is contained in:
commit
5d9ac8b1d9
@ -158,6 +158,14 @@ void reset_pin_number(uint8_t pin_number) {
|
|||||||
#endif
|
#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) {
|
void claim_pin(const mcu_pin_obj_t* pin) {
|
||||||
#ifdef MICROPY_HW_NEOPIXEL
|
#ifdef MICROPY_HW_NEOPIXEL
|
||||||
if (pin == MICROPY_HW_NEOPIXEL) {
|
if (pin == MICROPY_HW_NEOPIXEL) {
|
||||||
|
@ -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);
|
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) {
|
void claim_pin(const mcu_pin_obj_t* pin) {
|
||||||
// Set bit in claimed_pins bitmask.
|
// Set bit in claimed_pins bitmask.
|
||||||
claimed_pins[nrf_pin_port(pin->number)] |= 1 << nrf_relative_pin_number(pin->number);
|
claimed_pins[nrf_pin_port(pin->number)] |= 1 << nrf_relative_pin_number(pin->number);
|
||||||
|
@ -72,6 +72,14 @@ void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
|
|||||||
never_reset_pins[pin_port] |= 1<<pin_number;
|
never_reset_pins[pin_port] |= 1<<pin_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
|
||||||
|
never_reset_pin_number(pin->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) {
|
void claim_pin(const mcu_pin_obj_t* pin) {
|
||||||
// Set bit in claimed_pins bitmask.
|
// Set bit in claimed_pins bitmask.
|
||||||
claimed_pins[pin->port] |= 1<<pin->number;
|
claimed_pins[pin->port] |= 1<<pin->number;
|
||||||
|
@ -37,5 +37,7 @@ void assert_pin(mp_obj_t obj, bool none_ok);
|
|||||||
void assert_pin_free(const mcu_pin_obj_t* pin);
|
void assert_pin_free(const mcu_pin_obj_t* pin);
|
||||||
|
|
||||||
bool common_hal_mcu_pin_is_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
|
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H
|
||||||
|
@ -113,7 +113,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
|
|||||||
if (result != PWMOUT_OK) {
|
if (result != PWMOUT_OK) {
|
||||||
self->backlight_inout.base.type = &digitalio_digitalinout_type;
|
self->backlight_inout.base.type = &digitalio_digitalinout_type;
|
||||||
common_hal_digitalio_digitalinout_construct(&self->backlight_inout, backlight_pin);
|
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 {
|
} else {
|
||||||
self->backlight_pwm.base.type = &pulseio_pwmout_type;
|
self->backlight_pwm.base.type = &pulseio_pwmout_type;
|
||||||
common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm);
|
common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm);
|
||||||
|
@ -82,7 +82,7 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t*
|
|||||||
if (busy_pin != NULL) {
|
if (busy_pin != NULL) {
|
||||||
self->busy.base.type = &digitalio_digitalinout_type;
|
self->busy.base.type = &digitalio_digitalinout_type;
|
||||||
common_hal_digitalio_digitalinout_construct(&self->busy, busy_pin);
|
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.
|
// Clear the color memory if it isn't in use.
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "py/gc.h"
|
#include "py/gc.h"
|
||||||
#include "shared-bindings/busio/SPI.h"
|
#include "shared-bindings/busio/SPI.h"
|
||||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||||
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
#include "shared-bindings/microcontroller/__init__.h"
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
#include "shared-bindings/time/__init__.h"
|
#include "shared-bindings/time/__init__.h"
|
||||||
#include "shared-module/displayio/display_core.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;
|
self->reset.base.type = &digitalio_digitalinout_type;
|
||||||
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
|
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
|
||||||
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
|
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);
|
common_hal_displayio_fourwire_reset(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
never_reset_pin_number(command->number);
|
common_hal_never_reset_pin(command);
|
||||||
never_reset_pin_number(chip_select->number);
|
common_hal_never_reset_pin(chip_select);
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self) {
|
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);
|
common_hal_busio_spi_deinit(self->bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_pin_number(self->command.pin->number);
|
common_hal_reset_pin(self->command.pin);
|
||||||
reset_pin_number(self->chip_select.pin->number);
|
common_hal_reset_pin(self->chip_select.pin);
|
||||||
reset_pin_number(self->reset.pin->number);
|
common_hal_reset_pin(self->reset.pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_displayio_fourwire_reset(mp_obj_t obj) {
|
bool common_hal_displayio_fourwire_reset(mp_obj_t obj) {
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "shared-bindings/busio/I2C.h"
|
#include "shared-bindings/busio/I2C.h"
|
||||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||||
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
#include "shared-bindings/microcontroller/__init__.h"
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
#include "shared-bindings/time/__init__.h"
|
#include "shared-bindings/time/__init__.h"
|
||||||
#include "shared-module/displayio/display_core.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;
|
self->reset.base.type = &digitalio_digitalinout_type;
|
||||||
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
|
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
|
||||||
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
|
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);
|
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);
|
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) {
|
bool common_hal_displayio_i2cdisplay_reset(mp_obj_t obj) {
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mphalport.h"
|
#include "mphalport.h"
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
#include "rgb_led_status.h"
|
#include "rgb_led_status.h"
|
||||||
|
|
||||||
#ifdef MICROPY_HW_NEOPIXEL
|
#ifdef MICROPY_HW_NEOPIXEL
|
||||||
@ -117,7 +117,7 @@ void rgb_led_status_init() {
|
|||||||
mp_const_none);
|
mp_const_none);
|
||||||
#else
|
#else
|
||||||
if (!common_hal_busio_spi_deinited(&status_apa102)) {
|
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.
|
// The rgb_led_status_init_in_progress guard will prevent further recursion.
|
||||||
common_hal_busio_spi_deinit(&status_apa102);
|
common_hal_busio_spi_deinit(&status_apa102);
|
||||||
}
|
}
|
||||||
@ -181,11 +181,11 @@ void rgb_led_status_init() {
|
|||||||
|
|
||||||
void reset_status_led() {
|
void reset_status_led() {
|
||||||
#ifdef MICROPY_HW_NEOPIXEL
|
#ifdef MICROPY_HW_NEOPIXEL
|
||||||
reset_pin_number(MICROPY_HW_NEOPIXEL->number);
|
common_hal_reset_pin(MICROPY_HW_NEOPIXEL);
|
||||||
#endif
|
#endif
|
||||||
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
|
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
|
||||||
reset_pin_number(MICROPY_HW_APA102_MOSI->number);
|
common_hal_reset_pin(MICROPY_HW_APA102_MOSI);
|
||||||
reset_pin_number(MICROPY_HW_APA102_SCK->number);
|
common_hal_reset_pin(MICROPY_HW_APA102_SCK);
|
||||||
#endif
|
#endif
|
||||||
#if defined(CP_RGB_STATUS_LED)
|
#if defined(CP_RGB_STATUS_LED)
|
||||||
// TODO: Support sharing status LED with user.
|
// TODO: Support sharing status LED with user.
|
||||||
|
Loading…
Reference in New Issue
Block a user