// // Created by zemon on 24.06.2021. // #ifndef MAX_9860_H #define MAX_9860_H #include "I2cIO.h" #include "stdbool.h" #include "max9860_enums.h" #define MAX9860_TOTAL_REG_COUNT 0x11 typedef struct { MAX9860_MCLK_TO_PCLK_PrescalerMode MCLK_TO_PCLK_Prescaler; MAX9860_IntegerClockMode IntegerClockMode; bool EXACTLY_16KHZ; bool PLL_Enable; //enable core clock as divided mclk uint16_t LRCLK_Driver; //clock divider, depends on mclk and sample rate (lrclk) } MAX9860_ClocksState; typedef struct { bool MasterMode; bool LRCLK_Invert; bool DAC_BCLK_Invert; bool DAC_DelayMode; bool SDOUT_HighImpedanceMode; bool TDM_ModeSelect; bool ADC_BCLK_Invert; bool ADC_Delay_Mode; bool StereoEnable; uint8_t BCLK_Select; } MAX9860_AudioInterfaceState; typedef struct { MAX9860_DigitalFilterType ADC_DigitalFilter; MAX9860_DigitalFilterType DAC_DigitalFilter; } MAX9860_DigitalFiltersState; //range from +3dB to -90dB #define MAX9860_DAC_LEVEL_ADJUST__DB(DB_VALUE) (DB_VALUE>3?0:(DB_VALUE<-90?0xBC:(6-(DB_VALUE*2)))) //range from +3dB to -12dB #define MAX9860_ADC_OUTPUT_LEVEL__DB(DB_VALUE) (DB_VALUE>3?0:(DB_VALUE<-12?0xF:(3-DB_VALUE))) #define MAX9860_DAC_GAIN__0 0b00 #define MAX9860_DAC_GAIN__PLUS_6DB 0b01 #define MAX9860_DAC_GAIN__PLUS_12DB 0b10 #define MAX9860_DAC_GAIN__PLUS_18DB 0b11 #define MAX9860_SIDETONE_DISABLED 0b0 typedef struct { uint8_t DAC_LevelAdjust; uint8_t ADC_OutputLevelRight; uint8_t ADC_OutputLevelLeft; uint8_t DAC_Gain; uint8_t Sidetone; } MAX9860_DigitalLevelControlState; #define MAX9860_MIC_PREAMP_GAIN__DISABLED 0b00 #define MAX9860_MIC_PREAMP_GAIN__0 0b01 #define MAX9860_MIC_PREAMP_GAIN__PLUS_20 0b10 #define MAX9860_MIC_PREAMP_GAIN__PLUS_30 0b11 //range form 0 to +20dB #define MAX9860_MIC_PROGRAMMABLE_GAIN_PLUS_DB(DB_VALUE) (DB_VALUE<0?0x20:(DB_VALUE>20?0:(20-DB_VALUE))) typedef struct { uint8_t MicrophonePreampGain; uint8_t MicrophoneProgrammableGain; } MAX9860_MicrophoneInputState; typedef struct { MAX9860_NoiseGateSignalSource NoiseGateSource; MAX9860_AutomaticGainControlReleaseTime ReleaseTime; MAX9860_AutomaticGainControlAttackTime AttackTime; MAX9860_AutomaticGainControlHoldTime HoldTime; uint8_t NoiseGateThreshold; uint8_t AutomaticGainControlThreshold; } MAX9860_AutomaticGainControlAndNoiseGateState; typedef struct { bool FullPowerOn; bool DAC_Enabled; bool ADC_EnabledLeft; bool ADC_EnabledRight; } MAX9860_PowerManagementState; typedef struct { MAX9860_DigitalFiltersState filters; MAX9860_DigitalLevelControlState levelControl; MAX9860_MicrophoneInputState microphoneGains; MAX9860_AutomaticGainControlAndNoiseGateState autoGainAndNoiseGate; } MAX9860_ComplexAudioConfig; uint16_t xAudioCodecDebugGetRAW(tI2cIO *i2c, uint8_t *raw); uint16_t xAudioCodecDebugSetRAW(tI2cIO *i2c, uint8_t *raw); uint16_t xAudioCodecReadStatus(tI2cIO *i2c, uint8_t statuses[3]); bool xAudioCodecSetClock(tI2cIO *i2c, MAX9860_ClocksState clocksState); bool xAudioCodecSetInterface(tI2cIO *i2c, MAX9860_AudioInterfaceState interface); bool xAudioCodecSetDigitalFilters(tI2cIO *i2c, MAX9860_DigitalFiltersState filters); bool xAudioCodecSetDigitalLevelControls(tI2cIO *i2c, MAX9860_DigitalLevelControlState levels); bool xAudioCodecSetMicrophoneInput(tI2cIO *i2c, MAX9860_MicrophoneInputState micro); bool xAudioCodecSetAutomaticGainControlAndNoiseGate( tI2cIO *i2c, MAX9860_AutomaticGainControlAndNoiseGateState values ); bool xAudioCodecSetPowerManagement(tI2cIO *i2c, MAX9860_PowerManagementState values); #endif //MAX_9860_H