2022-05-24 14:00:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <furi_hal_gpio.h>
|
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2023-05-09 00:55:17 +00:00
|
|
|
/* helper for easier signal generation */
|
|
|
|
#define DIGITAL_SIGNAL_MS(x) ((x)*100000000UL)
|
|
|
|
#define DIGITAL_SIGNAL_US(x) ((x)*100000UL)
|
|
|
|
#define DIGITAL_SIGNAL_NS(x) ((x)*100UL)
|
|
|
|
#define DIGITAL_SIGNAL_PS(x) ((x) / 10UL)
|
|
|
|
|
|
|
|
/* using an anonymous type for the internals */
|
|
|
|
typedef struct DigitalSignalInternals DigitalSignalInternals;
|
|
|
|
|
|
|
|
/* and a public one for accessing user-side fields */
|
|
|
|
typedef struct DigitalSignal {
|
2022-05-24 14:00:15 +00:00
|
|
|
bool start_level;
|
|
|
|
uint32_t edge_cnt;
|
|
|
|
uint32_t edges_max_cnt;
|
2022-07-03 14:51:50 +00:00
|
|
|
uint32_t* edge_timings;
|
2023-05-09 00:55:17 +00:00
|
|
|
uint32_t* reload_reg_buff; /* internal, but used by unit tests */
|
|
|
|
DigitalSignalInternals* internals;
|
2022-05-24 14:00:15 +00:00
|
|
|
} DigitalSignal;
|
|
|
|
|
2023-05-09 00:55:17 +00:00
|
|
|
typedef struct DigitalSequence DigitalSequence;
|
|
|
|
|
2022-05-24 14:00:15 +00:00
|
|
|
DigitalSignal* digital_signal_alloc(uint32_t max_edges_cnt);
|
|
|
|
|
|
|
|
void digital_signal_free(DigitalSignal* signal);
|
|
|
|
|
2023-05-09 00:55:17 +00:00
|
|
|
void digital_signal_add(DigitalSignal* signal, uint32_t ticks);
|
|
|
|
|
|
|
|
void digital_signal_add_pulse(DigitalSignal* signal, uint32_t ticks, bool level);
|
|
|
|
|
2022-05-24 14:00:15 +00:00
|
|
|
bool digital_signal_append(DigitalSignal* signal_a, DigitalSignal* signal_b);
|
|
|
|
|
2022-07-03 14:51:50 +00:00
|
|
|
void digital_signal_prepare_arr(DigitalSignal* signal);
|
|
|
|
|
2022-05-24 14:00:15 +00:00
|
|
|
bool digital_signal_get_start_level(DigitalSignal* signal);
|
|
|
|
|
|
|
|
uint32_t digital_signal_get_edges_cnt(DigitalSignal* signal);
|
|
|
|
|
2022-07-03 14:51:50 +00:00
|
|
|
uint32_t digital_signal_get_edge(DigitalSignal* signal, uint32_t edge_num);
|
2022-05-24 14:00:15 +00:00
|
|
|
|
2022-07-03 14:51:50 +00:00
|
|
|
void digital_signal_send(DigitalSignal* signal, const GpioPin* gpio);
|
2022-09-14 16:11:38 +00:00
|
|
|
|
2023-05-09 00:55:17 +00:00
|
|
|
DigitalSequence* digital_sequence_alloc(uint32_t size, const GpioPin* gpio);
|
|
|
|
|
|
|
|
void digital_sequence_free(DigitalSequence* sequence);
|
|
|
|
|
|
|
|
void digital_sequence_set_signal(
|
|
|
|
DigitalSequence* sequence,
|
|
|
|
uint8_t signal_index,
|
|
|
|
DigitalSignal* signal);
|
|
|
|
|
|
|
|
void digital_sequence_set_sendtime(DigitalSequence* sequence, uint32_t send_time);
|
|
|
|
|
|
|
|
void digital_sequence_add(DigitalSequence* sequence, uint8_t signal_index);
|
|
|
|
|
|
|
|
bool digital_sequence_send(DigitalSequence* sequence);
|
|
|
|
|
|
|
|
void digital_sequence_clear(DigitalSequence* sequence);
|
|
|
|
|
|
|
|
void digital_sequence_timebase_correction(DigitalSequence* sequence, float factor);
|
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|