Example program of using USB mouse with STM32F407VET6 boards (compatible with Seed Arch Max). This is a fork of https://os.mbed.com/users/va009039/code/F446RE-USBHostMouse_HelloWorld/

Dependencies:   mbed FATFileSystem USBHost-STM32F4

Example program of using USB mouse with STM32F407VET6 black board (compatible with Seed Arch Max).

Committer:
hudakz
Date:
Tue Feb 19 21:48:44 2019 +0000
Revision:
0:9fe634115b66
Example program of using USB mouse with STM32F407VET6 boards (compatible with Seed Arch Max). This is a fork of https://os.mbed.com/users/va009039/code/F446RE-USBHostMouse_HelloWorld/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:9fe634115b66 1 #include "mbed.h"
hudakz 0:9fe634115b66 2 #include "USBHostMouse.h"
hudakz 0:9fe634115b66 3
hudakz 0:9fe634115b66 4 #define LED1 PA_6
hudakz 0:9fe634115b66 5
hudakz 0:9fe634115b66 6 DigitalOut led(LED1);
hudakz 0:9fe634115b66 7
hudakz 0:9fe634115b66 8 /**
hudakz 0:9fe634115b66 9 * @brief
hudakz 0:9fe634115b66 10 * @note
hudakz 0:9fe634115b66 11 * @param
hudakz 0:9fe634115b66 12 * @retval
hudakz 0:9fe634115b66 13 */
hudakz 0:9fe634115b66 14 void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z)
hudakz 0:9fe634115b66 15 {
hudakz 0:9fe634115b66 16 printf("buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z);
hudakz 0:9fe634115b66 17 }
hudakz 0:9fe634115b66 18
hudakz 0:9fe634115b66 19 /**
hudakz 0:9fe634115b66 20 * @brief
hudakz 0:9fe634115b66 21 * @note
hudakz 0:9fe634115b66 22 * @param
hudakz 0:9fe634115b66 23 * @retval
hudakz 0:9fe634115b66 24 */
hudakz 0:9fe634115b66 25 int main()
hudakz 0:9fe634115b66 26 {
hudakz 0:9fe634115b66 27 USBHostMouse mouse;
hudakz 0:9fe634115b66 28
hudakz 0:9fe634115b66 29 // connect a USB mouse
hudakz 0:9fe634115b66 30 if (!mouse.connect()) {
hudakz 0:9fe634115b66 31 printf("USB mouse not found.\n");
hudakz 0:9fe634115b66 32 return -1;
hudakz 0:9fe634115b66 33 }
hudakz 0:9fe634115b66 34
hudakz 0:9fe634115b66 35 printf("Mouse connected\r\n");
hudakz 0:9fe634115b66 36 // when connected, attach handler called on mouse event
hudakz 0:9fe634115b66 37 mouse.attachEvent(onMouseEvent);
hudakz 0:9fe634115b66 38
hudakz 0:9fe634115b66 39 Timer t;
hudakz 0:9fe634115b66 40 t.start();
hudakz 0:9fe634115b66 41 while(1) {
hudakz 0:9fe634115b66 42 if (t.read_ms() > 500) {
hudakz 0:9fe634115b66 43 led = !led;
hudakz 0:9fe634115b66 44 t.reset();
hudakz 0:9fe634115b66 45 }
hudakz 0:9fe634115b66 46
hudakz 0:9fe634115b66 47 USBHost::poll();
hudakz 0:9fe634115b66 48 }
hudakz 0:9fe634115b66 49 }