First Publish. Works fine.
Dependents: unzen_sample_LPC4088_quickstart
Diff: unzen.h
- Revision:
- 8:63e098b779e9
- Parent:
- 3:707608830793
- Child:
- 9:2da6ce640691
--- a/unzen.h Sat May 07 21:17:40 2016 +0000 +++ b/unzen.h Sun May 08 02:15:29 2016 +0000 @@ -204,74 +204,203 @@ Fs_32, Fs_441, Fs_48, Fs_96 } ; - // mbed I2C class needs the address as "left justified" value. Then, the ADAU1361's address 0x38 is - // shifted right by 1 bit - enum Addr_Type - { - addr_h70 = 0x70, - addr_h71, - addr_h72, - addr_h73 - } ; /** -* \brief UMB-ADAU1361-A controller. +* \brief abstract audio codec controller. * \details -* This class send a set of command to control the UMB-ADAU1361-A board. -* See http://dsps.shop-pro.jp/?pid=82798273 for detatails. This board -* uses 12MHz clock. This controler set the codec as master mode. +* This class is template for all codec classes */ - class umb_adau1361 + class codec_class + { + public: + /** + * \brief constructor. + * \param controler Pass the I2C controler object. + * \param Fs Sampling frequency. + * \param Addr I2C device address. value range is from 0 to 127 + * \details + * initialize the internal variables. + */ + codec_class( I2C * controler, Fs_Type Fs, unsigned int Addr ); + + /** + * \brief Actual initializer. + * \details + * Initialize the codec itself and start the conversion process. + * and configure for given parameter. + * + * Finally, set the input gain to 0dB. + */ + virtual void start(void)=0; + + /** + * \brief Set the line input gain and enable the relevant mixer. + * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param mute set true to mute + */ + virtual void set_line_input_gain(float left_gain, float right_gain, bool mute=false); + /** + * \brief Set the aux input gain and enable the relevant mixer. + * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param mute set true to mute + */ + virtual void set_aux_input_gain(float left_gain, float right_gain, bool mute=false); + /** + * \brief Set the mic input gain and enable the relevant mixer. + * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param mute set true to mute + */ + virtual void set_mic_input_gain(float left_gain, float right_gain, bool mute=false); + /** + * \brief Set the line output gain and enable the relevant mixer. + * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param mute set true to mute + */ + virtual void set_line_output_gain(float left_gain, float right_gain, bool mute=false); + /** + * \brief Set the headphone output gain and enable the relevant mixer. + * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param mute set true to mute + */ + virtual void set_hp_output_gain(float left_gain, float right_gain, bool mute=false); + protected: + I2C *i2c; + unsigned int addr; + Fs_Type fs; + }; + + +/** +* \brief ADAU1361 audio codec controller. +* \details +* This class sends a set of command to control an ADAU1361 codec. +* This class is template for all ADAU1361 based codec board. +*/ + class adau1361:public codec_class { public: /** * \brief constructor. * \param controler Pass the I2C controler object. * \param Fs Sampling frequency. - * \param Addr I2C device address. + * \param Addr I2C device address. value range is from 0 to 127 * \details * initialize the internal variables. */ - umb_adau1361( I2C * controler, Fs_Type Fs= unzen::Fs_48, Addr_Type Addr = unzen::addr_h70 ); + adau1361( I2C * controler, Fs_Type Fs, unsigned int Addr ): + codec_class( controler, Fs, Addr ){}; + virtual void start(void); + /** + * \brief Set the line input gain and enable the relevant mixer. + * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param mute set true to mute + */ + virtual void set_line_input_gain(float left_gain, float right_gain, bool mute=false); + /** + * \brief Set the aux input gain and enable the relevant mixer. + * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param mute set true to mute + */ + virtual void set_aux_input_gain(float left_gain, float right_gain, bool mute=false); + /** + * \brief Set the line output gain and enable the relevant mixer. + * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param mute set true to mute + */ + virtual void set_line_output_gain(float left_gain, float right_gain, bool mute=false); + /** + * \brief Set the headphone output gain and enable the relevant mixer. + * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. + * \param mute set true to mute + */ + virtual void set_hp_output_gain(float left_gain, float right_gain, bool mute=false); + protected: + virtual void configure_pll(void)=0; + virtual void configure_board(void)=0; /** - * \brief Actual initializer. + * Service function for the ADAu1361 board implementer. + * + * \brief send one command to ADAU1361. + * \param command command data array. It have to have register addess of ADAU1361 in first two bytes. + * \param size number of bytes in the command, including the regsiter address. * \details - * Initialize the ADUC1603 as reset state, and then, configure for the UMB-ADAU1361. - * http://dsps.shop-pro.jp/?pid=82798273 - * and configure for given parameter. + * Send one complete command to ADAU3161 by I2C. + */ + virtual void send_command( const char command[], int size ); + /** + * \brief send one command to ADAU1361. + * \param table command table. All commands are stored in one row. Each row has only 1 byte data after reg address. + * \param rows number of the rows in the table. + * \details + * Service function for the ADAu1361 board implementer. * - * Finally, set the input gain to 0dB. + * Send a list of command to ADAU1361. All commands has 3 bytes length. That mean, after two byte register + * address, only 1 byte data payload is allowed. Commadns are sent by I2C */ - void start(void); + virtual void send_command_table( const char table[][3], int rows); /** - * \brief Set the input gain and enable the relevant mixer. - * \param left_gain - * \param right_gain - * \param mute - */ - void set_line_input_gain(float left_gain, float right_gain, bool mute=false); - /** - * \brief Set the line output gain and enable the relevant mixer. - * \param left_gain - * \param right_gain - * \param mute + * \brief wait until PLL locks. + * \details + * Service function for the ADAu1361 board implementer. + * + * Read the PLL status and repeat it until the PLL locks. */ - void set_line_output_gain(float left_gain, float right_gain, bool mute=false); + virtual void wait_pll_lock(void); + }; + +/** +* \brief UMB-ADAU1361-A audio codec board controller. +* \details +* This class send a set of command to control an UMB-ADAU1361-A codec board. +* +* The hardware desription is here. http://dsps.shop-pro.jp/?pid=82798273 +*/ + class umb_adau1361a:public adau1361 + { + public: /** - * \brief Set the headphone output gain and enable the relevant mixer. - * \param left_gain - * \param right_gain - * \param mute + * \brief constructor. + * \param controler Pass the I2C controler object. + * \param Fs Sampling frequency. + * \param Addr I2C device address. value range is from 0 to 127 + * \details + * initialize the internal variables. */ - void set_hp_output_gain(float left_gain, float right_gain, bool mute=false); - private: - I2C *i2c; - Addr_Type addr; - Fs_Type fs; + umb_adau1361a( I2C * controler, Fs_Type Fs = unzen::Fs_48, unsigned int Addr=0x38 ): + adau1361( controler, Fs, Addr ){}; + protected: + /** + * \brief configuration of the PLL for the desired Fs. + * \details + * Configure the PLL based on the given Fs and hardware clock configuration. + * Fs is stored in fs member variable already. Hadrware clock have to be given + * from the circuit designer. For the UMB-ADAU1361-A, the clock is external + * 12MHz oscillator from the clock input. + */ + virtual void configure_pll(void); + /** + * \brief configuration of the the codec for UMB-ADAU1361-A + * \details + * Configure Internal signal pass and parameters for UMB-ADAU1361. + * The all pass-through signals are shut off. All cross channel signals are shut off. + * Monoral output is disabled. + */ + virtual void configure_board(void); }; + + } #endif