summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-05-24 12:07:33 +0700
committerGitHub <[email protected]>2021-05-24 12:07:33 +0700
commitca8724ee08375e85c3a8fd15b5088d38c20c1ae8 (patch)
treec3c04937c66317f3aabfa8a84a1ae62b2b713203 /src/class
parent056cd6b2293bf5f7cb49e6f101907023e5f7e720 (diff)
parent4f033321189eb572c870d08281dd06e044c7597e (diff)
Merge pull request #846 from hathach/house-keeping
House keeping
Diffstat (limited to 'src/class')
-rw-r--r--src/class/hid/hid_device.c13
-rw-r--r--src/class/hid/hid_host.c2
-rw-r--r--src/class/msc/msc_host.c5
3 files changed, 10 insertions, 10 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index ab9ef3ad8..0d9cdb22b 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -45,7 +45,7 @@ typedef struct
uint8_t ep_out; // optional Out endpoint
uint8_t itf_protocol; // Boot mouse or keyboard
- bool boot_mode; // default = false (Report)
+ uint8_t protocol_mode; // Boot (0) or Report protocol (1)
uint8_t idle_rate; // up to application to handle idle rate
uint16_t report_desc_len;
@@ -112,7 +112,7 @@ uint8_t tud_hid_n_interface_protocol(uint8_t instance)
uint8_t tud_hid_n_get_protocol(uint8_t instance)
{
- return _hidd_itf[instance].boot_mode ? HID_PROTOCOL_BOOT : HID_PROTOCOL_REPORT;
+ return _hidd_itf[instance].protocol_mode;
}
bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
@@ -213,7 +213,7 @@ uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint1
if ( desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT ) p_hid->itf_protocol = desc_itf->bInterfaceProtocol;
- p_hid->boot_mode = false; // default mode is REPORT
+ p_hid->protocol_mode = HID_PROTOCOL_REPORT; // Per Specs: default is report mode
p_hid->itf_num = desc_itf->bInterfaceNumber;
// Use offsetof to avoid pointer to the odd/misaligned address
@@ -326,8 +326,7 @@ bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
case HID_REQ_CONTROL_GET_PROTOCOL:
if ( stage == CONTROL_STAGE_SETUP )
{
- uint8_t protocol = (p_hid->boot_mode ? HID_PROTOCOL_BOOT : HID_PROTOCOL_REPORT);
- tud_control_xfer(rhport, request, &protocol, 1);
+ tud_control_xfer(rhport, request, &p_hid->protocol_mode, 1);
}
break;
@@ -338,10 +337,10 @@ bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
}
else if ( stage == CONTROL_STAGE_ACK )
{
- p_hid->boot_mode = (request->wValue == HID_PROTOCOL_BOOT);
+ p_hid->protocol_mode = (uint8_t) request->wValue;
if (tud_hid_set_protocol_cb)
{
- tud_hid_set_protocol_cb(hid_itf, (uint8_t) request->wValue);
+ tud_hid_set_protocol_cb(hid_itf, p_hid->protocol_mode);
}
}
break;
diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c
index e3ae5a155..1bc86e4ad 100644
--- a/src/class/hid/hid_host.c
+++ b/src/class/hid/hid_host.c
@@ -241,7 +241,7 @@ void hidh_close(uint8_t dev_addr)
hidh_device_t* hid_dev = get_dev(dev_addr);
if (tuh_hid_umount_cb)
{
- for ( uint8_t inst = 0; inst < hid_dev->inst_count; inst++) tuh_hid_umount_cb(dev_addr, inst);
+ for ( uint8_t inst = 0; inst < hid_dev->inst_count; inst++ ) tuh_hid_umount_cb(dev_addr, inst);
}
tu_memclr(hid_dev, sizeof(hidh_device_t));
diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c
index 08b4db9e1..ca360ca2a 100644
--- a/src/class/msc/msc_host.c
+++ b/src/class/msc/msc_host.c
@@ -297,10 +297,11 @@ void msch_init(void)
void msch_close(uint8_t dev_addr)
{
msch_interface_t* p_msc = get_itf(dev_addr);
- tu_memclr(p_msc, sizeof(msch_interface_t));
// invoke Application Callback
- if (tuh_msc_umount_cb) tuh_msc_umount_cb(dev_addr);
+ if (p_msc->mounted && tuh_msc_umount_cb) tuh_msc_umount_cb(dev_addr);
+
+ tu_memclr(p_msc, sizeof(msch_interface_t));
}
bool msch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)