From 2219068371fa514e320ddf1c6059c3f6ed901ae7 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 9 Oct 2020 13:50:55 +0700 Subject: rename hid multiple interface --- examples/device/hid_multiple_interface/Makefile | 12 ++ examples/device/hid_multiple_interface/src/main.c | 208 +++++++++++++++++++++ .../hid_multiple_interface/src/tusb_config.h | 110 +++++++++++ .../hid_multiple_interface/src/usb_descriptors.c | 188 +++++++++++++++++++ 4 files changed, 518 insertions(+) create mode 100644 examples/device/hid_multiple_interface/Makefile create mode 100644 examples/device/hid_multiple_interface/src/main.c create mode 100644 examples/device/hid_multiple_interface/src/tusb_config.h create mode 100644 examples/device/hid_multiple_interface/src/usb_descriptors.c (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/hid_multiple_interface/Makefile b/examples/device/hid_multiple_interface/Makefile new file mode 100644 index 000000000..69b633fea --- /dev/null +++ b/examples/device/hid_multiple_interface/Makefile @@ -0,0 +1,12 @@ +include ../../../tools/top.mk +include ../../make.mk + +INC += \ + src \ + $(TOP)/hw \ + +# Example source +EXAMPLE_SOURCE += $(wildcard src/*.c) +SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) + +include ../../rules.mk diff --git a/examples/device/hid_multiple_interface/src/main.c b/examples/device/hid_multiple_interface/src/main.c new file mode 100644 index 000000000..b1957b9fc --- /dev/null +++ b/examples/device/hid_multiple_interface/src/main.c @@ -0,0 +1,208 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + * + */ + +#include +#include +#include + +#include "bsp/board.h" +#include "tusb.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF PROTYPES +//--------------------------------------------------------------------+ + +/* Blink pattern + * - 250 ms : device not mounted + * - 1000 ms : device mounted + * - 2500 ms : device is suspended + */ +enum { + BLINK_NOT_MOUNTED = 250, + BLINK_MOUNTED = 1000, + BLINK_SUSPENDED = 2500, +}; + +static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED; + +void led_blinking_task(void); +void hid_task(void); + +/*------------- MAIN -------------*/ +int main(void) +{ + board_init(); + tusb_init(); + + while (1) + { + tud_task(); // tinyusb device task + led_blinking_task(); + + hid_task(); + } + + return 0; +} + +//--------------------------------------------------------------------+ +// Device callbacks +//--------------------------------------------------------------------+ + +// Invoked when device is mounted +void tud_mount_cb(void) +{ + blink_interval_ms = BLINK_MOUNTED; +} + +// Invoked when device is unmounted +void tud_umount_cb(void) +{ + blink_interval_ms = BLINK_NOT_MOUNTED; +} + +// Invoked when usb bus is suspended +// 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; + blink_interval_ms = BLINK_SUSPENDED; +} + +// Invoked when usb bus is resumed +void tud_resume_cb(void) +{ + blink_interval_ms = BLINK_MOUNTED; +} + +//--------------------------------------------------------------------+ +// USB HID +//--------------------------------------------------------------------+ + +void hid_task(void) +{ + //Set up interfaces + const uint8_t keyboard_interface = 0; + const uint8_t mouse_interface = 1; + + // Poll every 10ms + const uint32_t interval_ms = 10; + static uint32_t start_ms = 0; + + if ( board_millis() - start_ms < interval_ms) return; // not enough time + start_ms += interval_ms; + + uint32_t const btn = board_button_read(); + + // Remote wakeup + if ( tud_suspended() && btn ) + { + // Wake up host if we are in suspend mode + // and REMOTE_WAKEUP feature is enabled by host + tud_remote_wakeup(); + } + + /*------------- Keyboard -------------*/ + if ( tud_hid_n_ready(keyboard_interface) ) + { + // use to avoid send multiple consecutive zero report for keyboard + static bool has_key = false; + + if ( btn ) + { + uint8_t keycode[6] = { 0 }; + keycode[0] = HID_KEY_A; + + tud_hid_n_keyboard_report(keyboard_interface, 0, 0, keycode); + + has_key = true; + }else + { + // send empty key report if previously has key pressed + if (has_key) tud_hid_n_keyboard_report(keyboard_interface, 0, 0, NULL); + has_key = false; + } + } + + /*------------- Mouse -------------*/ + if ( tud_hid_n_ready(mouse_interface) ) + { + if ( btn ) + { + int8_t const delta = 5; + + // no button, right + down, no scroll pan + tud_hid_n_mouse_report(mouse_interface, 0, 0x00, delta, delta, 0, 0); + + // delay a bit before attempt to send keyboard report + board_delay(10); + } + } +} + + +// Invoked when received GET_REPORT control request +// Application must fill buffer report's content and return its length. +// Return zero will cause the stack to STALL request +uint16_t tud_hid_n_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) +{ + // TODO not Implemented + (void) itf; + (void) report_id; + (void) report_type; + (void) buffer; + (void) reqlen; + + return 0; +} + +// Invoked when received SET_REPORT control request or +// received data on OUT endpoint ( Report ID = 0, Type = 0 ) +void tud_hid_n_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) +{ + // TODO set LED based on CAPLOCK, NUMLOCK etc... + (void) itf; + (void) report_id; + (void) report_type; + (void) buffer; + (void) bufsize; +} + +//--------------------------------------------------------------------+ +// BLINKING TASK +//--------------------------------------------------------------------+ +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; + + board_led_write(led_state); + led_state = 1 - led_state; // toggle +} diff --git a/examples/device/hid_multiple_interface/src/tusb_config.h b/examples/device/hid_multiple_interface/src/tusb_config.h new file mode 100644 index 000000000..412f9b004 --- /dev/null +++ b/examples/device/hid_multiple_interface/src/tusb_config.h @@ -0,0 +1,110 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + * + */ + +#ifndef _TUSB_CONFIG_H_ +#define _TUSB_CONFIG_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +//-------------------------------------------------------------------- +// COMMON CONFIGURATION +//-------------------------------------------------------------------- + +// defined by board.mk +#ifndef CFG_TUSB_MCU + #error CFG_TUSB_MCU must be defined +#endif + +// RHPort number used for device can be defined by board.mk, default to port 0 +#ifndef BOARD_DEVICE_RHPORT_NUM + #define BOARD_DEVICE_RHPORT_NUM 0 +#endif + +// RHPort max operational speed can defined by board.mk +// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed +#ifndef BOARD_DEVICE_RHPORT_SPEED + #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \ + CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56) + #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED + #else + #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED + #endif +#endif + +// Device mode with rhport and speed defined by board.mk +#if BOARD_DEVICE_RHPORT_NUM == 0 + #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED) +#elif BOARD_DEVICE_RHPORT_NUM == 1 + #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED) +#else + #error "Incorrect RHPort configuration" +#endif + +// This example doesn't use an RTOS +#define CFG_TUSB_OS OPT_OS_NONE + +// CFG_TUSB_DEBUG is defined by compiler in DEBUG build +// #define CFG_TUSB_DEBUG 0 + +/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. + * Tinyusb use follows macros to declare transferring memory so that they can be put + * into those specific section. + * e.g + * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) + * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) + */ +#ifndef CFG_TUSB_MEM_SECTION +#define CFG_TUSB_MEM_SECTION +#endif + +#ifndef CFG_TUSB_MEM_ALIGN +#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) +#endif + +//-------------------------------------------------------------------- +// DEVICE CONFIGURATION +//-------------------------------------------------------------------- + +#ifndef CFG_TUD_ENDPOINT0_SIZE +#define CFG_TUD_ENDPOINT0_SIZE 64 +#endif + +//------------- CLASS -------------// +#define CFG_TUD_HID 2 +#define CFG_TUD_CDC 0 +#define CFG_TUD_MSC 0 +#define CFG_TUD_MIDI 0 +#define CFG_TUD_VENDOR 0 + +// HID buffer size Should be sufficient to hold ID (if any) + Data +#define CFG_TUD_HID_EP_BUFSIZE 8 + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_CONFIG_H_ */ diff --git a/examples/device/hid_multiple_interface/src/usb_descriptors.c b/examples/device/hid_multiple_interface/src/usb_descriptors.c new file mode 100644 index 000000000..dd8ef7120 --- /dev/null +++ b/examples/device/hid_multiple_interface/src/usb_descriptors.c @@ -0,0 +1,188 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + * + */ + +#include "tusb.h" + +/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug. + * Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC. + * + * Auto ProductID layout's Bitmap: + * [MSB] HID | MSC | CDC [LSB] + */ +#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) ) +#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \ + _PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) ) + +//--------------------------------------------------------------------+ +// Device Descriptors +//--------------------------------------------------------------------+ +tusb_desc_device_t const desc_device = +{ + .bLength = sizeof(tusb_desc_device_t), + .bDescriptorType = TUSB_DESC_DEVICE, + .bcdUSB = 0x0200, + .bDeviceClass = 0x00, + .bDeviceSubClass = 0x00, + .bDeviceProtocol = 0x00, + .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, + + .idVendor = 0xCafe, + .idProduct = USB_PID, + .bcdDevice = 0x0100, + + .iManufacturer = 0x01, + .iProduct = 0x02, + .iSerialNumber = 0x03, + + .bNumConfigurations = 0x01 +}; + +// Invoked when received GET DEVICE DESCRIPTOR +// Application return pointer to descriptor +uint8_t const * tud_descriptor_device_cb(void) +{ + return (uint8_t const *) &desc_device; +} + +//--------------------------------------------------------------------+ +// HID Report Descriptor +//--------------------------------------------------------------------+ + +uint8_t const desc_hid_report1[] = +{ + TUD_HID_REPORT_DESC_KEYBOARD() +}; + +uint8_t const desc_hid_report2[] = +{ + TUD_HID_REPORT_DESC_MOUSE() +}; + +// Invoked when received GET HID REPORT DESCRIPTOR +// Application return pointer to descriptor +// Descriptor contents must exist long enough for transfer to complete +uint8_t const * tud_hid_n_descriptor_report_cb(uint8_t itf) +{ + if (itf == 0) + { + return desc_hid_report1; + } + else if (itf == 1) + { + return desc_hid_report2; + } + + return NULL; +} + +//--------------------------------------------------------------------+ +// Configuration Descriptor +//--------------------------------------------------------------------+ + +enum +{ + ITF_NUM_HID1, + ITF_NUM_HID2, + ITF_NUM_TOTAL +}; + +#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_HID_DESC_LEN + TUD_HID_DESC_LEN) + +#define EPNUM_HID1 0x81 +#define EPNUM_HID2 0x82 + +uint8_t const desc_configuration[] = +{ + // Config number, interface count, string index, total length, attribute, power in mA + TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), + + // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval + TUD_HID_DESCRIPTOR(ITF_NUM_HID1, 4, HID_PROTOCOL_NONE, sizeof(desc_hid_report1), EPNUM_HID1, CFG_TUD_HID_EP_BUFSIZE, 10), + TUD_HID_DESCRIPTOR(ITF_NUM_HID2, 5, HID_PROTOCOL_NONE, sizeof(desc_hid_report2), EPNUM_HID2, CFG_TUD_HID_EP_BUFSIZE, 10) +}; + +// Invoked when received GET CONFIGURATION DESCRIPTOR +// Application return pointer to descriptor +// Descriptor contents must exist long enough for transfer to complete +uint8_t const * tud_descriptor_configuration_cb(uint8_t index) +{ + (void) index; // for multiple configurations + return desc_configuration; +} + +//--------------------------------------------------------------------+ +// String Descriptors +//--------------------------------------------------------------------+ + +// array of pointer to string descriptors +char const* string_desc_arr [] = +{ + (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409) + "TinyUSB", // 1: Manufacturer + "TinyUSB Device", // 2: Product + "123456", // 3: Serials, should use chip ID + "Keyboard Interface", // 4: Interface 1 String + "Mouse Interface", // 5: Interface 2 String +}; + +static uint16_t _desc_str[32]; + +// Invoked when received GET STRING DESCRIPTOR request +// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete +uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) +{ + (void) langid; + + uint8_t chr_count; + + if ( index == 0) + { + memcpy(&_desc_str[1], string_desc_arr[0], 2); + chr_count = 1; + }else + { + // Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors. + // https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors + + if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL; + + const char* str = string_desc_arr[index]; + + // Cap at max char + chr_count = strlen(str); + if ( chr_count > 31 ) chr_count = 31; + + // Convert ASCII string into UTF-16 + for(uint8_t i=0; i Date: Fri, 9 Oct 2020 13:57:23 +0700 Subject: clean up example --- examples/device/hid_multiple_interface/src/main.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/hid_multiple_interface/src/main.c b/examples/device/hid_multiple_interface/src/main.c index b1957b9fc..3599683c5 100644 --- a/examples/device/hid_multiple_interface/src/main.c +++ b/examples/device/hid_multiple_interface/src/main.c @@ -34,6 +34,12 @@ // MACRO CONSTANT TYPEDEF PROTYPES //--------------------------------------------------------------------+ +// Interface index depends on the order in configuration descriptor +enum { + ITF_KEYBOARD = 0, + ITF_MOUSE = 1 +}; + /* Blink pattern * - 250 ms : device not mounted * - 1000 ms : device mounted @@ -104,10 +110,6 @@ void tud_resume_cb(void) void hid_task(void) { - //Set up interfaces - const uint8_t keyboard_interface = 0; - const uint8_t mouse_interface = 1; - // Poll every 10ms const uint32_t interval_ms = 10; static uint32_t start_ms = 0; @@ -126,7 +128,7 @@ void hid_task(void) } /*------------- Keyboard -------------*/ - if ( tud_hid_n_ready(keyboard_interface) ) + if ( tud_hid_n_ready(ITF_KEYBOARD) ) { // use to avoid send multiple consecutive zero report for keyboard static bool has_key = false; @@ -136,29 +138,26 @@ void hid_task(void) uint8_t keycode[6] = { 0 }; keycode[0] = HID_KEY_A; - tud_hid_n_keyboard_report(keyboard_interface, 0, 0, keycode); + tud_hid_n_keyboard_report(ITF_KEYBOARD, 0, 0, keycode); has_key = true; }else { // send empty key report if previously has key pressed - if (has_key) tud_hid_n_keyboard_report(keyboard_interface, 0, 0, NULL); + if (has_key) tud_hid_n_keyboard_report(ITF_KEYBOARD, 0, 0, NULL); has_key = false; } } /*------------- Mouse -------------*/ - if ( tud_hid_n_ready(mouse_interface) ) + if ( tud_hid_n_ready(ITF_MOUSE) ) { if ( btn ) { int8_t const delta = 5; // no button, right + down, no scroll pan - tud_hid_n_mouse_report(mouse_interface, 0, 0x00, delta, delta, 0, 0); - - // delay a bit before attempt to send keyboard report - board_delay(10); + tud_hid_n_mouse_report(ITF_MOUSE, 0, 0x00, delta, delta, 0, 0); } } } -- cgit v1.3.1 From 13abcb953fcd3d51983e9768619adde776af257e Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 9 Oct 2020 20:24:10 +0700 Subject: rename multiple hid callback --- examples/device/hid_multiple_interface/src/main.c | 4 +-- .../hid_multiple_interface/src/usb_descriptors.c | 2 +- src/class/hid/hid_device.c | 8 +++--- src/class/hid/hid_device.h | 32 ++++++++++++---------- 4 files changed, 24 insertions(+), 22 deletions(-) (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/hid_multiple_interface/src/main.c b/examples/device/hid_multiple_interface/src/main.c index 3599683c5..7cb1d75a7 100644 --- a/examples/device/hid_multiple_interface/src/main.c +++ b/examples/device/hid_multiple_interface/src/main.c @@ -166,7 +166,7 @@ void hid_task(void) // Invoked when received GET_REPORT control request // Application must fill buffer report's content and return its length. // Return zero will cause the stack to STALL request -uint16_t tud_hid_n_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) +uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { // TODO not Implemented (void) itf; @@ -180,7 +180,7 @@ uint16_t tud_hid_n_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type // Invoked when received SET_REPORT control request or // received data on OUT endpoint ( Report ID = 0, Type = 0 ) -void tud_hid_n_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) +void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { // TODO set LED based on CAPLOCK, NUMLOCK etc... (void) itf; diff --git a/examples/device/hid_multiple_interface/src/usb_descriptors.c b/examples/device/hid_multiple_interface/src/usb_descriptors.c index dd8ef7120..0d67d499a 100644 --- a/examples/device/hid_multiple_interface/src/usb_descriptors.c +++ b/examples/device/hid_multiple_interface/src/usb_descriptors.c @@ -83,7 +83,7 @@ uint8_t const desc_hid_report2[] = // Invoked when received GET HID REPORT DESCRIPTOR // Application return pointer to descriptor // Descriptor contents must exist long enough for transfer to complete -uint8_t const * tud_hid_n_descriptor_report_cb(uint8_t itf) +uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf) { if (itf == 0) { diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 45b6aaaca..b1a4bb8de 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -250,7 +250,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request else if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT) { #if CFG_TUD_HID>1 - uint8_t const * desc_report = tud_hid_n_descriptor_report_cb(hid_itf); + uint8_t const * desc_report = tud_hid_descriptor_report_cb(hid_itf); #else uint8_t const * desc_report = tud_hid_descriptor_report_cb(); #endif @@ -273,7 +273,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request uint8_t const report_id = tu_u16_low(request->wValue); #if CFG_TUD_HID>1 - uint16_t xferlen = tud_hid_n_get_report_cb(hid_itf, report_id, (hid_report_type_t) report_type, p_hid->epin_buf, request->wLength); + uint16_t xferlen = tud_hid_get_report_cb(hid_itf, report_id, (hid_report_type_t) report_type, p_hid->epin_buf, request->wLength); #else uint16_t xferlen = tud_hid_get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epin_buf, request->wLength); #endif @@ -347,7 +347,7 @@ bool hidd_control_complete(uint8_t rhport, tusb_control_request_t const * p_requ #if CFG_TUD_HID>1 uint8_t const hid_itf = get_hid_index_by_itfnum((uint8_t)p_request->wIndex); TU_VERIFY(hid_itf<0xFF); - tud_hid_n_set_report_cb(hid_itf, report_id, (hid_report_type_t) report_type, p_hid->epout_buf, p_request->wLength); + tud_hid_set_report_cb(hid_itf, report_id, (hid_report_type_t) report_type, p_hid->epout_buf, p_request->wLength); #else tud_hid_set_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epout_buf, p_request->wLength); #endif @@ -373,7 +373,7 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_ if (ep_addr == p_hid->ep_out) { #if CFG_TUD_HID>1 - tud_hid_n_set_report_cb(itf, 0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes); + tud_hid_set_report_cb(itf, 0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes); #else tud_hid_set_report_cb(0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes); #endif diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 4b8cb17d5..fc060f0ce 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -84,30 +84,20 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8 // Callbacks (Weak is optional) //--------------------------------------------------------------------+ +#if CFG_TUD_HID > 1 + // Invoked when received GET HID REPORT DESCRIPTOR request // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete -#if CFG_TUD_HID>1 -uint8_t const * tud_hid_n_descriptor_report_cb(uint8_t itf); -#else -uint8_t const * tud_hid_descriptor_report_cb(void); -#endif +uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf); // Invoked when received GET_REPORT control request // Application must fill buffer report's content and return its length. // Return zero will cause the stack to STALL request -#if CFG_TUD_HID>1 -uint16_t tud_hid_n_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); -#else -uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); -#endif +uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); // Invoked when received SET_REPORT control request or // received data on OUT endpoint ( Report ID = 0, Type = 0 ) -#if CFG_TUD_HID>1 -void tud_hid_n_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); -#else -void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); -#endif +void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); // Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report ) TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode); @@ -117,6 +107,18 @@ TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode); // - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms). TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate); +#else + +uint8_t const * tud_hid_descriptor_report_cb(void); +uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); +void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); + +TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode); +TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate); + +#endif + + //--------------------------------------------------------------------+ // Inline Functions //--------------------------------------------------------------------+ -- cgit v1.3.1 From 83614418b588464873ccbd3fcaeef3d03917bd0e Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 25 Jan 2021 13:28:23 +0700 Subject: get all device example build with rp2040 (except freeRTOS) --- examples/device/audio_test/CMakeLists.txt | 5 ++ examples/device/board_test/CMakeLists.txt | 5 ++ examples/device/cdc_dual_ports/CMakeLists.txt | 5 ++ examples/device/cdc_msc/CMakeLists.txt | 5 ++ examples/device/dfu_rt/CMakeLists.txt | 5 ++ .../device/dynamic_configuration/CMakeLists.txt | 5 ++ examples/device/hid_composite/CMakeLists.txt | 5 ++ examples/device/hid_generic_inout/CMakeLists.txt | 40 ++++++++++ .../device/hid_generic_inout/src/tusb_config.h | 3 +- .../device/hid_multiple_interface/CMakeLists.txt | 40 ++++++++++ .../hid_multiple_interface/src/tusb_config.h | 3 +- examples/device/midi_test/CMakeLists.txt | 40 ++++++++++ examples/device/midi_test/src/tusb_config.h | 3 +- examples/device/msc_dual_lun/CMakeLists.txt | 41 ++++++++++ examples/device/msc_dual_lun/src/tusb_config.h | 3 +- examples/device/net_lwip_webserver/CMakeLists.txt | 87 ++++++++++++++++++++++ .../device/net_lwip_webserver/src/tusb_config.h | 3 +- examples/device/uac2_headset/CMakeLists.txt | 40 ++++++++++ examples/device/uac2_headset/src/tusb_config.h | 2 + examples/device/usbtmc/CMakeLists.txt | 41 ++++++++++ examples/device/usbtmc/src/tusb_config.h | 3 +- examples/device/webusb_serial/CMakeLists.txt | 40 ++++++++++ examples/device/webusb_serial/src/tusb_config.h | 3 +- examples/host/cdc_msc_hid/src/tusb_config.h | 2 + hw/bsp/rp2040/family.cmake | 1 - 25 files changed, 422 insertions(+), 8 deletions(-) create mode 100644 examples/device/hid_generic_inout/CMakeLists.txt create mode 100644 examples/device/hid_multiple_interface/CMakeLists.txt create mode 100644 examples/device/midi_test/CMakeLists.txt create mode 100644 examples/device/msc_dual_lun/CMakeLists.txt create mode 100644 examples/device/net_lwip_webserver/CMakeLists.txt create mode 100644 examples/device/uac2_headset/CMakeLists.txt create mode 100644 examples/device/usbtmc/CMakeLists.txt create mode 100644 examples/device/webusb_serial/CMakeLists.txt (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt index a1dc14b0a..99ee77bd3 100644 --- a/examples/device/audio_test/CMakeLists.txt +++ b/examples/device/audio_test/CMakeLists.txt @@ -27,6 +27,11 @@ if(FAMILY STREQUAL "rp2040") ${CMAKE_CURRENT_SOURCE_DIR}/src ) + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + target_link_libraries(${PROJECT} pico_stdlib) pico_add_extra_outputs(${PROJECT}) diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index c405c2eae..68577ba73 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -31,6 +31,11 @@ elseif(FAMILY STREQUAL "rp2040") ${CMAKE_CURRENT_SOURCE_DIR}/src ) + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + target_link_libraries(${PROJECT} pico_stdlib) pico_add_extra_outputs(${PROJECT}) diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt index a1dc14b0a..99ee77bd3 100644 --- a/examples/device/cdc_dual_ports/CMakeLists.txt +++ b/examples/device/cdc_dual_ports/CMakeLists.txt @@ -27,6 +27,11 @@ if(FAMILY STREQUAL "rp2040") ${CMAKE_CURRENT_SOURCE_DIR}/src ) + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + target_link_libraries(${PROJECT} pico_stdlib) pico_add_extra_outputs(${PROJECT}) diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index a8be05ad0..7f5d5a998 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -33,6 +33,11 @@ elseif(FAMILY STREQUAL "rp2040") ${CMAKE_CURRENT_SOURCE_DIR}/src ) + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + target_link_libraries(${PROJECT} pico_stdlib) pico_add_extra_outputs(${PROJECT}) diff --git a/examples/device/dfu_rt/CMakeLists.txt b/examples/device/dfu_rt/CMakeLists.txt index a1dc14b0a..99ee77bd3 100644 --- a/examples/device/dfu_rt/CMakeLists.txt +++ b/examples/device/dfu_rt/CMakeLists.txt @@ -27,6 +27,11 @@ if(FAMILY STREQUAL "rp2040") ${CMAKE_CURRENT_SOURCE_DIR}/src ) + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + target_link_libraries(${PROJECT} pico_stdlib) pico_add_extra_outputs(${PROJECT}) diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt index 783371860..f26465729 100644 --- a/examples/device/dynamic_configuration/CMakeLists.txt +++ b/examples/device/dynamic_configuration/CMakeLists.txt @@ -28,6 +28,11 @@ if(FAMILY STREQUAL "rp2040") ${CMAKE_CURRENT_SOURCE_DIR}/src ) + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + target_link_libraries(${PROJECT} pico_stdlib) pico_add_extra_outputs(${PROJECT}) diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt index a1dc14b0a..99ee77bd3 100644 --- a/examples/device/hid_composite/CMakeLists.txt +++ b/examples/device/hid_composite/CMakeLists.txt @@ -27,6 +27,11 @@ if(FAMILY STREQUAL "rp2040") ${CMAKE_CURRENT_SOURCE_DIR}/src ) + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + target_link_libraries(${PROJECT} pico_stdlib) pico_add_extra_outputs(${PROJECT}) diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt new file mode 100644 index 000000000..99ee77bd3 --- /dev/null +++ b/examples/device/hid_generic_inout/CMakeLists.txt @@ -0,0 +1,40 @@ +# use directory name for project id +get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + +# Check for -DFAMILY= +if(FAMILY STREQUAL "rp2040") + cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) + include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) + pico_sdk_init() + add_executable(${PROJECT}) + + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + + # Example source + target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + + # Example include + target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + + target_link_libraries(${PROJECT} pico_stdlib) + pico_add_extra_outputs(${PROJECT}) + +else() + message(FATAL_ERROR "Invalid FAMILY specified") +endif() diff --git a/examples/device/hid_generic_inout/src/tusb_config.h b/examples/device/hid_generic_inout/src/tusb_config.h index 347cb06d6..1b8b91c41 100644 --- a/examples/device/hid_generic_inout/src/tusb_config.h +++ b/examples/device/hid_generic_inout/src/tusb_config.h @@ -64,8 +64,9 @@ #error "Incorrect RHPort configuration" #endif -// This example doesn't use an RTOS +#ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE +#endif // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt new file mode 100644 index 000000000..99ee77bd3 --- /dev/null +++ b/examples/device/hid_multiple_interface/CMakeLists.txt @@ -0,0 +1,40 @@ +# use directory name for project id +get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + +# Check for -DFAMILY= +if(FAMILY STREQUAL "rp2040") + cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) + include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) + pico_sdk_init() + add_executable(${PROJECT}) + + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + + # Example source + target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + + # Example include + target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + + target_link_libraries(${PROJECT} pico_stdlib) + pico_add_extra_outputs(${PROJECT}) + +else() + message(FATAL_ERROR "Invalid FAMILY specified") +endif() diff --git a/examples/device/hid_multiple_interface/src/tusb_config.h b/examples/device/hid_multiple_interface/src/tusb_config.h index 412f9b004..a0aa17a90 100644 --- a/examples/device/hid_multiple_interface/src/tusb_config.h +++ b/examples/device/hid_multiple_interface/src/tusb_config.h @@ -64,8 +64,9 @@ #error "Incorrect RHPort configuration" #endif -// This example doesn't use an RTOS +#ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE +#endif // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt new file mode 100644 index 000000000..99ee77bd3 --- /dev/null +++ b/examples/device/midi_test/CMakeLists.txt @@ -0,0 +1,40 @@ +# use directory name for project id +get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + +# Check for -DFAMILY= +if(FAMILY STREQUAL "rp2040") + cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) + include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) + pico_sdk_init() + add_executable(${PROJECT}) + + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + + # Example source + target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + + # Example include + target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + + target_link_libraries(${PROJECT} pico_stdlib) + pico_add_extra_outputs(${PROJECT}) + +else() + message(FATAL_ERROR "Invalid FAMILY specified") +endif() diff --git a/examples/device/midi_test/src/tusb_config.h b/examples/device/midi_test/src/tusb_config.h index d0c327e27..61b9b6552 100644 --- a/examples/device/midi_test/src/tusb_config.h +++ b/examples/device/midi_test/src/tusb_config.h @@ -64,8 +64,9 @@ #error "Incorrect RHPort configuration" #endif -// This example doesn't use an RTOS +#ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE +#endif // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt new file mode 100644 index 000000000..084565400 --- /dev/null +++ b/examples/device/msc_dual_lun/CMakeLists.txt @@ -0,0 +1,41 @@ +# use directory name for project id +get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + +# Check for -DFAMILY= +if(FAMILY STREQUAL "rp2040") + cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) + include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) + pico_sdk_init() + add_executable(${PROJECT}) + + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + + # Example source + target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + + # Example include + target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + + target_link_libraries(${PROJECT} pico_stdlib) + pico_add_extra_outputs(${PROJECT}) + +else() + message(FATAL_ERROR "Invalid FAMILY specified") +endif() diff --git a/examples/device/msc_dual_lun/src/tusb_config.h b/examples/device/msc_dual_lun/src/tusb_config.h index e153a7967..44da21e54 100644 --- a/examples/device/msc_dual_lun/src/tusb_config.h +++ b/examples/device/msc_dual_lun/src/tusb_config.h @@ -64,8 +64,9 @@ #error "Incorrect RHPort configuration" #endif -// This example doesn't use an RTOS +#ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE +#endif // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt new file mode 100644 index 000000000..695dd7c59 --- /dev/null +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -0,0 +1,87 @@ +# use directory name for project id +get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + +# Check for -DFAMILY= +if(FAMILY STREQUAL "rp2040") + cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) + include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) + pico_sdk_init() + add_executable(${PROJECT}) + + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + + # lwip Stack source + set(SRC_LWIP + ${TOP}/lib/lwip/src/core/altcp.c + ${TOP}/lib/lwip/src/core/altcp_alloc.c + ${TOP}/lib/lwip/src/core/altcp_tcp.c + ${TOP}/lib/lwip/src/core/def.c + ${TOP}/lib/lwip/src/core/dns.c + ${TOP}/lib/lwip/src/core/inet_chksum.c + ${TOP}/lib/lwip/src/core/init.c + ${TOP}/lib/lwip/src/core/ip.c + ${TOP}/lib/lwip/src/core/mem.c + ${TOP}/lib/lwip/src/core/memp.c + ${TOP}/lib/lwip/src/core/netif.c + ${TOP}/lib/lwip/src/core/pbuf.c + ${TOP}/lib/lwip/src/core/raw.c + ${TOP}/lib/lwip/src/core/stats.c + ${TOP}/lib/lwip/src/core/sys.c + ${TOP}/lib/lwip/src/core/tcp.c + ${TOP}/lib/lwip/src/core/tcp_in.c + ${TOP}/lib/lwip/src/core/tcp_out.c + ${TOP}/lib/lwip/src/core/timeouts.c + ${TOP}/lib/lwip/src/core/udp.c + ${TOP}/lib/lwip/src/core/ipv4/autoip.c + ${TOP}/lib/lwip/src/core/ipv4/dhcp.c + ${TOP}/lib/lwip/src/core/ipv4/etharp.c + ${TOP}/lib/lwip/src/core/ipv4/icmp.c + ${TOP}/lib/lwip/src/core/ipv4/igmp.c + ${TOP}/lib/lwip/src/core/ipv4/ip4.c + ${TOP}/lib/lwip/src/core/ipv4/ip4_addr.c + ${TOP}/lib/lwip/src/core/ipv4/ip4_frag.c + ${TOP}/lib/lwip/src/netif/ethernet.c + ${TOP}/lib/lwip/src/netif/slipif.c + ${TOP}/lib/lwip/src/apps/http/httpd.c + ${TOP}/lib/lwip/src/apps/http/fs.c + ${TOP}/lib/networking/dhserver.c + ${TOP}/lib/networking/dnserver.c + ${TOP}/lib/networking/rndis_reports.c + ) + + # Example source + target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ${SRC_LWIP} + ) + + # Example include + target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${TOP}/lib/lwip/src/include + ${TOP}/lib/lwip/src/include/ipv4 + ${TOP}/lib/lwip/src/include/lwip/apps + ${TOP}/lib/networking + ) + + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + PBUF_POOL_SIZE=2 + TCP_WND=2*TCP_MSS + HTTPD_USE_CUSTOM_FSDATA=0 + ) + + target_link_libraries(${PROJECT} pico_stdlib) + pico_add_extra_outputs(${PROJECT}) + +else() + message(FATAL_ERROR "Invalid FAMILY specified") +endif() diff --git a/examples/device/net_lwip_webserver/src/tusb_config.h b/examples/device/net_lwip_webserver/src/tusb_config.h index b6d0e7a86..262d4ebce 100644 --- a/examples/device/net_lwip_webserver/src/tusb_config.h +++ b/examples/device/net_lwip_webserver/src/tusb_config.h @@ -64,8 +64,9 @@ #error "Incorrect RHPort configuration" #endif -// This example doesn't use an RTOS +#ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE +#endif // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt new file mode 100644 index 000000000..99ee77bd3 --- /dev/null +++ b/examples/device/uac2_headset/CMakeLists.txt @@ -0,0 +1,40 @@ +# use directory name for project id +get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + +# Check for -DFAMILY= +if(FAMILY STREQUAL "rp2040") + cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) + include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) + pico_sdk_init() + add_executable(${PROJECT}) + + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + + # Example source + target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + + # Example include + target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + + target_link_libraries(${PROJECT} pico_stdlib) + pico_add_extra_outputs(${PROJECT}) + +else() + message(FATAL_ERROR "Invalid FAMILY specified") +endif() diff --git a/examples/device/uac2_headset/src/tusb_config.h b/examples/device/uac2_headset/src/tusb_config.h index d19feeb86..ebf181671 100644 --- a/examples/device/uac2_headset/src/tusb_config.h +++ b/examples/device/uac2_headset/src/tusb_config.h @@ -46,7 +46,9 @@ extern "C" { #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE #endif +#ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE +#endif #ifndef CFG_TUSB_DEBUG // Can be set during compilation i.e.: make LOG= BOARD= diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt new file mode 100644 index 000000000..03bb04389 --- /dev/null +++ b/examples/device/usbtmc/CMakeLists.txt @@ -0,0 +1,41 @@ +# use directory name for project id +get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + +# Check for -DFAMILY= +if(FAMILY STREQUAL "rp2040") + cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) + include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) + pico_sdk_init() + add_executable(${PROJECT}) + + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + + # Example source + target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usbtmc_app.c + ) + + # Example include + target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + + target_link_libraries(${PROJECT} pico_stdlib) + pico_add_extra_outputs(${PROJECT}) + +else() + message(FATAL_ERROR "Invalid FAMILY specified") +endif() diff --git a/examples/device/usbtmc/src/tusb_config.h b/examples/device/usbtmc/src/tusb_config.h index 603e67453..a192d0dbc 100644 --- a/examples/device/usbtmc/src/tusb_config.h +++ b/examples/device/usbtmc/src/tusb_config.h @@ -46,8 +46,9 @@ #error "Incorrect RHPort configuration" #endif -// This example doesn't use an RTOS +#ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE +#endif // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt new file mode 100644 index 000000000..99ee77bd3 --- /dev/null +++ b/examples/device/webusb_serial/CMakeLists.txt @@ -0,0 +1,40 @@ +# use directory name for project id +get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# TOP is absolute path to root directory of TinyUSB git repo +set(TOP "../../..") +get_filename_component(TOP "${TOP}" REALPATH) + +# Check for -DFAMILY= +if(FAMILY STREQUAL "rp2040") + cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) + include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) + pico_sdk_init() + add_executable(${PROJECT}) + + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + + # Example source + target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + + # Example include + target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + + # Example defines + target_compile_definitions(${PROJECT} PUBLIC + CFG_TUSB_OS=OPT_OS_PICO + ) + + target_link_libraries(${PROJECT} pico_stdlib) + pico_add_extra_outputs(${PROJECT}) + +else() + message(FATAL_ERROR "Invalid FAMILY specified") +endif() diff --git a/examples/device/webusb_serial/src/tusb_config.h b/examples/device/webusb_serial/src/tusb_config.h index 48c9ddad6..26b81b389 100644 --- a/examples/device/webusb_serial/src/tusb_config.h +++ b/examples/device/webusb_serial/src/tusb_config.h @@ -64,8 +64,9 @@ #error "Incorrect RHPort configuration" #endif -// This example doesn't use an RTOS +#ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE +#endif // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index d8cf993be..fabc7765c 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -45,7 +45,9 @@ #define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST #endif +#ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE +#endif // CFG_TUSB_DEBUG is defined by compiler in DEBUG build // #define CFG_TUSB_DEBUG 0 diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index dd0123ded..edd57a39b 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -30,5 +30,4 @@ target_include_directories(${PROJECT} PUBLIC target_compile_definitions(${PROJECT} PUBLIC CFG_TUSB_MCU=OPT_MCU_RP2040 - CFG_TUSB_OS=OPT_OS_PICO ) -- cgit v1.3.1 From 4a0f5cbd6332a9ae76dc2eea293024fab2c81885 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 26 Jan 2021 12:46:24 +0700 Subject: change output filename to BOARD-Directory --- examples/device/audio_test/CMakeLists.txt | 3 ++- examples/device/board_test/CMakeLists.txt | 1 + examples/device/cdc_dual_ports/CMakeLists.txt | 1 + examples/device/cdc_msc/CMakeLists.txt | 1 + examples/device/cdc_msc_freertos/CMakeLists.txt | 14 ++++++------- examples/device/dfu_rt/CMakeLists.txt | 1 + .../device/dynamic_configuration/CMakeLists.txt | 1 + examples/device/hid_composite/CMakeLists.txt | 1 + .../device/hid_composite_freertos/CMakeLists.txt | 14 ++++++------- examples/device/hid_generic_inout/CMakeLists.txt | 1 + .../device/hid_multiple_interface/CMakeLists.txt | 1 + examples/device/midi_test/CMakeLists.txt | 1 + examples/device/msc_dual_lun/CMakeLists.txt | 1 + examples/device/net_lwip_webserver/CMakeLists.txt | 1 + examples/device/uac2_headset/CMakeLists.txt | 1 + examples/device/usbtmc/CMakeLists.txt | 1 + examples/device/webusb_serial/CMakeLists.txt | 1 + examples/make.mk | 1 + examples/rules.mk | 23 ++++++++++++---------- hw/bsp/da14695_dk_usb/board.mk | 4 ++-- hw/bsp/da1469x_dk_pro/board.mk | 4 ++-- hw/bsp/double_m33_express/board.mk | 2 +- hw/bsp/fomu/board.mk | 4 ++-- hw/bsp/imxrt/boards/teensy_40/board.mk | 2 +- hw/bsp/lpcxpresso11u37/board.mk | 2 +- hw/bsp/lpcxpresso11u68/board.mk | 2 +- hw/bsp/lpcxpresso51u68/board.mk | 2 +- hw/bsp/lpcxpresso54114/board.mk | 2 +- hw/bsp/lpcxpresso55s69/board.mk | 2 +- hw/bsp/mbed1768/board.mk | 2 +- hw/bsp/msp_exp430f5529lp/board.mk | 4 ++-- hw/bsp/nrf/boards/adafruit_clue/board.mk | 4 ++-- hw/bsp/nrf/boards/arduino_nano33_ble/board.mk | 2 +- .../boards/circuitplayground_bluefruit/board.mk | 4 ++-- .../nrf/boards/feather_nrf52840_express/board.mk | 4 ++-- hw/bsp/nrf/boards/feather_nrf52840_sense/board.mk | 4 ++-- hw/bsp/nrf/boards/itsybitsy_nrf52840/board.mk | 4 ++-- hw/bsp/nrf/boards/nrf52840_mdk_dongle/board.mk | 4 ++-- hw/bsp/nrf/boards/pca10059/board.mk | 4 ++-- hw/bsp/nutiny_nuc121s/board.mk | 2 +- hw/bsp/nutiny_nuc125s/board.mk | 2 +- hw/bsp/nutiny_nuc126v/board.mk | 2 +- hw/bsp/nutiny_sdk_nuc120/board.mk | 2 +- hw/bsp/nutiny_sdk_nuc505/board.mk | 2 +- hw/bsp/samd11_xplained/board.mk | 2 +- hw/bsp/samd21/boards/luna/board.mk | 2 +- hw/bsp/samd21/family.mk | 2 +- hw/bsp/samd51/family.mk | 2 +- hw/bsp/same70_xplained/board.mk | 2 +- hw/bsp/samg55xplained/board.mk | 2 +- hw/bsp/spresense/board.mk | 8 ++++---- hw/bsp/stm32f103bluepill/board.mk | 2 +- hw/bsp/stm32f4/boards/feather_stm32f405/board.mk | 2 +- hw/bsp/stm32f4/boards/stm32f401blackpill/board.mk | 2 +- hw/bsp/stm32f4/boards/stm32f411blackpill/board.mk | 2 +- hw/bsp/stm32l0538disco/board.mk | 2 +- hw/bsp/stm32l476disco/board.mk | 2 +- 57 files changed, 96 insertions(+), 77 deletions(-) (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt index 99ee77bd3..645d57157 100644 --- a/examples/device/audio_test/CMakeLists.txt +++ b/examples/device/audio_test/CMakeLists.txt @@ -1,5 +1,6 @@ -# use directory name for project id +# use BOARD-Directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index 68577ba73..573f026f3 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt index 99ee77bd3..c358eddab 100644 --- a/examples/device/cdc_dual_ports/CMakeLists.txt +++ b/examples/device/cdc_dual_ports/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index 7f5d5a998..5f4d9ba4e 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/cdc_msc_freertos/CMakeLists.txt b/examples/device/cdc_msc_freertos/CMakeLists.txt index 2e55d8c47..dabb4bc80 100644 --- a/examples/device/cdc_msc_freertos/CMakeLists.txt +++ b/examples/device/cdc_msc_freertos/CMakeLists.txt @@ -1,18 +1,18 @@ cmake_minimum_required(VERSION 3.5) -# use directory name for project id +# use BOARD-Directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= -if(NOT DEFINED FAMILY) +if(FAMILY STREQUAL "esp32s2") + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + project(${PROJECT}) + +else() message(FATAL_ERROR "Invalid FAMILY specified") endif() - -include(${TOP}/hw/bsp/${FAMILY}/family.cmake) -project(${PROJECT}) - -project(cdc_msc_freertos) diff --git a/examples/device/dfu_rt/CMakeLists.txt b/examples/device/dfu_rt/CMakeLists.txt index 99ee77bd3..c358eddab 100644 --- a/examples/device/dfu_rt/CMakeLists.txt +++ b/examples/device/dfu_rt/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt index f26465729..a759e56e8 100644 --- a/examples/device/dynamic_configuration/CMakeLists.txt +++ b/examples/device/dynamic_configuration/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt index 99ee77bd3..c358eddab 100644 --- a/examples/device/hid_composite/CMakeLists.txt +++ b/examples/device/hid_composite/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/hid_composite_freertos/CMakeLists.txt b/examples/device/hid_composite_freertos/CMakeLists.txt index c4777f122..dabb4bc80 100644 --- a/examples/device/hid_composite_freertos/CMakeLists.txt +++ b/examples/device/hid_composite_freertos/CMakeLists.txt @@ -1,18 +1,18 @@ cmake_minimum_required(VERSION 3.5) -# use directory name for project id +# use BOARD-Directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= -if(NOT DEFINED FAMILY) +if(FAMILY STREQUAL "esp32s2") + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + project(${PROJECT}) + +else() message(FATAL_ERROR "Invalid FAMILY specified") endif() - -include(${TOP}/hw/bsp/${FAMILY}/family.cmake) -project(${PROJECT}) - -project(hid_composite_freertos) diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt index 99ee77bd3..c358eddab 100644 --- a/examples/device/hid_generic_inout/CMakeLists.txt +++ b/examples/device/hid_generic_inout/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt index 99ee77bd3..c358eddab 100644 --- a/examples/device/hid_multiple_interface/CMakeLists.txt +++ b/examples/device/hid_multiple_interface/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt index 99ee77bd3..c358eddab 100644 --- a/examples/device/midi_test/CMakeLists.txt +++ b/examples/device/midi_test/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt index 084565400..f0e050f9c 100644 --- a/examples/device/msc_dual_lun/CMakeLists.txt +++ b/examples/device/msc_dual_lun/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index 695dd7c59..ec4996086 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt index 99ee77bd3..c358eddab 100644 --- a/examples/device/uac2_headset/CMakeLists.txt +++ b/examples/device/uac2_headset/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt index 03bb04389..686e8dc2d 100644 --- a/examples/device/usbtmc/CMakeLists.txt +++ b/examples/device/usbtmc/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt index 99ee77bd3..c358eddab 100644 --- a/examples/device/webusb_serial/CMakeLists.txt +++ b/examples/device/webusb_serial/CMakeLists.txt @@ -1,5 +1,6 @@ # use directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) +set(PROJECT ${BOARD}-${PROJECT}) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") diff --git a/examples/make.mk b/examples/make.mk index 556b0c41a..329efa774 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -4,6 +4,7 @@ # Build directory BUILD = _build/$(BOARD) +PROJECT = $(BOARD)-$(notdir $(CURDIR)) # Handy check parameter function check_defined = \ diff --git a/examples/rules.mk b/examples/rules.mk index ab0373bac..12ec35043 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -43,6 +43,9 @@ all: clean: $(RM) -rf $(BUILD) +#copy-artifact: +# @$(CP) + else # GNU Make build system @@ -100,9 +103,9 @@ endif # Set all as default goal .DEFAULT_GOAL := all -all: $(BUILD)/$(BOARD)-firmware.bin $(BUILD)/$(BOARD)-firmware.hex size +all: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex size -uf2: $(BUILD)/$(BOARD)-firmware.uf2 +uf2: $(BUILD)/$(PROJECT).uf2 OBJ_DIRS = $(sort $(dir $(OBJ))) $(OBJ): | $(OBJ_DIRS) @@ -113,20 +116,20 @@ else @$(MKDIR) -p $@ endif -$(BUILD)/$(BOARD)-firmware.elf: $(OBJ) +$(BUILD)/$(PROJECT).elf: $(OBJ) @echo LINK $@ @$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group -$(BUILD)/$(BOARD)-firmware.bin: $(BUILD)/$(BOARD)-firmware.elf +$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf @echo CREATE $@ @$(OBJCOPY) -O binary $^ $@ -$(BUILD)/$(BOARD)-firmware.hex: $(BUILD)/$(BOARD)-firmware.elf +$(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf @echo CREATE $@ @$(OBJCOPY) -O ihex $^ $@ UF2_FAMILY ?= 0x00 -$(BUILD)/$(BOARD)-firmware.uf2: $(BUILD)/$(BOARD)-firmware.hex +$(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).hex @echo CREATE $@ $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY) -c -o $@ $^ @@ -150,7 +153,7 @@ $(BUILD)/obj/%.o: %.S @echo AS $(notdir $@) @$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $< -size: $(BUILD)/$(BOARD)-firmware.elf +size: $(BUILD)/$(PROJECT).elf -@echo '' @$(SIZE) $< -@echo '' @@ -178,7 +181,7 @@ endif JLINK_IF ?= swd # Flash using jlink -flash-jlink: $(BUILD)/$(BOARD)-firmware.hex +flash-jlink: $(BUILD)/$(PROJECT).hex @echo halt > $(BUILD)/$(BOARD).jlink @echo r > $(BUILD)/$(BOARD).jlink @echo loadfile $^ >> $(BUILD)/$(BOARD).jlink @@ -188,11 +191,11 @@ flash-jlink: $(BUILD)/$(BOARD)-firmware.hex $(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink # flash STM32 MCU using stlink with STM32 Cube Programmer CLI -flash-stlink: $(BUILD)/$(BOARD)-firmware.elf +flash-stlink: $(BUILD)/$(PROJECT).elf STM32_Programmer_CLI --connect port=swd --write $< --go # flash with pyocd -flash-pyocd: $(BUILD)/$(BOARD)-firmware.hex +flash-pyocd: $(BUILD)/$(PROJECT).hex pyocd flash -t $(PYOCD_TARGET) $< pyocd reset -t $(PYOCD_TARGET) diff --git a/hw/bsp/da14695_dk_usb/board.mk b/hw/bsp/da14695_dk_usb/board.mk index b097262dc..2e76012d2 100644 --- a/hw/bsp/da14695_dk_usb/board.mk +++ b/hw/bsp/da14695_dk_usb/board.mk @@ -42,10 +42,10 @@ JLINK_DEVICE = DA14695 # flash using jlink but with some twists flash: flash-dialog -flash-dialog: $(BUILD)/$(BOARD)-firmware.bin +flash-dialog: $(BUILD)/$(PROJECT).bin @echo '#define SW_VERSION "v_1.0.0.1"' >$(BUILD)/version.h @echo '#define SW_VERSION_DATE "'`date +"%Y-%m-%d %H:%M"`'"' >>$(BUILD)/version.h - mkimage da1469x $(BUILD)/$(BOARD)-firmware.bin $(BUILD)/version.h $^.img + mkimage da1469x $(BUILD)/$(PROJECT).bin $(BUILD)/version.h $^.img cp $(TOP)/hw/bsp/$(BOARD)/product_header.dump $(BUILD)/$(BOARD)-image.bin cat $^.img >> $(BUILD)/$(BOARD)-image.bin @echo r > $(BUILD)/$(BOARD).jlink diff --git a/hw/bsp/da1469x_dk_pro/board.mk b/hw/bsp/da1469x_dk_pro/board.mk index 16bd6de6b..52064e63c 100644 --- a/hw/bsp/da1469x_dk_pro/board.mk +++ b/hw/bsp/da1469x_dk_pro/board.mk @@ -42,10 +42,10 @@ JLINK_DEVICE = DA14699 # flash using jlink but with some twists flash: flash-dialog -flash-dialog: $(BUILD)/$(BOARD)-firmware.bin +flash-dialog: $(BUILD)/$(PROJECT).bin @echo '#define SW_VERSION "v_1.0.0.1"' >$(BUILD)/version.h @echo '#define SW_VERSION_DATE "'`date +"%Y-%m-%d %H:%M"`'"' >>$(BUILD)/version.h - mkimage da1469x $(BUILD)/$(BOARD)-firmware.bin $(BUILD)/version.h $^.img + mkimage da1469x $(BUILD)/$(PROJECT).bin $(BUILD)/version.h $^.img cp $(TOP)/hw/bsp/$(BOARD)/product_header.dump $(BUILD)/$(BOARD)-image.bin cat $^.img >> $(BUILD)/$(BOARD)-image.bin @echo r > $(BUILD)/$(BOARD).jlink diff --git a/hw/bsp/double_m33_express/board.mk b/hw/bsp/double_m33_express/board.mk index c3401e5b2..5757aa5cd 100644 --- a/hw/bsp/double_m33_express/board.mk +++ b/hw/bsp/double_m33_express/board.mk @@ -51,5 +51,5 @@ FREERTOS_PORT = ARM_CM33_NTZ/non_secure JLINK_DEVICE = LPC55S69 # flash using pyocd -flash: $(BUILD)/$(BOARD)-firmware.hex +flash: $(BUILD)/$(PROJECT).hex pyocd flash -t LPC55S69 $< diff --git a/hw/bsp/fomu/board.mk b/hw/bsp/fomu/board.mk index 70fb66975..f31dfec2a 100644 --- a/hw/bsp/fomu/board.mk +++ b/hw/bsp/fomu/board.mk @@ -27,9 +27,9 @@ CHIP_FAMILY = eptri FREERTOS_PORT = RISC-V # flash using dfu-util -$(BUILD)/$(BOARD)-firmware.dfu: $(BUILD)/$(BOARD)-firmware.bin +$(BUILD)/$(PROJECT).dfu: $(BUILD)/$(PROJECT).bin @echo "Create $@" python $(TOP)/hw/bsp/$(BOARD)/dfu.py -b $^ -D 0x1209:0x5bf0 $@ -flash: $(BUILD)/$(BOARD)-firmware.dfu +flash: $(BUILD)/$(PROJECT).dfu dfu-util -D $^ diff --git a/hw/bsp/imxrt/boards/teensy_40/board.mk b/hw/bsp/imxrt/boards/teensy_40/board.mk index 02f77193f..0ad5ea5c0 100644 --- a/hw/bsp/imxrt/boards/teensy_40/board.mk +++ b/hw/bsp/imxrt/boards/teensy_40/board.mk @@ -6,5 +6,5 @@ JLINK_DEVICE = MIMXRT1062xxx6A # flash by using teensy_loader_cli https://github.com/PaulStoffregen/teensy_loader_cli # Make sure it is in your PATH -flash: $(BUILD)/$(BOARD)-firmware.hex +flash: $(BUILD)/$(PROJECT).hex teensy_loader_cli --mcu=imxrt1062 -v -w $< diff --git a/hw/bsp/lpcxpresso11u37/board.mk b/hw/bsp/lpcxpresso11u37/board.mk index d34125ac7..441e5215d 100644 --- a/hw/bsp/lpcxpresso11u37/board.mk +++ b/hw/bsp/lpcxpresso11u37/board.mk @@ -42,5 +42,5 @@ FREERTOS_PORT = ARM_CM0 JLINK_DEVICE = LPC11U37/401 # flash using pyocd -flash: $(BUILD)/$(BOARD)-firmware.hex +flash: $(BUILD)/$(PROJECT).hex pyocd flash -t lpc11u37 $< diff --git a/hw/bsp/lpcxpresso11u68/board.mk b/hw/bsp/lpcxpresso11u68/board.mk index 67124ab90..53d809cfc 100644 --- a/hw/bsp/lpcxpresso11u68/board.mk +++ b/hw/bsp/lpcxpresso11u68/board.mk @@ -39,5 +39,5 @@ FREERTOS_PORT = ARM_CM0 JLINK_DEVICE = LPC11U68 # flash using pyocd -flash: $(BUILD)/$(BOARD)-firmware.hex +flash: $(BUILD)/$(PROJECT).hex pyocd flash -t lpc11u68 $< diff --git a/hw/bsp/lpcxpresso51u68/board.mk b/hw/bsp/lpcxpresso51u68/board.mk index cb36b3409..e5ff8242d 100644 --- a/hw/bsp/lpcxpresso51u68/board.mk +++ b/hw/bsp/lpcxpresso51u68/board.mk @@ -43,5 +43,5 @@ FREERTOS_PORT = ARM_CM0 JLINK_DEVICE = LPC51U68 # flash using pyocd (51u68 is not supported yet) -flash: $(BUILD)/$(BOARD)-firmware.hex +flash: $(BUILD)/$(PROJECT).hex pyocd flash -t LPC51U68 $< diff --git a/hw/bsp/lpcxpresso54114/board.mk b/hw/bsp/lpcxpresso54114/board.mk index cc0f6cd43..88f2bc734 100644 --- a/hw/bsp/lpcxpresso54114/board.mk +++ b/hw/bsp/lpcxpresso54114/board.mk @@ -45,5 +45,5 @@ FREERTOS_PORT = ARM_CM4F JLINK_DEVICE = LPC54114J256_M4 # flash using pyocd -flash: $(BUILD)/$(BOARD)-firmware.hex +flash: $(BUILD)/$(PROJECT).hex pyocd flash -t LPC54114 $< diff --git a/hw/bsp/lpcxpresso55s69/board.mk b/hw/bsp/lpcxpresso55s69/board.mk index f98144cc5..646ca2833 100644 --- a/hw/bsp/lpcxpresso55s69/board.mk +++ b/hw/bsp/lpcxpresso55s69/board.mk @@ -45,5 +45,5 @@ FREERTOS_PORT = ARM_CM33_NTZ/non_secure JLINK_DEVICE = LPC55S69 # flash using pyocd -flash: $(BUILD)/$(BOARD)-firmware.hex +flash: $(BUILD)/$(PROJECT).hex pyocd flash -t LPC55S69 $< diff --git a/hw/bsp/mbed1768/board.mk b/hw/bsp/mbed1768/board.mk index 54a8357cc..1b09a7f7a 100644 --- a/hw/bsp/mbed1768/board.mk +++ b/hw/bsp/mbed1768/board.mk @@ -41,6 +41,6 @@ FREERTOS_PORT = ARM_CM3 JLINK_DEVICE = LPC1768 # flash using pyocd -flash: $(BUILD)/$(BOARD)-firmware.hex +flash: $(BUILD)/$(PROJECT).hex pyocd flash -t lpc1768 $< diff --git a/hw/bsp/msp_exp430f5529lp/board.mk b/hw/bsp/msp_exp430f5529lp/board.mk index 8e857eb66..9fe8da274 100644 --- a/hw/bsp/msp_exp430f5529lp/board.mk +++ b/hw/bsp/msp_exp430f5529lp/board.mk @@ -28,9 +28,9 @@ endif # flash target using TI MSP430-Flasher # http://www.ti.com/tool/MSP430-FLASHER # Please add its installation dir to PATH -flash: $(BUILD)/$(BOARD)-firmware.hex +flash: $(BUILD)/$(PROJECT).hex MSP430Flasher -w $< -z [VCC] # flash target using mspdebug. -flash-mspdebug: $(BUILD)/$(BOARD)-firmware.elf +flash-mspdebug: $(BUILD)/$(PROJECT).elf $(MSPDEBUG) tilib "prog $<" --allow-fw-update diff --git a/hw/bsp/nrf/boards/adafruit_clue/board.mk b/hw/bsp/nrf/boards/adafruit_clue/board.mk index d8530dc74..f31899eb7 100644 --- a/hw/bsp/nrf/boards/adafruit_clue/board.mk +++ b/hw/bsp/nrf/boards/adafruit_clue/board.mk @@ -1,10 +1,10 @@ MCU_VARIANT = nrf52840 CFLAGS += -DNRF52840_XXAA -$(BUILD)/$(BOARD)-firmware.zip: $(BUILD)/$(BOARD)-firmware.hex +$(BUILD)/$(PROJECT).zip: $(BUILD)/$(PROJECT).hex adafruit-nrfutil dfu genpkg --dev-type 0x0052 --sd-req 0xFFFE --application $^ $@ # flash using adafruit-nrfutil dfu -flash: $(BUILD)/$(BOARD)-firmware.zip +flash: $(BUILD)/$(PROJECT).zip @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) adafruit-nrfutil --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank --touch 1200 diff --git a/hw/bsp/nrf/boards/arduino_nano33_ble/board.mk b/hw/bsp/nrf/boards/arduino_nano33_ble/board.mk index 7d8e9bce1..94babd821 100644 --- a/hw/bsp/nrf/boards/arduino_nano33_ble/board.mk +++ b/hw/bsp/nrf/boards/arduino_nano33_ble/board.mk @@ -8,6 +8,6 @@ LD_FILE = $(BOARD_PATH)/$(BOARD).ld # Add it to your PATH or change BOSSAC variable to match your installation BOSSAC = bossac -flash: $(BUILD)/$(BOARD)-firmware.bin +flash: $(BUILD)/$(PROJECT).bin @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) $(BOSSAC) --port=$(SERIAL) -U -i -e -w $^ -R diff --git a/hw/bsp/nrf/boards/circuitplayground_bluefruit/board.mk b/hw/bsp/nrf/boards/circuitplayground_bluefruit/board.mk index d8530dc74..f31899eb7 100644 --- a/hw/bsp/nrf/boards/circuitplayground_bluefruit/board.mk +++ b/hw/bsp/nrf/boards/circuitplayground_bluefruit/board.mk @@ -1,10 +1,10 @@ MCU_VARIANT = nrf52840 CFLAGS += -DNRF52840_XXAA -$(BUILD)/$(BOARD)-firmware.zip: $(BUILD)/$(BOARD)-firmware.hex +$(BUILD)/$(PROJECT).zip: $(BUILD)/$(PROJECT).hex adafruit-nrfutil dfu genpkg --dev-type 0x0052 --sd-req 0xFFFE --application $^ $@ # flash using adafruit-nrfutil dfu -flash: $(BUILD)/$(BOARD)-firmware.zip +flash: $(BUILD)/$(PROJECT).zip @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) adafruit-nrfutil --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank --touch 1200 diff --git a/hw/bsp/nrf/boards/feather_nrf52840_express/board.mk b/hw/bsp/nrf/boards/feather_nrf52840_express/board.mk index d8530dc74..f31899eb7 100644 --- a/hw/bsp/nrf/boards/feather_nrf52840_express/board.mk +++ b/hw/bsp/nrf/boards/feather_nrf52840_express/board.mk @@ -1,10 +1,10 @@ MCU_VARIANT = nrf52840 CFLAGS += -DNRF52840_XXAA -$(BUILD)/$(BOARD)-firmware.zip: $(BUILD)/$(BOARD)-firmware.hex +$(BUILD)/$(PROJECT).zip: $(BUILD)/$(PROJECT).hex adafruit-nrfutil dfu genpkg --dev-type 0x0052 --sd-req 0xFFFE --application $^ $@ # flash using adafruit-nrfutil dfu -flash: $(BUILD)/$(BOARD)-firmware.zip +flash: $(BUILD)/$(PROJECT).zip @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) adafruit-nrfutil --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank --touch 1200 diff --git a/hw/bsp/nrf/boards/feather_nrf52840_sense/board.mk b/hw/bsp/nrf/boards/feather_nrf52840_sense/board.mk index d8530dc74..f31899eb7 100644 --- a/hw/bsp/nrf/boards/feather_nrf52840_sense/board.mk +++ b/hw/bsp/nrf/boards/feather_nrf52840_sense/board.mk @@ -1,10 +1,10 @@ MCU_VARIANT = nrf52840 CFLAGS += -DNRF52840_XXAA -$(BUILD)/$(BOARD)-firmware.zip: $(BUILD)/$(BOARD)-firmware.hex +$(BUILD)/$(PROJECT).zip: $(BUILD)/$(PROJECT).hex adafruit-nrfutil dfu genpkg --dev-type 0x0052 --sd-req 0xFFFE --application $^ $@ # flash using adafruit-nrfutil dfu -flash: $(BUILD)/$(BOARD)-firmware.zip +flash: $(BUILD)/$(PROJECT).zip @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) adafruit-nrfutil --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank --touch 1200 diff --git a/hw/bsp/nrf/boards/itsybitsy_nrf52840/board.mk b/hw/bsp/nrf/boards/itsybitsy_nrf52840/board.mk index d8530dc74..f31899eb7 100644 --- a/hw/bsp/nrf/boards/itsybitsy_nrf52840/board.mk +++ b/hw/bsp/nrf/boards/itsybitsy_nrf52840/board.mk @@ -1,10 +1,10 @@ MCU_VARIANT = nrf52840 CFLAGS += -DNRF52840_XXAA -$(BUILD)/$(BOARD)-firmware.zip: $(BUILD)/$(BOARD)-firmware.hex +$(BUILD)/$(PROJECT).zip: $(BUILD)/$(PROJECT).hex adafruit-nrfutil dfu genpkg --dev-type 0x0052 --sd-req 0xFFFE --application $^ $@ # flash using adafruit-nrfutil dfu -flash: $(BUILD)/$(BOARD)-firmware.zip +flash: $(BUILD)/$(PROJECT).zip @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) adafruit-nrfutil --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank --touch 1200 diff --git a/hw/bsp/nrf/boards/nrf52840_mdk_dongle/board.mk b/hw/bsp/nrf/boards/nrf52840_mdk_dongle/board.mk index a184fa892..3afa234aa 100644 --- a/hw/bsp/nrf/boards/nrf52840_mdk_dongle/board.mk +++ b/hw/bsp/nrf/boards/nrf52840_mdk_dongle/board.mk @@ -7,9 +7,9 @@ LD_FILE = $(BOARD_PATH)/$(BOARD).ld # make BOARD=nrf52840_mdk_dongle SERIAL=/dev/ttyACM0 all flash NRFUTIL = nrfutil -$(BUILD)/$(BOARD)-firmware.zip: $(BUILD)/$(BOARD)-firmware.hex +$(BUILD)/$(PROJECT).zip: $(BUILD)/$(PROJECT).hex $(NRFUTIL) pkg generate --hw-version 52 --sd-req 0x0000 --debug-mode --application $^ $@ -flash: $(BUILD)/$(BOARD)-firmware.zip +flash: $(BUILD)/$(PROJECT).zip @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) $(NRFUTIL) dfu usb-serial --package $^ -p $(SERIAL) -b 115200 \ No newline at end of file diff --git a/hw/bsp/nrf/boards/pca10059/board.mk b/hw/bsp/nrf/boards/pca10059/board.mk index 25609f2fa..0b82ecdbb 100644 --- a/hw/bsp/nrf/boards/pca10059/board.mk +++ b/hw/bsp/nrf/boards/pca10059/board.mk @@ -7,9 +7,9 @@ LD_FILE = $(BOARD_PATH)/$(BOARD).ld # make BOARD=pca10059 SERIAL=/dev/ttyACM0 all flash NRFUTIL = nrfutil -$(BUILD)/$(BOARD)-firmware.zip: $(BUILD)/$(BOARD)-firmware.hex +$(BUILD)/$(PROJECT).zip: $(BUILD)/$(PROJECT).hex $(NRFUTIL) pkg generate --hw-version 52 --sd-req 0x0000 --debug-mode --application $^ $@ -flash: $(BUILD)/$(BOARD)-firmware.zip +flash: $(BUILD)/$(PROJECT).zip @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) $(NRFUTIL) dfu usb-serial --package $^ -p $(SERIAL) -b 115200 diff --git a/hw/bsp/nutiny_nuc121s/board.mk b/hw/bsp/nutiny_nuc121s/board.mk index 0a8b6e048..ce18a749c 100644 --- a/hw/bsp/nutiny_nuc121s/board.mk +++ b/hw/bsp/nutiny_nuc121s/board.mk @@ -52,5 +52,5 @@ JLINK_DEVICE = NUC121SC2AE # Flash using Nuvoton's openocd fork at https://github.com/OpenNuvoton/OpenOCD-Nuvoton # Please compile and install it from github source -flash: $(BUILD)/$(BOARD)-firmware.elf +flash: $(BUILD)/$(PROJECT).elf openocd -f interface/nulink.cfg -f target/numicroM0.cfg -c "program $< reset exit" diff --git a/hw/bsp/nutiny_nuc125s/board.mk b/hw/bsp/nutiny_nuc125s/board.mk index 31577d800..fe51b79d2 100644 --- a/hw/bsp/nutiny_nuc125s/board.mk +++ b/hw/bsp/nutiny_nuc125s/board.mk @@ -36,5 +36,5 @@ JLINK_DEVICE = NUC125SC2AE # Flash using Nuvoton's openocd fork at https://github.com/OpenNuvoton/OpenOCD-Nuvoton # Please compile and install it from github source -flash: $(BUILD)/$(BOARD)-firmware.elf +flash: $(BUILD)/$(PROJECT).elf openocd -f interface/nulink.cfg -f target/numicroM0.cfg -c "program $< reset exit" diff --git a/hw/bsp/nutiny_nuc126v/board.mk b/hw/bsp/nutiny_nuc126v/board.mk index 7bf3989fc..30cb3df03 100644 --- a/hw/bsp/nutiny_nuc126v/board.mk +++ b/hw/bsp/nutiny_nuc126v/board.mk @@ -56,5 +56,5 @@ JLINK_DEVICE = NUC126VG4AE # Flash using Nuvoton's openocd fork at https://github.com/OpenNuvoton/OpenOCD-Nuvoton # Please compile and install it from github source -flash: $(BUILD)/$(BOARD)-firmware.elf +flash: $(BUILD)/$(PROJECT).elf openocd -f interface/nulink.cfg -f target/numicroM0.cfg -c "program $< reset exit" diff --git a/hw/bsp/nutiny_sdk_nuc120/board.mk b/hw/bsp/nutiny_sdk_nuc120/board.mk index 51841643a..0d3a3bff4 100644 --- a/hw/bsp/nutiny_sdk_nuc120/board.mk +++ b/hw/bsp/nutiny_sdk_nuc120/board.mk @@ -52,5 +52,5 @@ JLINK_DEVICE = NUC120LE3 # Flash using Nuvoton's openocd fork at https://github.com/OpenNuvoton/OpenOCD-Nuvoton # Please compile and install it from github source -flash: $(BUILD)/$(BOARD)-firmware.elf +flash: $(BUILD)/$(PROJECT).elf openocd -f interface/nulink.cfg -f target/numicroM0.cfg -c "program $< reset exit" diff --git a/hw/bsp/nutiny_sdk_nuc505/board.mk b/hw/bsp/nutiny_sdk_nuc505/board.mk index 2d00cd9be..99103fc65 100644 --- a/hw/bsp/nutiny_sdk_nuc505/board.mk +++ b/hw/bsp/nutiny_sdk_nuc505/board.mk @@ -57,5 +57,5 @@ JLINK_DEVICE = NUC505YO13Y # Flash using Nuvoton's openocd fork at https://github.com/OpenNuvoton/OpenOCD-Nuvoton # Please compile and install it from github source -flash: $(BUILD)/$(BOARD)-firmware.elf +flash: $(BUILD)/$(PROJECT).elf openocd -f interface/nulink.cfg -f target/numicroM4.cfg -c "program $< reset exit" diff --git a/hw/bsp/samd11_xplained/board.mk b/hw/bsp/samd11_xplained/board.mk index c80ece4a6..c12ecd214 100644 --- a/hw/bsp/samd11_xplained/board.mk +++ b/hw/bsp/samd11_xplained/board.mk @@ -42,5 +42,5 @@ FREERTOS_PORT = ARM_CM0 JLINK_DEVICE = ATSAMD11D14 # flash using edbg -flash: $(BUILD)/$(BOARD)-firmware.bin +flash: $(BUILD)/$(PROJECT).bin edbg -b -t samd11 -e -pv -f $< diff --git a/hw/bsp/samd21/boards/luna/board.mk b/hw/bsp/samd21/boards/luna/board.mk index 0feae9313..5beb5e02d 100644 --- a/hw/bsp/samd21/boards/luna/board.mk +++ b/hw/bsp/samd21/boards/luna/board.mk @@ -6,6 +6,6 @@ LD_FILE = $(BOARD_PATH)/samd21g18a_flash.ld JLINK_DEVICE = ATSAMD21G18 # flash using dfu-util -flash: $(BUILD)/$(BOARD)-firmware.bin +flash: $(BUILD)/$(PROJECT).bin dfu-util -a 0 -d 1d50:615c -D $< || dfu-util -a 0 -d 16d0:05a5 -D $< diff --git a/hw/bsp/samd21/family.mk b/hw/bsp/samd21/family.mk index 2f4d6b7ae..76929f74d 100644 --- a/hw/bsp/samd21/family.mk +++ b/hw/bsp/samd21/family.mk @@ -41,6 +41,6 @@ FREERTOS_PORT = ARM_CM0 # Add it to your PATH or change BOSSAC variable to match your installation BOSSAC = bossac -flash-bossac: $(BUILD)/$(BOARD)-firmware.bin +flash-bossac: $(BUILD)/$(PROJECT).bin @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) $(BOSSAC) --port=$(SERIAL) -U -i --offset=0x2000 -e -w $^ -R diff --git a/hw/bsp/samd51/family.mk b/hw/bsp/samd51/family.mk index 097593748..dbb0a1036 100644 --- a/hw/bsp/samd51/family.mk +++ b/hw/bsp/samd51/family.mk @@ -44,6 +44,6 @@ FREERTOS_PORT = ARM_CM4F # Add it to your PATH or change BOSSAC variable to match your installation BOSSAC = bossac -flash-bossac: $(BUILD)/$(BOARD)-firmware.bin +flash-bossac: $(BUILD)/$(PROJECT).bin @:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0) $(BOSSAC) --port=$(SERIAL) -U -i --offset=0x4000 -e -w $^ -R diff --git a/hw/bsp/same70_xplained/board.mk b/hw/bsp/same70_xplained/board.mk index efe597fe3..21f5350c3 100644 --- a/hw/bsp/same70_xplained/board.mk +++ b/hw/bsp/same70_xplained/board.mk @@ -54,5 +54,5 @@ JLINK_DEVICE = SAME70Q21B # flash using edbg from https://github.com/ataradov/edbg # Note: SAME70's GPNVM1 must be set to 1 to boot from flash with # edbg -t same70 -F w0,1,1 -flash: $(BUILD)/$(BOARD)-firmware.bin +flash: $(BUILD)/$(PROJECT).bin edbg --verbose -t same70 -pv -f $< diff --git a/hw/bsp/samg55xplained/board.mk b/hw/bsp/samg55xplained/board.mk index 79716d36d..b574a39e7 100644 --- a/hw/bsp/samg55xplained/board.mk +++ b/hw/bsp/samg55xplained/board.mk @@ -49,5 +49,5 @@ FREERTOS_PORT = ARM_CM4F JLINK_DEVICE = ATSAMG55J19 # flash using edbg from https://github.com/ataradov/edbg -flash: $(BUILD)/$(BOARD)-firmware.bin +flash: $(BUILD)/$(PROJECT).bin edbg --verbose -t samg55 -pv -f $< diff --git a/hw/bsp/spresense/board.mk b/hw/bsp/spresense/board.mk index 74b04ef5e..245976235 100644 --- a/hw/bsp/spresense/board.mk +++ b/hw/bsp/spresense/board.mk @@ -61,13 +61,13 @@ LDFLAGS += \ VENDOR = sony CHIP_FAMILY = cxd56 -$(MKSPK): $(BUILD)/$(BOARD)-firmware.elf +$(MKSPK): $(BUILD)/$(PROJECT).elf $(MAKE) -C $(TOP)/hw/mcu/sony/cxd56/mkspk -$(BUILD)/$(BOARD)-firmware.spk: $(MKSPK) +$(BUILD)/$(PROJECT).spk: $(MKSPK) @echo CREATE $@ - @$(MKSPK) -c 2 $(BUILD)/$(BOARD)-firmware.elf nuttx $@ + @$(MKSPK) -c 2 $(BUILD)/$(PROJECT).elf nuttx $@ # flash -flash: $(BUILD)/$(BOARD)-firmware.spk +flash: $(BUILD)/$(PROJECT).spk @$(TOP)/hw/mcu/sony/cxd56/tools/flash_writer.py -s -c $(SERIAL) -d -b 115200 -n $< diff --git a/hw/bsp/stm32f103bluepill/board.mk b/hw/bsp/stm32f103bluepill/board.mk index 8dc1fa3f5..e1517cfaa 100644 --- a/hw/bsp/stm32f103bluepill/board.mk +++ b/hw/bsp/stm32f103bluepill/board.mk @@ -46,5 +46,5 @@ FREERTOS_PORT = ARM_CM3 JLINK_DEVICE = stm32f103c8 # flash target ROM bootloader -flash: $(BUILD)/$(BOARD)-firmware.bin +flash: $(BUILD)/$(PROJECT).bin dfu-util -R -a 0 --dfuse-address 0x08000000 -D $< diff --git a/hw/bsp/stm32f4/boards/feather_stm32f405/board.mk b/hw/bsp/stm32f4/boards/feather_stm32f405/board.mk index f78bb63fc..1de56fe5a 100644 --- a/hw/bsp/stm32f4/boards/feather_stm32f405/board.mk +++ b/hw/bsp/stm32f4/boards/feather_stm32f405/board.mk @@ -8,5 +8,5 @@ SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f405xx.s JLINK_DEVICE = stm32f405rg # flash target ROM bootloader -flash: $(BUILD)/$(BOARD)-firmware.bin +flash: $(BUILD)/$(PROJECT).bin dfu-util -R -a 0 --dfuse-address 0x08000000 -D $< diff --git a/hw/bsp/stm32f4/boards/stm32f401blackpill/board.mk b/hw/bsp/stm32f4/boards/stm32f401blackpill/board.mk index 2d8b10318..de0f3d4c7 100644 --- a/hw/bsp/stm32f4/boards/stm32f401blackpill/board.mk +++ b/hw/bsp/stm32f4/boards/stm32f401blackpill/board.mk @@ -8,5 +8,5 @@ SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f401xc.s JLINK_DEVICE = stm32f401cc # flash target ROM bootloader -flash: $(BUILD)/$(BOARD)-firmware.bin +flash: $(BUILD)/$(PROJECT).bin dfu-util -R -a 0 --dfuse-address 0x08000000 -D $< diff --git a/hw/bsp/stm32f4/boards/stm32f411blackpill/board.mk b/hw/bsp/stm32f4/boards/stm32f411blackpill/board.mk index a8287d0bc..78be4348a 100644 --- a/hw/bsp/stm32f4/boards/stm32f411blackpill/board.mk +++ b/hw/bsp/stm32f4/boards/stm32f411blackpill/board.mk @@ -8,5 +8,5 @@ SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f411xe.s JLINK_DEVICE = stm32f411ce # flash target ROM bootloader -flash: $(BUILD)/$(BOARD)-firmware.bin +flash: $(BUILD)/$(PROJECT).bin dfu-util -R -a 0 --dfuse-address 0x08000000 -D $< diff --git a/hw/bsp/stm32l0538disco/board.mk b/hw/bsp/stm32l0538disco/board.mk index 9e3423fbc..2c9ffad69 100644 --- a/hw/bsp/stm32l0538disco/board.mk +++ b/hw/bsp/stm32l0538disco/board.mk @@ -50,5 +50,5 @@ JLINK_DEVICE = STM32L053R8 STM32Prog = STM32_Programmer_CLI # flash target using on-board stlink -flash: $(BUILD)/$(BOARD)-firmware.elf +flash: $(BUILD)/$(PROJECT).elf $(STM32Prog) --connect port=swd --write $< --go diff --git a/hw/bsp/stm32l476disco/board.mk b/hw/bsp/stm32l476disco/board.mk index 994849d9e..9e44598b0 100644 --- a/hw/bsp/stm32l476disco/board.mk +++ b/hw/bsp/stm32l476disco/board.mk @@ -53,5 +53,5 @@ JLINK_DEVICE = stm32l476vg STM32Prog = STM32_Programmer_CLI # flash target using on-board stlink -flash: $(BUILD)/$(BOARD)-firmware.elf +flash: $(BUILD)/$(PROJECT).elf $(STM32Prog) --connect port=swd --write $< --go -- cgit v1.3.1 From 8e954a439151822fcd415b3c611008aee423b813 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 1 Feb 2021 13:37:37 +0700 Subject: added enumerate walkaround for RP2040-E5 - PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1 - target linke pico_fix_rp2040_usb_device_enumeration --- examples/device/audio_test/CMakeLists.txt | 2 +- examples/device/board_test/CMakeLists.txt | 2 +- examples/device/cdc_dual_ports/CMakeLists.txt | 2 +- examples/device/cdc_msc/CMakeLists.txt | 2 +- examples/device/dfu_rt/CMakeLists.txt | 2 +- examples/device/dynamic_configuration/CMakeLists.txt | 2 +- examples/device/hid_composite/CMakeLists.txt | 2 +- examples/device/hid_generic_inout/CMakeLists.txt | 2 +- examples/device/hid_multiple_interface/CMakeLists.txt | 2 +- examples/device/midi_test/CMakeLists.txt | 2 +- examples/device/msc_dual_lun/CMakeLists.txt | 2 +- examples/device/net_lwip_webserver/CMakeLists.txt | 2 +- examples/device/uac2_headset/CMakeLists.txt | 2 +- examples/device/usbtmc/CMakeLists.txt | 2 +- examples/device/webusb_serial/CMakeLists.txt | 2 +- hw/bsp/rp2040/family.cmake | 1 + 16 files changed, 16 insertions(+), 15 deletions(-) (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt index 645d57157..a10473b79 100644 --- a/examples/device/audio_test/CMakeLists.txt +++ b/examples/device/audio_test/CMakeLists.txt @@ -33,7 +33,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index 573f026f3..b8b7e7297 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -37,7 +37,7 @@ elseif(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt index c358eddab..f4bf75c26 100644 --- a/examples/device/cdc_dual_ports/CMakeLists.txt +++ b/examples/device/cdc_dual_ports/CMakeLists.txt @@ -33,7 +33,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index 5f4d9ba4e..9e0d1f790 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -39,7 +39,7 @@ elseif(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/dfu_rt/CMakeLists.txt b/examples/device/dfu_rt/CMakeLists.txt index c358eddab..f4bf75c26 100644 --- a/examples/device/dfu_rt/CMakeLists.txt +++ b/examples/device/dfu_rt/CMakeLists.txt @@ -33,7 +33,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt index a759e56e8..b4c95652a 100644 --- a/examples/device/dynamic_configuration/CMakeLists.txt +++ b/examples/device/dynamic_configuration/CMakeLists.txt @@ -34,7 +34,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt index c358eddab..f4bf75c26 100644 --- a/examples/device/hid_composite/CMakeLists.txt +++ b/examples/device/hid_composite/CMakeLists.txt @@ -33,7 +33,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt index c358eddab..f4bf75c26 100644 --- a/examples/device/hid_generic_inout/CMakeLists.txt +++ b/examples/device/hid_generic_inout/CMakeLists.txt @@ -33,7 +33,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt index c358eddab..f4bf75c26 100644 --- a/examples/device/hid_multiple_interface/CMakeLists.txt +++ b/examples/device/hid_multiple_interface/CMakeLists.txt @@ -33,7 +33,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt index c358eddab..f4bf75c26 100644 --- a/examples/device/midi_test/CMakeLists.txt +++ b/examples/device/midi_test/CMakeLists.txt @@ -33,7 +33,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt index f0e050f9c..6032308f2 100644 --- a/examples/device/msc_dual_lun/CMakeLists.txt +++ b/examples/device/msc_dual_lun/CMakeLists.txt @@ -34,7 +34,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index ec4996086..e3c8190f4 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -80,7 +80,7 @@ if(FAMILY STREQUAL "rp2040") HTTPD_USE_CUSTOM_FSDATA=0 ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt index c358eddab..f4bf75c26 100644 --- a/examples/device/uac2_headset/CMakeLists.txt +++ b/examples/device/uac2_headset/CMakeLists.txt @@ -33,7 +33,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt index 686e8dc2d..9a4aa382b 100644 --- a/examples/device/usbtmc/CMakeLists.txt +++ b/examples/device/usbtmc/CMakeLists.txt @@ -34,7 +34,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt index c358eddab..f4bf75c26 100644 --- a/examples/device/webusb_serial/CMakeLists.txt +++ b/examples/device/webusb_serial/CMakeLists.txt @@ -33,7 +33,7 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib) + target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) pico_add_extra_outputs(${PROJECT}) else() diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index e936fbb24..e4f5f47b4 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -30,6 +30,7 @@ target_include_directories(${PROJECT} PUBLIC target_compile_definitions(${PROJECT} PUBLIC CFG_TUSB_MCU=OPT_MCU_RP2040 + PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1 ) if(DEFINED LOG) -- cgit v1.3.1 From bc80d686f507432be00ee961c00c39039b57408e Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 6 Feb 2021 12:54:16 +0700 Subject: clean up --- examples/device/hid_composite/src/usb_descriptors.c | 2 +- examples/device/hid_composite_freertos/src/usb_descriptors.c | 2 +- examples/device/hid_multiple_interface/src/usb_descriptors.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/hid_composite/src/usb_descriptors.c b/examples/device/hid_composite/src/usb_descriptors.c index 879eff05e..67ea34c08 100644 --- a/examples/device/hid_composite/src/usb_descriptors.c +++ b/examples/device/hid_composite/src/usb_descriptors.c @@ -105,7 +105,7 @@ uint8_t const desc_configuration[] = // Config number, interface count, string index, total length, attribute, power in mA TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), - // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval + // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval TUD_HID_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10) }; diff --git a/examples/device/hid_composite_freertos/src/usb_descriptors.c b/examples/device/hid_composite_freertos/src/usb_descriptors.c index a169ee2c7..ead1580da 100644 --- a/examples/device/hid_composite_freertos/src/usb_descriptors.c +++ b/examples/device/hid_composite_freertos/src/usb_descriptors.c @@ -105,7 +105,7 @@ uint8_t const desc_configuration[] = // Config number, interface count, string index, total length, attribute, power in mA TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), - // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval + // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval TUD_HID_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10) }; diff --git a/examples/device/hid_multiple_interface/src/usb_descriptors.c b/examples/device/hid_multiple_interface/src/usb_descriptors.c index 0d67d499a..2354e5c1f 100644 --- a/examples/device/hid_multiple_interface/src/usb_descriptors.c +++ b/examples/device/hid_multiple_interface/src/usb_descriptors.c @@ -118,7 +118,7 @@ uint8_t const desc_configuration[] = // Config number, interface count, string index, total length, attribute, power in mA TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), - // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval + // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval TUD_HID_DESCRIPTOR(ITF_NUM_HID1, 4, HID_PROTOCOL_NONE, sizeof(desc_hid_report1), EPNUM_HID1, CFG_TUD_HID_EP_BUFSIZE, 10), TUD_HID_DESCRIPTOR(ITF_NUM_HID2, 5, HID_PROTOCOL_NONE, sizeof(desc_hid_report2), EPNUM_HID2, CFG_TUD_HID_EP_BUFSIZE, 10) }; -- cgit v1.3.1 From 72bcc0685c142c512f1d04ff18eaa13b99f62e93 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 8 Feb 2021 19:08:16 +0700 Subject: add tud_hid_n_gamepad_report() helper for gamepad report - Add gamepad to hid_composite example. Though it needs a bit of extra work but it will come later as separated PR. --- examples/device/hid_composite/src/main.c | 29 ++++++++++++++++++++++ .../device/hid_composite/src/usb_descriptors.c | 3 ++- .../device/hid_composite/src/usb_descriptors.h | 1 + .../hid_multiple_interface/src/usb_descriptors.c | 10 ++++---- src/class/hid/hid.h | 4 +-- src/class/hid/hid_device.c | 27 ++++++++++++++------ src/class/hid/hid_device.h | 6 +++++ 7 files changed, 65 insertions(+), 15 deletions(-) (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c index 6a9b6445d..45b8ba674 100644 --- a/examples/device/hid_composite/src/main.c +++ b/examples/device/hid_composite/src/main.c @@ -183,6 +183,35 @@ void hid_task(void) if (has_consumer_key) tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &empty_key, 2); has_consumer_key = false; } + + // delay a bit before sending next report + board_delay(10); + } + + /*------------- Gamepad -------------*/ + if ( tud_hid_ready() ) + { + // use to avoid send multiple consecutive zero report for keyboard + static bool has_gamepad_key = false; + + hid_gamepad_report_t report = + { + .x = 0, .y = 0, .z = 0, .rz = 0, .rx = 0, .ry = 0, + .hat = 0, .buttons = 0 + }; + + if ( btn ) + { + report.hat = GAMEPAD_HAT_UP; + tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report)); + + has_gamepad_key = true; + }else + { + report.hat = GAMEPAD_HAT_CENTERED; + if (has_gamepad_key) tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report)); + has_gamepad_key = false; + } } } diff --git a/examples/device/hid_composite/src/usb_descriptors.c b/examples/device/hid_composite/src/usb_descriptors.c index 67ea34c08..fbe0e2550 100644 --- a/examples/device/hid_composite/src/usb_descriptors.c +++ b/examples/device/hid_composite/src/usb_descriptors.c @@ -75,7 +75,8 @@ uint8_t const desc_hid_report[] = { TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD )), TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE )), - TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(REPORT_ID_CONSUMER_CONTROL )) + TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(REPORT_ID_CONSUMER_CONTROL )), + TUD_HID_REPORT_DESC_GAMEPAD ( HID_REPORT_ID(REPORT_ID_GAMEPAD )) }; // Invoked when received GET HID REPORT DESCRIPTOR diff --git a/examples/device/hid_composite/src/usb_descriptors.h b/examples/device/hid_composite/src/usb_descriptors.h index feda83dcd..7894719fd 100644 --- a/examples/device/hid_composite/src/usb_descriptors.h +++ b/examples/device/hid_composite/src/usb_descriptors.h @@ -30,6 +30,7 @@ enum REPORT_ID_KEYBOARD = 1, REPORT_ID_MOUSE, REPORT_ID_CONSUMER_CONTROL, + REPORT_ID_GAMEPAD }; #endif /* USB_DESCRIPTORS_H_ */ diff --git a/examples/device/hid_multiple_interface/src/usb_descriptors.c b/examples/device/hid_multiple_interface/src/usb_descriptors.c index 2354e5c1f..a28e57a2b 100644 --- a/examples/device/hid_multiple_interface/src/usb_descriptors.c +++ b/examples/device/hid_multiple_interface/src/usb_descriptors.c @@ -140,11 +140,11 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index) char const* string_desc_arr [] = { (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409) - "TinyUSB", // 1: Manufacturer - "TinyUSB Device", // 2: Product - "123456", // 3: Serials, should use chip ID - "Keyboard Interface", // 4: Interface 1 String - "Mouse Interface", // 5: Interface 2 String + "TinyUSB", // 1: Manufacturer + "TinyUSB Device", // 2: Product + "123456", // 3: Serials, should use chip ID + "Keyboard Interface", // 4: Interface 1 String + "Mouse Interface", // 5: Interface 2 String }; static uint16_t _desc_str[32]; diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index cb1bd5835..a7db087a7 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -218,7 +218,7 @@ typedef enum //GAMEPAD_BUTTON_ = TU_BIT(15), ///< Undefined button }hid_gamepad_button_bm_t; -/// Standard Gamepad HAT/DPAD Buttons Bitmap (from Linux input event codes) +/// Standard Gamepad HAT/DPAD Buttons (from Linux input event codes) typedef enum { GAMEPAD_HAT_CENTERED = 0, ///< DPAD_CENTERED @@ -230,7 +230,7 @@ typedef enum GAMEPAD_HAT_DOWN_LEFT = 6, ///< DPAD_DOWN_LEFT GAMEPAD_HAT_LEFT = 7, ///< DPAD_LEFT GAMEPAD_HAT_UP_LEFT = 8, ///< DPAD_UP_LEFT -}hid_gamepad_hat_bm_t; +}hid_gamepad_hat_t; /// @} diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 1f03f8862..5b9735071 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -107,9 +107,6 @@ bool tud_hid_n_boot_mode(uint8_t itf) return _hidd_itf[itf].boot_mode; } -//--------------------------------------------------------------------+ -// KEYBOARD API -//--------------------------------------------------------------------+ bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]) { hid_keyboard_report_t report; @@ -127,10 +124,8 @@ bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, return tud_hid_n_report(itf, report_id, &report, sizeof(report)); } -//--------------------------------------------------------------------+ -// MOUSE APPLICATION API -//--------------------------------------------------------------------+ -bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal) +bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, + uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal) { hid_mouse_report_t report = { @@ -144,6 +139,24 @@ bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, uint8_t buttons, int return tud_hid_n_report(itf, report_id, &report, sizeof(report)); } +bool tud_hid_n_gamepad_report(uint8_t itf, uint8_t report_id, + int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons) +{ + hid_gamepad_report_t report = + { + .x = x, + .y = y, + .z = z, + .rz = rz, + .rx = rx, + .ry = ry, + .hat = hat, + .buttons = buttons, + }; + + return tud_hid_n_report(itf, report_id, &report, sizeof(report)); +} + //--------------------------------------------------------------------+ // USBD-CLASS API //--------------------------------------------------------------------+ diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index f429d8b9a..a92dc14e0 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -71,6 +71,10 @@ bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, // use template layout report as defined by hid_mouse_report_t bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal); +// Gamepad: convenient helper to send mouse report if application +// use template layout report TUD_HID_REPORT_DESC_GAMEPAD +bool tud_hid_n_gamepad_report(uint8_t itf, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons); + //--------------------------------------------------------------------+ // Application API (Single Port) //--------------------------------------------------------------------+ @@ -119,6 +123,8 @@ TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate); #endif +// TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t itf, ); + //--------------------------------------------------------------------+ // Inline Functions -- cgit v1.3.1 From ce942baad2b5601984662b428140e3cb9acdabbc Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 2 Mar 2021 22:57:33 +0700 Subject: update pico-sdk to more recent commit - move target_link_libraries() to family.cmake - enable pico_bootsel_via_double_reset --- examples/device/audio_test/CMakeLists.txt | 3 --- examples/device/board_test/CMakeLists.txt | 3 --- examples/device/cdc_dual_ports/CMakeLists.txt | 3 --- examples/device/cdc_msc/CMakeLists.txt | 3 --- examples/device/dfu_runtime/CMakeLists.txt | 3 --- examples/device/dynamic_configuration/CMakeLists.txt | 3 --- examples/device/hid_composite/CMakeLists.txt | 3 --- examples/device/hid_generic_inout/CMakeLists.txt | 3 --- examples/device/hid_multiple_interface/CMakeLists.txt | 3 --- examples/device/midi_test/CMakeLists.txt | 3 --- examples/device/msc_dual_lun/CMakeLists.txt | 3 --- examples/device/net_lwip_webserver/CMakeLists.txt | 3 --- examples/device/uac2_headset/CMakeLists.txt | 3 --- examples/device/usbtmc/CMakeLists.txt | 3 --- examples/device/webusb_serial/CMakeLists.txt | 3 --- examples/host/cdc_msc_hid/CMakeLists.txt | 3 --- examples/rules.mk | 3 ++- hw/bsp/rp2040/family.cmake | 8 ++++++++ hw/bsp/rp2040/family.mk | 2 ++ hw/mcu/raspberrypi/pico-sdk | 2 +- 20 files changed, 13 insertions(+), 50 deletions(-) (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt index a10473b79..7038dd041 100644 --- a/examples/device/audio_test/CMakeLists.txt +++ b/examples/device/audio_test/CMakeLists.txt @@ -33,9 +33,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index b8b7e7297..4e6a9b3f8 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -37,9 +37,6 @@ elseif(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt index f4bf75c26..5e3ec0909 100644 --- a/examples/device/cdc_dual_ports/CMakeLists.txt +++ b/examples/device/cdc_dual_ports/CMakeLists.txt @@ -33,9 +33,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index 9e0d1f790..41dd167b7 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -39,9 +39,6 @@ elseif(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/dfu_runtime/CMakeLists.txt b/examples/device/dfu_runtime/CMakeLists.txt index f4bf75c26..5e3ec0909 100644 --- a/examples/device/dfu_runtime/CMakeLists.txt +++ b/examples/device/dfu_runtime/CMakeLists.txt @@ -33,9 +33,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt index b4c95652a..be6224360 100644 --- a/examples/device/dynamic_configuration/CMakeLists.txt +++ b/examples/device/dynamic_configuration/CMakeLists.txt @@ -34,9 +34,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt index f4bf75c26..5e3ec0909 100644 --- a/examples/device/hid_composite/CMakeLists.txt +++ b/examples/device/hid_composite/CMakeLists.txt @@ -33,9 +33,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt index f4bf75c26..5e3ec0909 100644 --- a/examples/device/hid_generic_inout/CMakeLists.txt +++ b/examples/device/hid_generic_inout/CMakeLists.txt @@ -33,9 +33,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt index f4bf75c26..5e3ec0909 100644 --- a/examples/device/hid_multiple_interface/CMakeLists.txt +++ b/examples/device/hid_multiple_interface/CMakeLists.txt @@ -33,9 +33,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt index f4bf75c26..5e3ec0909 100644 --- a/examples/device/midi_test/CMakeLists.txt +++ b/examples/device/midi_test/CMakeLists.txt @@ -33,9 +33,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt index 6032308f2..0036dc685 100644 --- a/examples/device/msc_dual_lun/CMakeLists.txt +++ b/examples/device/msc_dual_lun/CMakeLists.txt @@ -34,9 +34,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index e3c8190f4..c9aabc636 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -80,9 +80,6 @@ if(FAMILY STREQUAL "rp2040") HTTPD_USE_CUSTOM_FSDATA=0 ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt index f4bf75c26..5e3ec0909 100644 --- a/examples/device/uac2_headset/CMakeLists.txt +++ b/examples/device/uac2_headset/CMakeLists.txt @@ -33,9 +33,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt index 9a4aa382b..808bdbcf8 100644 --- a/examples/device/usbtmc/CMakeLists.txt +++ b/examples/device/usbtmc/CMakeLists.txt @@ -34,9 +34,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt index f4bf75c26..5e3ec0909 100644 --- a/examples/device/webusb_serial/CMakeLists.txt +++ b/examples/device/webusb_serial/CMakeLists.txt @@ -33,9 +33,6 @@ if(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/host/cdc_msc_hid/CMakeLists.txt b/examples/host/cdc_msc_hid/CMakeLists.txt index dc2effde9..2302678b7 100644 --- a/examples/host/cdc_msc_hid/CMakeLists.txt +++ b/examples/host/cdc_msc_hid/CMakeLists.txt @@ -38,9 +38,6 @@ elseif(FAMILY STREQUAL "rp2040") CFG_TUSB_OS=OPT_OS_PICO ) - target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration) - pico_add_extra_outputs(${PROJECT}) - else() message(FATAL_ERROR "Invalid FAMILY specified") endif() diff --git a/examples/rules.mk b/examples/rules.mk index 2b28a4714..561494c6d 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -194,6 +194,8 @@ else $(RM) -rf $(BUILD) endif +endif # GNU Make + # Print out the value of a make variable. # https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile print-%: @@ -227,7 +229,6 @@ flash-pyocd: $(BUILD)/$(PROJECT).hex pyocd flash -t $(PYOCD_TARGET) $< pyocd reset -t $(PYOCD_TARGET) -endif # GNU Make #-------------- Artifacts -------------- diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index 699ad174d..e779e4cbb 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -1,3 +1,11 @@ +target_link_libraries(${PROJECT} + pico_stdlib + pico_bootsel_via_double_reset + pico_fix_rp2040_usb_device_enumeration +) + +pico_add_extra_outputs(${PROJECT}) + # TinyUSB Stack source set(SRC_TINYUSB ${TOP}/src/tusb.c diff --git a/hw/bsp/rp2040/family.mk b/hw/bsp/rp2040/family.mk index 8e30e7eb6..9aacae37d 100644 --- a/hw/bsp/rp2040/family.mk +++ b/hw/bsp/rp2040/family.mk @@ -1 +1,3 @@ FAMILY_SUBMODULES = hw/mcu/raspberrypi/pico-sdk + +JLINK_DEVICE = rp2040_m0_0 diff --git a/hw/mcu/raspberrypi/pico-sdk b/hw/mcu/raspberrypi/pico-sdk index 2d5789eca..61978dc70 160000 --- a/hw/mcu/raspberrypi/pico-sdk +++ b/hw/mcu/raspberrypi/pico-sdk @@ -1 +1 @@ -Subproject commit 2d5789eca89658a7f0a01e2d6010c0f254605d72 +Subproject commit 61978dc707c7f2026efa4c3300bbb94baa89c78a -- cgit v1.3.1 From 249852d25ced9852eb7f95dcc38b2a82b4c02390 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 18 Mar 2021 19:53:39 +0700 Subject: use boot2_generic_03h for adafruit feather rp2040 - also use boot2_generic_03h for now for itsy bitsy and qt rp2040 - change default flash target for rp2040 to flash-pyocd --- examples/device/audio_test/CMakeLists.txt | 3 ++- examples/device/board_test/CMakeLists.txt | 4 +++- examples/device/cdc_dual_ports/CMakeLists.txt | 3 ++- examples/device/cdc_msc/CMakeLists.txt | 3 +-- examples/device/dfu_runtime/CMakeLists.txt | 3 ++- examples/device/dynamic_configuration/CMakeLists.txt | 3 ++- examples/device/hid_composite/CMakeLists.txt | 3 ++- examples/device/hid_generic_inout/CMakeLists.txt | 3 ++- examples/device/hid_multiple_interface/CMakeLists.txt | 3 ++- examples/device/midi_test/CMakeLists.txt | 3 ++- examples/device/msc_dual_lun/CMakeLists.txt | 3 ++- examples/device/net_lwip_webserver/CMakeLists.txt | 3 ++- examples/device/uac2_headset/CMakeLists.txt | 3 ++- examples/device/usbtmc/CMakeLists.txt | 2 +- examples/device/webusb_serial/CMakeLists.txt | 3 ++- examples/host/cdc_msc_hid/CMakeLists.txt | 3 ++- hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake | 1 + hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake | 1 + hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake | 1 + hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake | 1 + hw/bsp/rp2040/family.cmake | 6 ++++++ hw/bsp/rp2040/family.mk | 10 +++++----- 22 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake create mode 100644 hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake create mode 100644 hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake create mode 100644 hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt index 7038dd041..03f2439e2 100644 --- a/examples/device/audio_test/CMakeLists.txt +++ b/examples/device/audio_test/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index 4e6a9b3f8..b4c4ce4d0 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -9,15 +9,17 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "esp32s2") cmake_minimum_required(VERSION 3.5) + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) project(${PROJECT}) elseif(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt index 5e3ec0909..94e4fc1fa 100644 --- a/examples/device/cdc_dual_ports/CMakeLists.txt +++ b/examples/device/cdc_dual_ports/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index 41dd167b7..f6cf64521 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -17,9 +17,8 @@ elseif(FAMILY STREQUAL "rp2040") set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) - + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) # Example source diff --git a/examples/device/dfu_runtime/CMakeLists.txt b/examples/device/dfu_runtime/CMakeLists.txt index 5e3ec0909..ea294b3b9 100644 --- a/examples/device/dfu_runtime/CMakeLists.txt +++ b/examples/device/dfu_runtime/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt index be6224360..09a8dcc4c 100644 --- a/examples/device/dynamic_configuration/CMakeLists.txt +++ b/examples/device/dynamic_configuration/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt index 5e3ec0909..c85f2ace2 100644 --- a/examples/device/hid_composite/CMakeLists.txt +++ b/examples/device/hid_composite/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt index 5e3ec0909..5de4a932d 100644 --- a/examples/device/hid_generic_inout/CMakeLists.txt +++ b/examples/device/hid_generic_inout/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt index 5e3ec0909..5de4a932d 100644 --- a/examples/device/hid_multiple_interface/CMakeLists.txt +++ b/examples/device/hid_multiple_interface/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt index 5e3ec0909..5de4a932d 100644 --- a/examples/device/midi_test/CMakeLists.txt +++ b/examples/device/midi_test/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt index 0036dc685..48e183edc 100644 --- a/examples/device/msc_dual_lun/CMakeLists.txt +++ b/examples/device/msc_dual_lun/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index c9aabc636..69a242be8 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt index 5e3ec0909..5de4a932d 100644 --- a/examples/device/uac2_headset/CMakeLists.txt +++ b/examples/device/uac2_headset/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt index 808bdbcf8..f40d123b0 100644 --- a/examples/device/usbtmc/CMakeLists.txt +++ b/examples/device/usbtmc/CMakeLists.txt @@ -11,8 +11,8 @@ if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt index 5e3ec0909..5de4a932d 100644 --- a/examples/device/webusb_serial/CMakeLists.txt +++ b/examples/device/webusb_serial/CMakeLists.txt @@ -9,10 +9,11 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/examples/host/cdc_msc_hid/CMakeLists.txt b/examples/host/cdc_msc_hid/CMakeLists.txt index 2302678b7..7413e4087 100644 --- a/examples/host/cdc_msc_hid/CMakeLists.txt +++ b/examples/host/cdc_msc_hid/CMakeLists.txt @@ -14,10 +14,11 @@ if(FAMILY STREQUAL "esp32s2") elseif(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) + set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + project(${PROJECT}) - pico_sdk_init() add_executable(${PROJECT}) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) diff --git a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake new file mode 100644 index 000000000..ea4070cf3 --- /dev/null +++ b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake @@ -0,0 +1 @@ +set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_generic_03h.S") diff --git a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake new file mode 100644 index 000000000..ea4070cf3 --- /dev/null +++ b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake @@ -0,0 +1 @@ +set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_generic_03h.S") diff --git a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake new file mode 100644 index 000000000..ea4070cf3 --- /dev/null +++ b/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake @@ -0,0 +1 @@ +set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_generic_03h.S") diff --git a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake new file mode 100644 index 000000000..eb9f219d2 --- /dev/null +++ b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake @@ -0,0 +1 @@ +set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_w25q080.S") diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index af23c2368..63c7daa38 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -1,3 +1,9 @@ +# Board specific define e.g boot stage2 +# PICO_DEFAULT_BOOT_STAGE2_FILE must be set before pico_sdk_init() +include(${TOP}/hw/bsp/${FAMILY}/boards/${BOARD}/board.cmake) + +pico_sdk_init() + target_link_libraries(${PROJECT} pico_stdlib pico_bootsel_via_double_reset diff --git a/hw/bsp/rp2040/family.mk b/hw/bsp/rp2040/family.mk index ed7b11564..6df367323 100644 --- a/hw/bsp/rp2040/family.mk +++ b/hw/bsp/rp2040/family.mk @@ -1,5 +1,8 @@ DEPS_SUBMODULES += hw/mcu/raspberrypi/pico-sdk +JLINK_DEVICE = rp2040_m0_0 +PYOCD_TARGET = rp2040 + ifeq ($(DEBUG), 1) CMAKE_DEFSYM += -DCMAKE_BUILD_TYPE=Debug endif @@ -13,9 +16,6 @@ all: $(BUILD) clean: $(RM) -rf $(BUILD) -#flash: flash-pyocd -flash: +flash: flash-pyocd +flash-uf2: @$(CP) $(BUILD)/$(PROJECT).uf2 /media/$(USER)/RPI-RP2 - -JLINK_DEVICE = rp2040_m0_0 -PYOCD_TARGET = rp2040 -- cgit v1.3.1 From c8bb0020ea186dab093cd7adf4c694d89657e1cd Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 11 Apr 2021 13:37:07 +0700 Subject: update rp2040 to use pico-sdk externally also try to update ci --- .github/workflows/build.yml | 6 +++ examples/device/audio_test/CMakeLists.txt | 4 +- examples/device/board_test/CMakeLists.txt | 4 +- examples/device/cdc_dual_ports/CMakeLists.txt | 4 +- examples/device/cdc_msc/CMakeLists.txt | 4 +- examples/device/dfu_runtime/CMakeLists.txt | 4 +- .../device/dynamic_configuration/CMakeLists.txt | 4 +- examples/device/hid_composite/CMakeLists.txt | 4 +- examples/device/hid_generic_inout/CMakeLists.txt | 4 +- .../device/hid_multiple_interface/CMakeLists.txt | 4 +- examples/device/midi_test/CMakeLists.txt | 4 +- examples/device/msc_dual_lun/CMakeLists.txt | 4 +- examples/device/net_lwip_webserver/CMakeLists.txt | 4 +- examples/device/uac2_headset/CMakeLists.txt | 4 +- examples/device/usbtmc/CMakeLists.txt | 5 +- examples/device/webusb_serial/CMakeLists.txt | 4 +- examples/host/cdc_msc_hid/CMakeLists.txt | 4 +- hw/bsp/rp2040/family.mk | 2 - hw/bsp/rp2040/pico_sdk_import.cmake | 62 ++++++++++++++++++++++ 19 files changed, 86 insertions(+), 49 deletions(-) create mode 100644 hw/bsp/rp2040/pico_sdk_import.cmake (limited to 'examples/device/hid_multiple_interface') diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f10d04afe..3d61f7f02 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,6 +62,12 @@ jobs: - name: Checkout common submodules in lib run: git submodule update --init lib/FreeRTOS-Kernel lib/lwip lib/sct_neopixel + - name: Checkout pico-sdk + if: ${{ matrix.family }} == 'rp2040' + run: | + git clone --depth 1 https://github.com/raspberrypi/pico-sdk ~/pico-sdk + echo >> $GITHUB_ENV PICO_SDK_PATH=~/pico-sdk + - name: Set Toolchain URL run: echo >> $GITHUB_ENV TOOLCHAIN_URL=https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v10.2.1-1.1/xpack-arm-none-eabi-gcc-10.2.1-1.1-linux-x64.tar.gz diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt index 03f2439e2..9cae652ea 100644 --- a/examples/device/audio_test/CMakeLists.txt +++ b/examples/device/audio_test/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index b4c4ce4d0..32c0329ea 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -16,9 +16,7 @@ if(FAMILY STREQUAL "esp32s2") elseif(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt index 94e4fc1fa..bb6416cc7 100644 --- a/examples/device/cdc_dual_ports/CMakeLists.txt +++ b/examples/device/cdc_dual_ports/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index f6cf64521..d4ee8c050 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -14,8 +14,8 @@ if(FAMILY STREQUAL "esp32s2") elseif(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) + + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/dfu_runtime/CMakeLists.txt b/examples/device/dfu_runtime/CMakeLists.txt index ea294b3b9..d59d2e9a1 100644 --- a/examples/device/dfu_runtime/CMakeLists.txt +++ b/examples/device/dfu_runtime/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt index 09a8dcc4c..a9c343994 100644 --- a/examples/device/dynamic_configuration/CMakeLists.txt +++ b/examples/device/dynamic_configuration/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt index c85f2ace2..7f85a3a40 100644 --- a/examples/device/hid_composite/CMakeLists.txt +++ b/examples/device/hid_composite/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt index 5de4a932d..d59d2e9a1 100644 --- a/examples/device/hid_generic_inout/CMakeLists.txt +++ b/examples/device/hid_generic_inout/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt index 5de4a932d..d59d2e9a1 100644 --- a/examples/device/hid_multiple_interface/CMakeLists.txt +++ b/examples/device/hid_multiple_interface/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt index 5de4a932d..d59d2e9a1 100644 --- a/examples/device/midi_test/CMakeLists.txt +++ b/examples/device/midi_test/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt index 48e183edc..454c5a08a 100644 --- a/examples/device/msc_dual_lun/CMakeLists.txt +++ b/examples/device/msc_dual_lun/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index 69a242be8..76f7be6cc 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt index 5de4a932d..d59d2e9a1 100644 --- a/examples/device/uac2_headset/CMakeLists.txt +++ b/examples/device/uac2_headset/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt index f40d123b0..f9ba2b529 100644 --- a/examples/device/usbtmc/CMakeLists.txt +++ b/examples/device/usbtmc/CMakeLists.txt @@ -9,9 +9,8 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt index 5de4a932d..d59d2e9a1 100644 --- a/examples/device/webusb_serial/CMakeLists.txt +++ b/examples/device/webusb_serial/CMakeLists.txt @@ -10,9 +10,7 @@ get_filename_component(TOP "${TOP}" REALPATH) if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/examples/host/cdc_msc_hid/CMakeLists.txt b/examples/host/cdc_msc_hid/CMakeLists.txt index 7413e4087..30b6c713e 100644 --- a/examples/host/cdc_msc_hid/CMakeLists.txt +++ b/examples/host/cdc_msc_hid/CMakeLists.txt @@ -15,9 +15,7 @@ if(FAMILY STREQUAL "esp32s2") elseif(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) - set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk) - include(${PICO_SDK_PATH}/pico_sdk_init.cmake) - + include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) diff --git a/hw/bsp/rp2040/family.mk b/hw/bsp/rp2040/family.mk index 6df367323..5db784b14 100644 --- a/hw/bsp/rp2040/family.mk +++ b/hw/bsp/rp2040/family.mk @@ -1,5 +1,3 @@ -DEPS_SUBMODULES += hw/mcu/raspberrypi/pico-sdk - JLINK_DEVICE = rp2040_m0_0 PYOCD_TARGET = rp2040 diff --git a/hw/bsp/rp2040/pico_sdk_import.cmake b/hw/bsp/rp2040/pico_sdk_import.cmake new file mode 100644 index 000000000..28efe9eab --- /dev/null +++ b/hw/bsp/rp2040/pico_sdk_import.cmake @@ -0,0 +1,62 @@ +# This is a copy of /external/pico_sdk_import.cmake + +# This can be dropped into an external project to help locate this SDK +# It should be include()ed prior to project() + +if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) + set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) + message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) + set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) + message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) + set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) + message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") +endif () + +set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") +set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") +set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") + +if (NOT PICO_SDK_PATH) + if (PICO_SDK_FETCH_FROM_GIT) + include(FetchContent) + set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) + if (PICO_SDK_FETCH_FROM_GIT_PATH) + get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") + endif () + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + ) + if (NOT pico_sdk) + message("Downloading Raspberry Pi Pico SDK") + FetchContent_Populate(pico_sdk) + set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) + endif () + set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) + else () + message(FATAL_ERROR + "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." + ) + endif () +endif () + +get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") +if (NOT EXISTS ${PICO_SDK_PATH}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") +endif () + +set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) +if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") +endif () + +set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) + +include(${PICO_SDK_INIT_CMAKE_FILE}) -- cgit v1.3.1 From 59f0fa1e5e6767602c346bdd9371bf7d6caa9d08 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 19 Apr 2021 13:30:04 +0700 Subject: cmake cleanup --- examples/device/audio_4_channel_mic/CMakeLists.txt | 2 +- examples/device/audio_test/CMakeLists.txt | 2 +- examples/device/board_test/CMakeLists.txt | 6 ++++-- examples/device/cdc_dual_ports/CMakeLists.txt | 2 +- examples/device/cdc_msc/CMakeLists.txt | 11 +++-------- examples/device/cdc_msc_freertos/CMakeLists.txt | 2 ++ examples/device/dfu_runtime/CMakeLists.txt | 2 +- examples/device/dynamic_configuration/CMakeLists.txt | 2 +- examples/device/hid_composite/CMakeLists.txt | 2 +- examples/device/hid_generic_inout/CMakeLists.txt | 2 +- examples/device/hid_multiple_interface/CMakeLists.txt | 2 +- examples/device/midi_test/CMakeLists.txt | 2 +- examples/device/msc_dual_lun/CMakeLists.txt | 2 +- examples/device/net_lwip_webserver/CMakeLists.txt | 2 +- examples/device/uac2_headset/CMakeLists.txt | 2 +- examples/device/usbtmc/CMakeLists.txt | 2 +- examples/device/webusb_serial/CMakeLists.txt | 2 +- examples/host/cdc_msc_hid/CMakeLists.txt | 2 +- 18 files changed, 24 insertions(+), 25 deletions(-) (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/audio_4_channel_mic/CMakeLists.txt b/examples/device/audio_4_channel_mic/CMakeLists.txt index 9cae652ea..f2c81c4d3 100644 --- a/examples/device/audio_4_channel_mic/CMakeLists.txt +++ b/examples/device/audio_4_channel_mic/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt index 9cae652ea..f2c81c4d3 100644 --- a/examples/device/audio_test/CMakeLists.txt +++ b/examples/device/audio_test/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index 698b0c96f..c41ad92ab 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -1,4 +1,6 @@ -# use directory name for project id +cmake_minimum_required(VERSION 3.5) + +# use BOARD-Directory name for project id get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) set(PROJECT ${BOARD}-${PROJECT}) @@ -38,5 +40,5 @@ elseif(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt index bb6416cc7..4160c0c88 100644 --- a/examples/device/cdc_dual_ports/CMakeLists.txt +++ b/examples/device/cdc_dual_ports/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index ca8f07ade..6c828a396 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -7,18 +7,13 @@ set(TOP "../../..") get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= -if(FAMILY MATCHES "^(esp32s[2-3])*") - cmake_minimum_required(VERSION 3.5) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - project(${PROJECT}) - -elseif(FAMILY STREQUAL "rp2040") +if(FAMILY STREQUAL "rp2040") cmake_minimum_required(VERSION 3.12) include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) project(${PROJECT}) add_executable(${PROJECT}) - + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) # Example source @@ -39,5 +34,5 @@ elseif(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/cdc_msc_freertos/CMakeLists.txt b/examples/device/cdc_msc_freertos/CMakeLists.txt index aaac4d894..1d04a8518 100644 --- a/examples/device/cdc_msc_freertos/CMakeLists.txt +++ b/examples/device/cdc_msc_freertos/CMakeLists.txt @@ -10,6 +10,8 @@ get_filename_component(TOP "${TOP}" REALPATH) # Check for -DFAMILY= if(FAMILY MATCHES "^esp32s[2-3]") + cmake_minimum_required(VERSION 3.5) + include(${TOP}/hw/bsp/${FAMILY}/family.cmake) project(${PROJECT}) diff --git a/examples/device/dfu_runtime/CMakeLists.txt b/examples/device/dfu_runtime/CMakeLists.txt index d59d2e9a1..2bac7c329 100644 --- a/examples/device/dfu_runtime/CMakeLists.txt +++ b/examples/device/dfu_runtime/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt index a9c343994..a99b755d3 100644 --- a/examples/device/dynamic_configuration/CMakeLists.txt +++ b/examples/device/dynamic_configuration/CMakeLists.txt @@ -34,5 +34,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt index 7f85a3a40..3b677b3b1 100644 --- a/examples/device/hid_composite/CMakeLists.txt +++ b/examples/device/hid_composite/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt index d59d2e9a1..2bac7c329 100644 --- a/examples/device/hid_generic_inout/CMakeLists.txt +++ b/examples/device/hid_generic_inout/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt index d59d2e9a1..2bac7c329 100644 --- a/examples/device/hid_multiple_interface/CMakeLists.txt +++ b/examples/device/hid_multiple_interface/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt index d59d2e9a1..2bac7c329 100644 --- a/examples/device/midi_test/CMakeLists.txt +++ b/examples/device/midi_test/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt index 454c5a08a..8b4722278 100644 --- a/examples/device/msc_dual_lun/CMakeLists.txt +++ b/examples/device/msc_dual_lun/CMakeLists.txt @@ -34,5 +34,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index 76f7be6cc..4325b4ea6 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -80,5 +80,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt index d59d2e9a1..2bac7c329 100644 --- a/examples/device/uac2_headset/CMakeLists.txt +++ b/examples/device/uac2_headset/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt index f9ba2b529..c14595dbe 100644 --- a/examples/device/usbtmc/CMakeLists.txt +++ b/examples/device/usbtmc/CMakeLists.txt @@ -34,5 +34,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt index d59d2e9a1..2bac7c329 100644 --- a/examples/device/webusb_serial/CMakeLists.txt +++ b/examples/device/webusb_serial/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/host/cdc_msc_hid/CMakeLists.txt b/examples/host/cdc_msc_hid/CMakeLists.txt index 1b2be4565..a9a4f08ad 100644 --- a/examples/host/cdc_msc_hid/CMakeLists.txt +++ b/examples/host/cdc_msc_hid/CMakeLists.txt @@ -33,5 +33,5 @@ if(FAMILY STREQUAL "rp2040") ) else() - message(FATAL_ERROR "Invalid FAMILY specified") + message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() -- cgit v1.3.1 From e163f85ee024ff366253478cfd20e3fc35e96819 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 18 May 2021 12:32:20 +0700 Subject: clean up, rename some HID device symbol/API - add tud_hid_n_interface_protocol() - rename tud_hid_n_boot_mode() to tud_hid_n_get_protocol() - rename tud_hid_boot_mode_cb() to tud_hid_set_protocol_cb() - add HID_PROTOCOL_BOOT/REPORT to avoid magic number 0,1 - rename HID_PROTOCOL_NONE/KEYBOARD/MOUSE to HID_ITF_PROTOCOL_ to avoid confusion --- .../device/hid_composite/src/usb_descriptors.c | 2 +- .../hid_composite_freertos/src/usb_descriptors.c | 2 +- .../device/hid_generic_inout/src/usb_descriptors.c | 2 +- .../hid_multiple_interface/src/usb_descriptors.c | 4 +- src/class/hid/hid.h | 29 +++++++---- src/class/hid/hid_device.c | 58 ++++++++++++---------- src/class/hid/hid_device.h | 55 ++++++++++++-------- src/class/hid/hid_host.c | 4 +- 8 files changed, 92 insertions(+), 64 deletions(-) (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/hid_composite/src/usb_descriptors.c b/examples/device/hid_composite/src/usb_descriptors.c index ccc1306bd..1aff5e68e 100644 --- a/examples/device/hid_composite/src/usb_descriptors.c +++ b/examples/device/hid_composite/src/usb_descriptors.c @@ -108,7 +108,7 @@ uint8_t const desc_configuration[] = TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval - TUD_HID_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 5) + TUD_HID_DESCRIPTOR(ITF_NUM_HID, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 5) }; // Invoked when received GET CONFIGURATION DESCRIPTOR diff --git a/examples/device/hid_composite_freertos/src/usb_descriptors.c b/examples/device/hid_composite_freertos/src/usb_descriptors.c index ccc1306bd..1aff5e68e 100644 --- a/examples/device/hid_composite_freertos/src/usb_descriptors.c +++ b/examples/device/hid_composite_freertos/src/usb_descriptors.c @@ -108,7 +108,7 @@ uint8_t const desc_configuration[] = TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval - TUD_HID_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 5) + TUD_HID_DESCRIPTOR(ITF_NUM_HID, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 5) }; // Invoked when received GET CONFIGURATION DESCRIPTOR diff --git a/examples/device/hid_generic_inout/src/usb_descriptors.c b/examples/device/hid_generic_inout/src/usb_descriptors.c index db4ddd76e..5a2f5ffdc 100644 --- a/examples/device/hid_generic_inout/src/usb_descriptors.c +++ b/examples/device/hid_generic_inout/src/usb_descriptors.c @@ -104,7 +104,7 @@ uint8_t const desc_configuration[] = TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval - TUD_HID_INOUT_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, 0x80 | EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10) + TUD_HID_INOUT_DESCRIPTOR(ITF_NUM_HID, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, 0x80 | EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10) }; // Invoked when received GET CONFIGURATION DESCRIPTOR diff --git a/examples/device/hid_multiple_interface/src/usb_descriptors.c b/examples/device/hid_multiple_interface/src/usb_descriptors.c index a28e57a2b..9eef21504 100644 --- a/examples/device/hid_multiple_interface/src/usb_descriptors.c +++ b/examples/device/hid_multiple_interface/src/usb_descriptors.c @@ -119,8 +119,8 @@ uint8_t const desc_configuration[] = TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval - TUD_HID_DESCRIPTOR(ITF_NUM_HID1, 4, HID_PROTOCOL_NONE, sizeof(desc_hid_report1), EPNUM_HID1, CFG_TUD_HID_EP_BUFSIZE, 10), - TUD_HID_DESCRIPTOR(ITF_NUM_HID2, 5, HID_PROTOCOL_NONE, sizeof(desc_hid_report2), EPNUM_HID2, CFG_TUD_HID_EP_BUFSIZE, 10) + TUD_HID_DESCRIPTOR(ITF_NUM_HID1, 4, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report1), EPNUM_HID1, CFG_TUD_HID_EP_BUFSIZE, 10), + TUD_HID_DESCRIPTOR(ITF_NUM_HID2, 5, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report2), EPNUM_HID2, CFG_TUD_HID_EP_BUFSIZE, 10) }; // Invoked when received GET CONFIGURATION DESCRIPTOR diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 351a4d600..6014e54a6 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -62,15 +62,15 @@ typedef enum { HID_SUBCLASS_NONE = 0, ///< No Subclass HID_SUBCLASS_BOOT = 1 ///< Boot Interface Subclass -}hid_subclass_type_t; +}hid_subclass_enum_t; -/// HID Protocol +/// HID Interface Protocol typedef enum { - HID_PROTOCOL_NONE = 0, ///< None - HID_PROTOCOL_KEYBOARD = 1, ///< Keyboard - HID_PROTOCOL_MOUSE = 2 ///< Mouse -}hid_protocol_type_t; + HID_ITF_PROTOCOL_NONE = 0, ///< None + HID_ITF_PROTOCOL_KEYBOARD = 1, ///< Keyboard + HID_ITF_PROTOCOL_MOUSE = 2 ///< Mouse +}hid_interface_protocol_enum_t; /// HID Descriptor Type typedef enum @@ -78,7 +78,7 @@ typedef enum HID_DESC_TYPE_HID = 0x21, ///< HID Descriptor HID_DESC_TYPE_REPORT = 0x22, ///< Report Descriptor HID_DESC_TYPE_PHYSICAL = 0x23 ///< Physical Descriptor -}hid_descriptor_type_t; +}hid_descriptor_enum_t; /// HID Request Report Type typedef enum @@ -87,7 +87,7 @@ typedef enum HID_REPORT_TYPE_INPUT, ///< Input HID_REPORT_TYPE_OUTPUT, ///< Output HID_REPORT_TYPE_FEATURE ///< Feature -}hid_report_type_t; +}hid_report_enum_t; /// HID Class Specific Control Request typedef enum @@ -98,9 +98,9 @@ typedef enum HID_REQ_CONTROL_SET_REPORT = 0x09, ///< Set Report HID_REQ_CONTROL_SET_IDLE = 0x0a, ///< Set Idle HID_REQ_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol -}hid_request_type_t; +}hid_request_enum_t; -/// HID Country Code +/// HID Local Code typedef enum { HID_LOCAL_NotSupported = 0 , ///< NotSupported @@ -139,7 +139,14 @@ typedef enum HID_LOCAL_US , ///< US HID_LOCAL_Yugoslavia , ///< Yugoslavia HID_LOCAL_Turkish_F ///< Turkish-F -} hid_country_code_t; +} hid_local_enum_t; + +// HID protocol value used by GetProtocol / SetProtocol +enum +{ + HID_PROTOCOL_BOOT = 0, + HID_PROTOCOL_REPORT = 1 +}; /** @} */ diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 18d35bc20..62d63e30a 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -43,7 +43,8 @@ typedef struct uint8_t itf_num; uint8_t ep_in; uint8_t ep_out; // optional Out endpoint - uint8_t boot_protocol; // Boot mouse or keyboard + uint8_t itf_protocol; // Boot mouse or keyboard + bool boot_mode; // default = false (Report) uint8_t idle_rate; // up to application to handle idle rate uint16_t report_desc_len; @@ -51,6 +52,8 @@ typedef struct CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_HID_EP_BUFSIZE]; CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_HID_EP_BUFSIZE]; + // TODO save hid descriptor since host can specifically request this after enumeration + // Note: HID descriptor may be not available from application after enumeration tusb_hid_descriptor_hid_t const * hid_descriptor; } hidd_interface_t; @@ -70,16 +73,16 @@ static inline uint8_t get_index_by_itfnum(uint8_t itf_num) //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ -bool tud_hid_n_ready(uint8_t itf) +bool tud_hid_n_ready(uint8_t instance) { - uint8_t const ep_in = _hidd_itf[itf].ep_in; + uint8_t const ep_in = _hidd_itf[instance].ep_in; return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in); } -bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_t len) +bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, uint8_t len) { uint8_t const rhport = 0; - hidd_interface_t * p_hid = &_hidd_itf[itf]; + hidd_interface_t * p_hid = &_hidd_itf[instance]; // claim endpoint TU_VERIFY( usbd_edpt_claim(rhport, p_hid->ep_in) ); @@ -102,12 +105,17 @@ bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_ return usbd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len); } -bool tud_hid_n_boot_mode(uint8_t itf) +uint8_t tud_hid_n_interface_protocol(uint8_t instance) +{ + return _hidd_itf[instance].itf_protocol; +} + +bool tud_hid_n_get_protocol(uint8_t instance) { - return _hidd_itf[itf].boot_mode; + return _hidd_itf[instance].boot_mode; } -bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]) +bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]) { hid_keyboard_report_t report; @@ -121,10 +129,10 @@ bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, tu_memclr(report.keycode, 6); } - return tud_hid_n_report(itf, report_id, &report, sizeof(report)); + return tud_hid_n_report(instance, report_id, &report, sizeof(report)); } -bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, +bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal) { hid_mouse_report_t report = @@ -136,10 +144,10 @@ bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, .pan = horizontal }; - return tud_hid_n_report(itf, report_id, &report, sizeof(report)); + return tud_hid_n_report(instance, report_id, &report, sizeof(report)); } -bool tud_hid_n_gamepad_report(uint8_t itf, uint8_t report_id, +bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons) { hid_gamepad_report_t report = @@ -154,7 +162,7 @@ bool tud_hid_n_gamepad_report(uint8_t itf, uint8_t report_id, .buttons = buttons, }; - return tud_hid_n_report(itf, report_id, &report, sizeof(report)); + return tud_hid_n_report(instance, report_id, &report, sizeof(report)); } //--------------------------------------------------------------------+ @@ -203,7 +211,7 @@ uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint1 p_desc = tu_desc_next(p_desc); TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, desc_itf->bNumEndpoints, TUSB_XFER_INTERRUPT, &p_hid->ep_out, &p_hid->ep_in), 0); - if ( desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT ) p_hid->boot_protocol = desc_itf->bInterfaceProtocol; + 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->itf_num = desc_itf->bInterfaceNumber; @@ -318,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 ) { - // 0 is Boot, 1 is Report protocol - uint8_t protocol = (uint8_t)(1-p_hid->boot_mode); + uint8_t protocol = (p_hid->boot_mode ? HID_PROTOCOL_BOOT : HID_PROTOCOL_REPORT); tud_control_xfer(rhport, request, &protocol, 1); } break; @@ -327,15 +334,14 @@ bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t case HID_REQ_CONTROL_SET_PROTOCOL: if ( stage == CONTROL_STAGE_SETUP ) { - // 0 is Boot, 1 is Report protocol - p_hid->boot_mode = 1 - request->wValue; + p_hid->boot_mode = (request->wValue == HID_PROTOCOL_BOOT); tud_control_status(rhport, request); } else if ( stage == CONTROL_STAGE_ACK ) { - if (tud_hid_boot_mode_cb) + if (tud_hid_set_protocol_cb) { - tud_hid_boot_mode_cb(hid_itf, p_hid->boot_mode); + tud_hid_set_protocol_cb(hid_itf, p_hid->boot_mode); } } break; @@ -354,29 +360,29 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_ { (void) result; - uint8_t itf = 0; + uint8_t instance = 0; hidd_interface_t * p_hid = _hidd_itf; // Identify which interface to use - for (itf = 0; itf < CFG_TUD_HID; itf++) + for (instance = 0; instance < CFG_TUD_HID; instance++) { - p_hid = &_hidd_itf[itf]; + p_hid = &_hidd_itf[instance]; if ( (ep_addr == p_hid->ep_out) || (ep_addr == p_hid->ep_in) ) break; } - TU_ASSERT(itf < CFG_TUD_HID); + TU_ASSERT(instance < CFG_TUD_HID); // Sent report successfully if (ep_addr == p_hid->ep_in) { if (tud_hid_report_complete_cb) { - tud_hid_report_complete_cb(itf, p_hid->epin_buf, (uint8_t) xferred_bytes); + tud_hid_report_complete_cb(instance, p_hid->epin_buf, (uint8_t) xferred_bytes); } } // Received report else if (ep_addr == p_hid->ep_out) { - tud_hid_set_report_cb(itf, 0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes); + tud_hid_set_report_cb(instance, 0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes); TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf))); } diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 0c59d5d20..cc34f19ac 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -55,34 +55,39 @@ //--------------------------------------------------------------------+ // Check if the interface is ready to use -bool tud_hid_n_ready(uint8_t itf); +bool tud_hid_n_ready(uint8_t instance); -// Check if current mode is Boot (true) or Report (false) -bool tud_hid_n_boot_mode(uint8_t itf); +// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible value +uint8_t tud_hid_n_interface_protocol(uint8_t instance); + +// Check if active protocol is Boot (true) or Report (false) +bool tud_hid_n_get_protocol(uint8_t instance); // Send report to host -bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_t len); +bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, uint8_t len); // KEYBOARD: convenient helper to send keyboard report if application // use template layout report as defined by hid_keyboard_report_t -bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]); +bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]); // MOUSE: convenient helper to send mouse report if application // use template layout report as defined by hid_mouse_report_t -bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal); +bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal); // Gamepad: convenient helper to send mouse report if application // use template layout report TUD_HID_REPORT_DESC_GAMEPAD -bool tud_hid_n_gamepad_report(uint8_t itf, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons); +bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons); //--------------------------------------------------------------------+ // Application API (Single Port) //--------------------------------------------------------------------+ -static inline bool tud_hid_ready(void); -static inline bool tud_hid_boot_mode(void); -static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len); -static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]); -static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal); +static inline bool tud_hid_ready(void); +static inline uint8_t tud_hid_interface_protocol(void); +static inline bool tud_hid_get_protocol(void); +static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len); +static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]); +static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal); +static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons); //--------------------------------------------------------------------+ // Callbacks (Weak is optional) @@ -90,29 +95,29 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8 // Invoked when received GET HID REPORT DESCRIPTOR request // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete -uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf); +uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance); // Invoked when received GET_REPORT control request // Application must fill buffer report's content and return its length. // Return zero will cause the stack to STALL request -uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); +uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); // Invoked when received SET_REPORT control request or // received data on OUT endpoint ( Report ID = 0, Type = 0 ) -void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); +void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); // Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report ) -TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t itf, uint8_t boot_mode); +TU_ATTR_WEAK void tud_hid_set_protocol_cb(uint8_t instance, bool boot_mode); // Invoked when received SET_IDLE request. return false will stall the request // - Idle Rate = 0 : only send report if there is changes, i.e skip duplication // - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms). -TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t itf, uint8_t idle_rate); +TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t instance, uint8_t idle_rate); // Invoked when sent REPORT successfully to host // Application can use this to send the next report // Note: For composite reports, report[0] is report ID -TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t itf, uint8_t const* report, uint8_t len); +TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint8_t len); //--------------------------------------------------------------------+ @@ -123,9 +128,14 @@ static inline bool tud_hid_ready(void) return tud_hid_n_ready(0); } -static inline bool tud_hid_boot_mode(void) +static inline uint8_t tud_hid_interface_protocol(void) +{ + return tud_hid_n_interface_protocol(0); +} + +static inline bool tud_hid_get_protocol(void) { - return tud_hid_n_boot_mode(0); + return tud_hid_n_get_protocol(0); } static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len) @@ -143,6 +153,11 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8 return tud_hid_n_mouse_report(0, report_id, buttons, x, y, vertical, horizontal); } +static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons) +{ + return tud_hid_n_gamepad_report(0, x, y, z, rz, rx, ry, hat, buttons); +} + /* --------------------------------------------------------------------+ * HID Report Descriptor Template * diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 64d1b8e5d..28440b1b4 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -178,7 +178,7 @@ bool hidh_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t c if ( HID_SUBCLASS_BOOT == p_interface_desc->bInterfaceSubClass ) { #if CFG_TUH_HID_KEYBOARD - if ( HID_PROTOCOL_KEYBOARD == p_interface_desc->bInterfaceProtocol) + if ( HID_ITF_PROTOCOL_KEYBOARD == p_interface_desc->bInterfaceProtocol) { TU_ASSERT( hidh_interface_open(rhport, dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboardh_data[dev_addr-1]) ); TU_LOG2_HEX(keyboardh_data[dev_addr-1].ep_in); @@ -186,7 +186,7 @@ bool hidh_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t c #endif #if CFG_TUH_HID_MOUSE - if ( HID_PROTOCOL_MOUSE == p_interface_desc->bInterfaceProtocol) + if ( HID_ITF_PROTOCOL_MOUSE == p_interface_desc->bInterfaceProtocol) { TU_ASSERT ( hidh_interface_open(rhport, dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouseh_data[dev_addr-1]) ); TU_LOG2_HEX(mouseh_data[dev_addr-1].ep_in); -- cgit v1.3.1 From 95f2478146ef83d18b52408c0692222bf2a15053 Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Sun, 30 May 2021 18:41:07 -0500 Subject: Rework rp2040 examples and CMake build: - Examples should be CMake buildable from their own subdirectory; such a build will error out based on matching .skip.MCU_xxx or a mismatched .only.MCU_ - It should be possible to build from a higher level and use .skip.MCU_ and .only.MCU_ to filter which examples get built - The intention is for the CMakeLists.txts in the examples to be non family specific and without MCU based IFs. I have started this work, but am not really sure the state of the esp32 stuff; in any case the plan is to have everything encapsulated in the FAMILY/family.cmake - pico_examples now just includes examples/device/CMakeLists.txt and examples/host/CMakeLists.txt directly, as they also build correctly when included from there. Note that .skip.MCU_ for esp32 in the directories it wasn't previously avaiable has not been added, as the .skip is common to the regular Makefile builds also. It isn't clear whether these examples should build for esp32, but if not .skip should be added. --- examples/device/CMakeLists.txt | 27 ++++ examples/device/audio_4_channel_mic/CMakeLists.txt | 65 ++++----- examples/device/audio_test/CMakeLists.txt | 65 ++++----- examples/device/board_test/CMakeLists.txt | 47 ++++--- examples/device/cdc_dual_ports/CMakeLists.txt | 65 ++++----- examples/device/cdc_msc/CMakeLists.txt | 67 ++++------ examples/device/dfu/CMakeLists.txt | 65 ++++----- examples/device/dfu_runtime/CMakeLists.txt | 65 ++++----- .../device/dynamic_configuration/CMakeLists.txt | 67 ++++------ examples/device/hid_composite/CMakeLists.txt | 65 ++++----- examples/device/hid_generic_inout/CMakeLists.txt | 65 ++++----- .../device/hid_multiple_interface/CMakeLists.txt | 65 ++++----- examples/device/midi_test/CMakeLists.txt | 65 ++++----- examples/device/msc_dual_lun/CMakeLists.txt | 67 ++++------ examples/device/net_lwip_webserver/CMakeLists.txt | 146 ++++++++++----------- examples/device/uac2_headset/CMakeLists.txt | 65 ++++----- examples/device/usbtmc/CMakeLists.txt | 67 ++++------ examples/device/webusb_serial/CMakeLists.txt | 65 ++++----- examples/host/CMakeLists.txt | 9 ++ examples/host/cdc_msc_hid/CMakeLists.txt | 67 ++++------ hw/bsp/esp32s2/family.cmake | 4 + hw/bsp/esp32s3/family.cmake | 4 + hw/bsp/family.cmake | 61 +++++++++ hw/bsp/rp2040/board.h | 53 ++++++++ .../boards/adafruit_feather_rp2040/board.cmake | 1 - .../rp2040/boards/adafruit_feather_rp2040/board.h | 53 -------- .../boards/adafruit_itsybitsy_rp2040/board.cmake | 1 - .../boards/adafruit_itsybitsy_rp2040/board.h | 53 -------- .../rp2040/boards/adafruit_qt_rp2040/board.cmake | 1 - hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h | 55 -------- hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake | 1 - hw/bsp/rp2040/boards/raspberry_pi_pico/board.h | 49 ------- hw/bsp/rp2040/family.c | 15 ++- hw/bsp/rp2040/family.cmake | 122 ++++++++--------- hw/mcu/microchip | 2 +- hw/mcu/sony/cxd56/spresense-exported-sdk | 2 +- lib/lwip | 2 +- 37 files changed, 776 insertions(+), 982 deletions(-) create mode 100644 examples/device/CMakeLists.txt create mode 100644 examples/host/CMakeLists.txt create mode 100644 hw/bsp/family.cmake create mode 100644 hw/bsp/rp2040/board.h delete mode 100644 hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake delete mode 100644 hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h delete mode 100644 hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake delete mode 100644 hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h delete mode 100644 hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake delete mode 100644 hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h delete mode 100644 hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake delete mode 100644 hw/bsp/rp2040/boards/raspberry_pi_pico/board.h (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/CMakeLists.txt b/examples/device/CMakeLists.txt new file mode 100644 index 000000000..4ed693cde --- /dev/null +++ b/examples/device/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/${FAMILY}/family.cmake) + +project(tinyusb_device_examples) +family_initialize_project(tinyusb_device_examples ${CMAKE_CURRENT_LIST_DIR}) + +# family_add_subdirectory will filter what to actually add based on selected FAMILY +family_add_subdirectory(audio_4_channel_mic) +family_add_subdirectory(audio_test) +family_add_subdirectory(board_test) +family_add_subdirectory(cdc_dual_ports) +family_add_subdirectory(cdc_msc) +family_add_subdirectory(cdc_msc_freertos) +family_add_subdirectory(dfu) +family_add_subdirectory(dfu_runtime) +family_add_subdirectory(dynamic_configuration) +family_add_subdirectory(hid_composite) +family_add_subdirectory(hid_composite_freertos) +family_add_subdirectory(hid_generic_inout) +family_add_subdirectory(hid_multiple_interface) +family_add_subdirectory(midi_test) +family_add_subdirectory(msc_dual_lun) +family_add_subdirectory(net_lwip_webserver) +family_add_subdirectory(uac2_headset) +family_add_subdirectory(usbtmc) +family_add_subdirectory(webusb_serial) diff --git a/examples/device/audio_4_channel_mic/CMakeLists.txt b/examples/device/audio_4_channel_mic/CMakeLists.txt index f2c81c4d3..b653fc91f 100644 --- a/examples/device/audio_4_channel_mic/CMakeLists.txt +++ b/examples/device/audio_4_channel_mic/CMakeLists.txt @@ -1,37 +1,28 @@ -# use BOARD-Directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c +) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt index f2c81c4d3..fac0ca64f 100644 --- a/examples/device/audio_test/CMakeLists.txt +++ b/examples/device/audio_test/CMakeLists.txt @@ -1,37 +1,28 @@ -# use BOARD-Directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c +) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index c41ad92ab..5bb8cb700 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -1,44 +1,41 @@ cmake_minimum_required(VERSION 3.5) -# use BOARD-Directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) # Check for -DFAMILY= if(FAMILY MATCHES "^esp32s[2-3]") - cmake_minimum_required(VERSION 3.5) + # use BOARD-Directory name for project id + get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) + set(PROJECT ${BOARD}-${PROJECT}) + + # TOP is absolute path to root directory of TinyUSB git repo + set(TOP "../../..") + get_filename_component(TOP "${TOP}" REALPATH) include(${TOP}/hw/bsp/${FAMILY}/family.cmake) project(${PROJECT}) -elseif(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) +else() + + # Family chooses name based on passed name and vars (e.g. -) + get_filename_component(DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) + family_get_project_name(PROJECT "${DIR_NAME}") + project(${PROJECT}) - add_executable(${PROJECT}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ) + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ) # Example include target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") + # Configure compilation flags and libraries for the example... see the corresponding function + # in hw/bsp/FAMILY/family.cmake for details. + family_configure_device_example(${PROJECT}) endif() diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt index 4160c0c88..18367a893 100644 --- a/examples/device/cdc_dual_ports/CMakeLists.txt +++ b/examples/device/cdc_dual_ports/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index 6c828a396..5da761a04 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -1,38 +1,29 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/dfu/CMakeLists.txt b/examples/device/dfu/CMakeLists.txt index 4160c0c88..18367a893 100644 --- a/examples/device/dfu/CMakeLists.txt +++ b/examples/device/dfu/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/dfu_runtime/CMakeLists.txt b/examples/device/dfu_runtime/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/dfu_runtime/CMakeLists.txt +++ b/examples/device/dfu_runtime/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt index a99b755d3..5da761a04 100644 --- a/examples/device/dynamic_configuration/CMakeLists.txt +++ b/examples/device/dynamic_configuration/CMakeLists.txt @@ -1,38 +1,29 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt index 3b677b3b1..18367a893 100644 --- a/examples/device/hid_composite/CMakeLists.txt +++ b/examples/device/hid_composite/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/hid_generic_inout/CMakeLists.txt +++ b/examples/device/hid_generic_inout/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/hid_multiple_interface/CMakeLists.txt +++ b/examples/device/hid_multiple_interface/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/midi_test/CMakeLists.txt +++ b/examples/device/midi_test/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt index 8b4722278..f60be8eda 100644 --- a/examples/device/msc_dual_lun/CMakeLists.txt +++ b/examples/device/msc_dual_lun/CMakeLists.txt @@ -1,38 +1,29 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index 4325b4ea6..63cca04a8 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -1,84 +1,82 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +cmake_minimum_required(VERSION 3.5) -# TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") get_filename_component(TOP "${TOP}" REALPATH) -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) +include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) - # lwip Stack source - set(SRC_LWIP - ${TOP}/lib/lwip/src/core/altcp.c - ${TOP}/lib/lwip/src/core/altcp_alloc.c - ${TOP}/lib/lwip/src/core/altcp_tcp.c - ${TOP}/lib/lwip/src/core/def.c - ${TOP}/lib/lwip/src/core/dns.c - ${TOP}/lib/lwip/src/core/inet_chksum.c - ${TOP}/lib/lwip/src/core/init.c - ${TOP}/lib/lwip/src/core/ip.c - ${TOP}/lib/lwip/src/core/mem.c - ${TOP}/lib/lwip/src/core/memp.c - ${TOP}/lib/lwip/src/core/netif.c - ${TOP}/lib/lwip/src/core/pbuf.c - ${TOP}/lib/lwip/src/core/raw.c - ${TOP}/lib/lwip/src/core/stats.c - ${TOP}/lib/lwip/src/core/sys.c - ${TOP}/lib/lwip/src/core/tcp.c - ${TOP}/lib/lwip/src/core/tcp_in.c - ${TOP}/lib/lwip/src/core/tcp_out.c - ${TOP}/lib/lwip/src/core/timeouts.c - ${TOP}/lib/lwip/src/core/udp.c - ${TOP}/lib/lwip/src/core/ipv4/autoip.c - ${TOP}/lib/lwip/src/core/ipv4/dhcp.c - ${TOP}/lib/lwip/src/core/ipv4/etharp.c - ${TOP}/lib/lwip/src/core/ipv4/icmp.c - ${TOP}/lib/lwip/src/core/ipv4/igmp.c - ${TOP}/lib/lwip/src/core/ipv4/ip4.c - ${TOP}/lib/lwip/src/core/ipv4/ip4_addr.c - ${TOP}/lib/lwip/src/core/ipv4/ip4_frag.c - ${TOP}/lib/lwip/src/netif/ethernet.c - ${TOP}/lib/lwip/src/netif/slipif.c - ${TOP}/lib/lwip/src/apps/http/httpd.c - ${TOP}/lib/lwip/src/apps/http/fs.c - ${TOP}/lib/networking/dhserver.c - ${TOP}/lib/networking/dnserver.c - ${TOP}/lib/networking/rndis_reports.c - ) +project(${PROJECT}) - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ${SRC_LWIP} - ) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${TOP}/lib/lwip/src/include + ${TOP}/lib/lwip/src/include/ipv4 + ${TOP}/lib/lwip/src/include/lwip/apps + ${TOP}/lib/networking + ) + +target_sources(${PROJECT} PUBLIC + ${TOP}/lib/lwip/src/core/altcp.c + ${TOP}/lib/lwip/src/core/altcp_alloc.c + ${TOP}/lib/lwip/src/core/altcp_tcp.c + ${TOP}/lib/lwip/src/core/def.c + ${TOP}/lib/lwip/src/core/dns.c + ${TOP}/lib/lwip/src/core/inet_chksum.c + ${TOP}/lib/lwip/src/core/init.c + ${TOP}/lib/lwip/src/core/ip.c + ${TOP}/lib/lwip/src/core/mem.c + ${TOP}/lib/lwip/src/core/memp.c + ${TOP}/lib/lwip/src/core/netif.c + ${TOP}/lib/lwip/src/core/pbuf.c + ${TOP}/lib/lwip/src/core/raw.c + ${TOP}/lib/lwip/src/core/stats.c + ${TOP}/lib/lwip/src/core/sys.c + ${TOP}/lib/lwip/src/core/tcp.c + ${TOP}/lib/lwip/src/core/tcp_in.c + ${TOP}/lib/lwip/src/core/tcp_out.c + ${TOP}/lib/lwip/src/core/timeouts.c + ${TOP}/lib/lwip/src/core/udp.c + ${TOP}/lib/lwip/src/core/ipv4/autoip.c + ${TOP}/lib/lwip/src/core/ipv4/dhcp.c + ${TOP}/lib/lwip/src/core/ipv4/etharp.c + ${TOP}/lib/lwip/src/core/ipv4/icmp.c + ${TOP}/lib/lwip/src/core/ipv4/igmp.c + ${TOP}/lib/lwip/src/core/ipv4/ip4.c + ${TOP}/lib/lwip/src/core/ipv4/ip4_addr.c + ${TOP}/lib/lwip/src/core/ipv4/ip4_frag.c + ${TOP}/lib/lwip/src/netif/ethernet.c + ${TOP}/lib/lwip/src/netif/slipif.c + ${TOP}/lib/lwip/src/apps/http/httpd.c + ${TOP}/lib/lwip/src/apps/http/fs.c + ${TOP}/lib/networking/dhserver.c + ${TOP}/lib/networking/dnserver.c + ${TOP}/lib/networking/rndis_reports.c + ) + +target_compile_definitions(${PROJECT} PUBLIC + PBUF_POOL_SIZE=2 + TCP_WND=2*TCP_MSS + HTTPD_USE_CUSTOM_FSDATA=0 +) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ${TOP}/lib/lwip/src/include - ${TOP}/lib/lwip/src/include/ipv4 - ${TOP}/lib/lwip/src/include/lwip/apps - ${TOP}/lib/networking - ) - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - PBUF_POOL_SIZE=2 - TCP_WND=2*TCP_MSS - HTTPD_USE_CUSTOM_FSDATA=0 - ) -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/uac2_headset/CMakeLists.txt +++ b/examples/device/uac2_headset/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt index c14595dbe..4306da8cb 100644 --- a/examples/device/usbtmc/CMakeLists.txt +++ b/examples/device/usbtmc/CMakeLists.txt @@ -1,38 +1,29 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usbtmc_app.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usbtmc_app.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt index 2bac7c329..18367a893 100644 --- a/examples/device/webusb_serial/CMakeLists.txt +++ b/examples/device/webusb_serial/CMakeLists.txt @@ -1,37 +1,28 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_device_example(${PROJECT}) \ No newline at end of file diff --git a/examples/host/CMakeLists.txt b/examples/host/CMakeLists.txt new file mode 100644 index 000000000..c70d11d5b --- /dev/null +++ b/examples/host/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/${FAMILY}/family.cmake) + +project(tinyusb_host_examples) +family_initialize_project(tinyusb_host_examples ${CMAKE_CURRENT_LIST_DIR}) + +# family_add_subdirectory will filter what to actually add based on selected FAMILY +family_add_subdirectory(cdc_msc_hid) diff --git a/examples/host/cdc_msc_hid/CMakeLists.txt b/examples/host/cdc_msc_hid/CMakeLists.txt index ac57bf6dd..ad0f412e2 100644 --- a/examples/host/cdc_msc_hid/CMakeLists.txt +++ b/examples/host/cdc_msc_hid/CMakeLists.txt @@ -1,38 +1,29 @@ -# use directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) - -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) - -# Check for -DFAMILY= -if(FAMILY STREQUAL "rp2040") - cmake_minimum_required(VERSION 3.12) - - include(${TOP}/hw/bsp/${FAMILY}/pico_sdk_import.cmake) - project(${PROJECT}) - add_executable(${PROJECT}) - - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - - # Example source - target_sources(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c - ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c - ) - - # Example include - target_include_directories(${PROJECT} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/src - ) - - # Example defines - target_compile_definitions(${PROJECT} PUBLIC - CFG_TUSB_OS=OPT_OS_PICO - ) - -else() - message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") -endif() +cmake_minimum_required(VERSION 3.5) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT}) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c + ) + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ) + +# Configure compilation flags and libraries for the example... see the corresponding function +# in hw/bsp/FAMILY/family.cmake for details. +family_configure_host_example(${PROJECT}) \ No newline at end of file diff --git a/hw/bsp/esp32s2/family.cmake b/hw/bsp/esp32s2/family.cmake index c19221b14..656f7d852 100644 --- a/hw/bsp/esp32s2/family.cmake +++ b/hw/bsp/esp32s2/family.cmake @@ -4,3 +4,7 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s2/boards" "${TOP}/hw/bsp/esp32s2/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(SUPPORTED_TARGETS esp32s2) + +# include basic family CMake functionality +set(FAMILY_MCUS esp32s2 ESP32S2) +include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) diff --git a/hw/bsp/esp32s3/family.cmake b/hw/bsp/esp32s3/family.cmake index 558ec5752..e57920bf7 100644 --- a/hw/bsp/esp32s3/family.cmake +++ b/hw/bsp/esp32s3/family.cmake @@ -4,3 +4,7 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s3/boards" "${TOP}/hw/bsp/esp32s3/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(SUPPORTED_TARGETS esp32s3) + +# include basic family CMake functionality +set(FAMILY_MCUS esp32s3 ESP32S3) # TODO MERGE THIS WITH supported targets? +include(${CMAKE_CURRENT_LIST_DIR}/../family.cmake) diff --git a/hw/bsp/family.cmake b/hw/bsp/family.cmake new file mode 100644 index 000000000..124399675 --- /dev/null +++ b/hw/bsp/family.cmake @@ -0,0 +1,61 @@ +if (NOT FAMILY_MCUS) + set(FAMILY_MCUS ${FAMILY}) +endif() + +# save it in case of re-inclusion +set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "") + +function(family_filter RESULT DIR) + get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + file(GLOB ONLYS "${DIR}/.only.MCU_*") + if (ONLYS) + foreach(MCU IN LISTS FAMILY_MCUS) + if (EXISTS ${DIR}/.only.MCU_${MCU}) + set(${RESULT} 1 PARENT_SCOPE) + return() + endif() + endforeach() + else() + foreach(MCU IN LISTS FAMILY_MCUS) + if (EXISTS ${DIR}/.skip.MCU_${MCU}) + set(${RESULT} 0 PARENT_SCOPE) + return() + endif() + endforeach() + endif() + set(${RESULT} 1 PARENT_SCOPE) +endfunction() + +function(family_add_subdirectory DIR) + family_filter(SHOULD_ADD "${DIR}") + if (SHOULD_ADD) + add_subdirectory(${DIR}) + endif() +endfunction() + +function(family_get_project_name OUTPUT_NAME DIR) + get_filename_component(SHORT_NAME ${DIR} NAME) + if (TINYUSB_FAMILY_PROJECT_NAME_INCLUDES_BOARD OR NOT DEFINED TINYUSB_FAMILY_PROJECT_NAME_INCLUDES_BOARD) + set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${BOARD}-${SHORT_NAME} PARENT_SCOPE) + else() + set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) + endif() +endfunction() + +function(family_initialize_project PROJECT DIR) + family_filter(ALLOWED "${DIR}") + if (NOT ALLOWED) + get_filename_component(SHORT_NAME ${DIR} NAME) + message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}") + endif() +endfunction() + +# configure an executable target to link to tinyusb in device mode, and add the board implementation +function(family_configure_device_example TARGET) + # default implentation is empty, the function should be redefined in the FAMILY/family.cmake +endfunction() + +# configure an executable target to link to tinyusb in host mode, and add the board implementation +function(family_configure_host_example TARGET) + # default implentation is empty, the function should be redefined in the FAMILY/family.cmake +endfunction() diff --git a/hw/bsp/rp2040/board.h b/hw/bsp/rp2040/board.h new file mode 100644 index 000000000..237f29dc2 --- /dev/null +++ b/hw/bsp/rp2040/board.h @@ -0,0 +1,53 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021, 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 BOARD_H_ +#define BOARD_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#ifdef PICO_DEFAULT_LED_PIN +#define LED_PIN PICO_DEFAULT_LED_PIN +#define LED_STATE_ON (!(PICO_DEFAULT_LED_PIN_INVERTED)) +#endif + +// Button pin is BOOTSEL which is flash CS pin +#define BUTTON_BOOTSEL +#define BUTTON_STATE_ACTIVE 0 + +#if defined(PICO_DEFAULT_UART_TX_PIN) && defined(PICO_DEFAULT_UART_RX_PIN) && defined(PICO_DEFAULT_UART) +#define UART_DEV PICO_DEFAULT_UART +#define UART_TX_PIN PICO_DEFAULT_UART_TX_PIN +#define UART_RX_PIN PICO_DEFAULT_UART_RX_PIN +#endif + +#ifdef __cplusplus + } +#endif + +#endif /* BOARD_H_ */ diff --git a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake deleted file mode 100644 index ea4070cf3..000000000 --- a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_generic_03h.S") diff --git a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h deleted file mode 100644 index 281b215d3..000000000 --- a/hw/bsp/rp2040/boards/adafruit_feather_rp2040/board.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021, 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 BOARD_H_ -#define BOARD_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -#define LED_PIN 13 -#define LED_STATE_ON 1 - -#define NEOPIXEL_PIN 16 -#define NEOPIXEL_POWER_PIN 17 -#define NEOPIXEL_POWER_STATE 1 - -// Button pin is BOOTSEL which is flash CS pin -#define BUTTON_BOOTSEL -#define BUTTON_STATE_ACTIVE 0 - -#define UART_DEV uart0 -#define UART_TX_PIN 0 -#define UART_RX_PIN 1 - -#ifdef __cplusplus - } -#endif - -#endif /* BOARD_H_ */ diff --git a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake deleted file mode 100644 index eb9f219d2..000000000 --- a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_w25q080.S") diff --git a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h deleted file mode 100644 index 72265176c..000000000 --- a/hw/bsp/rp2040/boards/adafruit_itsybitsy_rp2040/board.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021, 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 BOARD_H_ -#define BOARD_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -#define LED_PIN 11 -#define LED_STATE_ON 1 - -#define NEOPIXEL_PIN 17 -#define NEOPIXEL_POWER_PIN 16 -#define NEOPIXEL_POWER_STATE 1 - -// Button pin is BOOTSEL which is flash CS pin -#define BUTTON_BOOTSEL -#define BUTTON_STATE_ACTIVE 0 - -#define UART_DEV uart0 -#define UART_TX_PIN 0 -#define UART_RX_PIN 1 - -#ifdef __cplusplus - } -#endif - -#endif /* BOARD_H_ */ diff --git a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake b/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake deleted file mode 100644 index eb9f219d2..000000000 --- a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_w25q080.S") diff --git a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h b/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h deleted file mode 100644 index c0915f704..000000000 --- a/hw/bsp/rp2040/boards/adafruit_qt_rp2040/board.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021, 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 BOARD_H_ -#define BOARD_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -// TODO QT RP2040 only has neopixel -#define LED_PIN 11 -#define LED_STATE_ON 1 - -#define NEOPIXEL_PIN 12 -#define NEOPIXEL_POWER_PIN 11 -#define NEOPIXEL_POWER_STATE 1 - -// Button pin is BOOTSEL which is flash CS pin -#define BUTTON_BOOTSEL -#define BUTTON_STATE_ACTIVE 0 - - -#define UART_DEV uart0 -#define UART_TX_PIN 0 -#define UART_RX_PIN 1 - -#ifdef __cplusplus - } -#endif - -#endif /* BOARD_H_ */ diff --git a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake deleted file mode 100644 index eb9f219d2..000000000 --- a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2_common/boot_stage2/boot2_w25q080.S") diff --git a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h b/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h deleted file mode 100644 index e4a6514ad..000000000 --- a/hw/bsp/rp2040/boards/raspberry_pi_pico/board.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021, 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 BOARD_H_ -#define BOARD_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -#define LED_PIN PICO_DEFAULT_LED_PIN -#define LED_STATE_ON 1 - -// Button pin is BOOTSEL which is flash CS pin -#define BUTTON_BOOTSEL -#define BUTTON_STATE_ACTIVE 0 - -#define UART_DEV uart0 -#define UART_TX_PIN 0 -#define UART_RX_PIN 1 - -#ifdef __cplusplus - } -#endif - -#endif /* BOARD_H_ */ diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c index 9995c23d7..b2dbd3e6a 100644 --- a/hw/bsp/rp2040/family.c +++ b/hw/bsp/rp2040/family.c @@ -26,6 +26,7 @@ */ #include "pico/stdlib.h" +#include "pico/binary_info.h" #include "hardware/gpio.h" #include "hardware/sync.h" #include "hardware/structs/ioqspi.h" @@ -110,10 +111,14 @@ void stdio_rtt_init(void) #endif +#ifdef UART_DEV +static uart_inst_t *uart_inst; +#endif void board_init(void) { #ifdef LED_PIN + bi_decl(bi_1pin_with_name(LED_PIN, "LED")); gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT); #endif @@ -123,7 +128,9 @@ void board_init(void) #endif #ifdef UART_DEV - stdio_uart_init_full(UART_DEV, CFG_BOARD_UART_BAUDRATE, UART_TX_PIN, UART_RX_PIN); + bi_decl(bi_2pins_with_func(UART_TX_PIN, UART_TX_PIN, GPIO_FUNC_UART)); + uart_inst = uart_get_instance(UART_DEV); + stdio_uart_init_full(uart_inst, CFG_BOARD_UART_BAUDRATE, UART_TX_PIN, UART_RX_PIN); #endif #if defined(LOGGER_RTT) @@ -164,7 +171,7 @@ int board_uart_read(uint8_t* buf, int len) { #ifdef UART_DEV for(int i=0;i Date: Thu, 10 Jun 2021 10:11:20 -0500 Subject: Make examples standalone buildable via CMake --- examples/device/CMakeLists.txt | 2 +- examples/device/audio_4_channel_mic/CMakeLists.txt | 2 +- examples/device/audio_test/CMakeLists.txt | 2 +- examples/device/board_test/CMakeLists.txt | 3 +- examples/device/cdc_dual_ports/CMakeLists.txt | 2 +- examples/device/cdc_msc/CMakeLists.txt | 2 +- examples/device/cdc_msc_freertos/CMakeLists.txt | 19 +++--- examples/device/dfu/CMakeLists.txt | 2 +- examples/device/dfu_runtime/CMakeLists.txt | 2 +- .../device/dynamic_configuration/CMakeLists.txt | 2 +- examples/device/hid_composite/CMakeLists.txt | 2 +- examples/device/hid_generic_inout/CMakeLists.txt | 2 +- .../device/hid_multiple_interface/CMakeLists.txt | 2 +- examples/device/midi_test/CMakeLists.txt | 2 +- examples/device/msc_dual_lun/CMakeLists.txt | 2 +- examples/device/net_lwip_webserver/CMakeLists.txt | 2 +- examples/device/uac2_headset/CMakeLists.txt | 2 +- examples/device/usbtmc/CMakeLists.txt | 2 +- examples/device/webusb_serial/CMakeLists.txt | 2 +- examples/host/CMakeLists.txt | 2 +- examples/host/cdc_msc_hid/CMakeLists.txt | 2 +- hw/bsp/esp32s2/family.cmake | 3 - hw/bsp/esp32s3/family.cmake | 3 - hw/bsp/family_common.cmake | 57 ----------------- hw/bsp/family_support.cmake | 71 ++++++++++++++++++++++ hw/bsp/rp2040/family.cmake | 4 +- 26 files changed, 101 insertions(+), 97 deletions(-) delete mode 100644 hw/bsp/family_common.cmake create mode 100644 hw/bsp/family_support.cmake (limited to 'examples/device/hid_multiple_interface') diff --git a/examples/device/CMakeLists.txt b/examples/device/CMakeLists.txt index 4ed693cde..a0e4600f6 100644 --- a/examples/device/CMakeLists.txt +++ b/examples/device/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/family_support.cmake) project(tinyusb_device_examples) family_initialize_project(tinyusb_device_examples ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/audio_4_channel_mic/CMakeLists.txt b/examples/device/audio_4_channel_mic/CMakeLists.txt index b653fc91f..f6e10e2ea 100644 --- a/examples/device/audio_4_channel_mic/CMakeLists.txt +++ b/examples/device/audio_4_channel_mic/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt index fac0ca64f..cb321f9a8 100644 --- a/examples/device/audio_test/CMakeLists.txt +++ b/examples/device/audio_test/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index 8cd5b9ea4..37113578e 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # Check for -DFAMILY= if(FAMILY MATCHES "^esp32s[2-3]") @@ -12,7 +12,6 @@ if(FAMILY MATCHES "^esp32s[2-3]") set(TOP "../../..") get_filename_component(TOP "${TOP}" REALPATH) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) project(${PROJECT}) else() diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt index 18367a893..abc4d91da 100644 --- a/examples/device/cdc_dual_ports/CMakeLists.txt +++ b/examples/device/cdc_dual_ports/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt index 5da761a04..fa6e83b7e 100644 --- a/examples/device/cdc_msc/CMakeLists.txt +++ b/examples/device/cdc_msc/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/cdc_msc_freertos/CMakeLists.txt b/examples/device/cdc_msc_freertos/CMakeLists.txt index 1d04a8518..11f1c6135 100644 --- a/examples/device/cdc_msc_freertos/CMakeLists.txt +++ b/examples/device/cdc_msc_freertos/CMakeLists.txt @@ -1,20 +1,17 @@ cmake_minimum_required(VERSION 3.5) -# use BOARD-Directory name for project id -get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME) -set(PROJECT ${BOARD}-${PROJECT}) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) -# TOP is absolute path to root directory of TinyUSB git repo -set(TOP "../../..") -get_filename_component(TOP "${TOP}" REALPATH) +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) -# Check for -DFAMILY= -if(FAMILY MATCHES "^esp32s[2-3]") - cmake_minimum_required(VERSION 3.5) +project(${PROJECT}) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) - project(${PROJECT}) +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) +# Check for -DFAMILY= +if(FAMILY MATCHES "^esp32s[2-3]") else() message(FATAL_ERROR "Invalid FAMILY specified: ${FAMILY}") endif() diff --git a/examples/device/dfu/CMakeLists.txt b/examples/device/dfu/CMakeLists.txt index 18367a893..abc4d91da 100644 --- a/examples/device/dfu/CMakeLists.txt +++ b/examples/device/dfu/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/dfu_runtime/CMakeLists.txt b/examples/device/dfu_runtime/CMakeLists.txt index 18367a893..abc4d91da 100644 --- a/examples/device/dfu_runtime/CMakeLists.txt +++ b/examples/device/dfu_runtime/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt index 5da761a04..fa6e83b7e 100644 --- a/examples/device/dynamic_configuration/CMakeLists.txt +++ b/examples/device/dynamic_configuration/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt index 18367a893..abc4d91da 100644 --- a/examples/device/hid_composite/CMakeLists.txt +++ b/examples/device/hid_composite/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt index 18367a893..abc4d91da 100644 --- a/examples/device/hid_generic_inout/CMakeLists.txt +++ b/examples/device/hid_generic_inout/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt index 18367a893..abc4d91da 100644 --- a/examples/device/hid_multiple_interface/CMakeLists.txt +++ b/examples/device/hid_multiple_interface/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt index 18367a893..abc4d91da 100644 --- a/examples/device/midi_test/CMakeLists.txt +++ b/examples/device/midi_test/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt index f60be8eda..9e834ae21 100644 --- a/examples/device/msc_dual_lun/CMakeLists.txt +++ b/examples/device/msc_dual_lun/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt index f1f79b2d1..7500f6e9e 100644 --- a/examples/device/net_lwip_webserver/CMakeLists.txt +++ b/examples/device/net_lwip_webserver/CMakeLists.txt @@ -4,7 +4,7 @@ set(TOP "../../..") get_filename_component(TOP "${TOP}" REALPATH) if (EXISTS ${TOP}/lib/lwip/src) - include(${TOP}/hw/bsp/${FAMILY}/family.cmake) + include(${TOP}/hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt index 18367a893..abc4d91da 100644 --- a/examples/device/uac2_headset/CMakeLists.txt +++ b/examples/device/uac2_headset/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt index 4306da8cb..c49603c26 100644 --- a/examples/device/usbtmc/CMakeLists.txt +++ b/examples/device/usbtmc/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt index 18367a893..abc4d91da 100644 --- a/examples/device/webusb_serial/CMakeLists.txt +++ b/examples/device/webusb_serial/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/host/CMakeLists.txt b/examples/host/CMakeLists.txt index c70d11d5b..f185ac4f8 100644 --- a/examples/host/CMakeLists.txt +++ b/examples/host/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../hw/bsp/family_support.cmake) project(tinyusb_host_examples) family_initialize_project(tinyusb_host_examples ${CMAKE_CURRENT_LIST_DIR}) diff --git a/examples/host/cdc_msc_hid/CMakeLists.txt b/examples/host/cdc_msc_hid/CMakeLists.txt index ad0f412e2..0a99bc3a9 100644 --- a/examples/host/cdc_msc_hid/CMakeLists.txt +++ b/examples/host/cdc_msc_hid/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/${FAMILY}/family.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) diff --git a/hw/bsp/esp32s2/family.cmake b/hw/bsp/esp32s2/family.cmake index 9eb1627a1..f3d41d041 100644 --- a/hw/bsp/esp32s2/family.cmake +++ b/hw/bsp/esp32s2/family.cmake @@ -4,7 +4,4 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s2/boards" "${TOP}/hw/bsp/esp32s2/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(SUPPORTED_TARGETS esp32s2) - -# include basic family CMake functionality set(FAMILY_MCUS ESP32S2) -include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) diff --git a/hw/bsp/esp32s3/family.cmake b/hw/bsp/esp32s3/family.cmake index c99c3728b..511dd58bb 100644 --- a/hw/bsp/esp32s3/family.cmake +++ b/hw/bsp/esp32s3/family.cmake @@ -4,7 +4,4 @@ cmake_minimum_required(VERSION 3.5) set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s3/boards" "${TOP}/hw/bsp/esp32s3/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) set(SUPPORTED_TARGETS esp32s3) - -# include basic family CMake functionality set(FAMILY_MCUS ESP32S3) -include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) diff --git a/hw/bsp/family_common.cmake b/hw/bsp/family_common.cmake deleted file mode 100644 index 2544c58c6..000000000 --- a/hw/bsp/family_common.cmake +++ /dev/null @@ -1,57 +0,0 @@ -if (NOT FAMILY_MCUS) - set(FAMILY_MCUS ${FAMILY}) -endif() - -# save it in case of re-inclusion -set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "") - -function(family_filter RESULT DIR) - get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) - file(GLOB ONLYS "${DIR}/.only.MCU_*") - if (ONLYS) - foreach(MCU IN LISTS FAMILY_MCUS) - if (EXISTS ${DIR}/.only.MCU_${MCU}) - set(${RESULT} 1 PARENT_SCOPE) - return() - endif() - endforeach() - else() - foreach(MCU IN LISTS FAMILY_MCUS) - if (EXISTS ${DIR}/.skip.MCU_${MCU}) - set(${RESULT} 0 PARENT_SCOPE) - return() - endif() - endforeach() - endif() - set(${RESULT} 1 PARENT_SCOPE) -endfunction() - -function(family_add_subdirectory DIR) - family_filter(SHOULD_ADD "${DIR}") - if (SHOULD_ADD) - add_subdirectory(${DIR}) - endif() -endfunction() - -function(family_get_project_name OUTPUT_NAME DIR) - get_filename_component(SHORT_NAME ${DIR} NAME) - set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) -endfunction() - -function(family_initialize_project PROJECT DIR) - family_filter(ALLOWED "${DIR}") - if (NOT ALLOWED) - get_filename_component(SHORT_NAME ${DIR} NAME) - message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}") - endif() -endfunction() - -# configure an executable target to link to tinyusb in device mode, and add the board implementation -function(family_configure_device_example TARGET) - # default implentation is empty, the function should be redefined in the FAMILY/family.cmake -endfunction() - -# configure an executable target to link to tinyusb in host mode, and add the board implementation -function(family_configure_host_example TARGET) - # default implentation is empty, the function should be redefined in the FAMILY/family.cmake -endfunction() diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake new file mode 100644 index 000000000..af0e00b2d --- /dev/null +++ b/hw/bsp/family_support.cmake @@ -0,0 +1,71 @@ +if (NOT TARGET _family_support_marker) + add_library(_family_support_marker INTERFACE) + + if (NOT FAMILY) + message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, eps32s2, esp32s3). You can do this via -DFAMILY=xxx on the camke command line") + endif() + + if (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) + message(FATAL_ERROR "Family '${FAMILY}' is not known/supported") + endif() + + function(family_filter RESULT DIR) + get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + file(GLOB ONLYS "${DIR}/.only.MCU_*") + if (ONLYS) + foreach(MCU IN LISTS FAMILY_MCUS) + if (EXISTS ${DIR}/.only.MCU_${MCU}) + set(${RESULT} 1 PARENT_SCOPE) + return() + endif() + endforeach() + else() + foreach(MCU IN LISTS FAMILY_MCUS) + if (EXISTS ${DIR}/.skip.MCU_${MCU}) + set(${RESULT} 0 PARENT_SCOPE) + return() + endif() + endforeach() + endif() + set(${RESULT} 1 PARENT_SCOPE) + endfunction() + + function(family_add_subdirectory DIR) + family_filter(SHOULD_ADD "${DIR}") + if (SHOULD_ADD) + add_subdirectory(${DIR}) + endif() + endfunction() + + function(family_get_project_name OUTPUT_NAME DIR) + get_filename_component(SHORT_NAME ${DIR} NAME) + set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) + endfunction() + + function(family_initialize_project PROJECT DIR) + family_filter(ALLOWED "${DIR}") + if (NOT ALLOWED) + get_filename_component(SHORT_NAME ${DIR} NAME) + message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}") + endif() + endfunction() + + # configure an executable target to link to tinyusb in device mode, and add the board implementation + function(family_configure_device_example TARGET) + # default implentation is empty, the function should be redefined in the FAMILY/family.cmake + endfunction() + + # configure an executable target to link to tinyusb in host mode, and add the board implementation + function(family_configure_host_example TARGET) + # default implentation is empty, the function should be redefined in the FAMILY/family.cmake + endfunction() + + include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) + + if (NOT FAMILY_MCUS) + set(FAMILY_MCUS ${FAMILY}) + endif() + + # save it in case of re-inclusion + set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "") +endif() \ No newline at end of file diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index 752eb0cab..41960b6cd 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -3,7 +3,8 @@ if (NOT TARGET _rp2040_family_inclusion_marker) add_library(_rp2040_family_inclusion_marker INTERFACE) if (NOT BOARD) - message(FATAL_ERROR "BOARD must be specified") + message("BOARD not specified, defaulting to pico_sdk") + set(BOARD pico_sdk) endif() # add the SDK in case we are standalone tinyusb example (noop if already present) @@ -11,7 +12,6 @@ if (NOT TARGET _rp2040_family_inclusion_marker) # include basic family CMake functionality set(FAMILY_MCUS RP2040) - include(${CMAKE_CURRENT_LIST_DIR}/../family_common.cmake) include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) -- cgit v1.3.1