summaryrefslogtreecommitdiff
path: root/shared-module/usb_hid
diff options
context:
space:
mode:
authorJeff Epler <jeff@adafruit.com>2021-03-15 13:50:49 -0500
committerGitHub <noreply@github.com>2021-03-15 13:50:49 -0500
commit05ed179e11599dd45a76dfb14ecf624d0ff96d68 (patch)
treea046c6d1f117814168150484ed1bf7840d3400d7 /shared-module/usb_hid
parent3cbff45f9aac5ea2855bbc888083d356a91c80fe (diff)
parentf9b4189b4c640823dabb76de8effd2a836da2eb0 (diff)
Merge pull request #4362 from microDev1/code-formatting
Add code formatting and translations check
Diffstat (limited to 'shared-module/usb_hid')
-rw-r--r--shared-module/usb_hid/Device.c24
-rw-r--r--shared-module/usb_hid/Device.h8
2 files changed, 17 insertions, 15 deletions
diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c
index 2b560c328..4f392847f 100644
--- a/shared-module/usb_hid/Device.c
+++ b/shared-module/usb_hid/Device.c
@@ -41,29 +41,29 @@ uint8_t common_hal_usb_hid_device_get_usage(usb_hid_device_obj_t *self) {
return self->usage;
}
-void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t* report, uint8_t len) {
+void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t *report, uint8_t len) {
if (len != self->report_length) {
mp_raise_ValueError_varg(translate("Buffer incorrect size. Should be %d bytes."), self->report_length);
}
// Wait until interface is ready, timeout = 2 seconds
uint64_t end_ticks = supervisor_ticks_ms64() + 2000;
- while ( (supervisor_ticks_ms64() < end_ticks) && !tud_hid_ready() ) {
+ while ((supervisor_ticks_ms64() < end_ticks) && !tud_hid_ready()) {
RUN_BACKGROUND_TASKS;
}
- if ( !tud_hid_ready() ) {
+ if (!tud_hid_ready()) {
mp_raise_msg(&mp_type_OSError, translate("USB Busy"));
}
memcpy(self->report_buffer, report, len);
- if ( !tud_hid_report(self->report_id, self->report_buffer, len) ) {
+ if (!tud_hid_report(self->report_id, self->report_buffer, len)) {
mp_raise_msg(&mp_type_OSError, translate("USB Error"));
}
}
-static usb_hid_device_obj_t* get_hid_device(uint8_t report_id) {
+static usb_hid_device_obj_t *get_hid_device(uint8_t report_id) {
for (uint8_t i = 0; i < USB_HID_NUM_DEVICES; i++) {
if (usb_hid_devices[i].report_id == report_id) {
return &usb_hid_devices[i];
@@ -73,10 +73,12 @@ static usb_hid_device_obj_t* get_hid_device(uint8_t report_id) {
}
// Callbacks invoked when receive Get_Report request through control endpoint
-uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) {
- (void) itf;
+uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen) {
+ (void)itf;
// only support Input Report
- if ( report_type != HID_REPORT_TYPE_INPUT ) return 0;
+ if (report_type != HID_REPORT_TYPE_INPUT) {
+ return 0;
+ }
// fill buffer with current report
memcpy(buffer, get_hid_device(report_id)->report_buffer, reqlen);
@@ -84,8 +86,8 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t
}
// Callbacks invoked when receive Set_Report request through control endpoint
-void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
- (void) itf;
+void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize) {
+ (void)itf;
if (report_type == HID_REPORT_TYPE_INVALID) {
report_id = buffer[0];
buffer++;
@@ -94,7 +96,7 @@ void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t rep
return;
}
- usb_hid_device_obj_t* hid_device = get_hid_device(report_id);
+ usb_hid_device_obj_t *hid_device = get_hid_device(report_id);
if (hid_device && hid_device->out_report_length >= bufsize) {
memcpy(hid_device->out_report_buffer, buffer, bufsize);
diff --git a/shared-module/usb_hid/Device.h b/shared-module/usb_hid/Device.h
index 93c3518b4..bf4e9d9ad 100644
--- a/shared-module/usb_hid/Device.h
+++ b/shared-module/usb_hid/Device.h
@@ -33,17 +33,17 @@
#include "py/obj.h"
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
typedef struct {
mp_obj_base_t base;
- uint8_t* report_buffer;
+ uint8_t *report_buffer;
uint8_t report_id;
uint8_t report_length;
uint8_t usage_page;
uint8_t usage;
- uint8_t* out_report_buffer;
+ uint8_t *out_report_buffer;
uint8_t out_report_length;
} usb_hid_device_obj_t;
@@ -51,7 +51,7 @@ typedef struct {
extern usb_hid_device_obj_t usb_hid_devices[];
#ifdef __cplusplus
- }
+}
#endif
#endif /* SHARED_MODULE_USB_HID_DEVICE_H */