Skip to content

Commit afa403e

Browse files
committed
Add device connected callback to USBHost.
Add setEnumeratingDeviceIndex to IUSBEnumerator.h
1 parent faae263 commit afa403e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Diff for: src/USBHost/IUSBEnumerator.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class IUSBEnumerator
3131
virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) = 0; //Must return true if the interface should be parsed
3232
virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) = 0; //Must return true if the endpoint will be used
3333
virtual void parseConfigEntry(uint8_t type, uint8_t sub_type, uint8_t *data, uint32_t len) {};
34+
virtual void setEnumeratingDeviceIndex(int index) {};
3435
};
3536

3637
#endif /*IUSBENUMERATOR_H_*/

Diff for: src/USBHost/USBHost.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ void USBHost::usb_process()
225225

226226
if ((i < MAX_DEVICE_CONNECTED) && !too_many_hub) {
227227
deviceInUse[i] = true;
228+
if(device_connected_callback)
229+
device_connected_callback(i);
228230
}
229231

230232
} while(0);
@@ -960,6 +962,7 @@ USB_TYPE USBHost::enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerato
960962
dev->setPid(data[10] | (data[11] << 8));
961963
USB_DBG("CLASS: %02X \t VID: %04X \t PID: %04X", data[4], data[8] | (data[9] << 8), data[10] | (data[11] << 8));
962964

965+
pEnumerator->setEnumeratingDeviceIndex(index);
963966
pEnumerator->setVidPid( data[8] | (data[9] << 8), data[10] | (data[11] << 8) );
964967

965968
res = getConfigurationDescriptor(dev, data, sizeof(data), &total_conf_descr_length);

Diff for: src/USBHost/USBHost.h

+11
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ class USBHost : public USBHALHost {
189189
}
190190
}
191191

192+
193+
/**
194+
* Callback for connected device index
195+
*/
196+
void setDeviceConnectedCallback(mbed::Callback<void(uint8_t uDeviceIndex)> callback)
197+
{
198+
device_connected_callback = callback;
199+
}
200+
192201
/**
193202
* Instantiate to protect USB thread from accessing shared objects (USBConnectedDevices and Interfaces)
194203
*/
@@ -287,6 +296,8 @@ class USBHost : public USBHALHost {
287296
// buffer for conf descriptor
288297
uint8_t data[415];
289298

299+
mbed::Callback<void(uint8_t uDeviceIndex)> device_connected_callback = nullptr;
300+
290301
/**
291302
* Add a transfer on the TD linked list associated to an ED
292303
*

0 commit comments

Comments
 (0)