summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-05-04 09:22:11 +0700
committerhathach <[email protected]>2026-05-04 09:22:11 +0700
commit25ddb7ff0cfd361b733dadd3bb5307fdb94b6dc1 (patch)
treebae063011aba6e960c99e77b79f967d8b6155e16
parentea2de8be7e939fdffd73efd75cc2e2051ca495a9 (diff)
minor clean up
-rw-r--r--examples/device/net_lwip_webserver/src/usb_descriptors.c42
-rw-r--r--src/class/net/ecm_rndis_device.c4
-rw-r--r--src/class/net/ncm_device.c2
3 files changed, 30 insertions, 18 deletions
diff --git a/examples/device/net_lwip_webserver/src/usb_descriptors.c b/examples/device/net_lwip_webserver/src/usb_descriptors.c
index 1aa223eb9..a7e48c79b 100644
--- a/examples/device/net_lwip_webserver/src/usb_descriptors.c
+++ b/examples/device/net_lwip_webserver/src/usb_descriptors.c
@@ -221,45 +221,57 @@ static uint8_t const ncm_hs_configuration[] = {
#endif
-// Configuration array: RNDIS and CDC-ECM
+// NCM work with all latest OS i.e macos 10.10+, windows 10+, and Linux.
+// For older system Configuration array of RNDIS and CDC-ECM may be needed for better compatibility.
// - Windows only works with RNDIS
// - MacOS only works with CDC-ECM
// - Linux will work on both
-static const uint8_t *const configuration_fs_arr[CONFIG_ID_COUNT] = {
#if CFG_TUD_ECM_RNDIS
+
+static const uint8_t *const configuration_fs_arr[CONFIG_ID_COUNT] = {
[CONFIG_ID_RNDIS] = rndis_fs_configuration,
[CONFIG_ID_ECM] = ecm_fs_configuration
-#else
- [CONFIG_ID_NCM] = ncm_fs_configuration
-#endif
};
#if TUD_OPT_HIGH_SPEED
static const uint8_t *const configuration_hs_arr[CONFIG_ID_COUNT] = {
-#if CFG_TUD_ECM_RNDIS
[CONFIG_ID_RNDIS] = rndis_hs_configuration,
[CONFIG_ID_ECM] = ecm_hs_configuration
-#else
- [CONFIG_ID_NCM] = ncm_hs_configuration
-#endif
};
// Size array for each configuration
static const uint16_t configuration_sz_arr[CONFIG_ID_COUNT] = {
-#if CFG_TUD_ECM_RNDIS
[CONFIG_ID_RNDIS] = MAIN_CONFIG_TOTAL_LEN,
[CONFIG_ID_ECM] = ALT_CONFIG_TOTAL_LEN
+};
+
+// Scratch buffer for other speed configuration (sized to hold the largest config)
+#define MAX_CONFIG_TOTAL_LEN TU_MAX(MAIN_CONFIG_TOTAL_LEN, ALT_CONFIG_TOTAL_LEN)
+#endif
+
#else
+
+static const uint8_t *const configuration_fs_arr[CONFIG_ID_COUNT] = {
+ [CONFIG_ID_NCM] = ncm_fs_configuration
+};
+
+#if TUD_OPT_HIGH_SPEED
+static const uint8_t *const configuration_hs_arr[CONFIG_ID_COUNT] = {
+ [CONFIG_ID_NCM] = ncm_hs_configuration
+};
+
+// Size array for each configuration
+static const uint16_t configuration_sz_arr[CONFIG_ID_COUNT] = {
[CONFIG_ID_NCM] = NCM_CONFIG_TOTAL_LEN
-#endif
};
// Scratch buffer for other speed configuration (sized to hold the largest config)
-#if CFG_TUD_ECM_RNDIS
- #define MAX_CONFIG_TOTAL_LEN TU_MAX(MAIN_CONFIG_TOTAL_LEN, ALT_CONFIG_TOTAL_LEN)
-#else
- #define MAX_CONFIG_TOTAL_LEN NCM_CONFIG_TOTAL_LEN
+#define MAX_CONFIG_TOTAL_LEN NCM_CONFIG_TOTAL_LEN
#endif
+
+#endif
+
+#if TUD_OPT_HIGH_SPEED
static uint8_t desc_other_speed_config[MAX_CONFIG_TOTAL_LEN];
// device qualifier: device descriptor fields that differ at other speed
diff --git a/src/class/net/ecm_rndis_device.c b/src/class/net/ecm_rndis_device.c
index 52c4f7f87..b27cac3ea 100644
--- a/src/class/net/ecm_rndis_device.c
+++ b/src/class/net/ecm_rndis_device.c
@@ -48,10 +48,10 @@ typedef struct {
uint8_t itf_num; // Index number of Management Interface, +1 for Data Interface
uint8_t itf_data_alt; // Alternate setting of Data Interface. 0 : inactive, 1 : active
- uint8_t ep_notif;
uint8_t ep_in;
uint8_t ep_out;
uint16_t ep_size; // bulk endpoint max packet size (IN and OUT assumed equal)
+ uint8_t ep_notif;
bool ecm_mode;
@@ -361,7 +361,7 @@ bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
/* data transmission finished */
if (ep_addr == _netd_itf.ep_in) {
/* TinyUSB requires the class driver to implement ZLP (since ZLP usage is class-specific) */
- if (xferred_bytes && (0 == (xferred_bytes % _netd_itf.ep_size))) {
+ if (xferred_bytes > 0 && 0 == (xferred_bytes & (_netd_itf.ep_size-1))) {
do_in_xfer(NULL, 0); /* a ZLP is needed */
} else {
/* we're finally finished */
diff --git a/src/class/net/ncm_device.c b/src/class/net/ncm_device.c
index fe33d0247..1327dbaf2 100644
--- a/src/class/net/ncm_device.c
+++ b/src/class/net/ncm_device.c
@@ -342,7 +342,7 @@ static bool xmit_insert_required_zlp(uint8_t rhport, uint32_t xferred_bytes) {
TU_LOG_DRV("xmit_insert_required_zlp(%d,%ld)\n", rhport, xferred_bytes);
uint16_t const ep_size = ncm_interface.ep_size;
- if (xferred_bytes == 0 || xferred_bytes % ep_size != 0) {
+ if (xferred_bytes == 0 || (xferred_bytes & (ep_size-1)) != 0) {
return false;
}