This patch simply checks if NUM_ENDPOINTS is defined, and will bypass the built-in USB descriptor, device and memory code, and allows a custom setting. This bug does not affect the IDE unless someone adds the custom option to the boards.txt file, and provides replacement code in a library or sketch. It can also be used to turn off USB by providing no replacements, while allowing speeds >= 20MHz.teensy4-core
#if F_CPU >= 20000000 | #if F_CPU >= 20000000 | ||||
#include "usb_desc.h" | #include "usb_desc.h" | ||||
#ifdef NUM_ENDPOINTS | |||||
#include "usb_names.h" | #include "usb_names.h" | ||||
#include "mk20dx128.h" | #include "mk20dx128.h" | ||||
#include "avr_functions.h" | #include "avr_functions.h" | ||||
}; | }; | ||||
#endif // NUM_ENDPOINTS | |||||
#endif // F_CPU >= 20 MHz | #endif // F_CPU >= 20 MHz |
#endif | #endif | ||||
#ifdef NUM_ENDPOINTS | |||||
// NUM_ENDPOINTS = number of non-zero endpoints (0 to 15) | // NUM_ENDPOINTS = number of non-zero endpoints (0 to 15) | ||||
extern const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS]; | extern const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS]; | ||||
} usb_descriptor_list_t; | } usb_descriptor_list_t; | ||||
extern const usb_descriptor_list_t usb_descriptor_list[]; | extern const usb_descriptor_list_t usb_descriptor_list[]; | ||||
#endif // NUM_ENDPOINTS | |||||
#endif // F_CPU >= 20 MHz | #endif // F_CPU >= 20 MHz | ||||
* SOFTWARE. | * SOFTWARE. | ||||
*/ | */ | ||||
#if F_CPU >= 20000000 | |||||
#include "usb_dev.h" | |||||
#if F_CPU >= 20000000 && defined(NUM_ENDPOINTS) | |||||
#include "mk20dx128.h" | #include "mk20dx128.h" | ||||
//#include "HardwareSerial.h" | //#include "HardwareSerial.h" | ||||
#include "usb_dev.h" | |||||
#include "usb_mem.h" | #include "usb_mem.h" | ||||
// buffer descriptor table | // buffer descriptor table | ||||
} | } | ||||
#else // F_CPU < 20 MHz | |||||
#else // F_CPU < 20 MHz && defined(NUM_ENDPOINTS) | |||||
void usb_init(void) | void usb_init(void) | ||||
{ | { | ||||
} | } | ||||
#endif // F_CPU >= 20 MHz | |||||
#endif // F_CPU >= 20 MHz && defined(NUM_ENDPOINTS) |
#ifndef _usb_dev_h_ | #ifndef _usb_dev_h_ | ||||
#define _usb_dev_h_ | #define _usb_dev_h_ | ||||
#if F_CPU >= 20000000 | |||||
#include "usb_desc.h" | |||||
#if F_CPU >= 20000000 && defined(NUM_ENDPOINTS) | |||||
// This header is NOT meant to be included when compiling | // This header is NOT meant to be included when compiling | ||||
// user sketches in Arduino. The low-level functions | // user sketches in Arduino. The low-level functions | ||||
// code which provides higher-level interfaces to the user. | // code which provides higher-level interfaces to the user. | ||||
#include "usb_mem.h" | #include "usb_mem.h" | ||||
#include "usb_desc.h" | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
extern "C" { | extern "C" { | ||||
#ifdef __cplusplus | |||||
} | |||||
#endif | |||||
#else // F_CPU >= 20000000 && defined(NUM_ENDPOINTS) | |||||
#ifdef __cplusplus | |||||
extern "C" { | |||||
#endif | |||||
void usb_init(void); | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
} | } | ||||
#endif | #endif | ||||
#endif // F_CPU >= 20 MHz | |||||
#endif // F_CPU >= 20000000 && defined(NUM_ENDPOINTS) | |||||
#endif | #endif |
* SOFTWARE. | * SOFTWARE. | ||||
*/ | */ | ||||
#if F_CPU >= 20000000 | |||||
#include "usb_dev.h" | |||||
#if F_CPU >= 20000000 && defined(NUM_ENDPOINTS) | |||||
#include "mk20dx128.h" | #include "mk20dx128.h" | ||||
//#include "HardwareSerial.h" | //#include "HardwareSerial.h" | ||||
#include "usb_dev.h" | |||||
#include "usb_mem.h" | #include "usb_mem.h" | ||||
__attribute__ ((section(".usbbuffers"), used)) | __attribute__ ((section(".usbbuffers"), used)) | ||||
//serial_print("\n"); | //serial_print("\n"); | ||||
} | } | ||||
#endif // F_CPU >= 20 MHz | |||||
#endif // F_CPU >= 20 MHz && defined(NUM_ENDPOINTS) |