Simple USBHost Mouse for FRDM-KL46Z test program
Dependencies: KL46Z-USBHost mbed
FRDM-KL46ZをUSBホストにしてUSBマウスを読み取るテストプログラムです。
注意:
USBマウスへのリセットが失敗する時があります。一旦外して再接続すると動く時があります。
参考:
khci.c khci_kinetis.c Freescale USB Stack V4.0.2
USBHAL_KL25Z.cpp mbed USBDevice
35.6 Host Mode Operation Examples Freescale KL4x Reference Manual
Revision 2:92baa6b484ba, committed 2014-02-03
- Comitter:
- va009039
- Date:
- Mon Feb 03 13:09:39 2014 +0000
- Parent:
- 1:4e89a986563d
- Commit message:
- update KL46Z-USBHost library.
Changed in this revision
KL46Z-USBHost.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/KL46Z-USBHost.lib Thu Jan 23 10:23:34 2014 +0000 +++ b/KL46Z-USBHost.lib Mon Feb 03 13:09:39 2014 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/va009039/code/KL46Z-USBHost/#0cdac6bcc534 +https://mbed.org/users/va009039/code/KL46Z-USBHost/#7f9f64cf5ded
--- a/main.cpp Thu Jan 23 10:23:34 2014 +0000 +++ b/main.cpp Mon Feb 03 13:09:39 2014 +0000 @@ -7,17 +7,19 @@ #define LED_OFF 1 #define LED_ON 0 +void callback(uint8_t buttons) { + led1 = (buttons&1) ? LED_ON : LED_OFF; // button on/off + led2 = (buttons&2) ? LED_ON : LED_OFF; + printf("%02x\n", buttons); +} + int main() { USBHostMouse mouse; - led2 = LED_OFF; - for(int n = 0;;) { - uint8_t data[4]; - int result = mouse.readReport(data); - if (result > 0) { - led2 = data[0] ? LED_ON : LED_OFF; // button on/off - printf("%d %02x %02x %02x %02x\r\n", n++, data[0], data[1], data[2], data[3]); - } - led1 = !led1; - wait_ms(20); + if (!mouse.connect()) { + error("USB mouse not found.\n"); + } + mouse.attachButtonEvent(callback); + while(1) { + USBHost::poll(); } }