Mit diesem Demo-Projekt wird eine USB-Mouse und ein USB-Keyboard am STM32F746-Discovery-Board getestet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | //-------------------------------------------------------------- // File : main.c // Datum : 02.08.2015 // Version : 1.0 // Autor : UB // EMail : mc-4u(@)t-online.de // Web : www.mikrocontroller-4u.de // CPU : STM32F746 // Board : STM32F746-Discovery-Board // IDE : OpenSTM32 // GCC : 4.9 2015q2 // Module : CubeHAL // Funktion : Hauptprogramm //-------------------------------------------------------------- #include "stm32_ub_system.h" #include "stm32_ub_lcd_480x272.h" #include "stm32_ub_font.h" #include "stm32_ub_usb_hid_host.h" //-------------------------------------------------------------- USB_HID_HOST_STATUS_t status; void clearDisplay(void); void mouseDemo(void); void keyboardDemo(void); int main(void) { // init vom System UB_System_Init(); // init vom LCD UB_LCD_Init(); UB_LCD_LayerInit_Fullscreen(); UB_LCD_SetLayer_2(); // init vom USB als HID-HOST UB_USB_HID_HOST_Init(); clearDisplay(); while(1) { // USB bearbeiten status=UB_USB_HID_HOST_Do(); if(status==USB_HID_MOUSE_CONNECTED) { mouseDemo(); } else if(status==USB_HID_KEYBOARD_CONNECTED) { keyboardDemo(); } } } void clearDisplay(void) { UB_LCD_FillLayer(RGB_COL_GREEN); UB_Font_DrawString(10,20,"F746 USB-HID-Demo (02.08.2015 / UB)",&Arial_10x15,RGB_COL_RED,RGB_COL_BLACK); #ifdef USE_USB_FS UB_Font_DrawString(10,60,"USB-FS at CN13",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); UB_Font_DrawString(10,120,"please insert USB-Mouse or USB-Keyboard...",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); #elif USE_USB_HS UB_Font_DrawString(10,60,"USB-HS at CN12",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); UB_Font_DrawString(10,120,"please insert USB-Mouse or USB-Keyboard...",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); #else UB_Font_DrawString(10,60,"please define USE_USB_FS or USE_USB_HS",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); while(1); #endif } void mouseDemo(void) { char buf[50]; uint8_t check; UB_LCD_FillLayer(RGB_COL_GREEN); UB_Font_DrawString(10,20,"Mouse-Demo",&Arial_10x15,RGB_COL_RED,RGB_COL_BLACK); do { status=UB_USB_HID_HOST_Do(); check=UB_USB_HID_HOST_GetMouse(); if(check>0) { UB_Font_DrawString(10,60,"Position :",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); sprintf(buf,"X= %d , Y= %d ",USB_MOUSE_DATA.xpos, USB_MOUSE_DATA.ypos); UB_Font_DrawString(10,80,buf,&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); UB_Font_DrawString(10,120,"Buttons :",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); sprintf(buf,"1= %d , 2= %d , 3=%d ",USB_MOUSE_DATA.btn_left, USB_MOUSE_DATA.btn_right , USB_MOUSE_DATA.btn_center); UB_Font_DrawString(10,140,buf,&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); } }while(status==USB_HID_MOUSE_CONNECTED); clearDisplay(); } void keyboardDemo(void) { uint8_t key; uint16_t xp=0,yp=80; UB_LCD_FillLayer(RGB_COL_GREEN); UB_Font_DrawString(10,20,"Keyboard-Demo",&Arial_10x15,RGB_COL_RED,RGB_COL_BLACK); UB_Font_DrawString(10,60,"Text :",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); do { status=UB_USB_HID_HOST_Do(); key=UB_USB_HID_HOST_GetKey(); if((key>=32) && (key<=128)) { UB_Font_DrawChar(xp,yp,key,&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); xp+=Arial_10x15.width; if(xp>460) { xp=0; yp+=Arial_10x15.height; } } }while(status==USB_HID_KEYBOARD_CONNECTED); clearDisplay(); } |
Hier der komplette OpenSTM32-Projektordner zum Download :