@@ -57,29 +57,15 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
57
57
58
58
pcnt_unit_config (& pcnt_config );
59
59
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
83
69
84
70
pcnt_unit_config (& pcnt_config );
85
71
@@ -112,11 +98,7 @@ mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementa
112
98
int16_t count ;
113
99
pcnt_get_counter_value (self -> unit , & count );
114
100
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 ;
120
102
}
121
103
122
104
void common_hal_rotaryio_incrementalencoder_set_position (rotaryio_incrementalencoder_obj_t * self ,
0 commit comments