summaryrefslogtreecommitdiff
path: root/examples/device/cdc_msc/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-10-24 13:04:49 +0700
committerhathach <[email protected]>2025-10-24 13:04:49 +0700
commitf39dcae9f1bed1dfcfb239f76677ef980a9976c9 (patch)
treeba8e49a707d1547663abac80ef3c7c4738463c46 /examples/device/cdc_msc/src
parent878c8f26c5c760ec683a8d4ee4aa1ee6678b8a12 (diff)
fix several warnings
Diffstat (limited to 'examples/device/cdc_msc/src')
-rw-r--r--examples/device/cdc_msc/src/main.c19
-rw-r--r--examples/device/cdc_msc/src/msc_disk.c6
-rw-r--r--examples/device/cdc_msc/src/usb_descriptors.c12
3 files changed, 23 insertions, 14 deletions
diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c
index 4e7aa989e..c4606528a 100644
--- a/examples/device/cdc_msc/src/main.c
+++ b/examples/device/cdc_msc/src/main.c
@@ -42,6 +42,7 @@ enum {
};
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
+static bool blink_enable = true;
void led_blinking_task(void);
void cdc_task(void);
@@ -135,11 +136,13 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
(void) itf;
(void) rts;
- // TODO set some indicator
if (dtr) {
// Terminal connected
+ blink_enable = false;
+ board_led_write(true);
} else {
// Terminal disconnected
+ blink_enable = true;
}
}
@@ -155,10 +158,14 @@ void led_blinking_task(void) {
static uint32_t start_ms = 0;
static bool led_state = false;
- // Blink every interval ms
- if (board_millis() - start_ms < blink_interval_ms) return; // not enough time
- start_ms += blink_interval_ms;
+ if (blink_enable) {
+ // Blink every interval ms
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
+ start_ms += blink_interval_ms;
- board_led_write(led_state);
- led_state = 1 - led_state; // toggle
+ board_led_write(led_state);
+ led_state = !led_state;
+ }
}
diff --git a/examples/device/cdc_msc/src/msc_disk.c b/examples/device/cdc_msc/src/msc_disk.c
index 6c112aa8b..9a43d321e 100644
--- a/examples/device/cdc_msc/src/msc_disk.c
+++ b/examples/device/cdc_msc/src/msc_disk.c
@@ -48,7 +48,7 @@ enum {
#ifdef CFG_EXAMPLE_MSC_READONLY
const
#endif
-uint8_t msc_disk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] = {
+static uint8_t msc_disk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] = {
//------------- Block0: Boot Sector -------------//
// byte_per_sector = DISK_BLOCK_SIZE; fat12_sector_num_16 = DISK_BLOCK_NUM;
// sector_per_cluster = 1; reserved_sectors = 1;
@@ -213,7 +213,9 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
(void) lun;
// out of ramdisk
- if (lba >= DISK_BLOCK_NUM) return -1;
+ if (lba >= DISK_BLOCK_NUM) {
+ return -1;
+ }
#ifndef CFG_EXAMPLE_MSC_READONLY
uint8_t *addr = msc_disk[lba] + offset;
diff --git a/examples/device/cdc_msc/src/usb_descriptors.c b/examples/device/cdc_msc/src/usb_descriptors.c
index 597a6b1e6..4fe03f90e 100644
--- a/examples/device/cdc_msc/src/usb_descriptors.c
+++ b/examples/device/cdc_msc/src/usb_descriptors.c
@@ -42,7 +42,7 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
@@ -125,7 +125,7 @@ enum {
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN)
// full speed configuration
-uint8_t const desc_fs_configuration[] = {
+static uint8_t const desc_fs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -140,7 +140,7 @@ uint8_t const desc_fs_configuration[] = {
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
// high speed configuration
-uint8_t const desc_hs_configuration[] = {
+static uint8_t const desc_hs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -152,10 +152,10 @@ uint8_t const desc_hs_configuration[] = {
};
// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
+static uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier = {
+static tusb_desc_device_qualifier_t const desc_device_qualifier = {
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = USB_BCD,
@@ -223,7 +223,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] = {
+static char const *string_desc_arr[] = {
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product