2019-03-20 16:11:42 +07:00
|
|
|
/*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2019-05-14 11:48:05 +07:00
|
|
|
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
2019-03-20 16:11:42 +07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-01-22 17:41:06 +07:00
|
|
|
|
2014-03-24 12:35:44 +07:00
|
|
|
#ifndef _TUSB_USBH_H_
|
|
|
|
#define _TUSB_USBH_H_
|
2013-01-22 17:41:06 +07:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-05-27 18:18:30 +07:00
|
|
|
#include "common/tusb_common.h"
|
2013-01-22 17:41:06 +07:00
|
|
|
#include "hcd.h"
|
|
|
|
|
2013-01-27 12:18:01 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// MACRO CONSTANT TYPEDEF
|
|
|
|
//--------------------------------------------------------------------+
|
2020-09-07 15:19:20 +07:00
|
|
|
|
2022-03-11 21:57:55 +07:00
|
|
|
// forward declaration
|
|
|
|
struct tuh_control_xfer_s;
|
|
|
|
typedef struct tuh_control_xfer_s tuh_control_xfer_t;
|
|
|
|
|
|
|
|
typedef bool (*tuh_control_xfer_cb_t)(uint8_t daddr, tuh_control_xfer_t const * xfer, xfer_result_t result);
|
|
|
|
|
|
|
|
struct tuh_control_xfer_s
|
|
|
|
{
|
2022-03-17 12:53:52 +07:00
|
|
|
uint8_t ep_addr;
|
|
|
|
tusb_control_request_t const* setup;
|
|
|
|
uint32_t actual_len;
|
|
|
|
|
2022-03-11 21:57:55 +07:00
|
|
|
uint8_t* buffer;
|
|
|
|
tuh_control_xfer_cb_t complete_cb;
|
|
|
|
uintptr_t user_arg;
|
|
|
|
};
|
2020-10-12 00:35:38 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// APPLICATION CALLBACK
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
|
|
|
//TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device);
|
|
|
|
|
|
|
|
// Invoked when device is mounted (configured)
|
|
|
|
TU_ATTR_WEAK void tuh_mount_cb (uint8_t daddr);
|
|
|
|
|
|
|
|
/// Invoked when device is unmounted (bus reset/unplugged)
|
|
|
|
TU_ATTR_WEAK void tuh_umount_cb(uint8_t daddr);
|
|
|
|
|
2013-01-22 17:41:06 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// APPLICATION API
|
|
|
|
//--------------------------------------------------------------------+
|
2020-09-05 13:57:07 +07:00
|
|
|
|
|
|
|
// Init host stack
|
2021-05-11 17:32:52 +07:00
|
|
|
bool tuh_init(uint8_t rhport);
|
2020-09-05 13:57:07 +07:00
|
|
|
|
2021-05-02 01:46:22 +07:00
|
|
|
// Check if host stack is already initialized
|
|
|
|
bool tuh_inited(void);
|
|
|
|
|
2020-09-05 13:57:07 +07:00
|
|
|
// Task function should be called in main/rtos loop
|
2018-12-13 14:51:37 +07:00
|
|
|
void tuh_task(void);
|
|
|
|
|
2019-11-21 22:20:30 +07:00
|
|
|
// Interrupt handler, name alias to HCD
|
2020-09-03 13:12:09 +07:00
|
|
|
extern void hcd_int_handler(uint8_t rhport);
|
|
|
|
#define tuh_int_handler hcd_int_handler
|
2019-11-21 22:20:30 +07:00
|
|
|
|
2022-03-04 19:26:54 +07:00
|
|
|
bool tuh_vid_pid_get(uint8_t daddr, uint16_t* vid, uint16_t* pid);
|
2022-03-03 16:53:22 -08:00
|
|
|
|
2022-03-04 19:26:54 +07:00
|
|
|
tusb_speed_t tuh_speed_get(uint8_t daddr);
|
2013-03-24 15:50:49 +07:00
|
|
|
|
2021-08-24 12:30:57 +07:00
|
|
|
// Check if device is connected and configured
|
2022-03-04 19:26:54 +07:00
|
|
|
bool tuh_mounted(uint8_t daddr);
|
2021-08-24 12:30:57 +07:00
|
|
|
|
|
|
|
// Check if device is suspended
|
2022-03-04 21:41:27 +07:00
|
|
|
TU_ATTR_ALWAYS_INLINE
|
2022-03-04 19:26:54 +07:00
|
|
|
static inline bool tuh_suspended(uint8_t daddr)
|
2021-08-24 12:30:57 +07:00
|
|
|
{
|
|
|
|
// TODO implement suspend & resume on host
|
2022-03-04 19:26:54 +07:00
|
|
|
(void) daddr;
|
2021-08-24 12:30:57 +07:00
|
|
|
return false;
|
|
|
|
}
|
2021-05-13 00:11:20 +07:00
|
|
|
|
|
|
|
// Check if device is ready to communicate with
|
|
|
|
TU_ATTR_ALWAYS_INLINE
|
2022-03-04 19:26:54 +07:00
|
|
|
static inline bool tuh_ready(uint8_t daddr)
|
2021-05-13 00:11:20 +07:00
|
|
|
{
|
2022-03-04 19:26:54 +07:00
|
|
|
return tuh_mounted(daddr) && !tuh_suspended(daddr);
|
2021-05-13 00:11:20 +07:00
|
|
|
}
|
|
|
|
|
2022-03-17 12:53:52 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// Endpoint Asynchronous (non-blocking)
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
2022-03-10 23:16:59 +07:00
|
|
|
// Carry out a control transfer
|
2022-03-13 17:45:46 +07:00
|
|
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
|
|
|
// Blocking if complete callback is NULL, in this case 'user_arg' must contain xfer_result_t variable
|
2022-03-17 12:53:52 +07:00
|
|
|
bool tuh_control_xfer(uint8_t daddr, tuh_control_xfer_t const* xfer);
|
2022-03-11 21:57:55 +07:00
|
|
|
|
2022-03-17 12:53:52 +07:00
|
|
|
//bool tuh_edpt_xfer(uint8_t daddr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
|
2020-09-07 15:19:20 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Set Configuration (control transfer)
|
2022-03-04 21:41:27 +07:00
|
|
|
// config_num = 0 will un-configure device. Note: config_num = config_descriptor_index + 1
|
2022-03-13 17:45:46 +07:00
|
|
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
|
|
|
// Blocking if complete callback is NULL, in this case 'user_arg' must contain xfer_result_t variable
|
2022-03-11 21:57:55 +07:00
|
|
|
bool tuh_configuration_set(uint8_t daddr, uint8_t config_num,
|
|
|
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
2022-03-04 21:41:27 +07:00
|
|
|
|
2022-03-17 12:53:52 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// Endpoint Synchronous (blocking)
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
|
|
|
// Sync (blocking) version of tuh_control_xfer()
|
|
|
|
// return transfer result
|
|
|
|
uint8_t tuh_control_xfer_sync(uint8_t daddr, tuh_control_xfer_t const* xfer, uint32_t timeout_ms);
|
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// Descriptors Asynchronous (non-blocking)
|
|
|
|
//--------------------------------------------------------------------+
|
2022-03-04 21:41:27 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Get an descriptor (control transfer)
|
|
|
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
2022-03-11 21:57:55 +07:00
|
|
|
bool tuh_descriptor_get(uint8_t daddr, uint8_t type, uint8_t index, void* buffer, uint16_t len,
|
|
|
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
2022-03-04 21:41:27 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Get device descriptor (control transfer)
|
|
|
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
2022-03-11 21:57:55 +07:00
|
|
|
bool tuh_descriptor_get_device(uint8_t daddr, void* buffer, uint16_t len,
|
|
|
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
2022-03-04 21:41:27 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Get configuration descriptor (control transfer)
|
|
|
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
2022-03-11 21:57:55 +07:00
|
|
|
bool tuh_descriptor_get_configuration(uint8_t daddr, uint8_t index, void* buffer, uint16_t len,
|
|
|
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Get HID report descriptor (control transfer)
|
|
|
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
|
|
|
bool tuh_descriptor_get_hid_report(uint8_t daddr, uint8_t itf_num, uint8_t desc_type, uint8_t index, void* buffer, uint16_t len,
|
2022-03-11 21:57:55 +07:00
|
|
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
2022-03-04 21:41:27 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Get string descriptor (control transfer)
|
|
|
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
|
|
|
// Blocking if complete callback is NULL, in this case 'user_arg' must contain xfer_result_t variable
|
|
|
|
bool tuh_descriptor_get_string(uint8_t daddr, uint8_t index, uint16_t language_id, void* buffer, uint16_t len,
|
2022-03-11 21:57:55 +07:00
|
|
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
2022-03-04 21:41:27 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Get manufacturer string descriptor (control transfer)
|
|
|
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
2022-03-11 21:57:55 +07:00
|
|
|
bool tuh_descriptor_get_manufacturer_string(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len,
|
|
|
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
2022-03-04 21:41:27 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Get product string descriptor (control transfer)
|
|
|
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
2022-03-11 21:57:55 +07:00
|
|
|
bool tuh_descriptor_get_product_string(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len,
|
|
|
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
2022-03-04 22:23:56 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Get serial string descriptor (control transfer)
|
|
|
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
2022-03-11 21:57:55 +07:00
|
|
|
bool tuh_descriptor_get_serial_string(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len,
|
|
|
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
2022-03-09 11:03:29 +07:00
|
|
|
|
2013-03-24 15:50:49 +07:00
|
|
|
//--------------------------------------------------------------------+
|
2022-03-13 17:45:46 +07:00
|
|
|
// Descriptors Synchronous (blocking)
|
2013-03-24 15:50:49 +07:00
|
|
|
//--------------------------------------------------------------------+
|
2018-12-10 19:25:57 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Sync (blocking) version of tuh_descriptor_get()
|
|
|
|
// return transfer result
|
|
|
|
uint8_t tuh_descriptor_get_sync(uint8_t daddr, uint8_t type, uint8_t index, void* buffer, uint16_t len, uint8_t timeout_ms);
|
2018-12-10 19:25:57 +07:00
|
|
|
|
2022-03-13 17:45:46 +07:00
|
|
|
// Sync (blocking) version of tuh_descriptor_get_device()
|
|
|
|
// return transfer result
|
|
|
|
uint8_t tuh_descriptor_get_device_sync(uint8_t daddr, void* buffer, uint16_t len, uint8_t timeout_ms);
|
|
|
|
|
|
|
|
// Sync (blocking) version of tuh_descriptor_get_configuration()
|
|
|
|
// return transfer result
|
|
|
|
uint8_t tuh_descriptor_get_configuration_sync(uint8_t daddr, uint8_t index, void* buffer, uint16_t len, uint8_t timeout_ms);
|
|
|
|
|
|
|
|
// Sync (blocking) version of tuh_descriptor_get_hid_report()
|
|
|
|
// return transfer result
|
|
|
|
uint8_t tuh_descriptor_get_hid_report_sync(uint8_t daddr, uint8_t itf_num, uint8_t desc_type, uint8_t index, void* buffer, uint16_t len, uint8_t timeout_ms);
|
|
|
|
|
|
|
|
// Sync (blocking) version of tuh_descriptor_get_string()
|
|
|
|
// return transfer result
|
|
|
|
uint8_t tuh_descriptor_get_string_sync(uint8_t daddr, uint8_t index, uint16_t language_id, void* buffer, uint16_t len, uint8_t timeout_ms);
|
|
|
|
|
|
|
|
// Sync (blocking) version of tuh_descriptor_get_manufacturer_string()
|
|
|
|
// return transfer result
|
|
|
|
uint8_t tuh_descriptor_get_manufacturer_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, uint8_t timeout_ms);
|
|
|
|
|
|
|
|
// Sync (blocking) version of tuh_descriptor_get_product_string()
|
|
|
|
// return transfer result
|
|
|
|
uint8_t tuh_descriptor_get_product_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, uint8_t timeout_ms);
|
|
|
|
|
|
|
|
// Sync (blocking) version of tuh_descriptor_get_serial_string()
|
|
|
|
// return transfer result
|
|
|
|
uint8_t tuh_descriptor_get_serial_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, uint8_t timeout_ms);
|
2013-02-06 12:03:01 +07:00
|
|
|
|
2013-01-22 17:41:06 +07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-06-10 16:55:12 +07:00
|
|
|
#endif
|