tinyusb
hcd.h
Go to the documentation of this file.
1 /**************************************************************************/
37 /**************************************************************************/
38 
43 #ifndef _TUSB_HCD_H_
44 #define _TUSB_HCD_H_
45 
46 #include "common/common.h"
47 
48 #ifdef __cplusplus
49  extern "C" {
50 #endif
51 
52 //--------------------------------------------------------------------+
53 // MACRO CONSTANT TYPEDEF
54 //--------------------------------------------------------------------+
55 typedef struct {
56  uint8_t dev_addr;
57  uint8_t xfer_type;
58  uint8_t index;
59  uint8_t reserved;
61 
62 static inline bool pipehandle_is_valid(pipe_handle_t pipe_hdl) ATTR_CONST ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
63 static inline bool pipehandle_is_valid(pipe_handle_t pipe_hdl)
64 {
65  return pipe_hdl.dev_addr > 0;
66 }
67 
68 static inline bool pipehandle_is_equal(pipe_handle_t x, pipe_handle_t y) ATTR_CONST ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
69 static inline bool pipehandle_is_equal(pipe_handle_t x, pipe_handle_t y)
70 {
71  return (x.dev_addr == y.dev_addr) && (x.xfer_type == y.xfer_type) && (x.index == y.index);
72 }
73 
74 //--------------------------------------------------------------------+
75 // USBH-HCD API
76 //--------------------------------------------------------------------+
77 tusb_error_t hcd_init(void) ATTR_WARN_UNUSED_RESULT;
78 void hcd_isr(uint8_t hostid);
79 
80 //--------------------------------------------------------------------+
81 // PIPE API
82 //--------------------------------------------------------------------+
83 // TODO control xfer should be used via usbh layer
84 tusb_error_t hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) ATTR_WARN_UNUSED_RESULT;
85 tusb_error_t hcd_pipe_control_xfer(uint8_t dev_addr, tusb_control_request_t const * p_request, uint8_t data[]) ATTR_WARN_UNUSED_RESULT;
86 tusb_error_t hcd_pipe_control_close(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT;
87 
88 pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const * endpoint_desc, uint8_t class_code) ATTR_WARN_UNUSED_RESULT;
89 tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet
90 tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT;
91 tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) /*ATTR_WARN_UNUSED_RESULT*/;
92 
93 bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl) ATTR_PURE;
94 bool hcd_pipe_is_error(pipe_handle_t pipe_hdl) ATTR_PURE;
95 bool hcd_pipe_is_stalled(pipe_handle_t pipe_hdl) ATTR_PURE; // stalled also counted as error
96 
97 uint8_t hcd_pipe_get_endpoint_addr(pipe_handle_t pipe_hdl) ATTR_PURE;
98 tusb_error_t hcd_pipe_clear_stall(pipe_handle_t pipe_hdl);
99 
100 #if 0
101 tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT;
102 #endif
103 
104 //--------------------------------------------------------------------+
105 // PORT API
106 //--------------------------------------------------------------------+
108 bool hcd_port_connect_status(uint8_t hostid) ATTR_PURE ATTR_WARN_UNUSED_RESULT; // TODO make inline if possible
109 void hcd_port_reset(uint8_t hostid);
110 tusb_speed_t hcd_port_speed_get(uint8_t hostid) ATTR_PURE ATTR_WARN_UNUSED_RESULT; // TODO make inline if possible
111 void hcd_port_unplug(uint8_t hostid); // called by usbh to instruct hcd that it can execute unplug procedure
112 
113 #ifdef __cplusplus
114  }
115 #endif
116 
117 #endif /* _TUSB_HCD_H_ */
118 
tusb_speed_t
defined base on EHCI specs value for Endpoint Speed
Definition: tusb_types.h:51
#define ATTR_WARN_UNUSED_RESULT
The warn_unused_result attribute causes a warning to be emitted if a caller of the function with this...
Definition: compiler_gcc.h:118
Definition: std_request.h:49
bool hcd_port_connect_status(uint8_t hostid) ATTR_PURE ATTR_WARN_UNUSED_RESULT
return the current connect status of roothub port
Definition: hcd.h:55
#define ATTR_PURE
Many functions have no effects except the return value and their return value depends only on the par...
Definition: compiler_gcc.h:96
USB Standard Endpoint Descriptor (section 9.6.1 table 9-13)
Definition: std_descriptors.h:104
tusb_error_t
Error Code returned.
Definition: tusb_errors.h:100
#define ATTR_ALWAYS_INLINE
Generally, functions are not inlined unless optimization is specified. For functions declared inline...
Definition: compiler_gcc.h:89
#define ATTR_CONST
Many functions do not examine any values except their arguments, and have no effects except the retur...
Definition: compiler_gcc.h:100