API collection of Ukifune. Initial publish. Documents are not ready.

ukifuneはUI基板『浮舟』のAPIモジュールです。 浮舟はNucleo F746ZGに接続して使うUI基板で、以下のような特徴を持っています。

  • ピアノ鍵盤を模した13個のタクトスイッチ
  • 3個のモード切り替えスイッチ
  • 12個のLED
  • 2ポートのI2Cを通して使える計8個のボリューム。

以下にukifuneモジュール及び浮舟について解説します。

ハードウェア

浮舟基板は、Nucleo F746ZGのCN12ヘッダーに接続して使うUI基板です。 /media/uploads/shorie/imgp2217.jpg この写真では中央下の緑の基板が浮舟です。上の白い基板はNucleo F746ZGで、その上には、変換基板桐壺を介してアクアシグナルのUMB-ADAU1361-Aが接続されています。また、浮舟の両側にはやはりアクアシグナルのTPOL-POT4-Aが接続されています。

Nucleo F746ZGのCN12は非常に多くのピンが用意されていますが、そのうち最初の50ピンのみを使っています。使用している機能はGPIO機能のほか、I2C3およびI2C4ポートです。I2C2ポートは、CN11で使えるように手付かずであけてあります。

プッシュボタンはアンチ・チャタリング回路を入れていますが、簡易型であるためあまり効きがよくありません。現時点ではキャパシタの無駄です。追試してみたい方は時定数を大きくするか、いっそアンチ・チャタリング回路をやめてもいいでしょう。

LEDもプッシュボタンも、アクティブHです。すなわち、LEDは論理状態1で点灯し、プッシュボタンを押すと論理状態が1になります。

I2Cポートは基板でプルアップした後、外部に開放しています。これらはアクアシグナルのTOL-POT4-Aに直結できるピン配置になっています。 浮舟基板にはテストポイントが3本出ています。うち1本はGNDで、残りの2本は割り込み処理時間と信号処理時間を測定するためのステータスピンです。

ソフトウェア

ukifuneモジュールは浮舟基板制御用のAPI群です。これらは名前空間ukifuneでラップされており、ukifune.hを読むことで利用できます。 APIの一覧については、このページのAPI Documentationタブを参照してください。APIドキュメントには、LEDおよびプッシュ・ボタン・スイッチをプログラムから参照するための識別子も列挙してあります。

ukifuneモジュールのAPIを使用するためには、事前にukifune::init() APIを一度だけ呼ぶ必要があります。このAPIは内部変数を初期化するほか、雲仙オーディオフレームワークへのポインタを受け取り、フレームワークに対してテストピンを駆動するためのコールバック群を登録します。

ボリュームを使う場合には、周期的に ukifune::tick() を呼んでください。このAPIは呼ばれるたびにI2C経由でADCにアクセスしてアナログ値を読み取り、ukifuneモジュールの内部変数を更新します。呼び出し周期はおおむね50mS以内であれば十分でしょう。周期の精度については適当でかまいません。

プッシュボタンの状態を知りたい場合には、ukifune::get_button_state() を呼び出します。このAPIは3つのビットマスクを返します。

pushing 引数は、前回のAPI呼び出し時からどのボタンが押し込まれたかを返します。言い換えると、前回押されていなかったにもかかわらず、今回のAPI呼び出しで押されていることが検出されたボタンがこの変数から返されます。pushing引数はビットマップであり、ビット位置は enum ukifune::SWITCHの要素の値に対応します。対応するビットが1であるようなスイッチが、押し込まれたスイッチです。

releasing 引数は、前回のAPI呼び出し時からどのボタンが戻されたかを返します。言い換えると、前回押されていたにもかかわらず、今回のAPI呼び出しで押されていないことが検出されたプッシュボタンがこの変数から返されます。releasing引数はビットマップであり、ビット位置は enum ukifune::SWITCHの要素の値に対応します。対応するビットが1であるようなスイッチが、戻されたスイッチです。

pushed 引数は、どのボタンが押されているかを返します。pushed引数はビットマップであり、ビット位置は enum ukifune::SWITCHの要素の値に対応します。対応するビットが1であるようなスイッチが、押されているスイッチです。

ukifune::get_volume()は、ボリュームの状態を返します。引数は0から7の整数で、ボリュームに対応します。返り値の範囲は0から1.0です。

基板設計情報およびパーツリスト

