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を使う方はここから読み始めると良いでしょう。
umb_adau1361a.cpp@7:6d921f8c38d6, 2017-01-27 (annotated)
- Committer:
- shorie
- Date:
- Fri Jan 27 21:08:29 2017 +0000
- Revision:
- 7:6d921f8c38d6
- Parent:
- 2:fba0b8afebf0
Doxygen comment update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shorie | 1:ea6d442bd68a | 1 | #include "umb_adau1361a.h" |
shorie | 1:ea6d442bd68a | 2 | |
shorie | 2:fba0b8afebf0 | 3 | namespace shimabara |
shorie | 1:ea6d442bd68a | 4 | { |
shorie | 1:ea6d442bd68a | 5 | |
shorie | 1:ea6d442bd68a | 6 | |
shorie | 1:ea6d442bd68a | 7 | // 48kHz PLL setting for 12MHz input |
shorie | 1:ea6d442bd68a | 8 | // Denominator : 0x7D = 125 |
shorie | 1:ea6d442bd68a | 9 | // Nunerator : 0x0c = 12 |
shorie | 1:ea6d442bd68a | 10 | // Fractional PLL, *4 multiplying |
shorie | 1:ea6d442bd68a | 11 | // PLL Enable : Freq is 12Mhz * ( 4 + 12/125 ) = 49.125Mhz (1024 core clock) |
shorie | 1:ea6d442bd68a | 12 | static const char init_pll_48[] = {0x40, 0x02, 0x00, 0x7D, 0x00, 0x0C, 0x21, 0x01}; |
shorie | 1:ea6d442bd68a | 13 | // R17: Converter 0, SRC = 1 * core clock |
shorie | 1:ea6d442bd68a | 14 | static const char init_src_48[] = {0x40, 0x17, 0x00}; |
shorie | 1:ea6d442bd68a | 15 | |
shorie | 1:ea6d442bd68a | 16 | // 96kHz PLL setting for 12MHz input |
shorie | 1:ea6d442bd68a | 17 | #define init_pll_96 init_pll_48 |
shorie | 1:ea6d442bd68a | 18 | // R17: Converter 0, SRC = 1 * core clock |
shorie | 1:ea6d442bd68a | 19 | static const char init_src_96[] = {0x40, 0x17, 0x06}; |
shorie | 1:ea6d442bd68a | 20 | |
shorie | 1:ea6d442bd68a | 21 | |
shorie | 1:ea6d442bd68a | 22 | // 32kHz PLL setting for 12MHz input |
shorie | 1:ea6d442bd68a | 23 | #define init_pll_32 init_pll_48 |
shorie | 1:ea6d442bd68a | 24 | // R17: Converter 0, SRC = 1 * core clock |
shorie | 1:ea6d442bd68a | 25 | static const char init_src_32[] = {0x40, 0x17, 0x05}; |
shorie | 1:ea6d442bd68a | 26 | |
shorie | 1:ea6d442bd68a | 27 | |
shorie | 1:ea6d442bd68a | 28 | // 44.1kHz PLL setting for 12MHz input |
shorie | 1:ea6d442bd68a | 29 | // Denominator : 0x271 = 625 |
shorie | 1:ea6d442bd68a | 30 | // Nunerator : 0x1dd = 447 |
shorie | 1:ea6d442bd68a | 31 | // Fractional PLL, *3 multiplying |
shorie | 1:ea6d442bd68a | 32 | // PLL Enable : Freq is 12Mhz * ( 3 + 477/625 ) = 45.1584Mhz (1024 core clock) |
shorie | 1:ea6d442bd68a | 33 | static const char init_pll_441[] = {0x40, 0x02, 0x02, 0x71, 0x01, 0xDD, 0x19, 0x01}; |
shorie | 1:ea6d442bd68a | 34 | // R17: Converter 0, SRC = 1 * core clock |
shorie | 1:ea6d442bd68a | 35 | #define init_src_441 init_src_48 |
shorie | 1:ea6d442bd68a | 36 | |
shorie | 1:ea6d442bd68a | 37 | // Set UMB_ADAU1361A. No mono output, No cross channel Mix, No analog path through. |
shorie | 1:ea6d442bd68a | 38 | static const char config_UMB_ADAU1361A[][3] = |
shorie | 1:ea6d442bd68a | 39 | { |
shorie | 1:ea6d442bd68a | 40 | // Configuration for UMB-ADAU1361-A http://dsps.shop-pro.jp/?pid=82798273 |
shorie | 1:ea6d442bd68a | 41 | {0x40, 0x0a, 0x0B}, // R4: Rec Mixer Left 0, Mixer enable, LINNG 0dB |
shorie | 1:ea6d442bd68a | 42 | {0x40, 0x0c, 0x0B}, // R6: Rec Mixer Right 0, Mixer enable, RINNG 0dB |
shorie | 1:ea6d442bd68a | 43 | {0x40, 0x15, 0x01}, // R15:Serial Port control, Set code as Master mode I2S. |
shorie | 1:ea6d442bd68a | 44 | {0x40, 0x19, 0x63}, // R19:ADC Control. Enable ADC, Both Cannel ADC on, HPF on |
shorie | 1:ea6d442bd68a | 45 | {0x40, 0x29, 0x03}, // R35:Left Right Play back enable. Play back power Management |
shorie | 1:ea6d442bd68a | 46 | {0x40, 0x2a, 0x03}, // R36:DAC Control 0. Enable DAC. Both channels on. |
shorie | 1:ea6d442bd68a | 47 | {0x40, 0x1c, 0x21}, // R22:MIXER 3, Left DAC Mixer (set L DAC to L Mixer ) |
shorie | 1:ea6d442bd68a | 48 | {0x40, 0x1e, 0x41}, // R24:MIXER 4, Right DAC Mixer (set R DAC to R Mixer ) |
shorie | 1:ea6d442bd68a | 49 | {0x40, 0x20, 0x03}, // R26:MIXER 5, Left out mixer. L out MIX5G3 and enable |
shorie | 1:ea6d442bd68a | 50 | {0x40, 0x21, 0x09}, // R27:MIXER 6, Right out mixer. R out MIX6G4 and enable. |
shorie | 1:ea6d442bd68a | 51 | }; |
shorie | 1:ea6d442bd68a | 52 | |
shorie | 1:ea6d442bd68a | 53 | // Clear PLL regsiter and then, set up PLL registers for given Fs. |
shorie | 1:ea6d442bd68a | 54 | void UMB_ADAU1361A::configure_pll(void) |
shorie | 1:ea6d442bd68a | 55 | { |
shorie | 1:ea6d442bd68a | 56 | // set Fs ( xternal clock in is 12MHz ) |
shorie | 1:ea6d442bd68a | 57 | switch ( fs ) // fs is member variable. |
shorie | 1:ea6d442bd68a | 58 | { |
shorie | 1:ea6d442bd68a | 59 | case Fs_96: |
shorie | 1:ea6d442bd68a | 60 | send_command( init_pll_96, sizeof(init_pll_96) ); |
shorie | 1:ea6d442bd68a | 61 | wait_pll_lock(); |
shorie | 1:ea6d442bd68a | 62 | send_command( init_src_96, sizeof(init_src_96) ); |
shorie | 1:ea6d442bd68a | 63 | break; |
shorie | 1:ea6d442bd68a | 64 | case Fs_441: |
shorie | 1:ea6d442bd68a | 65 | send_command( init_pll_441, sizeof(init_pll_441) ); |
shorie | 1:ea6d442bd68a | 66 | wait_pll_lock(); |
shorie | 1:ea6d442bd68a | 67 | send_command( init_src_441, sizeof(init_src_441) ); |
shorie | 1:ea6d442bd68a | 68 | break; |
shorie | 1:ea6d442bd68a | 69 | case Fs_32: |
shorie | 1:ea6d442bd68a | 70 | send_command( init_pll_32, sizeof(init_pll_32) ); |
shorie | 1:ea6d442bd68a | 71 | wait_pll_lock(); |
shorie | 1:ea6d442bd68a | 72 | send_command( init_src_32, sizeof(init_src_32) ); |
shorie | 1:ea6d442bd68a | 73 | break; |
shorie | 1:ea6d442bd68a | 74 | case Fs_48: |
shorie | 1:ea6d442bd68a | 75 | default: |
shorie | 1:ea6d442bd68a | 76 | send_command( init_pll_48, sizeof(init_pll_48) ); |
shorie | 1:ea6d442bd68a | 77 | wait_pll_lock(); |
shorie | 1:ea6d442bd68a | 78 | send_command( init_src_48, sizeof(init_src_48) ); |
shorie | 1:ea6d442bd68a | 79 | break; |
shorie | 1:ea6d442bd68a | 80 | } |
shorie | 1:ea6d442bd68a | 81 | |
shorie | 1:ea6d442bd68a | 82 | } |
shorie | 1:ea6d442bd68a | 83 | |
shorie | 1:ea6d442bd68a | 84 | void UMB_ADAU1361A::configure_board(void) |
shorie | 1:ea6d442bd68a | 85 | { |
shorie | 1:ea6d442bd68a | 86 | send_command_table( config_UMB_ADAU1361A, sizeof(config_UMB_ADAU1361A)/3 ); |
shorie | 1:ea6d442bd68a | 87 | } |
shorie | 1:ea6d442bd68a | 88 | |
shorie | 1:ea6d442bd68a | 89 | } |
shorie | 1:ea6d442bd68a | 90 |