First Publish. Works fine.
Dependents: unzen_sample_nucleo_f746 unzen_delay_sample_nucleo_f746 skeleton_unzen_nucleo_f746 ifmag_noise_canceller ... more
Nucleo F746ZG用のオーディオ・フレームワークです。フレームワーク地震の詳細は『雲仙』オーディオ・フレームワークを参照してください。
参考リンク
- skeleton_unzen_nucleo_f746 Nucleo F746ZGおよびUI基板を使う場合のスケルトンプログラム。F746を使う方はここから読み始めると良いでしょう。
unzen.h@8:63e098b779e9, 2016-05-08 (annotated)
- Committer:
- shorie
- Date:
- Sun May 08 02:15:29 2016 +0000
- Revision:
- 8:63e098b779e9
- Parent:
- 3:707608830793
- Child:
- 9:2da6ce640691
refactored
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shorie | 0:5ac19c994288 | 1 | /** |
shorie | 0:5ac19c994288 | 2 | * \brief header file for the unzen audio frame work |
shorie | 0:5ac19c994288 | 3 | * \arthur SeiichiHorie |
shorie | 0:5ac19c994288 | 4 | * \date 6/Apr/2016 |
shorie | 0:5ac19c994288 | 5 | */ |
shorie | 0:5ac19c994288 | 6 | |
shorie | 0:5ac19c994288 | 7 | #ifndef _unzen_h_ |
shorie | 0:5ac19c994288 | 8 | #define _unzen_h_ |
shorie | 0:5ac19c994288 | 9 | |
shorie | 0:5ac19c994288 | 10 | #include "mbed.h" |
shorie | 0:5ac19c994288 | 11 | /** |
shorie | 0:5ac19c994288 | 12 | \brief audio framework name space. |
shorie | 0:5ac19c994288 | 13 | */ |
shorie | 0:5ac19c994288 | 14 | namespace unzen |
shorie | 0:5ac19c994288 | 15 | { |
shorie | 0:5ac19c994288 | 16 | /** |
shorie | 0:5ac19c994288 | 17 | \brief error status type. |
shorie | 0:5ac19c994288 | 18 | */ |
shorie | 0:5ac19c994288 | 19 | enum error_type { |
shorie | 0:5ac19c994288 | 20 | no_error, |
shorie | 0:5ac19c994288 | 21 | memory_allocation_error |
shorie | 0:5ac19c994288 | 22 | }; |
shorie | 0:5ac19c994288 | 23 | |
shorie | 0:5ac19c994288 | 24 | /** |
shorie | 0:5ac19c994288 | 25 | \brief singleton style audio frame work. Create a object and execute the \ref framework::start() method. |
shorie | 0:5ac19c994288 | 26 | */ |
shorie | 0:5ac19c994288 | 27 | class framework |
shorie | 0:5ac19c994288 | 28 | { |
shorie | 0:5ac19c994288 | 29 | private: |
shorie | 0:5ac19c994288 | 30 | /** |
shorie | 0:5ac19c994288 | 31 | \constructor |
shorie | 0:5ac19c994288 | 32 | \details |
shorie | 0:5ac19c994288 | 33 | initialize the internal variables and set up all interrrupt / I2S related peripheral. |
shorie | 0:5ac19c994288 | 34 | If needed, power up the peripheral, assign the clock and pins. |
shorie | 0:5ac19c994288 | 35 | At the end of this constructor, the audio framework is ready to run, but still paused. |
shorie | 0:5ac19c994288 | 36 | To start the real processing, call the \ref start method. |
shorie | 0:5ac19c994288 | 37 | |
shorie | 0:5ac19c994288 | 38 | Note that this constructor set the block size ( interval count which audio processing |
shorie | 0:5ac19c994288 | 39 | call back is called ) |
shorie | 0:5ac19c994288 | 40 | as 1. If it is needed to use other value, call \ref set_brock_size() method. |
shorie | 0:5ac19c994288 | 41 | */ |
shorie | 0:5ac19c994288 | 42 | framework(void); |
shorie | 0:5ac19c994288 | 43 | public: |
shorie | 0:5ac19c994288 | 44 | /** |
shorie | 0:5ac19c994288 | 45 | \brief getting the singleton object for processing. |
shorie | 0:5ac19c994288 | 46 | \returns a framework type object. |
shorie | 0:5ac19c994288 | 47 | \details |
shorie | 0:5ac19c994288 | 48 | TO call the object method, use this method to retrieve the singleton object. |
shorie | 0:5ac19c994288 | 49 | */ |
shorie | 1:9710fb328a08 | 50 | static framework * get() { static framework singleton; return &singleton ; } |
shorie | 0:5ac19c994288 | 51 | |
shorie | 0:5ac19c994288 | 52 | /** |
shorie | 0:5ac19c994288 | 53 | \brief set the interval interrupt count for each time call back is called. |
shorie | 0:5ac19c994288 | 54 | \param block_size An integer parameter > 1. If set to n, for each n interrupts, the audio call back is called. |
shorie | 0:5ac19c994288 | 55 | \returns show the error status |
shorie | 0:5ac19c994288 | 56 | \details |
shorie | 0:5ac19c994288 | 57 | This method re-allocate the internal buffer. Then, the memory allocation error could occur. To detect the |
shorie | 0:5ac19c994288 | 58 | memory allocation error, use \ref get_error() method. |
shorie | 0:5ac19c994288 | 59 | */ |
shorie | 0:5ac19c994288 | 60 | error_type set_block_size( unsigned int new_block_size ); |
shorie | 0:5ac19c994288 | 61 | |
shorie | 0:5ac19c994288 | 62 | /** |
shorie | 0:5ac19c994288 | 63 | \brief the real audio signal transfer. Trigger the I2S interrupt and call the call back. |
shorie | 0:5ac19c994288 | 64 | */ |
shorie | 0:5ac19c994288 | 65 | void start(void); |
shorie | 0:5ac19c994288 | 66 | |
shorie | 0:5ac19c994288 | 67 | /** |
shorie | 0:5ac19c994288 | 68 | \brief Set the user call back for audio processing. |
shorie | 0:5ac19c994288 | 69 | \param cb The call back function |
shorie | 0:5ac19c994288 | 70 | \details |
shorie | 0:5ac19c994288 | 71 | Set the call back function. This function is called for each time the rx buffer is filled. The call back has 5 parameters. |
shorie | 0:5ac19c994288 | 72 | \li left_rx Received data from I2S rx port. Left data only. |
shorie | 0:5ac19c994288 | 73 | \li right_rx Received data from I2S rx port. Right data only. |
shorie | 0:5ac19c994288 | 74 | \li left_tx Buffer to fill the transmission data. This buffer mus be filled by call back. Left data only |
shorie | 0:5ac19c994288 | 75 | \li right_tx Buffer to fill the transmission data. This buffer mus be filled by call back. Right data only |
shorie | 0:5ac19c994288 | 76 | \li length length of above buffers. |
shorie | 0:5ac19c994288 | 77 | |
shorie | 0:5ac19c994288 | 78 | The call back is called for each time interrupt comes n times. Where n is the value which is specified by \ref set_block_size() |
shorie | 2:6613e62da521 | 79 | function. This n is also passed to call back as above length parameter. By default, n is 1. |
shorie | 0:5ac19c994288 | 80 | |
shorie | 0:5ac19c994288 | 81 | Note that the call back is called at interrupt context. Not the thread level context. |
shorie | 2:6613e62da521 | 82 | That mean, it is better to avoid to call mbed API except the mbed-RTOS API for interrupt handler. |
shorie | 2:6613e62da521 | 83 | |
shorie | 0:5ac19c994288 | 84 | */ |
shorie | 0:5ac19c994288 | 85 | void set_process_callback( void (* cb ) (float[], float[], float[], float[], unsigned int)); |
shorie | 0:5ac19c994288 | 86 | |
shorie | 0:5ac19c994288 | 87 | /** |
shorie | 0:5ac19c994288 | 88 | \brief Debug hook for interrupt handler. |
shorie | 0:5ac19c994288 | 89 | \param cb A call back which is called at the beggining of I2S interrupt. |
shorie | 0:5ac19c994288 | 90 | \details |
shorie | 0:5ac19c994288 | 91 | Parameter cb is call at the beggining of the I2S interrupt. This call back can be |
shorie | 0:5ac19c994288 | 92 | used to mesure the timing of interrupt by toggling the GPIO pin. |
shorie | 0:5ac19c994288 | 93 | |
shorie | 0:5ac19c994288 | 94 | Passing 0 to cb parameter let the framwork ignore the callback. |
shorie | 0:5ac19c994288 | 95 | */ |
shorie | 0:5ac19c994288 | 96 | void set_pre_interrupt_callback( void (* cb ) (void)); |
shorie | 0:5ac19c994288 | 97 | |
shorie | 0:5ac19c994288 | 98 | /** |
shorie | 0:5ac19c994288 | 99 | \brief Debug hook for interrupt handler. |
shorie | 0:5ac19c994288 | 100 | \param cb A call back which is called at the end of I2S interrupt. |
shorie | 0:5ac19c994288 | 101 | \details |
shorie | 0:5ac19c994288 | 102 | Parameter cb is call at the end of the I2S interrupt. This call back can be |
shorie | 0:5ac19c994288 | 103 | used to mesure the timing of interrupt by toggling the GPIO pin. |
shorie | 0:5ac19c994288 | 104 | |
shorie | 0:5ac19c994288 | 105 | Passing 0 to cb parameter let the framwork ignore the callback. |
shorie | 0:5ac19c994288 | 106 | */ |
shorie | 0:5ac19c994288 | 107 | void set_post_interrupt_callback( void (* cb ) (void)); |
shorie | 0:5ac19c994288 | 108 | |
shorie | 0:5ac19c994288 | 109 | /** |
shorie | 0:5ac19c994288 | 110 | \brief Debug hook for processing handler. |
shorie | 0:5ac19c994288 | 111 | \param cb A call back which is called at the beggining of processing. |
shorie | 0:5ac19c994288 | 112 | \details |
shorie | 0:5ac19c994288 | 113 | Parameter cb is call at the beggining of the signal processing. This call back can be |
shorie | 0:5ac19c994288 | 114 | used to mesure the load of CPU by toggling the GPIO pin. |
shorie | 0:5ac19c994288 | 115 | |
shorie | 0:5ac19c994288 | 116 | Passing 0 to cb parameter let the framwork ignore the callback. |
shorie | 0:5ac19c994288 | 117 | */ |
shorie | 0:5ac19c994288 | 118 | void set_pre_process_callback( void (* cb ) (void)); |
shorie | 0:5ac19c994288 | 119 | |
shorie | 0:5ac19c994288 | 120 | /** |
shorie | 0:5ac19c994288 | 121 | \brief Debug hook for processing handler. |
shorie | 0:5ac19c994288 | 122 | \param cb A call back which is called at the end of processing. |
shorie | 0:5ac19c994288 | 123 | \details |
shorie | 0:5ac19c994288 | 124 | Parameter cb is call at the end of the signal processing. This call back can be |
shorie | 0:5ac19c994288 | 125 | used to mesure the load of CPU by toggling the GPIO pin. |
shorie | 0:5ac19c994288 | 126 | |
shorie | 0:5ac19c994288 | 127 | Passing 0 to cb parameter let the framwork ignore the callback. |
shorie | 0:5ac19c994288 | 128 | */ |
shorie | 0:5ac19c994288 | 129 | void set_post_process_callback( void (* cb ) (void)); |
shorie | 0:5ac19c994288 | 130 | |
shorie | 0:5ac19c994288 | 131 | /** |
shorie | 0:5ac19c994288 | 132 | \brief optional priority control for I2S IRQ. |
shorie | 0:5ac19c994288 | 133 | \param pri Priority of IRQ. |
shorie | 0:5ac19c994288 | 134 | \details |
shorie | 0:5ac19c994288 | 135 | This is optional control. Usually, user doesn't need to call this method. |
shorie | 0:5ac19c994288 | 136 | In case the framework has serious irq priority contention with other software, |
shorie | 0:5ac19c994288 | 137 | this API help programmer to change the priority of the Unzen framework. |
shorie | 0:5ac19c994288 | 138 | |
shorie | 0:5ac19c994288 | 139 | Value must be acceptable to CMSIS NVIC_SetPriority(). For LPC4337, it is range of 0..7. The 0 is highest priority. |
shorie | 0:5ac19c994288 | 140 | |
shorie | 0:5ac19c994288 | 141 | |
shorie | 0:5ac19c994288 | 142 | By default, the framework set this priority as +2 higher than the lowest. |
shorie | 0:5ac19c994288 | 143 | |
shorie | 0:5ac19c994288 | 144 | The priority set by this API must be higher than priority set by \ref set_process_irq_priority |
shorie | 0:5ac19c994288 | 145 | */ |
shorie | 0:5ac19c994288 | 146 | void set_i2s_irq_priority( unsigned int pri ); |
shorie | 0:5ac19c994288 | 147 | |
shorie | 0:5ac19c994288 | 148 | /** |
shorie | 0:5ac19c994288 | 149 | \brief optional priority control for Signal Processing IRQ. |
shorie | 0:5ac19c994288 | 150 | \param pri Priority of IRQ. |
shorie | 0:5ac19c994288 | 151 | \details |
shorie | 0:5ac19c994288 | 152 | This is optional control. Usually, user doesn't need to call this method. |
shorie | 0:5ac19c994288 | 153 | In case the framework has serious irq priority contention with other software, |
shorie | 0:5ac19c994288 | 154 | this API help programmer to change the priority of the Unzen framework |
shorie | 0:5ac19c994288 | 155 | |
shorie | 0:5ac19c994288 | 156 | Value must be acceptable to CMSIS NVIC_SetPriority(). For LPC4337, it is range of 0..7. The 0 is highest priority. |
shorie | 0:5ac19c994288 | 157 | |
shorie | 0:5ac19c994288 | 158 | By default, the framework set this priority as +2 higher than the lowest. |
shorie | 0:5ac19c994288 | 159 | |
shorie | 0:5ac19c994288 | 160 | */ |
shorie | 0:5ac19c994288 | 161 | void set_process_irq_priority( unsigned int pri ); |
shorie | 0:5ac19c994288 | 162 | |
shorie | 0:5ac19c994288 | 163 | private: |
shorie | 0:5ac19c994288 | 164 | void (* pre_interrupt_callback )(void); |
shorie | 0:5ac19c994288 | 165 | void (* post_interrupt_callback )(void); |
shorie | 0:5ac19c994288 | 166 | void (* pre_process_callback )(void); |
shorie | 0:5ac19c994288 | 167 | void (* post_process_callback )(void); |
shorie | 0:5ac19c994288 | 168 | |
shorie | 0:5ac19c994288 | 169 | void (* process_callback )( float left_in[], float right_in[], float left_out[], float right_out[], unsigned int length ); |
shorie | 0:5ac19c994288 | 170 | |
shorie | 2:6613e62da521 | 171 | // Size of the blocks ( interval of interrupt to call process_callback. 1 means every interrupt. 2 means every 2 interrupt ) |
shorie | 0:5ac19c994288 | 172 | int block_size; |
shorie | 0:5ac19c994288 | 173 | |
shorie | 2:6613e62da521 | 174 | // Index for indentifying the buffer for interrupt. 0 or 1. |
shorie | 2:6613e62da521 | 175 | int buffer_index; |
shorie | 0:5ac19c994288 | 176 | |
shorie | 2:6613e62da521 | 177 | // Index for indentifying the buffer for processing. 0 or 1. |
shorie | 2:6613e62da521 | 178 | int process_index; |
shorie | 2:6613e62da521 | 179 | |
shorie | 2:6613e62da521 | 180 | // next transfer position in buffer |
shorie | 2:6613e62da521 | 181 | int sample_index; |
shorie | 0:5ac19c994288 | 182 | |
shorie | 0:5ac19c994288 | 183 | // buffer for interrupt handler. |
shorie | 0:5ac19c994288 | 184 | // data format is LRLR... |
shorie | 0:5ac19c994288 | 185 | int *tx_int_buffer[2]; |
shorie | 0:5ac19c994288 | 186 | int *rx_int_buffer[2]; |
shorie | 0:5ac19c994288 | 187 | |
shorie | 0:5ac19c994288 | 188 | // buffers for passing |
shorie | 0:5ac19c994288 | 189 | float * tx_left_buffer, * tx_right_buffer; |
shorie | 0:5ac19c994288 | 190 | float * rx_left_buffer, * rx_right_buffer; |
shorie | 0:5ac19c994288 | 191 | |
shorie | 0:5ac19c994288 | 192 | // real processing method. |
shorie | 0:5ac19c994288 | 193 | void do_i2s_irq(void); |
shorie | 0:5ac19c994288 | 194 | void do_process_irq(void); |
shorie | 0:5ac19c994288 | 195 | |
shorie | 0:5ac19c994288 | 196 | // handler for NIVC |
shorie | 0:5ac19c994288 | 197 | static void i2s_irq_handler(); |
shorie | 0:5ac19c994288 | 198 | static void process_irq_handler(); |
shorie | 0:5ac19c994288 | 199 | }; |
shorie | 1:9710fb328a08 | 200 | |
shorie | 2:6613e62da521 | 201 | // Sampling Frequency of the umb_adau1361 |
shorie | 2:6613e62da521 | 202 | enum Fs_Type |
shorie | 2:6613e62da521 | 203 | { |
shorie | 3:707608830793 | 204 | Fs_32, Fs_441, Fs_48, Fs_96 |
shorie | 2:6613e62da521 | 205 | } ; |
shorie | 2:6613e62da521 | 206 | |
shorie | 2:6613e62da521 | 207 | |
shorie | 3:707608830793 | 208 | /** |
shorie | 8:63e098b779e9 | 209 | * \brief abstract audio codec controller. |
shorie | 3:707608830793 | 210 | * \details |
shorie | 8:63e098b779e9 | 211 | * This class is template for all codec classes |
shorie | 3:707608830793 | 212 | */ |
shorie | 8:63e098b779e9 | 213 | class codec_class |
shorie | 8:63e098b779e9 | 214 | { |
shorie | 8:63e098b779e9 | 215 | public: |
shorie | 8:63e098b779e9 | 216 | /** |
shorie | 8:63e098b779e9 | 217 | * \brief constructor. |
shorie | 8:63e098b779e9 | 218 | * \param controler Pass the I2C controler object. |
shorie | 8:63e098b779e9 | 219 | * \param Fs Sampling frequency. |
shorie | 8:63e098b779e9 | 220 | * \param Addr I2C device address. value range is from 0 to 127 |
shorie | 8:63e098b779e9 | 221 | * \details |
shorie | 8:63e098b779e9 | 222 | * initialize the internal variables. |
shorie | 8:63e098b779e9 | 223 | */ |
shorie | 8:63e098b779e9 | 224 | codec_class( I2C * controler, Fs_Type Fs, unsigned int Addr ); |
shorie | 8:63e098b779e9 | 225 | |
shorie | 8:63e098b779e9 | 226 | /** |
shorie | 8:63e098b779e9 | 227 | * \brief Actual initializer. |
shorie | 8:63e098b779e9 | 228 | * \details |
shorie | 8:63e098b779e9 | 229 | * Initialize the codec itself and start the conversion process. |
shorie | 8:63e098b779e9 | 230 | * and configure for given parameter. |
shorie | 8:63e098b779e9 | 231 | * |
shorie | 8:63e098b779e9 | 232 | * Finally, set the input gain to 0dB. |
shorie | 8:63e098b779e9 | 233 | */ |
shorie | 8:63e098b779e9 | 234 | virtual void start(void)=0; |
shorie | 8:63e098b779e9 | 235 | |
shorie | 8:63e098b779e9 | 236 | /** |
shorie | 8:63e098b779e9 | 237 | * \brief Set the line input gain and enable the relevant mixer. |
shorie | 8:63e098b779e9 | 238 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 239 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 240 | * \param mute set true to mute |
shorie | 8:63e098b779e9 | 241 | */ |
shorie | 8:63e098b779e9 | 242 | virtual void set_line_input_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 8:63e098b779e9 | 243 | /** |
shorie | 8:63e098b779e9 | 244 | * \brief Set the aux input gain and enable the relevant mixer. |
shorie | 8:63e098b779e9 | 245 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 246 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 247 | * \param mute set true to mute |
shorie | 8:63e098b779e9 | 248 | */ |
shorie | 8:63e098b779e9 | 249 | virtual void set_aux_input_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 8:63e098b779e9 | 250 | /** |
shorie | 8:63e098b779e9 | 251 | * \brief Set the mic input gain and enable the relevant mixer. |
shorie | 8:63e098b779e9 | 252 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 253 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 254 | * \param mute set true to mute |
shorie | 8:63e098b779e9 | 255 | */ |
shorie | 8:63e098b779e9 | 256 | virtual void set_mic_input_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 8:63e098b779e9 | 257 | /** |
shorie | 8:63e098b779e9 | 258 | * \brief Set the line output gain and enable the relevant mixer. |
shorie | 8:63e098b779e9 | 259 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 260 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 261 | * \param mute set true to mute |
shorie | 8:63e098b779e9 | 262 | */ |
shorie | 8:63e098b779e9 | 263 | virtual void set_line_output_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 8:63e098b779e9 | 264 | /** |
shorie | 8:63e098b779e9 | 265 | * \brief Set the headphone output gain and enable the relevant mixer. |
shorie | 8:63e098b779e9 | 266 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 267 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 268 | * \param mute set true to mute |
shorie | 8:63e098b779e9 | 269 | */ |
shorie | 8:63e098b779e9 | 270 | virtual void set_hp_output_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 8:63e098b779e9 | 271 | protected: |
shorie | 8:63e098b779e9 | 272 | I2C *i2c; |
shorie | 8:63e098b779e9 | 273 | unsigned int addr; |
shorie | 8:63e098b779e9 | 274 | Fs_Type fs; |
shorie | 8:63e098b779e9 | 275 | }; |
shorie | 8:63e098b779e9 | 276 | |
shorie | 8:63e098b779e9 | 277 | |
shorie | 8:63e098b779e9 | 278 | /** |
shorie | 8:63e098b779e9 | 279 | * \brief ADAU1361 audio codec controller. |
shorie | 8:63e098b779e9 | 280 | * \details |
shorie | 8:63e098b779e9 | 281 | * This class sends a set of command to control an ADAU1361 codec. |
shorie | 8:63e098b779e9 | 282 | * This class is template for all ADAU1361 based codec board. |
shorie | 8:63e098b779e9 | 283 | */ |
shorie | 8:63e098b779e9 | 284 | class adau1361:public codec_class |
shorie | 1:9710fb328a08 | 285 | { |
shorie | 1:9710fb328a08 | 286 | public: |
shorie | 2:6613e62da521 | 287 | /** |
shorie | 2:6613e62da521 | 288 | * \brief constructor. |
shorie | 2:6613e62da521 | 289 | * \param controler Pass the I2C controler object. |
shorie | 2:6613e62da521 | 290 | * \param Fs Sampling frequency. |
shorie | 8:63e098b779e9 | 291 | * \param Addr I2C device address. value range is from 0 to 127 |
shorie | 2:6613e62da521 | 292 | * \details |
shorie | 2:6613e62da521 | 293 | * initialize the internal variables. |
shorie | 2:6613e62da521 | 294 | */ |
shorie | 8:63e098b779e9 | 295 | adau1361( I2C * controler, Fs_Type Fs, unsigned int Addr ): |
shorie | 8:63e098b779e9 | 296 | codec_class( controler, Fs, Addr ){}; |
shorie | 8:63e098b779e9 | 297 | virtual void start(void); |
shorie | 8:63e098b779e9 | 298 | /** |
shorie | 8:63e098b779e9 | 299 | * \brief Set the line input gain and enable the relevant mixer. |
shorie | 8:63e098b779e9 | 300 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 301 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 302 | * \param mute set true to mute |
shorie | 8:63e098b779e9 | 303 | */ |
shorie | 8:63e098b779e9 | 304 | virtual void set_line_input_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 8:63e098b779e9 | 305 | /** |
shorie | 8:63e098b779e9 | 306 | * \brief Set the aux input gain and enable the relevant mixer. |
shorie | 8:63e098b779e9 | 307 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 308 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 309 | * \param mute set true to mute |
shorie | 8:63e098b779e9 | 310 | */ |
shorie | 8:63e098b779e9 | 311 | virtual void set_aux_input_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 8:63e098b779e9 | 312 | /** |
shorie | 8:63e098b779e9 | 313 | * \brief Set the line output gain and enable the relevant mixer. |
shorie | 8:63e098b779e9 | 314 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 315 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 316 | * \param mute set true to mute |
shorie | 8:63e098b779e9 | 317 | */ |
shorie | 8:63e098b779e9 | 318 | virtual void set_line_output_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 8:63e098b779e9 | 319 | /** |
shorie | 8:63e098b779e9 | 320 | * \brief Set the headphone output gain and enable the relevant mixer. |
shorie | 8:63e098b779e9 | 321 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 322 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 8:63e098b779e9 | 323 | * \param mute set true to mute |
shorie | 8:63e098b779e9 | 324 | */ |
shorie | 8:63e098b779e9 | 325 | virtual void set_hp_output_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 2:6613e62da521 | 326 | |
shorie | 8:63e098b779e9 | 327 | protected: |
shorie | 8:63e098b779e9 | 328 | virtual void configure_pll(void)=0; |
shorie | 8:63e098b779e9 | 329 | virtual void configure_board(void)=0; |
shorie | 2:6613e62da521 | 330 | /** |
shorie | 8:63e098b779e9 | 331 | * Service function for the ADAu1361 board implementer. |
shorie | 8:63e098b779e9 | 332 | * |
shorie | 8:63e098b779e9 | 333 | * \brief send one command to ADAU1361. |
shorie | 8:63e098b779e9 | 334 | * \param command command data array. It have to have register addess of ADAU1361 in first two bytes. |
shorie | 8:63e098b779e9 | 335 | * \param size number of bytes in the command, including the regsiter address. |
shorie | 2:6613e62da521 | 336 | * \details |
shorie | 8:63e098b779e9 | 337 | * Send one complete command to ADAU3161 by I2C. |
shorie | 8:63e098b779e9 | 338 | */ |
shorie | 8:63e098b779e9 | 339 | virtual void send_command( const char command[], int size ); |
shorie | 8:63e098b779e9 | 340 | /** |
shorie | 8:63e098b779e9 | 341 | * \brief send one command to ADAU1361. |
shorie | 8:63e098b779e9 | 342 | * \param table command table. All commands are stored in one row. Each row has only 1 byte data after reg address. |
shorie | 8:63e098b779e9 | 343 | * \param rows number of the rows in the table. |
shorie | 8:63e098b779e9 | 344 | * \details |
shorie | 8:63e098b779e9 | 345 | * Service function for the ADAu1361 board implementer. |
shorie | 2:6613e62da521 | 346 | * |
shorie | 8:63e098b779e9 | 347 | * Send a list of command to ADAU1361. All commands has 3 bytes length. That mean, after two byte register |
shorie | 8:63e098b779e9 | 348 | * address, only 1 byte data payload is allowed. Commadns are sent by I2C |
shorie | 2:6613e62da521 | 349 | */ |
shorie | 8:63e098b779e9 | 350 | virtual void send_command_table( const char table[][3], int rows); |
shorie | 2:6613e62da521 | 351 | |
shorie | 2:6613e62da521 | 352 | /** |
shorie | 8:63e098b779e9 | 353 | * \brief wait until PLL locks. |
shorie | 8:63e098b779e9 | 354 | * \details |
shorie | 8:63e098b779e9 | 355 | * Service function for the ADAu1361 board implementer. |
shorie | 8:63e098b779e9 | 356 | * |
shorie | 8:63e098b779e9 | 357 | * Read the PLL status and repeat it until the PLL locks. |
shorie | 3:707608830793 | 358 | */ |
shorie | 8:63e098b779e9 | 359 | virtual void wait_pll_lock(void); |
shorie | 8:63e098b779e9 | 360 | }; |
shorie | 8:63e098b779e9 | 361 | |
shorie | 8:63e098b779e9 | 362 | /** |
shorie | 8:63e098b779e9 | 363 | * \brief UMB-ADAU1361-A audio codec board controller. |
shorie | 8:63e098b779e9 | 364 | * \details |
shorie | 8:63e098b779e9 | 365 | * This class send a set of command to control an UMB-ADAU1361-A codec board. |
shorie | 8:63e098b779e9 | 366 | * |
shorie | 8:63e098b779e9 | 367 | * The hardware desription is here. http://dsps.shop-pro.jp/?pid=82798273 |
shorie | 8:63e098b779e9 | 368 | */ |
shorie | 8:63e098b779e9 | 369 | class umb_adau1361a:public adau1361 |
shorie | 8:63e098b779e9 | 370 | { |
shorie | 8:63e098b779e9 | 371 | public: |
shorie | 3:707608830793 | 372 | /** |
shorie | 8:63e098b779e9 | 373 | * \brief constructor. |
shorie | 8:63e098b779e9 | 374 | * \param controler Pass the I2C controler object. |
shorie | 8:63e098b779e9 | 375 | * \param Fs Sampling frequency. |
shorie | 8:63e098b779e9 | 376 | * \param Addr I2C device address. value range is from 0 to 127 |
shorie | 8:63e098b779e9 | 377 | * \details |
shorie | 8:63e098b779e9 | 378 | * initialize the internal variables. |
shorie | 3:707608830793 | 379 | */ |
shorie | 8:63e098b779e9 | 380 | umb_adau1361a( I2C * controler, Fs_Type Fs = unzen::Fs_48, unsigned int Addr=0x38 ): |
shorie | 8:63e098b779e9 | 381 | adau1361( controler, Fs, Addr ){}; |
shorie | 8:63e098b779e9 | 382 | protected: |
shorie | 8:63e098b779e9 | 383 | /** |
shorie | 8:63e098b779e9 | 384 | * \brief configuration of the PLL for the desired Fs. |
shorie | 8:63e098b779e9 | 385 | * \details |
shorie | 8:63e098b779e9 | 386 | * Configure the PLL based on the given Fs and hardware clock configuration. |
shorie | 8:63e098b779e9 | 387 | * Fs is stored in fs member variable already. Hadrware clock have to be given |
shorie | 8:63e098b779e9 | 388 | * from the circuit designer. For the UMB-ADAU1361-A, the clock is external |
shorie | 8:63e098b779e9 | 389 | * 12MHz oscillator from the clock input. |
shorie | 8:63e098b779e9 | 390 | */ |
shorie | 8:63e098b779e9 | 391 | virtual void configure_pll(void); |
shorie | 8:63e098b779e9 | 392 | /** |
shorie | 8:63e098b779e9 | 393 | * \brief configuration of the the codec for UMB-ADAU1361-A |
shorie | 8:63e098b779e9 | 394 | * \details |
shorie | 8:63e098b779e9 | 395 | * Configure Internal signal pass and parameters for UMB-ADAU1361. |
shorie | 8:63e098b779e9 | 396 | * The all pass-through signals are shut off. All cross channel signals are shut off. |
shorie | 8:63e098b779e9 | 397 | * Monoral output is disabled. |
shorie | 8:63e098b779e9 | 398 | */ |
shorie | 8:63e098b779e9 | 399 | virtual void configure_board(void); |
shorie | 1:9710fb328a08 | 400 | }; |
shorie | 1:9710fb328a08 | 401 | |
shorie | 8:63e098b779e9 | 402 | |
shorie | 8:63e098b779e9 | 403 | |
shorie | 0:5ac19c994288 | 404 | } |
shorie | 0:5ac19c994288 | 405 | |
shorie | 0:5ac19c994288 | 406 | #endif |