Add files via upload

This commit is contained in:
Frank Adams 2020-04-29 07:00:27 -07:00 committed by GitHub
parent 7c9b6e2333
commit 574c29a440
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 506 additions and 0 deletions

View file

@ -0,0 +1,117 @@
I/O # FPC Conn #
MODIFIERKEY_LEFT_CTRL 4 11 10 24
MODIFIERKEY_RIGHT_CTRL 4 31 10 17
MODIFIERKEY_LEFT_SHIFT 3 11 8 24
MODIFIERKEY_RIGHT_SHIFT 3 31 8 17
MODIFIERKEY_LEFT_ALT 20 11 7 24
MODIFIERKEY_RIGHT_ALT 20 31 7 17
MODIFIERKEY_GUI 33 28 19 25
MODIFIERKEY_FN 9 28 20 25
KEY_A 17 9 13 20
KEY_B 17 10 13 22
KEY_C 3 8 8 18
KEY_D 18 9 11 20
KEY_E 20 32 7 21
KEY_F 19 8 9 18
KEY_G 19 30 9 23
KEY_H 0 11 2 24
KEY_I 6 11 14 24
KEY_J 29 11 15 24
KEY_K 2 11 6 24
KEY_L 1 11 4 24
KEY_M 3 10 8 22
KEY_N 5 10 12 22
KEY_O 21 11 5 24
KEY_P 22 11 3 24
KEY_Q 18 32 11 21
KEY_R 18 8 11 18
KEY_S 5 33 12 19
KEY_T 17 30 13 23
KEY_U 7 11 16 24
KEY_V 20 30 7 23
KEY_W 5 32 12 21
KEY_X 4 9 10 20
KEY_Y 11 12 24 26
KEY_Z 4 33 10 19
KEY_TILDE 9 12 20 26
KEY_1 21 31 5 17
KEY_2 7 31 16 17
KEY_3 29 31 15 17
KEY_4 6 31 14 17
KEY_5 2 31 6 17
KEY_6 6 33 14 19
KEY_7 2 33 6 19
KEY_8 7 8 16 18
KEY_9 29 8 15 18
KEY_0 6 8 14 18
KEY_MINUS 29 30 15 23
KEY_EQUAL 21 30 5 23
KEY_BACKSPACE 23 8 1 18
KEY_ESC 32 12 21 26
KEY_F1 21 8 5 18
KEY_F2 7 32 16 21
KEY_F3 29 32 15 21
KEY_F4 6 32 14 21
KEY_F5 2 32 6 21
KEY_F6 2 9 6 20
KEY_F7 21 32 5 21
KEY_F8 21 9 5 20
KEY_F9 22 32 3 21
KEY_F10 1 32 4 21
KEY_F11 0 32 2 21
KEY_F12 23 32 1 21
KEY_INSERT 21 33 5 19
KEY_DELETE 2 8 6 18
KEY_RIGHT 23 31 1 17
KEY_LEFT 0 31 2 17
KEY_UP 22 31 3 17
KEY_DOWN 1 31 4 17
KEY_MENU 7 9 16 20
KEY_SLASH 7 30 16 23
KEY_PERIOD 2 30 6 23
KEY_COMMA 23 11 1 24
KEY_SEMICOLON 23 30 1 23
KEY_QUOTE 22 30 3 23
KEY_ENTER 30 28 23 25
KEY_LEFT_BRACE 30 12 23 26
KEY_RIGHT_BRACE 6 30 14 23
KEY_BACKSLASH 0 8 2 18
KEY_CAPS_LOCK 0 33 2 19
KEY_TAB 31 12 17 26
KEY_SPACE 19 33 9 19
KEY_HOME 7 33 16 19
KEY_END 29 33 15 19
KEY_PAGE_UP FN 7 33 16 19
KEY_PAGE_DOWN FN 29 33 15 19
KEY_NUM_LOCK 23 33 1 19
KEYPAD_SLASH 23 9 1 20
KEYPAD_ASTERIX 0 9 2 20
KEYPAD_MINUS 1 9 4 20
KEYPAD_7 23 10 1 22
KEYPAD_8 22 10 3 22
KEYPAD_9 1 10 4 22
KEYPAD_PLUS 22 9 3 20
KEYPAD_4 29 10 15 22
KEYPAD_5 10 12 22 26
KEYPAD_6 0 10 2 22
KEYPAD_1 21 10 5 22
KEYPAD_2 6 10 14 22
KEYPAD_3 7 10 16 22
KEYPAD_0 2 10 6 22
KEYPAD_PERIOD 33 12 19 26
KEYPAD_ENTER 10 28 22 25
KEY_MEDIA_VOLUME_DEC FN 0 31 2 17
KEY_MEDIA_VOLUME_INC FN 23 31 1 17
KEY_MEDIA_MUTE FN 2 10 6 22
KEY_MEDIA_EJECT FN
custom FN keys not on list:
bightness in FN 22 31 3 17
bightness de FN 1 31 4 17
sleep FN 23 32 1 21
touch mouse toggle FN 29 32 15 21
sceen project FN 7 32 16 21
camera toggle FN 2 9 6 20
airplane toggle mode FN 1 32 4 21
eco mode FN 2 32
performance mode swith FN 21 32 5 21

