Merge pull request #274 from adafruit/develop

more with usb
This commit is contained in:
hathach authored and GitHub committed 2019-05-24 09:03:12 +07:00
commit a38ac7e7a6
51 files changed
+337 -508

No files matched your search

@@ -94,6 +94,11 @@ void Adafruit_TinyUSB_Core_init(void)
xTaskCreate( usb_device_task, "usbd", USBD_STACK_SZ, NULL, TASK_PRIO_HIGH, NULL);
}
void Adafruit_TinyUSB_Core_touch1200(void)
{
enterSerialDfu();
}
uint8_t load_serial_number(uint16_t* serial_str)
{
// Serial is 64-bit DeviceID -> 16 chars len
@@ -39,4 +39,7 @@
// Called by main.cpp to initialize usb device typically with CDC device for Serial
void Adafruit_TinyUSB_Core_init(void);
// Invoked when host disconnects cdc at baud 1200, usually touch feature to go into DFU mode
void Adafruit_TinyUSB_Core_touch1200(void);
#endif /* ADAFRUIT_TINYUSB_CORE_H_ */
@@ -131,7 +131,7 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
cdc_line_coding_t coding;
tud_cdc_get_line_coding(&coding);
if ( coding.bit_rate == 1200 ) enterSerialDfu();
if ( coding.bit_rate == 1200 ) Adafruit_TinyUSB_Core_touch1200();
}
}
@@ -36,57 +36,6 @@
extern uint8_t load_serial_number(uint16_t* serial_str);
extern "C"
{
// tud_desc_set is required by tinyusb stack
tud_desc_set_t tud_desc_set =
{
.device = NULL, // update later
.config = NULL, // update later
.hid_report = NULL // update later
};
// Invoked when received GET_STRING_DESC request
// max_char is CFG_TUD_ENDOINT0_SIZE/2 -1, typically max_char = 31 if Endpoint0 size is 64
// Return number of characters. Note usb string is in 16-bits unicode format
uint8_t tud_descriptor_string_cb(uint8_t index, uint16_t* desc, uint8_t max_char)
{
switch (index)
{
case 0:
// language = English
desc[0] = 0x0409;
return 1;
case 1: // Manufacturer
case 2: // Product
{
char const * str = (index == 1) ? USB_MANUFACTURER : USB_PRODUCT;
// cap at max char
uint8_t count = strlen(str);
if ( count > max_char ) count = max_char;
for(uint8_t i=0; i<count; i++)
{
*desc++ = str[i];
}
return count;
}
break;
case 3:
return load_serial_number(desc);
default: return 0;
}
return 0;
}
} // extern C
Adafruit_USBD_Device USBDevice;
Adafruit_USBD_Device::Adafruit_USBD_Device(void)
@@ -97,17 +46,11 @@ Adafruit_USBD_Device::Adafruit_USBD_Device(void)
.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,
@@ -144,9 +87,6 @@ Adafruit_USBD_Device::Adafruit_USBD_Device(void)
_desc_cfglen = sizeof(tusb_desc_configuration_t);
_itf_count = 0;
_epin_count = _epout_count = 1;
tud_desc_set.config = _desc_cfg;
tud_desc_set.device = &_desc_device;
}
// Add interface descriptor
@@ -206,4 +146,70 @@ bool Adafruit_USBD_Device::begin(void)
return true;
}
extern "C"
{
// Invoked when received GET DEVICE DESCRIPTOR
// Application return pointer to descriptor
uint8_t const * tud_descriptor_device_cb(void)
{
return (uint8_t const *) &USBDevice._desc_device;
}
// Invoked when received GET CONFIGURATION DESCRIPTOR
// Application return pointer to descriptor, whose 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 USBDevice._desc_cfg;
}
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)
{
uint8_t chr_count;
switch (index)
{
case 0:
// language = English
_desc_str[1] = 0x0409;
chr_count = 1;
break;
case 1: // Manufacturer
case 2: // Product
{
char const * str = (index == 1) ? USB_MANUFACTURER : USB_PRODUCT;
// cap at max char
chr_count = strlen(str);
if ( chr_count > 31 ) chr_count = 31;
for(uint8_t i=0; i<chr_count; i++)
{
_desc_str[1+i] = str[i];
}
}
break;
case 3:
// serial Number
chr_count = load_serial_number(_desc_str+1);
break;
default: return NULL;
}
// first byte is len, second byte is string type
_desc_str[0] = TUD_DESC_STR_HEADER(chr_count);
return _desc_str;
}
} // extern C
#endif // USE_TINYUSB
@@ -58,6 +58,9 @@ class Adafruit_USBD_Device
bool suspended(void) { return tud_suspended(); }
bool ready(void) { return tud_ready(); }
bool remoteWakeup(void) { return tud_remote_wakeup(); }
friend uint8_t const * tud_descriptor_device_cb(void);
friend uint8_t const * tud_descriptor_configuration_cb(uint8_t index);
};
extern Adafruit_USBD_Device USBDevice;
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -99,7 +99,7 @@ static void _prep_out_transaction (uint8_t itf)
bool tud_cdc_n_connected(uint8_t itf)
{
// DTR (bit 0) active is considered as connected
return tud_ready() && TU_BIT_TEST(_cdcd_itf[itf].line_state, 0);
return tud_ready() && tu_bit_test(_cdcd_itf[itf].line_state, 0);
}
uint8_t tud_cdc_n_get_line_state (uint8_t itf)
@@ -126,9 +126,9 @@ uint32_t tud_cdc_n_available(uint8_t itf)
return tu_fifo_count(&_cdcd_itf[itf].rx_ff);
}
char tud_cdc_n_read_char(uint8_t itf)
signed char tud_cdc_n_read_char(uint8_t itf)
{
char ch;
signed char ch;
return tud_cdc_n_read(itf, &ch, 1) ? ch : (-1);
}
@@ -139,9 +139,9 @@ uint32_t tud_cdc_n_read(uint8_t itf, void* buffer, uint32_t bufsize)
return num_read;
}
char tud_cdc_n_peek(uint8_t itf, int pos)
signed char tud_cdc_n_peek(uint8_t itf, int pos)
{
char ch;
signed char ch;
return tu_fifo_peek_at(&_cdcd_itf[itf].rx_ff, pos, &ch) ? ch : (-1);
}
@@ -358,7 +358,7 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request
usbd_control_status(rhport, request);
// Invoke callback
if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, TU_BIT_TEST(request->wValue, 0), TU_BIT_TEST(request->wValue, 1));
if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, tu_bit_test(request->wValue, 0), tu_bit_test(request->wValue, 1));
break;
default: return false; // stall unsupported request
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -51,40 +51,40 @@
// APPLICATION API (Multiple Interfaces)
// CFG_TUD_CDC > 1
//--------------------------------------------------------------------+
bool tud_cdc_n_connected (uint8_t itf);
uint8_t tud_cdc_n_get_line_state (uint8_t itf);
void tud_cdc_n_get_line_coding (uint8_t itf, cdc_line_coding_t* coding);
void tud_cdc_n_set_wanted_char (uint8_t itf, char wanted);
bool tud_cdc_n_connected (uint8_t itf);
uint8_t tud_cdc_n_get_line_state (uint8_t itf);
void tud_cdc_n_get_line_coding (uint8_t itf, cdc_line_coding_t* coding);
void tud_cdc_n_set_wanted_char (uint8_t itf, char wanted);
uint32_t tud_cdc_n_available (uint8_t itf);
char tud_cdc_n_read_char (uint8_t itf);
uint32_t tud_cdc_n_read (uint8_t itf, void* buffer, uint32_t bufsize);
void tud_cdc_n_read_flush (uint8_t itf);
char tud_cdc_n_peek (uint8_t itf, int pos);
uint32_t tud_cdc_n_available (uint8_t itf);
signed char tud_cdc_n_read_char (uint8_t itf);
uint32_t tud_cdc_n_read (uint8_t itf, void* buffer, uint32_t bufsize);
void tud_cdc_n_read_flush (uint8_t itf);
signed char tud_cdc_n_peek (uint8_t itf, int pos);
uint32_t tud_cdc_n_write_char (uint8_t itf, char ch);
uint32_t tud_cdc_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str);
bool tud_cdc_n_write_flush (uint8_t itf);
uint32_t tud_cdc_n_write_char (uint8_t itf, char ch);
uint32_t tud_cdc_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str);
bool tud_cdc_n_write_flush (uint8_t itf);
//--------------------------------------------------------------------+
// APPLICATION API (Interface0)
//--------------------------------------------------------------------+
static inline bool tud_cdc_connected (void) { return tud_cdc_n_connected(0); }
static inline uint8_t tud_cdc_get_line_state (void) { return tud_cdc_n_get_line_state(0); }
static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding) { return tud_cdc_n_get_line_coding(0, coding);}
static inline void tud_cdc_set_wanted_char (char wanted) { tud_cdc_n_set_wanted_char(0, wanted); }
static inline bool tud_cdc_connected (void) { return tud_cdc_n_connected(0); }
static inline uint8_t tud_cdc_get_line_state (void) { return tud_cdc_n_get_line_state(0); }
static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding) { return tud_cdc_n_get_line_coding(0, coding);}
static inline void tud_cdc_set_wanted_char (char wanted) { tud_cdc_n_set_wanted_char(0, wanted); }
static inline uint32_t tud_cdc_available (void) { return tud_cdc_n_available(0); }
static inline char tud_cdc_read_char (void) { return tud_cdc_n_read_char(0); }
static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize) { return tud_cdc_n_read(0, buffer, bufsize); }
static inline void tud_cdc_read_flush (void) { tud_cdc_n_read_flush(0); }
static inline char tud_cdc_peek (int pos) { return tud_cdc_n_peek(0, pos); }
static inline uint32_t tud_cdc_available (void) { return tud_cdc_n_available(0); }
static inline signed char tud_cdc_read_char (void) { return tud_cdc_n_read_char(0); }
static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize) { return tud_cdc_n_read(0, buffer, bufsize); }
static inline void tud_cdc_read_flush (void) { tud_cdc_n_read_flush(0); }
static inline signed char tud_cdc_peek (int pos) { return tud_cdc_n_peek(0, pos); }
static inline uint32_t tud_cdc_write_char (char ch) { return tud_cdc_n_write_char(0, ch); }
static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize) { return tud_cdc_n_write(0, buffer, bufsize); }
static inline uint32_t tud_cdc_write_str (char const* str) { return tud_cdc_n_write_str(0, str); }
static inline bool tud_cdc_write_flush (void) { return tud_cdc_n_write_flush(0); }
static inline uint32_t tud_cdc_write_char (char ch) { return tud_cdc_n_write_char(0, ch); }
static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize) { return tud_cdc_n_write(0, buffer, bufsize); }
static inline uint32_t tud_cdc_write_str (char const* str) { return tud_cdc_n_write_str(0, str); }
static inline bool tud_cdc_write_flush (void) { return tud_cdc_n_write_flush(0); }
//--------------------------------------------------------------------+
// APPLICATION CALLBACK API (WEAK is optional)
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -201,7 +201,8 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
{
usbd_control_xfer(rhport, p_request, (void*) tud_desc_set.hid_report, p_hid->reprot_desc_len);
uint8_t const * desc_report = tud_hid_descriptor_report_cb();
usbd_control_xfer(rhport, p_request, (void*) desc_report, p_hid->reprot_desc_len);
}else
{
return false; // stall unsupported request
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -68,6 +68,10 @@ bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y
// Callbacks (Weak is optional)
//--------------------------------------------------------------------+
// Invoked when received GET HID REPORT DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
ATTR_WEAK uint8_t const * tud_hid_descriptor_report_cb(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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -80,7 +80,8 @@ static inline uint32_t rdwr10_get_lba(uint8_t const command[])
uint32_t lba;
memcpy(&lba, &p_rdwr10->lba, 4);
return __be2n(lba);
// lba is in Big Endian format
return tu_ntohl(lba);
}
static inline uint16_t rdwr10_get_blockcount(uint8_t const command[])
@@ -92,7 +93,7 @@ static inline uint16_t rdwr10_get_blockcount(uint8_t const command[])
uint16_t block_count;
memcpy(&block_count, &p_rdwr10->block_count, 2);
return __be2n_16(block_count);
return tu_ntohs(block_count);
}
//--------------------------------------------------------------------+
@@ -238,8 +239,8 @@ int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_t* buff
{
scsi_read_capacity10_resp_t read_capa10;
read_capa10.last_lba = ENDIAN_BE(block_count-1);
read_capa10.block_size = ENDIAN_BE(block_size);
read_capa10.last_lba = tu_htonl(block_count-1);
read_capa10.block_size = tu_htonl(block_size);
resplen = sizeof(read_capa10);
memcpy(buffer, &read_capa10, resplen);
@@ -272,8 +273,8 @@ int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_t* buff
if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
}else
{
read_fmt_capa.block_num = ENDIAN_BE(block_count);
read_fmt_capa.block_size_u16 = ENDIAN_BE16(block_size);
read_fmt_capa.block_num = tu_htonl(block_count);
read_fmt_capa.block_size_u16 = tu_htons(block_size);
resplen = sizeof(read_fmt_capa);
memcpy(buffer, &read_fmt_capa, resplen);
@@ -390,7 +391,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
// For other SCSI commands
// 1. OUT : queue transfer (invoke app callback after done)
// 2. IN & Zero: Process if is built-in, else Invoke app callback. Skip DATA if zero length
if ( (p_cbw->total_bytes > 0 ) && !TU_BIT_TEST(p_cbw->dir, 7) )
if ( (p_cbw->total_bytes > 0 ) && !tu_bit_test(p_cbw->dir, 7) )
{
// queue transfer
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
@@ -439,7 +440,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
case MSC_STAGE_DATA:
// OUT transfer, invoke callback if needed
if ( !TU_BIT_TEST(p_cbw->dir, 7) )
if ( !tu_bit_test(p_cbw->dir, 7) )
{
if ( SCSI_CMD_WRITE_10 != p_cbw->command[0] )
{
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,74 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (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.
*/
/** \ingroup Group_Compiler
* \defgroup Group_GCC GNU GCC
* @{ */
#ifndef _TUSB_COMPILER_GCC_H_
#define _TUSB_COMPILER_GCC_H_
#ifdef __cplusplus
extern "C" {
#endif
#define ALIGN_OF(x) __alignof__(x)
// Specifies a minimum alignment for the variable or structure field, measured in bytes
#define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
// Place variable in a specific section
#define ATTR_SECTION(sec_name) __attribute__ (( section(#sec_name) ))
// Packed struct/variable into smallest possible size
#define ATTR_PACKED __attribute__ ((packed))
#define ATTR_PREPACKED
// The deprecated attribute results in a warning if the function is used.
#define ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess)))
// The weak attribute causes the declaration to be emitted as a weak symbol rather than a global.
#define ATTR_WEAK __attribute__ ((weak))
// Function/Variable is meant to be possibly unused (thus no warning)
#define ATTR_UNUSED __attribute__ ((unused))
// TODO mcu specific
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __n2be(x) __builtin_bswap32(x) ///< built-in function to convert 32-bit from native to Big Endian
#define __be2n(x) __n2be(x) ///< built-in function to convert 32-bit from Big Endian to native
#define __n2be_16(u16) __builtin_bswap16(u16)
#define __be2n_16(u16) __n2be_16(u16)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_COMPILER_GCC_H_ */
/// @}
@@ -1,58 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
#ifndef _TUSB_COMPILER_IAR_H_
#define _TUSB_COMPILER_IAR_H_
#ifdef __cplusplus
extern "C" {
#endif
#define ALIGN_OF(x) __ALIGNOF__(x)
#define ATTR_ALIGNED(bytes) _Pragma(XSTRING_(data_alignment=##bytes))
//#define ATTR_SECTION(section) _Pragma((#section))
#define ATTR_PREPACKED __packed
#define ATTR_PACKED
#define ATTR_DEPRECATED(mess)
#define ATTR_WEAK __weak
#define ATTR_UNUSED
// built-in function to convert 32-bit Big-Endian to Little-Endian
//#if __LITTLE_ENDIAN__
#define __be2n __REV
#define __n2be __be2n
#define __n2be_16(u16) ((uint16_t) __REV16(u16))
#define __be2n_16(u16) __n2be_16(u16)
#error "IAR won't work due to '__packed' placement before struct"
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_COMPILER_IAR_H_ */
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -38,65 +38,27 @@
//--------------------------------------------------------------------+
// Macros Helper
//--------------------------------------------------------------------+
#define TU_ARRAY_SZIE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
#define TU_MIN(_x, _y) ( (_x) < (_y) ) ? (_x) : (_y) )
#define TU_MAX(_x, _y) ( (_x) > (_y) ) ? (_x) : (_y) )
#define TU_ARRAY_SZIE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
#define TU_MIN(_x, _y) ( (_x) < (_y) ) ? (_x) : (_y) )
#define TU_MAX(_x, _y) ( (_x) > (_y) ) ? (_x) : (_y) )
#define U16_HIGH_U8(u16) ((uint8_t) (((u16) >> 8) & 0x00ff))
#define U16_LOW_U8(u16) ((uint8_t) ((u16) & 0x00ff))
#define U16_TO_U8S_BE(u16) U16_HIGH_U8(u16), U16_LOW_U8(u16)
#define U16_TO_U8S_LE(u16) U16_LOW_U8(u16), U16_HIGH_U8(u16)
#define TU_U16_HIGH(u16) ((uint8_t) (((u16) >> 8) & 0x00ff))
#define TU_U16_LOW(u16) ((uint8_t) ((u16) & 0x00ff))
#define U16_TO_U8S_BE(u16) TU_U16_HIGH(u16), TU_U16_LOW(u16)
#define U16_TO_U8S_LE(u16) TU_U16_LOW(u16), TU_U16_HIGH(u16)
#define U32_B1_U8(u32) ((uint8_t) (((u32) >> 24) & 0x000000ff)) // MSB
#define U32_B2_U8(u32) ((uint8_t) (((u32) >> 16) & 0x000000ff))
#define U32_B3_U8(u32) ((uint8_t) (((u32) >> 8) & 0x000000ff))
#define U32_B4_U8(u32) ((uint8_t) ((u32) & 0x000000ff)) // LSB
#define U32_B1_U8(u32) ((uint8_t) (((u32) >> 24) & 0x000000ff)) // MSB
#define U32_B2_U8(u32) ((uint8_t) (((u32) >> 16) & 0x000000ff))
#define U32_B3_U8(u32) ((uint8_t) (((u32) >> 8) & 0x000000ff))
#define U32_B4_U8(u32) ((uint8_t) ((u32) & 0x000000ff)) // LSB
#define U32_TO_U8S_BE(u32) U32_B1_U8(u32), U32_B2_U8(u32), U32_B3_U8(u32), U32_B4_U8(u32)
#define U32_TO_U8S_LE(u32) U32_B4_U8(u32), U32_B3_U8(u32), U32_B2_U8(u32), U32_B1_U8(u32)
#define U32_TO_U8S_BE(u32) U32_B1_U8(u32), U32_B2_U8(u32), U32_B3_U8(u32), U32_B4_U8(u32)
#define U32_TO_U8S_LE(u32) U32_B4_U8(u32), U32_B3_U8(u32), U32_B2_U8(u32), U32_B1_U8(u32)
//------------- Bit -------------//
#define TU_BIT(n) (1U << (n)) ///< n-th Bit
#define TU_BIT_SET(x, n) ( (x) | TU_BIT(n) ) ///< set n-th bit of x to 1
#define TU_BIT_CLEAR(x, n) ( (x) & (~TU_BIT(n)) ) ///< clear n-th bit of x
#define TU_BIT_TEST(x, n) ( ((x) & TU_BIT(n)) ? true : false ) ///< check if n-th bit of x is 1
//------------- Endian Conversion -------------//
#define ENDIAN_BE(u32) \
(uint32_t) ( (((u32) & 0xFF) << 24) | (((u32) & 0xFF00) << 8) | (((u32) >> 8) & 0xFF00) | (((u32) >> 24) & 0xFF) )
#define ENDIAN_BE16(le16) ((uint16_t) ((U16_LOW_U8(le16) << 8) | U16_HIGH_U8(le16)) )
//------------- Binary constant -------------//
#if defined(__GNUC__) && !defined(__CC_ARM)
#define TU_BIN8(x) ((uint8_t) (0b##x))
#define TU_BIN16(b1, b2) ((uint16_t) (0b##b1##b2))
#define TU_BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4))
#else
// internal macro of B8, B16, B32
#define _B8__(x) (((x&0x0000000FUL)?1:0) \
+((x&0x000000F0UL)?2:0) \
+((x&0x00000F00UL)?4:0) \
+((x&0x0000F000UL)?8:0) \
+((x&0x000F0000UL)?16:0) \
+((x&0x00F00000UL)?32:0) \
+((x&0x0F000000UL)?64:0) \
+((x&0xF0000000UL)?128:0))
#define TU_BIN8(d) ((uint8_t) _B8__(0x##d##UL))
#define TU_BIN16(dmsb,dlsb) (((uint16_t)TU_BIN8(dmsb)<<8) + TU_BIN8(dlsb))
#define TU_BIN32(dmsb,db2,db3,dlsb) \
(((uint32_t)TU_BIN8(dmsb)<<24) \
+ ((uint32_t)TU_BIN8(db2)<<16) \
+ ((uint32_t)TU_BIN8(db3)<<8) \
+ TU_BIN8(dlsb))
#endif
#define TU_BIT(n) (1U << (n))
// for declaration of reserved field, make use of _TU_COUNTER_
#define TU_RESERVED XSTRING_CONCAT_(reserved, _TU_COUNTER_)
#define TU_RESERVED XSTRING_CONCAT_(reserved, _TU_COUNTER_)
//--------------------------------------------------------------------+
// INCLUDES
@@ -113,54 +75,28 @@
#include "tusb_option.h"
#include "tusb_compiler.h"
#include "tusb_verify.h"
#include "tusb_error.h"
#include "tusb_error.h" // TODO remove
#include "tusb_timeout.h"
#include "tusb_types.h"
//--------------------------------------------------------------------+
// INLINE FUNCTION
//--------------------------------------------------------------------+
#ifndef __n2be_16 // TODO clean up
#define __n2be_16(u16) ((uint16_t) ((U16_LOW_U8(u16) << 8) | U16_HIGH_U8(u16)) )
#define __be2n_16(u16) __n2be_16(u16)
#endif
#define tu_memclr(buffer, size) memset((buffer), 0, (size))
#define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var)))
static inline bool tu_mem_test_zero (void const* buffer, uint32_t size)
{
uint8_t const* p_mem = (uint8_t const*) buffer;
for(uint32_t i=0; i<size; i++) if (p_mem[i] != 0) return false;
return true;
}
//------------- Conversion -------------//
static inline uint32_t tu_u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4)
static inline uint32_t tu_u32(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4)
{
return ( ((uint32_t) b1) << 24) + ( ((uint32_t) b2) << 16) + ( ((uint32_t) b3) << 8) + b4;
}
static inline uint16_t tu_u16_from_u8(uint8_t high, uint8_t low)
static inline uint16_t tu_u16(uint8_t high, uint8_t low)
{
return (((uint16_t) high) << 8) + low;
}
static inline uint8_t tu_u16_high(uint16_t u16)
{
return (uint8_t) ( ((uint16_t) (u16 >> 8)) & 0x00ff);
}
static inline uint8_t tu_u16_low(uint16_t u16)
{
return (uint8_t) (u16 & 0x00ff);
}
static inline uint16_t tu_u16_le2be(uint16_t u16)
{
return ((uint16_t)(tu_u16_low(u16) << 8)) | tu_u16_high(u16);
}
static inline uint8_t tu_u16_high(uint16_t u16) { return (uint8_t) (((uint16_t) (u16 >> 8)) & 0x00ff); }
static inline uint8_t tu_u16_low (uint16_t u16) { return (uint8_t) (u16 & 0x00ff); }
// Min
static inline uint8_t tu_min8 (uint8_t x, uint8_t y ) { return (x < y) ? x : y; }
@@ -175,9 +111,7 @@ static inline uint32_t tu_max32 (uint32_t x, uint32_t y) { return (x > y) ? x :
// Align
static inline uint32_t tu_align32 (uint32_t value) { return (value & 0xFFFFFFE0UL); }
static inline uint32_t tu_align16 (uint32_t value) { return (value & 0xFFFFFFF0UL); }
static inline uint32_t tu_align_n (uint32_t alignment, uint32_t value) { return value & ((uint32_t) ~(alignment-1)); }
static inline uint32_t tu_align4k (uint32_t value) { return (value & 0xFFFFF000UL); }
static inline uint32_t tu_offset4k(uint32_t value) { return (value & 0xFFFUL); }
//------------- Mathematics -------------//
@@ -190,7 +124,7 @@ static inline bool tu_within(uint32_t lower, uint32_t value, uint32_t upper)
}
// log2 of a value is its MSB's position
// TODO use clz
// TODO use clz TODO remove
static inline uint8_t tu_log2(uint32_t value)
{
uint8_t result = 0;
@@ -203,9 +137,9 @@ static inline uint8_t tu_log2(uint32_t value)
}
// Bit
static inline uint32_t tu_bit_set(uint32_t value, uint8_t n) { return value | TU_BIT(n); }
static inline uint32_t tu_bit_set (uint32_t value, uint8_t n) { return value | TU_BIT(n); }
static inline uint32_t tu_bit_clear(uint32_t value, uint8_t n) { return value & (~TU_BIT(n)); }
static inline bool tu_bit_test(uint32_t value, uint8_t n) { return (value & TU_BIT(n)) ? true : false; }
static inline bool tu_bit_test (uint32_t value, uint8_t n) { return (value & TU_BIT(n)) ? true : false; }
/*------------------------------------------------------------------*/
/* Count number of arguments of __VA_ARGS__
@@ -237,6 +171,35 @@ static inline bool tu_bit_test(uint32_t value, uint8_t n) { return (value & TU_B
9,8,7,6,5,4,3,2,1,0
#endif
// To be removed
//------------- Binary constant -------------//
#if defined(__GNUC__) && !defined(__CC_ARM)
#define TU_BIN8(x) ((uint8_t) (0b##x))
#define TU_BIN16(b1, b2) ((uint16_t) (0b##b1##b2))
#define TU_BIN32(b1, b2, b3, b4) ((uint32_t) (0b##b1##b2##b3##b4))
#else
// internal macro of B8, B16, B32
#define _B8__(x) (((x&0x0000000FUL)?1:0) \
+((x&0x000000F0UL)?2:0) \
+((x&0x00000F00UL)?4:0) \
+((x&0x0000F000UL)?8:0) \
+((x&0x000F0000UL)?16:0) \
+((x&0x00F00000UL)?32:0) \
+((x&0x0F000000UL)?64:0) \
+((x&0xF0000000UL)?128:0))
#define TU_BIN8(d) ((uint8_t) _B8__(0x##d##UL))
#define TU_BIN16(dmsb,dlsb) (((uint16_t)TU_BIN8(dmsb)<<8) + TU_BIN8(dlsb))
#define TU_BIN32(dmsb,db2,db3,dlsb) \
(((uint32_t)TU_BIN8(dmsb)<<24) \
+ ((uint32_t)TU_BIN8(db2)<<16) \
+ ((uint32_t)TU_BIN8(db3)<<8) \
+ TU_BIN8(dlsb))
#endif
#ifdef __cplusplus
}
#endif
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -43,27 +43,41 @@
#define _TU_COUNTER_ __LINE__
#endif
//--------------------------------------------------------------------+
// Compile-time Assert (use TU_VERIFY_STATIC to avoid name conflict)
//--------------------------------------------------------------------+
// Compile-time Assert
#if __STDC_VERSION__ >= 201112L
#define TU_VERIFY_STATIC _Static_assert
#else
#define TU_VERIFY_STATIC(const_expr, _mess) enum { XSTRING_CONCAT_(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) }
#endif
// allow debugger to watch any module-wide variables anywhere
#if CFG_TUSB_DEBUG
#define STATIC_VAR
#else
#define STATIC_VAR static
#endif
//--------------------------------------------------------------------+
// Compiler porting with Attribute and Endian
//--------------------------------------------------------------------+
#if defined(__GNUC__)
#include "compiler/tusb_compiler_gcc.h"
#elif defined __ICCARM__
#include "compiler/tusb_compiler_iar.h"
#define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
#define ATTR_SECTION(sec_name) __attribute__ ((section(#sec_name)))
#define ATTR_PACKED __attribute__ ((packed))
#define ATTR_PREPACKED
#define ATTR_WEAK __attribute__ ((weak))
#define ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used
#define ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused
// Endian conversion use well-known host to network (big endian) naming
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define tu_htonl(u32) __builtin_bswap32(u32)
#define tu_ntohl(u32) __builtin_bswap32(u32)
#define tu_htons(u16) __builtin_bswap16(u16)
#define tu_ntohs(u16) __builtin_bswap16(u16)
#else
#define tu_htonl(u32) (u32)
#define tu_ntohl(u32) (u32)
#define tu_htons(u16) (u16)
#define tu_ntohs(u16) (u16)
#endif
#else
#error "Compiler attribute porting are required"
#endif
#endif /* _TUSB_COMPILER_H_ */
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -403,10 +403,10 @@ static inline uint8_t tu_desc_len(void const* desc)
}
// Length of the string descriptors in bytes with slen characters
#define TUD_DESC_STRLEN(_slen) (2*(_slen) + 2)
#define TUD_DESC_STRLEN(_chr_count) (2*(_chr_count) + 2)
// Header of string descriptors with len + string type
#define TUD_DESC_STR_HEADER(_slen) ( (uint16_t) ( (TUSB_DESC_STRING << 8 ) | TUD_DESC_STRLEN(_slen)) )
#define TUD_DESC_STR_HEADER(_chr_count) ( (uint16_t) ( (TUSB_DESC_STRING << 8 ) | TUD_DESC_STRLEN(_chr_count)) )
// Convert comma-separated string to descriptor unicode format
#define TUD_DESC_STRCONV( ... ) (const uint16_t[]) { TUD_DESC_STR_HEADER(VA_ARGS_NUM_(__VA_ARGS__)), __VA_ARGS__ }
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -46,11 +46,10 @@
extern "C" {
#endif
//--------------------------------------------------------------------+
// TU_VERIFY Helper
//--------------------------------------------------------------------+
#if CFG_TUSB_DEBUG >= 1
#if CFG_TUSB_DEBUG
#include <stdio.h>
#define _MESS_ERR(_err) printf("%s: %d: failed, error = %s\n", __func__, __LINE__, tusb_strerr[_err])
#define _MESS_FAILED() printf("%s: %d: failed\n", __func__, __LINE__)
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -159,7 +159,7 @@ static osal_queue_t _usbd_q;
//--------------------------------------------------------------------+
static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id);
static bool process_control_request(uint8_t rhport, tusb_control_request_t const * p_request);
static bool process_set_config(uint8_t rhport);
static bool process_set_config(uint8_t rhport, uint8_t cfg_num);
static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request);
void usbd_control_reset (uint8_t rhport);
@@ -376,13 +376,13 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
dcd_set_config(rhport, cfg_num);
_usbd_dev.configured = cfg_num ? 1 : 0;
TU_ASSERT( process_set_config(rhport) );
if ( cfg_num ) TU_ASSERT( process_set_config(rhport, cfg_num) );
usbd_control_status(rhport, p_request);
}
break;
case TUSB_REQ_GET_DESCRIPTOR:
TU_ASSERT( process_get_descriptor(rhport, p_request) );
TU_VERIFY( process_get_descriptor(rhport, p_request) );
break;
case TUSB_REQ_SET_FEATURE:
@@ -477,9 +477,9 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
// Process Set Configure Request
// This function parse configuration descriptor & open drivers accordingly
static bool process_set_config(uint8_t rhport)
static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
{
tusb_desc_configuration_t const * desc_cfg = (tusb_desc_configuration_t const *) tud_desc_set.config;
tusb_desc_configuration_t const * desc_cfg = (tusb_desc_configuration_t const *) tud_descriptor_configuration_cb(cfg_num-1); // index is cfg_num-1
TU_ASSERT(desc_cfg != NULL && desc_cfg->bDescriptorType == TUSB_DESC_CONFIGURATION);
// Parse configuration descriptor
@@ -558,11 +558,14 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
switch(desc_type)
{
case TUSB_DESC_DEVICE:
return usbd_control_xfer(rhport, p_request, (void*) tud_desc_set.device, sizeof(tusb_desc_device_t));
return usbd_control_xfer(rhport, p_request, (void*) tud_descriptor_device_cb(), sizeof(tusb_desc_device_t));
break;
case TUSB_DESC_CONFIGURATION:
return usbd_control_xfer(rhport, p_request, (void*) tud_desc_set.config, ((tusb_desc_configuration_t const*) tud_desc_set.config)->wTotalLength);
{
tusb_desc_configuration_t const* desc_config = (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(desc_index);
return usbd_control_xfer(rhport, p_request, (void*) desc_config, desc_config->wTotalLength);
}
break;
case TUSB_DESC_STRING:
@@ -574,16 +577,11 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
return false;
}else
{
uint16_t desc_str[CFG_TUD_ENDOINT0_SIZE/2]; // up to endpoint0 size only
uint8_t len = 2*tud_descriptor_string_cb(desc_index, desc_str+1, CFG_TUD_ENDOINT0_SIZE/2-1);
uint8_t const* desc_str = (uint8_t const*) tud_descriptor_string_cb(desc_index);
TU_ASSERT(desc_str);
TU_ASSERT(len > 0);
// first byte of descriptor is size, second byte is string type
len += 2; // header len
desc_str[0] = tu_u16_from_u8(TUSB_DESC_STRING, len);
return usbd_control_xfer(rhport, p_request, desc_str, len);
// first byte of descriptor is its size
return usbd_control_xfer(rhport, p_request, (void*) desc_str, desc_str[0]);
}
break;
@@ -741,7 +739,7 @@ void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
uint8_t const dir = tu_edpt_dir(ep_addr);
dcd_edpt_stall(rhport, ep_addr);
_usbd_dev.ep_stall_mask[dir] = tu_bit_set(_usbd_dev.ep_stall_mask[dir], epnum);
_usbd_dev.ep_stall_mask[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_stall_mask[dir], epnum);
}
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
@@ -750,7 +748,7 @@ void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
uint8_t const dir = tu_edpt_dir(ep_addr);
dcd_edpt_clear_stall(rhport, ep_addr);
_usbd_dev.ep_stall_mask[dir] = tu_bit_clear(_usbd_dev.ep_stall_mask[dir], epnum);
_usbd_dev.ep_stall_mask[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_stall_mask[dir], epnum);
}
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -37,17 +37,6 @@
#include "common/tusb_common.h"
#include "device/dcd.h"
/// \brief Descriptor pointer collector to all the needed.
typedef struct {
void const * device; ///< pointer to device descriptor \ref tusb_desc_device_t
void const * config; ///< pointer to the whole configuration descriptor, starting by \ref tusb_desc_configuration_t
uint8_t const* hid_report;
}tud_desc_set_t;
// Descriptor collection set, must be defined by application
extern tud_desc_set_t tud_desc_set;
//--------------------------------------------------------------------+
// Application API
//--------------------------------------------------------------------+
@@ -74,10 +63,17 @@ bool tud_remote_wakeup(void);
// Application Callbacks (WEAK is optional)
//--------------------------------------------------------------------+
// Invoked when received GET_STRING_DESC request
// max_char is CFG_TUD_ENDOINT0_SIZE/2 -1, typically max_char = 31 if Endpoint0 size is 64
// Return number of characters. Note usb string is in 16-bits unicode format
uint8_t tud_descriptor_string_cb(uint8_t index, uint16_t* desc, uint8_t max_char);
// Invoked when received GET DEVICE DESCRIPTOR request
// Application return pointer to descriptor
uint8_t const * tud_descriptor_device_cb(void);
// Invoked when received GET CONFIGURATION DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
uint8_t const * tud_descriptor_configuration_cb(uint8_t index);
// 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);
// Invoked when device is mounted (configured)
ATTR_WEAK void tud_mount_cb(void);
@@ -98,7 +94,7 @@ ATTR_WEAK void tud_resume_cb(void);
#define TUD_CONFIG_DESC_LEN (9)
// Inteface count, string index, total length, attribute, power in mA
// Interface count, string index, total length, attribute, power in mA
#define TUD_CONFIG_DESCRIPTOR(_itfcount, _stridx, _total_len, _attribute, _power_ma) \
9, TUSB_DESC_CONFIGURATION, U16_TO_U8S_LE(_total_len), _itfcount, 1, _stridx, TU_BIT(7) | _attribute, (_power_ma)/2
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -93,8 +93,10 @@ bool usbd_control_xfer(uint8_t rhport, tusb_control_request_t const * request, v
_control_state.total_len = tu_min16(len, request->wLength);
_control_state.total_transferred = 0;
if ( (buffer != NULL) && len )
if ( len )
{
TU_ASSERT(buffer);
// Data stage
TU_ASSERT( start_control_data_xact(rhport) );
}else
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -375,7 +375,7 @@ void USBD_IRQHandler(void)
for(uint8_t i=0; i<USBD_INTEN_EPDATA_Pos+1; i++)
{
if ( TU_BIT_TEST(inten, i) && regevt[i] )
if ( tu_bit_test(inten, i) && regevt[i] )
{
int_status |= TU_BIT(i);
@@ -477,7 +477,7 @@ void USBD_IRQHandler(void)
*/
for(uint8_t epnum=0; epnum<8; epnum++)
{
if ( TU_BIT_TEST(int_status, USBD_INTEN_ENDEPOUT0_Pos+epnum))
if ( tu_bit_test(int_status, USBD_INTEN_ENDEPOUT0_Pos+epnum))
{
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT);
uint8_t const xact_len = NRF_USBD->EPOUT[epnum].AMOUNT;
@@ -517,7 +517,7 @@ void USBD_IRQHandler(void)
// CBI In: Endpoint -> Host (transaction complete)
for(uint8_t epnum=0; epnum<8; epnum++)
{
if ( TU_BIT_TEST(data_status, epnum ) || ( epnum == 0 && is_control_in) )
if ( tu_bit_test(data_status, epnum ) || ( epnum == 0 && is_control_in) )
{
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_IN);
@@ -538,7 +538,7 @@ void USBD_IRQHandler(void)
// CBI OUT: Host -> Endpoint
for(uint8_t epnum=0; epnum<8; epnum++)
{
if ( TU_BIT_TEST(data_status, 16+epnum ) || ( epnum == 0 && is_control_out) )
if ( tu_bit_test(data_status, 16+epnum ) || ( epnum == 0 && is_control_out) )
{
xfer_td_t* xfer = get_td(epnum, TUSB_DIR_OUT);
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -41,48 +41,48 @@
//------------- HOST -------------//
#if TUSB_OPT_HOST_ENABLED
#include "host/usbh.h"
#endif
#if HOST_CLASS_HID
#include "class/hid/hid_host.h"
#endif
#if HOST_CLASS_HID
#include "class/hid/hid_host.h"
#endif
#if CFG_TUH_MSC
#include "class/msc/msc_host.h"
#endif
#if CFG_TUH_MSC
#include "class/msc/msc_host.h"
#endif
#if CFG_TUH_CDC
#include "class/cdc/cdc_host.h"
#endif
#if CFG_TUH_CDC
#include "class/cdc/cdc_host.h"
#endif
#if CFG_TUSB_HOST_CUSTOM_CLASS
#include "class/custom_host.h"
#endif
#if CFG_TUSB_HOST_CUSTOM_CLASS
#include "class/custom_host.h"
#endif
#endif
//------------- DEVICE -------------//
#if TUSB_OPT_DEVICE_ENABLED
#include "device/usbd.h"
#endif
#if CFG_TUD_HID
#include "class/hid/hid_device.h"
#endif
#if CFG_TUD_HID
#include "class/hid/hid_device.h"
#endif
#if CFG_TUD_CDC
#include "class/cdc/cdc_device.h"
#endif
#if CFG_TUD_CDC
#include "class/cdc/cdc_device.h"
#endif
#if CFG_TUD_MSC
#include "class/msc/msc_device.h"
#endif
#if CFG_TUD_MSC
#include "class/msc/msc_device.h"
#endif
#if CFG_TUD_MIDI
#include "class/midi/midi_device.h"
#endif
#if CFG_TUD_MIDI
#include "class/midi/midi_device.h"
#endif
#if CFG_TUD_CUSTOM_CLASS
#include "class/custom/custom_device.h"
#if CFG_TUD_CUSTOM_CLASS
#include "class/custom/custom_device.h"
#endif
#endif
@@ -101,20 +101,6 @@ bool tusb_inited(void);
// TODO
// bool tusb_teardown(void);
// backward compatible only. TODO remove later
ATTR_DEPRECATED("Please use either tud_task() or tuh_task()")
static inline void tusb_task(void)
{
#if TUSB_OPT_HOST_ENABLED
tuh_task();
#endif
#if TUSB_OPT_DEVICE_ENABLED
tud_task();
#endif
}
/** @} */
#ifdef __cplusplus
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach (tinyusb.org)
* 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
@@ -119,13 +119,8 @@
//--------------------------------------------------------------------+
// COMMON OPTIONS
//--------------------------------------------------------------------+
/**
determines the debug level for the stack
- Level 3: TBD
- Level 2: TBD
- Level 1: Print out if Assert failed. STATIC_VAR is NULL --> accessible when debugging
- Level 0: no debug information is generated
*/
// Debug enable to print out error message
#ifndef CFG_TUSB_DEBUG
#define CFG_TUSB_DEBUG 0
#endif
@@ -136,24 +131,21 @@
#endif
#ifndef CFG_TUSB_MEM_ALIGN
#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4)
#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4)
#endif
#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
#define CFG_TUSB_OS OPT_OS_NONE
#endif
//--------------------------------------------------------------------
// DEVICE OPTIONS
//--------------------------------------------------------------------
#ifndef CFG_TUD_ENDOINT0_SIZE
#define CFG_TUD_ENDOINT0_SIZE 64
#endif
#ifndef CFG_TUD_CTRL_BUFSIZE
#define CFG_TUD_CTRL_BUFSIZE 256
#endif
#ifndef CFG_TUD_CDC
#define CFG_TUD_CDC 0
#endif
+4 -4
View File
@@ -128,10 +128,10 @@ void flash_qspi_init (void)
.pins = {
.sck_pin = g_ADigitalPinMap[PIN_QSPI_SCK],
.csn_pin = g_ADigitalPinMap[PIN_QSPI_CS],
.io0_pin = g_ADigitalPinMap[PIN_QSPI_DATA0],
.io1_pin = g_ADigitalPinMap[PIN_QSPI_DATA1],
.io2_pin = g_ADigitalPinMap[PIN_QSPI_DATA2],
.io3_pin = g_ADigitalPinMap[PIN_QSPI_DATA3],
.io0_pin = g_ADigitalPinMap[PIN_QSPI_IO0],
.io1_pin = g_ADigitalPinMap[PIN_QSPI_IO1],
.io2_pin = g_ADigitalPinMap[PIN_QSPI_IO2],
.io3_pin = g_ADigitalPinMap[PIN_QSPI_IO3],
},
.prot_if = {
.readoc = NRF_QSPI_READOC_READ4IO,
@@ -41,8 +41,8 @@
#include "BLECharacteristic.h"
#include "BLEService.h"
// for HID definitions
#include "tusb.h"
// include usb hid definitions
#include "class/hid/hid.h"
enum
{
@@ -104,8 +104,5 @@ void initVariant()
pinMode(PIN_LED2, OUTPUT);
ledOff(PIN_LED2);
// Init External Flash
flash_qspi_init();
}
+5 -7
View File
@@ -122,15 +122,13 @@ static const uint8_t SCK = PIN_SPI_SCK ;
#define PIN_WIRE_SDA (22)
#define PIN_WIRE_SCL (23)
/*
* QSPI interface for external flash
*/
// QSPI Pins
#define PIN_QSPI_SCK 27
#define PIN_QSPI_CS 28
#define PIN_QSPI_DATA0 29
#define PIN_QSPI_DATA1 30
#define PIN_QSPI_DATA2 31
#define PIN_QSPI_DATA3 32
#define PIN_QSPI_IO0 29
#define PIN_QSPI_IO1 30
#define PIN_QSPI_IO2 31
#define PIN_QSPI_IO3 32
// On-board QSPI Flash
#define EXTERNAL_FLASH_DEVICES GD25Q16C
+7 -9
View File
@@ -122,15 +122,13 @@ static const uint8_t SCK = PIN_SPI_SCK ;
#define PIN_WIRE_SDA (22)
#define PIN_WIRE_SCL (23)
/*
* QSPI interface for external flash
*/
#define PIN_QSPI_SCK 27
#define PIN_QSPI_CS 28
#define PIN_QSPI_DATA0 29
#define PIN_QSPI_DATA1 30
#define PIN_QSPI_DATA2 31
#define PIN_QSPI_DATA3 32
// QSPI Pins
#define PIN_QSPI_SCK 27
#define PIN_QSPI_CS 28
#define PIN_QSPI_IO0 29
#define PIN_QSPI_IO1 30
#define PIN_QSPI_IO2 31
#define PIN_QSPI_IO3 32
// On-board QSPI Flash
// If EXTERNAL_FLASH_DEVICES is not defined, all supported devices will be used
+1 -4
View File
@@ -45,9 +45,6 @@ void initVariant()
ledOff(PIN_LED1);
pinMode(PIN_LED2, OUTPUT);
ledOff(PIN_LED2);
// Init External Flash
flash_qspi_init();
ledOff(PIN_LED2);;
}
+5 -7
View File
@@ -114,15 +114,13 @@ static const uint8_t SCK = PIN_SPI_SCK ;
#define PIN_WIRE_SDA (26)
#define PIN_WIRE_SCL (27)
/*
* QSPI interface for external flash
*/
// QSPI Pins
#define PIN_QSPI_SCK 19
#define PIN_QSPI_CS 17
#define PIN_QSPI_DATA0 20
#define PIN_QSPI_DATA1 21
#define PIN_QSPI_DATA2 22
#define PIN_QSPI_DATA3 23
#define PIN_QSPI_IO0 20
#define PIN_QSPI_IO1 21
#define PIN_QSPI_IO2 22
#define PIN_QSPI_IO3 23
// On-board QSPI Flash
#define EXTERNAL_FLASH_DEVICES MX25R6435F