ukifuneの 基板設計情報をアップロードしておきます( 2017/01/28, ver 2 )。

この基板はKiCad 4.0.2 で設計し、出力したgerberデータをスイッチサイエンスの基板製造サービスで製造し、動作を確認しています(写真)。万に一つのことがありますので、基板を外注に出す方は、くれぐれも事前の注意を払ってください。また、この基板は実験用に作成したものであり、民生、産業、医療などの用途に耐えるような設計ではありません。どのような理由であれ、この基板によって発生した問題については責任を取りません。

部品表は以下の通りです。C1の脚の幅にご注意ください。LEDやプッシュボタン・スイッチの色は任意です。なお、U1だけは表面実装部品です。ご注意ください。 以下の部品の他に、Nucleo側のピンヘッダおよび、基板接続用のフラットケーブル(圧接コネクタ付き)が必要です。

ReferenceValueFootprint注釈
C10.1uCapacitors_ThroughHole:C_Disc_D3_P2.50.1uF ピン幅2.54mm
C210uCapacitors_ThroughHole:C_Radial_D5_L6_P2.510uF ピン幅2.54mm
C30.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C40.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C50.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C60.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C70.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C80.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C90.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C100.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C110.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C120.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C130.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C140.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C150.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C160.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C170.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
C180.1uCapacitors_ThroughHole:C_Disc_D6_P50.1uF ピン幅5.08mm
D1_1LEDLEDs:LED-3MMLED ピン幅2.54mm
D1_2LEDLEDs:LED-3MMLED ピン幅2.54mm
D1_3LEDLEDs:LED-3MMLED ピン幅2.54mm
D1_4LEDLEDs:LED-3MMLED ピン幅2.54mm
D2_1LEDLEDs:LED-3MMLED ピン幅2.54mm
D2_2LEDLEDs:LED-3MMLED ピン幅2.54mm
D2_3LEDLEDs:LED-3MMLED ピン幅2.54mm
D2_4LEDLEDs:LED-3MMLED ピン幅2.54mm
D3_1LEDLEDs:LED-3MMLED ピン幅2.54mm
D3_2LEDLEDs:LED-3MMLED ピン幅2.54mm
D3_3LEDLEDs:LED-3MMLED ピン幅2.54mm
D3_4LEDLEDs:LED-3MMLED ピン幅2.54mm
P1CONN_02X25Pin_Headers:Pin_Header_Straight_2x25ピンヘッダ 2x25 2.54mm
P2CONN_02X05Pin_Headers:Pin_Header_Straight_2x05ピンヘッダ 2x5 2.54mm
P3CONN_02X05Pin_Headers:Pin_Header_Straight_2x05ピンヘッダ 2x5 2.54mm
R1660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R2660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R3660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R4660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R5660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R6660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R7660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R8660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R9660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R10660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R11660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R12660Resistors_ThroughHole:Resistor_Horizontal_RM7mm660Ω 炭素皮膜
R13330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R14330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R15330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R16330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R17330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R18330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R19330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R20330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R21330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R22330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R23330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R24330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R25330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R26330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R27330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R28330kResistors_ThroughHole:Resistor_Horizontal_RM7mm330kΩ 炭素皮膜
R292.2kResistors_ThroughHole:Resistor_Horizontal_RM7mm2.2kΩ 炭素皮膜
R302.2kResistors_ThroughHole:Resistor_Horizontal_RM7mm2.2kΩ 炭素皮膜
R312.2kResistors_ThroughHole:Resistor_Horizontal_RM7mm2.2kΩ 炭素皮膜
R322.2kResistors_ThroughHole:Resistor_Horizontal_RM7mm2.2kΩ 炭素皮膜
SWM1SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWM2SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWM3SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK1SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK2SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK3SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK4SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK5SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK6SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK7SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK8SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK9SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK10SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK11SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK12SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
SWK13SPSTButtons_Switches_ThroughHole:SW_PUSH_6mmタクトスイッチ
TP1TEST_1PPin_Headers:Pin_Header_Straight_1x01
TP2TEST_1PPin_Headers:Pin_Header_Straight_1x01
TP3TEST_1PPin_Headers:Pin_Header_Straight_1x01
U1TA48M033FTO_SOT_Packages_SMD:TO-252-2LeadSMD 3.3V レギュレータ

Nucleo F746ZGの改造

