#pragma once #include "hardware/pio.h" typedef struct substep_state_t { uint calibration_data[4]; // relative phase sizes uint clocks_per_us; // save the clk_sys frequency in clocks per us uint idle_stop_samples; // after these samples without transitions, assume the encoder is stopped PIO pio; uint sm; uint prev_trans_pos, prev_trans_us; uint prev_step_us; uint prev_low, prev_high; uint idle_stop_sample_count; int speed_2_20; int stopped; int speed; uint position; uint raw_step; } substep_state_t; void substep_init_state(PIO pio, int sm, int pin_a, substep_state_t *state); void substep_update(substep_state_t *state);