22 #include "USBDevice_Types.h" 24 #include "mbed_critical.h" 66 uint8_t dataTransferDirection;
84 USBDevice(
USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
149 bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, ep_cb_t
callback = NULL);
163 return endpoint_add(endpoint, max_packet, type, static_cast<ep_cb_t>(callback));
233 bool read_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size);
255 bool write_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size);
270 virtual const uint8_t *device_desc();
278 virtual const uint8_t *configuration_desc(uint8_t index) = 0;
285 virtual const uint8_t *string_langid_desc();
292 virtual const uint8_t *string_imanufacturer_desc();
299 virtual const uint8_t *string_iproduct_desc();
306 virtual const uint8_t *string_iserial_desc();
313 virtual const uint8_t *string_iconfiguration_desc();
320 virtual const uint8_t *string_iinterface_desc();
327 virtual uint16_t report_desc_dength()
408 void complete_request(RequestResult result, uint8_t *data = NULL, uint32_t size = 0);
441 virtual void callback_set_configuration(uint8_t configuration) = 0;
461 virtual void callback_set_interface(uint16_t interface, uint8_t alternate) = 0;
509 uint16_t product_release;
510 uint8_t device_descriptor[18];
514 virtual void power(
bool powered);
515 virtual void suspend(
bool suspended);
516 virtual void sof(
int frame_number);
517 virtual void reset();
518 virtual void ep0_setup();
519 virtual void ep0_out();
520 virtual void ep0_in();
521 virtual void out(usb_ep_t endpoint);
522 virtual void in(usb_ep_t endpoint);
524 bool _request_get_descriptor();
527 bool _request_set_address();
528 bool _request_set_configuration();
529 bool _request_set_feature();
530 bool _request_clear_feature();
531 bool _request_get_status();
532 bool _request_setup();
533 void _control_setup();
534 void _control_abort();
535 void _control_abort_start();
536 void _control_setup_continue();
538 bool _request_get_configuration();
539 bool _request_get_interface();
540 bool _request_set_interface();
541 void _change_state(DeviceState state);
542 void _run_later(
void (
USBDevice::*
function)());
544 void _complete_request();
545 void _complete_request_xfer_done();
546 void _complete_set_configuration();
547 void _complete_set_interface();
549 struct endpoint_info_t {
551 uint16_t max_packet_size;
552 uint16_t transfer_size;
557 struct usb_device_t {
558 volatile DeviceState state;
559 uint8_t configuration;
578 struct complete_request_t {
579 RequestResult result;
584 union complete_args_t {
585 complete_request_t request;
589 struct control_transfer_t {
597 UserCallback user_callback;
598 complete_args_t args;
601 endpoint_info_t _endpoint_info[32 - 2];
606 bool _endpoint_add_remove_allowed;
607 control_transfer_t _transfer;
608 usb_device_t _device;
609 uint32_t _max_packet_size_ep0;
615 uint16_t _current_interface;
616 uint8_t _current_alternate;
void complete_request(RequestResult result, uint8_t *data=NULL, uint32_t size=0)
Called to complete the setup stage of a callback request.
void sof_enable()
Enable the start of frame interrupt.
void endpoint_remove_all()
Remove all non-zero endpoints.
void deinit()
Power down this instance.
void complete_request_xfer_done(bool success)
Called to complete the data stage of a callback request.
void endpoint_stall(usb_ep_t endpoint)
Stall an endpoint.
void disconnect()
Disconnect a device.
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, ep_cb_t callback=NULL)
Add an endpoint.
void endpoint_remove(usb_ep_t endpoint)
Remove an endpoint.
uint32_t read_finish(usb_ep_t endpoint)
Get the status of a read.
virtual void callback_power(bool powered)
Called by USBDevice layer on power state change.
uint8_t * find_descriptor(uint8_t descriptor_type, uint8_t index=0)
Find a descriptor type inside the configuration descriptor.
virtual void callback_request_xfer_done(const setup_packet_t *setup, bool aborted)=0
Called by USBDevice on data stage completion.
void connect()
Connect a device.
Abstract interface to physical USB hardware.
virtual void callback_reset()
Called by USBDevice layer on bus reset.
void endpoint_unstall(usb_ep_t endpoint)
Unstall an endpoint.
void complete_set_configuration(bool success)
Called to complete a set configuration command.
virtual void callback_request(const setup_packet_t *setup)=0
Called by USBDevice on Endpoint0 request.
virtual void callback_state_change(DeviceState new_state)=0
Called when USB changes state.
bool read_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size)
start a read on the given endpoint
void sof_disable()
Disable the start of frame interrupt.
virtual void lock()
Acquire exclusive access to this instance USBDevice.
const usb_ep_table_t * endpoint_table()
Get the endpoint table of this device.
virtual void start_process()
Callback called to indicate the USB processing needs to be done.
uint32_t endpoint_max_packet_size(usb_ep_t endpoint)
Get the current maximum size for this endpoint.
virtual void unlock()
Release exclusive access to this instance USBDevice.
void init()
Initialize this instance.
bool write_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size)
Write a data to the given endpoint.
virtual ~USBDevice()
Cleanup this USBDevice.
void endpoint_abort(usb_ep_t endpoint)
Abort the current transfer on this endpoint.
USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
Instantiate a new USBDevice with the given parameters.
bool configured()
Check if the device is configured.
void complete_set_interface(bool success)
Called to complete a set interface command.
virtual void callback_sof(int frame_number)
Called by USBDevice layer on each new USB frame.
Event handler for USBPhy.
virtual void assert_locked()
Assert that the current thread of execution holds the lock.
uint32_t write_finish(usb_ep_t endpoint)
Get the status of a write.
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, void(T::*callback)())
Add an endpoint.