mirror of https://github.com/ARMmbed/mbed-os.git
Change USBDevice read handling
Remove the USBDevice function read_start and automatically start all reads internally in USBDevice. This patch also renames the function read_finish to read.pull/6479/head
parent
4aba910249
commit
311e8b7d0d
|
@ -866,6 +866,8 @@ void USBDevice::out(usb_ep_t endpoint)
|
||||||
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
|
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
|
||||||
|
|
||||||
info->pending += 1;
|
info->pending += 1;
|
||||||
|
_phy->endpoint_read(endpoint, info->max_packet_size);
|
||||||
|
|
||||||
if (info->callback) {
|
if (info->callback) {
|
||||||
(this->*(info->callback))(endpoint);
|
(this->*(info->callback))(endpoint);
|
||||||
}
|
}
|
||||||
|
@ -994,7 +996,11 @@ bool USBDevice::endpoint_add(usb_ep_t endpoint, uint32_t max_packet_size, usb_ep
|
||||||
info->flags |= ENDPOINT_ENABLED;
|
info->flags |= ENDPOINT_ENABLED;
|
||||||
info->pending = 0;
|
info->pending = 0;
|
||||||
info->max_packet_size = max_packet_size;
|
info->max_packet_size = max_packet_size;
|
||||||
ret = true;
|
ret = _phy->endpoint_read(endpoint, max_packet_size);
|
||||||
|
if (!ret) {
|
||||||
|
MBED_ASSERT(0);
|
||||||
|
endpoint_remove(endpoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -1191,36 +1197,7 @@ uint32_t USBDevice::endpoint_max_packet_size(usb_ep_t endpoint)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool USBDevice::read_start(usb_ep_t endpoint)
|
bool USBDevice::read(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size, uint32_t *size)
|
||||||
{
|
|
||||||
lock();
|
|
||||||
|
|
||||||
if (!EP_INDEXABLE(endpoint)) {
|
|
||||||
MBED_ASSERT(0);
|
|
||||||
unlock();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!configured()) {
|
|
||||||
unlock();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
|
|
||||||
if (!(info->flags & ENDPOINT_ENABLED)) {
|
|
||||||
// Invalid endpoint is being used
|
|
||||||
MBED_ASSERT(0);
|
|
||||||
unlock();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ret = _phy->endpoint_read(endpoint, info->max_packet_size);
|
|
||||||
|
|
||||||
unlock();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool USBDevice::read_finish(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size, uint32_t *size)
|
|
||||||
{
|
{
|
||||||
lock();
|
lock();
|
||||||
|
|
||||||
|
|
|
@ -201,22 +201,12 @@ public:
|
||||||
*/
|
*/
|
||||||
uint32_t endpoint_max_packet_size(usb_ep_t endpoint);
|
uint32_t endpoint_max_packet_size(usb_ep_t endpoint);
|
||||||
|
|
||||||
/** Start a read on the given endpoint
|
|
||||||
*
|
|
||||||
* After the read is finished call read_start to get the result.
|
|
||||||
*
|
|
||||||
* @param endpoint endpoint to perform the read on
|
|
||||||
* @return true if the read was started, false if no more reads can be started
|
|
||||||
* @note This endpoint must already have been setup with endpoint_add
|
|
||||||
*/
|
|
||||||
bool read_start(usb_ep_t endpoint);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finish a read on the given endpoint
|
* Read a packet on the given endpoint
|
||||||
*
|
*
|
||||||
* Get the contents of a read started with read_start. To ensure all
|
* Get the contents of an IN transfer. To ensure all the data from this
|
||||||
* the data from this endpoint is read make sure the buffer and size
|
* endpoint is read make sure the buffer and size passed in is at least
|
||||||
* passed is at least as big as the maximum packet for this endpoint.
|
* as big as the maximum packet for this endpoint.
|
||||||
*
|
*
|
||||||
* @param endpoint endpoint to read data from
|
* @param endpoint endpoint to read data from
|
||||||
* @param buffer buffer to fill with read data
|
* @param buffer buffer to fill with read data
|
||||||
|
@ -226,7 +216,7 @@ public:
|
||||||
* @return true if the read was completed, otherwise false
|
* @return true if the read was completed, otherwise false
|
||||||
* @note This endpoint must already have been setup with endpoint_add
|
* @note This endpoint must already have been setup with endpoint_add
|
||||||
*/
|
*/
|
||||||
bool read_finish(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size, uint32_t *size);
|
bool read(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size, uint32_t *size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a data to the given endpoint
|
* Write a data to the given endpoint
|
||||||
|
|
Loading…
Reference in New Issue