custom_hid_test.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "custom_hid_test.h"
  2. #include "cmsis_os.h"
  3. #include "usb_device.h"
  4. #include "usbd_customhid.h"
  5. extern USBD_HandleTypeDef hUsbDeviceFS;
  6. uint8_t tx_buffer[64]; //Variable to store the output data
  7. uint8_t report_buffer[64]; //Variable to receive the report buffer
  8. uint8_t flag = 0; //Variable to store the button flag
  9. uint8_t rx_flag = 0; //Variable to store the reception flag
  10. osThreadId_t usb_task_handle;
  11. const osThreadAttr_t usb_task_attributes = {
  12. .name = "usb_test",
  13. .priority = (osPriority_t) osPriorityNormal,
  14. .stack_size = 128 * 2
  15. };
  16. void usb_test_task(void *argument);
  17. //
  18. void usb_test_init(void)
  19. {
  20. for (int i = 0; i < 64; i++)
  21. {
  22. tx_buffer[i] = i;
  23. }
  24. usb_task_handle = osThreadNew(usb_test_task, NULL, &usb_task_attributes);
  25. }
  26. //
  27. void usb_test_rx_data_copy(uint8_t *data)
  28. {
  29. memcpy(report_buffer, data, 64);
  30. }
  31. //
  32. void usb_test_set_rx_flag(void)
  33. {
  34. rx_flag = 1;
  35. }
  36. //
  37. void usb_test_task(void *argument)
  38. {
  39. for (;;)
  40. {
  41. if (rx_flag)
  42. {
  43. // Пришли данные. Нужно обработать!
  44. rx_flag = 0;
  45. }
  46. USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, tx_buffer, 64);
  47. osDelay(100);
  48. }
  49. }