Skip to content

File dac.h

File List > external-docs > libDaisy > src > per > dac.h

Go to the documentation of this file

Source Code

#pragma once
#ifndef DSY_DAC_H
#define DSY_DAC_H
#include "stm32h7xx_hal.h"
#include "daisy_core.h"

namespace daisy
{
class DacHandle
{
  public:
    enum class Result
    {
        OK,
        ERR,
    };

    enum class Channel
    {
        ONE,
        TWO,
        BOTH,
    };

    enum class Mode
    {
        POLLING,
        DMA,
    };

    enum class BitDepth
    {
        BITS_8,
        BITS_12
    };

    enum class BufferState
    {
        ENABLED,
        DISABLED,
    };

    struct Config
    {
        uint32_t target_samplerate;

        Channel     chn;
        Mode        mode;
        BitDepth    bitdepth;
        BufferState buff_state;
    };

    DacHandle() : pimpl_(nullptr) {}
    DacHandle(const DacHandle &other) = default;
    DacHandle &operator=(const DacHandle &other) = default;

    typedef void (*DacCallback)(uint16_t **out, size_t size);

    Result        Init(const Config &config);
    const Config &GetConfig() const;

    Result Start(uint16_t *buffer, size_t size, DacCallback cb);

    Result
    Start(uint16_t *buffer_1, uint16_t *buffer_2, size_t size, DacCallback cb);

    Result Stop();

    Result WriteValue(Channel chn, uint16_t val);

    class Impl;

  private:
    Impl *pimpl_;
};
} // namespace daisy

#endif