View file

@ -0,0 +1,389 @@
/* Copyright 2020 Frank Adams
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This software implements a Laptop Keyboard Controller for an msi ge63 raider rgb 8re
// using a Teensy 4.0 on a daughterboard with an FPC connector.
// This routine uses the Teensyduino "Micro-Manager Method" to send Normal and Modifier
// keys over USB. Multi-media keys are sent with keyboard press and release functions.
// Description of Teensyduino keyboard functions is at www.pjrc.com/teensy/td_keyboard.html
//
// Revision History
// Initial Release April 28, 2020
//
#define MODIFIERKEY_FN 0x8f // give Fn key a HID code
#define CAPS_LED 13 // Teensy LED shows Caps-Lock
//
const byte rows_max = 18; // sets the number of rows in the matrix
const byte cols_max = 8; // sets the number of columns in the matrix
//
// Load the normal key matrix with the Teensyduino key names described at www.pjrc.com/teensy/td_keyboard.html
// A zero indicates no normal key at that location.
//
int normal[rows_max][cols_max] = {
{KEY_RIGHT,KEY_BACKSPACE,KEY_NUM_LOCK,KEYPAD_SLASH,KEY_F12,KEYPAD_7,KEY_SEMICOLON,KEY_COMMA},
{KEY_LEFT,KEY_BACKSLASH,KEY_CAPS_LOCK,KEYPAD_ASTERIX,KEY_F11,KEYPAD_6,0,KEY_H},
{KEY_UP,0,0,KEYPAD_PLUS,KEY_F9,KEYPAD_8,KEY_QUOTE,KEY_P},
{KEY_DOWN,0,0,KEYPAD_MINUS,KEY_F10,KEYPAD_9,0,KEY_L},
{KEY_1,KEY_F1,KEY_INSERT,KEY_F8,KEY_F7,KEYPAD_1,KEY_EQUAL,KEY_O},
{KEY_5,KEY_DELETE,KEY_7,KEY_F6,KEY_F5,KEYPAD_0,KEY_PERIOD,KEY_K},
{0,0,0,0,KEY_E,0,KEY_V,0},
{0,KEY_C,0,0,0,KEY_M,0,0},
{0,KEY_F,KEY_SPACE,0,0,0,KEY_G,0},
{0,0,KEY_Z,KEY_X,0,0,0,0},
{0,KEY_R,0,KEY_D,KEY_Q,0,0,0},
{0,0,KEY_S,0,KEY_W,KEY_N,0,0},
{0,0,0,KEY_A,0,KEY_B,KEY_T,0},
{KEY_4,KEY_0,KEY_6,0,KEY_F4,KEYPAD_2,KEY_RIGHT_BRACE,KEY_I},
{KEY_3,KEY_9,KEY_END,0,KEY_F3,KEYPAD_4,KEY_MINUS,KEY_J},
{KEY_2,KEY_8,KEY_HOME,KEY_MENU,KEY_F2,KEYPAD_3,KEY_SLASH,KEY_U},
{0,0,0,0,0,KEYPAD_ENTER,KEY_ENTER,0},
{KEY_TAB,0,KEY_PERIOD,KEY_TILDE,KEY_ESC,KEYPAD_5,KEY_LEFT_BRACE,KEY_Y}
};
// Load the modifier key matrix with key names at the correct row-column location.
// A zero indicates no modifier key at that location.
int modifier[rows_max][cols_max] = {
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{MODIFIERKEY_RIGHT_ALT,0,0,0,0,0,0,MODIFIERKEY_LEFT_ALT},
{MODIFIERKEY_RIGHT_SHIFT,0,0,0,0,0,0,MODIFIERKEY_LEFT_SHIFT},
{0,0,0,0,0,0,0,0},
{MODIFIERKEY_RIGHT_CTRL,0,0,0,0,0,0,MODIFIERKEY_LEFT_CTRL},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,MODIFIERKEY_GUI,MODIFIERKEY_FN,0,0,0,0},
{0,0,0,0,0,0,0,0}
};
// Load the media key matrix with Fn key names at the correct row-column location.
// A zero indicates no media key at that location.
int media[rows_max][cols_max] = {
{KEY_MEDIA_VOLUME_INC,0,0,0,KEY_SYSTEM_SLEEP,0,0,0},
{KEY_MEDIA_VOLUME_DEC,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,KEY_MEDIA_MUTE,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,KEY_PAGE_DOWN,0,0,0,0,0},
{0,0,KEY_PAGE_UP,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}
};
// Initialize the old_key matrix with one's.
// 1 = key not pressed, 0 = key is pressed
boolean old_key[rows_max][cols_max] = {
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1}
};
//
// Define the Teensy 4.0 I/O numbers (translated from the FPC pin #)
// Row FPC pin # 01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,25,26
// Teensy I/O # 23,00,22,01,21,02,20,03,19,04,18,05,17,06,29,07,28,12
int Row_IO[rows_max] = {23,0,22,1,21,2,20,3,19,4,18,5,17,6,29,7,28,12}; // Teensy 4.0 I/O numbers for rows
//
// Column FPC pin # 17,18,19,20,21,22,23,24
// Teensy I/O # 31,08,33,09,32,10,30,11
int Col_IO[cols_max] = {31,8,33,9,32,10,30,11}; // Teensy 4.0 I/O numbers for columns
// Declare variables that will be used by functions
boolean slots_full = LOW; // Goes high when slots 1 thru 6 contain normal keys
// slot 1 thru slot 6 hold the normal key values to be sent over USB.
int slot1 = 0; //value of 0 means the slot is empty and can be used.
int slot2 = 0;
int slot3 = 0;
int slot4 = 0;
int slot5 = 0;
int slot6 = 0;
//
int mod_shift_l = 0; // These variables are sent over USB as modifier keys.
int mod_shift_r = 0; // Each is either set to 0 or MODIFIER_ ...
int mod_ctrl_l = 0;
int mod_ctrl_r = 0;
int mod_alt_l = 0;
int mod_alt_r = 0;
int mod_gui = 0;
//
// Function to load the key name into the first available slot
void load_slot(int key) {
if (!slot1) {
slot1 = key;
}
else if (!slot2) {
slot2 = key;
}
else if (!slot3) {
slot3 = key;
}
else if (!slot4) {
slot4 = key;
}
else if (!slot5) {
slot5 = key;
}
else if (!slot6) {
slot6 = key;
}
if (!slot1 || !slot2 || !slot3 || !slot4 || !slot5 || !slot6) {
slots_full = LOW; // slots are not full
}
else {
slots_full = HIGH; // slots are full
}
}
//
// Function to clear the slot that contains the key name
void clear_slot(int key) {
if (slot1 == key) {
slot1 = 0;
}
else if (slot2 == key) {
slot2 = 0;
}
else if (slot3 == key) {
slot3 = 0;
}
else if (slot4 == key) {
slot4 = 0;
}
else if (slot5 == key) {
slot5 = 0;
}
else if (slot6 == key) {
slot6 = 0;
}
if (!slot1 || !slot2 || !slot3 || !slot4 || !slot5 || !slot6) {
slots_full = LOW; // slots are not full
}
else {
slots_full = HIGH; // slots are full
}
}
//
// Function to load the modifier key name into the appropriate mod variable
void load_mod(int m_key) {
if (m_key == MODIFIERKEY_LEFT_SHIFT) {
mod_shift_l = m_key;
}
else if (m_key == MODIFIERKEY_RIGHT_SHIFT) {
mod_shift_r = m_key;
}
else if (m_key == MODIFIERKEY_LEFT_CTRL) {
mod_ctrl_l = m_key;
}
else if (m_key == MODIFIERKEY_RIGHT_CTRL) {
mod_ctrl_r = m_key;
}
else if (m_key == MODIFIERKEY_LEFT_ALT) {
mod_alt_l = m_key;
}
else if (m_key == MODIFIERKEY_RIGHT_ALT) {
mod_alt_r = m_key;
}
else if (m_key == MODIFIERKEY_GUI) {
mod_gui = m_key;
}
}
//
// Function to load 0 into the appropriate mod variable
void clear_mod(int m_key) {
if (m_key == MODIFIERKEY_LEFT_SHIFT) {
mod_shift_l = 0;
}
else if (m_key == MODIFIERKEY_RIGHT_SHIFT) {
mod_shift_r = 0;
}
else if (m_key == MODIFIERKEY_LEFT_CTRL) {
mod_ctrl_l = 0;
}
else if (m_key == MODIFIERKEY_RIGHT_CTRL) {
mod_ctrl_r = 0;
}
else if (m_key == MODIFIERKEY_LEFT_ALT) {
mod_alt_l = 0;
}
else if (m_key == MODIFIERKEY_RIGHT_ALT) {
mod_alt_r = 0;
}
else if (m_key == MODIFIERKEY_GUI) {
mod_gui = 0;
}
}
//
// Function to send the modifier keys over usb
void send_mod() {
Keyboard.set_modifier(mod_shift_l | mod_shift_r | mod_ctrl_l | mod_ctrl_r | mod_alt_l | mod_alt_r | mod_gui);
Keyboard.send_now();
}
//
// Function to send the normal keys in the 6 slots over usb
void send_normals() {
Keyboard.set_key1(slot1);
Keyboard.set_key2(slot2);
Keyboard.set_key3(slot3);
Keyboard.set_key4(slot4);
Keyboard.set_key5(slot5);
Keyboard.set_key6(slot6);
Keyboard.send_now();
}
//
// Function to set a pin to high impedance (acts like open drain output)
void go_z(int pin)
{
pinMode(pin, INPUT);
digitalWrite(pin, HIGH);
}
//
// Function to set a pin as an input with a pullup
void go_pu(int pin)
{
pinMode(pin, INPUT_PULLUP);
digitalWrite(pin, HIGH);
}
//
// Function to send a pin to a logic low
void go_0(int pin)
{
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
}
//
// Function to send a pin to a logic high
void go_1(int pin)
{
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
}
//
//----------------------------------Setup-------------------------------------------
void setup() {
for (int a = 0; a < cols_max; a++) { // loop thru all column pins
go_pu(Col_IO[a]); // set each column pin as an input with a pullup
}
//
for (int b = 0; b < rows_max; b++) { // loop thru all row pins
go_z(Row_IO[b]); // set each row pin as a floating output
}
}
//
boolean Fn_pressed = HIGH; // Initialize Fn key to HIGH = "not pressed"
extern volatile uint8_t keyboard_leds; // 8 bits sent from Host to Teensy that give keyboard LED status. Caps lock is bit D1.
//
//---------------------------------Main Loop---------------------------------------------
//
void loop() {
// Scan keyboard matrix with an outer loop that drives each row low and an inner loop that reads every column (with pull ups).
// The routine looks at each key's present state (by reading the column input pin) and also the previous state from the last scan
// that was 30msec ago. The status of a key that was just pressed or just released is sent over USB and the state is saved in the old_key matrix.
// The keyboard keys will read as logic low if they are pressed (negative logic).
// The old_key matrix also uses negative logic (low=pressed).
//
for (int x = 0; x < rows_max; x++) { // loop thru the rows
go_0(Row_IO[x]); // Activate Row (send it low)
delayMicroseconds(10); // give the row time to go low and settle out
for (int y = 0; y < cols_max; y++) { // loop thru the columns
// **********Modifier keys including the Fn special case
if (modifier[x][y] != 0) { // check if modifier key exists at this location in the array (a non-zero value)
if (!digitalRead(Col_IO[y]) && (old_key[x][y])) { // Read column to see if key is low (pressed) and was previously not pressed
if (modifier[x][y] != MODIFIERKEY_FN) { // Exclude Fn modifier key
load_mod(modifier[x][y]); // function reads which modifier key is pressed and loads it into the appropriate mod_... variable
send_mod(); // function sends the state of all modifier keys over usb including the one that just got pressed
old_key[x][y] = LOW; // Save state of key as "pressed"
}
else {
Fn_pressed = LOW; // Fn status variable is active low
old_key[x][y] = LOW; // old_key state is "pressed" (active low)
}
}
else if (digitalRead(Col_IO[y]) && (!old_key[x][y])) { //check if key is not pressed and was previously pressed
if (modifier[x][y] != MODIFIERKEY_FN) { // Exclude Fn modifier key
clear_mod(modifier[x][y]); // function reads which modifier key was released and loads 0 into the appropriate mod_... variable
send_mod(); // function sends all mod's over usb including the one that just released
old_key[x][y] = HIGH; // Save state of key as "not pressed"
}
else {
Fn_pressed = HIGH; // Fn is no longer active
old_key[x][y] = HIGH; // old_key state is "not pressed"
}
}
}
// ***********end of modifier section
//
// ***********Normal keys and media keys in this section
else if ((normal[x][y] != 0) || (media[x][y] != 0)) { // check if normal or media key exists at this location in the array
if (!digitalRead(Col_IO[y]) && (old_key[x][y]) && (!slots_full)) { // check if key is pressed and was not previously pressed and slots not full
old_key[x][y] = LOW; // Save state of key as "pressed"
if (Fn_pressed) { // Fn_pressed is active low so it is not pressed and normal key needs to be sent
load_slot(normal[x][y]); //update first available slot with normal key name
send_normals(); // send all slots over USB including the key that just got pressed
}
else if (media[x][y] != 0) { // Fn is pressed so send media if a key exists in the matrix
Keyboard.press(media[x][y]); // media key is sent using keyboard press function per PJRC
delay(5); // delay 5 milliseconds before releasing to make sure it gets sent over USB
Keyboard.release(media[x][y]); // send media key release
}
}
else if (digitalRead(Col_IO[y]) && (!old_key[x][y])) { //check if key is not pressed, but was previously pressed
old_key[x][y] = HIGH; // Save state of key as "not pressed"
if (Fn_pressed) { // Fn is not pressed
clear_slot(normal[x][y]); //clear the slot that contains the normal key name
send_normals(); // send all slots over USB including the key that was just released
}
}
}
// **************end of normal and media key section
//
}
go_z(Row_IO[x]); // De-activate Row (send it to hi-z)
}
//
// **********keyboard scan complete
//
// Turn on the LED on the Teensy for Caps Lock based on bit 1 in the keyboard_leds variable controlled by the USB host computer
//
if (keyboard_leds & 1<<1) { // mask off all bits but D1 and test if set
go_1(CAPS_LED); // turn on the LED
}
else {
go_0(CAPS_LED); // turn off the LED
}
//
delay(25); // The overall keyboard scanning rate is about 30ms
}