Skip to content

Commit

Permalink
Update tinyusb to 0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
Ultrawipf committed Nov 18, 2024
1 parent ce23127 commit 5f23403
Show file tree
Hide file tree
Showing 173 changed files with 57,915 additions and 10,482 deletions.
2 changes: 1 addition & 1 deletion Firmware/FFBoard/Src/global_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void tud_cdc_tx_complete_cb(uint8_t itf){
* HID Out and Set Feature
*/
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){
if(report_type == HID_REPORT_TYPE_INVALID && report_id == 0){
if((report_type == HID_REPORT_TYPE_INVALID || report_type == HID_REPORT_TYPE_OUTPUT) && report_id == 0){
report_id = *buffer;
}

Expand Down
37 changes: 32 additions & 5 deletions Firmware/FFBoard/USB/class/audio/audio.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
Expand Down Expand Up @@ -489,7 +489,7 @@ typedef enum
AUDIO_DATA_FORMAT_TYPE_I_IEEE_FLOAT = (uint32_t) (1 << 2),
AUDIO_DATA_FORMAT_TYPE_I_ALAW = (uint32_t) (1 << 3),
AUDIO_DATA_FORMAT_TYPE_I_MULAW = (uint32_t) (1 << 4),
AUDIO_DATA_FORMAT_TYPE_I_RAW_DATA = 0x80000000,
AUDIO_DATA_FORMAT_TYPE_I_RAW_DATA = 0x80000000u,
} audio_data_format_type_I_t;

/// All remaining definitions are taken from the descriptor descriptions in the UAC2 main specification
Expand Down Expand Up @@ -640,7 +640,7 @@ typedef enum
AUDIO_CHANNEL_CONFIG_BOTTOM_CENTER = 0x01000000,
AUDIO_CHANNEL_CONFIG_BACK_LEFT_OF_CENTER = 0x02000000,
AUDIO_CHANNEL_CONFIG_BACK_RIGHT_OF_CENTER = 0x04000000,
AUDIO_CHANNEL_CONFIG_RAW_DATA = 0x80000000,
AUDIO_CHANNEL_CONFIG_RAW_DATA = 0x80000000u,
} audio_channel_config_t;

/// AUDIO Channel Cluster Descriptor (4.1)
Expand Down Expand Up @@ -721,11 +721,13 @@ typedef struct TU_ATTR_PACKED
uint8_t bLength ; ///< Size of this descriptor, in bytes: 17.
uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AC_INTERFACE_INPUT_TERMINAL.
uint8_t bTerminalID ; ///< Constant uniquely identifying the Terminal within the audio function. This value is used in all requests to address this terminal.
uint16_t wTerminalType ; ///< Constant characterizing the type of Terminal. See: audio_terminal_type_t for USB streaming and audio_terminal_input_type_t for other input types.
uint8_t bAssocTerminal ; ///< ID of the Output Terminal to which this Input Terminal is associated.
uint8_t bCSourceID ; ///< ID of the Clock Entity to which this Input Terminal is connected.
uint8_t bNrChannels ; ///< Number of logical output channels in the Terminal’s output audio channel cluster.
uint32_t bmChannelConfig ; ///< Describes the spatial location of the logical channels. See:audio_channel_config_t.
uint8_t iChannelNames ; ///< Index of a string descriptor, describing the name of the first logical channel.
uint16_t bmControls ; ///< See: audio_terminal_input_control_pos_t.
uint8_t iTerminal ; ///< Index of a string descriptor, describing the Input Terminal.
} audio_desc_input_terminal_t;
Expand Down Expand Up @@ -822,10 +824,10 @@ typedef struct TU_ATTR_PACKED
uint8_t type : 2; ///< Request type tusb_request_type_t.
uint8_t direction : 1; ///< Direction type. tusb_dir_t
} bmRequestType_bit;

uint8_t bmRequestType;
};

uint8_t bRequest; ///< Request type audio_cs_req_t
uint8_t bChannelNumber;
uint8_t bControlSelector;
Expand Down Expand Up @@ -922,6 +924,31 @@ typedef struct TU_ATTR_PACKED {
} subrange[numSubRanges]; \
}

