mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-30 16:29:12 +00:00
e1c6e78b2e
* added DigitalSequence to chain multiple DigitalSignals added PulseReader for hardware assisted digital signal sampling * added send_time option to start a signal at a specific DWT->CYCCNT value * fixed linter errors and undone function renaming * fixed renaming * flagged functions in api_symbols.csv * allow gpio field to stay uninitialized in digital_signal_prepare_arr() * fix test cases to match (expected) implementation * pulse_reader: build as static library Signed-off-by: g3gg0.de <git@g3gg0.de> * fix starting level detection in pulse_reader * added unit test for pulse_reader * change pulse reader test timings to 1, 10 and 100 ms * fine tuned timings for pulse_reader test * pulse_reader_stop now deinits GPIO as recommended by @gornekich * ran format_py * pulse_reader: remove from API, allow to link with faps Signed-off-by: g3gg0.de <git@g3gg0.de> * remove unit test for pulse_reader again * pulse_reader: add call to set GPIO pull direction * make structures private, add C implementation of digital_signal_update_dma() * digital_signal/pulse_reader: allow parameters for free to be NULL * digital_signal: show unoptimized and optimized code for digital_signal_update_dma() next to each other * pulse_reader: further optimize assembly code * digital_signal: reduce code complexity of digital_signal_update_dma() by only reconfiguring DMA2 * digital_signal: remove assembly code, limiting the performance but increasing portability * added recovery if the timer already expired * digital_signal: fix memory leak * digital_signal: keep lock until all DMA transfers have finished * DigitalSequence: fix issues with concatenation of same levels and spurious bit flips * DigitalSignal: use cyclic DMA buffer for sequences * update api_symbols.csv * Update api_symbols.csv for f18 target * Patches from @gornekich to fix linter warnings. * Remove some redundant if checks * Remove some magic numbers and reformat. * Remove forced terminating edge. Signed-off-by: g3gg0.de <git@g3gg0.de> Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: Tiernan Messmer <tiernan.messmer@gmail.com> Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
75 lines
2.1 KiB
C
75 lines
2.1 KiB
C
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
|
|
#include <furi_hal_gpio.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* 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 {
|
|
bool start_level;
|
|
uint32_t edge_cnt;
|
|
uint32_t edges_max_cnt;
|
|
uint32_t* edge_timings;
|
|
uint32_t* reload_reg_buff; /* internal, but used by unit tests */
|
|
DigitalSignalInternals* internals;
|
|
} DigitalSignal;
|
|
|
|
typedef struct DigitalSequence DigitalSequence;
|
|
|
|
DigitalSignal* digital_signal_alloc(uint32_t max_edges_cnt);
|
|
|
|
void digital_signal_free(DigitalSignal* signal);
|
|
|
|
void digital_signal_add(DigitalSignal* signal, uint32_t ticks);
|
|
|
|
void digital_signal_add_pulse(DigitalSignal* signal, uint32_t ticks, bool level);
|
|
|
|
bool digital_signal_append(DigitalSignal* signal_a, DigitalSignal* signal_b);
|
|
|
|
void digital_signal_prepare_arr(DigitalSignal* signal);
|
|
|
|
bool digital_signal_get_start_level(DigitalSignal* signal);
|
|
|
|
uint32_t digital_signal_get_edges_cnt(DigitalSignal* signal);
|
|
|
|
uint32_t digital_signal_get_edge(DigitalSignal* signal, uint32_t edge_num);
|
|
|
|
void digital_signal_send(DigitalSignal* signal, const GpioPin* gpio);
|
|
|
|
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);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|