updated code (untested)
This commit is contained in:
3
mainboard/CMakeLists.txt
Normal file
3
mainboard/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16.0)
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(mainboard)
|
||||||
2084
mainboard/sdkconfig.esp32doit-devkit-v1
Normal file
2084
mainboard/sdkconfig.esp32doit-devkit-v1
Normal file
File diff suppressed because it is too large
Load Diff
6
mainboard/src/CMakeLists.txt
Normal file
6
mainboard/src/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# This file was automatically generated for projects
|
||||||
|
# without default 'CMakeLists.txt' file.
|
||||||
|
|
||||||
|
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
|
||||||
|
|
||||||
|
idf_component_register(SRCS ${app_sources})
|
||||||
@@ -4,21 +4,68 @@
|
|||||||
#define ROWS 2
|
#define ROWS 2
|
||||||
#define COLS 2
|
#define COLS 2
|
||||||
|
|
||||||
|
int ROW[] = {15,2};
|
||||||
|
int COL[] = {0,4};
|
||||||
|
|
||||||
|
//Stores The Raw Report of the Keyboard
|
||||||
|
uint8_t keyboard_report[ROWS][COLS];
|
||||||
|
|
||||||
|
//Stores The Mapping of Each of The Key. Mapping is based of the ASCII value of that key.
|
||||||
|
//Mappings are in the 2D Space - it's shifted version is 32 bits more than the original
|
||||||
|
//Thus to get shifted version of M which is 0x4D we can add it by 32 which would be 0x6D
|
||||||
|
//
|
||||||
|
// Potential Improvements:
|
||||||
|
// It may be possible to make a firmware by just altering this variable to the mappings are reconfigurable.
|
||||||
|
// It may be possible to use more than 2 dimension of the array to allocate for special "shift" keys found on SFF keyboards
|
||||||
|
uint8_t keyboard_mapping[ROWS][COLS] = {
|
||||||
|
{0x4D,0x69},
|
||||||
|
{0x4B,0x55},
|
||||||
|
};
|
||||||
|
|
||||||
|
//Temporary variable to store old and new keyoard report.
|
||||||
|
//This way we only change the keyboard state when there is a change in the raw data.
|
||||||
|
//This allows us to hold keys and press multiple at the same time
|
||||||
|
//Rather than sending individual keystroke each press
|
||||||
|
uint8_t old_report;
|
||||||
|
uint8_t new_report;
|
||||||
|
|
||||||
BleKeyboard bleKeyboard("ModularKeyboard_MainBoard");
|
BleKeyboard bleKeyboard("ModularKeyboard_MainBoard");
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Starting BLE work!");
|
Serial.println("Starting BLE work!");
|
||||||
bleKeyboard.begin();
|
bleKeyboard.begin();
|
||||||
|
for (int i=0; i<COLS; i++){
|
||||||
|
pinMode(ROW[i], INPUT);
|
||||||
|
pinMode(COL[i], OUTPUT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if(bleKeyboard.isConnected()){
|
if(bleKeyboard.isConnected()){
|
||||||
|
// Reset keyboard report
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
for (int j = 0; j < 2; j++) {
|
||||||
|
keyboard_report[i][j] = 0x0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Read keyboard report and send
|
||||||
for(int i=0; i < COLS; i++){
|
for(int i=0; i < COLS; i++){
|
||||||
//TURN ON ROW
|
//Write to the column
|
||||||
|
digitalWrite(COL[i], HIGH);
|
||||||
for(int j=0; j < ROWS; j++){
|
for(int j=0; j < ROWS; j++){
|
||||||
//READ EACH ROW
|
//Read row input
|
||||||
//ENABLE KEY IN THAT PIN
|
old_report = keyboard_report[i][j];
|
||||||
|
new_report = digitalRead(ROW[j]);
|
||||||
|
if(old_report!=new_report){
|
||||||
|
if(new_report){
|
||||||
|
bleKeyboard.press(keyboard_mapping[i][j]);
|
||||||
|
}else{
|
||||||
|
bleKeyboard.release(keyboard_mapping[i][j]);
|
||||||
|
bleKeyboard.release(keyboard_mapping[i][j] + 32); //Shifted version
|
||||||
|
}
|
||||||
|
keyboard_report[i][j] = new_report;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user