nrf: switch to shared softencoder implementation
This commit is contained in:
parent
3aec1032f7
commit
d69ca4a8ae
@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common-hal/rotaryio/IncrementalEncoder.h"
|
#include "common-hal/rotaryio/IncrementalEncoder.h"
|
||||||
|
#include "shared-module/rotaryio/IncrementalEncoder.h"
|
||||||
#include "nrfx_gpiote.h"
|
#include "nrfx_gpiote.h"
|
||||||
|
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
@ -44,25 +45,7 @@ static void _intr_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
|||||||
uint8_t new_state = nrf_gpio_pin_read(self->pin_a);
|
uint8_t new_state = nrf_gpio_pin_read(self->pin_a);
|
||||||
new_state = (new_state << 1) + (new_state ^ nrf_gpio_pin_read(self->pin_b));
|
new_state = (new_state << 1) + (new_state ^ nrf_gpio_pin_read(self->pin_b));
|
||||||
|
|
||||||
uint8_t change = (new_state - self->state) & 0x03;
|
shared_module_softencoder_state_update(self, new_state);
|
||||||
if (change == 1) {
|
|
||||||
self->quarter++;
|
|
||||||
} else if (change == 3) {
|
|
||||||
self->quarter--;
|
|
||||||
}
|
|
||||||
// ignore other state transitions
|
|
||||||
|
|
||||||
self->state = new_state;
|
|
||||||
|
|
||||||
// logic from the atmel-samd port: provides some damping and scales movement
|
|
||||||
// down by 4:1.
|
|
||||||
if (self->quarter >= 4) {
|
|
||||||
self->position++;
|
|
||||||
self->quarter = 0;
|
|
||||||
} else if (self->quarter <= -4) {
|
|
||||||
self->position--;
|
|
||||||
self->quarter = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencoder_obj_t *self,
|
void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencoder_obj_t *self,
|
||||||
@ -110,12 +93,3 @@ void common_hal_rotaryio_incrementalencoder_deinit(rotaryio_incrementalencoder_o
|
|||||||
self->pin_a = NO_PIN;
|
self->pin_a = NO_PIN;
|
||||||
self->pin_b = NO_PIN;
|
self->pin_b = NO_PIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementalencoder_obj_t *self) {
|
|
||||||
return self->position;
|
|
||||||
}
|
|
||||||
|
|
||||||
void common_hal_rotaryio_incrementalencoder_set_position(rotaryio_incrementalencoder_obj_t *self,
|
|
||||||
mp_int_t new_position) {
|
|
||||||
self->position = new_position;
|
|
||||||
}
|
|
||||||
|
@ -35,8 +35,8 @@ typedef struct {
|
|||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
uint8_t pin_a;
|
uint8_t pin_a;
|
||||||
uint8_t pin_b;
|
uint8_t pin_b;
|
||||||
uint8_t state;
|
int8_t quarter_count : 4;
|
||||||
int8_t quarter;
|
uint8_t state : 4;
|
||||||
mp_int_t position;
|
mp_int_t position;
|
||||||
} rotaryio_incrementalencoder_obj_t;
|
} rotaryio_incrementalencoder_obj_t;
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ CIRCUITPY_RTC ?= 1
|
|||||||
CIRCUITPY_FREQUENCYIO = 0
|
CIRCUITPY_FREQUENCYIO = 0
|
||||||
|
|
||||||
CIRCUITPY_RGBMATRIX ?= 1
|
CIRCUITPY_RGBMATRIX ?= 1
|
||||||
|
CIRCUITPY_ROTARYIO_SOFTENCODER = 1
|
||||||
CIRCUITPY_FRAMEBUFFERIO ?= 1
|
CIRCUITPY_FRAMEBUFFERIO ?= 1
|
||||||
|
|
||||||
CIRCUITPY_COUNTIO = 0
|
CIRCUITPY_COUNTIO = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user