aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/source/periph/dac.hpp
blob: f4266c732fb9a0dd6f0115e23db98560b7ead1d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
 * @file dac.hpp
 * @brief Manages signal creation using the DAC.
 *
 * Copyright (C) 2023 Clyne Sullivan
 *
 * Distributed under the GNU GPL v3 or later. You should have received a copy of
 * the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef STMDSP_DAC_HPP_
#define STMDSP_DAC_HPP_

#include "hal.h"
#undef DAC

class DAC
{
public:
    /**
     * Initializes DAC output pins and peripheral.
     */
    static void begin();

    /**
     * Begins continuous DAC conversion on the given channel, running at the
     * current SClock sampling rate.
     * @param channel Selected output channel (0 = sig. out, 1 = sig. gen.).
     * @param buffer Buffer of sample data to output.
     * @param count Number of samples in sample buffer.
     */
    static void start(int channel, dacsample_t *buffer, size_t count);

    /**
     * Stops DAC conversion on the given channel.
     */
    static void stop(int channel);

    /**
     * Determines if signal generator needs more sample data for streamed
     * output (i.e. audio file streaming).
     * @return >0 if samples needed, <0 on initial run.
     */
    static int sigGenWantsMore();

    /**
     * Returns true if signal generator is currently running.
     */
    static int isSigGenRunning();

private:
    static DACDriver *m_driver[2];

    static const DACConfig m_config;
    static const DACConversionGroup m_group_config;
};

#endif // STMDSP_DAC_HPP_