Skip to content

Commit 5d9ac8b

Browse files
authored
Merge pull request #2290 from hierophect/pin-commonhal-additions
Add pin reset and never reset to common-hal
2 parents f3038e5 + 81223c7 commit 5d9ac8b

File tree

9 files changed

+43
-15
lines changed

9 files changed

+43
-15
lines changed

ports/atmel-samd/common-hal/microcontroller/Pin.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ void reset_pin_number(uint8_t pin_number) {
158158
#endif
159159
}
160160

161+
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
162+
never_reset_pin_number(pin->number);
163+
}
164+
165+
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
166+
reset_pin_number(pin->number);
167+
}
168+
161169
void claim_pin(const mcu_pin_obj_t* pin) {
162170
#ifdef MICROPY_HW_NEOPIXEL
163171
if (pin == MICROPY_HW_NEOPIXEL) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ void never_reset_pin_number(uint8_t pin_number) {
125125
never_reset_pins[nrf_pin_port(pin_number)] |= 1 << nrf_relative_pin_number(pin_number);
126126
}
127127

128+
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
129+
never_reset_pin_number(pin->number);
130+
}
131+
132+
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
133+
reset_pin_number(pin->number);
134+
}
135+
128136
void claim_pin(const mcu_pin_obj_t* pin) {
129137
// Set bit in claimed_pins bitmask.
130138
claimed_pins[nrf_pin_port(pin->number)] |= 1 << nrf_relative_pin_number(pin->number);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
7272
never_reset_pins[pin_port] |= 1<<pin_number;
7373
}
7474

75+
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
76+
never_reset_pin_number(pin->port, pin->number);
77+
}
78+
79+
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
80+
reset_pin_number(pin->port, pin->number);
81+
}
82+
7583
void claim_pin(const mcu_pin_obj_t* pin) {
7684
// Set bit in claimed_pins bitmask.
7785
claimed_pins[pin->port] |= 1<<pin->number;

shared-bindings/microcontroller/Pin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ void assert_pin(mp_obj_t obj, bool none_ok);
3737
void assert_pin_free(const mcu_pin_obj_t* pin);
3838

3939
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin);
40+
void common_hal_never_reset_pin(const mcu_pin_obj_t* pin);
41+
void common_hal_reset_pin(const mcu_pin_obj_t* pin);
4042

4143
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H

shared-module/displayio/Display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
113113
if (result != PWMOUT_OK) {
114114
self->backlight_inout.base.type = &digitalio_digitalinout_type;
115115
common_hal_digitalio_digitalinout_construct(&self->backlight_inout, backlight_pin);
116-
never_reset_pin_number(backlight_pin->number);
116+
common_hal_never_reset_pin(backlight_pin);
117117
} else {
118118
self->backlight_pwm.base.type = &pulseio_pwmout_type;
119119
common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm);

shared-module/displayio/EPaperDisplay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t*
8282
if (busy_pin != NULL) {
8383
self->busy.base.type = &digitalio_digitalinout_type;
8484
common_hal_digitalio_digitalinout_construct(&self->busy, busy_pin);
85-
never_reset_pin_number(busy_pin->number);
85+
common_hal_never_reset_pin(busy_pin);
8686
}
8787

8888
// Clear the color memory if it isn't in use.

shared-module/displayio/FourWire.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "py/gc.h"
3232
#include "shared-bindings/busio/SPI.h"
3333
#include "shared-bindings/digitalio/DigitalInOut.h"
34+
#include "shared-bindings/microcontroller/Pin.h"
3435
#include "shared-bindings/microcontroller/__init__.h"
3536
#include "shared-bindings/time/__init__.h"
3637
#include "shared-module/displayio/display_core.h"
@@ -61,22 +62,22 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
6162
self->reset.base.type = &digitalio_digitalinout_type;
6263
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
6364
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
64-
never_reset_pin_number(reset->number);
65+
common_hal_never_reset_pin(reset);
6566
common_hal_displayio_fourwire_reset(self);
6667
}
6768

68-
never_reset_pin_number(command->number);
69-
never_reset_pin_number(chip_select->number);
69+
common_hal_never_reset_pin(command);
70+
common_hal_never_reset_pin(chip_select);
7071
}
7172

7273
void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self) {
7374
if (self->bus == &self->inline_bus) {
7475
common_hal_busio_spi_deinit(self->bus);
7576
}
7677

77-
reset_pin_number(self->command.pin->number);
78-
reset_pin_number(self->chip_select.pin->number);
79-
reset_pin_number(self->reset.pin->number);
78+
common_hal_reset_pin(self->command.pin);
79+
common_hal_reset_pin(self->chip_select.pin);
80+
common_hal_reset_pin(self->reset.pin);
8081
}
8182

8283
bool common_hal_displayio_fourwire_reset(mp_obj_t obj) {

shared-module/displayio/I2CDisplay.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "py/runtime.h"
3434
#include "shared-bindings/busio/I2C.h"
3535
#include "shared-bindings/digitalio/DigitalInOut.h"
36+
#include "shared-bindings/microcontroller/Pin.h"
3637
#include "shared-bindings/microcontroller/__init__.h"
3738
#include "shared-bindings/time/__init__.h"
3839
#include "shared-module/displayio/display_core.h"
@@ -48,7 +49,7 @@ void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self,
4849
self->reset.base.type = &digitalio_digitalinout_type;
4950
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
5051
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
51-
never_reset_pin_number(reset->number);
52+
common_hal_never_reset_pin(reset);
5253
common_hal_displayio_i2cdisplay_reset(self);
5354
}
5455

@@ -72,7 +73,7 @@ void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) {
7273
common_hal_busio_i2c_deinit(self->bus);
7374
}
7475

75-
reset_pin_number(self->reset.pin->number);
76+
common_hal_reset_pin(self->reset.pin);
7677
}
7778

7879
bool common_hal_displayio_i2cdisplay_reset(mp_obj_t obj) {

supervisor/shared/rgb_led_status.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
#include "mphalport.h"
28-
#include "common-hal/microcontroller/Pin.h"
28+
#include "shared-bindings/microcontroller/Pin.h"
2929
#include "rgb_led_status.h"
3030

3131
#ifdef MICROPY_HW_NEOPIXEL
@@ -117,7 +117,7 @@ void rgb_led_status_init() {
117117
mp_const_none);
118118
#else
119119
if (!common_hal_busio_spi_deinited(&status_apa102)) {
120-
// This may call us recursively if reset_pin_number() is called,
120+
// This may call us recursively if common_hal_reset_pin() is called,
121121
// The rgb_led_status_init_in_progress guard will prevent further recursion.
122122
common_hal_busio_spi_deinit(&status_apa102);
123123
}
@@ -181,11 +181,11 @@ void rgb_led_status_init() {
181181

182182
void reset_status_led() {
183183
#ifdef MICROPY_HW_NEOPIXEL
184-
reset_pin_number(MICROPY_HW_NEOPIXEL->number);
184+
common_hal_reset_pin(MICROPY_HW_NEOPIXEL);
185185
#endif
186186
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
187-
reset_pin_number(MICROPY_HW_APA102_MOSI->number);
188-
reset_pin_number(MICROPY_HW_APA102_SCK->number);
187+
common_hal_reset_pin(MICROPY_HW_APA102_MOSI);
188+
common_hal_reset_pin(MICROPY_HW_APA102_SCK);
189189
#endif
190190
#if defined(CP_RGB_STATUS_LED)
191191
// TODO: Support sharing status LED with user.

0 commit comments

Comments
 (0)