You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 line
7.4KB

  1. /*
  2. * HiFi Audio Codec Module support library for Teensy 3.x
  3. *
  4. * Copyright 2015, Michele Perla
  5. *
  6. */
  7. #ifndef control_ak4558_h_
  8. #define control_ak4558_h_
  9. #include "AudioControl.h"
  10. // for Teensy audio lib operation the following settings are needed
  11. // 1fs = 44.1 KHz
  12. // sample size = 16 bits
  13. // MCKI : 11.2896 MHz
  14. // BICK : 1.4112 MHz
  15. // LRCK : 44.100 KHz
  16. // to do so we need to set the following bits:
  17. // PMPLL = 0 (EXT Slave Mode; disables internal PLL and uses ext. clock) (by DEFAULT)
  18. // ACKS = 0 (Manual Setting Mode; disables automatic clock selection) (by DEFAULT)
  19. // DFS1-0 = 00 (Sampling Speed = Normal Speed Mode, default)
  20. // MCKS1-0 = 00 (Master Clock Input Frequency Select, set 256fs for Normal Speed Mode -> 11.2896 MHz)
  21. // BCKO1-0 = 00 (BICK Output Frequency at Master Mode = 32fs = 1.4112 MHz)
  22. // TDM1-0 = 00 (Time Division Multiplexing mode OFF) (by DEFAULT)
  23. // DIF2-1-0 = 011 ( 16 bit I2S compatible when BICK = 32fs)
  24. #ifndef PIN_PDN
  25. #define PIN_PDN 1
  26. #endif
  27. // Power-Down & Reset Mode Pin
  28. // “L”: Power-down and Reset, “H”: Normal operation
  29. // The AK4558 should be reset once by bringing PDN pin = “L”
  30. #ifndef AK4558_CAD1
  31. #define AK4558_CAD1 1
  32. #endif
  33. // Chip Address 1 pin
  34. // set to 'H' by default, configurable to 'L' via a jumper on bottom side of the board
  35. #ifndef AK4558_CAD0
  36. #define AK4558_CAD0 1
  37. #endif
  38. // Chip Address 0 pin
  39. // set to 'H' by default, configurable to 'L' via a jumper on bottom side of the board
  40. #define AK4558_I2C_ADDR (0x10 + (AK4558_CAD1<<1) + AK4558_CAD0)
  41. // datasheet page 81:
  42. // This address is 7 bits long followed by the eighth bit that is a data direction bit (R/W).
  43. // The most significant five bits of the slave address are fixed as “00100”. The next bits are
  44. // CAD1 and CAD0 (device address bit). These bits identify the specific device on the bus.
  45. // The hard-wired input pins (CAD1 and CAD0) set these device address bits (Figure 69)
  46. // Power Management register
  47. #define AK4558_PWR_MNGT 0x00
  48. // D4 D3 D2 D1 D0
  49. // PMADR PMADL PMDAR PMDAL RSTN
  50. #define AK4558_PMADR (1u<<4)
  51. #define AK4558_PMADL (1u<<3)
  52. // PMADL/R: ADC L/Rch Power Management
  53. // 0: ADC L/Rch Power Down (default)
  54. // 1: Normal Operation
  55. #define AK4558_PMDAR (1u<<2)
  56. #define AK4558_PMDAL (1u<<1)
  57. // PMDAL/R: DAC L/Rch Power Management
  58. // 0: DAC L/Rch Power Down (default)
  59. // 1: Normal Operation
  60. #define AK4558_RSTN (1u)
  61. // RSTN: Internal Timing Reset
  62. // 0: Reset Register values are not reset.
  63. // 1: Normal Operation (default)
  64. // PLL Control register
  65. #define AK4558_PLL_CTRL 0X01
  66. // D4 D3 D2 D1 D0
  67. // PLL3 PLL2 PLL1 PLL0 PMPLL
  68. #define AK4558_PLL3 (1u<<4)
  69. #define AK4558_PLL2 (1u<<3)
  70. #define AK4558_PLL1 (1u<<2)
  71. #define AK4558_PLL0 (1u<<1)
  72. // PLL3-0: PLL Reference Clock Select (Table 16)
  73. // Default: “0010” (BICK pin=64fs)
  74. #define AK4558_PMPLL (1u)
  75. // PMPLL: PLL Power Management
  76. // 0: EXT Mode and Power down (default)
  77. // 1: PLL Mode and Power up
  78. // DAC TDM register
  79. #define AK4558_DAC_TDM 0X02
  80. // D1 D0
  81. // SDS1 SDS0
  82. #define AK4558_SDS1 (1u<<1)
  83. #define AK4558_SDS0 (1u)
  84. // SDS1-0: DAC TDM Data Select (Table 24)
  85. // Default: “00”
  86. // Control 1 register
  87. #define AK4558_CTRL_1 0X03
  88. // D7 D6 D5 D4 D3 D2 D1 D0
  89. // TDM1 TDM0 DIF2 DIF1 DIF0 ATS1 ATS0 SMUTE
  90. #define AK4558_TDM1 (1u<<7)
  91. #define AK4558_TDM0 (1u<<6)
  92. // TDM1-0: TDM Format Select (Table 23, Table 25, Table 26)
  93. // Default: “00” (Stereo Mode)
  94. #define AK4558_DIF2 (1u<<5)
  95. #define AK4558_DIF1 (1u<<4)
  96. #define AK4558_DIF0 (1u<<3)
  97. // DIF2-0: Audio Interface Format Mode Select (Table 23)
  98. // Default: “111” (32bit I2S)
  99. #define AK4558_ATS1 (1u<<2)
  100. #define AK4558_ATS0 (1u<<1)
  101. // ATS1-0: Transition Time Setting of Digital Attenuator (Table 31)
  102. // Default: “00”
  103. #define AK4558_SMUTE (1u)
  104. // SMUTE: Soft Mute Enable
  105. // 0: Normal Operation (default)
  106. // 1: All DAC outputs are soft muted.
  107. // Control 2 register
  108. #define AK4558_CTRL_2 0X04
  109. // D4 D3 D2 D1 D0
  110. // MCKS1 MCKS0 DFS1 DFS0 ACKS
  111. #define AK4558_MCKS1 (1u<<4)
  112. #define AK4558_MCKS0 (1u<<3)
  113. // MCKS1-0: Master Clock Input Frequency Select (Table 9, follows):
  114. // MCKS1 MCKS0 NSM DSM QSM
  115. // 0 0 256fs 256fs 128fs
  116. // 0 1 384fs 256fs 128fs
  117. // 1 0 512fs 256fs 128fs (default)
  118. // 1 1 768fs 256fs 128fs
  119. #define AK4558_DFS1 (1u<<2)
  120. #define AK4558_DFS0 (1u<<1)
  121. // DFS1-0: Sampling Speed Control (Table 8)
  122. // The setting of DFS1-0 bits is ignored when ACKS bit =“1”.
  123. #define AK4558_ACKS (1u)
  124. // ACKS: Automatic Clock Recognition Mode
  125. // 0: Disable, Manual Setting Mode (default)
  126. // 1: Enable, Auto Setting Mode
  127. // When ACKS bit = “1”, master clock frequency is detected automatically. In this case, the setting of
  128. // DFS1-0 bits is ignored. When ACKS bit = “0”, DFS1-0 bits set the sampling speed mode. The MCKI
  129. // frequency of each mode is detected automatically.
  130. // Mode Control register
  131. #define AK4558_MODE_CTRL 0X05
  132. // D6 D5 D4 D3 D2 D1 D0
  133. // FS3 FS2 FS1 FS0 BCKO1 BCKO0 LOPS
  134. #define AK4558_FS3 (1u<<6)
  135. #define AK4558_FS2 (1u<<5)
  136. #define AK4558_FS1 (1u<<4)
  137. #define AK4558_FS0 (1u<<3)
  138. // FS3-0: Sampling Frequency (Table 17, Table 18)
  139. // Default: “0101”
  140. #define AK4558_BCKO1 (1u<<2)
  141. #define AK4558_BCKO0 (1u<<1)
  142. // BCKO1-0: BICK Output Frequency Setting in Master Mode (Table 21)
  143. // Default: “01” (64fs)
  144. #define AK4558_LOPS (1u<<0)
  145. // LOPS: Power-save Mode of LOUT/ROUT
  146. // 0: Normal Operation (default)
  147. // 1: Power-save Mode
  148. // Filter Setting register
  149. #define AK4558_FLTR_SET 0x06
  150. // D7 D6 D5 D4 D3 D2 D1 D0
  151. // FIRDA2 FIRDA1 FIRDA0 SLDA SDDA SSLOW DEM1 DEM0
  152. #define AK4558_FIRDA2 (1u<<7)
  153. #define AK4558_FIRDA1 (1u<<6)
  154. #define AK4558_FIRDA0 (1u<<5)
  155. // FIRDA2-0: Out band noise eliminating Filters Setting (Table 32)
  156. // default: “001” (48kHz)
  157. #define AK4558_SLDA (1u<<4)
  158. // SLDA: DAC Slow Roll-off Filter Enable (Table 28)
  159. // 0: Sharp Roll-off filter (default)
  160. // 1: Slow Roll-off Filter
  161. #define AK4558_SDDA (1u<<3)
  162. // SDDA: DAC Short delay Filter Enable (Table 28)
  163. // 0: Normal filter
  164. // 1: Short delay Filter (default)
  165. #define AK4558_SSLOW (1u<<2)
  166. // SSLOW: Digital Filter Bypass Mode Enable
  167. // 0: Roll-off filter (default)
  168. // 1: Super Slow Roll-off Mode
  169. #define AK4558_DEM1 (1u<<1)
  170. #define AK4558_DEM0 (1u)
  171. // DEM1-0: De-emphasis response control for DAC (Table 22)
  172. // Default: “01”, OFF
  173. // HPF Enable, Filter Setting
  174. #define AK4558_HPF_EN_FLTR_SET 0x07
  175. // D3 D2 D1 D0
  176. // SLAD SDAD HPFER HPFEL
  177. #define AK4558_SLAD (1u<<3)
  178. // SLAD: ADC Slow Roll-off Filter Enable (Table 27)
  179. // 0: Sharp Roll-off filter (default)
  180. // 1: Slow Roll-off Filter
  181. #define AK4558_SDAD (1u<<2)
  182. // SDAD: ADC Short delay Filter Enable (Table 27)
  183. // 0: Normal filter
  184. // 1: Short delay Filter (default)
  185. #define AK4558_HPFER (1u<<1)
  186. #define AK4558_HPFEL (1u)
  187. // HPFEL/R: ADC HPF L/Rch Setting
  188. // 0: HPF L/Rch OFF
  189. // 1: HPF L/Rch ON (default)
  190. // LOUT Volume Control register
  191. #define AK4558_LOUT_VOL 0X08
  192. // D7 D6 D5 D4 D3 D2 D1 D0
  193. // ATL7 ATL6 ATL5 ATL4 ATL3 ATL2 ATL1 ATL0
  194. //
  195. // ATL 7-0: Attenuation Level (Table 30)
  196. // Default:FF(0dB)
  197. // ROUT Volume Control register
  198. #define AK4558_ROUT_VOL 0X09
  199. // D7 D6 D5 D4 D3 D2 D1 D0
  200. // ATR7 ATR6 ATR5 ATR4 ATR3 ATR2 ATR1 ATR0
  201. //
  202. // ATR 7-0: Attenuation Level (Table 30)
  203. // Default:FF(0dB)
  204. class AudioControlAK4558 : public AudioControl
  205. {
  206. public:
  207. bool enable(void);
  208. bool disable(void) { return false; }
  209. bool volume(float n) { return false; }
  210. bool inputLevel(float n) { return false; }
  211. bool inputSelect(int n) { return false; }
  212. protected:
  213. unsigned int registers[10];
  214. void readInitConfig(void);
  215. bool write(unsigned int reg, unsigned int val);
  216. };
  217. #endif