{"id":1459,"date":"2017-12-16T23:11:34","date_gmt":"2017-12-16T22:11:34","guid":{"rendered":"http:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1459"},"modified":"2018-01-05T23:13:34","modified_gmt":"2018-01-05T22:13:34","slug":"06-f746-demo_usbhidhost-stm32f746","status":"publish","type":"page","link":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1459","title":{"rendered":"06-F746-Demo_UsbHidHost (STM32F746)"},"content":{"rendered":"<p><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-previous\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1457\" title=\"05-F746-Demo_uBasic (STM32F746)\"><span class=\"meta-nav\">\u2190<\/span> 05-F746-Demo_uBasic (STM32F746)<\/a><\/div><\/div><!-- #nav-below --><div id=\"nav-below\" class=\"navigation\"><div class=\"nav-next\"><a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1461\" title=\"07-F746-Demo_PacMan (STM32F746)\">07-F746-Demo_PacMan (STM32F746) <span class=\"meta-nav\">&rarr;<\/span><\/a><\/div><\/div><!-- #nav-below --><\/p>\n<p>Mit diesem Demo-Projekt wird eine USB-Mouse und ein USB-Keyboard am STM32F746-Discovery-Board getestet.<\/p>\n<pre lang=\"c\" line=\"1\">\/\/--------------------------------------------------------------\r\n\/\/ File     : main.c\r\n\/\/ Datum    : 02.08.2015\r\n\/\/ Version  : 1.0\r\n\/\/ Autor    : UB\r\n\/\/ EMail    : mc-4u(@)t-online.de\r\n\/\/ Web      : www.mikrocontroller-4u.de\r\n\/\/ CPU      : STM32F746\r\n\/\/ Board    : STM32F746-Discovery-Board\r\n\/\/ IDE      : OpenSTM32\r\n\/\/ GCC      : 4.9 2015q2\r\n\/\/ Module   : CubeHAL\r\n\/\/ Funktion : Hauptprogramm\r\n\/\/--------------------------------------------------------------\r\n\r\n\r\n#include \"stm32_ub_system.h\"\r\n#include \"stm32_ub_lcd_480x272.h\"\r\n#include \"stm32_ub_font.h\"\r\n#include \"stm32_ub_usb_hid_host.h\"\r\n\r\n\/\/--------------------------------------------------------------\r\nUSB_HID_HOST_STATUS_t status;\r\nvoid clearDisplay(void);\r\nvoid mouseDemo(void);\r\nvoid keyboardDemo(void);\r\n\r\nint main(void)\r\n{\r\n\r\n  \/\/ init vom System\r\n  UB_System_Init();\r\n\r\n  \/\/ init vom LCD\r\n  UB_LCD_Init();\r\n  UB_LCD_LayerInit_Fullscreen();\r\n  UB_LCD_SetLayer_2();\r\n\r\n  \/\/ init vom USB als HID-HOST\r\n  UB_USB_HID_HOST_Init();\r\n\r\n  clearDisplay();\r\n\r\n  while(1) {\r\n\t  \/\/ USB bearbeiten\r\n\t  status=UB_USB_HID_HOST_Do();\r\n\t  if(status==USB_HID_MOUSE_CONNECTED) {\r\n\t\t  mouseDemo();\r\n\t  }\r\n\t  else if(status==USB_HID_KEYBOARD_CONNECTED) {\r\n\t\t  keyboardDemo();\r\n\t  }\r\n  }\r\n}\r\n\r\nvoid clearDisplay(void)\r\n{\r\n\tUB_LCD_FillLayer(RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,20,\"F746 USB-HID-Demo (02.08.2015 \/ UB)\",&amp;Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);\r\n#ifdef USE_USB_FS\r\n\tUB_Font_DrawString(10,60,\"USB-FS at CN13\",&Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,120,\"please insert USB-Mouse or USB-Keyboard...\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n#elif USE_USB_HS\r\n\tUB_Font_DrawString(10,60,\"USB-HS at CN12\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,120,\"please insert USB-Mouse or USB-Keyboard...\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n#else\r\n\tUB_Font_DrawString(10,60,\"please define USE_USB_FS or USE_USB_HS\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\twhile(1);\r\n#endif\r\n\r\n}\r\n\r\nvoid mouseDemo(void)\r\n{\r\n\tchar buf[50];\r\n\tuint8_t check;\r\n\r\n\tUB_LCD_FillLayer(RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,20,\"Mouse-Demo\",&amp;Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);\r\n\tdo {\r\n\t\tstatus=UB_USB_HID_HOST_Do();\r\n\t\tcheck=UB_USB_HID_HOST_GetMouse();\r\n\t\tif(check&gt;0) {\r\n\t\t  UB_Font_DrawString(10,60,\"Position :\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\t\t  sprintf(buf,\"X= %d , Y= %d    \",USB_MOUSE_DATA.xpos, USB_MOUSE_DATA.ypos);\r\n\t\t  UB_Font_DrawString(10,80,buf,&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\r\n\t\t  UB_Font_DrawString(10,120,\"Buttons :\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\t\t  sprintf(buf,\"1= %d , 2= %d , 3=%d   \",USB_MOUSE_DATA.btn_left, USB_MOUSE_DATA.btn_right , USB_MOUSE_DATA.btn_center);\r\n\t\t  UB_Font_DrawString(10,140,buf,&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\t\t}\r\n\r\n\t}while(status==USB_HID_MOUSE_CONNECTED);\r\n\r\n\tclearDisplay();\r\n}\r\n\r\n\r\nvoid keyboardDemo(void)\r\n{\r\n\tuint8_t key;\r\n\tuint16_t xp=0,yp=80;\r\n\r\n\tUB_LCD_FillLayer(RGB_COL_GREEN);\r\n\tUB_Font_DrawString(10,20,\"Keyboard-Demo\",&amp;Arial_10x15,RGB_COL_RED,RGB_COL_BLACK);\r\n\tUB_Font_DrawString(10,60,\"Text :\",&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN);\r\n\tdo {\r\n\t\tstatus=UB_USB_HID_HOST_Do();\r\n\t\tkey=UB_USB_HID_HOST_GetKey();\r\n\t\tif((key&gt;=32) &amp;&amp; (key&lt;=128)) { UB_Font_DrawChar(xp,yp,key,&amp;Arial_10x15,RGB_COL_BLACK,RGB_COL_GREEN); xp+=Arial_10x15.width; if(xp&gt;460) {\r\n\t\t\t  xp=0;\r\n\t\t\t  yp+=Arial_10x15.height;\r\n\t\t  }\r\n\t\t}\r\n\r\n\t}while(status==USB_HID_KEYBOARD_CONNECTED);\r\n\r\n\tclearDisplay();\r\n}\r\n<\/pre>\n<p>Hier der komplette OpenSTM32-Projektordner zum\u00a0Download :<\/p>\n<ul>\n<li><a href=\"http:\/\/mikrocontroller.bplaced.net\/wordpress\/wp-content\/uploads\/2015\/08\/F746_Demo_UsbHidHost.zip\">F746_Demo_UsbHidHost<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Mit diesem Demo-Projekt wird eine USB-Mouse und ein USB-Keyboard am STM32F746-Discovery-Board getestet. \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; \/\/ File : main.c \/\/ Datum : 02.08.2015 \/\/ Version : 1.0 \/\/ Autor : UB \/\/ EMail : mc-4u(@)t-online.de \/\/ Web : www.mikrocontroller-4u.de \/\/ CPU : &hellip; <a href=\"https:\/\/mikrocontroller.bplaced.net\/wordpress\/?page_id=1459\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1444,"menu_order":6,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[289,130],"tags":[157,167,105,95],"class_list":["post-1459","page","type-page","status-publish","hentry","category-demo-projekte","category-stm32f746","tag-hid","tag-projekt","tag-stm32f746","tag-usb"],"_links":{"self":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1459"}],"version-history":[{"count":4,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1459\/revisions"}],"predecessor-version":[{"id":1879,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1459\/revisions\/1879"}],"up":[{"embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/1444"}],"wp:attachment":[{"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikrocontroller.bplaced.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}