Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00077 #ifndef HAL_USB_H__
00078 #define HAL_USB_H__
00079
00080 #include <stdint.h>
00081 #include <stdbool.h>
00082
00083 #include "hal_usb_desc.h"
00084 #include "config.h"
00085
00086 #ifndef USB_DESC_TEMPLATE
00087 #error "USB_DESC_TEMPLATE not defined. Please include a file with g_usb_string_desc, g_usb_conf_desc and g_usb_dev_desc defined"
00088 #endif
00089
00090 #define USB_BM_STATE_CONFIGURED 0x01
00091 #define USB_BM_STATE_ALLOW_REMOTE_WAKEUP 0x02
00092 #define USB_BM_STATE_HOST_WU 0x04
00093
00099 typedef enum {
00100 ATTACHED,
00101 POWERED,
00102 DEFAULT,
00103 ADDRESSED,
00104 CONFIGURED,
00105 SUSPENDED
00106 } hal_usb_state_t;
00107
00112 typedef struct {
00113 uint8_t bmRequestType;
00131 uint8_t bRequest;
00133 uint8_t wValueMsb;
00134 uint8_t wValueLsb;
00135 uint8_t wIndex;
00136 uint8_t wLength;
00137
00138 } hal_usb_device_req;
00139
00143 typedef enum {
00144 STALL,
00145 NAK,
00146 ACK,
00147 NO_RESPONSE,
00148 DATA,
00149 EMPTY_RESPONSE
00150 } hal_usb_dev_req_resp_t;
00151
00159 typedef hal_usb_dev_req_resp_t (*hal_usb_cb_device_req_t)(hal_usb_device_req* device_req, uint8_t ** data_ptr, uint8_t* size) large reentrant;
00160
00168 typedef uint8_t (*hal_usb_cb_endpoint_t)(uint8_t* adr_ptr, uint8_t* size) large reentrant;
00169
00174 typedef void (*hal_usb_cb_resume_t)() large reentrant;
00175
00181 typedef void (*hal_usb_cb_suspend_t)(uint8_t allow_remote_wu) large reentrant;
00182
00186 typedef void (*hal_usb_cb_reset_t)() large reentrant;
00187
00192 typedef struct {
00193 usb_descs_templ_t descs;
00194 uint8_t bm_state;
00195 uint8_t current_config;
00196 uint8_t current_alt_interface;
00197 hal_usb_state_t state;
00199 hal_usb_cb_device_req_t device_req;
00200 hal_usb_cb_reset_t reset;
00201 hal_usb_cb_resume_t resume;
00202 hal_usb_cb_suspend_t suspend;
00203 } hal_usb_t;
00204
00213 void hal_usb_init(
00214 bool usb_disconnect,
00215 hal_usb_cb_device_req_t device_req,
00216 hal_usb_cb_reset_t reset,
00217 hal_usb_cb_resume_t resume,
00218 hal_usb_cb_suspend_t suspend);
00219
00225 void hal_usb_send_data(uint8_t ep_in_num, uint8_t* buffer, uint8_t bytes_to_send);
00226
00233 void hal_usb_endpoint_config(uint8_t ep_num, uint8_t ep_size, hal_usb_cb_endpoint_t endpoint_isr);
00234
00239 void hal_usb_endpoint_stall(uint8_t ep_num, bool stall);
00240
00244 hal_usb_state_t hal_usb_get_state();
00245
00247 uint8_t hal_usb_get_address();
00248
00250 void hal_usb_wakeup();
00251
00253 void hal_usb_reset();
00254
00256 void hal_usb_bus_disconnect();
00257
00259 void hal_usb_bus_connect();
00260
00262 void hal_usb_sleep();
00263
00264 extern hal_usb_t volatile g_hal_usb;
00265
00266 #endif // HAL_USB_H__
00267