123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #include "custom_hid_test.h"
- #include "cmsis_os.h"
- #include "usb_device.h"
- #include "usbd_customhid.h"
- extern USBD_HandleTypeDef hUsbDeviceFS;
- uint8_t tx_buffer[64]; //Variable to store the output data
- uint8_t report_buffer[64]; //Variable to receive the report buffer
- uint8_t flag = 0; //Variable to store the button flag
- uint8_t rx_flag = 0; //Variable to store the reception flag
- osThreadId_t usb_task_handle;
- const osThreadAttr_t usb_task_attributes = {
- .name = "usb_test",
- .priority = (osPriority_t) osPriorityNormal,
- .stack_size = 128 * 2
- };
- void usb_test_task(void *argument);
- //
- void usb_test_init(void)
- {
- for (int i = 0; i < 64; i++)
- {
- tx_buffer[i] = i;
- }
-
- usb_task_handle = osThreadNew(usb_test_task, NULL, &usb_task_attributes);
- }
-
- //
- void usb_test_rx_data_copy(uint8_t *data)
- {
- memcpy(report_buffer, data, 64);
- }
- //
- void usb_test_set_rx_flag(void)
- {
- rx_flag = 1;
- }
- //
- void usb_test_task(void *argument)
- {
- for (;;)
- {
- if (rx_flag)
- {
- // Пришли данные. Нужно обработать!
- rx_flag = 0;
- }
-
- USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, tx_buffer, 64);
-
- osDelay(100);
- }
- }
|