summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/build_system/cmake/toolchain/common.cmake17
-rw-r--r--examples/device/cdc_uac2/src/common.h3
-rw-r--r--examples/device/cdc_uac2/src/main.c3
-rw-r--r--examples/device/net_lwip_webserver/src/main.c3
-rw-r--r--examples/device/usbtmc/src/main.c1
-rw-r--r--examples/device/usbtmc/src/usbtmc_app.c1
-rw-r--r--examples/device/video_capture_2ch/src/main.c5
-rw-r--r--examples/device/webusb_serial/src/main.c2
-rw-r--r--examples/host/cdc_msc_hid/src/app.h32
-rw-r--r--examples/host/cdc_msc_hid/src/cdc_app.c1
-rw-r--r--examples/host/cdc_msc_hid/src/hid_app.c1
-rw-r--r--examples/host/cdc_msc_hid/src/main.c3
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/app.h33
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/cdc_app.c1
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/hid_app.c3
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/main.c4
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/msc_app.c1
-rw-r--r--examples/host/hid_controller/src/app.h31
-rw-r--r--examples/host/hid_controller/src/hid_app.c1
-rw-r--r--examples/host/hid_controller/src/main.c20
20 files changed, 121 insertions, 45 deletions
diff --git a/examples/build_system/cmake/toolchain/common.cmake b/examples/build_system/cmake/toolchain/common.cmake
index 4c181137b..fa3034e6f 100644
--- a/examples/build_system/cmake/toolchain/common.cmake
+++ b/examples/build_system/cmake/toolchain/common.cmake
@@ -20,11 +20,11 @@ include(${CMAKE_CURRENT_LIST_DIR}/../cpu/${CMAKE_SYSTEM_CPU}.cmake)
# ----------------------------------------------------------------------------
# Compile flags
# ----------------------------------------------------------------------------
-if (TOOLCHAIN STREQUAL "gcc")
+if (TOOLCHAIN STREQUAL "gcc" OR TOOLCHAIN STREQUAL "clang")
list(APPEND TOOLCHAIN_COMMON_FLAGS
-fdata-sections
-ffunction-sections
- -fsingle-precision-constant
+# -fsingle-precision-constant # not supported by clang
-fno-strict-aliasing
)
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
@@ -34,22 +34,9 @@ if (TOOLCHAIN STREQUAL "gcc")
)
elseif (TOOLCHAIN STREQUAL "iar")
- #list(APPEND TOOLCHAIN_COMMON_FLAGS)
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
--diag_suppress=Li065
)
-
-elseif (TOOLCHAIN STREQUAL "clang")
- list(APPEND TOOLCHAIN_COMMON_FLAGS
- -fdata-sections
- -ffunction-sections
- -fno-strict-aliasing
- )
- list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
- -Wl,--print-memory-usage
- -Wl,--gc-sections
- -Wl,--cref
- )
endif ()
# join the toolchain flags into a single string
diff --git a/examples/device/cdc_uac2/src/common.h b/examples/device/cdc_uac2/src/common.h
index f281024c7..ff8b7a953 100644
--- a/examples/device/cdc_uac2/src/common.h
+++ b/examples/device/cdc_uac2/src/common.h
@@ -31,4 +31,7 @@ enum
VOLUME_CTRL_SILENCE = 0x8000,
};
+void led_blinking_task(void);
+void audio_task(void);
+
#endif
diff --git a/examples/device/cdc_uac2/src/main.c b/examples/device/cdc_uac2/src/main.c
index bc87f6e3c..22c462be7 100644
--- a/examples/device/cdc_uac2/src/main.c
+++ b/examples/device/cdc_uac2/src/main.c
@@ -38,9 +38,6 @@ extern uint32_t blink_interval_ms;
#include "pico/stdlib.h"
#endif
-void led_blinking_task(void);
-void audio_task(void);
-
/*------------- MAIN -------------*/
int main(void)
{
diff --git a/examples/device/net_lwip_webserver/src/main.c b/examples/device/net_lwip_webserver/src/main.c
index dd9f213ae..867cf2812 100644
--- a/examples/device/net_lwip_webserver/src/main.c
+++ b/examples/device/net_lwip_webserver/src/main.c
@@ -58,6 +58,7 @@ try changing the first byte of tud_network_mac_address[] below from 0x02 to 0x00
#include "lwip/ethip6.h"
#include "lwip/init.h"
#include "lwip/timeouts.h"
+#include "lwip/sys.h"
#ifdef INCLUDE_IPERF
#include "lwip/apps/lwiperf.h"
@@ -172,7 +173,7 @@ static void init_lwip(void) {
}
/* handle any DNS requests from dns-server */
-bool dns_query_proc(const char *name, ip4_addr_t *addr) {
+static bool dns_query_proc(const char *name, ip4_addr_t *addr) {
if (0 == strcmp(name, "tiny.usb")) {
*addr = ipaddr;
return true;
diff --git a/examples/device/usbtmc/src/main.c b/examples/device/usbtmc/src/main.c
index f78cce91f..5cbbb85ef 100644
--- a/examples/device/usbtmc/src/main.c
+++ b/examples/device/usbtmc/src/main.c
@@ -29,6 +29,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "main.h"
#include "usbtmc_app.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
diff --git a/examples/device/usbtmc/src/usbtmc_app.c b/examples/device/usbtmc/src/usbtmc_app.c
index e738f1008..4c3724ac4 100644
--- a/examples/device/usbtmc/src/usbtmc_app.c
+++ b/examples/device/usbtmc/src/usbtmc_app.c
@@ -28,6 +28,7 @@
#include "tusb.h"
#include "bsp/board_api.h"
#include "main.h"
+#include "usbtmc_app.h"
#if (CFG_TUD_USBTMC_ENABLE_488)
static usbtmc_response_capabilities_488_t const
diff --git a/examples/device/video_capture_2ch/src/main.c b/examples/device/video_capture_2ch/src/main.c
index f56738f67..a63efa82d 100644
--- a/examples/device/video_capture_2ch/src/main.c
+++ b/examples/device/video_capture_2ch/src/main.c
@@ -180,7 +180,7 @@ static void fill_color_bar(uint8_t* buffer, unsigned start_position) {
}
#endif
-size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, void **fb) {
+static size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, void **fb) {
uint32_t idx = ctl_idx + stm_idx;
if (idx == 0) {
@@ -205,8 +205,7 @@ size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, voi
//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
-
-void video_send_frame(uint_fast8_t ctl_idx, uint_fast8_t stm_idx) {
+static void video_send_frame(uint_fast8_t ctl_idx, uint_fast8_t stm_idx) {
static unsigned start_ms[CFG_TUD_VIDEO_STREAMING] = {0, };
static unsigned already_sent = 0;
diff --git a/examples/device/webusb_serial/src/main.c b/examples/device/webusb_serial/src/main.c
index 4a724f45e..0c2acd94e 100644
--- a/examples/device/webusb_serial/src/main.c
+++ b/examples/device/webusb_serial/src/main.c
@@ -107,7 +107,7 @@ int main(void) {
}
// send characters to both CDC and WebUSB
-void echo_all(const uint8_t buf[], uint32_t count) {
+static void echo_all(const uint8_t buf[], uint32_t count) {
// echo to web serial
if (web_serial_connected) {
tud_vendor_write(buf, count);
diff --git a/examples/host/cdc_msc_hid/src/app.h b/examples/host/cdc_msc_hid/src/app.h
new file mode 100644
index 000000000..bf15c7bea
--- /dev/null
+++ b/examples/host/cdc_msc_hid/src/app.h
@@ -0,0 +1,32 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2025 Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+#ifndef TUSB_TINYUSB_EXAMPLES_APP_H
+#define TUSB_TINYUSB_EXAMPLES_APP_H
+
+void cdc_app_task(void);
+void hid_app_task(void);
+
+#endif
diff --git a/examples/host/cdc_msc_hid/src/cdc_app.c b/examples/host/cdc_msc_hid/src/cdc_app.c
index 97f1a96d6..d3daedffc 100644
--- a/examples/host/cdc_msc_hid/src/cdc_app.c
+++ b/examples/host/cdc_msc_hid/src/cdc_app.c
@@ -26,6 +26,7 @@
#include "tusb.h"
#include "bsp/board_api.h"
+#include "app.h"
static size_t get_console_inputs(uint8_t* buf, size_t bufsize) {
size_t count = 0;
diff --git a/examples/host/cdc_msc_hid/src/hid_app.c b/examples/host/cdc_msc_hid/src/hid_app.c
index 6f01d6f45..f6a83aeed 100644
--- a/examples/host/cdc_msc_hid/src/hid_app.c
+++ b/examples/host/cdc_msc_hid/src/hid_app.c
@@ -25,6 +25,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c
index e2dd6e5d2..c309a7cae 100644
--- a/examples/host/cdc_msc_hid/src/main.c
+++ b/examples/host/cdc_msc_hid/src/main.c
@@ -29,13 +29,12 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTOTYPES
//--------------------------------------------------------------------+
void led_blinking_task(void);
-extern void cdc_app_task(void);
-extern void hid_app_task(void);
/*------------- MAIN -------------*/
int main(void) {
diff --git a/examples/host/cdc_msc_hid_freertos/src/app.h b/examples/host/cdc_msc_hid_freertos/src/app.h
new file mode 100644
index 000000000..960f7e8cc
--- /dev/null
+++ b/examples/host/cdc_msc_hid_freertos/src/app.h
@@ -0,0 +1,33 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2025 Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+#ifndef TUSB_TINYUSB_EXAMPLES_APP_H
+#define TUSB_TINYUSB_EXAMPLES_APP_H
+
+void cdc_app_init(void);
+void hid_app_init(void);
+void msc_app_init(void);
+
+#endif
diff --git a/examples/host/cdc_msc_hid_freertos/src/cdc_app.c b/examples/host/cdc_msc_hid_freertos/src/cdc_app.c
index d99760a02..279efe7b7 100644
--- a/examples/host/cdc_msc_hid_freertos/src/cdc_app.c
+++ b/examples/host/cdc_msc_hid_freertos/src/cdc_app.c
@@ -26,6 +26,7 @@
#include "tusb.h"
#include "bsp/board_api.h"
+#include "app.h"
#ifdef ESP_PLATFORM
#define CDC_STACK_SZIE 2048
diff --git a/examples/host/cdc_msc_hid_freertos/src/hid_app.c b/examples/host/cdc_msc_hid_freertos/src/hid_app.c
index 9ea5c1be0..0b4ee2c78 100644
--- a/examples/host/cdc_msc_hid_freertos/src/hid_app.c
+++ b/examples/host/cdc_msc_hid_freertos/src/hid_app.c
@@ -25,6 +25,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
@@ -160,7 +161,7 @@ static void process_kbd_report(hid_keyboard_report_t const *report) {
// Mouse
//--------------------------------------------------------------------+
-void cursor_movement(int8_t x, int8_t y, int8_t wheel) {
+static void cursor_movement(int8_t x, int8_t y, int8_t wheel) {
#if USE_ANSI_ESCAPE
// Move X using ansi escape
if ( x < 0) {
diff --git a/examples/host/cdc_msc_hid_freertos/src/main.c b/examples/host/cdc_msc_hid_freertos/src/main.c
index d498c1b57..5dab2bed0 100644
--- a/examples/host/cdc_msc_hid_freertos/src/main.c
+++ b/examples/host/cdc_msc_hid_freertos/src/main.c
@@ -29,6 +29,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
#ifdef ESP_PLATFORM
#define USBH_STACK_SIZE 4096
@@ -65,9 +66,6 @@ TimerHandle_t blinky_tm;
static void led_blinky_cb(TimerHandle_t xTimer);
static void usb_host_task(void* param);
-extern void cdc_app_init(void);
-extern void hid_app_init(void);
-extern void msc_app_init(void);
/*------------- MAIN -------------*/
int main(void) {
diff --git a/examples/host/cdc_msc_hid_freertos/src/msc_app.c b/examples/host/cdc_msc_hid_freertos/src/msc_app.c
index 6439495a8..a6e3ed4ee 100644
--- a/examples/host/cdc_msc_hid_freertos/src/msc_app.c
+++ b/examples/host/cdc_msc_hid_freertos/src/msc_app.c
@@ -24,6 +24,7 @@
*/
#include "tusb.h"
+#include "app.h"
// define the buffer to be place in USB/DMA memory with correct alignment/cache line size
CFG_TUH_MEM_SECTION static struct {
diff --git a/examples/host/hid_controller/src/app.h b/examples/host/hid_controller/src/app.h
new file mode 100644
index 000000000..1f9015cd2
--- /dev/null
+++ b/examples/host/hid_controller/src/app.h
@@ -0,0 +1,31 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2025 Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+#ifndef TUSB_TINYUSB_EXAMPLES_APP_H
+#define TUSB_TINYUSB_EXAMPLES_APP_H
+
+void hid_app_task(void);
+
+#endif
diff --git a/examples/host/hid_controller/src/hid_app.c b/examples/host/hid_controller/src/hid_app.c
index 1d6ca8b07..f8c3d029b 100644
--- a/examples/host/hid_controller/src/hid_app.c
+++ b/examples/host/hid_controller/src/hid_app.c
@@ -25,6 +25,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
/* From https://www.kernel.org/doc/html/latest/input/gamepad.html
____________________________ __
diff --git a/examples/host/hid_controller/src/main.c b/examples/host/hid_controller/src/main.c
index f3244db95..fa70d7d1a 100644
--- a/examples/host/hid_controller/src/main.c
+++ b/examples/host/hid_controller/src/main.c
@@ -34,18 +34,15 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+
void led_blinking_task(void);
-extern void cdc_task(void);
-extern void hid_app_task(void);
-
/*------------- MAIN -------------*/
-int main(void)
-{
+int main(void) {
board_init();
printf("TinyUSB Host HID Controller Example\r\n");
@@ -60,19 +57,11 @@ int main(void)
board_init_after_tusb();
- while (1)
- {
+ while (1) {
// tinyusb host task
tuh_task();
led_blinking_task();
-
-#if CFG_TUH_CDC
- cdc_task();
-#endif
-
-#if CFG_TUH_HID
hid_app_task();
-#endif
}
}
@@ -83,8 +72,7 @@ int main(void)
//--------------------------------------------------------------------+
// Blinking Task
//--------------------------------------------------------------------+
-void led_blinking_task(void)
-{
+void led_blinking_task(void) {
const uint32_t interval_ms = 1000;
static uint32_t start_ms = 0;