// 6.1 Interrupt Data Message Format
typedef struct TU_ATTR_PACKED
{
uint8_t bInfo;
uint8_t bAttribute;
union
{
uint16_t wValue;
struct
{
uint8_t wValue_cn_or_mcn;
uint8_t wValue_cs;
};
};
union
{
uint16_t wIndex;
struct
{
uint8_t wIndex_ep_or_int;
uint8_t wIndex_entity_id;
};
};
} audio_interrupt_data_t;

/** @} */

#ifdef __cplusplus
Expand Down
1,693 changes: 1,154 additions & 539 deletions Firmware/FFBoard/USB/class/audio/audio_device.c

Large diffs are not rendered by default.

159 changes: 121 additions & 38 deletions Firmware/FFBoard/USB/class/audio/audio_device.h

Large diffs are not rendered by default.

66 changes: 51 additions & 15 deletions Firmware/FFBoard/USB/class/bth/bth_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "tusb_option.h"

#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_BTH)
#if (CFG_TUD_ENABLED && CFG_TUD_BTH)

//--------------------------------------------------------------------+
// INCLUDE
Expand All @@ -42,10 +42,14 @@ typedef struct
uint8_t itf_num;
uint8_t ep_ev;
uint8_t ep_acl_in;
uint16_t ep_acl_in_pkt_sz;
uint8_t ep_acl_out;
uint8_t ep_voice[2]; // Not used yet
uint8_t ep_voice_size[2][CFG_TUD_BTH_ISO_ALT_COUNT];

// Previous amount of bytes sent when issuing ZLP
uint32_t prev_xferred_bytes;

// Endpoint Transfer buffer
CFG_TUSB_MEM_ALIGN bt_hci_cmd_t hci_cmd;
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_BTH_DATA_EPSIZE];
Expand All @@ -55,14 +59,16 @@ typedef struct
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION btd_interface_t _btd_itf;
CFG_TUD_MEM_SECTION btd_interface_t _btd_itf;

