Skip to content

Commit 7171990

Browse files
committed
Adapt for feedback and hack around pIRkey size constraint.
1 parent f386144 commit 7171990

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

ports/atmel-samd/common-hal/busio/I2C.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141

4242
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
4343
const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) {
44+
#ifdef PIRKEY_M0
45+
mp_raise_NotImplementedError("Not enough pins available");
46+
return;
47+
#endif
4448
Sercom* sercom = NULL;
4549
uint8_t sercom_index;
4650
uint32_t sda_pinmux = 0;

ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementa
9696
return self->position;
9797
}
9898

99+
void common_hal_rotaryio_incrementalencoder_set_position(rotaryio_incrementalencoder_obj_t* self,
100+
mp_int_t new_position) {
101+
self->position = new_position;
102+
}
103+
99104
void incrementalencoder_interrupt_handler(uint8_t channel) {
100105
rotaryio_incrementalencoder_obj_t* self = get_eic_channel_data(channel);
101106

ports/atmel-samd/peripherals/samd21/events.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ void init_event_channel_interrupt(uint8_t channel, uint8_t gclk, uint8_t generat
7474
EVSYS_CHANNEL_EVGEN(generator) |
7575
EVSYS_CHANNEL_PATH_RESYNCHRONIZED |
7676
EVSYS_CHANNEL_EDGSEL_RISING_EDGE;
77-
if (channel > 7) {
78-
uint8_t value = 1 << (channel - 7);
77+
if (channel >= 8) {
78+
uint8_t value = 1 << (channel - 8);
7979
EVSYS->INTFLAG.reg = EVSYS_INTFLAG_EVDp8(value) | EVSYS_INTFLAG_OVRp8(value);
8080
EVSYS->INTENSET.reg = EVSYS_INTENSET_EVDp8(value) | EVSYS_INTENSET_OVRp8(value);
8181
} else {
@@ -87,8 +87,8 @@ void init_event_channel_interrupt(uint8_t channel, uint8_t gclk, uint8_t generat
8787

8888
bool event_interrupt_active(uint8_t channel) {
8989
bool active = false;
90-
if (channel > 7) {
91-
uint8_t value = 1 << (channel - 7);
90+
if (channel >= 8) {
91+
uint8_t value = 1 << (channel - 8);
9292
active = (EVSYS->INTFLAG.reg & EVSYS_INTFLAG_EVDp8(value)) != 0;
9393
// Only clear if we know its active, otherwise there is the possibility it becomes active
9494
// after we check but before we clear.
@@ -107,8 +107,8 @@ bool event_interrupt_active(uint8_t channel) {
107107

108108
bool event_interrupt_overflow(uint8_t channel) {
109109
bool overflow = false;
110-
if (channel > 7) {
111-
uint8_t value = 1 << (channel - 7);
110+
if (channel >= 8) {
111+
uint8_t value = 1 << (channel - 8);
112112
overflow = (EVSYS->INTFLAG.reg & EVSYS_INTFLAG_OVRp8(value)) != 0;
113113
} else {
114114
uint8_t value = 1 << channel;

shared-bindings/rotaryio/IncrementalEncoder.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
//| .. currentmodule:: rotaryio
3838
//|
39-
//| :class:`IncrementalEncoder` -- Read the position of the incremental encoder
40-
//| ============================================================================
39+
//| :class:`IncrementalEncoder` -- Track the relative position of an incremental encoder
40+
//| ====================================================================================
4141
//|
4242
//| IncrementalEncoder determines the relative rotational position based on two series of pulses.
4343
//|
@@ -47,8 +47,8 @@
4747
//| state of an incremental rotary encoder (also known as a quadrature encoder.) Position is
4848
//| relative to the position when the object is contructed.
4949
//|
50-
//| :param ~microcontroller.Pin pin: First pin to read pulses from.
51-
//| :param ~microcontroller.Pin pin: Second pin to read pulses from.
50+
//| :param ~microcontroller.Pin pin_a: First pin to read pulses from.
51+
//| :param ~microcontroller.Pin pin_b: Second pin to read pulses from.
5252
//|
5353
//| For example::
5454
//|
@@ -94,7 +94,7 @@ STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type,
9494

9595
//| .. method:: deinit()
9696
//|
97-
//| Deinitialises the IncrementalEncoder and releases any hardware resources for reuse.
97+
//| Deinitializes the IncrementalEncoder and releases any hardware resources for reuse.
9898
//|
9999
STATIC mp_obj_t rotaryio_incrementalencoder_deinit(mp_obj_t self_in) {
100100
rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -135,10 +135,19 @@ STATIC mp_obj_t rotaryio_incrementalencoder_obj_get_position(mp_obj_t self_in) {
135135
}
136136
MP_DEFINE_CONST_FUN_OBJ_1(rotaryio_incrementalencoder_get_position_obj, rotaryio_incrementalencoder_obj_get_position);
137137

138+
STATIC mp_obj_t rotaryio_incrementalencoder_obj_set_position(mp_obj_t self_in, mp_obj_t new_position) {
139+
rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in);
140+
raise_error_if_deinited(common_hal_rotaryio_incrementalencoder_deinited(self));
141+
142+
common_hal_rotaryio_incrementalencoder_set_position(self, mp_obj_get_int(new_position));
143+
return mp_const_none;
144+
}
145+
MP_DEFINE_CONST_FUN_OBJ_2(rotaryio_incrementalencoder_set_position_obj, rotaryio_incrementalencoder_obj_set_position);
146+
138147
const mp_obj_property_t rotaryio_incrementalencoder_position_obj = {
139148
.base.type = &mp_type_property,
140149
.proxy = {(mp_obj_t)&rotaryio_incrementalencoder_get_position_obj,
141-
(mp_obj_t)&mp_const_none_obj,
150+
(mp_obj_t)&rotaryio_incrementalencoder_set_position_obj,
142151
(mp_obj_t)&mp_const_none_obj},
143152
};
144153

shared-bindings/rotaryio/IncrementalEncoder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ extern void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementa
3737
extern void common_hal_rotaryio_incrementalencoder_deinit(rotaryio_incrementalencoder_obj_t* self);
3838
extern bool common_hal_rotaryio_incrementalencoder_deinited(rotaryio_incrementalencoder_obj_t* self);
3939
extern mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementalencoder_obj_t* self);
40+
extern void common_hal_rotaryio_incrementalencoder_set_position(rotaryio_incrementalencoder_obj_t* self,
41+
mp_int_t new_position);
4042

4143
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ROTARYIO_INCREMENTALENCODER_H

0 commit comments

Comments
 (0)