Files
RadioPhotonic_PCB_software/App/Services/sweep.h
T
2026-10-09 19:45:27 +03:00

58 lines
1.4 KiB
C

/**
* @file sweep.h
* @brief Hardware-agnostic periodic staircase sweep between two output codes.
*
* The output steps from `min_code` up to `max_code` (inclusive) every step
* period, then returns to `min_code` and holds it for an extra pause before
* the next sweep starts.
*/
#ifndef SWEEP_H
#define SWEEP_H
#include <stdbool.h>
#include <stdint.h>
/**
* @brief Host-supplied sweep parameters.
*/
typedef struct sweep_config_t {
uint16_t min_code;
uint16_t max_code;
uint16_t step_code;
uint16_t step_period_us;
uint16_t pause_ms;
} sweep_config_t;
/**
* @brief Sweep state advanced from the periodic tick interrupt.
*/
typedef struct sweep_t {
uint8_t enabled;
uint16_t min_code;
uint16_t max_code;
uint16_t step_code;
uint32_t step_ticks;
uint32_t pause_ticks;
uint32_t next_code;
uint32_t countdown_ticks;
} sweep_t;
/**
* @brief Validate the configuration and start sweeping from `min_code` on the next tick.
*
* @return false (sweep left stopped) if bounds, step or period are invalid.
*/
bool sweep_start(sweep_t *sweep, const sweep_config_t *config, uint32_t tick_us);
void sweep_stop(sweep_t *sweep);
/**
* @brief Advance the sweep by one tick.
*
* @return true when `*out_code` holds a new value that must be written to the output.
*/
bool sweep_tick(sweep_t *sweep, uint16_t *out_code);
#endif /* SWEEP_H */