forked from espressif/arduino-esp32
IDF master c13afea63 (#5214)
esp-dsp: master 7cc5073 esp-face: master 420fc7e esp-rainmaker: f1b82c7 esp32-camera: master 6f8489e esp_littlefs: master b58f00c
This commit is contained in:
@ -358,33 +358,37 @@ extern "C" {
|
||||
// Application API (Multiple Interfaces)
|
||||
// CFG_TUD_AUDIO > 1
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_audio_n_mounted (uint8_t itf);
|
||||
bool tud_audio_n_mounted (uint8_t func_id);
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
uint16_t tud_audio_n_available (uint8_t itf);
|
||||
uint16_t tud_audio_n_read (uint8_t itf, void* buffer, uint16_t bufsize);
|
||||
bool tud_audio_n_clear_ep_out_ff (uint8_t itf); // Delete all content in the EP OUT FIFO
|
||||
uint16_t tud_audio_n_available (uint8_t func_id);
|
||||
uint16_t tud_audio_n_read (uint8_t func_id, void* buffer, uint16_t bufsize);
|
||||
bool tud_audio_n_clear_ep_out_ff (uint8_t func_id); // Delete all content in the EP OUT FIFO
|
||||
tu_fifo_t* tud_audio_n_get_ep_out_ff (uint8_t func_id);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
bool tud_audio_n_clear_rx_support_ff (uint8_t itf, uint8_t channelId); // Delete all content in the support RX FIFOs
|
||||
uint16_t tud_audio_n_available_support_ff (uint8_t itf, uint8_t channelId);
|
||||
uint16_t tud_audio_n_read_support_ff (uint8_t itf, uint8_t channelId, void* buffer, uint16_t bufsize);
|
||||
bool tud_audio_n_clear_rx_support_ff (uint8_t func_id, uint8_t ff_idx); // Delete all content in the support RX FIFOs
|
||||
uint16_t tud_audio_n_available_support_ff (uint8_t func_id, uint8_t ff_idx);
|
||||
uint16_t tud_audio_n_read_support_ff (uint8_t func_id, uint8_t ff_idx, void* buffer, uint16_t bufsize);
|
||||
tu_fifo_t* tud_audio_n_get_rx_support_ff (uint8_t func_id, uint8_t ff_idx);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
uint16_t tud_audio_n_write (uint8_t itf, const void * data, uint16_t len);
|
||||
bool tud_audio_n_clear_ep_in_ff (uint8_t itf); // Delete all content in the EP IN FIFO
|
||||
uint16_t tud_audio_n_write (uint8_t func_id, const void * data, uint16_t len);
|
||||
bool tud_audio_n_clear_ep_in_ff (uint8_t func_id); // Delete all content in the EP IN FIFO
|
||||
tu_fifo_t* tud_audio_n_get_ep_in_ff (uint8_t func_id);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
uint16_t tud_audio_n_flush_tx_support_ff (uint8_t itf); // Force all content in the support TX FIFOs to be written into EP SW FIFO
|
||||
bool tud_audio_n_clear_tx_support_ff (uint8_t itf, uint8_t channelId);
|
||||
uint16_t tud_audio_n_write_support_ff (uint8_t itf, uint8_t channelId, const void * data, uint16_t len);
|
||||
uint16_t tud_audio_n_flush_tx_support_ff (uint8_t func_id); // Force all content in the support TX FIFOs to be written into EP SW FIFO
|
||||
bool tud_audio_n_clear_tx_support_ff (uint8_t func_id, uint8_t ff_idx);
|
||||
uint16_t tud_audio_n_write_support_ff (uint8_t func_id, uint8_t ff_idx, const void * data, uint16_t len);
|
||||
tu_fifo_t* tud_audio_n_get_tx_support_ff (uint8_t func_id, uint8_t ff_idx);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
|
||||
uint16_t tud_audio_int_ctr_n_write (uint8_t itf, uint8_t const* buffer, uint16_t len);
|
||||
uint16_t tud_audio_int_ctr_n_write (uint8_t func_id, uint8_t const* buffer, uint16_t len);
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -399,12 +403,14 @@ static inline bool tud_audio_mounted (void);
|
||||
static inline uint16_t tud_audio_available (void);
|
||||
static inline bool tud_audio_clear_ep_out_ff (void); // Delete all content in the EP OUT FIFO
|
||||
static inline uint16_t tud_audio_read (void* buffer, uint16_t bufsize);
|
||||
static inline tu_fifo_t* tud_audio_get_ep_out_ff (void);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
static inline bool tud_audio_clear_rx_support_ff (uint8_t channelId);
|
||||
static inline uint16_t tud_audio_available_support_ff (uint8_t channelId);
|
||||
static inline uint16_t tud_audio_read_support_ff (uint8_t channelId, void* buffer, uint16_t bufsize);
|
||||
static inline bool tud_audio_clear_rx_support_ff (uint8_t ff_idx);
|
||||
static inline uint16_t tud_audio_available_support_ff (uint8_t ff_idx);
|
||||
static inline uint16_t tud_audio_read_support_ff (uint8_t ff_idx, void* buffer, uint16_t bufsize);
|
||||
static inline tu_fifo_t* tud_audio_get_rx_support_ff (uint8_t ff_idx);
|
||||
#endif
|
||||
|
||||
// TX API
|
||||
@ -412,12 +418,14 @@ static inline uint16_t tud_audio_read_support_ff (uint8_t channelId,
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
static inline uint16_t tud_audio_write (const void * data, uint16_t len);
|
||||
static inline bool tud_audio_clear_ep_in_ff (void);
|
||||
static inline tu_fifo_t* tud_audio_get_ep_in_ff (void);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
static inline uint16_t tud_audio_flush_tx_support_ff (void);
|
||||
static inline uint16_t tud_audio_clear_tx_support_ff (uint8_t channelId);
|
||||
static inline uint16_t tud_audio_write_support_ff (uint8_t channelId, const void * data, uint16_t len);
|
||||
static inline uint16_t tud_audio_clear_tx_support_ff (uint8_t ff_idx);
|
||||
static inline uint16_t tud_audio_write_support_ff (uint8_t ff_idx, const void * data, uint16_t len);
|
||||
static inline tu_fifo_t* tud_audio_get_tx_support_ff (uint8_t ff_idx);
|
||||
#endif
|
||||
|
||||
// INT CTR API
|
||||
@ -439,13 +447,13 @@ bool tud_audio_buffer_and_schedule_control_xfer(uint8_t rhport, tusb_control_req
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN
|
||||
TU_ATTR_WEAK bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t itf, uint8_t ep_in, uint8_t cur_alt_setting);
|
||||
TU_ATTR_WEAK bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uint8_t itf, uint8_t ep_in, uint8_t cur_alt_setting);
|
||||
TU_ATTR_WEAK bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t func_id, uint8_t ep_in, uint8_t cur_alt_setting);
|
||||
TU_ATTR_WEAK bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uint8_t func_id, uint8_t ep_in, uint8_t cur_alt_setting);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
|
||||
TU_ATTR_WEAK bool tud_audio_rx_done_pre_read_cb(uint8_t rhport, uint16_t n_bytes_received, uint8_t itf, uint8_t ep_out, uint8_t cur_alt_setting);
|
||||
TU_ATTR_WEAK bool tud_audio_rx_done_post_read_cb(uint8_t rhport, uint16_t n_bytes_received, uint8_t itf, uint8_t ep_out, uint8_t cur_alt_setting);
|
||||
TU_ATTR_WEAK bool tud_audio_rx_done_pre_read_cb(uint8_t rhport, uint16_t n_bytes_received, uint8_t func_id, uint8_t ep_out, uint8_t cur_alt_setting);
|
||||
TU_ATTR_WEAK bool tud_audio_rx_done_post_read_cb(uint8_t rhport, uint16_t n_bytes_received, uint8_t func_id, uint8_t ep_out, uint8_t cur_alt_setting);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
|
||||
@ -454,7 +462,7 @@ TU_ATTR_WEAK bool tud_audio_fb_done_cb(uint8_t rhport);
|
||||
// Value will be corrected for FS to 10.14 format automatically.
|
||||
// (see Universal Serial Bus Specification Revision 2.0 5.12.4.2).
|
||||
// Feedback value will be sent at FB endpoint interval till it's changed.
|
||||
bool tud_audio_n_fb_set(uint8_t itf, uint32_t feedback);
|
||||
bool tud_audio_n_fb_set(uint8_t func_id, uint32_t feedback);
|
||||
static inline bool tud_audio_fb_set(uint32_t feedback);
|
||||
#endif
|
||||
|
||||
@ -514,23 +522,33 @@ static inline bool tud_audio_clear_ep_out_ff(void)
|
||||
return tud_audio_n_clear_ep_out_ff(0);
|
||||
}
|
||||
|
||||
static inline tu_fifo_t* tud_audio_get_ep_out_ff(void)
|
||||
{
|
||||
return tud_audio_n_get_ep_out_ff(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
|
||||
|
||||
static inline bool tud_audio_clear_rx_support_ff(uint8_t channelId)
|
||||
static inline bool tud_audio_clear_rx_support_ff(uint8_t ff_idx)
|
||||
{
|
||||
return tud_audio_n_clear_rx_support_ff(0, channelId);
|
||||
return tud_audio_n_clear_rx_support_ff(0, ff_idx);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_available_support_ff(uint8_t channelId)
|
||||
static inline uint16_t tud_audio_available_support_ff(uint8_t ff_idx)
|
||||
{
|
||||
return tud_audio_n_available_support_ff(0, channelId);
|
||||
return tud_audio_n_available_support_ff(0, ff_idx);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_read_support_ff(uint8_t channelId, void* buffer, uint16_t bufsize)
|
||||
static inline uint16_t tud_audio_read_support_ff(uint8_t ff_idx, void* buffer, uint16_t bufsize)
|
||||
{
|
||||
return tud_audio_n_read_support_ff(0, channelId, buffer, bufsize);
|
||||
return tud_audio_n_read_support_ff(0, ff_idx, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline tu_fifo_t* tud_audio_get_rx_support_ff(uint8_t ff_idx)
|
||||
{
|
||||
return tud_audio_n_get_rx_support_ff(0, ff_idx);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -549,6 +567,11 @@ static inline bool tud_audio_clear_ep_in_ff(void)
|
||||
return tud_audio_n_clear_ep_in_ff(0);
|
||||
}
|
||||
|
||||
static inline tu_fifo_t* tud_audio_get_ep_in_ff(void)
|
||||
{
|
||||
return tud_audio_n_get_ep_in_ff(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
|
||||
@ -558,14 +581,19 @@ static inline uint16_t tud_audio_flush_tx_support_ff(void)
|
||||
return tud_audio_n_flush_tx_support_ff(0);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_clear_tx_support_ff(uint8_t channelId)
|
||||
static inline uint16_t tud_audio_clear_tx_support_ff(uint8_t ff_idx)
|
||||
{
|
||||
return tud_audio_n_clear_tx_support_ff(0, channelId);
|
||||
return tud_audio_n_clear_tx_support_ff(0, ff_idx);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_write_support_ff(uint8_t channelId, const void * data, uint16_t len)
|
||||
static inline uint16_t tud_audio_write_support_ff(uint8_t ff_idx, const void * data, uint16_t len)
|
||||
{
|
||||
return tud_audio_n_write_support_ff(0, channelId, data, len);
|
||||
return tud_audio_n_write_support_ff(0, ff_idx, data, len);
|
||||
}
|
||||
|
||||
static inline tu_fifo_t* tud_audio_get_tx_support_ff(uint8_t ff_idx)
|
||||
{
|
||||
return tud_audio_n_get_tx_support_ff(0, ff_idx);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -83,7 +83,7 @@ int32_t tud_cdc_n_read_char (uint8_t itf);
|
||||
void tud_cdc_n_read_flush (uint8_t itf);
|
||||
|
||||
// Get a byte from FIFO at the specified position without removing it
|
||||
bool tud_cdc_n_peek (uint8_t itf, int pos, uint8_t* u8);
|
||||
bool tud_cdc_n_peek (uint8_t itf, uint8_t* u8);
|
||||
|
||||
// Write bytes to TX FIFO, data may remain in the FIFO for a while
|
||||
uint32_t tud_cdc_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
|
||||
@ -117,7 +117,7 @@ static inline uint32_t tud_cdc_available (void);
|
||||
static inline int32_t tud_cdc_read_char (void);
|
||||
static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize);
|
||||
static inline void tud_cdc_read_flush (void);
|
||||
static inline bool tud_cdc_peek (int pos, uint8_t* u8);
|
||||
static inline bool tud_cdc_peek (uint8_t* u8);
|
||||
|
||||
static inline uint32_t tud_cdc_write_char (char ch);
|
||||
static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize);
|
||||
@ -207,9 +207,9 @@ static inline void tud_cdc_read_flush (void)
|
||||
tud_cdc_n_read_flush(0);
|
||||
}
|
||||
|
||||
static inline bool tud_cdc_peek (int pos, uint8_t* u8)
|
||||
static inline bool tud_cdc_peek (uint8_t* u8)
|
||||
{
|
||||
return tud_cdc_n_peek(0, pos, u8);
|
||||
return tud_cdc_n_peek(0, u8);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_cdc_write_char (char ch)
|
||||
|
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2021 XMOS LIMITED
|
||||
*
|
||||
* 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_DFU_H_
|
||||
#define _TUSB_DFU_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Common Definitions
|
||||
//--------------------------------------------------------------------+
|
||||
// DFU Protocol
|
||||
typedef enum
|
||||
{
|
||||
DFU_PROTOCOL_RT = 0x01,
|
||||
DFU_PROTOCOL_DFU = 0x02,
|
||||
} dfu_protocol_type_t;
|
||||
|
||||
// DFU Descriptor Type
|
||||
typedef enum
|
||||
{
|
||||
DFU_DESC_FUNCTIONAL = 0x21,
|
||||
} dfu_descriptor_type_t;
|
||||
|
||||
// DFU Requests
|
||||
typedef enum {
|
||||
DFU_REQUEST_DETACH = 0,
|
||||
DFU_REQUEST_DNLOAD = 1,
|
||||
DFU_REQUEST_UPLOAD = 2,
|
||||
DFU_REQUEST_GETSTATUS = 3,
|
||||
DFU_REQUEST_CLRSTATUS = 4,
|
||||
DFU_REQUEST_GETSTATE = 5,
|
||||
DFU_REQUEST_ABORT = 6,
|
||||
} dfu_requests_t;
|
||||
|
||||
// DFU States
|
||||
typedef enum {
|
||||
APP_IDLE = 0,
|
||||
APP_DETACH = 1,
|
||||
DFU_IDLE = 2,
|
||||
DFU_DNLOAD_SYNC = 3,
|
||||
DFU_DNBUSY = 4,
|
||||
DFU_DNLOAD_IDLE = 5,
|
||||
DFU_MANIFEST_SYNC = 6,
|
||||
DFU_MANIFEST = 7,
|
||||
DFU_MANIFEST_WAIT_RESET = 8,
|
||||
DFU_UPLOAD_IDLE = 9,
|
||||
DFU_ERROR = 10,
|
||||
} dfu_state_t;
|
||||
|
||||
// DFU Status
|
||||
typedef enum {
|
||||
DFU_STATUS_OK = 0x00,
|
||||
DFU_STATUS_ERRTARGET = 0x01,
|
||||
DFU_STATUS_ERRFILE = 0x02,
|
||||
DFU_STATUS_ERRWRITE = 0x03,
|
||||
DFU_STATUS_ERRERASE = 0x04,
|
||||
DFU_STATUS_ERRCHECK_ERASED = 0x05,
|
||||
DFU_STATUS_ERRPROG = 0x06,
|
||||
DFU_STATUS_ERRVERIFY = 0x07,
|
||||
DFU_STATUS_ERRADDRESS = 0x08,
|
||||
DFU_STATUS_ERRNOTDONE = 0x09,
|
||||
DFU_STATUS_ERRFIRMWARE = 0x0A,
|
||||
DFU_STATUS_ERRVENDOR = 0x0B,
|
||||
DFU_STATUS_ERRUSBR = 0x0C,
|
||||
DFU_STATUS_ERRPOR = 0x0D,
|
||||
DFU_STATUS_ERRUNKNOWN = 0x0E,
|
||||
DFU_STATUS_ERRSTALLEDPKT = 0x0F,
|
||||
} dfu_device_status_t;
|
||||
|
||||
#define DFU_FUNC_ATTR_CAN_DOWNLOAD_BITMASK (1 << 0)
|
||||
#define DFU_FUNC_ATTR_CAN_UPLOAD_BITMASK (1 << 1)
|
||||
#define DFU_FUNC_ATTR_MANIFESTATION_TOLERANT_BITMASK (1 << 2)
|
||||
#define DFU_FUNC_ATTR_WILL_DETACH_BITMASK (1 << 3)
|
||||
|
||||
// DFU Status Request Payload
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bStatus;
|
||||
uint8_t bwPollTimeout[3];
|
||||
uint8_t bState;
|
||||
uint8_t iString;
|
||||
} dfu_status_req_payload_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(dfu_status_req_payload_t) == 6, "size is not correct");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_DFU_H_ */
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2021 XMOS LIMITED
|
||||
*
|
||||
* 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_DFU_DEVICE_H_
|
||||
#define _TUSB_DFU_DEVICE_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/usbd.h"
|
||||
#include "dfu.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application Callback API (weak is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
// Invoked during DFU_MANIFEST_SYNC get status request to check if firmware
|
||||
// is valid
|
||||
bool tud_dfu_firmware_valid_check_cb(void);
|
||||
|
||||
// Invoked when a DFU_DNLOAD request is received
|
||||
// This callback takes the wBlockNum chunk of length length and provides it
|
||||
// to the application at the data pointer. This data is only valid for this
|
||||
// call, so the app must use it not or copy it.
|
||||
void tud_dfu_req_dnload_data_cb(uint16_t wBlockNum, uint8_t* data, uint16_t length);
|
||||
|
||||
// Must be called when the application is done using the last block of data
|
||||
// provided by tud_dfu_req_dnload_data_cb
|
||||
void tud_dfu_dnload_complete(void);
|
||||
|
||||
// Invoked during the last DFU_DNLOAD request, signifying that the host believes
|
||||
// it is done transmitting data.
|
||||
// Return true if the application agrees there is no more data
|
||||
// Return false if the device disagrees, which will stall the pipe, and the Host
|
||||
// should initiate a recovery procedure
|
||||
bool tud_dfu_device_data_done_check_cb(void);
|
||||
|
||||
// Invoked when the Host has terminated a download or upload transfer
|
||||
TU_ATTR_WEAK void tud_dfu_abort_cb(void);
|
||||
|
||||
// Invoked when a DFU_UPLOAD request is received
|
||||
// This callback must populate data with up to length bytes
|
||||
// Return the number of bytes to write
|
||||
uint16_t tud_dfu_req_upload_data_cb(uint16_t block_num, uint8_t* data, uint16_t length);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal Class Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
void dfu_moded_init(void);
|
||||
void dfu_moded_reset(uint8_t rhport);
|
||||
uint16_t dfu_moded_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
|
||||
bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_DFU_MODE_DEVICE_H_ */
|
@ -29,36 +29,17 @@
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/usbd.h"
|
||||
#include "dfu.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Common Definitions
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// DFU Protocol
|
||||
typedef enum
|
||||
{
|
||||
DFU_PROTOCOL_RT = 1,
|
||||
DFU_PROTOCOL_DFU = 2,
|
||||
} dfu_protocol_type_t;
|
||||
|
||||
// DFU Descriptor Type
|
||||
typedef enum
|
||||
{
|
||||
DFU_DESC_FUNCTIONAL = 0x21,
|
||||
} dfu_descriptor_type_t;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application Callback API (weak is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when received new data
|
||||
TU_ATTR_WEAK void tud_dfu_runtime_reboot_to_dfu_cb(void);
|
||||
// Invoked when a DFU_DETACH request is received and bitWillDetach is set
|
||||
void tud_dfu_runtime_reboot_to_dfu_cb(void);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal Class Driver API
|
||||
@ -67,7 +48,6 @@ void dfu_rtd_init(void);
|
||||
void dfu_rtd_reset(uint8_t rhport);
|
||||
uint16_t dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
|
||||
bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
|
||||
bool dfu_rtd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -62,15 +62,15 @@ typedef enum
|
||||
{
|
||||
HID_SUBCLASS_NONE = 0, ///< No Subclass
|
||||
HID_SUBCLASS_BOOT = 1 ///< Boot Interface Subclass
|
||||
}hid_subclass_type_t;
|
||||
}hid_subclass_enum_t;
|
||||
|
||||
/// HID Protocol
|
||||
/// HID Interface Protocol
|
||||
typedef enum
|
||||
{
|
||||
HID_PROTOCOL_NONE = 0, ///< None
|
||||
HID_PROTOCOL_KEYBOARD = 1, ///< Keyboard
|
||||
HID_PROTOCOL_MOUSE = 2 ///< Mouse
|
||||
}hid_protocol_type_t;
|
||||
HID_ITF_PROTOCOL_NONE = 0, ///< None
|
||||
HID_ITF_PROTOCOL_KEYBOARD = 1, ///< Keyboard
|
||||
HID_ITF_PROTOCOL_MOUSE = 2 ///< Mouse
|
||||
}hid_interface_protocol_enum_t;
|
||||
|
||||
/// HID Descriptor Type
|
||||
typedef enum
|
||||
@ -78,7 +78,7 @@ typedef enum
|
||||
HID_DESC_TYPE_HID = 0x21, ///< HID Descriptor
|
||||
HID_DESC_TYPE_REPORT = 0x22, ///< Report Descriptor
|
||||
HID_DESC_TYPE_PHYSICAL = 0x23 ///< Physical Descriptor
|
||||
}hid_descriptor_type_t;
|
||||
}hid_descriptor_enum_t;
|
||||
|
||||
/// HID Request Report Type
|
||||
typedef enum
|
||||
@ -98,9 +98,9 @@ typedef enum
|
||||
HID_REQ_CONTROL_SET_REPORT = 0x09, ///< Set Report
|
||||
HID_REQ_CONTROL_SET_IDLE = 0x0a, ///< Set Idle
|
||||
HID_REQ_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol
|
||||
}hid_request_type_t;
|
||||
}hid_request_enum_t;
|
||||
|
||||
/// HID Country Code
|
||||
/// HID Local Code
|
||||
typedef enum
|
||||
{
|
||||
HID_LOCAL_NotSupported = 0 , ///< NotSupported
|
||||
@ -139,7 +139,14 @@ typedef enum
|
||||
HID_LOCAL_US , ///< US
|
||||
HID_LOCAL_Yugoslavia , ///< Yugoslavia
|
||||
HID_LOCAL_Turkish_F ///< Turkish-F
|
||||
} hid_country_code_t;
|
||||
} hid_local_enum_t;
|
||||
|
||||
// HID protocol value used by GetProtocol / SetProtocol
|
||||
typedef enum
|
||||
{
|
||||
HID_PROTOCOL_BOOT = 0,
|
||||
HID_PROTOCOL_REPORT = 1
|
||||
} hid_protocol_mode_enum_t;
|
||||
|
||||
/** @} */
|
||||
|
||||
@ -479,6 +486,7 @@ typedef enum
|
||||
//--------------------------------------------------------------------+
|
||||
// REPORT DESCRIPTOR
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//------------- ITEM & TAG -------------//
|
||||
#define HID_REPORT_DATA_0(data)
|
||||
#define HID_REPORT_DATA_1(data) , data
|
||||
@ -488,18 +496,31 @@ typedef enum
|
||||
#define HID_REPORT_ITEM(data, tag, type, size) \
|
||||
(((tag) << 4) | ((type) << 2) | (size)) HID_REPORT_DATA_##size(data)
|
||||
|
||||
#define RI_TYPE_MAIN 0
|
||||
#define RI_TYPE_GLOBAL 1
|
||||
#define RI_TYPE_LOCAL 2
|
||||
// Report Item Types
|
||||
enum {
|
||||
RI_TYPE_MAIN = 0,
|
||||
RI_TYPE_GLOBAL = 1,
|
||||
RI_TYPE_LOCAL = 2
|
||||
};
|
||||
|
||||
//------------- MAIN ITEMS 6.2.2.4 -------------//
|
||||
#define HID_INPUT(x) HID_REPORT_ITEM(x, 8, RI_TYPE_MAIN, 1)
|
||||
#define HID_OUTPUT(x) HID_REPORT_ITEM(x, 9, RI_TYPE_MAIN, 1)
|
||||
#define HID_COLLECTION(x) HID_REPORT_ITEM(x, 10, RI_TYPE_MAIN, 1)
|
||||
#define HID_FEATURE(x) HID_REPORT_ITEM(x, 11, RI_TYPE_MAIN, 1)
|
||||
#define HID_COLLECTION_END HID_REPORT_ITEM(x, 12, RI_TYPE_MAIN, 0)
|
||||
//------------- Main Items - HID 1.11 section 6.2.2.4 -------------//
|
||||
|
||||
//------------- INPUT, OUTPUT, FEATURE 6.2.2.5 -------------//
|
||||
// Report Item Main group
|
||||
enum {
|
||||
RI_MAIN_INPUT = 8,
|
||||
RI_MAIN_OUTPUT = 9,
|
||||
RI_MAIN_COLLECTION = 10,
|
||||
RI_MAIN_FEATURE = 11,
|
||||
RI_MAIN_COLLECTION_END = 12
|
||||
};
|
||||
|
||||
#define HID_INPUT(x) HID_REPORT_ITEM(x, RI_MAIN_INPUT , RI_TYPE_MAIN, 1)
|
||||
#define HID_OUTPUT(x) HID_REPORT_ITEM(x, RI_MAIN_OUTPUT , RI_TYPE_MAIN, 1)
|
||||
#define HID_COLLECTION(x) HID_REPORT_ITEM(x, RI_MAIN_COLLECTION , RI_TYPE_MAIN, 1)
|
||||
#define HID_FEATURE(x) HID_REPORT_ITEM(x, RI_MAIN_FEATURE , RI_TYPE_MAIN, 1)
|
||||
#define HID_COLLECTION_END HID_REPORT_ITEM(x, RI_MAIN_COLLECTION_END, RI_TYPE_MAIN, 0)
|
||||
|
||||
//------------- Input, Output, Feature - HID 1.11 section 6.2.2.5 -------------//
|
||||
#define HID_DATA (0<<0)
|
||||
#define HID_CONSTANT (1<<0)
|
||||
|
||||
@ -527,7 +548,7 @@ typedef enum
|
||||
#define HID_BITFIELD (0<<8)
|
||||
#define HID_BUFFERED_BYTES (1<<8)
|
||||
|
||||
//------------- COLLECTION ITEM 6.2.2.6 -------------//
|
||||
//------------- Collection Item - HID 1.11 section 6.2.2.6 -------------//
|
||||
enum {
|
||||
HID_COLLECTION_PHYSICAL = 0,
|
||||
HID_COLLECTION_APPLICATION,
|
||||
@ -538,49 +559,81 @@ enum {
|
||||
HID_COLLECTION_USAGE_MODIFIER
|
||||
};
|
||||
|
||||
//------------- GLOBAL ITEMS 6.2.2.7 -------------//
|
||||
#define HID_USAGE_PAGE(x) HID_REPORT_ITEM(x, 0, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_USAGE_PAGE_N(x, n) HID_REPORT_ITEM(x, 0, RI_TYPE_GLOBAL, n)
|
||||
//------------- Global Items - HID 1.11 section 6.2.2.7 -------------//
|
||||
|
||||
#define HID_LOGICAL_MIN(x) HID_REPORT_ITEM(x, 1, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_LOGICAL_MIN_N(x, n) HID_REPORT_ITEM(x, 1, RI_TYPE_GLOBAL, n)
|
||||
// Report Item Global group
|
||||
enum {
|
||||
RI_GLOBAL_USAGE_PAGE = 0,
|
||||
RI_GLOBAL_LOGICAL_MIN = 1,
|
||||
RI_GLOBAL_LOGICAL_MAX = 2,
|
||||
RI_GLOBAL_PHYSICAL_MIN = 3,
|
||||
RI_GLOBAL_PHYSICAL_MAX = 4,
|
||||
RI_GLOBAL_UNIT_EXPONENT = 5,
|
||||
RI_GLOBAL_UNIT = 6,
|
||||
RI_GLOBAL_REPORT_SIZE = 7,
|
||||
RI_GLOBAL_REPORT_ID = 8,
|
||||
RI_GLOBAL_REPORT_COUNT = 9,
|
||||
RI_GLOBAL_PUSH = 10,
|
||||
RI_GLOBAL_POP = 11
|
||||
};
|
||||
|
||||
#define HID_LOGICAL_MAX(x) HID_REPORT_ITEM(x, 2, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_LOGICAL_MAX_N(x, n) HID_REPORT_ITEM(x, 2, RI_TYPE_GLOBAL, n)
|
||||
#define HID_USAGE_PAGE(x) HID_REPORT_ITEM(x, RI_GLOBAL_USAGE_PAGE, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_USAGE_PAGE_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_USAGE_PAGE, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_PHYSICAL_MIN(x) HID_REPORT_ITEM(x, 3, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_PHYSICAL_MIN_N(x, n) HID_REPORT_ITEM(x, 3, RI_TYPE_GLOBAL, n)
|
||||
#define HID_LOGICAL_MIN(x) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MIN, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_LOGICAL_MIN_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MIN, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_PHYSICAL_MAX(x) HID_REPORT_ITEM(x, 4, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_PHYSICAL_MAX_N(x, n) HID_REPORT_ITEM(x, 4, RI_TYPE_GLOBAL, n)
|
||||
#define HID_LOGICAL_MAX(x) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MAX, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_LOGICAL_MAX_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MAX, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_UNIT_EXPONENT(x) HID_REPORT_ITEM(x, 5, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_UNIT_EXPONENT_N(x, n) HID_REPORT_ITEM(x, 5, RI_TYPE_GLOBAL, n)
|
||||
#define HID_PHYSICAL_MIN(x) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MIN, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_PHYSICAL_MIN_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MIN, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_UNIT(x) HID_REPORT_ITEM(x, 6, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_UNIT_N(x, n) HID_REPORT_ITEM(x, 6, RI_TYPE_GLOBAL, n)
|
||||
#define HID_PHYSICAL_MAX(x) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MAX, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_PHYSICAL_MAX_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MAX, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_REPORT_SIZE(x) HID_REPORT_ITEM(x, 7, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_REPORT_SIZE_N(x, n) HID_REPORT_ITEM(x, 7, RI_TYPE_GLOBAL, n)
|
||||
#define HID_UNIT_EXPONENT(x) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT_EXPONENT, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_UNIT_EXPONENT_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT_EXPONENT, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_REPORT_ID(x) HID_REPORT_ITEM(x, 8, RI_TYPE_GLOBAL, 1),
|
||||
#define HID_REPORT_ID_N(x) HID_REPORT_ITEM(x, 8, RI_TYPE_GLOBAL, n),
|
||||
#define HID_UNIT(x) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_UNIT_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_REPORT_COUNT(x) HID_REPORT_ITEM(x, 9, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_REPORT_COUNT_N(x, n) HID_REPORT_ITEM(x, 9, RI_TYPE_GLOBAL, n)
|
||||
#define HID_REPORT_SIZE(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_SIZE, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_REPORT_SIZE_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_SIZE, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_PUSH HID_REPORT_ITEM(x, 10, RI_TYPE_GLOBAL, 0)
|
||||
#define HID_POP HID_REPORT_ITEM(x, 11, RI_TYPE_GLOBAL, 0)
|
||||
#define HID_REPORT_ID(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_ID, RI_TYPE_GLOBAL, 1),
|
||||
#define HID_REPORT_ID_N(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_ID, RI_TYPE_GLOBAL, n),
|
||||
|
||||
#define HID_REPORT_COUNT(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_COUNT, RI_TYPE_GLOBAL, 1)
|
||||
#define HID_REPORT_COUNT_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_COUNT, RI_TYPE_GLOBAL, n)
|
||||
|
||||
#define HID_PUSH HID_REPORT_ITEM(x, RI_GLOBAL_PUSH, RI_TYPE_GLOBAL, 0)
|
||||
#define HID_POP HID_REPORT_ITEM(x, RI_GLOBAL_POP, RI_TYPE_GLOBAL, 0)
|
||||
|
||||
//------------- LOCAL ITEMS 6.2.2.8 -------------//
|
||||
#define HID_USAGE(x) HID_REPORT_ITEM(x, 0, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_N(x, n) HID_REPORT_ITEM(x, 0, RI_TYPE_LOCAL, n)
|
||||
|
||||
#define HID_USAGE_MIN(x) HID_REPORT_ITEM(x, 1, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_MIN_N(x, n) HID_REPORT_ITEM(x, 1, RI_TYPE_LOCAL, n)
|
||||
enum {
|
||||
RI_LOCAL_USAGE = 0,
|
||||
RI_LOCAL_USAGE_MIN = 1,
|
||||
RI_LOCAL_USAGE_MAX = 2,
|
||||
RI_LOCAL_DESIGNATOR_INDEX = 3,
|
||||
RI_LOCAL_DESIGNATOR_MIN = 4,
|
||||
RI_LOCAL_DESIGNATOR_MAX = 5,
|
||||
// 6 is reserved
|
||||
RI_LOCAL_STRING_INDEX = 7,
|
||||
RI_LOCAL_STRING_MIN = 8,
|
||||
RI_LOCAL_STRING_MAX = 9,
|
||||
RI_LOCAL_DELIMITER = 10,
|
||||
};
|
||||
|
||||
#define HID_USAGE_MAX(x) HID_REPORT_ITEM(x, 2, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_MAX_N(x, n) HID_REPORT_ITEM(x, 2, RI_TYPE_LOCAL, n)
|
||||
#define HID_USAGE(x) HID_REPORT_ITEM(x, RI_LOCAL_USAGE, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_N(x, n) HID_REPORT_ITEM(x, RI_LOCAL_USAGE, RI_TYPE_LOCAL, n)
|
||||
|
||||
#define HID_USAGE_MIN(x) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MIN, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_MIN_N(x, n) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MIN, RI_TYPE_LOCAL, n)
|
||||
|
||||
#define HID_USAGE_MAX(x) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MAX, RI_TYPE_LOCAL, 1)
|
||||
#define HID_USAGE_MAX_N(x, n) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MAX, RI_TYPE_LOCAL, n)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Usage Table
|
||||
|
@ -50,39 +50,44 @@
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Multiple Ports)
|
||||
// Application API (Multiple Instances)
|
||||
// CFG_TUD_HID > 1
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Check if the interface is ready to use
|
||||
bool tud_hid_n_ready(uint8_t itf);
|
||||
bool tud_hid_n_ready(uint8_t instance);
|
||||
|
||||
// Check if current mode is Boot (true) or Report (false)
|
||||
bool tud_hid_n_boot_mode(uint8_t itf);
|
||||
// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible values
|
||||
uint8_t tud_hid_n_interface_protocol(uint8_t instance);
|
||||
|
||||
// Get current active protocol: HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
|
||||
uint8_t tud_hid_n_get_protocol(uint8_t instance);
|
||||
|
||||
// Send report to host
|
||||
bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_t len);
|
||||
bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, uint8_t len);
|
||||
|
||||
// KEYBOARD: convenient helper to send keyboard report if application
|
||||
// use template layout report as defined by hid_keyboard_report_t
|
||||
bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
|
||||
bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
|
||||
|
||||
// MOUSE: convenient helper to send mouse report if application
|
||||
// use template layout report as defined by hid_mouse_report_t
|
||||
bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
|
||||
bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
|
||||
|
||||
// Gamepad: convenient helper to send mouse report if application
|
||||
// use template layout report TUD_HID_REPORT_DESC_GAMEPAD
|
||||
bool tud_hid_n_gamepad_report(uint8_t itf, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons);
|
||||
bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Single Port)
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool tud_hid_ready(void);
|
||||
static inline bool tud_hid_boot_mode(void);
|
||||
static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len);
|
||||
static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
|
||||
static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
|
||||
static inline bool tud_hid_ready(void);
|
||||
static inline uint8_t tud_hid_interface_protocol(void);
|
||||
static inline uint8_t tud_hid_get_protocol(void);
|
||||
static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len);
|
||||
static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
|
||||
static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
|
||||
static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Callbacks (Weak is optional)
|
||||
@ -90,29 +95,30 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8
|
||||
|
||||
// Invoked when received GET HID REPORT DESCRIPTOR request
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf);
|
||||
uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance);
|
||||
|
||||
// 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
|
||||
uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
|
||||
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
|
||||
|
||||
// Invoked when received SET_REPORT control request or
|
||||
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
|
||||
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);
|
||||
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
|
||||
|
||||
// Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report )
|
||||
TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t itf, uint8_t boot_mode);
|
||||
// Invoked when received SET_PROTOCOL request
|
||||
// protocol is either HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
|
||||
TU_ATTR_WEAK void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol);
|
||||
|
||||
// Invoked when received SET_IDLE request. return false will stall the request
|
||||
// - Idle Rate = 0 : only send report if there is changes, i.e skip duplication
|
||||
// - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
|
||||
TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t itf, uint8_t idle_rate);
|
||||
TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t instance, uint8_t idle_rate);
|
||||
|
||||
// Invoked when sent REPORT successfully to host
|
||||
// Application can use this to send the next report
|
||||
// Note: For composite reports, report[0] is report ID
|
||||
TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t itf, uint8_t const* report, uint8_t len);
|
||||
TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint8_t len);
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -123,9 +129,14 @@ static inline bool tud_hid_ready(void)
|
||||
return tud_hid_n_ready(0);
|
||||
}
|
||||
|
||||
static inline bool tud_hid_boot_mode(void)
|
||||
static inline uint8_t tud_hid_interface_protocol(void)
|
||||
{
|
||||
return tud_hid_n_boot_mode(0);
|
||||
return tud_hid_n_interface_protocol(0);
|
||||
}
|
||||
|
||||
static inline uint8_t tud_hid_get_protocol(void)
|
||||
{
|
||||
return tud_hid_n_get_protocol(0);
|
||||
}
|
||||
|
||||
static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
|
||||
@ -143,6 +154,11 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8
|
||||
return tud_hid_n_mouse_report(0, report_id, buttons, x, y, vertical, horizontal);
|
||||
}
|
||||
|
||||
static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons)
|
||||
{
|
||||
return tud_hid_n_gamepad_report(0, report_id, x, y, z, rz, rx, ry, hat, buttons);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------+
|
||||
* HID Report Descriptor Template
|
||||
*
|
||||
@ -184,9 +200,9 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8
|
||||
/* 6-byte Keycodes */ \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ) ,\
|
||||
HID_USAGE_MIN ( 0 ) ,\
|
||||
HID_USAGE_MAX ( 255 ) ,\
|
||||
HID_USAGE_MAX_N ( 255, 2 ) ,\
|
||||
HID_LOGICAL_MIN ( 0 ) ,\
|
||||
HID_LOGICAL_MAX ( 255 ) ,\
|
||||
HID_LOGICAL_MAX_N( 255, 2 ) ,\
|
||||
HID_REPORT_COUNT ( 6 ) ,\
|
||||
HID_REPORT_SIZE ( 8 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
|
||||
@ -272,7 +288,7 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8
|
||||
* 0x00 - do nothing
|
||||
* 0x01 - Power Off
|
||||
* 0x02 - Standby
|
||||
* 0x04 - Wake Host
|
||||
* 0x03 - Wake Host
|
||||
*/
|
||||
#define TUD_HID_REPORT_DESC_SYSTEM_CONTROL(...) \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
@ -285,8 +301,8 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8
|
||||
HID_LOGICAL_MAX ( 3 ) ,\
|
||||
HID_REPORT_COUNT ( 1 ) ,\
|
||||
HID_REPORT_SIZE ( 2 ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_SLEEP ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_POWER_DOWN ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_SLEEP ) ,\
|
||||
HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_WAKE_UP ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
|
||||
/* 6 bit padding */ \
|
||||
|
@ -39,166 +39,94 @@
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD Application API
|
||||
// Class Driver Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
|
||||
* @{ */
|
||||
|
||||
/** \defgroup Keyboard_Host Host
|
||||
* The interface API includes status checking function, data transferring function and callback functions
|
||||
* @{ */
|
||||
// TODO Highspeed interrupt can be up to 512 bytes
|
||||
#ifndef CFG_TUH_HID_EP_BUFSIZE
|
||||
#define CFG_TUH_HID_EP_BUFSIZE 64
|
||||
#endif
|
||||
|
||||
extern uint8_t const hid_keycode_to_ascii_tbl[2][128]; // TODO used weak attr if build failed without KEYBOARD enabled
|
||||
typedef struct
|
||||
{
|
||||
uint8_t report_id;
|
||||
uint8_t usage;
|
||||
uint16_t usage_page;
|
||||
|
||||
/** \brief Check if device supports Keyboard interface or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if device supports Keyboard interface
|
||||
* \retval false if device does not support Keyboard interface or is not mounted
|
||||
*/
|
||||
bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr);
|
||||
|
||||
/** \brief Check if the interface is currently busy or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to device
|
||||
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to device
|
||||
* \note This function is primarily used for polling/waiting result after \ref tuh_hid_keyboard_get_report.
|
||||
* Alternatively, asynchronous event API can be used
|
||||
*/
|
||||
bool tuh_hid_keyboard_is_busy(uint8_t dev_addr);
|
||||
|
||||
/** \brief Perform a get report from Keyboard interface
|
||||
* \param[in] dev_addr device address
|
||||
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref CFG_TUSB_MEM_SECTION)
|
||||
* \returns \ref tusb_error_t type to indicate success or error condition.
|
||||
* \retval TUSB_ERROR_NONE on success
|
||||
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
|
||||
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
|
||||
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
|
||||
* \note This function is non-blocking and returns immediately. The result of usb transfer will be reported by the interface's callback function
|
||||
*/
|
||||
tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void * p_report);
|
||||
|
||||
//------------- Application Callback -------------//
|
||||
/** \brief Callback function that is invoked when an transferring event occurred
|
||||
* \param[in] dev_addr Address of device
|
||||
* \param[in] event an value from \ref xfer_result_t
|
||||
* \note event can be one of following
|
||||
* - XFER_RESULT_SUCCESS : previously scheduled transfer completes successfully.
|
||||
* - XFER_RESULT_FAILED : previously scheduled transfer encountered a transaction error.
|
||||
* - XFER_RESULT_STALLED : previously scheduled transfer is stalled by device.
|
||||
* \note Application should schedule the next report by calling \ref tuh_hid_keyboard_get_report within this callback
|
||||
*/
|
||||
void tuh_hid_keyboard_isr(uint8_t dev_addr, xfer_result_t event);
|
||||
|
||||
/** \brief Callback function that will be invoked when a device with Keyboard interface is mounted
|
||||
* \param[in] dev_addr Address of newly mounted device
|
||||
* \note This callback should be used by Application to set-up interface-related data
|
||||
*/
|
||||
void tuh_hid_keyboard_mounted_cb(uint8_t dev_addr);
|
||||
|
||||
/** \brief Callback function that will be invoked when a device with Keyboard interface is unmounted
|
||||
* \param[in] dev_addr Address of newly unmounted device
|
||||
* \note This callback should be used by Application to tear-down interface-related data
|
||||
*/
|
||||
void tuh_hid_keyboard_unmounted_cb(uint8_t dev_addr);
|
||||
|
||||
/** @} */ // Keyboard_Host
|
||||
/** @} */ // ClassDriver_HID_Keyboard
|
||||
// TODO still use the endpoint size for now
|
||||
// uint8_t in_len; // length of IN report
|
||||
// uint8_t out_len; // length of OUT report
|
||||
} tuh_hid_report_info_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MOUSE Application API
|
||||
// Application API
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Mouse Mouse
|
||||
* @{ */
|
||||
|
||||
/** \defgroup Mouse_Host Host
|
||||
* The interface API includes status checking function, data transferring function and callback functions
|
||||
* @{ */
|
||||
// Get the number of HID instances
|
||||
uint8_t tuh_hid_instance_count(uint8_t dev_addr);
|
||||
|
||||
/** \brief Check if device supports Mouse interface or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if device supports Mouse interface
|
||||
* \retval false if device does not support Mouse interface or is not mounted
|
||||
*/
|
||||
bool tuh_hid_mouse_is_mounted(uint8_t dev_addr);
|
||||
// Check if HID instance is mounted
|
||||
bool tuh_hid_mounted(uint8_t dev_addr, uint8_t instance);
|
||||
|
||||
/** \brief Check if the interface is currently busy or not
|
||||
* \param[in] dev_addr device address
|
||||
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to device
|
||||
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to device
|
||||
* \note This function is primarily used for polling/waiting result after \ref tuh_hid_mouse_get_report.
|
||||
* Alternatively, asynchronous event API can be used
|
||||
*/
|
||||
bool tuh_hid_mouse_is_busy(uint8_t dev_addr);
|
||||
// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible values
|
||||
uint8_t tuh_hid_interface_protocol(uint8_t dev_addr, uint8_t instance);
|
||||
|
||||
/** \brief Perform a get report from Mouse interface
|
||||
* \param[in] dev_addr device address
|
||||
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref CFG_TUSB_MEM_SECTION)
|
||||
* \returns \ref tusb_error_t type to indicate success or error condition.
|
||||
* \retval TUSB_ERROR_NONE on success
|
||||
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
|
||||
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
|
||||
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
|
||||
* \note This function is non-blocking and returns immediately. The result of usb transfer will be reported by the interface's callback function
|
||||
*/
|
||||
tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void* p_report);
|
||||
// Get current active protocol: HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
|
||||
// Note: as HID spec, device will be initialized in Report mode
|
||||
bool tuh_hid_get_protocol(uint8_t dev_addr, uint8_t instance);
|
||||
|
||||
//------------- Application Callback -------------//
|
||||
/** \brief Callback function that is invoked when an transferring event occurred
|
||||
* \param[in] dev_addr Address of device
|
||||
* \param[in] event an value from \ref xfer_result_t
|
||||
* \note event can be one of following
|
||||
* - XFER_RESULT_SUCCESS : previously scheduled transfer completes successfully.
|
||||
* - XFER_RESULT_FAILED : previously scheduled transfer encountered a transaction error.
|
||||
* - XFER_RESULT_STALLED : previously scheduled transfer is stalled by device.
|
||||
* \note Application should schedule the next report by calling \ref tuh_hid_mouse_get_report within this callback
|
||||
*/
|
||||
void tuh_hid_mouse_isr(uint8_t dev_addr, xfer_result_t event);
|
||||
// Set protocol to HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
|
||||
// This function is only supported by Boot interface (tuh_n_hid_interface_protocol() != NONE)
|
||||
bool tuh_hid_set_protocol(uint8_t dev_addr, uint8_t instance, uint8_t protocol);
|
||||
|
||||
/** \brief Callback function that will be invoked when a device with Mouse interface is mounted
|
||||
* \param[in] dev_addr Address of newly mounted device
|
||||
* \note This callback should be used by Application to set-up interface-related data
|
||||
*/
|
||||
void tuh_hid_mouse_mounted_cb(uint8_t dev_addr);
|
||||
// Set Report using control endpoint
|
||||
// report_type is either Intput, Output or Feature, (value from hid_report_type_t)
|
||||
bool tuh_hid_set_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, void* report, uint16_t len);
|
||||
|
||||
/** \brief Callback function that will be invoked when a device with Mouse interface is unmounted
|
||||
* \param[in] dev_addr Address of newly unmounted device
|
||||
* \note This callback should be used by Application to tear-down interface-related data
|
||||
*/
|
||||
void tuh_hid_mouse_unmounted_cb(uint8_t dev_addr);
|
||||
// Parse report descriptor into array of report_info struct and return number of reports.
|
||||
// For complicated report, application should write its own parser.
|
||||
uint8_t tuh_hid_parse_report_descriptor(tuh_hid_report_info_t* reports_info_arr, uint8_t arr_count, uint8_t const* desc_report, uint16_t desc_len) TU_ATTR_UNUSED;
|
||||
|
||||
/** @} */ // Mouse_Host
|
||||
/** @} */ // ClassDriver_HID_Mouse
|
||||
// Check if the interface is ready to use
|
||||
//bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t instance);
|
||||
|
||||
// Send report using interrupt endpoint
|
||||
// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent.
|
||||
//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// GENERIC Application API
|
||||
// Callbacks (Weak is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
/** \addtogroup ClassDriver_HID_Generic Generic (not supported yet)
|
||||
* @{ */
|
||||
|
||||
/** \defgroup Generic_Host Host
|
||||
* The interface API includes status checking function, data transferring function and callback functions
|
||||
* @{ */
|
||||
// Invoked when device with hid interface is mounted
|
||||
// Report descriptor is also available for use. tuh_hid_parse_report_descriptor()
|
||||
// can be used to parse common/simple enough descriptor.
|
||||
void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report_desc, uint16_t desc_len);
|
||||
|
||||
bool tuh_hid_generic_is_mounted(uint8_t dev_addr);
|
||||
tusb_error_t tuh_hid_generic_get_report(uint8_t dev_addr, void* p_report, bool int_on_complete);
|
||||
tusb_error_t tuh_hid_generic_set_report(uint8_t dev_addr, void* p_report, bool int_on_complete);
|
||||
tusb_interface_status_t tuh_hid_generic_get_status(uint8_t dev_addr);
|
||||
tusb_interface_status_t tuh_hid_generic_set_status(uint8_t dev_addr);
|
||||
// Invoked when device with hid interface is un-mounted
|
||||
TU_ATTR_WEAK void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance);
|
||||
|
||||
//------------- Application Callback -------------//
|
||||
void tuh_hid_generic_isr(uint8_t dev_addr, xfer_result_t event);
|
||||
// Invoked when received report from device via interrupt endpoint
|
||||
// Note: if there is report ID (composite), it is 1st byte of report
|
||||
void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
||||
|
||||
/** @} */ // Generic_Host
|
||||
/** @} */ // ClassDriver_HID_Generic
|
||||
// Invoked when sent report to device successfully via interrupt endpoint
|
||||
TU_ATTR_WEAK void tuh_hid_report_sent_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
|
||||
|
||||
// Invoked when Sent Report to device via either control endpoint
|
||||
// len = 0 indicate there is error in the transfer e.g stalled response
|
||||
TU_ATTR_WEAK void tuh_hid_set_report_complete_cb(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, uint16_t len);
|
||||
|
||||
// Invoked when Set Protocol request is complete
|
||||
TU_ATTR_WEAK void tuh_hid_set_protocol_complete_cb(uint8_t dev_addr, uint8_t instance, uint8_t protocol);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal Class Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
void hidh_init(void);
|
||||
bool hidh_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length);
|
||||
bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t *p_length);
|
||||
bool hidh_set_config(uint8_t dev_addr, uint8_t itf_num);
|
||||
bool hidh_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
bool hidh_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
|
||||
void hidh_close(uint8_t dev_addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -106,17 +106,17 @@ bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_r
|
||||
//------------- Application Callback -------------//
|
||||
|
||||
// Invoked when a device with MassStorage interface is mounted
|
||||
void tuh_msc_mount_cb(uint8_t dev_addr);
|
||||
TU_ATTR_WEAK void tuh_msc_mount_cb(uint8_t dev_addr);
|
||||
|
||||
// Invoked when a device with MassStorage interface is unmounted
|
||||
void tuh_msc_unmount_cb(uint8_t dev_addr);
|
||||
TU_ATTR_WEAK void tuh_msc_umount_cb(uint8_t dev_addr);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal Class Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void msch_init(void);
|
||||
bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length);
|
||||
bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t *p_length);
|
||||
bool msch_set_config(uint8_t dev_addr, uint8_t itf_num);
|
||||
bool msch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
void msch_close(uint8_t dev_addr);
|
||||
|
@ -45,7 +45,7 @@ bool tud_vendor_n_mounted (uint8_t itf);
|
||||
|
||||
uint32_t tud_vendor_n_available (uint8_t itf);
|
||||
uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize);
|
||||
bool tud_vendor_n_peek (uint8_t itf, int pos, uint8_t* u8);
|
||||
bool tud_vendor_n_peek (uint8_t itf, uint8_t* u8);
|
||||
|
||||
uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
|
||||
uint32_t tud_vendor_n_write_available (uint8_t itf);
|
||||
@ -59,7 +59,7 @@ uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
|
||||
static inline bool tud_vendor_mounted (void);
|
||||
static inline uint32_t tud_vendor_available (void);
|
||||
static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize);
|
||||
static inline bool tud_vendor_peek (int pos, uint8_t* u8);
|
||||
static inline bool tud_vendor_peek (uint8_t* u8);
|
||||
static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize);
|
||||
static inline uint32_t tud_vendor_write_str (char const* str);
|
||||
static inline uint32_t tud_vendor_write_available (void);
|
||||
@ -95,9 +95,9 @@ static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize)
|
||||
return tud_vendor_n_read(0, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline bool tud_vendor_peek (int pos, uint8_t* u8)
|
||||
static inline bool tud_vendor_peek (uint8_t* u8)
|
||||
{
|
||||
return tud_vendor_n_peek(0, pos, u8);
|
||||
return tud_vendor_n_peek(0, u8);
|
||||
}
|
||||
|
||||
static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
@ -47,13 +47,13 @@
|
||||
#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) ((((uint32_t) u32) >> 24) & 0x000000ff)) // MSB
|
||||
#define U32_B2_U8(u32) ((uint8_t) ((((uint32_t) u32) >> 16) & 0x000000ff))
|
||||
#define U32_B3_U8(u32) ((uint8_t) ((((uint32_t) u32) >> 8) & 0x000000ff))
|
||||
#define U32_B4_U8(u32) ((uint8_t) (((uint32_t) u32) & 0x000000ff)) // LSB
|
||||
#define TU_U32_BYTE3(u32) ((uint8_t) ((((uint32_t) u32) >> 24) & 0x000000ff)) // MSB
|
||||
#define TU_U32_BYTE2(u32) ((uint8_t) ((((uint32_t) u32) >> 16) & 0x000000ff))
|
||||
#define TU_U32_BYTE1(u32) ((uint8_t) ((((uint32_t) u32) >> 8) & 0x000000ff))
|
||||
#define TU_U32_BYTE0(u32) ((uint8_t) (((uint32_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) TU_U32_BYTE3(u32), TU_U32_BYTE2(u32), TU_U32_BYTE1(u32), TU_U32_BYTE0(u32)
|
||||
#define U32_TO_U8S_LE(u32) TU_U32_BYTE0(u32), TU_U32_BYTE1(u32), TU_U32_BYTE2(u32), TU_U32_BYTE3(u32)
|
||||
|
||||
#define TU_BIT(n) (1U << (n))
|
||||
|
||||
@ -81,9 +81,9 @@
|
||||
#define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var)))
|
||||
|
||||
//------------- Bytes -------------//
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_u32(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4)
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_u32(uint8_t b3, uint8_t b2, uint8_t b1, uint8_t b0)
|
||||
{
|
||||
return ( ((uint32_t) b1) << 24) | ( ((uint32_t) b2) << 16) | ( ((uint32_t) b3) << 8) | b4;
|
||||
return ( ((uint32_t) b3) << 24) | ( ((uint32_t) b2) << 16) | ( ((uint32_t) b1) << 8) | b0;
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_u16(uint8_t high, uint8_t low)
|
||||
@ -91,8 +91,13 @@ TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_u16(uint8_t high, uint8_t low)
|
||||
return (uint16_t) ((((uint16_t) high) << 8) | low);
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_high(uint16_t u16) { return (uint8_t) (((uint16_t) (u16 >> 8)) & 0x00ff); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_low (uint16_t u16) { return (uint8_t) (u16 & 0x00ff); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u32_byte3(uint32_t u32) { return TU_U32_BYTE3(u32); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u32_byte2(uint32_t u32) { return TU_U32_BYTE2(u32); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u32_byte1(uint32_t u32) { return TU_U32_BYTE1(u32); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u32_byte0(uint32_t u32) { return TU_U32_BYTE0(u32); }
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_high(uint16_t u16) { return TU_U16_HIGH(u16); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_low (uint16_t u16) { return TU_U16_LOW(u16); }
|
||||
|
||||
//------------- Bits -------------//
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_bit_set (uint32_t value, uint8_t pos) { return value | TU_BIT(pos); }
|
||||
@ -115,8 +120,8 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align(uint32_t value, uint32_t a
|
||||
return value & ((uint32_t) ~(alignment-1));
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align32 (uint32_t value) { return (value & 0xFFFFFFE0UL); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align16 (uint32_t value) { return (value & 0xFFFFFFF0UL); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align32 (uint32_t value) { return (value & 0xFFFFFFE0UL); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_align4k (uint32_t value) { return (value & 0xFFFFF000UL); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_offset4k(uint32_t value) { return (value & 0xFFFUL); }
|
||||
|
||||
@ -141,6 +146,8 @@ static inline uint8_t tu_log2(uint32_t value)
|
||||
//------------- Unaligned Access -------------//
|
||||
#if TUP_ARCH_STRICT_ALIGN
|
||||
|
||||
// Rely on compiler to generate correct code for unaligned access
|
||||
|
||||
typedef struct { uint16_t val; } TU_ATTR_PACKED tu_unaligned_uint16_t;
|
||||
typedef struct { uint32_t val; } TU_ATTR_PACKED tu_unaligned_uint32_t;
|
||||
|
||||
@ -168,8 +175,44 @@ TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16(void* mem, uint16_
|
||||
ua16->val = value;
|
||||
}
|
||||
|
||||
#elif TUP_MCU_STRICT_ALIGN
|
||||
|
||||
// MCU such as LPC_IP3511 Highspeed cannot access unaligned memory on USB_RAM although it is ARM M4.
|
||||
// We have to manually pick up bytes since tu_unaligned_uint32_t will still generate unaligned code
|
||||
// NOTE: volatile cast to memory to prevent compiler to optimize and generate unaligned code
|
||||
// TODO Big Endian may need minor changes
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_unaligned_read32(const void* mem)
|
||||
{
|
||||
volatile uint8_t const* buf8 = (uint8_t const*) mem;
|
||||
return tu_u32(buf8[3], buf8[2], buf8[1], buf8[0]);
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write32(void* mem, uint32_t value)
|
||||
{
|
||||
volatile uint8_t* buf8 = (uint8_t*) mem;
|
||||
buf8[0] = tu_u32_byte0(value);
|
||||
buf8[1] = tu_u32_byte1(value);
|
||||
buf8[2] = tu_u32_byte2(value);
|
||||
buf8[3] = tu_u32_byte3(value);
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_unaligned_read16(const void* mem)
|
||||
{
|
||||
volatile uint8_t const* buf8 = (uint8_t const*) mem;
|
||||
return tu_u16(buf8[1], buf8[0]);
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16(void* mem, uint16_t value)
|
||||
{
|
||||
volatile uint8_t* buf8 = (uint8_t*) mem;
|
||||
buf8[0] = tu_u16_low(value);
|
||||
buf8[1] = tu_u16_high(value);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
// MCU that could access unaligned memory natively
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_unaligned_read32 (const void* mem ) { return *((uint32_t*) mem); }
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_unaligned_read16 (const void* mem ) { return *((uint16_t*) mem); }
|
||||
|
||||
|
@ -25,10 +25,6 @@
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_Common
|
||||
* \defgroup group_fifo fifo
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_FIFO_H_
|
||||
#define _TUSB_FIFO_H_
|
||||
|
||||
@ -62,16 +58,16 @@ extern "C" {
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t* buffer ; ///< buffer pointer
|
||||
uint16_t depth ; ///< max items
|
||||
uint16_t item_size ; ///< size of each item
|
||||
bool overwritable ;
|
||||
uint8_t* buffer ; ///< buffer pointer
|
||||
uint16_t depth ; ///< max items
|
||||
uint16_t item_size ; ///< size of each item
|
||||
bool overwritable ;
|
||||
|
||||
uint16_t non_used_index_space ; ///< required for non-power-of-two buffer length
|
||||
uint16_t max_pointer_idx ; ///< maximum absolute pointer index
|
||||
uint16_t non_used_index_space ; ///< required for non-power-of-two buffer length
|
||||
uint16_t max_pointer_idx ; ///< maximum absolute pointer index
|
||||
|
||||
volatile uint16_t wr_idx ; ///< write pointer
|
||||
volatile uint16_t rd_idx ; ///< read pointer
|
||||
volatile uint16_t wr_idx ; ///< write pointer
|
||||
volatile uint16_t rd_idx ; ///< read pointer
|
||||
|
||||
#if CFG_FIFO_MUTEX
|
||||
tu_fifo_mutex_t mutex_wr;
|
||||
@ -80,6 +76,14 @@ typedef struct
|
||||
|
||||
} tu_fifo_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t len_lin ; ///< linear length in item size
|
||||
uint16_t len_wrap ; ///< wrapped length in item size
|
||||
void * ptr_lin ; ///< linear part start pointer
|
||||
void * ptr_wrap ; ///< wrapped part start pointer
|
||||
} tu_fifo_buffer_info_t;
|
||||
|
||||
#define TU_FIFO_INIT(_buffer, _depth, _type, _overwritable) \
|
||||
{ \
|
||||
.buffer = _buffer, \
|
||||
@ -115,8 +119,8 @@ bool tu_fifo_read (tu_fifo_t* f, void * p_buffer);
|
||||
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t n);
|
||||
uint16_t tu_fifo_read_n_const_addr_full_words (tu_fifo_t* f, void * buffer, uint16_t n);
|
||||
|
||||
bool tu_fifo_peek_at (tu_fifo_t* f, uint16_t pos, void * p_buffer);
|
||||
uint16_t tu_fifo_peek_at_n (tu_fifo_t* f, uint16_t pos, void * p_buffer, uint16_t n);
|
||||
bool tu_fifo_peek (tu_fifo_t* f, void * p_buffer);
|
||||
uint16_t tu_fifo_peek_n (tu_fifo_t* f, void * p_buffer, uint16_t n);
|
||||
|
||||
uint16_t tu_fifo_count (tu_fifo_t* f);
|
||||
bool tu_fifo_empty (tu_fifo_t* f);
|
||||
@ -125,27 +129,22 @@ uint16_t tu_fifo_remaining (tu_fifo_t* f);
|
||||
bool tu_fifo_overflowed (tu_fifo_t* f);
|
||||
void tu_fifo_correct_read_pointer (tu_fifo_t* f);
|
||||
|
||||
static inline uint16_t tu_fifo_depth(tu_fifo_t* f)
|
||||
{
|
||||
return f->depth;
|
||||
}
|
||||
|
||||
// Pointer modifications intended to be used in combinations with DMAs.
|
||||
// USE WITH CARE - NO SAFTY CHECKS CONDUCTED HERE! NOT MUTEX PROTECTED!
|
||||
void tu_fifo_advance_write_pointer (tu_fifo_t *f, uint16_t n);
|
||||
void tu_fifo_advance_read_pointer (tu_fifo_t *f, uint16_t n);
|
||||
|
||||
// If you want to read/write from/to the FIFO by use of a DMA, you may need to conduct two copies to handle a possible wrapping part
|
||||
// This functions deliver a pointer to start reading/writing from/to and a valid linear length along which no wrap occurs.
|
||||
// In case not all of your data is available within one read/write, update the read/write pointer by
|
||||
// tu_fifo_advance_read_pointer()/tu_fifo_advance_write_pointer and conduct a second read/write operation
|
||||
uint16_t tu_fifo_get_linear_read_info (tu_fifo_t *f, uint16_t offset, void **ptr, uint16_t n);
|
||||
uint16_t tu_fifo_get_linear_write_info (tu_fifo_t *f, uint16_t offset, void **ptr, uint16_t n);
|
||||
// If you want to read/write from/to the FIFO by use of a DMA, you may need to conduct two copies
|
||||
// to handle a possible wrapping part. These functions deliver a pointer to start
|
||||
// reading/writing from/to and a valid linear length along which no wrap occurs.
|
||||
void tu_fifo_get_read_info (tu_fifo_t *f, tu_fifo_buffer_info_t *info);
|
||||
void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info);
|
||||
|
||||
static inline bool tu_fifo_peek(tu_fifo_t* f, void * p_buffer)
|
||||
{
|
||||
return tu_fifo_peek_at(f, 0, p_buffer);
|
||||
}
|
||||
|
||||
static inline uint16_t tu_fifo_depth(tu_fifo_t* f)
|
||||
{
|
||||
return f->depth;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -309,6 +309,8 @@ typedef struct TU_ATTR_PACKED
|
||||
uint8_t bMaxPower ; ///< Maximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
|
||||
} tusb_desc_configuration_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_configuration_t) == 9, "size is not correct");
|
||||
|
||||
/// USB Interface Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
@ -421,6 +423,29 @@ typedef struct TU_ATTR_PACKED
|
||||
char url[];
|
||||
} tusb_desc_webusb_url_t;
|
||||
|
||||
// DFU Functional Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
|
||||
union {
|
||||
struct TU_ATTR_PACKED {
|
||||
uint8_t bitCanDnload : 1;
|
||||
uint8_t bitCanUpload : 1;
|
||||
uint8_t bitManifestationTolerant : 1;
|
||||
uint8_t bitWillDetach : 1;
|
||||
uint8_t reserved : 4;
|
||||
} bmAttributes;
|
||||
|
||||
uint8_t bAttributes;
|
||||
};
|
||||
|
||||
uint16_t wDetachTimeOut;
|
||||
uint16_t wTransferSize;
|
||||
uint16_t bcdDFUVersion;
|
||||
} tusb_desc_dfu_functional_t;
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Types
|
||||
*------------------------------------------------------------------*/
|
||||
|
@ -24,10 +24,6 @@
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
/** \ingroup group_usbd
|
||||
* \defgroup group_dcd Device Controller Driver (DCD)
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_DCD_H_
|
||||
#define _TUSB_DCD_H_
|
||||
|
||||
@ -168,5 +164,3 @@ extern void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t x
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_DCD_H_ */
|
||||
|
||||
/// @}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
@ -41,7 +41,10 @@ extern "C" {
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Init device stack
|
||||
bool tud_init (void);
|
||||
bool tud_init (uint8_t rhport);
|
||||
|
||||
// Check if device stack is already initialized
|
||||
bool tud_inited(void);
|
||||
|
||||
// Task function should be called in main/rtos loop
|
||||
void tud_task (void);
|
||||
@ -67,6 +70,7 @@ bool tud_mounted(void);
|
||||
bool tud_suspended(void);
|
||||
|
||||
// Check if device is ready to transfer
|
||||
TU_ATTR_ALWAYS_INLINE
|
||||
static inline bool tud_ready(void)
|
||||
{
|
||||
return tud_mounted() && !tud_suspended();
|
||||
@ -583,7 +587,7 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
|
||||
//------------- DFU Runtime -------------//
|
||||
#define TUD_DFU_APP_CLASS (TUSB_CLASS_APPLICATION_SPECIFIC)
|
||||
#define TUD_DFU_APP_SUBCLASS 0x01u
|
||||
#define TUD_DFU_APP_SUBCLASS (APP_SUBCLASS_DFU_RUNTIME)
|
||||
|
||||
// Length of template descriptr: 18 bytes
|
||||
#define TUD_DFU_RT_DESC_LEN (9 + 9)
|
||||
@ -596,6 +600,17 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
/* Function */ \
|
||||
9, DFU_DESC_FUNCTIONAL, _attr, U16_TO_U8S_LE(_timeout), U16_TO_U8S_LE(_xfer_size), U16_TO_U8S_LE(0x0101)
|
||||
|
||||
// Length of template descriptr: 18 bytes
|
||||
#define TUD_DFU_MODE_DESC_LEN (9 + 9)
|
||||
|
||||
// DFU runtime descriptor
|
||||
// Interface number, string index, attributes, detach timeout, transfer size
|
||||
#define TUD_DFU_MODE_DESCRIPTOR(_itfnum, _stridx, _attr, _timeout, _xfer_size) \
|
||||
/* Interface */ \
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUD_DFU_APP_CLASS, TUD_DFU_APP_SUBCLASS, DFU_PROTOCOL_DFU, _stridx, \
|
||||
/* Function */ \
|
||||
9, DFU_DESC_FUNCTIONAL, _attr, U16_TO_U8S_LE(_timeout), U16_TO_U8S_LE(_xfer_size), U16_TO_U8S_LE(0x0101)
|
||||
|
||||
|
||||
//------------- CDC-ECM -------------//
|
||||
|
||||
|
@ -47,7 +47,7 @@ typedef struct
|
||||
void (* reset ) (uint8_t rhport);
|
||||
uint16_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t max_len);
|
||||
bool (* control_xfer_cb ) (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
|
||||
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
|
||||
void (* sof ) (uint8_t rhport); /* optional */
|
||||
} usbd_class_driver_t;
|
||||
|
||||
|
@ -24,14 +24,10 @@
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
/** \ingroup group_usbh
|
||||
* \defgroup Group_HCD Host Controller Driver (HCD)
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_HCD_H_
|
||||
#define _TUSB_HCD_H_
|
||||
|
||||
#include <common/tusb_common.h>
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -85,9 +81,8 @@ typedef struct
|
||||
#if TUSB_OPT_HOST_ENABLED
|
||||
// Max number of endpoints per device
|
||||
enum {
|
||||
HCD_MAX_ENDPOINT = CFG_TUSB_HOST_DEVICE_MAX*(CFG_TUH_HUB + CFG_TUH_HID_KEYBOARD + CFG_TUH_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC +
|
||||
CFG_TUH_MSC*2 + CFG_TUH_CDC*3),
|
||||
|
||||
// TODO better computation
|
||||
HCD_MAX_ENDPOINT = CFG_TUSB_HOST_DEVICE_MAX*(CFG_TUH_HUB + CFG_TUH_HID*2 + CFG_TUH_MSC*2 + CFG_TUH_CDC*3),
|
||||
HCD_MAX_XFER = HCD_MAX_ENDPOINT*2,
|
||||
};
|
||||
|
||||
@ -96,27 +91,46 @@ enum {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Controller & Port API
|
||||
// Controller API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Initialize controller to host mode
|
||||
bool hcd_init(uint8_t rhport);
|
||||
|
||||
// Interrupt Handler
|
||||
void hcd_int_handler(uint8_t rhport);
|
||||
|
||||
// Enable USB interrupt
|
||||
void hcd_int_enable (uint8_t rhport);
|
||||
|
||||
// Disable USB interrupt
|
||||
void hcd_int_disable(uint8_t rhport);
|
||||
|
||||
// Get micro frame number (125 us)
|
||||
uint32_t hcd_uframe_number(uint8_t rhport);
|
||||
|
||||
// Get frame number (1ms)
|
||||
static inline uint32_t hcd_frame_number(uint8_t rhport)
|
||||
TU_ATTR_ALWAYS_INLINE static inline
|
||||
uint32_t hcd_frame_number(uint8_t rhport)
|
||||
{
|
||||
return hcd_uframe_number(rhport) >> 3;
|
||||
}
|
||||
|
||||
/// return the current connect status of roothub port
|
||||
bool hcd_port_connect_status(uint8_t hostid);
|
||||
void hcd_port_reset(uint8_t hostid);
|
||||
//--------------------------------------------------------------------+
|
||||
// Port API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Get the current connect status of roothub port
|
||||
bool hcd_port_connect_status(uint8_t rhport);
|
||||
|
||||
// Reset USB bus on the port
|
||||
void hcd_port_reset(uint8_t rhport);
|
||||
|
||||
// TODO implement later
|
||||
void hcd_port_reset_end(uint8_t rhport);
|
||||
tusb_speed_t hcd_port_speed_get(uint8_t hostid);
|
||||
|
||||
// Get port link speed
|
||||
tusb_speed_t hcd_port_speed_get(uint8_t rhport);
|
||||
|
||||
// HCD closes all opened endpoints belong to this device
|
||||
void hcd_device_close(uint8_t rhport, uint8_t dev_addr);
|
||||
@ -124,6 +138,7 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr);
|
||||
//--------------------------------------------------------------------+
|
||||
// Endpoints API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]);
|
||||
bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc);
|
||||
|
||||
@ -135,14 +150,12 @@ bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr);
|
||||
bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PIPE API
|
||||
// PIPE API - TODO remove later
|
||||
//--------------------------------------------------------------------+
|
||||
// TODO control xfer should be used via usbh layer
|
||||
bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes); // only queue, not transferring yet
|
||||
bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete);
|
||||
|
||||
// tusb_error_t hcd_pipe_cancel();
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Event API (implemented by stack)
|
||||
//--------------------------------------------------------------------+
|
||||
@ -164,5 +177,3 @@ extern void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, uint32_t
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_HCD_H_ */
|
||||
|
||||
/// @}
|
||||
|
@ -76,7 +76,10 @@ typedef bool (*tuh_control_complete_cb_t)(uint8_t dev_addr, tusb_control_request
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Init host stack
|
||||
bool tuh_init(void);
|
||||
bool tuh_init(uint8_t rhport);
|
||||
|
||||
// Check if host stack is already initialized
|
||||
bool tuh_inited(void);
|
||||
|
||||
// Task function should be called in main/rtos loop
|
||||
void tuh_task(void);
|
||||
@ -85,13 +88,19 @@ void tuh_task(void);
|
||||
extern void hcd_int_handler(uint8_t rhport);
|
||||
#define tuh_int_handler hcd_int_handler
|
||||
|
||||
tusb_device_state_t tuh_device_get_state (uint8_t dev_addr);
|
||||
tusb_speed_t tuh_device_get_speed (uint8_t dev_addr);
|
||||
static inline bool tuh_device_is_configured(uint8_t dev_addr)
|
||||
|
||||
// Check if device is configured
|
||||
bool tuh_device_configured(uint8_t dev_addr);
|
||||
|
||||
// Check if device is ready to communicate with
|
||||
TU_ATTR_ALWAYS_INLINE
|
||||
static inline bool tuh_device_ready(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_device_get_state(dev_addr) == TUSB_DEVICE_STATE_CONFIGURED;
|
||||
return tuh_device_configured(dev_addr);
|
||||
}
|
||||
|
||||
// Carry out control transfer
|
||||
bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -121,6 +130,8 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num);
|
||||
|
||||
uint8_t usbh_get_rhport(uint8_t dev_addr);
|
||||
|
||||
uint8_t* usbh_get_enum_buf(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -67,7 +67,7 @@ static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
BaseType_t res = xSemaphoreGiveFromISR(sem_hdl, &xHigherPriorityTaskWoken);
|
||||
|
||||
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2
|
||||
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
|
||||
if ( xHigherPriorityTaskWoken ) portYIELD_FROM_ISR();
|
||||
#else
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
@ -150,7 +150,7 @@ static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
BaseType_t res = xQueueSendToBackFromISR(qhdl, data, &xHigherPriorityTaskWoken);
|
||||
|
||||
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2
|
||||
#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
|
||||
if ( xHigherPriorityTaskWoken ) portYIELD_FROM_ISR();
|
||||
#else
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
|
@ -57,6 +57,7 @@ static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semde
|
||||
|
||||
static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
|
||||
{
|
||||
(void) in_isr;
|
||||
sem_release(sem_hdl);
|
||||
return true;
|
||||
}
|
||||
@ -158,6 +159,7 @@ static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in
|
||||
// however osal_queue_recieve may be. therefore my assumption is that
|
||||
// the fifo mutex is not populated for queues used from an IRQ context
|
||||
//assert(!qhdl->ff.mutex);
|
||||
(void) in_isr;
|
||||
|
||||
_osal_q_lock(qhdl);
|
||||
bool success = tu_fifo_write(&qhdl->ff, data);
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2021, 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
|
||||
* 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_HCD_EHCI_H_
|
||||
#define _TUSB_HCD_EHCI_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// API Implemented by HCD
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Get operational address i.e EHCI Command register
|
||||
uint32_t hcd_ehci_register_addr(uint8_t rhport);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// API Implemented by EHCI
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Initialize EHCI driver
|
||||
extern bool hcd_ehci_init (uint8_t rhport);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
@ -42,7 +42,7 @@
|
||||
#if TUSB_OPT_HOST_ENABLED
|
||||
#include "host/usbh.h"
|
||||
|
||||
#if HOST_CLASS_HID
|
||||
#if CFG_TUH_HID
|
||||
#include "class/hid/hid_host.h"
|
||||
#endif
|
||||
|
||||
@ -96,6 +96,10 @@
|
||||
#include "class/dfu/dfu_rt_device.h"
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_DFU_MODE
|
||||
#include "class/dfu/dfu_device.h"
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_NET
|
||||
#include "class/net/net_device.h"
|
||||
#endif
|
||||
|
@ -94,6 +94,7 @@
|
||||
|
||||
// Espressif
|
||||
#define OPT_MCU_ESP32S2 900 ///< Espressif ESP32-S2
|
||||
#define OPT_MCU_ESP32S3 901 ///< Espressif ESP32-S3
|
||||
|
||||
// Dialog
|
||||
#define OPT_MCU_DA1469X 1000 ///< Dialog Semiconductor DA1469x
|
||||
@ -240,7 +241,15 @@
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_DFU_RUNTIME
|
||||
#define CFG_TUD_DFU_RUNTIME 0
|
||||
#define CFG_TUD_DFU_RUNTIME 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_DFU_MODE
|
||||
#define CFG_TUD_DFU_MODE 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_DFU_TRANSFER_BUFFER_SIZE
|
||||
#define CFG_TUD_DFU_TRANSFER_BUFFER_SIZE 64
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_NET
|
||||
@ -265,11 +274,8 @@
|
||||
#error there is no benefit enable hub with max device is 1. Please disable hub or increase CFG_TUSB_HOST_DEVICE_MAX
|
||||
#endif
|
||||
|
||||
//------------- HID CLASS -------------//
|
||||
#define HOST_CLASS_HID ( CFG_TUH_HID_KEYBOARD + CFG_TUH_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC )
|
||||
|
||||
#ifndef CFG_TUSB_HOST_ENUM_BUFFER_SIZE
|
||||
#define CFG_TUSB_HOST_ENUM_BUFFER_SIZE 256
|
||||
#ifndef CFG_TUH_ENUMERATION_BUFSZIE
|
||||
#define CFG_TUH_ENUMERATION_BUFSZIE 256
|
||||
#endif
|
||||
|
||||
//------------- CLASS -------------//
|
||||
@ -282,6 +288,7 @@
|
||||
|
||||
// TUP_ARCH_STRICT_ALIGN if arch cannot access unaligned memory
|
||||
|
||||
|
||||
// ARMv7+ (M3-M7, M23-M33) can access unaligned memory
|
||||
#if (defined(__ARM_ARCH) && (__ARM_ARCH >= 7))
|
||||
#define TUP_ARCH_STRICT_ALIGN 0
|
||||
@ -289,6 +296,16 @@
|
||||
#define TUP_ARCH_STRICT_ALIGN 1
|
||||
#endif
|
||||
|
||||
// TUP_MCU_STRICT_ALIGN will overwrite TUP_ARCH_STRICT_ALIGN.
|
||||
// In case TUP_MCU_STRICT_ALIGN = 1 and TUP_ARCH_STRICT_ALIGN =0, we will not reply on compiler
|
||||
// to generate unaligned access code.
|
||||
// LPC_IP3511 Highspeed cannot access unaligned memory on USB_RAM
|
||||
#if TUD_OPT_HIGH_SPEED && (CFG_TUSB_MCU == OPT_MCU_LPC54XXX || CFG_TUSB_MCU == OPT_MCU_LPC55XX)
|
||||
#define TUP_MCU_STRICT_ALIGN 1
|
||||
#else
|
||||
#define TUP_MCU_STRICT_ALIGN 0
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Configuration Validation
|
||||
//------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user