8000 Always configure the second PCNT channel. · domdfcoding/circuitpython@319ca85 · GitHub
[go: up one dir, main page]

Skip to content

Commit 319ca85

Browse files
committed
Always configure the second PCNT channel.
1 parent 6d025a2 commit 319ca85

File tree

3 files changed

+11
-33
lines changed

3 files changed

+11
-33
lines changed

locale/circuitpython.pot

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,10 +3126,6 @@ msgstr ""
31263126
msgid "division by zero"
31273127
msgstr ""
31283128

3129-
#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c
3130-
msgid "divisor must be 4"
3131-
msgstr ""
3132-
31333129
#: extmod/ulab/code/numpy/vector.c
31343130
msgid "dtype must be float, or complex"
31353131
msgstr ""

ports/espressif/common-hal/rotaryio/IncrementalEncoder.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,15 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
5757

5858
pcnt_unit_config(&pcnt_config);
5959

60-
if ((self->divisor == 2) || (self->divisor == 1)) {
61-
// Setup channel 1 for divisor=2 or divisor=1
62-
pcnt_config.pulse_gpio_num = pin_b->number; // What was control is now signal
63-
pcnt_config.ctrl_gpio_num = pin_a->number; // What was signal is now control
64-
pcnt_config.channel = PCNT_CHANNEL_1;
65-
// What to do on the positive / negative edge of pulse input?
66-
pcnt_config.pos_mode = PCNT_COUNT_DEC; // Count up on the positive edge
67-
pcnt_config.neg_mode = PCNT_COUNT_INC; // Keep the counter value on the negative edge
68-
// What to do when control input is low or high?
69-
pcnt_config.lctrl_mode = PCNT_MODE_KEEP; // Keep the primary counter mode if low
70-
pcnt_config.hctrl_mode = PCNT_MODE_REVERSE; // Reverse counting direction if high
71-
} else {
72-
// Ensure channel 1 is disabled for divisor=4
73-
pcnt_config.pulse_gpio_num = pin_b->number; // What was control is now signal
74-
pcnt_config.ctrl_gpio_num = pin_a->number; // What was signal is now control
75-
pcnt_config.channel = PCNT_CHANNEL_1;
76-
// What to do on the positive / negative edge of pulse input?
77-
pcnt_config.pos_mode = PCNT_COUNT_DIS; // Disabled
78-
pcnt_config.neg_mode = PCNT_COUNT_DIS; // Disabled
79-
// What to do when control input is low or high?
80-
pcnt_config.lctrl_mode = PCNT_MODE_DISABLE; // Disabled
81-
pcnt_config.hctrl_mode = PCNT_MODE_DISABLE; // Disabled
82-
}
60+
pcnt_config.pulse_gpio_num = pin_b->number; // What was control is now signal
61+
pcnt_config.ctrl_gpio_num = pin_a->number; // What was signal is now control
62+
pcnt_config.channel = PCNT_CHANNEL_1;
63+
// What to do on the positive / negative edge of pulse input?
64+
pcnt_config.pos_mode = PCNT_COUNT_DEC; // Count up on the positive edge
65+
pcnt_config.neg_mode = PCNT_COUNT_INC; // Keep the counter value on the negative edge
66+
// What to do when control input is low or high?
67+
pcnt_config.lctrl_mode = PCNT_MODE_KEEP; // Keep the primary counter mode if low
68+
pcnt_config.hctrl_mode = PCNT_MODE_REVERSE; // Reverse counting direction if high
8369

8470
pcnt_unit_config(&pcnt_config);
8571

@@ -112,11 +98,7 @@ mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementa
11298
int16_t count;
11399
pcnt_get_counter_value(self->unit, &count);
114100

115-
if ((self->divisor == 4) || (self->divisor == 2)) {
116-
return (count / 2) + self->position;
117-
} else {
118-
return (count) + self->position;
119-
}
101+
return (count / self->divisor) + self->position;
120102
}
121103

122104
void common_hal_rotaryio_incrementalencoder_set_position(rotaryio_incrementalencoder_obj_t *self,

shared-bindings/rotaryio/IncrementalEncoder.c

Lines changed: 1 addition & 1 dele 7734 tion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type,
7777
rotaryio_incrementalencoder_obj_t *self = m_new_obj(rotaryio_incrementalencoder_obj_t);
7878
self->base.type = &rotaryio_incrementalencoder_type;
7979

80-
common_hal_rotaryio_incrementalencoder_set_divisor(self, args[ARG_divisor].u_int);
8180
common_hal_rotaryio_incrementalencoder_construct(self, pin_a, pin_b);
81+
common_hal_rotaryio_incrementalencoder_set_divisor(self, args[ARG_divisor].u_int);
8282

8383
return MP_OBJ_FROM_PTR(self);
8484
}

0 commit comments

Comments
 (0)
0