You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.1 KiB

  1. #include <cdc_XR21B1411.h>
  2. // Satisfy IDE, which only needs to see the include statment in the ino.
  3. #ifdef dobogusinclude
  4. #include <spi4teensy3.h>
  5. #include <SPI.h>
  6. #endif
  7. class ACMAsyncOper : public CDCAsyncOper
  8. {
  9. public:
  10. uint8_t OnInit(ACM *pacm);
  11. };
  12. uint8_t ACMAsyncOper::OnInit(ACM *pacm)
  13. {
  14. uint8_t rcode;
  15. // Set DTR = 1 RTS=1
  16. rcode = pacm->SetControlLineState(3);
  17. if (rcode)
  18. {
  19. ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
  20. return rcode;
  21. }
  22. LINE_CODING lc;
  23. lc.dwDTERate = 115200;
  24. lc.bCharFormat = 0;
  25. lc.bParityType = 0;
  26. lc.bDataBits = 8;
  27. rcode = pacm->SetLineCoding(&lc);
  28. if (rcode)
  29. ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
  30. return rcode;
  31. }
  32. USB Usb;
  33. ACMAsyncOper AsyncOper;
  34. XR21B1411 Acm(&Usb, &AsyncOper);
  35. void setup() {
  36. Serial.begin( 115200 );
  37. #if !defined(__MIPSEL__)
  38. while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  39. #endif
  40. Serial.println("\r\n\r\nStart");
  41. if (Usb.Init() == -1) Serial.println("OSCOKIRQ failed to assert");
  42. }
  43. void loop() {
  44. Usb.Task();
  45. if( Acm.isReady()) {
  46. uint8_t rcode;
  47. uint8_t buf[1];
  48. uint16_t rcvd = 1;
  49. /* read keyboard */
  50. if(Serial.available()) {
  51. uint8_t data = Serial.read();
  52. /* send */
  53. rcode = Acm.SndData(1, &data);
  54. if (rcode)
  55. ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
  56. }
  57. /* read XR serial */
  58. rcode = Acm.RcvData(&rcvd, buf);
  59. if (rcode && rcode != hrNAK)
  60. ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
  61. if( rcvd ) { //more than zero bytes received
  62. for(uint16_t i=0; i < rcvd; i++ ) {
  63. Serial.print((char)buf[i]);
  64. }
  65. }
  66. }
  67. }