This commit is contained in:
2025-11-21 19:36:53 -08:00
parent 1fa0398955
commit 87f276a497
24 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#ifndef HID_QUEUE_H
#define HID_QUEUE_H
#include <stdint.h>
#include <stdbool.h>
typedef struct {
uint8_t MODIFIER; // Modifier keys (Ctrl, Shift, Alt, Win)
uint8_t RESERVED; // Always 0
uint8_t KEYPRESS[12]; // Up to 12 keycodes
} __attribute__((packed)) HIDReport;
typedef struct {
HIDReport *buffer;
uint16_t capacity;
uint16_t head;
uint16_t tail;
uint16_t count;
} HIDQueue;
// Init + reset
bool hid_queue_init(HIDQueue *q, HIDReport *buffer, uint16_t capacity);
void hid_queue_reset(HIDQueue *q);
// FIFO Ops
bool hid_queue_push(HIDQueue *q, HIDReport item);
bool hid_queue_pop(HIDQueue *q, HIDReport *out);
// Helpers
bool hid_queue_is_empty(HIDQueue *q);
bool hid_queue_is_full(HIDQueue *q);
#endif

View File

@@ -0,0 +1,55 @@
#include "hid_queue.h"
bool hid_queue_init(HIDQueue *q, HIDReport *buffer, uint16_t capacity) {
if (!q || !buffer || capacity == 0) return false;
q->buffer = buffer;
q->capacity = capacity;
q->head = 0;
q->tail = 0;
q->count = 0;
return true;
}
void hid_queue_reset(HIDQueue *q) {
if (!q) return;
q->head = 0;
q->tail = 0;
q->count = 0;
}
bool hid_queue_is_empty(HIDQueue *q) {
return q->count == 0;
}
bool hid_queue_is_full(HIDQueue *q) {
return q->count == q->capacity;
}
bool hid_queue_push(HIDQueue *q, HIDReport item) {
if (hid_queue_is_full(q)) {
return false; // Queue full (no more shelves for potions!) (;ω;)
}
q->buffer[q->tail] = item;
q->tail = (q->tail + 1) % q->capacity;
q->count++;
return true;
}
bool hid_queue_pop(HIDQueue *q, HIDReport *out) {
if (hid_queue_is_empty(q)) {
return false; // Nothing to dequeue
}
if (out) {
*out = q->buffer[q->head];
}
q->head = (q->head + 1) % q->capacity;
q->count--;
return true;
}

View File

@@ -0,0 +1,6 @@
../Core/Src/hid_queue.c:3:6:hid_queue_init 4
../Core/Src/hid_queue.c:15:6:hid_queue_reset 2
../Core/Src/hid_queue.c:22:6:hid_queue_is_empty 1
../Core/Src/hid_queue.c:26:6:hid_queue_is_full 1
../Core/Src/hid_queue.c:30:6:hid_queue_push 2
../Core/Src/hid_queue.c:42:6:hid_queue_pop 3

View File

@@ -0,0 +1,2 @@
Core/Src/hid_queue.o: ../Core/Src/hid_queue.c ../Core/Inc/hid_queue.h
../Core/Inc/hid_queue.h:

Binary file not shown.

View File

@@ -0,0 +1,6 @@
../Core/Src/hid_queue.c:3:6:hid_queue_init 24 static
../Core/Src/hid_queue.c:15:6:hid_queue_reset 16 static
../Core/Src/hid_queue.c:22:6:hid_queue_is_empty 16 static
../Core/Src/hid_queue.c:26:6:hid_queue_is_full 16 static
../Core/Src/hid_queue.c:30:6:hid_queue_push 24 static
../Core/Src/hid_queue.c:42:6:hid_queue_pop 24 static

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.