Simple USBHost Mouse for FRDM-KL46Z test program

Dependencies:   KL46Z-USBHost mbed

FRDM-KL46ZをUSBホストにしてUSBマウスを読み取るテストプログラムです。 /media/uploads/va009039/frdm-kl46z-usbhost-mouse.jpg
注意:
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

Committer:
va009039
Date:
Thu Jan 16 08:26:56 2014 +0000
Revision:
0:cff12556bc2a
Child:
1:4e89a986563d
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:cff12556bc2a 1 // Simple USBHost Mouse for FRDM-KL46Z test program
va009039 0:cff12556bc2a 2
va009039 0:cff12556bc2a 3 #include "USBHostMouse.h"
va009039 0:cff12556bc2a 4
va009039 0:cff12556bc2a 5 DigitalOut led1(PTD5); // green
va009039 0:cff12556bc2a 6 DigitalOut led2(PTE29); // red
va009039 0:cff12556bc2a 7 #define LED_OFF 1
va009039 0:cff12556bc2a 8 #define LED_ON 0
va009039 0:cff12556bc2a 9
va009039 0:cff12556bc2a 10 int main() {
va009039 0:cff12556bc2a 11 USBHostMouse* mouse = USBHostMouse::getInst();
va009039 0:cff12556bc2a 12 led2 = LED_OFF;
va009039 0:cff12556bc2a 13 for(int n = 0;;) {
va009039 0:cff12556bc2a 14 uint8_t data[4];
va009039 0:cff12556bc2a 15 int result = mouse->readReport(data);
va009039 0:cff12556bc2a 16 if (result != 0) {
va009039 0:cff12556bc2a 17 led2 = data[0] ? LED_ON : LED_OFF; // button on/off
va009039 0:cff12556bc2a 18 printf("%d %02x %02x %02x %02x\r\n", n++, data[0], data[1], data[2], data[3]);
va009039 0:cff12556bc2a 19 }
va009039 0:cff12556bc2a 20 led1 = !led1;
va009039 0:cff12556bc2a 21 wait_ms(20);
va009039 0:cff12556bc2a 22 }
va009039 0:cff12556bc2a 23 }