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-04 19:26:54 +07:00
|
|
|
typedef bool (*tuh_control_complete_cb_t)(uint8_t daddr, tusb_control_request_t const * request, xfer_result_t result);
|
2020-10-12 00:35:38 +07:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Carry out control transfer
|
2022-03-04 19:26:54 +07:00
|
|
|
bool tuh_control_xfer (uint8_t daddr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb);
|
2020-09-07 15:19:20 +07:00
|
|
|
|
2022-03-04 21:41:27 +07:00
|
|
|
// Set Configuration
|
|
|
|
// config_num = 0 will un-configure device. Note: config_num = config_descriptor_index + 1
|
|
|
|
bool tuh_configuration_set(uint8_t daddr, uint8_t config_num, tuh_control_complete_cb_t complete_cb);
|
|
|
|
|
|
|
|
//------------- descriptors -------------//
|
|
|
|
|
|
|
|
// Get an descriptor
|
|
|
|
bool tuh_descriptor_get(uint8_t daddr, uint8_t type, uint8_t index,
|
|
|
|
void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
|
|
|
|
|
|
|
|
// Get device descriptor
|
|
|
|
bool tuh_descriptor_device_get(uint8_t daddr, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
|
|
|
|
|
|
|
|
// Get configuration descriptor
|
|
|
|
bool tuh_descriptor_configuration_get(uint8_t daddr, uint8_t index, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
|
|
|
|
|
|
|
|
// Get string descriptor
|
|
|
|
bool tuh_descriptor_string_get(uint8_t daddr, uint16_t language_id, uint8_t index,
|
2022-03-04 22:23:56 +07:00
|
|
|
void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
|
2022-03-04 21:41:27 +07:00
|
|
|
|
2022-03-04 22:23:56 +07:00
|
|
|
// Get manufacturer string descriptor
|
|
|
|
bool tuh_descriptor_string_manufacturer_get(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
|
2022-03-04 21:41:27 +07:00
|
|
|
|
2022-03-04 22:23:56 +07:00
|
|
|
// Get product string descriptor
|
|
|
|
bool tuh_descriptor_string_product_get(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
|
|
|
|
|
|
|
|
// Get serial string descriptor
|
|
|
|
bool tuh_descriptor_string_serial_get(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
|
2022-03-04 21:41:27 +07:00
|
|
|
|
2022-03-09 11:03:29 +07:00
|
|
|
// Get HID report descriptor
|
|
|
|
bool tuh_descriptor_hid_report_get(uint8_t daddr, uint8_t itf_num, uint8_t desc_type, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
|
|
|
|
|
2013-03-24 15:50:49 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// APPLICATION CALLBACK
|
|
|
|
//--------------------------------------------------------------------+
|
2020-09-07 15:19:20 +07:00
|
|
|
//TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device);
|
2018-12-10 19:25:57 +07:00
|
|
|
|
2021-06-10 16:48:20 +07:00
|
|
|
// Invoked when device is mounted (configured)
|
2022-03-04 19:26:54 +07:00
|
|
|
TU_ATTR_WEAK void tuh_mount_cb (uint8_t daddr);
|
2018-12-10 19:25:57 +07:00
|
|
|
|
2021-06-10 16:48:20 +07:00
|
|
|
/// Invoked when device is unmounted (bus reset/unplugged)
|
2022-03-04 19:26:54 +07:00
|
|
|
TU_ATTR_WEAK void tuh_umount_cb(uint8_t daddr);
|
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
|