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 21 07:16:57 2017 +0000
Revision:
0:bb828a2c4208
Child:
1:6253da3ab855
update APIs

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