Nucleo F746ZGは非常に多機能なSoCマイコンを使っています。多くの機能がピンに多重化されているものの、一部は基板外の複数の信号がピンを奪い合う形になっています。これを解決するために、Nucleo F746ZGには多くのショート・ブリッジがあります。

浮舟基板を使うためにはNucleo F746ZGの以下のショート・ブリッジを取り去ってください。

  • SB125
  • SB132
  • SB133
  • SB178
  • SB181

また、以下のジャンパー・ピンはオープンにしてください。

  • JP6
  • JP7

以上の改造によって、Nucelo F746ZGのEthernetポートおよび、USB OTGポートが使用できなくなります(ホストと接続しているmbed用USBポートには影響はありません)。

既知の問題

  • アンチ・チャタリング回路は見直した方がいいです。現状でチャタリングが残っています。
  • C1は他のキャパシタと異なり、2.54mmピッチです。

参考リンク

Committer:
shorie
Date:
Sat Jan 28 12:50:04 2017 +0000
Revision:
7:e2a690a654ff
Parent:
1:6253da3ab855
Refactor the name of parameter of the get_button_state() API.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shorie 0:bb828a2c4208 1 #include "mbed.h"
shorie 0:bb828a2c4208 2 #include "ukifune.h"
shorie 0:bb828a2c4208 3 #include "unzen.h"
shorie 1:6253da3ab855 4 #include "amakusa.h"
shorie 0:bb828a2c4208 5
shorie 0:bb828a2c4208 6 #define AD7999 (0x29<<1)
shorie 0:bb828a2c4208 7 #define ADCBUFSIZE 8
shorie 1:6253da3ab855 8 #define ADCNUM 8
shorie 0:bb828a2c4208 9
shorie 0:bb828a2c4208 10 namespace ukifune
shorie 0:bb828a2c4208 11 {
shorie 0:bb828a2c4208 12 //
shorie 0:bb828a2c4208 13 DigitalOut *leds[12];
shorie 0:bb828a2c4208 14 DigitalIn *switches[16];
shorie 1:6253da3ab855 15 float adc[ADCNUM];
shorie 1:6253da3ab855 16 amakusa::Hysteresis * hysteresis[ADCNUM];
shorie 0:bb828a2c4208 17
shorie 0:bb828a2c4208 18
shorie 0:bb828a2c4208 19 // Test points
shorie 0:bb828a2c4208 20 DigitalOut TP1( PE_12 ); // TP1 for _interrupt _flag.
shorie 0:bb828a2c4208 21 DigitalOut TP2( PF_14 ); // TP2 for _process _flag.
shorie 0:bb828a2c4208 22
shorie 0:bb828a2c4208 23 // LED
shorie 0:bb828a2c4208 24 DigitalOut LED1_1(PE_7);
shorie 0:bb828a2c4208 25 DigitalOut LED1_2(PF_10);
shorie 0:bb828a2c4208 26 DigitalOut LED1_3(PF_4);
shorie 0:bb828a2c4208 27 DigitalOut LED1_4(PC_4);
shorie 0:bb828a2c4208 28
shorie 0:bb828a2c4208 29 DigitalOut LED2_1(PB_13);
shorie 0:bb828a2c4208 30 DigitalOut LED2_2(PB_5);
shorie 0:bb828a2c4208 31 DigitalOut LED2_3(PB_14);
shorie 0:bb828a2c4208 32 DigitalOut LED2_4(PB_15);
shorie 0:bb828a2c4208 33
shorie 0:bb828a2c4208 34 DigitalOut LED3_1(PB_6);
shorie 0:bb828a2c4208 35 DigitalOut LED3_2(PA_11);
shorie 0:bb828a2c4208 36 DigitalOut LED3_3(PA_5);
shorie 0:bb828a2c4208 37 DigitalOut LED3_4(PC_6);
shorie 0:bb828a2c4208 38
shorie 0:bb828a2c4208 39 // Mode Button
shorie 0:bb828a2c4208 40 DigitalIn SWM1(PD_14);
shorie 1:6253da3ab855 41 DigitalIn SWM2(PB_4);
shorie 0:bb828a2c4208 42 DigitalIn SWM3(PA_12);
shorie 0:bb828a2c4208 43
shorie 0:bb828a2c4208 44 // Key Button
shorie 0:bb828a2c4208 45 DigitalIn SWK1(PE_10);
shorie 0:bb828a2c4208 46 DigitalIn SWK2(PD_15);
shorie 0:bb828a2c4208 47 DigitalIn SWK3(PD_11);
shorie 0:bb828a2c4208 48 DigitalIn SWK4(PE_8);
shorie 0:bb828a2c4208 49 DigitalIn SWK5(PF_5);
shorie 0:bb828a2c4208 50 DigitalIn SWK6(PA_10);
shorie 0:bb828a2c4208 51 DigitalIn SWK7(PB_1);
shorie 0:bb828a2c4208 52 DigitalIn SWK8(PB_12);
shorie 0:bb828a2c4208 53 DigitalIn SWK9(PA_7);
shorie 0:bb828a2c4208 54 DigitalIn SWK10(PA_6);
shorie 1:6253da3ab855 55 DigitalIn SWK11(PC_7);
shorie 0:bb828a2c4208 56 DigitalIn SWK12(PC_5);
shorie 0:bb828a2c4208 57 DigitalIn SWK13(PC_8);
shorie 0:bb828a2c4208 58
shorie 0:bb828a2c4208 59
shorie 0:bb828a2c4208 60 // I2S ports for potentiometer
shorie 0:bb828a2c4208 61 I2C i2c3(PC_9, PA_8); // SDA, SCL of I2C3
shorie 0:bb828a2c4208 62 I2C i2c4(PD_13, PD_12); // SDA, SCL of I2C4
shorie 0:bb828a2c4208 63
shorie 0:bb828a2c4208 64 void assert_process_flag( void )
shorie 0:bb828a2c4208 65 {
shorie 0:bb828a2c4208 66 TP2 = 1;
shorie 0:bb828a2c4208 67 }
shorie 0:bb828a2c4208 68
shorie 0:bb828a2c4208 69 void deassert_process_flag( void )
shorie 0:bb828a2c4208 70 {
shorie 0:bb828a2c4208 71 TP2 = 0;
shorie 0:bb828a2c4208 72 }
shorie 0:bb828a2c4208 73
shorie 0:bb828a2c4208 74 void assert_interrupt_flag( void )
shorie 0:bb828a2c4208 75 {
shorie 0:bb828a2c4208 76 TP1 = 1;
shorie 0:bb828a2c4208 77 }
shorie 0:bb828a2c4208 78
shorie 0:bb828a2c4208 79 void deassert_interrupt_flag( void )
shorie 0:bb828a2c4208 80 {
shorie 0:bb828a2c4208 81 TP1 = 0;
shorie 0:bb828a2c4208 82 }
shorie 0:bb828a2c4208 83
shorie 0:bb828a2c4208 84 void init( unzen::Framework *audio)
shorie 0:bb828a2c4208 85 {
shorie 1:6253da3ab855 86
shorie 0:bb828a2c4208 87 // Setup interrupt/process activity flag.
shorie 0:bb828a2c4208 88 audio->set_pre_interrupt_callback( assert_interrupt_flag );
shorie 0:bb828a2c4208 89 audio->set_post_interrupt_callback( deassert_interrupt_flag );
shorie 0:bb828a2c4208 90 audio->set_pre_process_callback( assert_process_flag );
shorie 0:bb828a2c4208 91 audio->set_post_process_callback( deassert_process_flag );
shorie 0:bb828a2c4208 92
shorie 0:bb828a2c4208 93 // Setup LEDs
shorie 0:bb828a2c4208 94 leds[ led1_1 ] = &LED1_1;
shorie 0:bb828a2c4208 95 leds[ led1_2 ] = &LED1_2;
shorie 0:bb828a2c4208 96 leds[ led1_3 ] = &LED1_3;
shorie 0:bb828a2c4208 97 leds[ led1_4 ] = &LED1_4;
shorie 0:bb828a2c4208 98
shorie 0:bb828a2c4208 99 leds[ led2_1 ] = &LED2_1;
shorie 0:bb828a2c4208 100 leds[ led2_2 ] = &LED2_2;
shorie 0:bb828a2c4208 101 leds[ led2_3 ] = &LED2_3;
shorie 0:bb828a2c4208 102 leds[ led2_4 ] = &LED2_4;
shorie 0:bb828a2c4208 103
shorie 0:bb828a2c4208 104 leds[ led3_1 ] = &LED3_1;
shorie 0:bb828a2c4208 105 leds[ led3_2 ] = &LED3_2;
shorie 0:bb828a2c4208 106 leds[ led3_3 ] = &LED3_3;
shorie 0:bb828a2c4208 107 leds[ led3_4 ] = &LED3_4;
shorie 0:bb828a2c4208 108
shorie 0:bb828a2c4208 109 // Setup Switches
shorie 0:bb828a2c4208 110 switches[ swm1 ] = & SWM1;
shorie 0:bb828a2c4208 111 switches[ swm2 ] = & SWM2;
shorie 0:bb828a2c4208 112 switches[ swm3 ] = & SWM3;
shorie 0:bb828a2c4208 113 switches[ swk1 ] = & SWK1;
shorie 0:bb828a2c4208 114 switches[ swk2 ] = & SWK2;
shorie 0:bb828a2c4208 115 switches[ swk3 ] = & SWK3;
shorie 0:bb828a2c4208 116 switches[ swk4 ] = & SWK4;
shorie 0:bb828a2c4208 117 switches[ swk5 ] = & SWK5;
shorie 0:bb828a2c4208 118 switches[ swk6 ] = & SWK6;
shorie 0:bb828a2c4208 119 switches[ swk7 ] = & SWK7;
shorie 0:bb828a2c4208 120 switches[ swk8 ] = & SWK8;
shorie 0:bb828a2c4208 121 switches[ swk9 ] = & SWK9;
shorie 0:bb828a2c4208 122 switches[ swk10 ] = & SWK10;
shorie 0:bb828a2c4208 123 switches[ swk11 ] = & SWK11;
shorie 0:bb828a2c4208 124 switches[ swk12 ] = & SWK12;
shorie 0:bb828a2c4208 125 switches[ swk13 ] = & SWK13;
shorie 1:6253da3ab855 126
shorie 1:6253da3ab855 127 for ( int i= 0; i<ADCNUM; i++ )
shorie 1:6253da3ab855 128 hysteresis[ i ] = new amakusa::Hysteresis((int32_t)0,(int32_t) 255);
shorie 1:6253da3ab855 129
shorie 0:bb828a2c4208 130 }
shorie 0:bb828a2c4208 131
shorie 0:bb828a2c4208 132 void get_button_state(
shorie 1:6253da3ab855 133 uint32_t & pusshing,
shorie 1:6253da3ab855 134 uint32_t & releasing,
shorie 7:e2a690a654ff 135 uint32_t & holding )
shorie 0:bb828a2c4208 136 {
shorie 0:bb828a2c4208 137 static int last_button = 0;
shorie 0:bb828a2c4208 138 int current_button = 0;
shorie 0:bb828a2c4208 139 int index;
shorie 0:bb828a2c4208 140
shorie 0:bb828a2c4208 141 // get current button mask pattern
shorie 0:bb828a2c4208 142 index = 0;
shorie 0:bb828a2c4208 143 for ( int sw = 0; sw < 16; sw ++ )
shorie 0:bb828a2c4208 144 {
shorie 0:bb828a2c4208 145 if ( *(switches[sw]) )
shorie 0:bb828a2c4208 146 current_button |= 1<<index;
shorie 0:bb828a2c4208 147 index ++;
shorie 0:bb828a2c4208 148 }
shorie 0:bb828a2c4208 149
shorie 0:bb828a2c4208 150 // return pushed button
shorie 7:e2a690a654ff 151 holding = current_button;
shorie 0:bb828a2c4208 152
shorie 0:bb828a2c4208 153 // buttons which are pushed from last state.
shorie 1:6253da3ab855 154 pusshing = ( last_button ^ current_button ) & current_button;
shorie 0:bb828a2c4208 155
shorie 0:bb828a2c4208 156 // buttons which are released from last state
shorie 1:6253da3ab855 157 releasing = ( last_button ^ current_button ) & last_button;
shorie 0:bb828a2c4208 158
shorie 0:bb828a2c4208 159 last_button = current_button;
shorie 0:bb828a2c4208 160 }
shorie 0:bb828a2c4208 161
shorie 0:bb828a2c4208 162 void turn_led_on( enum LED led )
shorie 0:bb828a2c4208 163 {
shorie 0:bb828a2c4208 164 *( leds[ led ] ) = 1;
shorie 0:bb828a2c4208 165 }
shorie 0:bb828a2c4208 166
shorie 0:bb828a2c4208 167 void turn_led_off( enum LED led )
shorie 0:bb828a2c4208 168 {
shorie 0:bb828a2c4208 169 *( leds[ led ] ) = 0;
shorie 0:bb828a2c4208 170 }
shorie 0:bb828a2c4208 171
shorie 0:bb828a2c4208 172 void toggle_led( enum LED led )
shorie 0:bb828a2c4208 173 {
shorie 0:bb828a2c4208 174 *( leds[ led ] ) = ! get_led_state( led );
shorie 0:bb828a2c4208 175 }
shorie 0:bb828a2c4208 176
shorie 0:bb828a2c4208 177 int get_led_state( enum LED led )
shorie 0:bb828a2c4208 178 {
shorie 0:bb828a2c4208 179 return *( leds[ led ] );
shorie 0:bb828a2c4208 180 }
shorie 0:bb828a2c4208 181
shorie 1:6253da3ab855 182 float get_volume( int number )
shorie 1:6253da3ab855 183 {
shorie 1:6253da3ab855 184 if ( number < 0)
shorie 1:6253da3ab855 185 return 0.0;
shorie 1:6253da3ab855 186 if ( number >= ADCNUM )
shorie 1:6253da3ab855 187 return 0.0;
shorie 1:6253da3ab855 188
shorie 1:6253da3ab855 189 return adc[ number ];
shorie 1:6253da3ab855 190
shorie 1:6253da3ab855 191 }
shorie 1:6253da3ab855 192
shorie 1:6253da3ab855 193 void parse_adc( char * buf, int &ch, int &data )
shorie 1:6253da3ab855 194 {
shorie 1:6253da3ab855 195 ch = ( buf[0] & 0x30 ) >> 4;
shorie 1:6253da3ab855 196 data =
shorie 1:6253da3ab855 197 ( buf[0] & 0x0F ) << 4 |
shorie 1:6253da3ab855 198 ( buf[1] & 0xF0 ) >> 4;
shorie 1:6253da3ab855 199
shorie 1:6253da3ab855 200 }
shorie 1:6253da3ab855 201
shorie 1:6253da3ab855 202
shorie 1:6253da3ab855 203
shorie 0:bb828a2c4208 204 void tick(void)
shorie 0:bb828a2c4208 205 {
shorie 1:6253da3ab855 206 char adcbuf[ADCBUFSIZE];
shorie 1:6253da3ab855 207 int ch, data;
shorie 0:bb828a2c4208 208
shorie 1:6253da3ab855 209 i2c3.read( AD7999, adcbuf, 8);
shorie 1:6253da3ab855 210 parse_adc(& adcbuf[0], ch, data);
shorie 1:6253da3ab855 211 adc[ch] = hysteresis[ch]->run( data ) / 255.0;
shorie 1:6253da3ab855 212 parse_adc(& adcbuf[2], ch, data);
shorie 1:6253da3ab855 213 adc[ch] = hysteresis[ch]->run( data ) / 255.0;
shorie 1:6253da3ab855 214 parse_adc(& adcbuf[4], ch, data);
shorie 1:6253da3ab855 215 adc[ch] = hysteresis[ch]->run( data ) / 255.0;
shorie 1:6253da3ab855 216 parse_adc(& adcbuf[6], ch, data);
shorie 1:6253da3ab855 217 adc[ch] = hysteresis[ch]->run( data ) / 255.0;
shorie 1:6253da3ab855 218
shorie 1:6253da3ab855 219 i2c4.read( AD7999, adcbuf, 8);
shorie 1:6253da3ab855 220 parse_adc(& adcbuf[0], ch, data);
shorie 1:6253da3ab855 221 adc[ch+4] = hysteresis[ch+4]->run( data ) / 255.0;
shorie 1:6253da3ab855 222 parse_adc(& adcbuf[2], ch, data);
shorie 1:6253da3ab855 223 adc[ch+4] = hysteresis[ch+4]->run( data ) / 255.0;
shorie 1:6253da3ab855 224 parse_adc(& adcbuf[4], ch, data);
shorie 1:6253da3ab855 225 adc[ch+4] = hysteresis[ch+4]->run( data ) / 255.0;
shorie 1:6253da3ab855 226 parse_adc(& adcbuf[6], ch, data);
shorie 1:6253da3ab855 227 adc[ch+4] = hysteresis[ch+4]->run( data ) / 255.0;
shorie 0:bb828a2c4208 228 }
shorie 0:bb828a2c4208 229
shorie 0:bb828a2c4208 230
shorie 0:bb828a2c4208 231 };