選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

control_cs42448.cpp 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 <Arduino.h>
  27. #include "control_cs42448.h"
  28. #include "Wire.h"
  29. #define CS42448_Chip_ID 0x01
  30. #define CS42448_Power_Control 0x02
  31. #define CS42448_Functional_Mode 0x03
  32. #define CS42448_Interface_Formats 0x04
  33. #define CS42448_ADC_Control_DAC_DeEmphasis 0x05
  34. #define CS42448_Transition_Control 0x06
  35. #define CS42448_DAC_Channel_Mute 0x07
  36. #define CS42448_AOUT1_Volume_Control 0x08
  37. #define CS42448_AOUT2_Volume_Control 0x09
  38. #define CS42448_AOUT3_Volume_Control 0x0A
  39. #define CS42448_AOUT4_Volume_Control 0x0B
  40. #define CS42448_AOUT5_Volume_Control 0x0C
  41. #define CS42448_AOUT6_Volume_Control 0x0D
  42. #define CS42448_AOUT7_Volume_Control 0x0E
  43. #define CS42448_AOUT8_Volume_Control 0x0F
  44. #define CS42448_DAC_Channel_Invert 0x10
  45. #define CS42448_AIN1_Volume_Control 0x11
  46. #define CS42448_AIN2_Volume_Control 0x12
  47. #define CS42448_AIN3_Volume_Control 0x13
  48. #define CS42448_AIN4_Volume_Control 0x14
  49. #define CS42448_AIN5_Volume_Control 0x15
  50. #define CS42448_AIN6_Volume_Control 0x16
  51. #define CS42448_ADC_Channel_Invert 0x17
  52. #define CS42448_Status_Control 0x18
  53. #define CS42448_Status 0x19
  54. #define CS42448_Status_Mask 0x1A
  55. #define CS42448_MUTEC_Pin_Control 0x1B
  56. // 4.9 Recommended Power-Up Sequence
  57. // 1. Hold RST low until the power supply and clocks are stable. In this state,
  58. // the control port is reset to its default settings and VQ will remain low.
  59. // 2. Bring RST high. The device will initially be in a low power state with VQ
  60. // low. All features will default as described in the "Register Quick Reference"
  61. // on page 40.
  62. // 3. Perform a write operation to the Power Control register ("Power Control
  63. // (Address 02h)" on page 43) to set bit 0 to a '1'b. This will place the
  64. // device in a power down state.
  65. // 4. Load the desired register settings while keeping the PDN bit set to '1'b.
  66. // 5. Mute all DACs. Muting the DACs suppresses any noise associated with the
  67. // CODEC's first initialization after power is applied.
  68. // 6. Set the PDN bit in the power control register to '0'b. VQ will ramp to
  69. // approximately VA/2 according to the Popguard specification in section
  70. // "Popguard" on page 29.
  71. // 7. Following approximately 2000 LRCK cycles, the device is initialized and
  72. // ready for normal operation.
  73. // 8. After the CODEC is initialized, wait ~90 LRCK cycles (~1.9 ms @48 kHz) and
  74. // then un-mute the DACs.
  75. // 9. Normal operation begins.
  76. static const uint8_t default_config[] = {
  77. 0xF4, // CS42448_Functional_Mode = slave mode, MCLK 25.6 MHz max
  78. 0x76, // CS42448_Interface_Formats = TDM mode
  79. 0x1C, // CS42448_ADC_Control_DAC_DeEmphasis = single ended ADC
  80. 0x63, // CS42448_Transition_Control = soft vol control
  81. 0xFF // CS42448_DAC_Channel_Mute = all outputs mute
  82. };
  83. bool AudioControlCS42448::enable(void)
  84. {
  85. Wire.begin();
  86. // TODO: wait for reset signal high??
  87. if (!write(CS42448_Power_Control, 0xFF)) return false; // power down
  88. if (!write(CS42448_Functional_Mode, default_config, sizeof(default_config))) return false;
  89. if (!write(CS42448_Power_Control, 0)) return false; // power up
  90. return true;
  91. }
  92. bool AudioControlCS42448::volumeInteger(uint32_t n)
  93. {
  94. uint8_t data[9];
  95. data[0] = 0;
  96. for (int i=1; i < 9; i++) {
  97. data[i] = n;
  98. }
  99. return write(CS42448_DAC_Channel_Mute, data, 9);
  100. }
  101. bool AudioControlCS42448::volumeInteger(int channel, uint32_t n)
  102. {
  103. return true;
  104. }
  105. bool AudioControlCS42448::inputLevelInteger(int32_t n)
  106. {
  107. return true;
  108. }
  109. bool AudioControlCS42448::inputLevelInteger(int chnnel, int32_t n)
  110. {
  111. return true;
  112. }
  113. bool AudioControlCS42448::write(uint32_t address, uint32_t data)
  114. {
  115. Wire.beginTransmission(i2c_addr);
  116. Wire.write(address);
  117. Wire.write(data);
  118. if (Wire.endTransmission() == 0) return true;
  119. return false;
  120. }
  121. bool AudioControlCS42448::write(uint32_t address, const void *data, uint32_t len)
  122. {
  123. Wire.beginTransmission(i2c_addr);
  124. Wire.write(address | 0x80);
  125. const uint8_t *p = (const uint8_t *)data;
  126. const uint8_t *end = p + len;
  127. while (p < end) {
  128. Wire.write(*p++);
  129. }
  130. if (Wire.endTransmission() == 0) return true;
  131. return false;
  132. }