PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

129 line
5.2KB

  1. /*
  2. control_tlv320aic3206
  3. Created: Brendan Flynn (http://www.flexvoltbiosensor.com/) for Tympan, Jan-Feb 2017
  4. Modified: Chip Audette (https://openaudio.blogspot.com) for Tympan 2017-2018
  5. Purpose: Control module for Texas Instruments TLV320AIC3206 compatible with Teensy Audio Library
  6. License: MIT License. Use at your own risk.
  7. Note that the TLV320AIC3206 has a reset that should be connected to microcontroller.
  8. This code defaults to Teensy Pin 21, which was used on Tympan Rev C.
  9. You can set the reset pin in the constructor
  10. Note that this can configure the AIC for 32-bit per sample I2S transfers or 16-bit per sample.
  11. Defaults to 16 bits per sample to allow it to work with default Teensy audio library.
  12. Example Usage for Teensy:
  13. #include <Audio.h> //Teensy Audio Library
  14. int AIC3206_RESET_PIN=21; //What pin is your AIC3206 reset pin connected to?
  15. AudioControlTLV320AIC3206 audioHardware(AIC3206_RESET_PIN);
  16. AudioInputI2S i2s_in; //Digital audio *from* the AIC.
  17. AudioOutputI2S i2s_out; //Digital audio *to* the AIC.
  18. AudioConnection patchCord1(i2s_in, 0, i2s_out, 0); //connect left input to left output
  19. AudioConnection patchCord2(i2s_in, 1, i2s_out, 1); //connect right input to right output
  20. void setup(void)
  21. {
  22. //begin the serial comms (for debugging)
  23. Serial.begin(115200); delay(500);
  24. Serial.println("AudioPassThru: Starting setup()...");
  25. //allocate the dynamic memory for audio processing blocks
  26. AudioMemory(10);
  27. //Enable the TLV32AIC3206 to start the audio flowing!
  28. audioHardware.enable(); // activate AIC
  29. //Choose the desired input
  30. audioHardware.inputSelect(AIC3206_INPUT_IN1); // use Input 1
  31. //Set the desired volume levels
  32. audioHardware.volume_dB(0); // headphone amplifier. -63.6 to +24 dB in 0.5dB steps.
  33. audioHardware.setInputGain_dB(10.0); // set input volume, 0-47.5dB in 0.5dB setps
  34. }
  35. void loop(void)
  36. {
  37. // Nothing to do
  38. }
  39. */
  40. #ifndef control_tlv320aic3206_h_
  41. #define control_tlv320aic3206_h_
  42. #include "AudioControl.h"
  43. #include <Arduino.h>
  44. //convenience names to use with inputSelect() to set whnch analog inputs to use
  45. #define AIC3206_INPUT_IN1 1 //uses IN1
  46. #define AIC3206_INPUT_IN2 2 //uses IN2 analog inputs
  47. #define AIC3206_INPUT_IN3 3 //uses IN3 analog inputs
  48. #define AIC3206_INPUT_IN3_MICBIAS 4 //uses IN3 analog inputs *and* enables mic bias
  49. //convenience names to use with outputSelect()
  50. #define AIC3206_OUTPUT_HEADPHONE_JACK_OUT 1
  51. #define AIC3206_OUTPUT_LINE_OUT 2
  52. #define AIC3206_OUTPUT_HEADPHONE_AND_LINE_OUT 3
  53. //names to use with setMicBias() to set the amount of bias voltage to use
  54. #define AIC3206_MIC_BIAS_OFF 0
  55. #define AIC3206_MIC_BIAS_1_25 1
  56. #define AIC3206_MIC_BIAS_1_7 2
  57. #define AIC3206_MIC_BIAS_2_5 3
  58. #define AIC3206_MIC_BIAS_VSUPPLY 4
  59. #define AIC3206_DEFAULT_MIC_BIAS AIC3206_MIC_BIAS_2_5
  60. #define AIC3206_BOTH_CHAN 0
  61. #define AIC3206_LEFT_CHAN 1
  62. #define AIC3206_RIGHT_CHAN 2
  63. class AudioControlTLV320AIC3206: public AudioControl
  64. {
  65. public:
  66. //GUI: inputs:0, outputs:0 //this line used for automatic generation of GUI node
  67. AudioControlTLV320AIC3206(void) { debugToSerial = false; };
  68. AudioControlTLV320AIC3206(bool _debugToSerial) { debugToSerial = _debugToSerial; };
  69. AudioControlTLV320AIC3206(int _resetPin) { debugToSerial = false; resetPinAIC = _resetPin; }
  70. AudioControlTLV320AIC3206(int _resetPin, bool _debugToSerial) { resetPinAIC = _resetPin; debugToSerial = _debugToSerial; };
  71. bool enable(void);
  72. bool disable(void);
  73. bool outputSelect(int n); //use AIC3206_OUTPUT_HEADPHONE_JACK_OUT or one of other choices defined earlier
  74. bool volume(float n);
  75. bool volume_dB(float n);
  76. bool inputLevel(float n); //dummy to be compatible with Teensy Audio Library
  77. bool inputSelect(int n); //use AIC3206_INPUT_IN1 or one of other choices defined earlier
  78. bool setInputGain_dB(float n);
  79. bool setMicBias(int n); //use AIC3206_MIC_BIAS_OFF or AIC3206_MIC_BIAS_2_5 or one of other choices defined earlier
  80. bool updateInputBasedOnMicDetect(int setting = AIC3206_INPUT_IN1); //which input to monitor
  81. bool enableMicDetect(bool);
  82. int readMicDetect(void);
  83. bool debugToSerial;
  84. unsigned int aic_readPage(uint8_t page, uint8_t reg);
  85. bool aic_writePage(uint8_t page, uint8_t reg, uint8_t val);
  86. void setHPFonADC(bool enable, float cutoff_Hz, float fs_Hz);
  87. float getHPCutoff_Hz(void) { return HP_cutoff_Hz; }
  88. float getSampleRate_Hz(void) { return sample_rate_Hz; }
  89. void setIIRCoeffOnADC(int chan, uint32_t *coeff); //for chan, use AIC3206_BOTH_CHAN or AIC3206_LEFT_CHAN or AIC3206_RIGHT_CHAN
  90. bool enableAutoMuteDAC(bool, uint8_t);
  91. private:
  92. void aic_reset(void);
  93. void aic_init(void);
  94. void aic_initDAC(void);
  95. void aic_initADC(void);
  96. bool aic_writeAddress(uint16_t address, uint8_t val);
  97. bool aic_goToPage(uint8_t page);
  98. int prevMicDetVal = -1;
  99. int resetPinAIC = 21; //AIC reset pin, Tympan Rev C
  100. float HP_cutoff_Hz = 0.0f;
  101. float sample_rate_Hz = 44100; //only used with HP_cutoff_Hz to design HP filter on ADC, if used
  102. void setIIRCoeffOnADC_Left(uint32_t *coeff);
  103. void setIIRCoeffOnADC_Right(uint32_t *coeff);
  104. };
  105. #endif