Skip to content

Commit 9feda72

Browse files
committed
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.
1 parent 08c20fc commit 9feda72

File tree

2 files changed

+13
-46
lines changed

2 files changed

+13
-46
lines changed

usb/device/USBDevice/USBDevice.cpp

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@ void USBDevice::out(usb_ep_t endpoint)
866866
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
867867

868868
info->pending += 1;
869+
_phy->endpoint_read(endpoint, info->max_packet_size);
870+
869871
if (info->callback) {
870872
(this->*(info->callback))(endpoint);
871873
}
@@ -994,7 +996,11 @@ bool USBDevice::endpoint_add(usb_ep_t endpoint, uint32_t max_packet_size, usb_ep
994996
info->flags |= ENDPOINT_ENABLED;
995997
info->pending = 0;
996998
info->max_packet_size = max_packet_size;
997-
ret = true;
999+
ret = _phy->endpoint_read(endpoint, max_packet_size);
1000+
if (!ret) {
1001+
MBED_ASSERT(0);
1002+
endpoint_remove(endpoint);
1003+
}
9981004
}
9991005

10001006
unlock();
@@ -1191,36 +1197,7 @@ uint32_t USBDevice::endpoint_max_packet_size(usb_ep_t endpoint)
11911197
return size;
11921198
}
11931199

1194-
bool USBDevice::read_start(usb_ep_t endpoint)
1195-
{
1196-
lock();
1197-
1198-
if (!EP_INDEXABLE(endpoint)) {
1199-
MBED_ASSERT(0);
1200-
unlock();
1201-
return false;
1202-
}
1203-
1204-
if(!configured()) {
1205-
unlock();
1206-
return false;
1207-
}
1208-
1209-
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
1210-
if (!(info->flags & ENDPOINT_ENABLED)) {
1211-
// Invalid endpoint is being used
1212-
MBED_ASSERT(0);
1213-
unlock();
1214-
return false;
1215-
}
1216-
1217-
bool ret = _phy->endpoint_read(endpoint, info->max_packet_size);
1218-
1219-
unlock();
1220-
return ret;
1221-
}
1222-
1223-
bool USBDevice::read_finish(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size, uint32_t *size)
1200+
bool USBDevice::read(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size, uint32_t *size)
12241201
{
12251202
lock();
12261203

usb/device/USBDevice/USBDevice.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,12 @@ class USBDevice: public USBPhyEvents {
201201
*/
202202
uint32_t endpoint_max_packet_size(usb_ep_t endpoint);
203203

204-
/** Start a read on the given endpoint
205-
*
206-
* After the read is finished call read_start to get the result.
207-
*
208-
* @param endpoint endpoint to perform the read on
209-
* @return true if the read was started, false if no more reads can be started
210-
* @note This endpoint must already have been setup with endpoint_add
211-
*/
212-
bool read_start(usb_ep_t endpoint);
213-
214204
/**
215-
* Finish a read on the given endpoint
205+
* Read a packet on the given endpoint
216206
*
217-
* Get the contents of a read started with read_start. To ensure all
218-
* the data from this endpoint is read make sure the buffer and size
219-
* passed is at least as big as the maximum packet for this endpoint.
207+
* Get the contents of an IN transfer. To ensure all the data from this
208+
* endpoint is read make sure the buffer and size passed in is at least
209+
* as big as the maximum packet for this endpoint.
220210
*
221211
* @param endpoint endpoint to read data from
222212
* @param buffer buffer to fill with read data
@@ -226,7 +216,7 @@ class USBDevice: public USBPhyEvents {
226216
* @return true if the read was completed, otherwise false
227217
* @note This endpoint must already have been setup with endpoint_add
228218
*/
229-
bool read_finish(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size, uint32_t *size);
219+
bool read(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size, uint32_t *size);
230220

231221
/**
232222
* Write a data to the given endpoint

0 commit comments

Comments
 (0)