Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

149 rindas
5.4KB

  1. /* Audio Library for Teensy 3.X
  2. * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
  3. *
  4. * Development of this audio library was funded by PJRC.COM, LLC by sales of
  5. * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
  6. * open source software by purchasing Teensy or other PJRC products.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice, development funding notice, and this permission
  16. * notice shall be included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include "control_cs42448.h"
  27. #include "Wire.h"
  28. #define CS42448_Chip_ID 0x01
  29. #define CS42448_Power_Control 0x02
  30. #define CS42448_Functional_Mode 0x03
  31. #define CS42448_Interface_Formats 0x04
  32. #define CS42448_ADC_Control_DAC_DeEmphasis 0x05
  33. #define CS42448_Transition_Control 0x06
  34. #define CS42448_DAC_Channel_Mute 0x07
  35. #define CS42448_AOUT1_Volume_Control 0x08
  36. #define CS42448_AOUT2_Volume_Control 0x09
  37. #define CS42448_AOUT3_Volume_Control 0x0A
  38. #define CS42448_AOUT4_Volume_Control 0x0B
  39. #define CS42448_AOUT5_Volume_Control 0x0C
  40. #define CS42448_AOUT6_Volume_Control 0x0D
  41. #define CS42448_AOUT7_Volume_Control 0x0E
  42. #define CS42448_AOUT8_Volume_Control 0x0F
  43. #define CS42448_DAC_Channel_Invert 0x10
  44. #define CS42448_AIN1_Volume_Control 0x11
  45. #define CS42448_AIN2_Volume_Control 0x12
  46. #define CS42448_AIN3_Volume_Control 0x13
  47. #define CS42448_AIN4_Volume_Control 0x14
  48. #define CS42448_AIN5_Volume_Control 0x15
  49. #define CS42448_AIN6_Volume_Control 0x16
  50. #define CS42448_ADC_Channel_Invert 0x17
  51. #define CS42448_Status_Control 0x18
  52. #define CS42448_Status 0x19
  53. #define CS42448_Status_Mask 0x1A
  54. #define CS42448_MUTEC_Pin_Control 0x1B
  55. // 4.9 Recommended Power-Up Sequence
  56. // 1. Hold RST low until the power supply and clocks are stable. In this state,
  57. // the control port is reset to its default settings and VQ will remain low.
  58. // 2. Bring RST high. The device will initially be in a low power state with VQ
  59. // low. All features will default as described in the "Register Quick Reference"
  60. // on page 40.
  61. // 3. Perform a write operation to the Power Control register ("Power Control
  62. // (Address 02h)" on page 43) to set bit 0 to a '1'b. This will place the
  63. // device in a power down state.
  64. // 4. Load the desired register settings while keeping the PDN bit set to '1'b.
  65. // 5. Mute all DACs. Muting the DACs suppresses any noise associated with the
  66. // CODEC's first initialization after power is applied.
  67. // 6. Set the PDN bit in the power control register to '0'b. VQ will ramp to
  68. // approximately VA/2 according to the Popguard specification in section
  69. // "Popguard" on page 29.
  70. // 7. Following approximately 2000 LRCK cycles, the device is initialized and
  71. // ready for normal operation.
  72. // 8. After the CODEC is initialized, wait ~90 LRCK cycles (~1.9 ms @48 kHz) and
  73. // then un-mute the DACs.
  74. // 9. Normal operation begins.
  75. static const uint8_t default_config[] = {
  76. 0xF4, // CS42448_Functional_Mode = slave mode, MCLK 25.6 MHz max
  77. 0x76, // CS42448_Interface_Formats = TDM mode
  78. 0x1C, // CS42448_ADC_Control_DAC_DeEmphasis = single ended ADC
  79. 0x63, // CS42448_Transition_Control = soft vol control
  80. 0xFF // CS42448_DAC_Channel_Mute = all outputs mute
  81. };
  82. bool AudioControlCS42448::enable(void)
  83. {
  84. Wire.begin();
  85. // TODO: wait for reset signal high??
  86. if (!write(CS42448_Power_Control, 0xFF)) return false; // power down
  87. if (!write(CS42448_Functional_Mode, default_config, sizeof(default_config))) return false;
  88. if (!write(CS42448_Power_Control, 0)) return false; // power up
  89. return true;
  90. }
  91. bool AudioControlCS42448::volumeInteger(uint32_t n)
  92. {
  93. uint8_t data[9];
  94. data[0] = 0;
  95. for (int i=1; i < 9; i++) {
  96. data[i] = n;
  97. }
  98. return write(CS42448_DAC_Channel_Mute, data, 9);
  99. }
  100. bool AudioControlCS42448::volumeInteger(int channel, uint32_t n)
  101. {
  102. return true;
  103. }
  104. bool AudioControlCS42448::inputLevelInteger(int32_t n)
  105. {
  106. return true;
  107. }
  108. bool AudioControlCS42448::inputLevelInteger(int chnnel, int32_t n)
  109. {
  110. return true;
  111. }
  112. bool AudioControlCS42448::write(uint32_t address, uint32_t data)
  113. {
  114. Wire.beginTransmission(i2c_addr);
  115. Wire.write(address);
  116. Wire.write(data);
  117. if (Wire.endTransmission() == 0) return true;
  118. return false;
  119. }
  120. bool AudioControlCS42448::write(uint32_t address, const void *data, uint32_t len)
  121. {
  122. Wire.beginTransmission(i2c_addr);
  123. Wire.write(address | 0x80);
  124. const uint8_t *p = (const uint8_t *)data;
  125. const uint8_t *end = p + len;
  126. while (p < end) {
  127. Wire.write(*p++);
  128. }
  129. if (Wire.endTransmission() == 0) return true;
  130. return false;
  131. }