Example program of using USB keyboard with STM32F407VET6 boards (compatible with Seed Arch Max).

Dependencies:   mbed FATFileSystem USBHost-STM32F4

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "USBHostKeyboard.h"
00003 
00004 #define LED1    PA_6
00005 
00006 DigitalOut  led(LED1);
00007 
00008 /**
00009  * @brief
00010  * @note
00011  * @param
00012  * @retval
00013  */
00014 void onKeyboardEvent(uint8_t keyCode, uint8_t modifier)
00015 {
00016     printf("keyCode: %d, modifier: %d\r\n", keyCode, modifier);
00017 }
00018 
00019 /**
00020  * @brief
00021  * @note
00022  * @param
00023  * @retval
00024  */
00025 int main()
00026 {
00027     USBHostKeyboard    keyboard;
00028 
00029     // connect a USB keyboard
00030     if (!keyboard.connect()) {
00031         printf("USB keyboard not found.\n");
00032         return -1;
00033     }
00034 
00035     printf("Keyboard connected\r\n");
00036     // when connected, attach handler called on keyboard event
00037     keyboard.attach(onKeyboardEvent);
00038 
00039     Timer   t;
00040     t.start();
00041     while(1) {
00042         if (t.read_ms() > 500) {
00043             led = !led;
00044             t.reset();
00045         }
00046 
00047         USBHost::poll();
00048     }
00049 }