arm/libhidでARMマイコンパーフェクト学習基板にアクセス
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
[[FrontPage]]
2011/02/06 からのアクセス回数 &counter;
#contents
** はじめに [#g593bfb6]
[[ARMマイコン>http://www.amazon.co.jp/dp/B004AX9QWG/]]
で、「ARMマイコンパーフェクト学習基板」のUSB HIDの作り方...
いましたので、オープンソースのHIDライブラリであるlibhidを
使ってオリジナルのHIDにアクセスする方法を紹介します。
** ARMマイコンパーフェクト学習基板のHIDを作成 [#j794d453]
[[ARMマイコン>http://www.amazon.co.jp/dp/B004AX9QWG/]]
では、HID作成のポイントとなるソースは公開されていますが、
全ソースがありません。
*** LPC Xpressoの例題を使う [#c6f310b0]
スタートポイントは、LPC Xpressoに付属するLPC13xxのサンプル
プログラムから、usbhid_romプロジェクトをインポートします。
このusbhidrom_main.cを以下のように変更します。
- &ref(usbhidrom_main.c);
*** HID依存のソースはとても短い [#rdebadbf]
[[ARMマイコン>http://www.amazon.co.jp/dp/B004AX9QWG/]]
に解説されているとおり、オリジナルのHIDを作る場合、変更す...
- GetInReport (ホストにデータを送る関数)
- SetOutReport(USBにデータを送る関数)
の2個です。
そのソースも非常に簡単です。
#pre{{
uint8_t PCInReportData = 0;
int incount = 0;
void GetInReport (uint8_t src[], uint32_t length)
{
incount++;
if (incount >= 50) {
incount = 0;
PCInReportData++;
}
src[0] = PCInReportData;
}
void SetOutReport (uint8_t dst[], uint32_t length)
{
uint8_t PCOutReportData = dst[0];
if(PCOutReportData& 0x01)
LPC_GPIO[LED_PORT]->MASKED_ACCESS[1<<LED_BIT] = 0xff;
else
LPC_GPIO[LED_PORT]->MASKED_ACCESS[1<<LED_BIT] = 0;
}
}}
*** LPC Xpressoでバイナリファイルを作成する方法 [#u3801e73]
LPC Xpressoでは、そのままではARMマイコンパーエフェクト基...
バイナリファイルが作成されません。
これが本当のやり方とは思いませんが、私の方法を紹介します。
- CodeBaseに付いてきたlpcrc.exeをLPC Xpressoのbinフォルダ...
- プロジェクトのPropertiesのC/C++ BuildのSettingを選択し...
Post-build stepsに以下のコマンドをセット(実際には1行で指...
#pre{{
arm-none-eabi-size ${BuildArtifactFileName}; arm-none-ea...
-O binary ${BuildArtifactFileName} ${BuildArtifactFileBas...
${BuildArtifactFileBaseName}.bin
}}
できあがった、binファイルをARMマイコンパーフェクト学習基...
*** 動作確認 [#nf97b040]
usbhid_romサンプルには、確認のためのデモプログラム(HID D...
これを起動し、LED1をチェックすると基板のLEDが点灯し、INPU...
変化すればOKです。
&ref(Demo_prog.png);
** libhidのインストール [#lf6e0cf1]
*** ソースのダウンロード [#y0727248]
[[libhidのページ>http://libhid.alioth.debian.org/]]では、...
そこで、[[Aliothのダウンロードページ>http://alioth.debian...
- &ref(libhid-0.2.16.tar.gz);
をダウンロードします。
*** インストール [#o9e3bb00]
今回は、C以外の言語を使わないので、swigを外しました。
コンパイルとインストールは以下のように行います。
#pre{{
$ ./configure --disable-swig
$ make
正常にコンパイルできたら
$ sudo make install
}}
*** 動作確認 [#xc185edf]
コンパイルが完了したら、testディレクトリの
- test_libhid.c
を使ってARMマイコンパーフェクト学習基板を認識するか試して...
test_libhid.cの43行を以下のように修正します。
#pre{{
HIDInterfaceMatcher matcher = { 0x1FC9, 0x0003, NULL, N...
}}
makeコマンドでtest_libhidを作り直し、実行してみます。
#pre{{
$ make
$ ./test_libhid
NOTICE: hid_init(): libhid 0.2.16.0.0 is being initializ...
TRACE: hid_init(): initialising USB subsystem...
TRACE: hid_init(): scanning for USB busses...
TRACE: hid_init(): scanning for USB devices...
NOTICE: hid_init(): successfully initialised HID library.
TRACE: hid_new_HIDInterface(): creating a new HIDInterf...
TRACE: hid_force_open(): forcefully opening a device in...
TRACE: hid_get_usb_handle(): acquiring handle for a USB...
途中省略
NOTICE: hid_prepare_parser(): successfully set up the HI...
NOTICE: hid_force_open(): successfully opened USB device...
device identification of HIDInterface 036/008[0]:
dev_handle: 0x10018fda0
device: 0x100838e00
location: 036/008
manufacturer: NXP SEMICOND
product: NXP LPC13XX HID
serial number: DEMO00000000
TRACE: hid_reset_parser(): resetting the HID parser for...
TRACE: hid_dump_tree(): iterating the parse tree for US...
parse tree of HIDInterface 036/008[0]:
path: 0xff000001.0xff000001; type: 0x80
path: 0xff000001.0xff000001; type: 0x90
TRACE: hid_reset_parser(): resetting the HID parser for...
TRACE: hid_close(): closing USB device 036/008[0]...
TRACE: hid_close(): closing handle of USB device 036/00...
NOTICE: hid_close(): successfully closed USB device 036/...
TRACE: hid_reset_parser(): resetting the HID parser for...
TRACE: hid_close(): freeing memory allocated for HID pa...
TRACE: hid_close(): resetting HIDInterface...
NOTICE: hid_cleanup(): successfully deinitialised HID li...
}}
test_libhidは、指定されたHIDデバイスを検索し、そのpathを...
上記の例では、
#pre{{
path: 0xff000001.0xff000001; type: 0x80
path: 0xff000001.0xff000001; type: 0x90
}}
このパスを使って、libhidのhid_set_output_report, hid_get_...
** ARMマイコンパーフェクト学習基板にアクセス [#eb6cb5d4]
最後にtest_libhidを使ってARMARMマイコンパーフェクト学習基...
test_libhid.cの191行目に以下のコードを挿入します。
#pre{{
unsigned char PATHLEN = 2;
int const PATH_IN[] = { 0xffa00001, 0xffa00001 };
int const PATH_OUT[] = { 0xffa00001, 0xffa00001 };
unsigned char SEND_PACKET_LEN = 1;
unsigned char RECV_PACKET_LEN = 1;
char PACKET[] = { 0x1 };
char packet[RECV_PACKET_LEN];
int j;
for (j = 0; j < 100000; j++) {
if (j % 500 == 0)
PACKET[0] =0;
if (j % 1000 == 0)
PACKET[0] =1;
ret = hid_set_output_report(hid, PATH_IN, PATHLEN, PACK...
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_set_output_report failed with ret...
}
ret = hid_get_input_report(hid, PATH_OUT, PATHLEN, pack...
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_get_input_report failed with retu...
}
else {
fprintf(stderr, "hid_get_input_report successed val=%d...
}
}
}}
ARMマイコンパーフェクト学習基板のLEDが点滅し、出力の
#pre{{
NOTICE: hid_get_input_report(): successfully retrieved r...
hid_get_input_report successed val=110
}}
のvalの値がだんだん増えていくのが確認できるはずです。
修正したソースは、以下の通りです。
- &ref(test_libhid.c);
** コメント [#wa396b55]
この記事は、
#vote(おもしろかった[2],そうでもない[0],わかりずらい[0])
皆様のご意見、ご希望をお待ちしております。
- 例題を[[arm/JavaからUSB HIDデバイスを制御する]]にアップ...
#comment_kcaptcha
終了行:
[[FrontPage]]
2011/02/06 からのアクセス回数 &counter;
#contents
** はじめに [#g593bfb6]
[[ARMマイコン>http://www.amazon.co.jp/dp/B004AX9QWG/]]
で、「ARMマイコンパーフェクト学習基板」のUSB HIDの作り方...
いましたので、オープンソースのHIDライブラリであるlibhidを
使ってオリジナルのHIDにアクセスする方法を紹介します。
** ARMマイコンパーフェクト学習基板のHIDを作成 [#j794d453]
[[ARMマイコン>http://www.amazon.co.jp/dp/B004AX9QWG/]]
では、HID作成のポイントとなるソースは公開されていますが、
全ソースがありません。
*** LPC Xpressoの例題を使う [#c6f310b0]
スタートポイントは、LPC Xpressoに付属するLPC13xxのサンプル
プログラムから、usbhid_romプロジェクトをインポートします。
このusbhidrom_main.cを以下のように変更します。
- &ref(usbhidrom_main.c);
*** HID依存のソースはとても短い [#rdebadbf]
[[ARMマイコン>http://www.amazon.co.jp/dp/B004AX9QWG/]]
に解説されているとおり、オリジナルのHIDを作る場合、変更す...
- GetInReport (ホストにデータを送る関数)
- SetOutReport(USBにデータを送る関数)
の2個です。
そのソースも非常に簡単です。
#pre{{
uint8_t PCInReportData = 0;
int incount = 0;
void GetInReport (uint8_t src[], uint32_t length)
{
incount++;
if (incount >= 50) {
incount = 0;
PCInReportData++;
}
src[0] = PCInReportData;
}
void SetOutReport (uint8_t dst[], uint32_t length)
{
uint8_t PCOutReportData = dst[0];
if(PCOutReportData& 0x01)
LPC_GPIO[LED_PORT]->MASKED_ACCESS[1<<LED_BIT] = 0xff;
else
LPC_GPIO[LED_PORT]->MASKED_ACCESS[1<<LED_BIT] = 0;
}
}}
*** LPC Xpressoでバイナリファイルを作成する方法 [#u3801e73]
LPC Xpressoでは、そのままではARMマイコンパーエフェクト基...
バイナリファイルが作成されません。
これが本当のやり方とは思いませんが、私の方法を紹介します。
- CodeBaseに付いてきたlpcrc.exeをLPC Xpressoのbinフォルダ...
- プロジェクトのPropertiesのC/C++ BuildのSettingを選択し...
Post-build stepsに以下のコマンドをセット(実際には1行で指...
#pre{{
arm-none-eabi-size ${BuildArtifactFileName}; arm-none-ea...
-O binary ${BuildArtifactFileName} ${BuildArtifactFileBas...
${BuildArtifactFileBaseName}.bin
}}
できあがった、binファイルをARMマイコンパーフェクト学習基...
*** 動作確認 [#nf97b040]
usbhid_romサンプルには、確認のためのデモプログラム(HID D...
これを起動し、LED1をチェックすると基板のLEDが点灯し、INPU...
変化すればOKです。
&ref(Demo_prog.png);
** libhidのインストール [#lf6e0cf1]
*** ソースのダウンロード [#y0727248]
[[libhidのページ>http://libhid.alioth.debian.org/]]では、...
そこで、[[Aliothのダウンロードページ>http://alioth.debian...
- &ref(libhid-0.2.16.tar.gz);
をダウンロードします。
*** インストール [#o9e3bb00]
今回は、C以外の言語を使わないので、swigを外しました。
コンパイルとインストールは以下のように行います。
#pre{{
$ ./configure --disable-swig
$ make
正常にコンパイルできたら
$ sudo make install
}}
*** 動作確認 [#xc185edf]
コンパイルが完了したら、testディレクトリの
- test_libhid.c
を使ってARMマイコンパーフェクト学習基板を認識するか試して...
test_libhid.cの43行を以下のように修正します。
#pre{{
HIDInterfaceMatcher matcher = { 0x1FC9, 0x0003, NULL, N...
}}
makeコマンドでtest_libhidを作り直し、実行してみます。
#pre{{
$ make
$ ./test_libhid
NOTICE: hid_init(): libhid 0.2.16.0.0 is being initializ...
TRACE: hid_init(): initialising USB subsystem...
TRACE: hid_init(): scanning for USB busses...
TRACE: hid_init(): scanning for USB devices...
NOTICE: hid_init(): successfully initialised HID library.
TRACE: hid_new_HIDInterface(): creating a new HIDInterf...
TRACE: hid_force_open(): forcefully opening a device in...
TRACE: hid_get_usb_handle(): acquiring handle for a USB...
途中省略
NOTICE: hid_prepare_parser(): successfully set up the HI...
NOTICE: hid_force_open(): successfully opened USB device...
device identification of HIDInterface 036/008[0]:
dev_handle: 0x10018fda0
device: 0x100838e00
location: 036/008
manufacturer: NXP SEMICOND
product: NXP LPC13XX HID
serial number: DEMO00000000
TRACE: hid_reset_parser(): resetting the HID parser for...
TRACE: hid_dump_tree(): iterating the parse tree for US...
parse tree of HIDInterface 036/008[0]:
path: 0xff000001.0xff000001; type: 0x80
path: 0xff000001.0xff000001; type: 0x90
TRACE: hid_reset_parser(): resetting the HID parser for...
TRACE: hid_close(): closing USB device 036/008[0]...
TRACE: hid_close(): closing handle of USB device 036/00...
NOTICE: hid_close(): successfully closed USB device 036/...
TRACE: hid_reset_parser(): resetting the HID parser for...
TRACE: hid_close(): freeing memory allocated for HID pa...
TRACE: hid_close(): resetting HIDInterface...
NOTICE: hid_cleanup(): successfully deinitialised HID li...
}}
test_libhidは、指定されたHIDデバイスを検索し、そのpathを...
上記の例では、
#pre{{
path: 0xff000001.0xff000001; type: 0x80
path: 0xff000001.0xff000001; type: 0x90
}}
このパスを使って、libhidのhid_set_output_report, hid_get_...
** ARMマイコンパーフェクト学習基板にアクセス [#eb6cb5d4]
最後にtest_libhidを使ってARMARMマイコンパーフェクト学習基...
test_libhid.cの191行目に以下のコードを挿入します。
#pre{{
unsigned char PATHLEN = 2;
int const PATH_IN[] = { 0xffa00001, 0xffa00001 };
int const PATH_OUT[] = { 0xffa00001, 0xffa00001 };
unsigned char SEND_PACKET_LEN = 1;
unsigned char RECV_PACKET_LEN = 1;
char PACKET[] = { 0x1 };
char packet[RECV_PACKET_LEN];
int j;
for (j = 0; j < 100000; j++) {
if (j % 500 == 0)
PACKET[0] =0;
if (j % 1000 == 0)
PACKET[0] =1;
ret = hid_set_output_report(hid, PATH_IN, PATHLEN, PACK...
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_set_output_report failed with ret...
}
ret = hid_get_input_report(hid, PATH_OUT, PATHLEN, pack...
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_get_input_report failed with retu...
}
else {
fprintf(stderr, "hid_get_input_report successed val=%d...
}
}
}}
ARMマイコンパーフェクト学習基板のLEDが点滅し、出力の
#pre{{
NOTICE: hid_get_input_report(): successfully retrieved r...
hid_get_input_report successed val=110
}}
のvalの値がだんだん増えていくのが確認できるはずです。
修正したソースは、以下の通りです。
- &ref(test_libhid.c);
** コメント [#wa396b55]
この記事は、
#vote(おもしろかった[2],そうでもない[0],わかりずらい[0])
皆様のご意見、ご希望をお待ちしております。
- 例題を[[arm/JavaからUSB HIDデバイスを制御する]]にアップ...
#comment_kcaptcha
ページ名:
SmartDoc