diff --git a/.gitignore b/.gitignore index 62e0404..e02c006 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,10 @@ *.sch-bak -*.kicad_pcb-bak \ No newline at end of file +*.kicad_pcb-bak + +*.o +*.d + +software/arduino/.cproject +software/arduino/.project +software/arduino/.settings/ +.vscode/ diff --git a/.gitmodules b/.gitmodules index 0c8c60b..c87a293 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,6 @@ [submodule "hardware/lib/biacco42_promicro"] path = hardware/lib/biacco42_promicro url = https://github.com/Biacco42/ProMicroKiCad.git +[submodule "software/arduino/sim/matgui"] + path = software/arduino/sim/matgui + url = https://github.com/mls-m5/matgui diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e0d31f0 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ + +all: + make -C software/arduino/keyboard \ No newline at end of file diff --git a/software/arduino/keyboard/Makefile b/software/arduino/keyboard/Makefile index 9691cd9..caa3efb 100644 --- a/software/arduino/keyboard/Makefile +++ b/software/arduino/keyboard/Makefile @@ -2,7 +2,7 @@ all: verify verify: - ~/Prog/Program/arduino-1.8.9/arduino --verify keyboard.ino | sed "s/stepper:/stepper.ino:/g" + ~/Prog/Program/arduino-1.8.9/arduino --verify keyboard.ino -v | sed "s/stepper:/stepper.ino:/g" upload: ~/Prog/Program/arduino-1.8.9/arduino --upload keyboard.ino | sed "s/stepper:/stepper.ino:/g" diff --git a/software/arduino/keyboard/io.h b/software/arduino/keyboard/io.h new file mode 100644 index 0000000..8099785 --- /dev/null +++ b/software/arduino/keyboard/io.h @@ -0,0 +1,65 @@ +/* + * io.h + * + * Created on: 3 mars 2020 + * Author: Mattias Larsson Sköld + */ + +#pragma once + +#include "keyboardmap.h" +#include "keyboardstate.h" +#include "pins.h" + +// Standad layer +const char *keyConfig1 = "§12345" + "\tQWERT" + "\177ASDFG" + "\129 keyboard_state_t; +keyboard_state_t state; + +KeyboardMap keyboardMap(width, height, keyConfig1); + + + +void setup() { + for (auto pin : xPins) { + pinMode(pin, OUTPUT); + } +} + +//! Turn on one column pin and turn of the rest +void changeColumnPin(size_t column) { + for (size_t i = 0; i < width; ++i) { + digitalWrite(xPins[i], i == column); + } +} + +void readRowPins(keyboard_state_t &keyboardState, size_t x) { + for (size_t y = 0; y < height; ++y) { + int value = digitalRead(yPins[y]); + auto &keyState = keyboardState.state(x, y); + + if (keyState != value) { + Serial.print("readRowPins: key is changed "); + Serial.print(x); + Serial.print(y); + keyboardMap.publishEvent(x, y, keyState); + keyState = value; + } + } +} + +void loop() { + // Cycle through columns + for (size_t x = 0; x < width; ++x) { + changeColumnPin(x); + + readRowPins(state, x); + } +} + + diff --git a/software/arduino/keyboard/keyboard.ino b/software/arduino/keyboard/keyboard.ino index a9cfe27..493c7d6 100644 --- a/software/arduino/keyboard/keyboard.ino +++ b/software/arduino/keyboard/keyboard.ino @@ -1,27 +1,6 @@ -#include "keyboardmap.h" -#include "keyboardstate.h" -#include -namespace { -const char *keyConfig1 = "§12345" - "\tQWERT" - "\177ASDFG" - "\129 xPins = {}; -const std::array yPins = {}; - -typedef KeyboardState keyboard_state_t; -keyboard_state_t state; - -KeyboardMap keyboardMap(width, height, keyConfig1); - -} // namespace +#include "io.h" void writeKeyRelease(char key) { // Implement this @@ -29,39 +8,4 @@ void writeKeyRelease(char key) { void writeKeyPress(char key) { // Implement this -} - -void setup() { - for (auto pin : xPins) { - pinMode(pin, OUTPUT); - } -} - -//! Turn on one column pin and turn of the rest -void changeColumnPin(size_t column) { - for (size_t i = 0; i < xPins.size(); ++i) { - digitalWrite(xPins[i], i == column); - } -} - -void readRowPins(keyboard_state_t &keyboardState, size_t x) { - for (size_t y = 0; y < yPins.size(); ++y) { - int value = digitalRead(yPins[y]); - auto &keyState = keyboardState.state(x, y); - - if (keyState != value) { - keyboardMap.publishEvent(x, y, keyState); - Serial.print("key is changed"); - keyState = value; - } - } -} - -void loop() { - // Cycle through columns - for (size_t x = 0; x < width; ++x) { - changeColumnPin(x); - - readRowPins(state, x); - } -} +} \ No newline at end of file diff --git a/software/arduino/keyboard/keyboardstate.h b/software/arduino/keyboard/keyboardstate.h index b20b373..e05c749 100644 --- a/software/arduino/keyboard/keyboardstate.h +++ b/software/arduino/keyboard/keyboardstate.h @@ -1,10 +1,8 @@ #pragma once -#include - template class KeyboardState { - std::array _state = {}; + char _state[width * height] = {}; public: typedef char state_t; diff --git a/software/arduino/keyboard/pins.h b/software/arduino/keyboard/pins.h new file mode 100644 index 0000000..b5995c4 --- /dev/null +++ b/software/arduino/keyboard/pins.h @@ -0,0 +1,17 @@ +/* + * pins.h + * + * Created on: 3 mars 2020 + * Author: Mattias Larsson Sköld + */ + +#pragma once + +constexpr size_t width = 6; +constexpr size_t height = 5; + +const char xPins[width] = {1, 2, 3, 4, 5, 6}; +const char yPins[height] = {8, 9, 10, 11, 12}; + + + diff --git a/software/arduino/sim/Matmakefile b/software/arduino/sim/Matmakefile new file mode 100644 index 0000000..9a0925e --- /dev/null +++ b/software/arduino/sim/Matmakefile @@ -0,0 +1,18 @@ +# using matmake +# https://github.com/mls-m5/matmake + +config += + debug + c++14 + +includes += + ../keyboard + +sysincludes += + matgui/include + +sim.src = *.cpp + +sim.src += matgui/src/*.cpp + +sim.libs += -lGL -lSDL2 -lSDL2_image \ No newline at end of file diff --git a/software/arduino/sim/keyboard.cpp b/software/arduino/sim/keyboard.cpp new file mode 100644 index 0000000..55fe9ee --- /dev/null +++ b/software/arduino/sim/keyboard.cpp @@ -0,0 +1,19 @@ +/* + * keyboard.cpp + * + * Created on: 3 mars 2020 + * Author: Mattias Larsson Sköld + */ + +#include +using namespace std; + +void writeKeyRelease(char key) { + cout << "Key released " << key << endl; +} + +void writeKeyPress(char key) { + cout << "keyboard.cpp: key pressed " << key << ", " << static_cast(key) << endl; +} + + diff --git a/software/arduino/sim/main.cpp b/software/arduino/sim/main.cpp new file mode 100644 index 0000000..e45a179 --- /dev/null +++ b/software/arduino/sim/main.cpp @@ -0,0 +1,59 @@ +/* + * main.cpp + * + * Created on: 3 mars 2020 + * Author: Mattias Larsson Sköld + */ + +#include "keys.h" + +#include "matgui/application.h" +#include "matgui/window.h" +#include "matgui/button.h" + +// Simulator +#include "simio.h" +#include "keyboardwritefunctions.h" + +// The code +#include "io.h" + +#include + +using namespace std; +using namespace MatGui; + +int main(int argc, char **argv) { + Application app(argc, argv); + + Window window("keyboard simulator"); + + setup(); + + for (size_t y = 0; y < height; ++y) { + auto layout = make_unique(); + layout->orientation(LayoutOrientation::LAYOUT_HORIZONTAL); + for (size_t x = 0; x < width; ++x) { + auto button = make_unique