added Adafruit_USBDevice based on tinyusb

- added Adafruit_USBInterface
- remove setLoopStacksize
- move usb code around
This commit is contained in:
hathach committed 2019-04-12 00:12:24 +07:00
1 parent 85eb9a54ef
commit 55b4d3cfc2
20 files changed
+354 -220

No files matched your search

+1 -3
View File
@@ -36,7 +36,6 @@ void setup( void ) ;
void loop( void ) ;
void suspendLoop(void);
uint32_t setLoopStacksize(void);
#include "WVariant.h"
@@ -70,11 +69,10 @@ uint32_t setLoopStacksize(void);
#ifdef NRF52840_XXAA
#include "tusb.h"
#ifdef __cplusplus
#include "Adafruit_USBDevice.h"
#include "USBSerial.h"
#endif
#endif
// Include board variant
+34 -11
View File
@@ -16,6 +16,14 @@
#define ARDUINO_MAIN
#include "Arduino.h"
#include "usb.h"
/* USB VID/PID if not defined, tinyusb to use default value
* Note: different class combination e.g CDC and (CDC + MSC) should have different
* PID since Host OS will "remembered" device driver after the first plug */
#define USB_VID 0x239A
#define USB_PID 0x8029
// DEBUG Level 1
#if CFG_DEBUG
// weak function to avoid compilation error with
@@ -37,9 +45,8 @@ static TaskHandle_t _loopHandle;
void initVariant() __attribute__((weak));
void initVariant() { }
uint32_t _loopStacksize = 512*3;
uint32_t setLoopStacksize(void) __attribute__ ((weak));
#define LOOP_STACK_SZ (512*3)
#define USBD_STACK_SZ (150)
static void loop_task(void* arg)
{
@@ -68,25 +75,41 @@ static void loop_task(void* arg)
}
}
/*
* \brief Main entry point of Arduino application
*/
// USB Device Driver task
// This top level thread process all usb events and invoke callbacks
static void usb_device_task(void* param)
{
(void) param;
// RTOS forever loop
while (1)
{
// tinyusb device task
tud_task();
}
}
// \brief Main entry point of Arduino application
int main( void )
{
init();
initVariant();
if (setLoopStacksize)
{
_loopStacksize = setLoopStacksize();
}
#ifdef NRF52840_XXAA
USBDevice.addInterface( (Adafruit_USBInterface&) Serial);
USBDevice.begin(USB_VID, USB_PID);
usb_init();
// Create a task for tinyusb device stack
xTaskCreate( usb_device_task, "usbd", USBD_STACK_SZ, NULL, TASK_PRIO_HIGH, NULL);
#endif
#if CFG_DEBUG >= 3
SEGGER_SYSVIEW_Conf();
#endif
// Create a task for loop()
xTaskCreate( loop_task, "loop", _loopStacksize, NULL, TASK_PRIO_LOW, &_loopHandle);
xTaskCreate( loop_task, "loop", LOOP_STACK_SZ, NULL, TASK_PRIO_LOW, &_loopHandle);
// Initialize callback task
ada_callback_init();
+180
View File
@@ -0,0 +1,180 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 hathach for Adafruit Industries
*
* 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.
*/
#ifdef NRF52840_XXAA
#include "Adafruit_USBDevice.h"
extern "C"
{
extern uint16_t usb_desc_str_serial[1+16];
// array of pointer to string descriptors
uint16_t const * const string_desc_arr [] =
{
// 0: is supported language = English
TUD_DESC_STRCONV(0x0409),
// 1: Manufacturer
TUD_DESC_STRCONV('A','d','a','f','r','u','i','t',' ','I','n','d','u','s','t','r','i','e','s'),
// 2: Product
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','n','R','F','5','2','8','4','0'),
// 3: Serials
usb_desc_str_serial,
// // 4: CDC Interface
// TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','S','e','r','i','a','l'),
//
// // 5: MSC Interface
// TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','U','F','2'),
};
// tud_desc_set is required by tinyusb stack
// since CFG_TUD_DESC_AUTO is enabled, we only need to set string_arr
tud_desc_set_t tud_desc_set =
{
.device = NULL,
.config = NULL,
.string_arr = (uint8_t const **) string_desc_arr,
.string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]),
.hid_report =
{
.generic = NULL,
.boot_keyboard = NULL,
.boot_mouse = NULL
}
};
} // extern C
Adafruit_USBDevice USBDevice;
Adafruit_USBDevice::Adafruit_USBDevice(void)
{
tusb_desc_device_t desc_dev =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
#if CFG_TUD_CDC
// Use Interface Association Descriptor (IAD) for CDC
// As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
.bDeviceClass = TUSB_CLASS_MISC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
#else
.bDeviceClass = 0x00,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
#endif
.bMaxPacketSize0 = CFG_TUD_ENDOINT0_SIZE,
.idVendor = 0,
.idProduct = 0,
.bcdDevice = 0x0100,
.iManufacturer = 0x01,
.iProduct = 0x02,
.iSerialNumber = 0x03,
.bNumConfigurations = 0x01
};
_desc_device = desc_dev;
tusb_desc_configuration_t dev_cfg =
{
.bLength = sizeof(tusb_desc_configuration_t),
.bDescriptorType = TUSB_DESC_CONFIGURATION,
// Total Length & Interface Number will be updated later
.wTotalLength = 0,
.bNumInterfaces = 0,
.bConfigurationValue = 1,
.iConfiguration = 0x00,
.bmAttributes = TU_BIT(7) | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP,
.bMaxPower = TUSB_DESC_CONFIG_POWER_MA(100)
};
memcpy(_desc_cfg, &dev_cfg, sizeof(tusb_desc_configuration_t));
_desc_cfglen = sizeof(tusb_desc_configuration_t);
_itf_count = 0;
tud_desc_set.config = _desc_cfg;
tud_desc_set.device = &_desc_device;
}
// Add interface descriptor, interface number will be updated to match current count
bool Adafruit_USBDevice::addInterface(Adafruit_USBInterface& itf)
{
uint8_t* desc = _desc_cfg+_desc_cfglen;
uint16_t len = itf.getDescriptor(desc, sizeof(_desc_cfg)-_desc_cfglen);
uint8_t* desc_end = desc+len;
// Handle IAD
if ( desc[1] == TUSB_DESC_INTERFACE_ASSOCIATION )
{
// update starting interface
((tusb_desc_interface_assoc_t*) desc)->bFirstInterface = _itf_count;
desc += desc[0]; // next
}
while (desc < desc_end)
{
if (desc[1] == TUSB_DESC_INTERFACE)
{
// No alternate interface support
((tusb_desc_interface_t*) desc)->bInterfaceNumber = _itf_count++;
}
if (desc[0] == 0) return false;
desc += desc[0]; // next
}
_desc_cfglen += len;
// Update config descriptor
tusb_desc_configuration_t* config = (tusb_desc_configuration_t*)_desc_cfg;
config->wTotalLength = _desc_cfglen;
config->bNumInterfaces = _itf_count;
return true;
}
bool Adafruit_USBDevice::begin(uint16_t vid, uint16_t pid)
{
_desc_device.idVendor = vid;
_desc_device.idProduct = pid;
}
#endif
+56
View File
@@ -0,0 +1,56 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 hathach for Adafruit Industries
*
* 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 ADAFRUIT_USBDEVICE_H_
#define ADAFRUIT_USBDEVICE_H_
#include "tusb.h"
class Adafruit_USBInterface
{
public:
virtual uint16_t getDescriptor(uint8_t* buf, uint16_t bufsize) = 0;
};
class Adafruit_USBDevice
{
private:
tusb_desc_device_t _desc_device;
uint8_t _desc_cfg[256];
uint16_t _desc_cfglen;
uint8_t _itf_count;
public:
Adafruit_USBDevice(void);
bool addInterface(Adafruit_USBInterface& itf);
bool begin(uint16_t vid, uint16_t pid);
};
extern Adafruit_USBDevice USBDevice;
#endif /* ADAFRUIT_USBDEVICE_H_ */
+13 -1
View File
@@ -27,7 +27,6 @@
#include "Arduino.h"
#include "tusb.h"
USBSerial Serial;
USBSerial::USBSerial(void)
@@ -35,6 +34,19 @@ USBSerial::USBSerial(void)
}
uint16_t USBSerial::getDescriptor(uint8_t* buf, uint16_t bufsize)
{
// CDC is mostly always existed for DFU
// Let's pick EP 1 & 2 for it
uint8_t desc[] = { TUD_CDC_DESCRIPTOR(0, 0, 0x81, 8, 0x02, 0x82, 64) };
uint16_t const len = sizeof(desc);
if ( bufsize < len ) return 0;
memcpy(buf, desc, len);
return len;
}
// Baud and config is ignore in CDC
void USBSerial::begin (uint32_t baud)
{
+5 -1
View File
@@ -27,13 +27,17 @@
#ifdef NRF52840_XXAA
#include "Adafruit_USBDevice.h"
#include "Stream.h"
class USBSerial : public Stream
class USBSerial : public Stream, Adafruit_USBInterface
{
public:
USBSerial(void);
// fron Adafruit_USBInterface
virtual uint16_t getDescriptor(uint8_t* buf, uint16_t bufsize);
void setPins(uint8_t pin_rx, uint8_t pin_tx) { (void) pin_rx; (void) pin_tx; }
void begin(uint32_t baud_count);
void begin(uint32_t baud, uint8_t config);
@@ -104,6 +104,38 @@ bool cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const
bool cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
void cdcd_reset (uint8_t rhport);
//--------------------------------------------------------------------+
// Interface Descriptor Template
//--------------------------------------------------------------------+
// Length of template descriptor: 66 bytes
#define TUD_CDC_DESC_LEN (8+9+5+5+4+5+7+9+7+7)
// CDC Descriptor Template
// interface number, string index, EP notification address and size, EP data address (out,in) and size.
#define TUD_CDC_DESCRIPTOR(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
/* Interface Associate */\
0x08, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 0x02, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, 0x00,\
/* CDC Control Interface */\
0x09, TUSB_DESC_INTERFACE, _itfnum, 0x00, 0x01, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, _stridx,\
/* CDC Header */\
0x05, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\
/* CDC Call */\
0x05, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_CALL_MANAGEMENT, 0x00, (_itfnum) + 1,\
/* CDC ACM: support line request */\
0x04, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 0x02,\
/* CDC Union */\
0x05, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_UNION, _itfnum, (_itfnum) + 1,\
/* Endpoint Notification */\
0x07, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 0x10,\
/* CDC Data Interface */\
0x09, TUSB_DESC_INTERFACE, (_itfnum)+1, 0x00, 0x02, TUSB_CLASS_CDC_DATA, 0x00, 0x00, 0x00,\
/* Endpoint Out */\
0x07, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0x00,\
/* Endpoint In */\
0x07, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0x00
#ifdef __cplusplus
}
#endif
@@ -31,6 +31,9 @@
#include "device/usbd.h"
#include "msc.h"
#ifdef __cplusplus
extern "C" {
#endif
//--------------------------------------------------------------------+
// Class Driver Configuration
@@ -59,9 +62,23 @@ TU_VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct");
#error CFG_TUD_MSC_PRODUCT_REV 4-byte string must be defined
#endif
#ifdef __cplusplus
extern "C" {
#endif
//--------------------------------------------------------------------+
// Interface Descriptor Template
//--------------------------------------------------------------------+
// Length of template descriptor: 23 bytes
#define TUD_MSC_DESC_LEN (9 + 7 + 7)
// Interface Number, EP Out & EP In address
#define TUD_MSC_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
/* Interface */\
0x09, TUSB_DESC_INTERFACE, _itfnum, 0x00, 0x02, TUSB_CLASS_MSC, MSC_SUBCLASS_SCSI, MSC_PROTOCOL_BOT, _stridx,\
/* Endpoint Out */\
0x07, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0x00,\
/* Endpoint In */\
0x07, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0x00
/** \addtogroup ClassDriver_MSC
* @{
@@ -113,7 +113,6 @@
#include "tusb_option.h"
#include "tusb_compiler.h"
#include "tusb_verify.h"
//#include "binary.h"
#include "tusb_error.h"
#include "tusb_timeout.h"
#include "tusb_types.h"
+1 -1
View File
@@ -577,7 +577,7 @@ static void const* get_descriptor(tusb_control_request_t const * p_request, uint
switch(desc_type)
{
case TUSB_DESC_DEVICE:
desc_data = (uint8_t const *) usbd_desc_set->device;
desc_data = (uint8_t const *) tud_desc_set.device;
len = sizeof(tusb_desc_device_t);
break;
@@ -30,30 +30,10 @@
#include "tusb.h"
//--------------------------------------------------------------------+
// Auto Description Default Configure & Validation
//--------------------------------------------------------------------+
// If HID Generic interface is generated
#define AUTO_DESC_HID_GENERIC (CFG_TUD_HID && ((CFG_TUD_HID_KEYBOARD && !CFG_TUD_HID_KEYBOARD_BOOT) || \
(CFG_TUD_HID_MOUSE && !CFG_TUD_HID_MOUSE_BOOT)) )
/*------------- VID/PID -------------*/
#ifndef CFG_TUD_DESC_VID
#define CFG_TUD_DESC_VID 0xCAFE
#endif
#ifndef CFG_TUD_DESC_PID
/* 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 Generic | Boot Mouse | Boot Keyboard | MSC | CDC [LSB]
*/
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
#define CFG_TUD_DESC_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
_PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) | (AUTO_DESC_HID_GENERIC << 4) )
#endif
//--------------------------------------------------------------------+
// Interface & Endpoint mapping
@@ -62,7 +42,6 @@
/*------------- Interface Numbering -------------*/
/* The order as follows: CDC, MSC, Boot Keyboard, Boot Mouse, HID Generic
* If an interface is not enabled, the later will take its place */
enum
{
#if CFG_TUD_CDC
@@ -147,9 +126,9 @@ enum
#endif
#if TUD_OPT_HIGH_SPEED
#define EP_MSC_SIZE 512
#define EP_MSC_SIZE 512
#else
#define EP_MSC_SIZE 64
#define EP_MSC_SIZE 64
#endif
@@ -173,12 +152,10 @@ enum
#define EP_HID_GEN _EP_IN ( ITF_NUM_HID_GEN+1 )
#define EP_HID_GEN_SIZE 16
//--------------------------------------------------------------------+
// Auto generated HID Report Descriptors
//--------------------------------------------------------------------+
/*------------- Boot Protocol Report Descriptor -------------*/
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
uint8_t const _desc_auto_hid_boot_kbd_report[] = { HID_REPORT_DESC_KEYBOARD() };
@@ -213,51 +190,9 @@ uint8_t const _desc_auto_hid_generic_report[] =
/*------------------------------------------------------------------*/
/* Auto generated Device & Configuration descriptor
/* Auto generated Configuration descriptor
*------------------------------------------------------------------*/
// For highspeed device but currently in full speed mode
//tusb_desc_device_qualifier_t _device_qual =
//{
// .bLength = sizeof(tusb_desc_device_qualifier_t),
// .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
// .bcdUSB = 0x0200,
// .bDeviceClass =
//};
/*------------- Device Descriptor -------------*/
tusb_desc_device_t const _desc_auto_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
#if CFG_TUD_CDC
// Use Interface Association Descriptor (IAD) for CDC
// As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
.bDeviceClass = TUSB_CLASS_MISC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
#else
.bDeviceClass = 0x00,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
#endif
.bMaxPacketSize0 = CFG_TUD_ENDOINT0_SIZE,
.idVendor = CFG_TUD_DESC_VID,
.idProduct = CFG_TUD_DESC_PID,
.bcdDevice = 0x0100,
.iManufacturer = 0x01,
.iProduct = 0x02,
.iSerialNumber = 0x03,
.bNumConfigurations = 0x01
};
/*------------- Configuration Descriptor -------------*/
typedef struct ATTR_PACKED
{
@@ -484,7 +419,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
.bEndpointAddress = EP_MSC_OUT,
.bmAttributes = { .xfer = TUSB_XFER_BULK },
.wMaxPacketSize = { .size = EP_MSC_SIZE},
.bInterval = 1
.bInterval = 0
},
.ep_in =
@@ -494,7 +429,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
.bEndpointAddress = EP_MSC_IN,
.bmAttributes = { .xfer = TUSB_XFER_BULK },
.wMaxPacketSize = { .size = EP_MSC_SIZE},
.bInterval = 1
.bInterval = 0
}
},
#endif // msc
@@ -624,7 +559,7 @@ uint8_t const * const _desc_auto_config = (uint8_t const*) &_desc_auto_config_st
tud_desc_set_t const _usbd_auto_desc_set =
{
.device = &_desc_auto_device,
.device = NULL, // no auto device
.config = &_desc_auto_config_struct,
.hid_report =
+2 -13
View File
@@ -39,13 +39,8 @@
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE
#endif
#define CFG_TUSB_DEBUG 0
/*------------- RTOS -------------*/
#define CFG_TUSB_OS OPT_OS_FREERTOS
#define CFG_TUD_TASK_PRIO (configMAX_PRIORITIES-2) // TASK_PRIO_HIGH = Bluefruit Task
//#define CFG_TUD_TASK_QUEUE_SZ 16
//#define CFG_TUD_TASK_STACK_SZ 150
#define CFG_TUSB_DEBUG 0
//--------------------------------------------------------------------
// DEVICE CONFIGURATION
@@ -60,13 +55,7 @@
*
* Note: All CFG_TUD_DESC_* are relevant only if CFG_TUD_DESC_AUTO is enabled
*/
#define CFG_TUD_DESC_AUTO 1
/* USB VID/PID if not defined, tinyusb to use default value
* Note: different class combination e.g CDC and (CDC + MSC) should have different
* PID since Host OS will "remembered" device driver after the first plug */
#define CFG_TUD_DESC_VID 0x239A
#define CFG_TUD_DESC_PID 0x8029
#define CFG_TUD_DESC_AUTO 0
//------------- CLASS -------------//
#define CFG_TUD_CDC 1
+2 -1
View File
@@ -35,7 +35,8 @@
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
extern uint16_t usb_desc_str_serial[1+16];
// Serial is 64-bit DeviceID -> 16 chars len
uint16_t usb_desc_str_serial[1+16] = { TUD_DESC_STR_HEADER(16) };
// Init usb when starting up. Softdevice is not enabled yet
void usb_init(void)
-86
View File
@@ -1,86 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach for Adafruit
*
* 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.
*/
#ifdef NRF52840_XXAA
#include "tusb.h"
/*------------- Interface Numbering -------------*/
enum {
ITF_STR_LANGUAGE = 0 ,
ITF_STR_MANUFACTURER ,
ITF_STR_PRODUCT ,
ITF_STR_SERIAL ,
ITF_STR_CDC ,
ITF_STR_MSC
};
//--------------------------------------------------------------------+
// STRING DESCRIPTORS
//--------------------------------------------------------------------+
// Serial is 64-bit DeviceID -> 16 chars len
uint16_t usb_desc_str_serial[1+16] = { TUD_DESC_STR_HEADER(16) };
// array of pointer to string descriptors
uint16_t const * const string_desc_arr [] =
{
// 0: is supported language = English
TUD_DESC_STRCONV(0x0409),
// 1: Manufacturer
TUD_DESC_STRCONV('A','d','a','f','r','u','i','t',' ','I','n','d','u','s','t','r','i','e','s'),
// 2: Product
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','n','R','F','5','2','8','4','0'),
// 3: Serials
usb_desc_str_serial,
// 4: CDC Interface
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','S','e','r','i','a','l'),
// 5: MSC Interface
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','U','F','2'),
};
// tud_desc_set is required by tinyusb stack
// since CFG_TUD_DESC_AUTO is enabled, we only need to set string_arr
tud_desc_set_t tud_desc_set =
{
.device = NULL,
.config = NULL,
.string_arr = (uint8_t const **) string_desc_arr,
.string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]),
.hid_report =
{
.generic = NULL,
.boot_keyboard = NULL,
.boot_mouse = NULL
}
};
#endif
-8
View File
@@ -21,10 +21,6 @@
#include "nrf.h"
#include "nrf_nvic.h"
#ifdef __cplusplus
extern "C" {
#endif
nrf_nvic_state_t nrf_nvic_state;
#define DFU_MAGIC_SERIAL_ONLY_RESET 0x4e
@@ -142,7 +138,3 @@ void systemOff(uint32_t pin, uint8_t wake_logic)
NRF_POWER->SYSTEMOFF = 1;
}
}
#ifdef __cplusplus
}
#endif
-1
View File
@@ -21,7 +21,6 @@ suspendLoop KEYWORD2
enterSerialDfu KEYWORD2
enterOTADfu KEYWORD2
setLoopStacksize KEYWORD2
ledOn KEYWORD2
ledOff KEYWORD2
+2 -2
View File
@@ -154,7 +154,7 @@ AdafruitBluefruit::AdafruitBluefruit(void)
_event_cb = NULL;
_rssi_cb = NULL;
_sec_param = (ble_gap_sec_params_t)
_sec_param = ((ble_gap_sec_params_t)
{
.bond = 1,
.mitm = 0,
@@ -166,7 +166,7 @@ AdafruitBluefruit::AdafruitBluefruit(void)
.max_key_size = 16,
.kdist_own = { .enc = 1, .id = 1},
.kdist_peer = { .enc = 1, .id = 1},
};
});
COMMENT_OUT(
_auth_type = BLE_GAP_AUTH_KEY_TYPE_NONE;
@@ -22,8 +22,6 @@
#include "wiring_constants.h"
#include "wiring_digital.h"
#include "nrf.h"
#include "usb.h"
#include "flash/flash_qspi.h"
const uint32_t g_ADigitalPinMap[] =
@@ -84,9 +82,5 @@ void initVariant()
// Init External Flash
flash_qspi_init();
#endif
// USB init
usb_init();
}
@@ -22,8 +22,6 @@
#include "wiring_constants.h"
#include "wiring_digital.h"
#include "nrf.h"
#include "usb.h"
#include "flash/flash_qspi.h"
#define _PINNUM(port, pin) ((port)*32 + (pin))
@@ -95,9 +93,5 @@ void initVariant()
// Init External Flash
flash_qspi_init();
#endif
// USB init
usb_init();
}
-5
View File
@@ -22,8 +22,6 @@
#include "wiring_constants.h"
#include "wiring_digital.h"
#include "nrf.h"
#include "usb.h"
#include "flash/flash_qspi.h"
const uint32_t g_ADigitalPinMap[] =
@@ -51,8 +49,5 @@ void initVariant()
// Init External Flash
flash_qspi_init();
// USB init
usb_init();
}