mirror of https://github.com/ARMmbed/mbed-os.git
USBHost : USBHostHID , USBHostHub fix indentation.
parent
bae762eb24
commit
fa2abd22c7
|
@ -19,71 +19,81 @@
|
||||||
#if USBHOST_KEYBOARD
|
#if USBHOST_KEYBOARD
|
||||||
|
|
||||||
static uint8_t keymap[4][0x39] = {
|
static uint8_t keymap[4][0x39] = {
|
||||||
{ 0, 0, 0, 0, 'a', 'b' /*0x05*/,
|
{
|
||||||
'c', 'd', 'e', 'f', 'g' /*0x0a*/,
|
0, 0, 0, 0, 'a', 'b' /*0x05*/,
|
||||||
'h', 'i', 'j', 'k', 'l'/*0x0f*/,
|
'c', 'd', 'e', 'f', 'g' /*0x0a*/,
|
||||||
'm', 'n', 'o', 'p', 'q'/*0x14*/,
|
'h', 'i', 'j', 'k', 'l'/*0x0f*/,
|
||||||
'r', 's', 't', 'u', 'v'/*0x19*/,
|
'm', 'n', 'o', 'p', 'q'/*0x14*/,
|
||||||
'w', 'x', 'y', 'z', '1'/*0x1E*/,
|
'r', 's', 't', 'u', 'v'/*0x19*/,
|
||||||
'2', '3', '4', '5', '6'/*0x23*/,
|
'w', 'x', 'y', 'z', '1'/*0x1E*/,
|
||||||
'7', '8', '9', '0', 0x0A /*enter*/, /*0x28*/
|
'2', '3', '4', '5', '6'/*0x23*/,
|
||||||
0x1B /*escape*/, 0x08 /*backspace*/, 0x09/*tab*/, 0x20/*space*/, '-', /*0x2d*/
|
'7', '8', '9', '0', 0x0A /*enter*/, /*0x28*/
|
||||||
'=', '[', ']', '\\', '#', /*0x32*/
|
0x1B /*escape*/, 0x08 /*backspace*/, 0x09/*tab*/, 0x20/*space*/, '-', /*0x2d*/
|
||||||
';', '\'', 0, ',', '.', /*0x37*/
|
'=', '[', ']', '\\', '#', /*0x32*/
|
||||||
'/'},
|
';', '\'', 0, ',', '.', /*0x37*/
|
||||||
|
'/'
|
||||||
|
},
|
||||||
|
|
||||||
/* CTRL MODIFIER */
|
/* CTRL MODIFIER */
|
||||||
{ 0, 0, 0, 0, 0, 0 /*0x05*/,
|
{
|
||||||
0, 0, 0, 0, 0 /*0x0a*/,
|
0, 0, 0, 0, 0, 0 /*0x05*/,
|
||||||
0, 0, 0, 0, 0/*0x0f*/,
|
0, 0, 0, 0, 0 /*0x0a*/,
|
||||||
0, 0, 0, 0, 0/*0x14*/,
|
0, 0, 0, 0, 0/*0x0f*/,
|
||||||
0, 0, 0, 0, 0/*0x19*/,
|
0, 0, 0, 0, 0/*0x14*/,
|
||||||
0, 0, 0, 0, 0/*0x1E*/,
|
0, 0, 0, 0, 0/*0x19*/,
|
||||||
0, 0, 0, 0, 0/*0x23*/,
|
0, 0, 0, 0, 0/*0x1E*/,
|
||||||
0, 0, 0, 0, 0 /*enter*/, /*0x28*/
|
0, 0, 0, 0, 0/*0x23*/,
|
||||||
0, 0, 0, 0, 0, /*0x2d*/
|
0, 0, 0, 0, 0 /*enter*/, /*0x28*/
|
||||||
0, 0, 0, 0, 0, /*0x32*/
|
0, 0, 0, 0, 0, /*0x2d*/
|
||||||
0, 0, 0, 0, 0, /*0x37*/
|
0, 0, 0, 0, 0, /*0x32*/
|
||||||
0},
|
0, 0, 0, 0, 0, /*0x37*/
|
||||||
|
0
|
||||||
|
},
|
||||||
|
|
||||||
/* SHIFT MODIFIER */
|
/* SHIFT MODIFIER */
|
||||||
{ 0, 0, 0, 0, 'A', 'B' /*0x05*/,
|
{
|
||||||
'C', 'D', 'E', 'F', 'G' /*0x0a*/,
|
0, 0, 0, 0, 'A', 'B' /*0x05*/,
|
||||||
'H', 'I', 'J', 'K', 'L'/*0x0f*/,
|
'C', 'D', 'E', 'F', 'G' /*0x0a*/,
|
||||||
'M', 'N', 'O', 'P', 'Q'/*0x14*/,
|
'H', 'I', 'J', 'K', 'L'/*0x0f*/,
|
||||||
'R', 'S', 'T', 'U', 'V'/*0x19*/,
|
'M', 'N', 'O', 'P', 'Q'/*0x14*/,
|
||||||
'W', 'X', 'Y', 'Z', '!'/*0x1E*/,
|
'R', 'S', 'T', 'U', 'V'/*0x19*/,
|
||||||
'@', '#', '$', '%', '^'/*0x23*/,
|
'W', 'X', 'Y', 'Z', '!'/*0x1E*/,
|
||||||
'&', '*', '(', ')', 0, /*0x28*/
|
'@', '#', '$', '%', '^'/*0x23*/,
|
||||||
0, 0, 0, 0, 0, /*0x2d*/
|
'&', '*', '(', ')', 0, /*0x28*/
|
||||||
'+', '{', '}', '|', '~', /*0x32*/
|
0, 0, 0, 0, 0, /*0x2d*/
|
||||||
':', '"', 0, '<', '>', /*0x37*/
|
'+', '{', '}', '|', '~', /*0x32*/
|
||||||
'?'},
|
':', '"', 0, '<', '>', /*0x37*/
|
||||||
|
'?'
|
||||||
|
},
|
||||||
|
|
||||||
/* ALT MODIFIER */
|
/* ALT MODIFIER */
|
||||||
{ 0, 0, 0, 0, 0, 0 /*0x05*/,
|
{
|
||||||
0, 0, 0, 0, 0 /*0x0a*/,
|
0, 0, 0, 0, 0, 0 /*0x05*/,
|
||||||
0, 0, 0, 0, 0/*0x0f*/,
|
0, 0, 0, 0, 0 /*0x0a*/,
|
||||||
0, 0, 0, 0, 0/*0x14*/,
|
0, 0, 0, 0, 0/*0x0f*/,
|
||||||
0, 0, 0, 0, 0/*0x19*/,
|
0, 0, 0, 0, 0/*0x14*/,
|
||||||
0, 0, 0, 0, 0/*0x1E*/,
|
0, 0, 0, 0, 0/*0x19*/,
|
||||||
0, 0, 0, 0, 0/*0x23*/,
|
0, 0, 0, 0, 0/*0x1E*/,
|
||||||
0, 0, 0, 0, 0 /*enter*/, /*0x28*/
|
0, 0, 0, 0, 0/*0x23*/,
|
||||||
0, 0, 0, 0, 0, /*0x2d*/
|
0, 0, 0, 0, 0 /*enter*/, /*0x28*/
|
||||||
0, 0, 0, 0, 0, /*0x32*/
|
0, 0, 0, 0, 0, /*0x2d*/
|
||||||
0, 0, 0, 0, 0, /*0x37*/
|
0, 0, 0, 0, 0, /*0x32*/
|
||||||
0}
|
0, 0, 0, 0, 0, /*0x37*/
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
USBHostKeyboard::USBHostKeyboard() {
|
USBHostKeyboard::USBHostKeyboard()
|
||||||
|
{
|
||||||
host = USBHost::getHostInst();
|
host = USBHost::getHostInst();
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void USBHostKeyboard::init() {
|
void USBHostKeyboard::init()
|
||||||
|
{
|
||||||
dev = NULL;
|
dev = NULL;
|
||||||
int_in = NULL;
|
int_in = NULL;
|
||||||
report_id = 0;
|
report_id = 0;
|
||||||
|
@ -94,7 +104,8 @@ void USBHostKeyboard::init() {
|
||||||
keyboard_device_found = false;
|
keyboard_device_found = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool USBHostKeyboard::connected() {
|
bool USBHostKeyboard::connected()
|
||||||
|
{
|
||||||
return dev_connected;
|
return dev_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,8 +120,9 @@ bool USBHostKeyboard::connect()
|
||||||
for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
|
for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
|
||||||
if ((dev = host->getDevice(i)) != NULL) {
|
if ((dev = host->getDevice(i)) != NULL) {
|
||||||
|
|
||||||
if (host->enumerate(dev, this))
|
if (host->enumerate(dev, this)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (keyboard_device_found) {
|
if (keyboard_device_found) {
|
||||||
{
|
{
|
||||||
|
@ -121,8 +133,9 @@ bool USBHostKeyboard::connect()
|
||||||
|
|
||||||
int_in = dev->getEndpoint(keyboard_intf, INTERRUPT_ENDPOINT, IN);
|
int_in = dev->getEndpoint(keyboard_intf, INTERRUPT_ENDPOINT, IN);
|
||||||
|
|
||||||
if (!int_in)
|
if (!int_in) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
USB_INFO("New Keyboard device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, keyboard_intf);
|
USB_INFO("New Keyboard device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, keyboard_intf);
|
||||||
dev->setName("Keyboard", keyboard_intf);
|
dev->setName("Keyboard", keyboard_intf);
|
||||||
|
@ -141,7 +154,8 @@ bool USBHostKeyboard::connect()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostKeyboard::rxHandler() {
|
void USBHostKeyboard::rxHandler()
|
||||||
|
{
|
||||||
int len = int_in->getLengthTransferred();
|
int len = int_in->getLengthTransferred();
|
||||||
int index = (len == 9) ? 1 : 0;
|
int index = (len == 9) ? 1 : 0;
|
||||||
int len_listen = int_in->getSize();
|
int len_listen = int_in->getSize();
|
||||||
|
@ -157,8 +171,9 @@ void USBHostKeyboard::rxHandler() {
|
||||||
(*onKeyCode)(report[index + 2], modifier);
|
(*onKeyCode)(report[index + 2], modifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dev && int_in)
|
if (dev && int_in) {
|
||||||
host->interruptRead(dev, int_in, report, len_listen, false);
|
host->interruptRead(dev, int_in, report, len_listen, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/ void USBHostKeyboard::setVidPid(uint16_t vid, uint16_t pid)
|
/*virtual*/ void USBHostKeyboard::setVidPid(uint16_t vid, uint16_t pid)
|
||||||
|
@ -169,9 +184,9 @@ void USBHostKeyboard::rxHandler() {
|
||||||
/*virtual*/ bool USBHostKeyboard::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
|
/*virtual*/ bool USBHostKeyboard::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
|
||||||
{
|
{
|
||||||
if ((keyboard_intf == -1) &&
|
if ((keyboard_intf == -1) &&
|
||||||
(intf_class == HID_CLASS) &&
|
(intf_class == HID_CLASS) &&
|
||||||
(intf_subclass == 0x01) &&
|
(intf_subclass == 0x01) &&
|
||||||
(intf_protocol == 0x01)) {
|
(intf_protocol == 0x01)) {
|
||||||
keyboard_intf = intf_nb;
|
keyboard_intf = intf_nb;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
/**
|
/**
|
||||||
* A class to communicate a USB keyboard
|
* A class to communicate a USB keyboard
|
||||||
*/
|
*/
|
||||||
class USBHostKeyboard : public IUSBEnumerator {
|
class USBHostKeyboard : public IUSBEnumerator
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +54,8 @@ public:
|
||||||
*
|
*
|
||||||
* @param ptr function pointer
|
* @param ptr function pointer
|
||||||
*/
|
*/
|
||||||
inline void attach(void (*ptr)(uint8_t key)) {
|
inline void attach(void (*ptr)(uint8_t key))
|
||||||
|
{
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
onKey = ptr;
|
onKey = ptr;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +66,8 @@ public:
|
||||||
*
|
*
|
||||||
* @param ptr function pointer
|
* @param ptr function pointer
|
||||||
*/
|
*/
|
||||||
inline void attach(void (*ptr)(uint8_t keyCode, uint8_t modifier)) {
|
inline void attach(void (*ptr)(uint8_t keyCode, uint8_t modifier))
|
||||||
|
{
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
onKeyCode = ptr;
|
onKeyCode = ptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,14 @@
|
||||||
|
|
||||||
#if USBHOST_MOUSE
|
#if USBHOST_MOUSE
|
||||||
|
|
||||||
USBHostMouse::USBHostMouse() {
|
USBHostMouse::USBHostMouse()
|
||||||
|
{
|
||||||
host = USBHost::getHostInst();
|
host = USBHost::getHostInst();
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostMouse::init() {
|
void USBHostMouse::init()
|
||||||
|
{
|
||||||
dev = NULL;
|
dev = NULL;
|
||||||
int_in = NULL;
|
int_in = NULL;
|
||||||
onUpdate = NULL;
|
onUpdate = NULL;
|
||||||
|
@ -42,7 +44,8 @@ void USBHostMouse::init() {
|
||||||
z = 0;
|
z = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool USBHostMouse::connected() {
|
bool USBHostMouse::connected()
|
||||||
|
{
|
||||||
return dev_connected;
|
return dev_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +60,9 @@ bool USBHostMouse::connect()
|
||||||
for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
|
for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
|
||||||
if ((dev = host->getDevice(i)) != NULL) {
|
if ((dev = host->getDevice(i)) != NULL) {
|
||||||
|
|
||||||
if(host->enumerate(dev, this))
|
if(host->enumerate(dev, this)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
if (mouse_device_found) {
|
if (mouse_device_found) {
|
||||||
{
|
{
|
||||||
/* As this is done in a specific thread
|
/* As this is done in a specific thread
|
||||||
|
@ -66,8 +70,9 @@ bool USBHostMouse::connect()
|
||||||
* disconnect in usb process during the device registering */
|
* disconnect in usb process during the device registering */
|
||||||
USBHost::Lock Lock(host);
|
USBHost::Lock Lock(host);
|
||||||
int_in = dev->getEndpoint(mouse_intf, INTERRUPT_ENDPOINT, IN);
|
int_in = dev->getEndpoint(mouse_intf, INTERRUPT_ENDPOINT, IN);
|
||||||
if (!int_in)
|
if (!int_in) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
USB_INFO("New Mouse device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, mouse_intf);
|
USB_INFO("New Mouse device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, mouse_intf);
|
||||||
dev->setName("Mouse", mouse_intf);
|
dev->setName("Mouse", mouse_intf);
|
||||||
|
@ -81,10 +86,12 @@ bool USBHostMouse::connect()
|
||||||
}
|
}
|
||||||
int ret=host->interruptRead(dev, int_in, report, len_listen, false);
|
int ret=host->interruptRead(dev, int_in, report, len_listen, false);
|
||||||
MBED_ASSERT((ret==USB_TYPE_OK) || (ret ==USB_TYPE_PROCESSING) || (ret == USB_TYPE_FREE));
|
MBED_ASSERT((ret==USB_TYPE_OK) || (ret ==USB_TYPE_PROCESSING) || (ret == USB_TYPE_FREE));
|
||||||
if ((ret==USB_TYPE_OK) || (ret ==USB_TYPE_PROCESSING))
|
if ((ret==USB_TYPE_OK) || (ret ==USB_TYPE_PROCESSING)) {
|
||||||
dev_connected = true;
|
dev_connected = true;
|
||||||
if (ret == USB_TYPE_FREE)
|
}
|
||||||
|
if (ret == USB_TYPE_FREE) {
|
||||||
dev_connected = false;
|
dev_connected = false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +100,8 @@ bool USBHostMouse::connect()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostMouse::rxHandler() {
|
void USBHostMouse::rxHandler()
|
||||||
|
{
|
||||||
int len_listen = int_in->getSize();
|
int len_listen = int_in->getSize();
|
||||||
|
|
||||||
if (onUpdate) {
|
if (onUpdate) {
|
||||||
|
@ -126,8 +134,9 @@ void USBHostMouse::rxHandler() {
|
||||||
len_listen = sizeof(report);
|
len_listen = sizeof(report);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev)
|
if (dev) {
|
||||||
host->interruptRead(dev, int_in, report, len_listen, false);
|
host->interruptRead(dev, int_in, report, len_listen, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/ void USBHostMouse::setVidPid(uint16_t vid, uint16_t pid)
|
/*virtual*/ void USBHostMouse::setVidPid(uint16_t vid, uint16_t pid)
|
||||||
|
@ -138,9 +147,9 @@ void USBHostMouse::rxHandler() {
|
||||||
/*virtual*/ bool USBHostMouse::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
|
/*virtual*/ bool USBHostMouse::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
|
||||||
{
|
{
|
||||||
if ((mouse_intf == -1) &&
|
if ((mouse_intf == -1) &&
|
||||||
(intf_class == HID_CLASS) &&
|
(intf_class == HID_CLASS) &&
|
||||||
(intf_subclass == 0x01) &&
|
(intf_subclass == 0x01) &&
|
||||||
(intf_protocol == 0x02)) {
|
(intf_protocol == 0x02)) {
|
||||||
mouse_intf = intf_nb;
|
mouse_intf = intf_nb;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
/**
|
/**
|
||||||
* A class to communicate a USB mouse
|
* A class to communicate a USB mouse
|
||||||
*/
|
*/
|
||||||
class USBHostMouse : public IUSBEnumerator {
|
class USBHostMouse : public IUSBEnumerator
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +54,8 @@ public:
|
||||||
*
|
*
|
||||||
* @param ptr function pointer
|
* @param ptr function pointer
|
||||||
*/
|
*/
|
||||||
inline void attachEvent(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z)) {
|
inline void attachEvent(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z))
|
||||||
|
{
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
onUpdate = ptr;
|
onUpdate = ptr;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +66,8 @@ public:
|
||||||
*
|
*
|
||||||
* @param ptr function pointer
|
* @param ptr function pointer
|
||||||
*/
|
*/
|
||||||
inline void attachButtonEvent(void (*ptr)(uint8_t buttons)) {
|
inline void attachButtonEvent(void (*ptr)(uint8_t buttons))
|
||||||
|
{
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
onButtonUpdate = ptr;
|
onButtonUpdate = ptr;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +78,8 @@ public:
|
||||||
*
|
*
|
||||||
* @param ptr function pointer
|
* @param ptr function pointer
|
||||||
*/
|
*/
|
||||||
inline void attachXEvent(void (*ptr)(int8_t x)) {
|
inline void attachXEvent(void (*ptr)(int8_t x))
|
||||||
|
{
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
onXUpdate = ptr;
|
onXUpdate = ptr;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +90,8 @@ public:
|
||||||
*
|
*
|
||||||
* @param ptr function pointer
|
* @param ptr function pointer
|
||||||
*/
|
*/
|
||||||
inline void attachYEvent(void (*ptr)(int8_t y)) {
|
inline void attachYEvent(void (*ptr)(int8_t y))
|
||||||
|
{
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
onYUpdate = ptr;
|
onYUpdate = ptr;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +102,8 @@ public:
|
||||||
*
|
*
|
||||||
* @param ptr function pointer
|
* @param ptr function pointer
|
||||||
*/
|
*/
|
||||||
inline void attachZEvent(void (*ptr)(int8_t z)) {
|
inline void attachZEvent(void (*ptr)(int8_t z))
|
||||||
|
{
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
onZUpdate = ptr;
|
onZUpdate = ptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,14 @@
|
||||||
#define C_PORT_OVER_CURRENT (1 << 19)
|
#define C_PORT_OVER_CURRENT (1 << 19)
|
||||||
#define C_PORT_RESET (1 << 20)
|
#define C_PORT_RESET (1 << 20)
|
||||||
|
|
||||||
USBHostHub::USBHostHub() {
|
USBHostHub::USBHostHub()
|
||||||
|
{
|
||||||
host = NULL;
|
host = NULL;
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostHub::init() {
|
void USBHostHub::init()
|
||||||
|
{
|
||||||
dev_connected = false;
|
dev_connected = false;
|
||||||
dev = NULL;
|
dev = NULL;
|
||||||
int_in = NULL;
|
int_in = NULL;
|
||||||
|
@ -70,7 +72,8 @@ void USBHostHub::init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostHub::setHost(USBHost * host_) {
|
void USBHostHub::setHost(USBHost * host_)
|
||||||
|
{
|
||||||
host = host_;
|
host = host_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +132,8 @@ bool USBHostHub::connect(USBDeviceConnected * dev)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostHub::disconnect() {
|
void USBHostHub::disconnect()
|
||||||
|
{
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,9 +145,9 @@ void USBHostHub::disconnect() {
|
||||||
/*virtual*/ bool USBHostHub::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
|
/*virtual*/ bool USBHostHub::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
|
||||||
{
|
{
|
||||||
if ((hub_intf == -1) &&
|
if ((hub_intf == -1) &&
|
||||||
(intf_class == HUB_CLASS) &&
|
(intf_class == HUB_CLASS) &&
|
||||||
(intf_subclass == 0) &&
|
(intf_subclass == 0) &&
|
||||||
(intf_protocol == 0)) {
|
(intf_protocol == 0)) {
|
||||||
hub_intf = intf_nb;
|
hub_intf = intf_nb;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -161,15 +165,18 @@ void USBHostHub::disconnect() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostHub::deviceConnected(USBDeviceConnected * dev) {
|
void USBHostHub::deviceConnected(USBDeviceConnected * dev)
|
||||||
|
{
|
||||||
device_children[dev->getPort() - 1] = dev;
|
device_children[dev->getPort() - 1] = dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostHub::deviceDisconnected(USBDeviceConnected * dev) {
|
void USBHostHub::deviceDisconnected(USBDeviceConnected * dev)
|
||||||
|
{
|
||||||
device_children[dev->getPort() - 1] = NULL;
|
device_children[dev->getPort() - 1] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostHub::hubDisconnected() {
|
void USBHostHub::hubDisconnected()
|
||||||
|
{
|
||||||
for (uint8_t i = 0; i < MAX_HUB_PORT; i++) {
|
for (uint8_t i = 0; i < MAX_HUB_PORT; i++) {
|
||||||
if (device_children[i] != NULL) {
|
if (device_children[i] != NULL) {
|
||||||
host->freeDevice(device_children[i]);
|
host->freeDevice(device_children[i]);
|
||||||
|
@ -177,7 +184,8 @@ void USBHostHub::hubDisconnected() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostHub::rxHandler() {
|
void USBHostHub::rxHandler()
|
||||||
|
{
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
if (int_in) {
|
if (int_in) {
|
||||||
if (int_in->getState() == USB_TYPE_IDLE) {
|
if (int_in->getState() == USB_TYPE_IDLE) {
|
||||||
|
@ -217,7 +225,8 @@ void USBHostHub::rxHandler() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostHub::portReset(uint8_t port) {
|
void USBHostHub::portReset(uint8_t port)
|
||||||
|
{
|
||||||
// reset port
|
// reset port
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
USB_DBG("reset port %d on hub: %p [this: %p]", port, dev, this)
|
USB_DBG("reset port %d on hub: %p [this: %p]", port, dev, this)
|
||||||
|
@ -228,10 +237,12 @@ void USBHostHub::portReset(uint8_t port) {
|
||||||
while(1) {
|
while(1) {
|
||||||
status = getPortStatus(port);
|
status = getPortStatus(port);
|
||||||
/* disconnection since reset request */
|
/* disconnection since reset request */
|
||||||
if (!(status & PORT_CONNECTION))
|
if (!(status & PORT_CONNECTION)) {
|
||||||
break;
|
break;
|
||||||
if (status & (PORT_ENABLE | PORT_RESET))
|
}
|
||||||
|
if (status & (PORT_ENABLE | PORT_RESET)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
if (status & PORT_OVER_CURRENT) {
|
if (status & PORT_OVER_CURRENT) {
|
||||||
USB_ERR("OVER CURRENT DETECTED\r\n");
|
USB_ERR("OVER CURRENT DETECTED\r\n");
|
||||||
clearPortFeature(PORT_OVER_CURRENT, port);
|
clearPortFeature(PORT_OVER_CURRENT, port);
|
||||||
|
@ -242,7 +253,8 @@ void USBHostHub::portReset(uint8_t port) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostHub::setPortFeature(uint32_t feature, uint8_t port) {
|
void USBHostHub::setPortFeature(uint32_t feature, uint8_t port)
|
||||||
|
{
|
||||||
host->controlWrite( dev,
|
host->controlWrite( dev,
|
||||||
USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
|
USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
|
||||||
SET_FEATURE,
|
SET_FEATURE,
|
||||||
|
@ -252,7 +264,8 @@ void USBHostHub::setPortFeature(uint32_t feature, uint8_t port) {
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void USBHostHub::clearPortFeature(uint32_t feature, uint8_t port) {
|
void USBHostHub::clearPortFeature(uint32_t feature, uint8_t port)
|
||||||
|
{
|
||||||
host->controlWrite( dev,
|
host->controlWrite( dev,
|
||||||
USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
|
USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
|
||||||
CLEAR_FEATURE,
|
CLEAR_FEATURE,
|
||||||
|
@ -262,7 +275,8 @@ void USBHostHub::clearPortFeature(uint32_t feature, uint8_t port) {
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t USBHostHub::getPortStatus(uint8_t port) {
|
uint32_t USBHostHub::getPortStatus(uint8_t port)
|
||||||
|
{
|
||||||
uint32_t st;
|
uint32_t st;
|
||||||
host->controlRead( dev,
|
host->controlRead( dev,
|
||||||
USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
|
USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
|
||||||
|
|
|
@ -31,7 +31,8 @@ class USBEndpoint;
|
||||||
/**
|
/**
|
||||||
* A class to use a USB Hub
|
* A class to use a USB Hub
|
||||||
*/
|
*/
|
||||||
class USBHostHub : public IUSBEnumerator {
|
class USBHostHub : public IUSBEnumerator
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
|
Loading…
Reference in New Issue