Compare commits

3 Commits
v1.0 ... main

Author SHA1 Message Date
ea98f6e605 interrupts are disabled on reset 2021-05-17 17:55:44 +02:00
9b64822db7 cleaner code 2021-05-15 20:59:58 +02:00
474773f155 working software 2021-05-15 00:57:30 +02:00

70
software/software.ino Normal file
View File

@@ -0,0 +1,70 @@
#include "Keyboard.h"
#include "HID.h"
#if F_CPU == 16000000
#error should be running at 8MHz
#endif
#define PIN A0
void goto_bootloader() {
cli();
UDCON |= (1<<DETACH);
USBCON |= (1<<USBE);
TIMSK0 = 0;
MCUCR |= (1<<IVCE);
MCUCR |= (1<<IVSEL);
asm("jmp 0x7000");
}
void check_blcmd() {
if (Serial.available()) {
String in = Serial.readStringUntil("\n");
if (in.equals("bootloader\n")) {
goto_bootloader();
}
}
}
void toggle() {}
void turned_on() {
Keyboard.press(KEY_F15);
Keyboard.releaseAll();
}
void turned_off() {
Keyboard.press(KEY_F14);
Keyboard.releaseAll();
}
void setup() {
pinMode(PIN, INPUT_PULLUP);
Keyboard.begin();
Serial.begin(9600);
Serial.setTimeout(50);
}
void loop() {
static bool last_state = 0;
bool current_state = digitalRead(PIN);
if (last_state != current_state) {
toggle();
if (current_state)
turned_on();
else
turned_off();
last_state = current_state;
}
check_blcmd();
delay(100);
}