|
|
@ -15,19 +15,11 @@
|
|
|
|
#include "KeyboardioFirmware.h"
|
|
|
|
#include "KeyboardioFirmware.h"
|
|
|
|
#include <EEPROM.h> // Don't need this for CLI compilation, but do need it in the IDE
|
|
|
|
#include <EEPROM.h> // Don't need this for CLI compilation, but do need it in the IDE
|
|
|
|
#include <Wire.h>
|
|
|
|
#include <Wire.h>
|
|
|
|
#include "KeyboardioSX1509.h"
|
|
|
|
|
|
|
|
#include "HID-Project.h"
|
|
|
|
#include "HID-Project.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const byte LEFT_SX1509_ADDRESS = 0x70; // SX1509 I2C address (10)
|
|
|
|
|
|
|
|
const byte RIGHT_SX1509_ADDRESS = 0x71; // SX1509 I2C address (11)
|
|
|
|
|
|
|
|
sx1509Class leftsx1509(LEFT_SX1509_ADDRESS);
|
|
|
|
|
|
|
|
sx1509Class rightsx1509(RIGHT_SX1509_ADDRESS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int right_initted = 0;
|
|
|
|
|
|
|
|
int left_initted = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -68,42 +60,15 @@ void scan_matrix() {
|
|
|
|
y = 0;
|
|
|
|
y = 0;
|
|
|
|
//scan the Keyboard matrix looking for connections
|
|
|
|
//scan the Keyboard matrix looking for connections
|
|
|
|
for (byte row = 0; row < LEFT_ROWS; row++) {
|
|
|
|
for (byte row = 0; row < LEFT_ROWS; row++) {
|
|
|
|
TS("Scanning row ")
|
|
|
|
implementation_scan_row(row);
|
|
|
|
if (left_initted) {
|
|
|
|
|
|
|
|
leftsx1509.updatePinState(left_rowpins[row], LOW);
|
|
|
|
|
|
|
|
leftsx1509.sendPinStates();
|
|
|
|
|
|
|
|
leftsx1509.fetchPinStates();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right_initted) {
|
|
|
|
|
|
|
|
rightsx1509.updatePinState(right_rowpins[row], LOW);
|
|
|
|
|
|
|
|
rightsx1509.sendPinStates();
|
|
|
|
|
|
|
|
rightsx1509.fetchPinStates();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (byte col = 0; col < LEFT_COLS; col++) {
|
|
|
|
for (byte col = 0; col < LEFT_COLS; col++) {
|
|
|
|
TS("Scanning col")
|
|
|
|
TS("Scanning col")
|
|
|
|
//If we see an electrical connection on I->J,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
matrixState[row][col] <<= 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
matrixState[row][(COLS - 1) - col] <<= 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TS("Reading left pin")
|
|
|
|
|
|
|
|
if (left_initted && leftsx1509.readPrefetchedPin(left_colpins[col])) {
|
|
|
|
|
|
|
|
matrixState[row][col] |= 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
matrixState[row][col] |= 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TS("Reading right pin")
|
|
|
|
|
|
|
|
if (right_initted && rightsx1509.readPrefetchedPin(right_colpins[col])) {
|
|
|
|
|
|
|
|
matrixState[row][(COLS - 1) - col] |= 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
matrixState[row][(COLS - 1) - col] |= 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
matrixState[row][col] = implementation_scan_left_col(row,col,matrixState[row][col]);
|
|
|
|
|
|
|
|
matrixState[row][(COLS - 1) - col] = implementation_scan_right_col(row,col,matrixState[row][(COLS - 1) - col]);
|
|
|
|
|
|
|
|
|
|
|
|
// while we're inspecting the electrical matrix, we look
|
|
|
|
// while we're inspecting the electrical matrix, we look
|
|
|
|
// to see if the Key being held is a firmware level
|
|
|
|
// to see if the Key being held is a firmware level
|
|
|
@ -111,18 +76,15 @@ void scan_matrix() {
|
|
|
|
// that we should be looking at a seconary Keymap halfway
|
|
|
|
// that we should be looking at a seconary Keymap halfway
|
|
|
|
// through the matrix scan
|
|
|
|
// through the matrix scan
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TS("calling send_key_event")
|
|
|
|
TS("calling send_key_event")
|
|
|
|
send_key_event(row, col);
|
|
|
|
send_key_event(row, col);
|
|
|
|
if (right_initted)
|
|
|
|
|
|
|
|
|
|
|
|
if (implementation_right_hand_connected()) {
|
|
|
|
send_key_event(row, (COLS - 1) - col);
|
|
|
|
send_key_event(row, (COLS - 1) - col);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TS("clearing output pins")
|
|
|
|
TS("clearing output pins")
|
|
|
|
if (left_initted)
|
|
|
|
implementation_finish_scanning_row(row);
|
|
|
|
leftsx1509.updatePinState(left_rowpins[row], HIGH);
|
|
|
|
|
|
|
|
if (right_initted)
|
|
|
|
|
|
|
|
rightsx1509.updatePinState(right_rowpins[row], HIGH);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TS("Sending key report");
|
|
|
|
TS("Sending key report");
|
|
|
|
Keyboard.sendReport();
|
|
|
|
Keyboard.sendReport();
|
|
|
@ -142,8 +104,7 @@ void setup() {
|
|
|
|
Mouse.begin();
|
|
|
|
Mouse.begin();
|
|
|
|
setup_leds();
|
|
|
|
setup_leds();
|
|
|
|
led_bootup();
|
|
|
|
led_bootup();
|
|
|
|
setup_pins();
|
|
|
|
implementation_pins_setup();
|
|
|
|
rightsx1509.fetchPinStates();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
temporary_keymap = primary_keymap = load_primary_keymap();
|
|
|
|
temporary_keymap = primary_keymap = load_primary_keymap();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -262,69 +223,4 @@ void press_key(Key mappedKey) {
|
|
|
|
Keyboard.press(mappedKey.rawKey);
|
|
|
|
Keyboard.press(mappedKey.rawKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void make_input(sx1509Class sx1509, uint8_t pin) {
|
|
|
|
|
|
|
|
sx1509.pinDir(pin, INPUT); // Set SX1509 pin 1 as an input
|
|
|
|
|
|
|
|
sx1509.writePin(pin, HIGH); // Activate pull-up
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void make_output(sx1509Class sx1509, uint8_t pin) {
|
|
|
|
|
|
|
|
sx1509.pinDir(pin, OUTPUT);
|
|
|
|
|
|
|
|
sx1509.writePin(pin, HIGH);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setup_pins() {
|
|
|
|
|
|
|
|
right_initted = setup_sx1509(rightsx1509, right_colpins, right_rowpins);
|
|
|
|
|
|
|
|
left_initted = setup_sx1509(leftsx1509, left_colpins, left_rowpins);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int setup_sx1509 (sx1509Class sx1509, uint8_t colpins[], uint8_t rowpins[]) {
|
|
|
|
|
|
|
|
byte initted;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int counter = 0; counter < 10; counter++) {
|
|
|
|
|
|
|
|
initted = sx1509.init();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (initted)
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (initted) { // init ok
|
|
|
|
|
|
|
|
// In order to use the keypad, the clock must first be
|
|
|
|
|
|
|
|
// configured. We can call configureClock() with the default
|
|
|
|
|
|
|
|
// parameters (2MHz internal oscillator, no clock in/out).
|
|
|
|
|
|
|
|
sx1509.configClock();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the debounceConfig function sets the debounce time. This
|
|
|
|
|
|
|
|
// function's parameter should be a 3-bit value.
|
|
|
|
|
|
|
|
// 0: 0.5ms * 2MHz/fOSC
|
|
|
|
|
|
|
|
// 1: 1ms * 2MHz/fOSC
|
|
|
|
|
|
|
|
// 2: 2ms * 2MHz/fOSC
|
|
|
|
|
|
|
|
// 3: 4ms * 2MHz/fOSC
|
|
|
|
|
|
|
|
// 4: 8ms * 2MHz/fOSC
|
|
|
|
|
|
|
|
// 5: 16ms * 2MHz/fOSC
|
|
|
|
|
|
|
|
// 6: 32ms * 2MHz/fOSC
|
|
|
|
|
|
|
|
// 7: 64ms * 2MHz/fOSC
|
|
|
|
|
|
|
|
sx1509.debounceConfig(4); // maximum debuonce time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < LEFT_ROWS; i++) {
|
|
|
|
|
|
|
|
make_output(sx1509, rowpins[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < LEFT_COLS; j++) {
|
|
|
|
|
|
|
|
make_input(sx1509, colpins[j]);
|
|
|
|
|
|
|
|
sx1509.debounceEnable(colpins[j]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return initted;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|