First publishment of Shimabara Audio Codec Controller library. Including code for ADAU1361 and UMB-ADAU1361A. Working pretty fine. Checked with LPCXpresso 4337 and Unzen_lpc4337
Dependents: unzen_sample_LPC4088_quickstart unzen_sample_lpcxpresso_4337_callbacks unzen_sample_nucleo_f746 unzen_delay_sample_nucleo_f746 ... more
shimabaraは、mbedからオーディオ・コーデックのハードウェアを操作するクラス・ライブラリです。このライブラリは雲仙オーディオ・フレームワークと共に使うことを想定して開発しましたが、独立して使うことも可能です。
使い方
shimabaraは BaseAudioCodec, ADAU1361, UMB_ADAU1361Aの三つのクラスを定義しています。いずれのクラスも名前空間simabaraに属しています。実際のアプリケーションで使用するのはshimabara::UMB_ADAU1361Aだけで、このクラスはアクアシグナルのUMB-ADAU1361-Aに対応しています。ヘッダーファイルは umb_adau1361a.hです。
shimabara::UMB_ADAU1361Aのコンストラクタは三つの引数を受け取ります。
- Fs はサンプル周波数です。これはenum Fs_type型の引数で、やはり名前空間shimabaraに属しています。
- controller はADAU1361Aが接続されているI2Cポートに対応するI2Cオブジェクトを与えます。shimabaraはこのポートを通してCODECと通信します。
- Addrには、コーデックのI2Cアドレスを与えます。現時点ではこの引数は0x38固定です。
コンストラクタでオブジェクトを初期化したら、start()メソッドを呼んでください。これでshimabaraはコーデックと通信し、I2Sモードでの動作が始まります。
参考リンク
- 『雲仙』 オーディオ・フレームワーク
- skeleton_unzen_nucleo_f746 Nucleo F746ZGおよびUI基板を使う場合のスケルトンプログラム。F746を使う方はここから読み始めると良いでしょう。
adau1361.h@3:c0f834049ee2, 2016-05-14 (annotated)
- Committer:
- shorie
- Date:
- Sat May 14 21:37:32 2016 +0000
- Revision:
- 3:c0f834049ee2
- Parent:
- 2:fba0b8afebf0
- Child:
- 4:a838173c951d
First Publishment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shorie | 3:c0f834049ee2 | 1 | /* |
shorie | 2:fba0b8afebf0 | 2 | * \file adau1361.h |
shorie | 2:fba0b8afebf0 | 3 | * \brief header file for the ADAU1361 codec controler abstract class |
shorie | 1:ea6d442bd68a | 4 | */ |
shorie | 1:ea6d442bd68a | 5 | |
shorie | 1:ea6d442bd68a | 6 | #ifndef _Adau1361_h_ |
shorie | 1:ea6d442bd68a | 7 | #define _Adau1361_h_ |
shorie | 1:ea6d442bd68a | 8 | |
shorie | 1:ea6d442bd68a | 9 | #include "baseaudiocodec.h" |
shorie | 1:ea6d442bd68a | 10 | #include "mbed.h" |
shorie | 1:ea6d442bd68a | 11 | |
shorie | 1:ea6d442bd68a | 12 | /** |
shorie | 1:ea6d442bd68a | 13 | \brief audio framework name space. |
shorie | 1:ea6d442bd68a | 14 | */ |
shorie | 2:fba0b8afebf0 | 15 | namespace shimabara |
shorie | 1:ea6d442bd68a | 16 | { |
shorie | 1:ea6d442bd68a | 17 | |
shorie | 1:ea6d442bd68a | 18 | |
shorie | 1:ea6d442bd68a | 19 | |
shorie | 1:ea6d442bd68a | 20 | /** |
shorie | 1:ea6d442bd68a | 21 | * \brief ADAU1361 audio codec controller. |
shorie | 1:ea6d442bd68a | 22 | * \details |
shorie | 2:fba0b8afebf0 | 23 | * This class sends a set of command to control an ADAU1361 codec. This class is template for all ADAU1361 based codec board. |
shorie | 2:fba0b8afebf0 | 24 | * |
shorie | 2:fba0b8afebf0 | 25 | * To implement the real board, you must override the configure_pll() method and configure_board method. |
shorie | 1:ea6d442bd68a | 26 | */ |
shorie | 1:ea6d442bd68a | 27 | class Adau1361:public BaseAudioCodec |
shorie | 1:ea6d442bd68a | 28 | { |
shorie | 1:ea6d442bd68a | 29 | public: |
shorie | 1:ea6d442bd68a | 30 | /** |
shorie | 1:ea6d442bd68a | 31 | * \brief constructor. |
shorie | 1:ea6d442bd68a | 32 | * \param controler Pass the I2C controler object. |
shorie | 1:ea6d442bd68a | 33 | * \param Fs Sampling frequency. |
shorie | 1:ea6d442bd68a | 34 | * \param Addr I2C device address. value range is from 0 to 127 |
shorie | 1:ea6d442bd68a | 35 | * \details |
shorie | 1:ea6d442bd68a | 36 | * initialize the internal variables. |
shorie | 1:ea6d442bd68a | 37 | */ |
shorie | 2:fba0b8afebf0 | 38 | Adau1361( Fs_Type Fs, I2C * controler, unsigned int Addr ); |
shorie | 2:fba0b8afebf0 | 39 | |
shorie | 2:fba0b8afebf0 | 40 | /** |
shorie | 2:fba0b8afebf0 | 41 | * \brief Set up the ADAU1361 codec, and then, start the codec. |
shorie | 2:fba0b8afebf0 | 42 | * \details |
shorie | 2:fba0b8afebf0 | 43 | * This method starts the ADAU1361 AD/DA conversion and I2S communication. |
shorie | 2:fba0b8afebf0 | 44 | * |
shorie | 2:fba0b8afebf0 | 45 | * The line in is configured to use the Single-End negative input. This is funny but ADAU1361 datasheet |
shorie | 2:fba0b8afebf0 | 46 | * specifies to do it. The positive in and diff in are killed. All biases are set as "normal". |
shorie | 2:fba0b8afebf0 | 47 | * |
shorie | 2:fba0b8afebf0 | 48 | * The CODEC is configured as master mode. That mean, bclk and WS are given from ADAU1361 to the micro processor. |
shorie | 2:fba0b8afebf0 | 49 | */ |
shorie | 1:ea6d442bd68a | 50 | virtual void start(void); |
shorie | 2:fba0b8afebf0 | 51 | |
shorie | 1:ea6d442bd68a | 52 | /** |
shorie | 1:ea6d442bd68a | 53 | * \brief Set the line input gain and enable the relevant mixer. |
shorie | 1:ea6d442bd68a | 54 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 1:ea6d442bd68a | 55 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 1:ea6d442bd68a | 56 | * \param mute set true to mute |
shorie | 2:fba0b8afebf0 | 57 | * \details |
shorie | 2:fba0b8afebf0 | 58 | * As same as start(), this gain control function uses the single-end negative input only. Other |
shorie | 2:fba0b8afebf0 | 59 | * input signal of the line in like positive signal or diff signal are killed. |
shorie | 2:fba0b8afebf0 | 60 | * |
shorie | 2:fba0b8afebf0 | 61 | * Other input line like aux are not killed. To kill it, user have to mute them explicitly. |
shorie | 1:ea6d442bd68a | 62 | */ |
shorie | 1:ea6d442bd68a | 63 | virtual void set_line_input_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 2:fba0b8afebf0 | 64 | |
shorie | 1:ea6d442bd68a | 65 | /** |
shorie | 1:ea6d442bd68a | 66 | * \brief Set the aux input gain and enable the relevant mixer. |
shorie | 1:ea6d442bd68a | 67 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 1:ea6d442bd68a | 68 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 1:ea6d442bd68a | 69 | * \param mute set true to mute |
shorie | 2:fba0b8afebf0 | 70 | * \details |
shorie | 2:fba0b8afebf0 | 71 | * Other input lines are not killed. To kill it, user have to mute them explicitly. |
shorie | 1:ea6d442bd68a | 72 | */ |
shorie | 1:ea6d442bd68a | 73 | virtual void set_aux_input_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 2:fba0b8afebf0 | 74 | |
shorie | 1:ea6d442bd68a | 75 | /** |
shorie | 1:ea6d442bd68a | 76 | * \brief Set the line output gain and enable the relevant mixer. |
shorie | 1:ea6d442bd68a | 77 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 1:ea6d442bd68a | 78 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 1:ea6d442bd68a | 79 | * \param mute set true to mute |
shorie | 2:fba0b8afebf0 | 80 | * \details |
shorie | 2:fba0b8afebf0 | 81 | * Other output lines are not killed. To kill it, user have to mute them explicitly. |
shorie | 2:fba0b8afebf0 | 82 | * |
shorie | 1:ea6d442bd68a | 83 | */ |
shorie | 1:ea6d442bd68a | 84 | virtual void set_line_output_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 2:fba0b8afebf0 | 85 | |
shorie | 1:ea6d442bd68a | 86 | /** |
shorie | 1:ea6d442bd68a | 87 | * \brief Set the headphone output gain and enable the relevant mixer. |
shorie | 1:ea6d442bd68a | 88 | * \param left_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 1:ea6d442bd68a | 89 | * \param right_gain Gain by dB. The gain value outside of the acceptable range will be saturated. |
shorie | 1:ea6d442bd68a | 90 | * \param mute set true to mute |
shorie | 2:fba0b8afebf0 | 91 | * \details |
shorie | 2:fba0b8afebf0 | 92 | * Other out line like line in are not killed. To kill it, user have to mute them explicitly. |
shorie | 1:ea6d442bd68a | 93 | */ |
shorie | 1:ea6d442bd68a | 94 | virtual void set_hp_output_gain(float left_gain, float right_gain, bool mute=false); |
shorie | 1:ea6d442bd68a | 95 | |
shorie | 1:ea6d442bd68a | 96 | protected: |
shorie | 2:fba0b8afebf0 | 97 | I2C *i2c; |
shorie | 2:fba0b8afebf0 | 98 | unsigned int addr; |
shorie | 2:fba0b8afebf0 | 99 | |
shorie | 2:fba0b8afebf0 | 100 | /** |
shorie | 2:fba0b8afebf0 | 101 | * \brief configuration of PLL for the desired core clock |
shorie | 2:fba0b8afebf0 | 102 | * \details |
shorie | 2:fba0b8afebf0 | 103 | * A pure virutal function. |
shorie | 2:fba0b8afebf0 | 104 | * |
shorie | 2:fba0b8afebf0 | 105 | * This member function must be overriden by inherited class. Before the call of this function, |
shorie | 2:fba0b8afebf0 | 106 | * R0 is initialized as 0 and then, set the clock source is PLL. |
shorie | 2:fba0b8afebf0 | 107 | * |
shorie | 2:fba0b8afebf0 | 108 | * This member funciton must configure the PLL correctly, confirm the PLL lock status. And then |
shorie | 2:fba0b8afebf0 | 109 | * set the SRC. |
shorie | 2:fba0b8afebf0 | 110 | * |
shorie | 2:fba0b8afebf0 | 111 | * Note that the setting SRC before PLL lock may fail. |
shorie | 2:fba0b8afebf0 | 112 | */ |
shorie | 1:ea6d442bd68a | 113 | virtual void configure_pll(void)=0; |
shorie | 2:fba0b8afebf0 | 114 | |
shorie | 2:fba0b8afebf0 | 115 | /** |
shorie | 2:fba0b8afebf0 | 116 | * \brief configuration of the ADAU1361 for the codec board |
shorie | 2:fba0b8afebf0 | 117 | * \details |
shorie | 2:fba0b8afebf0 | 118 | * A pure virutal function. |
shorie | 2:fba0b8afebf0 | 119 | * |
shorie | 2:fba0b8afebf0 | 120 | * This member function must be overriden by inherited class. Before the calling of this function, |
shorie | 2:fba0b8afebf0 | 121 | * the codec is initialized as default state except PLL. PLL is set by configure_pll() method |
shorie | 2:fba0b8afebf0 | 122 | * before calling this function. |
shorie | 2:fba0b8afebf0 | 123 | * |
shorie | 2:fba0b8afebf0 | 124 | * This member funciton must configure the ADAU1361 registered based on the board circuit. For example, |
shorie | 2:fba0b8afebf0 | 125 | * internal signal pass or bias. |
shorie | 2:fba0b8afebf0 | 126 | * |
shorie | 2:fba0b8afebf0 | 127 | */ |
shorie | 1:ea6d442bd68a | 128 | virtual void configure_board(void)=0; |
shorie | 1:ea6d442bd68a | 129 | /** |
shorie | 1:ea6d442bd68a | 130 | * Service function for the ADAu1361 board implementer. |
shorie | 1:ea6d442bd68a | 131 | * |
shorie | 1:ea6d442bd68a | 132 | * \brief send one command to ADAU1361. |
shorie | 1:ea6d442bd68a | 133 | * \param command command data array. It have to have register addess of ADAU1361 in first two bytes. |
shorie | 1:ea6d442bd68a | 134 | * \param size number of bytes in the command, including the regsiter address. |
shorie | 1:ea6d442bd68a | 135 | * \details |
shorie | 1:ea6d442bd68a | 136 | * Send one complete command to ADAU3161 by I2C. |
shorie | 1:ea6d442bd68a | 137 | */ |
shorie | 1:ea6d442bd68a | 138 | virtual void send_command( const char command[], int size ); |
shorie | 1:ea6d442bd68a | 139 | /** |
shorie | 1:ea6d442bd68a | 140 | * \brief send one command to ADAU1361. |
shorie | 1:ea6d442bd68a | 141 | * \param table command table. All commands are stored in one row. Each row has only 1 byte data after reg address. |
shorie | 1:ea6d442bd68a | 142 | * \param rows number of the rows in the table. |
shorie | 1:ea6d442bd68a | 143 | * \details |
shorie | 1:ea6d442bd68a | 144 | * Service function for the ADAu1361 board implementer. |
shorie | 1:ea6d442bd68a | 145 | * |
shorie | 1:ea6d442bd68a | 146 | * Send a list of command to ADAU1361. All commands has 3 bytes length. That mean, after two byte register |
shorie | 1:ea6d442bd68a | 147 | * address, only 1 byte data payload is allowed. Commadns are sent by I2C |
shorie | 1:ea6d442bd68a | 148 | */ |
shorie | 1:ea6d442bd68a | 149 | virtual void send_command_table( const char table[][3], int rows); |
shorie | 1:ea6d442bd68a | 150 | |
shorie | 1:ea6d442bd68a | 151 | /** |
shorie | 1:ea6d442bd68a | 152 | * \brief wait until PLL locks. |
shorie | 1:ea6d442bd68a | 153 | * \details |
shorie | 1:ea6d442bd68a | 154 | * Service function for the ADAu1361 board implementer. |
shorie | 1:ea6d442bd68a | 155 | * |
shorie | 1:ea6d442bd68a | 156 | * Read the PLL status and repeat it until the PLL locks. |
shorie | 1:ea6d442bd68a | 157 | */ |
shorie | 1:ea6d442bd68a | 158 | virtual void wait_pll_lock(void); |
shorie | 1:ea6d442bd68a | 159 | }; |
shorie | 1:ea6d442bd68a | 160 | |
shorie | 1:ea6d442bd68a | 161 | } |
shorie | 1:ea6d442bd68a | 162 | |
shorie | 1:ea6d442bd68a | 163 | #endif |