unleashed-firmware/applications/plugins/protoview/app_buffer.h

33 lines
1.4 KiB
C
Raw Normal View History

/* Copyright (C) 2022-2023 Salvatore Sanfilippo -- All Rights Reserved
* See the LICENSE file for information about the license. */
/* Our circular buffer of raw samples, used in order to display
* the signal. */
2023-01-18 19:25:39 +00:00
#define RAW_SAMPLES_NUM \
2048 /* Use a power of two: we take the modulo
of the index quite often to normalize inside
the range, and division is slow. */
typedef struct RawSamplesBuffer {
2023-01-18 19:25:39 +00:00
FuriMutex* mutex;
struct {
2023-01-18 19:25:39 +00:00
uint16_t level : 1;
uint16_t dur : 15;
} samples[RAW_SAMPLES_NUM];
2023-01-18 19:25:39 +00:00
uint32_t idx; /* Current idx (next to write). */
uint32_t total; /* Total samples: same as RAW_SAMPLES_NUM, we provide
this field for a cleaner interface with the user, but
we always use RAW_SAMPLES_NUM when taking the modulo so
the compiler can optimize % as bit masking. */
/* Signal features. */
uint32_t short_pulse_dur; /* Duration of the shortest pulse. */
} RawSamplesBuffer;
2023-01-18 19:25:39 +00:00
RawSamplesBuffer* raw_samples_alloc(void);
void raw_samples_reset(RawSamplesBuffer* s);
void raw_samples_center(RawSamplesBuffer* s, uint32_t offset);
void raw_samples_add(RawSamplesBuffer* s, bool level, uint32_t dur);
void raw_samples_get(RawSamplesBuffer* s, uint32_t idx, bool* level, uint32_t* dur);
void raw_samples_copy(RawSamplesBuffer* dst, RawSamplesBuffer* src);
void raw_samples_free(RawSamplesBuffer* s);