2011-06-22 19:41:22 +02:00
|
|
|
#include <cdcacm.h>
|
2013-10-02 00:49:46 +02:00
|
|
|
#include <usbhub.h>
|
2011-06-22 19:41:22 +02:00
|
|
|
|
2013-12-05 03:56:06 +01:00
|
|
|
#include "pgmstrings.h"
|
|
|
|
|
|
|
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
|
|
|
#ifdef dobogusinclude
|
|
|
|
#include <spi4teensy3.h>
|
|
|
|
#endif
|
2011-06-22 19:41:22 +02:00
|
|
|
|
|
|
|
class ACMAsyncOper : public CDCAsyncOper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual uint8_t OnInit(ACM *pacm);
|
|
|
|
};
|
|
|
|
|
|
|
|
uint8_t ACMAsyncOper::OnInit(ACM *pacm)
|
|
|
|
{
|
|
|
|
uint8_t rcode;
|
|
|
|
// Set DTR = 1 RTS=1
|
|
|
|
rcode = pacm->SetControlLineState(3);
|
|
|
|
|
|
|
|
if (rcode)
|
|
|
|
{
|
|
|
|
ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
|
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
LINE_CODING lc;
|
2013-12-05 03:56:06 +01:00
|
|
|
lc.dwDTERate = 115200;
|
2011-06-22 19:41:22 +02:00
|
|
|
lc.bCharFormat = 0;
|
|
|
|
lc.bParityType = 0;
|
2013-12-05 03:56:06 +01:00
|
|
|
lc.bDataBits = 8;
|
|
|
|
|
2011-06-22 19:41:22 +02:00
|
|
|
rcode = pacm->SetLineCoding(&lc);
|
|
|
|
|
|
|
|
if (rcode)
|
|
|
|
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
|
2013-12-05 03:56:06 +01:00
|
|
|
|
2011-06-22 19:41:22 +02:00
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
USB Usb;
|
|
|
|
//USBHub Hub(&Usb);
|
|
|
|
ACMAsyncOper AsyncOper;
|
|
|
|
ACM Acm(&Usb, &AsyncOper);
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin( 115200 );
|
2013-10-21 19:58:03 +02:00
|
|
|
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
2011-06-22 19:41:22 +02:00
|
|
|
Serial.println("Start");
|
|
|
|
|
|
|
|
if (Usb.Init() == -1)
|
|
|
|
Serial.println("OSCOKIRQ failed to assert");
|
2013-12-05 03:56:06 +01:00
|
|
|
|
|
|
|
delay( 200 );
|
2011-06-22 19:41:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
Usb.Task();
|
2013-12-05 03:56:06 +01:00
|
|
|
|
|
|
|
if( Acm.isReady()) {
|
2011-06-22 19:41:22 +02:00
|
|
|
uint8_t rcode;
|
2013-12-05 03:56:06 +01:00
|
|
|
|
2011-06-22 19:41:22 +02:00
|
|
|
/* reading the keyboard */
|
|
|
|
if(Serial.available()) {
|
|
|
|
uint8_t data= Serial.read();
|
|
|
|
/* sending to the phone */
|
|
|
|
rcode = Acm.SndData(1, &data);
|
|
|
|
if (rcode)
|
|
|
|
ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
|
|
|
|
}//if(Serial.available()...
|
|
|
|
|
|
|
|
delay(50);
|
2013-12-05 03:56:06 +01:00
|
|
|
|
2011-06-22 19:41:22 +02:00
|
|
|
/* reading the phone */
|
2011-06-24 19:49:19 +02:00
|
|
|
/* buffer size must be greater or equal to max.packet size */
|
|
|
|
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
|
|
|
|
for particular endpoint */
|
2013-12-05 03:56:06 +01:00
|
|
|
uint8_t buf[64];
|
2011-06-24 19:49:19 +02:00
|
|
|
uint16_t rcvd = 64;
|
2011-06-22 19:41:22 +02:00
|
|
|
rcode = Acm.RcvData(&rcvd, buf);
|
|
|
|
if (rcode && rcode != hrNAK)
|
|
|
|
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
|
2013-12-05 03:56:06 +01:00
|
|
|
|
2011-06-22 19:41:22 +02:00
|
|
|
if( rcvd ) { //more than zero bytes received
|
|
|
|
for(uint16_t i=0; i < rcvd; i++ ) {
|
2012-01-10 20:49:42 +01:00
|
|
|
Serial.print((char)buf[i]); //printing on the screen
|
2013-12-05 03:56:06 +01:00
|
|
|
}
|
2011-06-22 19:41:22 +02:00
|
|
|
}
|
2013-12-05 03:56:06 +01:00
|
|
|
delay(10);
|
|
|
|
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
|
2011-06-22 19:41:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|