22#include "USBDevice_Types.h"
24#include "mbed_critical.h"
60 uint8_t dataTransferDirection;
78 USBDevice(
USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
162 bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type,
void (T::*callback)())
234 bool read_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size);
256 bool write_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size);
271 virtual const uint8_t *device_desc();
279 virtual const uint8_t *configuration_desc(uint8_t index) = 0;
286 virtual const uint8_t *string_langid_desc();
293 virtual const uint8_t *string_imanufacturer_desc();
300 virtual const uint8_t *string_iproduct_desc();
307 virtual const uint8_t *string_iserial_desc();
314 virtual const uint8_t *string_iconfiguration_desc();
321 virtual const uint8_t *string_iinterface_desc();
328 virtual uint16_t report_desc_dength()
442 virtual void callback_set_configuration(uint8_t configuration) = 0;
462 virtual void callback_set_interface(uint16_t interface, uint8_t alternate) = 0;
510 uint16_t product_release;
511 uint8_t device_descriptor[18];
515 virtual void power(
bool powered);
516 virtual void suspend(
bool suspended);
517 virtual void sof(
int frame_number);
518 virtual void reset();
519 virtual void ep0_setup();
520 virtual void ep0_out();
521 virtual void ep0_in();
522 virtual void out(usb_ep_t endpoint);
523 virtual void in(usb_ep_t endpoint);
525 bool _request_get_descriptor();
528 bool _request_set_address();
529 bool _request_set_configuration();
530 bool _request_set_feature();
531 bool _request_clear_feature();
532 bool _request_get_status();
533 bool _request_setup();
534 void _control_setup();
535 void _control_abort();
536 void _control_abort_start();
537 void _control_setup_continue();
539 bool _request_get_configuration();
540 bool _request_get_interface();
541 bool _request_set_interface();
542 void _change_state(DeviceState state);
543 void _run_later(
void (
USBDevice::*function)());
545 void _complete_request();
546 void _complete_request_xfer_done();
547 void _complete_set_configuration();
548 void _complete_set_interface();
550 void _clear_endpoints();
552 struct endpoint_info_t {
554 uint16_t max_packet_size;
555 uint16_t transfer_size;
560 struct usb_device_t {
561 volatile DeviceState state;
562 uint8_t configuration;
581 struct complete_request_t {
582 RequestResult result;
587 union complete_args_t {
588 complete_request_t request;
592 struct control_transfer_t {
593 setup_packet_t setup;
600 UserCallback user_callback;
601 complete_args_t args;
604 endpoint_info_t _endpoint_info[32 - 2];
609 bool _endpoint_add_remove_allowed;
610 control_transfer_t _transfer;
611 usb_device_t _device;
612 uint32_t _max_packet_size_ep0;
618 uint16_t _current_interface;
619 uint8_t _current_alternate;
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, void(T::*callback)())
Add an endpoint.
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.
uint8_t * find_descriptor(uint8_t descriptor_type, uint8_t index=0)
Find a descriptor type inside the configuration descriptor.
uint32_t endpoint_max_packet_size(usb_ep_t endpoint)
Get the current maximum size for this endpoint.
void connect()
Connect a device This method can also be used to resume USB operation when USB power is detected afte...
virtual void callback_power(bool powered)
Called by USBDevice layer on power state change.
uint32_t write_finish(usb_ep_t endpoint)
Get the status of a write.
virtual void callback_reset()
Called by USBDevice layer on bus reset.
void complete_set_configuration(bool success)
Called to complete a set configuration command.
void sof_enable()
Enable the start of frame interrupt.
virtual void callback_request_xfer_done(const setup_packet_t *setup, bool aborted)=0
Called by USBDevice on data stage completion.
bool read_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size)
start a read on the given endpoint
bool configured()
Check if the device is configured.
uint32_t read_finish(usb_ep_t endpoint)
Get the status of a read.
USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
Instantiate a new USBDevice with the given parameters.
void endpoint_remove(usb_ep_t endpoint)
Remove an endpoint.
void complete_request_xfer_done(bool success)
Called to complete the data stage of a callback request.
virtual void callback_request(const setup_packet_t *setup)=0
Called by USBDevice on Endpoint0 request.
const usb_ep_table_t * endpoint_table()
Get the endpoint table of this device.
void disconnect()
Disconnect a device.
void deinit()
Power down this instance.
virtual void callback_sof(int frame_number)
Called by USBDevice layer on each new USB frame.
void complete_set_interface(bool success)
Called to complete a set interface command.
virtual void callback_state_change(DeviceState new_state)=0
Called when USB changes state.
void endpoint_abort(usb_ep_t endpoint)
Abort the current transfer on this endpoint.
virtual ~USBDevice()
Cleanup this USBDevice.
void endpoint_unstall(usb_ep_t endpoint)
Un-stall an endpoint.
void endpoint_stall(usb_ep_t endpoint)
Stall an endpoint.
virtual void start_process()
Callback called to indicate the USB processing needs to be done.
bool endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback< void()> callback=nullptr)
Add an endpoint.
virtual void lock()
Acquire exclusive access to this instance USBDevice.
virtual void unlock()
Release exclusive access to this instance USBDevice.
virtual void assert_locked()
Assert that the current thread of execution holds the lock.
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_disable()
Disable the start of frame interrupt.
void endpoint_remove_all()
Remove all non-zero endpoints.
Event handler for USBPhy.
Abstract interface to physical USB hardware.
Callback class based on template specialization.