NetBurner 3.5.6
PDF Version
wm8904.h
1#ifndef __WM8904_H
2#define __WM8904_H
3/*NB_REVISION*/
4
5/*NB_COPYRIGHT*/
6
7#include <predef.h>
8#include <stdio.h>
9#include <init.h>
10#include <sim.h> /*on-chip register definitions*/
11#include <pins.h>
12#include <nbrtos.h>
13#include <i2c.h>
14#include "ssc_i2s.h"
15
16#include "wm8904_reg.h"
17
22class WM8904
23{
24 public:
25 struct Reg
26 {
27 enum RegAddr_t
28 {
29 SWRST_ID = 0x00,
30 BIAS_CTL0 = 0x04,
31 VMID_CTL0 = 0x05,
32 MIC_BIAS_CTL0 = 0x06,
33 MIC_BIAS_CTL1 = 0x07,
34 ANA_ADC0 = 0x0A,
35 PWR_MGMNT0 = 0x0C,
36 PWR_MGMNT2 = 0x0E,
37 PWR_MGMNT3 = 0x0F,
38 PWR_MGMNT6 = 0x12,
39 CLK_RATES0 = 0x14,
40 CLK_RATES1 = 0x15,
41 CLK_RATES2 = 0x16,
42 AUDIO_INTF0 = 0x18,
43 AUDIO_INTF1 = 0x19,
44 AUDIO_INTF2 = 0x1A,
45 AUDIO_INTF3 = 0x1B,
46 DAC_DGTL_VOL_L = 0x1E,
47 DAC_DGTL_VOL_R = 0x1F,
48 DAC_DGTL0 = 0x20,
49 DAC_DGTL1 = 0x21,
50 ADC_DGTL_VOL_L = 0x24,
51 ADC_DGTL_VOL_R = 0x25,
52 ADC_DGTL0 = 0x26,
53 DGTL_MIC0 = 0x27,
54 DRC0 = 0x28,
55 DRC1 = 0x29,
56 DRC2 = 0x2A,
57 DRC3 = 0x2B,
58 ANA_L_IN0 = 0x2C,
59 ANA_R_IN0 = 0x2D,
60 ANA_L_IN1 = 0x2E,
61 ANA_R_IN1 = 0x2F,
62 ANA_OUT1_L = 0x39,
63 ANA_OUT1_R = 0x3A,
64 ANA_OUT2_L = 0x3B,
65 ANA_OUT2_R = 0x3C,
66 ANA_OUT12_ZC = 0x3D,
67 DC_SERVO0 = 0x43,
68 DC_SERVO1 = 0x44,
69 DC_SERVO2 = 0x45,
70 DC_SERVO4 = 0x47,
71 DC_SERVO5 = 0x48,
72 DC_SERVO6 = 0x49,
73 DC_SERVO7 = 0x4A,
74 DC_SERVO8 = 0x4B,
75 DC_SERVO9 = 0x4C,
76 DC_SERVO_RDBK0 = 0x4D,
77 ANA_HP0 = 0x5A,
78 ANA_LINEOUT0 = 0x5E,
79 CHARGE_PUMP0 = 0x62,
80 CLASS_W0 = 0x68,
81 WR_SEQ0 = 0x6C,
82 WR_SEQ1 = 0x6D,
83 WR_SEQ2 = 0x6E,
84 WR_SEQ3 = 0x6F,
85 WR_SEQ4 = 0x70,
86 FLL_CTL1 = 0x74,
87 FLL_CTL2 = 0x75,
88 FLL_CTL3 = 0x76,
89 FLL_CTL4 = 0x77,
90 FLL_CTL5 = 0x78,
91 GPIO_CTL1 = 0x79,
92 GPIO_CTL2 = 0x7A,
93 GPIO_CTL3 = 0x7B,
94 GPIO_CTL4 = 0x7C,
95 DGTL_PULLS = 0x7E,
96 IRQ_STAT = 0x7F,
97 IRQ_STAT_MASK = 0x80,
98 IRQ_POL = 0x81,
99 IRQ_DEBOUNCE = 0x82,
100 EQ1 = 0x86,
101 EQ2 = 0x87,
102 EQ3 = 0x88,
103 EQ4 = 0x89,
104 EQ5 = 0x8A,
105 EQ6 = 0x8B,
106 EQ7 = 0x8C,
107 EQ8 = 0x8D,
108 EQ9 = 0x8E,
109 EQ10 = 0x8F,
110 EQ11 = 0x90,
111 EQ12 = 0x91,
112 EQ13 = 0x92,
113 EQ14 = 0x93,
114 EQ15 = 0x94,
115 EQ16 = 0x95,
116 EQ17 = 0x96,
117 EQ18 = 0x97,
118 EQ19 = 0x98,
119 EQ20 = 0x99,
120 EQ21 = 0x9A,
121 EQ22 = 0x9B,
122 EQ23 = 0x9C,
123 EQ24 = 0x9D,
124 ADC_TEST0 = 0xC6,
125 FLL_NCO_TEST0 = 0xF7,
126 FLL_NCO_TEST1 = 0xF8
127 };
128 struct cmd_t
129 {
130 RegAddr_t reg;
131 uint16_t val;
132 uint16_t dly;
133 cmd_t &operator=(const cmd_t rhs)
134 {
135 reg = rhs.reg;
136 val = rhs.val;
137 dly = rhs.dly;
138 return *this;
139 }
140 };
141 static cmd_t init_cmds_0[];
142 static cmd_t init_cmds_1[];
143 static cmd_t init_cmds_2[];
144 static cmd_t init_cmds_3[];
145 static cmd_t init_cmds_4[];
146 static cmd_t init_cmds_5[];
147 static cmd_t init_cmds_6[];
148 };
149
150 enum DataLen_t
151 {
152 DATA_LEN_16,
153 DATA_LEN_24,
154 DATA_LEN_32
155 };
156
157 enum DataFmt_t
158 {
159 DATA_FMT_16_L_JUSTIFIED,
160 DATA_FMT_16_I2S,
161 DATA_FMT_32_L_JUSTIFIED,
162 DATA_FMT_32_I2S
163 };
164
165 enum AudioChSelect_t
166 {
167 CH_SELECT_LEFT,
168 CH_SELECT_RIGHT,
169 CH_SELECT_LEFT_RIGHT
170 };
171
172 enum AudioOutSelect_t
173 {
174 AUDIO_OUT_NONE,
175 AUDIO_OUT_HP,
176 AUDIO_OUT_LINE,
177 AUDIO_OUT_SPKR
178 };
179
180 enum AudioInSelect_t
181 {
182 AUDIO_IN_NONE,
183 AUDIO_IN_1,
184 AUDIO_IN_2,
185 AUDIO_IN_3,
186 };
187
188 struct cfg_t
189 {
190 uint16_t sampleRate;
191 uint32_t refClkRate;
192 DataFmt_t dataFormat;
193 AudioChSelect_t inCh;
194 AudioChSelect_t outCh;
195 AudioInSelect_t inSrc;
196 AudioOutSelect_t outSrc;
197
198 uint8_t initMicGain;
199 uint8_t initOutVol;
200 };
201
202 private:
203 I2C &twi;
204
205 void InitInput(const cfg_t &cfg);
206 void ConfigFLL(const cfg_t &cfg);
207
208 public:
214 WM8904(I2C &module);
220 void Init(const cfg_t &cfg, const SSC_cfg_t &ssc_cfg);
224 void Shutdown();
230 void WriteReg(Reg::RegAddr_t reg, uint16_t dat);
236 uint16_t ReadReg(Reg::RegAddr_t reg);
237
243 void SendCmd(Reg::cmd_t cmd);
251 void SendCmdList(Reg::cmd_t *cmds, uint32_t len);
260 void UpdateCmd(Reg::cmd_t cmd, uint16_t updateMask);
261
268 void SetVolume(AudioOutSelect_t out, AudioChSelect_t channel, uint8_t volume);
275 uint8_t GetVolume(AudioOutSelect_t out, AudioChSelect_t channel);
282 void Mute(AudioOutSelect_t out, AudioChSelect_t channel, bool mute);
283
289 void SetMicGain(AudioChSelect_t channel, uint8_t gain);
295 uint8_t GetMicGain(AudioChSelect_t channel);
301 void MuteMic(AudioChSelect_t channel, bool mute);
302
314 int TransmitBuffer(void *buffer, uint32_t bufferLen, bool waitIfNeeded);
326 int ReadyReceiveBuffer(void *buffer, uint32_t bufferLen, bool waitIfNeeded);
327
331 void RegisterTxBufferDoneCB(SSC_BufferDoneFn_t cb);
335 void RegisterRxBufferDoneCB(SSC_BufferDoneFn_t cb);
336};
337#endif /* ----- #ifndef __WM8904_H ----- */
I2C Peripheral Class.
Definition i2c.h:213
Definition wm8904.h:23
void SendCmdList(Reg::cmd_t *cmds, uint32_t len)
Execute an array of codec Commands. A command is: a register to write, a value to write,...
Definition wm8904.cpp:145
void SendCmd(Reg::cmd_t cmd)
Execute codec Command. A command is: a register to write, a value to write, and a delay of time requi...
Definition wm8904.cpp:139
void MuteMic(AudioChSelect_t channel, bool mute)
Mute or unmute the selected input channel.
Definition wm8904.cpp:464
uint16_t ReadReg(Reg::RegAddr_t reg)
Read a register on the WM8904.
Definition wm8904.cpp:30
void SetMicGain(AudioChSelect_t channel, uint8_t gain)
Set the microphone gain of the selected input channel.
Definition wm8904.cpp:440
void WriteReg(Reg::RegAddr_t reg, uint16_t dat)
Write a register on the WM8904.
Definition wm8904.cpp:17
void Init(const cfg_t &cfg, const SSC_cfg_t &ssc_cfg)
Configures and initializes both the driver and the codec.
Definition wm8904.cpp:245
void Mute(AudioOutSelect_t out, AudioChSelect_t channel, bool mute)
Mute or unmute the selected audio output and channel.
Definition wm8904.cpp:389
void RegisterTxBufferDoneCB(SSC_BufferDoneFn_t cb)
Registers a callback for when a transmit buffer is finished.
Definition wm8904.cpp:510
WM8904(I2C &module)
The constructor for the WM8904 context.
Definition wm8904.cpp:15
uint8_t GetVolume(AudioOutSelect_t out, AudioChSelect_t channel)
Get the volume of the selected audio output and channel.
Definition wm8904.cpp:369
void Shutdown()
Shuts down the WM8904 codec driver.
int ReadyReceiveBuffer(void *buffer, uint32_t bufferLen, bool waitIfNeeded)
Hands off a buffer to be written to by the codec.
Definition wm8904.cpp:505
void RegisterRxBufferDoneCB(SSC_BufferDoneFn_t cb)
Registers a callback for when a receive buffer is finished.
Definition wm8904.cpp:515
void UpdateCmd(Reg::cmd_t cmd, uint16_t updateMask)
Execute a codec Command to update a register. A command is: a register to write, a value to write,...
Definition wm8904.cpp:153
int TransmitBuffer(void *buffer, uint32_t bufferLen, bool waitIfNeeded)
Hands off a buffer to be transmitted to the codec.
Definition wm8904.cpp:500
uint8_t GetMicGain(AudioChSelect_t channel)
Get the microphone gain of the selected input channel.
Definition wm8904.cpp:459
void SetVolume(AudioOutSelect_t out, AudioChSelect_t channel, uint8_t volume)
Set the volume of the selected audio output and channel.
Definition wm8904.cpp:329
NetBurner I2C API for ARM SAME70.
NetBurner System Initialization Header File.
NetBurner Real-Time Operating System (NBRTOS) API.
Configuration structure for the SSC driver. Passed to the initialize function to configure the hardwa...
Definition ssc_i2s.h:249