Loading...
Searching...
No Matches
dac_dds.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Beuth Hochschule für Technik Berlin
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
37
38#include <stddef.h>
39#include <stdint.h>
40#include <limits.h>
41
42#include "periph/dac.h"
43#include "periph/timer.h"
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
57typedef void (*dac_dds_cb_t)(void *arg);
58
63typedef struct {
66 uint32_t timer_hz;
68
69
73typedef uint8_t dac_dds_t;
74
78#ifndef DAC_FLAG_8BIT
79#define DAC_FLAG_8BIT (0x0)
80#endif
81
85#ifndef DAC_FLAG_16BIT
86#define DAC_FLAG_16BIT (0x1)
87#endif
88
101void dac_dds_init(dac_dds_t dac, uint16_t sample_rate, uint8_t flags,
102 dac_dds_cb_t cb, void *cb_arg);
103
119void dac_dds_set_cb(dac_dds_t dac, dac_dds_cb_t cb, void *cb_arg);
120
146bool dac_dds_play(dac_dds_t dac, const void *buf, size_t len);
147
154
155#ifdef __cplusplus
156}
157#endif
158
DAC peripheral driver interface definition.
Low-level timer peripheral driver interface definitions.
void dac_dds_init(dac_dds_t dac, uint16_t sample_rate, uint8_t flags, dac_dds_cb_t cb, void *cb_arg)
Initialize a DAC for playing audio samples A user defined callback can be provided that will be calle...
void dac_dds_stop(dac_dds_t dac)
Stop playback of the current sample buffer.
void(* dac_dds_cb_t)(void *arg)
The callback that will be called when the end of the current sample buffer has been reached.
Definition dac_dds.h:57
bool dac_dds_play(dac_dds_t dac, const void *buf, size_t len)
Play a buffer of (audio) samples on a DAC.
uint8_t dac_dds_t
Index of the DAC DDS channel.
Definition dac_dds.h:73
void dac_dds_set_cb(dac_dds_t dac, dac_dds_cb_t cb, void *cb_arg)
Change the 'buffer done' callback.
uint_fast8_t dac_t
Define default DAC type identifier.
Definition dac.h:63
uint_fast8_t tim_t
Default timer type.
Definition timer.h:67
Configuration struct for a DAC DDS channel.
Definition dac_dds.h:63
dac_t dac
The DAC used for playing the sample.
Definition dac_dds.h:64
uint32_t timer_hz
Timer frequency, must be at least 2x sample rate.
Definition dac_dds.h:66
tim_t timer
Timer used for periodic DAC events.
Definition dac_dds.h:65