Browse Source

Allow custom USB enumeration.

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
Andrew J. Kroll 10 years ago
parent
commit
c9d85378d7
5 changed files with 26 additions and 12 deletions
  1. +2
    -1
      teensy3/usb_desc.c
  2. +2
    -1
      teensy3/usb_desc.h
  3. +4
    -4
      teensy3/usb_dev.c
  4. +15
    -3
      teensy3/usb_dev.h
  5. +3
    -3
      teensy3/usb_mem.c

+ 2
- 1
teensy3/usb_desc.c View File

#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

+ 2
- 1
teensy3/usb_desc.h View File



#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



+ 4
- 4
teensy3/usb_dev.c View File

* 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)

+ 15
- 3
teensy3/usb_dev.h View File

#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

+ 3
- 3
teensy3/usb_mem.c View File

* 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)

Loading…
Cancel
Save