34 #if defined(PIOS_INCLUDE_DAC_ANNUNCIATOR)
39 struct annuncdac_dev_s {
41 #define ANNUNCDAC_DEV_MAGIC 0x43414441 // 'ADAC'
51 uintptr_t tx_out_context;
56 static bool PIOS_ANNUNCDAC_cb(
void *ctx, uint16_t *buf,
int len);
60 return (annuncdac_dev->magic == ANNUNCDAC_DEV_MAGIC);
73 if (!annuncdac_dev)
return -1;
75 *annuncdac_dev = (
struct annuncdac_dev_s) {
76 .magic = ANNUNCDAC_DEV_MAGIC,
80 *annuncdac_id = annuncdac_dev;
83 PIOS_ANNUNCDAC_cb, annuncdac_dev);
89 uint16_t freq,
int start_mag,
int stop_mag) {
90 int mag_span = stop_mag - start_mag;
92 for (
int i=0;
i < len;
i++) {
93 dev->phase_accum += freq;
95 int magnitude = (mag_span *
i + len / 2) / len;
96 magnitude += start_mag;
98 uint16_t result = 32768 +
99 (magnitude *
sin_approx(dev->phase_accum >> 1) >> 2);
101 buf[
i] = result & 0xFFF0;
105 #define ANNUNC_FREQ 1911
106 static bool PIOS_ANNUNCDAC_cb(
void *ctx, uint16_t *buf,
int len)
117 switch (dev->history & 3) {
120 for (
int i = 0;
i < len;
i++) {
125 FillBuf(dev, buf, len, ANNUNC_FREQ, 1, 6);
129 FillBuf(dev, buf, len, ANNUNC_FREQ, 6, 1);
133 FillBuf(dev, buf, len, ANNUNC_FREQ, 6, 6);
Main PiOS header to include all the compiled in PiOS options.
int32_t PIOS_ANNUNCDAC_Init(annuncdac_dev_t *annuncdac_id, dac_dev_t dac)
Allocate and initialise ANNUNCDAC device.
bool PIOS_DAC_install_callback(dac_dev_t dev, uint8_t priority, fill_dma_cb cb, void *ctx)
#define PIOS_DEBUG_Assert(test)
void * PIOS_malloc(size_t size)
static struct flyingpicmd_cfg_fa cfg
void PIOS_ANNUNCDAC_SetValue(annuncdac_dev_t dev, bool active, bool value)
Set whether we should be beeping.
static int16_t sin_approx(int32_t x)
Fast approximation of sine; 3rd order taylor expansion. Based on http://www.coranac.com/2009/07/sines/.
struct dac_dev_s * dac_dev_t
struct annuncdac_dev_s * annuncdac_dev_t
#define PIOS_Assert(test)
uint16_t(* pios_com_callback)(uintptr_t context, uint8_t *buf, uint16_t buf_len, uint16_t *headroom, bool *task_woken)