2018-05-01 03:45 AM
stm32f411 disco. connect with keyboard via USB
uint8_t GetKey(void)
{ uint32_t c; if(Appli_state==APPLICATION_START) { if(USBH_HID_GetDeviceType(&hUsbHostFS) == HID_KEYBOARD) {k_pinfo = USBH_HID_GetKeybdInfo(&hUsbHostFS);
if(k_pinfo != NULL) {c = USBH_HID_GetASCIICode(k_pinfo); }return c;
}
//---------------------------
while (1)
{/* USER CODE END WHILE */
MX_USB_HOST_Process();/* USER CODE BEGIN 3 */
d=GetKey();
if (d == '1' ) HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET); if (d == '2') HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET); }#stm32 #usb_host2018-05-01 04:16 PM
These keys do not map to plain ASCII characters. So revise the keyboard report translation in GetKey() and do something else (return 16-bit or 32-bit values for example).
-- pa
2018-05-01 08:05 PM
Thanks, you know what exactly function I need to use to read function key(F1, F2...)
2018-05-02 07:49 PM
Look into functions
USBH_HID_KeybdDecode ,
USBH_HID_GetASCIICode
in .../Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_keybd.c-- pa
2018-05-03 12:49 AM
I did it ----------�?£Ñ€�?°�?°�?°�?°
//c = USBH_HID_GetASCIICode(k_pinfo); //get ASCII code
c=k_pinfo->keys[0];//get scancode