Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

108 lines
2.7KB

  1. #include "control_wm8731.h"
  2. #include "Wire.h"
  3. #define WM8731_I2C_ADDR 0x1A
  4. //#define WM8731_I2C_ADDR 0x1B
  5. #define WM8731_REG_LLINEIN 0
  6. #define WM8731_REG_RLINEIN 1
  7. #define WM8731_REG_LHEADOUT 2
  8. #define WM8731_REG_RHEADOUT 3
  9. #define WM8731_REG_ANALOG 4
  10. #define WM8731_REG_DIGITAL 5
  11. #define WM8731_REG_POWERDOWN 6
  12. #define WM8731_REG_INTERFACE 7
  13. #define WM8731_REG_SAMPLING 8
  14. #define WM8731_REG_ACTIVE 9
  15. #define WM8731_REG_RESET 15
  16. bool AudioControlWM8731::enable(void)
  17. {
  18. Wire.begin();
  19. delay(5);
  20. //write(WM8731_REG_RESET, 0);
  21. write(WM8731_REG_INTERFACE, 0x02); // I2S, 16 bit, MCLK slave
  22. write(WM8731_REG_SAMPLING, 0x20); // 256*Fs, 44.1 kHz, MCLK/1
  23. // In order to prevent pops, the DAC should first be soft-muted (DACMU),
  24. // the output should then be de-selected from the line and headphone output
  25. // (DACSEL), then the DAC powered down (DACPD).
  26. write(WM8731_REG_DIGITAL, 0x08); // DAC soft mute
  27. write(WM8731_REG_ANALOG, 0x00); // disable all
  28. write(WM8731_REG_POWERDOWN, 0x00); // codec powerdown
  29. write(WM8731_REG_LHEADOUT, 0x80); // volume off
  30. write(WM8731_REG_RHEADOUT, 0x80);
  31. delay(100); // how long to power up?
  32. write(WM8731_REG_ACTIVE, 1);
  33. delay(5);
  34. write(WM8731_REG_DIGITAL, 0x00); // DAC unmuted
  35. write(WM8731_REG_ANALOG, 0x10); // DAC selected
  36. return true;
  37. }
  38. bool AudioControlWM8731::write(unsigned int reg, unsigned int val)
  39. {
  40. Wire.beginTransmission(WM8731_I2C_ADDR);
  41. Wire.write((reg << 1) | ((val >> 8) & 1));
  42. Wire.write(val & 0xFF);
  43. Wire.endTransmission();
  44. return true;
  45. }
  46. bool AudioControlWM8731::volumeInteger(unsigned int n)
  47. {
  48. if (n > 127) n = 127;
  49. //Serial.print("volumeInteger, n = ");
  50. //Serial.println(n);
  51. write(WM8731_REG_LHEADOUT, n | 0x180);
  52. write(WM8731_REG_RHEADOUT, n | 0x80);
  53. return true;
  54. }
  55. /******************************************************************/
  56. bool AudioControlWM8731master::enable(void)
  57. {
  58. Wire.begin();
  59. delay(5);
  60. //write(WM8731_REG_RESET, 0);
  61. write(WM8731_REG_INTERFACE, 0x42); // I2S, 16 bit, MCLK master
  62. write(WM8731_REG_SAMPLING, 0x20); // 256*Fs, 44.1 kHz, MCLK/1
  63. // In order to prevent pops, the DAC should first be soft-muted (DACMU),
  64. // the output should then be de-selected from the line and headphone output
  65. // (DACSEL), then the DAC powered down (DACPD).
  66. write(WM8731_REG_DIGITAL, 0x08); // DAC soft mute
  67. write(WM8731_REG_ANALOG, 0x00); // disable all
  68. write(WM8731_REG_POWERDOWN, 0x00); // codec powerdown
  69. write(WM8731_REG_LHEADOUT, 0x80); // volume off
  70. write(WM8731_REG_RHEADOUT, 0x80);
  71. delay(100); // how long to power up?
  72. write(WM8731_REG_ACTIVE, 1);
  73. delay(5);
  74. write(WM8731_REG_DIGITAL, 0x00); // DAC unmuted
  75. write(WM8731_REG_ANALOG, 0x10); // DAC selected
  76. return true;
  77. }