Hi all,
We are two Belgian students that are currently working on a project to establish USB communication between an Android device, which has to be the host, and a mbed LPC1768 and we have some trouble using the HID library.
Our setup:
We have a USB host device a Samsung Galaxy S2 and the mbed LPC1768 as client device (pin D- and D+).
What should happen:
We send some data from the android device to the mbed device where we do nothing with the data (to have as few variables as possible). So the connection should just continue until we reset the mbed.
What happens:
After sending some packets of data the android device detects that the device is detached and the mbed resets the bus.
The USB communication first slows down and then crashes completely. (A buffer that overflows maybe?). Communication packages seem to disappear.
This is our code, the rest is the HID library.
main.cpp
#include "AndroidConnection.h"
// read
AndroidConnection con;
int main(void) {
printf("Here\r\n");
con.setupConnection();
while(1){
con.readData();
// uint8_t dummy = 'c';
//con.write(&dummy,1);
}
}
AndroidConnection.cpp
#include "AndroidConnection.h"
BusOut leds(LED1, LED2, LED3, LED4);
void AndroidConnection::setupConnection()
{
printf("Waiting for connection\r\n");
connect();
connected();
}
void AndroidConnection::connected()
{
printf("Device Connected\r\n");
}
void AndroidConnection::disconnected()
{
printf("Device Disconnected\r\n");
setupConnection();
}
void AndroidConnection::write(uint8_t* data, uint32_t len)
{
send.length = len;
int index;
for(index = 0; index < len; index++) {
send.data[index] = data[index];
}
sendNB(&send);
printf("Wrote bytes\r\n");
}
void AndroidConnection::readData()
{
// if(configured()) {
if(read(&recv)) {
if (recv.length > 0) {
printf("Read bytes\r\n");
handlePacket();
}
}
/* } else {
disconnected();
}*/
}
void AndroidConnection::handlePacket()
{
leds = recv.data[0];
}
void AndroidConnection::USBCallback_busReset(void) {
printf("Bus Reset\r\n");
}
void AndroidConnection::USBCallback_requestCompleted(uint8_t * buf, uint32_t length) {
printf("Incoming Request with len %d\r\n",length);
}
AndroidConnection.h
#include "mbed.h"
#include "USBHID.h"
class AndroidConnection:public USBHID {
public:
AndroidConnection():USBHID(32,32,0x1234,0x0006,0x0001,false){
};
virtual void setupConnection();
virtual void connected();
virtual void disconnected();
virtual void write(uint8_t* buffer, uint32_t len);
virtual void readData();
virtual void handlePacket();
virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length);
virtual void USBCallback_busReset(void);
private:
HID_REPORT recv;
HID_REPORT send;
};
I hope I gave enough information.
Thank you for your time and effort.
Cheers
Thomas & Vincent
Hi all,
We are two Belgian students that are currently working on a project to establish USB communication between an Android device, which has to be the host, and a mbed LPC1768 and we have some trouble using the HID library.
Our setup: We have a USB host device a Samsung Galaxy S2 and the mbed LPC1768 as client device (pin D- and D+).
What should happen: We send some data from the android device to the mbed device where we do nothing with the data (to have as few variables as possible). So the connection should just continue until we reset the mbed.
What happens: After sending some packets of data the android device detects that the device is detached and the mbed resets the bus.
The USB communication first slows down and then crashes completely. (A buffer that overflows maybe?). Communication packages seem to disappear.
This is our code, the rest is the HID library.
main.cpp
AndroidConnection.cpp
AndroidConnection.h
I hope I gave enough information.
Thank you for your time and effort.
Cheers Thomas & Vincent