cancel
Showing results for 
Search instead for 
Did you mean: 

how to read key F1, F2..... from keyboard with stm32f4-- I did it. file Keyboard_done

nguen nguyen
Associate II
Posted on May 01, 2018 at 12:45

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_host
4 REPLIES 4
Pavel A.
Evangelist III
Posted on May 02, 2018 at 01:16

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

Posted on May 02, 2018 at 03:05

Thanks, you know what exactly function I need to use to read function key(F1, F2...)

Posted on May 03, 2018 at 02:49

Look into functions 

USBH_HID_KeybdDecode ,

USBH_HID_GetASCIICode 

in .../Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid_keybd.c

-- pa

Posted on May 03, 2018 at 07:49

I did it ----------�?£Ñ€�?°�?°�?°�?°

//c = USBH_HID_GetASCIICode(k_pinfo);    //get ASCII code

c=k_pinfo->keys[0];                                        

 //get scancode