summaryrefslogtreecommitdiff
path: root/examples/device/cdc_msc
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-11-19 11:32:44 +0700
committerhathach <[email protected]>2025-11-19 11:32:44 +0700
commitfd3161087d76c84fb21e8e2f2d30a81d6b11bfba (patch)
tree527172cad87c76062490e4ecc9277e21d3691224 /examples/device/cdc_msc
parentbe4b38c54dc4e23af322ae04eda1f30e5ced0289 (diff)
parentd46f71bdde8b3160b0efaf83598d6b4cf596f787 (diff)
Merge branch 'refs/heads/master' into dwc2_ep0
# Conflicts: # examples/device/dfu/src/usb_descriptors.c # examples/device/dfu_runtime/src/usb_descriptors.c # src/device/usbd_control.c # src/portable/synopsys/dwc2/dcd_dwc2.c
Diffstat (limited to 'examples/device/cdc_msc')
-rw-r--r--examples/device/cdc_msc/src/main.c35
-rw-r--r--examples/device/cdc_msc/src/msc_disk.c28
2 files changed, 29 insertions, 34 deletions
diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c
index c4606528a..e4a205533 100644
--- a/examples/device/cdc_msc/src/main.c
+++ b/examples/device/cdc_msc/src/main.c
@@ -37,12 +37,12 @@
*/
enum {
BLINK_NOT_MOUNTED = 250,
- BLINK_MOUNTED = 1000,
- BLINK_SUSPENDED = 2500,
+ BLINK_MOUNTED = 1000,
+ BLINK_SUSPENDED = 2500,
};
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
-static bool blink_enable = true;
+static bool blink_enable = true;
void led_blinking_task(void);
void cdc_task(void);
@@ -52,10 +52,7 @@ int main(void) {
board_init();
// init device stack on configured roothub port
- tusb_rhport_init_t dev_init = {
- .role = TUSB_ROLE_DEVICE,
- .speed = TUSB_SPEED_AUTO
- };
+ tusb_rhport_init_t dev_init = {.role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO};
tusb_init(BOARD_TUD_RHPORT, &dev_init);
board_init_after_tusb();
@@ -86,7 +83,7 @@ void tud_umount_cb(void) {
// remote_wakeup_en : if host allow us to perform remote wakeup
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
void tud_suspend_cb(bool remote_wakeup_en) {
- (void) remote_wakeup_en;
+ (void)remote_wakeup_en;
blink_interval_ms = BLINK_SUSPENDED;
}
@@ -107,9 +104,9 @@ void cdc_task(void) {
// connected and there are data available
if (tud_cdc_available()) {
// read data
- char buf[64];
+ char buf[64];
uint32_t count = tud_cdc_read(buf, sizeof(buf));
- (void) count;
+ (void)count;
// Echo back
// Note: Skip echo by commenting out write() and write_flush()
@@ -120,10 +117,12 @@ void cdc_task(void) {
}
// Press on-board button to send Uart status notification
+ static cdc_notify_uart_state_t uart_state = {.value = 0};
+
static uint32_t btn_prev = 0;
- static cdc_notify_uart_state_t uart_state = { .value = 0 };
- const uint32_t btn = board_button_read();
- if (!btn_prev && btn) {
+ const uint32_t btn = board_button_read();
+
+ if ((btn_prev == 0u) && (btn != 0u)) {
uart_state.dsr ^= 1;
tud_cdc_notify_uart_state(&uart_state);
}
@@ -133,8 +132,8 @@ void cdc_task(void) {
// Invoked when cdc when line state changed e.g connected/disconnected
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
- (void) itf;
- (void) rts;
+ (void)itf;
+ (void)rts;
if (dtr) {
// Terminal connected
@@ -148,15 +147,15 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
// Invoked when CDC interface received data from host
void tud_cdc_rx_cb(uint8_t itf) {
- (void) itf;
+ (void)itf;
}
//--------------------------------------------------------------------+
// BLINKING TASK
//--------------------------------------------------------------------+
void led_blinking_task(void) {
- static uint32_t start_ms = 0;
- static bool led_state = false;
+ static uint32_t start_ms = 0;
+ static bool led_state = false;
if (blink_enable) {
// Blink every interval ms
diff --git a/examples/device/cdc_msc/src/msc_disk.c b/examples/device/cdc_msc/src/msc_disk.c
index 1a95f7f8b..e091c2985 100644
--- a/examples/device/cdc_msc/src/msc_disk.c
+++ b/examples/device/cdc_msc/src/msc_disk.c
@@ -128,9 +128,9 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t *inquiry_resp, uin
const char pid[] = "Mass Storage";
const char rev[] = "1.0";
- strncpy((char*) inquiry_resp->vendor_id, vid, 8);
- strncpy((char*) inquiry_resp->product_id, pid, 16);
- strncpy((char*) inquiry_resp->product_rev, rev, 4);
+ (void) strncpy((char*) inquiry_resp->vendor_id, vid, 8);
+ (void) strncpy((char*) inquiry_resp->product_id, pid, 16);
+ (void) strncpy((char*) inquiry_resp->product_rev, rev, 4);
return sizeof(scsi_inquiry_resp_t); // 36 bytes
}
@@ -143,8 +143,7 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun) {
// RAM disk is ready until ejected
if (ejected) {
// Additional Sense 3A-00 is NOT_FOUND
- tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x3a, 0x00);
- return false;
+ return tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x3a, 0x00);
}
return true;
@@ -154,7 +153,6 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun) {
// Application update block count and block size
void tud_msc_capacity_cb(uint8_t lun, uint32_t *block_count, uint16_t *block_size) {
(void) lun;
-
*block_count = DISK_BLOCK_NUM;
*block_size = DISK_BLOCK_SIZE;
}
@@ -194,7 +192,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buff
}
uint8_t const *addr = msc_disk[lba] + offset;
- memcpy(buffer, addr, bufsize);
+ (void) memcpy(buffer, addr, bufsize);
return (int32_t) bufsize;
}
@@ -221,7 +219,7 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
#ifndef CFG_EXAMPLE_MSC_READONLY
uint8_t *addr = msc_disk[lba] + offset;
- memcpy(addr, buffer, bufsize);
+ (void) memcpy(addr, buffer, bufsize);
#else
(void) lba;
(void) offset;
@@ -235,19 +233,17 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
// - READ10 and WRITE10 has their own callbacks
int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize) {
+ (void) lun;
+ (void) scsi_cmd;
(void) buffer;
(void) bufsize;
- switch (scsi_cmd[0]) {
- default:
- // Set Sense = Invalid Command Operation
- tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
+ // currently no other commands is supported
- // negative means error -> tinyusb could stall and/or response with failed status
- return -1;
- }
+ // Set Sense = Invalid Command Operation
+ (void) tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
- return -1;
+ return -1; // stall/failed command request;
}
#endif