Skip to content

File codec_wm8731.h

File List > dev > codec_wm8731.h

Go to the documentation of this file

Source Code

#pragma once
#ifndef DSY_CODEC_WM8731_H
#define DSY_CODEC_WM8731_H
#include "per/i2c.h"

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

    struct Config
    {
        enum class Format
        {
            MSB_FIRST_RJ = 0x00,
            MSB_FIRST_LJ = 0x01,
            I2S          = 0x02,
            DSP          = 0x03,
        };

        enum class WordLength
        {
            BITS_16 = (0x00 << 2),
            BITS_20 = (0x01 << 2),
            BITS_24 = (0x02 << 2),
            BITS_32 = (0x03 << 2),
        };

        bool mcu_is_master;

        bool lr_swap;

        bool csb_pin_state;

        Format     fmt;
        WordLength wl;

        void Defaults()
        {
            mcu_is_master = true;
            lr_swap       = false;
            csb_pin_state = false;
            fmt           = Format::MSB_FIRST_LJ;
            wl            = WordLength::BITS_24;
        }
    };

    Wm8731() {}
    ~Wm8731() {}

    Result Init(const Config &config, I2CHandle i2c);

  private:
    I2CHandle i2c_;
    Config    cfg_;
    Result    WriteControlRegister(uint8_t addr, uint16_t data);
    uint8_t   dev_addr_;
};

} // namespace daisy


#endif