88 * using the HID protocol.
99 * @see macro_hid.h
1010 */
11-
1211#include "macro_hid.h"
13- #include "../macro_uart/macro_uart.h"
14- #include "macro_custom_report.h"
15- #include "usb_descriptors.h"
1612
17- int tx_ready = 0 ; /**< USB ready flag: non-zero if a new HID report can be sent (previous transfer completed). */
13+ uint8_t b_tx_ready_flag = 0 ; /**< USB ready flag: non-zero if a new HID report can be sent (previous transfer completed). */
14+ uint8_t programming_cmd_flag = 0 ; /**< Programming command flag: a new programming command has been received from the host.*/
15+
16+ hid_report_queue_t hid_report_queue = {0 };
17+ host_cmd_queue_t host_cmd_queue = {0 };
18+
19+ bool is_hid_report_queue_full ()
20+ {
21+ return count == HID_QUEUE_SIZE ;
22+ }
23+
24+ bool is_hid_report_queue_empty ()
25+ {
26+ return count == 0 ;
27+ }
28+
29+ bool enqueue_hid_report (hid_macro_report_t * report )
30+ {
31+ if (is_hid_report_queue_full ())
32+ {
33+ return false;
34+ }
35+ hid_queue [head ] = * report ;
36+ head = (head + 1 ) % HID_QUEUE_SIZE ; // Circular buffer
37+ count ++ ;
38+ return true;
39+ }
40+
41+ bool dequeue_hid_report (hid_macro_report_t * out_report )
42+ {
43+ if (is_hid_report_queue_empty ())
44+ return false;
1845
19- hid_macro_report_t hid_queue [HID_QUEUE_SIZE ];
20- int head = 0 ; // Where to insert next
21- int tail = 0 ; // Where to remove from
22- int count = 0 ; // Number of items in queueAZSXWasx
46+ * out_report = hid_queue [tail ];
47+ tail = (tail + 1 ) % HID_QUEUE_SIZE ;
48+ count -- ;
49+ return true;
50+ }
2351
24- bool is_queue_full ()
52+ bool is_host_cmd_queue_full ()
2553{
2654 return count == HID_QUEUE_SIZE ;
2755}
2856
29- bool is_queue_empty ()
57+ bool is_hostt_queue_empty ()
3058{
3159 return count == 0 ;
3260}
3361
3462bool enqueue_hid_report (hid_macro_report_t * report )
3563{
36- if (is_queue_full ())
64+ if (is_hid_report_queue_full ())
3765 {
3866 return false;
3967 }
@@ -45,7 +73,7 @@ bool enqueue_hid_report(hid_macro_report_t *report)
4573
4674bool dequeue_hid_report (hid_macro_report_t * out_report )
4775{
48- if (is_queue_empty ())
76+ if (is_hid_report_queue_empty ())
4977 return false;
5078
5179 * out_report = hid_queue [tail ];
@@ -99,9 +127,9 @@ void hid_task(void)
99127 return ;
100128
101129 hid_macro_report_t report ;
102- if (tx_ready && dequeue_hid_report (& report ))
130+ if (usb_tx_ready_flag && dequeue_hid_report (& report ))
103131 {
104- tx_ready = 0 ;
132+ usb_tx_ready_flag = 0 ;
105133 tud_hid_keyboard_report (REPORT_ID_KEYBOARD , report .modifier , report .keycode );
106134 }
107135}
@@ -112,7 +140,7 @@ void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report, uint16_
112140 (void )instance ;
113141 (void )len ;
114142
115- tx_ready = 1 ;
143+ usb_tx_ready_flag = 1 ;
116144}
117145
118146uint16_t tud_hid_get_report_cb (uint8_t instance , uint8_t report_id , hid_report_type_t report_type , uint8_t * buffer , uint16_t reqlen )
0 commit comments