diff options
Diffstat (limited to 'hid')
-rw-r--r-- | hid/.gitignore | 2 | ||||
-rw-r--r-- | hid/Makefile | 17 | ||||
-rw-r--r-- | hid/platformio.ini | 16 | ||||
-rw-r--r-- | hid/src/main.cpp | 38 |
4 files changed, 73 insertions, 0 deletions
diff --git a/hid/.gitignore b/hid/.gitignore new file mode 100644 index 00000000..c6d216a4 --- /dev/null +++ b/hid/.gitignore @@ -0,0 +1,2 @@ +/.pioenvs/ +/.piolibdeps/ diff --git a/hid/Makefile b/hid/Makefile new file mode 100644 index 00000000..ec8bb999 --- /dev/null +++ b/hid/Makefile @@ -0,0 +1,17 @@ +all: + @ cat Makefile + +build: + platformio run + +update: + platformio platform update + +upload: + platformio run --target upload + +serial: + platformio serialports monitor + +clean: + rm -rf .pioenvs .piolibdeps diff --git a/hid/platformio.ini b/hid/platformio.ini new file mode 100644 index 00000000..d56457fc --- /dev/null +++ b/hid/platformio.ini @@ -0,0 +1,16 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:micro] +platform = atmelavr +board = micro +framework = arduino +upload_port = /dev/ttyACM0 +monitor_baud = 115200 diff --git a/hid/src/main.cpp b/hid/src/main.cpp new file mode 100644 index 00000000..32c14c14 --- /dev/null +++ b/hid/src/main.cpp @@ -0,0 +1,38 @@ +#include <Arduino.h> +#include <Keyboard.h> + +#define CMD_SERIAL Serial1 +#define SERIAL_SPEED 115200 + +#define INLINE inline __attribute__((always_inline)) + + +INLINE void cmdResetHid() { + Keyboard.releaseAll(); +} + +INLINE void cmdKeyEvent() { + uint8_t state = Serial.read(); + uint8_t key = Serial.read(); + if (state) { + Keyboard.press(key); + } else { + Keyboard.release(key); + } +} + + +void setup() { + CMD_SERIAL.begin(SERIAL_SPEED); + Keyboard.begin(); +} + +void loop() { + while (true) { // fast + switch (Serial.read()) { + case 0: cmdResetHid(); break; + case 1: cmdKeyEvent(); break; + default: break; + } + } +} |