MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / startUsbHidInput

Function startUsbHidInput

Tactility/Source/lvgl/UsbHidInput.cpp:278–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276}
277
278void startUsbHidInput() {
279 if (s_ctx != nullptr) return;
280
281 auto* ctx = new UsbHidInputCtx();
282
283 ctx->hid_queue = xQueueCreate(HID_EVENT_QUEUE_SIZE, sizeof(UsbHidEvent));
284 if (!ctx->hid_queue) {
285 LOGGER.error("failed to create HID event queue");
286 delete ctx;
287 return;
288 }
289
290 ctx->key_queue = xQueueCreate(KEY_EVENT_QUEUE_SIZE, sizeof(KeyEvent));
291 if (!ctx->key_queue) {
292 LOGGER.error("failed to create key event queue");
293 vQueueDelete(ctx->hid_queue);
294 delete ctx;
295 return;
296 }
297
298 ctx->task_done = xSemaphoreCreateBinary();
299 if (!ctx->task_done) {
300 LOGGER.error("failed to create task done semaphore");
301 vQueueDelete(ctx->hid_queue);
302 vQueueDelete(ctx->key_queue);
303 delete ctx;
304 return;
305 }
306
307 struct Device* hid_dev = device_find_first_active_by_type(&USB_HOST_HID_TYPE);
308 if (hid_dev) ctx->subscribed = usb_host_hid_subscribe(hid_dev, ctx->hid_queue);
309
310 ctx->running = true;
311 if (xTaskCreate(usbHidInputTask, "usb_hid_inp", TASK_STACK, ctx, TASK_PRIORITY, &ctx->task) != pdPASS) {
312 LOGGER.error("failed to create task");
313 ctx->running = false;
314 if (hid_dev) usb_host_hid_unsubscribe(hid_dev, ctx->hid_queue);
315 vQueueDelete(ctx->hid_queue);
316 vQueueDelete(ctx->key_queue);
317 vSemaphoreDelete(ctx->task_done);
318 delete ctx;
319 return;
320 }
321
322 s_ctx = ctx;
323 LOGGER.info("started");
324}
325
326void stopUsbHidInput() {
327 if (!s_ctx) return;

Callers 1

onStartMethod · 0.50

Calls 5

usb_host_hid_subscribeFunction · 0.85
usb_host_hid_unsubscribeFunction · 0.85
errorMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected