pulse_counter_ulp: only read valid bits of ulp_edge_count

This commit is contained in:
brisk 2024-07-13 18:29:04 +09:30
parent bd8858e053
commit 7cd5bad1c2
2 changed files with 3 additions and 2 deletions

View file

@ -64,6 +64,7 @@ bool UlpPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) {
* *
* Note that the ULP reads only the lower 16 bits of these variables. * Note that the ULP reads only the lower 16 bits of these variables.
*/ */
ulp_edge_count = 0;
ulp_debounce_counter = 3; ulp_debounce_counter = 3;
ulp_debounce_max_count = 3; ulp_debounce_max_count = 3;
ulp_next_edge = 0; ulp_next_edge = 0;
@ -91,7 +92,7 @@ bool UlpPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) {
pulse_counter_t UlpPulseCounterStorage::read_raw_value() { pulse_counter_t UlpPulseCounterStorage::read_raw_value() {
// TODO count edges separately // TODO count edges separately
uint32_t count = ulp_edge_count; auto count = static_cast<pulse_counter_t>(ulp_edge_count);
ulp_edge_count = 0; ulp_edge_count = 0;
return count; return count;
} }

View file

@ -15,7 +15,7 @@ namespace pulse_counter_ulp {
enum class CountMode { disable = 0, increment = 1, decrement = -1 }; enum class CountMode { disable = 0, increment = 1, decrement = -1 };
using pulse_counter_t = int32_t; using pulse_counter_t = int16_t;
using timestamp_t = int64_t; using timestamp_t = int64_t;
struct UlpPulseCounterStorage { struct UlpPulseCounterStorage {