From fad3038b035db90c59f297891835d37fd97b79c5 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Thu, 13 Jun 2019 18:00:42 -0400 Subject: Initial commit. --- samd/Makefile | 15 +++++++ samd/Makefile.feather-m4 | 12 ++++++ samd/Makefile.trinket-m0 | 10 +++++ samd/samd.ino | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 samd/Makefile create mode 100644 samd/Makefile.feather-m4 create mode 100644 samd/Makefile.trinket-m0 create mode 100644 samd/samd.ino (limited to 'samd') diff --git a/samd/Makefile b/samd/Makefile new file mode 100644 index 0000000..314396c --- /dev/null +++ b/samd/Makefile @@ -0,0 +1,15 @@ +include ../Makefile.common +include Makefile.feather-m4 +#include Makefile.trinket-m0 + +SERIALPORT = $(shell ../find-serial-port $(USBVID) $(USBPID) || echo cant-find-serial-port) + +APP = samd + +all: $(BUILDDIR)/$(APP).ino.bin + +flash: $(BUILDDIR)/$(APP).ino.bin $(SERIALPORT) + $(PKGDIR)/arduino/tools/bossac/1.8.0-48-gb176eee/bossac -R -e -w -v -o$(IMGOFFSET) -p$(SERIALPORT) $< + +console: + screen $(SERIALPORT) 115200 diff --git a/samd/Makefile.feather-m4 b/samd/Makefile.feather-m4 new file mode 100644 index 0000000..b8c15ec --- /dev/null +++ b/samd/Makefile.feather-m4 @@ -0,0 +1,12 @@ +# -*- mode: Makefile -*- + +VENDOR = adafruit +PLATFORM = samd +BOARD = adafruit_feather_m4 + +EXTRAPREFS = -prefs "build.f_cpu=120000000L" + +USBVID = 239a +USBPID = 0022 + +IMGOFFSET = 0x4000 diff --git a/samd/Makefile.trinket-m0 b/samd/Makefile.trinket-m0 new file mode 100644 index 0000000..1c37abb --- /dev/null +++ b/samd/Makefile.trinket-m0 @@ -0,0 +1,10 @@ +# -*- mode: Makefile -*- + +VENDOR = adafruit +PLATFORM = samd +BOARD = adafruit_trinket_m0 + +USBVID = 239a +USBPID = '001e|801e' + +IMGOFFSET = 0x2000 diff --git a/samd/samd.ino b/samd/samd.ino new file mode 100644 index 0000000..a09cb5e --- /dev/null +++ b/samd/samd.ino @@ -0,0 +1,109 @@ +// -*- mode: c++ -*- + +#include "i2c_message.h" + +#include +#include +#include + +#ifdef ADAFRUIT_TRINKET_M0 +#include + +const uint8_t NUMPIXELS = 1; +const uint8_t DATAPIN = 7; +const uint8_t CLOCKPIN = 8; + +Adafruit_DotStar px(NUMPIXELS, DATAPIN, CLOCKPIN); + + +void initTXLED() { +} + +void turnOffTXLED() { + px.clear(); + px.show(); +} + +void turnOnTXLED() { + px.setPixelColor(0, 63, 63, 0); + px.show(); +} +#else // ADAFRUIT_TRINKET_M0 +void initTXLED() { + pinMode(LED_BUILTIN, OUTPUT); +} + +void turnOffTXLED() { + digitalWrite(LED_BUILTIN, HIGH); +} + +void turnOnTXLED() { + digitalWrite(LED_BUILTIN, LOW); +} +#endif // ADAFRUIT_TRINKET_M0 + +void dbg(char *msg) { + uint8_t len = strlen(msg); + + Wire.beginTransmission(BTLE_WIREADDR); + Wire.write(DBG); + Wire.write(len); + Wire.write(msg); + Wire.endTransmission(); +} + +class KeyboardRaw: public KeyboardReportParser { +public: + void Parse(HID *hid, uint32_t is_rpt_id, uint32_t len, uint8_t *buf); +}; + +void KeyboardRaw::Parse(HID *hid, uint32_t is_rpt_id, uint32_t len, uint8_t *buf) { + turnOnTXLED(); + + KeyboardReportParser::Parse(hid, is_rpt_id, len, buf); + + Wire.beginTransmission(BTLE_WIREADDR); + Wire.write(KBD); + Wire.write(len); + Wire.write(buf, len); + Wire.endTransmission(); + + turnOffTXLED(); +} + +USBHost usb; +USBHub hub(&usb); +HIDBoot hidKeyBoard(&usb); +KeyboardRaw parser; + +void setup() { + initTXLED(); + turnOffTXLED(); + + Wire.begin(); + + dbg("Booting\r\n"); + + if (usb.Init()) { + dbg("USB Host did not start!\r\n"); + while (true) { + digitalWrite(LED_BUILTIN, HIGH); + delay(125); + digitalWrite(LED_BUILTIN, LOW); + delay(125); + digitalWrite(LED_BUILTIN, HIGH); + delay(125); + digitalWrite(LED_BUILTIN, LOW); + delay(125); + + delay(500); + } + } + + hidKeyBoard.SetReportParser(0, &parser); +} + +void loop() { + asm("wfe \n"); + usb.Task(); +} -- cgit v1.2.3