static bool bt_tx_data(uint8_t ep, void *data, uint16_t len)
{
uint8_t const rhport = 0;

// skip if previous transfer not complete
TU_VERIFY(!usbd_edpt_busy(TUD_OPT_RHPORT, ep));
TU_VERIFY(!usbd_edpt_busy(rhport, ep));

TU_ASSERT(usbd_edpt_xfer(TUD_OPT_RHPORT, ep, data, len));
TU_ASSERT(usbd_edpt_xfer(rhport, ep, data, len));

return true;
}
Expand All @@ -89,11 +95,14 @@ bool tud_bt_acl_data_send(void *event, uint16_t event_len)
//--------------------------------------------------------------------+
// USBD Driver API
//--------------------------------------------------------------------+
void btd_init(void)
{
void btd_init(void) {
tu_memclr(&_btd_itf, sizeof(_btd_itf));
}

bool btd_deinit(void) {
return true;
}

void btd_reset(uint8_t rhport)
{
(void)rhport;
Expand Down Expand Up @@ -122,11 +131,25 @@ uint16_t btd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_
TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
_btd_itf.ep_ev = desc_ep->bEndpointAddress;

desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(desc_ep);

// Open endpoint pair
TU_ASSERT(usbd_open_edpt_pair(rhport, tu_desc_next(desc_ep), 2, TUSB_XFER_BULK, &_btd_itf.ep_acl_out,
&_btd_itf.ep_acl_in), 0);
TU_ASSERT(usbd_open_edpt_pair(rhport, (uint8_t const *)desc_ep, 2,
TUSB_XFER_BULK, &_btd_itf.ep_acl_out,
&_btd_itf.ep_acl_in),
0);

// Save acl in endpoint max packet size
tusb_desc_endpoint_t const *desc_ep_acl_in = desc_ep;
for (size_t p = 0; p < 2; p++) {
if (tu_edpt_dir(desc_ep_acl_in->bEndpointAddress) == TUSB_DIR_IN) {
_btd_itf.ep_acl_in_pkt_sz = tu_edpt_packet_size(desc_ep_acl_in);
break;
}
desc_ep_acl_in = (tusb_desc_endpoint_t const *)tu_desc_next(desc_ep_acl_in);
}

itf_desc = (tusb_desc_interface_t const *)tu_desc_next(tu_desc_next(tu_desc_next(desc_ep)));
itf_desc = (tusb_desc_interface_t const *)tu_desc_next(tu_desc_next(desc_ep));

// Prepare for incoming data from host
TU_ASSERT(usbd_edpt_xfer(rhport, _btd_itf.ep_acl_out, _btd_itf.epout_buf, CFG_TUD_BTH_DATA_EPSIZE), 0);
Expand Down Expand Up @@ -202,7 +225,9 @@ bool btd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t c
request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_DEVICE)
{
// HCI command packet addressing for single function Primary Controllers
TU_VERIFY(request->bRequest == 0 && request->wValue == 0 && request->wIndex == 0);
// also compatible with historical mode if enabled
TU_VERIFY((request->bRequest == 0 && request->wValue == 0 && request->wIndex == 0) ||
(CFG_TUD_BTH_HISTORICAL_COMPATIBLE && request->bRequest == 0xe0));
}
else if (request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE)
{
Expand Down Expand Up @@ -231,10 +256,8 @@ bool btd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t c
return true;
}

bool btd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
{
(void)result;

bool btd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result,
uint32_t xferred_bytes) {
// received new data from host
if (ep_addr == _btd_itf.ep_acl_out)
{
Expand All @@ -249,7 +272,20 @@ bool btd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t
}
else if (ep_addr == _btd_itf.ep_acl_in)
{
if (tud_bt_acl_data_sent_cb) tud_bt_acl_data_sent_cb((uint16_t)xferred_bytes);
if ((result == XFER_RESULT_SUCCESS) && (xferred_bytes > 0) &&
((xferred_bytes & (_btd_itf.ep_acl_in_pkt_sz - 1)) == 0)) {
// Save number of transferred bytes
_btd_itf.prev_xferred_bytes = xferred_bytes;

// Send zero-length packet
tud_bt_acl_data_send(NULL, 0);
} else if (tud_bt_acl_data_sent_cb) {
if (xferred_bytes == 0) {
xferred_bytes = _btd_itf.prev_xferred_bytes;
_btd_itf.prev_xferred_bytes = 0;
}
tud_bt_acl_data_sent_cb((uint16_t)xferred_bytes);
}
}

return true;
Expand Down
10 changes: 9 additions & 1 deletion Firmware/FFBoard/USB/class/bth/bth_device.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Jerzy Kasenberg
Expand Down Expand Up @@ -36,10 +36,17 @@
#ifndef CFG_TUD_BTH_EVENT_EPSIZE
#define CFG_TUD_BTH_EVENT_EPSIZE 16
#endif

#ifndef CFG_TUD_BTH_DATA_EPSIZE
#define CFG_TUD_BTH_DATA_EPSIZE 64
#endif

// Allow BTH class to work in historically compatibility mode where the bRequest is always 0xe0.
// See Bluetooth Core v5.3, Vol. 4, Part B, Section 2.2
#ifndef CFG_TUD_BTH_HISTORICAL_COMPATIBLE
#define CFG_TUD_BTH_HISTORICAL_COMPATIBLE 0
#endif

typedef struct TU_ATTR_PACKED
{
uint16_t op_code;
Expand Down Expand Up @@ -97,6 +104,7 @@ bool tud_bt_acl_data_send(void *acl_data, uint16_t data_len);
// Internal Class Driver API
//--------------------------------------------------------------------+
void btd_init (void);
bool btd_deinit (void);
void btd_reset (uint8_t rhport);
uint16_t btd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
bool btd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
Expand Down
55 changes: 35 additions & 20 deletions Firmware/FFBoard/USB/class/cdc/cdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@
/** \defgroup ClassDriver_CDC_Common Common Definitions
* @{ */

// TODO remove
/// CDC Pipe ID, used to indicate which pipe the API is addressing to (Notification, Out, In)
typedef enum
{
CDC_PIPE_NOTIFICATION , ///< Notification pipe
CDC_PIPE_DATA_IN , ///< Data in pipe
CDC_PIPE_DATA_OUT , ///< Data out pipe
CDC_PIPE_ERROR , ///< Invalid Pipe ID
}cdc_pipeid_t;

//--------------------------------------------------------------------+
// CDC Communication Interface Class
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -146,8 +136,7 @@ typedef enum{
//--------------------------------------------------------------------+

/// Communication Interface Management Element Request Codes
typedef enum
{
typedef enum {
CDC_REQUEST_SEND_ENCAPSULATED_COMMAND = 0x00, ///< is used to issue a command in the format of the supported control protocol of the Communications Class interface
CDC_REQUEST_GET_ENCAPSULATED_RESPONSE = 0x01, ///< is used to request a response in the format of the supported control protocol of the Communications Class interface.
CDC_REQUEST_SET_COMM_FEATURE = 0x02,
Expand Down Expand Up @@ -190,15 +179,38 @@ typedef enum
CDC_REQUEST_GET_ATM_VC_STATISTICS = 0x53,

CDC_REQUEST_MDLM_SEMANTIC_MODEL = 0x60,
}cdc_management_request_t;
} cdc_management_request_t;

typedef enum {
CDC_CONTROL_LINE_STATE_DTR = 0x01,
CDC_CONTROL_LINE_STATE_RTS = 0x02,
} cdc_control_line_state_t;

typedef enum {
CDC_LINE_CODING_STOP_BITS_1 = 0, // 1 bit
CDC_LINE_CODING_STOP_BITS_1_5 = 1, // 1.5 bits
CDC_LINE_CODING_STOP_BITS_2 = 2, // 2 bits
} cdc_line_coding_stopbits_t;

// TODO Backward compatible for typos. Maybe removed in the future release
#define CDC_LINE_CONDING_STOP_BITS_1 CDC_LINE_CODING_STOP_BITS_1
#define CDC_LINE_CONDING_STOP_BITS_1_5 CDC_LINE_CODING_STOP_BITS_1_5
#define CDC_LINE_CONDING_STOP_BITS_2 CDC_LINE_CODING_STOP_BITS_2

typedef enum {
CDC_LINE_CODING_PARITY_NONE = 0,
CDC_LINE_CODING_PARITY_ODD = 1,
CDC_LINE_CODING_PARITY_EVEN = 2,
CDC_LINE_CODING_PARITY_MARK = 3,
CDC_LINE_CODING_PARITY_SPACE = 4,
} cdc_line_coding_parity_t;

//--------------------------------------------------------------------+
// Management Elemenent Notification (Notification Endpoint)
// Management Element Notification (Notification Endpoint)
//--------------------------------------------------------------------+

/// 6.3 Notification Codes
typedef enum
{
typedef enum {
CDC_NOTIF_NETWORK_CONNECTION = 0x00, ///< This notification allows the device to notify the host about network connection status.
CDC_NOTIF_RESPONSE_AVAILABLE = 0x01, ///< This notification allows the device to notify the hostthat a response is available. This response can be retrieved with a subsequent \ref CDC_REQUEST_GET_ENCAPSULATED_RESPONSE request.
CDC_NOTIF_AUX_JACK_HOOK_STATE = 0x08,
Expand Down Expand Up @@ -365,7 +377,9 @@ typedef struct TU_ATTR_PACKED
uint32_t incoming_distinctive : 1; ///< 0 : Reports only incoming ringing. 1 : Reports incoming distinctive ringing patterns.
uint32_t dual_tone_multi_freq : 1; ///< 0 : Cannot report dual tone multi-frequency (DTMF) digits input remotely over the telephone line. 1 : Can report DTMF digits input remotely over the telephone line.
uint32_t line_state_change : 1; ///< 0 : Does not support line state change notification. 1 : Does support line state change notification
uint32_t TU_RESERVED : 26;
uint32_t TU_RESERVED0 : 2;
uint32_t TU_RESERVED1 : 16;
uint32_t TU_RESERVED2 : 8;
} bmCapabilities;
}cdc_desc_func_telephone_call_state_reporting_capabilities_t;

Expand All @@ -390,9 +404,10 @@ TU_VERIFY_STATIC(sizeof(cdc_line_coding_t) == 7, "size is not correct");

typedef struct TU_ATTR_PACKED
{
uint16_t dte_is_present : 1; ///< Indicates to DCE if DTE is presentor not. This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR.
uint16_t half_duplex_carrier_control : 1;
uint16_t : 14;
uint16_t dtr : 1;
uint16_t rts : 1;
uint16_t : 6;
uint16_t : 8;
} cdc_line_control_state_t;

TU_VERIFY_STATIC(sizeof(cdc_line_control_state_t) == 2, "size is not correct");
Expand Down
Loading

0 comments on commit 5f23403

Please sign in to comment.