diff --git a/keyboards/system76/launch_3/config.h b/keyboards/system76/launch_3/config.h new file mode 100644 index 00000000000..009bebdbc67 --- /dev/null +++ b/keyboards/system76/launch_3/config.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2021 System76 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +/* + * Key matrix pins + * ROWS: GPIO pins used for rows, top to bottom + * COLS: GPIO pins used for columns, left to right + */ +#define MATRIX_ROW_PINS {GP24, GP23, GP22, GP21, GP28, GP15} +#define MATRIX_COL_PINS {GP12, GP11, GP10, GP9, GP8, GP6, GP13, GP14, GP16, GP17, GP18, GP19, GP7, GP25} + +/* + * Diode Direction + * COL2ROW = COL => Anode (+), ROW => Cathode (-) + * ROW2COL = ROW => Anode (+), COL => Cathode (-) + */ +#define DIODE_DIRECTION COL2ROW + +#ifdef RGB_MATRIX_ENABLE +# define WS2812_DI_PIN GP5 +# define RGB_MATRIX_LED_COUNT 84 +# define RGB_MATRIX_KEYPRESSES // Reacts to keypresses +// # define RGB_MATRIX_KEYRELEASES // Reacts to keyreleases (instead of keypresses) +// # define RGB_MATRIX_FRAMEBUFFER_EFFECTS // Enables framebuffer effects +# define RGB_DISABLE_WHEN_USB_SUSPENDED // Turns off effects when suspended +// Limit brightness to support USB-A at 0.5 A +// TODO: Do this dynamically based on power source +# define RGB_MATRIX_MAXIMUM_BRIGHTNESS 176 // Limits maximum brightness of LEDs to 176 out of 255. If not defined, maximum brightness is set to 255 +# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_RAINBOW_MOVING_CHEVRON // Sets the default mode, if none has been set +# define RGB_MATRIX_DEFAULT_HUE 142 // Sets the default hue value, if none has been set +# define RGB_MATRIX_DEFAULT_SAT 255 // Sets the default saturation value, if none has been set +# define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS // Sets the default brightness value, if none has been set +# define RGB_MATRIX_DEFAULT_SPD 127 // Sets the default animation speed, if none has been set +# define RGB_MATRIX_DISABLE_KEYCODES // Disables control of rgb matrix by keycodes (must use code functions to control the feature) + +# define ENABLE_RGB_MATRIX_CYCLE_ALL +# define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +# define ENABLE_RGB_MATRIX_CYCLE_UP_DOWN +# define ENABLE_RGB_MATRIX_CYCLE_OUT_IN +# define ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL +# define ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +# define ENABLE_RGB_MATRIX_CYCLE_PINWHEEL +# define ENABLE_RGB_MATRIX_CYCLE_SPIRAL +# define ENABLE_RGB_MATRIX_RAINDROPS +# define ENABLE_RGB_MATRIX_SPLASH +# define ENABLE_RGB_MATRIX_MULTISPLASH +#endif // RGB_MATRIX_ENABLE + +// Mechanical locking support; use KC_LCAP, KC_LNUM, or KC_LSCR instead in keymap +#define LOCKING_SUPPORT_ENABLE + +// Locking resynchronize hack +#define LOCKING_RESYNC_ENABLE + +// I2C { +#define I2C_DRIVER I2CD1 +#define I2C1_CLOCK_SPEED 100000UL // Run I2C bus at 100 kHz +#define I2C1_SCL_PIN GP27 +#define I2C1_SDA_PIN GP26 +// } I2C + +// EEPROM { +#define EEPROM_SIZE 1024 +// TODO: Refactor with new user EEPROM code (coming soon) +#define EEPROM_MAGIC 0x76EC +#define EEPROM_MAGIC_ADDR 64 +// Bump this every time we change what we store +// This will automatically reset the EEPROM with defaults +// and avoid loading invalid data from the EEPROM +#define EEPROM_VERSION 0x02 +#define EEPROM_VERSION_ADDR (EEPROM_MAGIC_ADDR + 2) +// } EEPROM + +// Dynamic keymap { +#define DYNAMIC_KEYMAP_LAYER_COUNT 4 +#define DYNAMIC_KEYMAP_MACRO_COUNT 0 +// Dynamic keymap starts after EEPROM version +#define DYNAMIC_KEYMAP_EEPROM_ADDR (EEPROM_VERSION_ADDR + 1) +// Dynamic macro starts after dynamic keymaps, it is disabled +#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_EEPROM_ADDR + (DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2)) +#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 0 +// } Dynamic keymap + +// System76 EC { +#define SYSTEM76_EC_EEPROM_ADDR (DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE) +#define SYSTEM76_EC_EEPROM_SIZE (EEPROM_SIZE - SYSTEM76_EC_EEPROM_ADDR) +// } System76 EC diff --git a/keyboards/system76/launch_3/halconf.h b/keyboards/system76/launch_3/halconf.h new file mode 100644 index 00000000000..8c220f68b6a --- /dev/null +++ b/keyboards/system76/launch_3/halconf.h @@ -0,0 +1,21 @@ +/* Copyright 2023 System76 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#define HAL_USE_I2C TRUE + +#include_next diff --git a/keyboards/system76/launch_3/info.json b/keyboards/system76/launch_3/info.json new file mode 100644 index 00000000000..29b21bcbcd7 --- /dev/null +++ b/keyboards/system76/launch_3/info.json @@ -0,0 +1,102 @@ +{ + "keyboard_name": "Launch Configurable Keyboard (launch_3)", + "manufacturer": "System76", + "url": "https://system76.com/accessories/launch", + "usb": { + "vid": "0x3384", + "pid": "0x0009", + "device_version": "0.0.1" + }, + "processor": "RP2040", + "bootloader": "rp2040", + "layouts": { + "LAYOUT": { + "layout": [ + { "label": "Esc", "x": 0, "y": 0 }, + { "label": "F1", "x": 1, "y": 0 }, + { "label": "F2", "x": 2, "y": 0 }, + { "label": "F3", "x": 3, "y": 0 }, + { "label": "F4", "x": 4, "y": 0 }, + { "label": "F5", "x": 5, "y": 0 }, + { "label": "F6", "x": 6, "y": 0 }, + { "label": "F7", "x": 7, "y": 0 }, + { "label": "F8", "x": 8, "y": 0 }, + { "label": "F9", "x": 9, "y": 0 }, + { "label": "F10", "x": 10, "y": 0 }, + { "label": "F11", "x": 11, "y": 0 }, + { "label": "F12", "x": 12, "y": 0 }, + { "label": "Del", "x": 13, "y": 0, "w": 1.5 }, + { "label": "Home", "x": 14.75, "y": 0 }, + { "label": "`", "x": 0, "y": 1 }, + { "label": "1", "x": 1, "y": 1 }, + { "label": "2", "x": 2, "y": 1 }, + { "label": "3", "x": 3, "y": 1 }, + { "label": "4", "x": 4, "y": 1 }, + { "label": "5", "x": 5, "y": 1 }, + { "label": "6", "x": 6, "y": 1 }, + { "label": "7", "x": 7, "y": 1 }, + { "label": "8", "x": 8, "y": 1 }, + { "label": "9", "x": 9, "y": 1 }, + { "label": "0", "x": 10, "y": 1 }, + { "label": "-", "x": 11, "y": 1 }, + { "label": "=", "x": 12, "y": 1 }, + { "label": "Bksp", "x": 13, "y": 1, "w": 1.5 }, + { "label": "PgUp", "x": 14.75, "y": 1 }, + { "label": "Tab", "x": 0, "y": 2, "w": 1.5 }, + { "label": "Q", "x": 1.5, "y": 2 }, + { "label": "W", "x": 2.5, "y": 2 }, + { "label": "E", "x": 3.5, "y": 2 }, + { "label": "R", "x": 4.5, "y": 2 }, + { "label": "T", "x": 5.5, "y": 2 }, + { "label": "Y", "x": 6.5, "y": 2 }, + { "label": "U", "x": 7.5, "y": 2 }, + { "label": "I", "x": 8.5, "y": 2 }, + { "label": "O", "x": 9.5, "y": 2 }, + { "label": "P", "x": 10.5, "y": 2 }, + { "label": "[", "x": 11.5, "y": 2 }, + { "label": "]", "x": 12.5, "y": 2 }, + { "label": "\\", "x": 13.5, "y": 2 }, + { "label": "PgDn", "x": 14.75, "y": 2 }, + { "label": "Caps", "x": 0.25, "y": 3, "w": 1.5 }, + { "label": "A", "x": 1.75, "y": 3 }, + { "label": "S", "x": 2.75, "y": 3 }, + { "label": "D", "x": 3.75, "y": 3 }, + { "label": "F", "x": 4.75, "y": 3 }, + { "label": "G", "x": 5.75, "y": 3 }, + { "label": "H", "x": 6.75, "y": 3 }, + { "label": "J", "x": 7.75, "y": 3 }, + { "label": "K", "x": 8.75, "y": 3 }, + { "label": "L", "x": 9.75, "y": 3 }, + { "label": ";", "x": 10.75, "y": 3 }, + { "label": "'", "x": 11.75, "y": 3 }, + { "label": "Enter", "x": 12.75, "y": 3, "w": 1.5 }, + { "label": "End", "x": 14.75, "y": 3 }, + { "label": "LShift", "x": 0.25, "y": 4, "w": 2 }, + { "label": "Z", "x": 2.25, "y": 4 }, + { "label": "X", "x": 3.25, "y": 4 }, + { "label": "C", "x": 4.25, "y": 4 }, + { "label": "V", "x": 5.25, "y": 4 }, + { "label": "B", "x": 6.25, "y": 4 }, + { "label": "N", "x": 7.25, "y": 4 }, + { "label": "M", "x": 8.25, "y": 4 }, + { "label": ",", "x": 9.25, "y": 4 }, + { "label": ".", "x": 10.25, "y": 4 }, + { "label": "/", "x": 11.25, "y": 4 }, + { "label": "RShift", "x": 12.25, "y": 4, "w": 1.5 }, + { "label": "Up", "x": 13.75, "y": 4 }, + { "label": "LCtrl", "x": 0.25, "y": 5, "w": 1.5 }, + { "label": "LAlt", "x": 1.75, "y": 5 }, + { "label": "LFn", "x": 2.75, "y": 5 }, + { "label": "Super", "x": 3.75, "y": 5 }, + { "label": "Space", "x": 4.75, "y": 5, "w": 2 }, + { "label": "Space", "x": 6.75, "y": 5, "w": 2 }, + { "label": "RCtrl", "x": 8.75, "y": 5 }, + { "label": "RAlt", "x": 9.75, "y": 5 }, + { "label": "RFn", "x": 10.75, "y": 5, "w": 1.5 }, + { "label": "Left", "x": 12.75, "y": 5 }, + { "label": "Down", "x": 13.75, "y": 5 }, + { "label": "Right", "x": 14.75, "y": 5 } + ] + } + } +} diff --git a/keyboards/system76/launch_3/keymaps/default/keymap.c b/keyboards/system76/launch_3/keymaps/default/keymap.c new file mode 100644 index 00000000000..3efec2d1df4 --- /dev/null +++ b/keyboards/system76/launch_3/keymaps/default/keymap.c @@ -0,0 +1,91 @@ +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + + /* Layer 0, default layer +__________________________________________________________________________________________________________________________________ ________ +| | | | | | | | | | | | | | || | +| ESC | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | DELETE || HOME | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | | | || | +| ~` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | _ - | = + | BACKSPACE || PGUP | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | [ | ] | || | +| TAB | Q | W | E | R | T | Y | U | I | O | P | { | } | | \ || PGDN | +|____________|________|________|________|________|________|________|________|________|________|________|________|________|________||________| + | | | | | | | | | | | ; | ' | | | | + | CAPS | A | S | D | F | G | H | J | K | L | : | " | ENTER | | END | + |____________|________|________|________|________|________|________|________|________|________|________|________|____________|___|________| + | | | | | | | | | , | . | / | | | + | SHIFT | Z | X | C | V | B | N | M | < | > | ? | SHIFT | UP | + |________________|________|________|________|________|________|________|________|________|________|________|____________|________|_________ + | | | | | | | | | | | | | | + | CTRL | LALT | FN | LGUI | SPACE | SPACE | RCTRL | RALT | FN | | LEFT | DOWN | RIGHT | + |____________|________|_______|________|_________________|_________________|________|________|_____________| |________|________|________| +*/ + + [0] = LAYOUT( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_HOME, + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_PGUP, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGDN, + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_END, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, + KC_LCTL, KC_LALT, MO(1), KC_LGUI, KC_SPC, KC_SPC, KC_RCTL, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT + ), + + /* Layer 1, function layer +__________________________________________________________________________________________________________________________________ ________ +| | | | | | | | | | | | | | || PLAY/ | +| QK_BOOT | | | | | | | | | | | | | || PAUSE | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | LED | LED | LED | || VOLUME | +| | | | | | | | | | | TOGGLE | DOWN | UP | || UP | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | | | || VOLUME | +|PRINT SCREEN| | | | | | HOME | PGDN | PGUP | END | | | | || DOWN | +|____________|________|________|________|________|________|________|________|________|________|________|________|________|________||________| + | | | | | | | | | | | | | | | | + | | | | | | | LEFT | DOWN | UP | RIGHT | | | | | MUTE | + |____________|________|________|________|________|________|________|________|________|________|________|________|____________|___|________| + | | | | | | | | | | | | | | + | | | | | | | | | | | | | PGUP | + |________________|________|________|________|________|________|________|________|________|________|________|____________|________|_________ + | | | | | | | | | | | | | | + | | | | | | | | | | | HOME | PGDN | END | + |____________|________|_______|________|_________________|_________________|________|________|_____________| |________|________|________| + +* 'QK_BOOT' resets the controller and puts the board into firmware flashing mode. If this key is hit accidentally, just unplug the board +* and plug it back in. +*/ + + [1] = LAYOUT( + QK_BOOT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_TOG, RGB_VAD, RGB_VAI, KC_TRNS, KC_VOLU, + KC_PSCR, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_PGUP, KC_END, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_VOLD, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_TRNS, KC_TRNS, KC_TRNS, KC_MUTE, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END + ), + + [2] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS + ), + + [3] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS + ), +}; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + return true; +} diff --git a/keyboards/system76/launch_3/keymaps/jeremy/keymap.c b/keyboards/system76/launch_3/keymaps/jeremy/keymap.c new file mode 100644 index 00000000000..3bbaf119fcb --- /dev/null +++ b/keyboards/system76/launch_3/keymaps/jeremy/keymap.c @@ -0,0 +1,91 @@ +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + + /* Layer 0, default layer +__________________________________________________________________________________________________________________________________ ________ +| | | | | | | | | | | | | | || | +| ESC | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | DELETE || HOME | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | | | || | +| ~` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | _ - | = + | BACKSPACE || PGUP | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | [ | ] | || | +| TAB | Q | W | E | R | T | Y | U | I | O | P | { | } | | \ || PGDN | +|____________|________|________|________|________|________|________|________|________|________|________|________|________|________||________| + | | | | | | | | | | | ; | ' | | | | + | FN | A | S | D | F | G | H | J | K | L | : | " | ENTER | | END | + |____________|________|________|________|________|________|________|________|________|________|________|________|____________|___|________| + | | | | | | | | | , | . | / | | | + | SHIFT | Z | X | C | V | B | N | M | < | > | ? | SHIFT | UP | + |________________|________|________|________|________|________|________|________|________|________|________|____________|________|_________ + | | | | | | | | | | | | | | + | CTRL | FN | LALT | LGUI | SPACE | BACKSPACE | ESC | RALT | FN | | LEFT | DOWN | RIGHT | + |____________|________|_______|________|_________________|_________________|________|________|_____________| |________|________|________| +*/ + + [0] = LAYOUT( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_HOME, + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_PGUP, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGDN, + MO(1), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_END, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, + KC_LCTL, MO(1), KC_LALT, KC_LGUI, KC_SPC, KC_BSPC, KC_ESC, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT + ), + + /* Layer 1, function layer +__________________________________________________________________________________________________________________________________ ________ +| | | | | | | | | | | | | | || PLAY/ | +| RESET | | | | | | | | | | | | | || PAUSE | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | | | || VOLUME | +| ESC | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | DELETE || UP | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | LED | LED | LED || VOLUME | +|PRINT SCREEN| | | | | | | PGUP | HOME | PGDN | | DOWN | UP | TOGGLE || DOWN | +|____________|________|________|________|________|________|________|________|________|________|________|________|________|________||________| + | | | VOL | VOL | | | | | | | | | | | | + | | | DOWN | UP | MUTE | | LEFT | DOWN | UP | RIGHT | | | | | MUTE | + |____________|________|________|________|________|________|________|________|________|________|________|________|____________|___|________| + | | | | | | | | | | | | | | + | | | | | | | END | | | | | | PGUP | + |________________|________|________|________|________|________|________|________|________|________|________|____________|________|_________ + | | | | | | | | | | | | | | + | | | | | ENTER | DELETE | | | | | HOME | PGDN | END | + |____________|________|_______|________|_________________|_________________|________|________|_____________| |________|________|________| + +* 'RESET' resets the controller and puts the board into firmware flashing mode. If this key is hit accidentally, just unplug the board +* and plug it back in. +*/ + + [1] = LAYOUT( + QK_BOOT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_VOLU, + KC_PSCR, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_HOME, KC_PGDN, KC_TRNS, RGB_VAD, RGB_VAI, RGB_TOG, KC_VOLD, + KC_TRNS, KC_TRNS, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_TRNS, KC_TRNS, KC_TRNS, KC_MUTE, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_END, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_ENT, KC_DEL, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END + ), + + [2] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS + ), + + [3] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS + ), +}; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + return true; +} diff --git a/keyboards/system76/launch_3/keymaps/levi/keymap.c b/keyboards/system76/launch_3/keymaps/levi/keymap.c new file mode 100644 index 00000000000..f1db7f0b0cc --- /dev/null +++ b/keyboards/system76/launch_3/keymaps/levi/keymap.c @@ -0,0 +1,133 @@ +#include QMK_KEYBOARD_H + +static bool lctl_pressed, rctl_pressed, esc_pressed; +void system76_ec_unlock(void); + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + + /* Layer 0, Dvorak layer +__________________________________________________________________________________________________________________________________ ________ +| | | | | | | | | | | | | | || | +| ESC | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | DELETE || HOME | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | [ | ] | || | +| ~` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | { | } | BACKSPACE || PGUP | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | ' | , | . | | | | | | | | / | = | || | +| TAB | " | < | > | P | Y | F | G | C | R | L | ? | + | | \ || PGDN | +|____________|________|________|________|________|________|________|________|________|________|________|________|________|________||________| + | | | | | | | | | | | | - | | | | + | CTRL | A | O | E | U | I | D | H | T | N | S | _ | ENTER | | END | + |____________|________|________|________|________|________|________|________|________|________|________|________|____________|___|________| + | | : | | | | | | | | | | | | + | SHIFT | ; | Q | J | K | X | B | M | W | V | Z | SHIFT | UP | + |________________|________|________|________|________|________|________|________|________|________|________|____________|________|_________ + | | | | | | | | | | | | | | + | FN | CTRL | LALT | LGUI | SPACE | FN | RCTRL | RALT | FN | | LEFT | DOWN | RIGHT | + |____________|________|_______|________|_________________|_________________|________|________|_____________| |________|________|________| +*/ + + [0] = LAYOUT( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_HOME, + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_LBRC, KC_RBRC, KC_BSPC, KC_PGUP, + KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_SLSH, KC_EQL, KC_BSLS, KC_PGDN, + KC_LCTL, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_MINS, KC_ENT, KC_END, + KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_RSFT, KC_UP, + MO(2), KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, MO(2), KC_RCTL, KC_RALT, MO(2), KC_LEFT, KC_DOWN, KC_RIGHT + ), + +/* Layer 1, QWERTY layer +__________________________________________________________________________________________________________________________________ ________ +| | | | | | | | | | | | | | || | +| ESC | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | DELETE || HOME | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | | | || | +| ~` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | _ - | = + | BACKSPACE || PGUP | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | [ | ] | || | +| TAB | Q | W | E | R | T | Y | U | I | O | P | { | } | | \ || PGDN | +|____________|________|________|________|________|________|________|________|________|________|________|________|________|________||________| + | | | | | | | | | | | ; | ' | | | | + | CTRL | A | S | D | F | G | H | J | K | L | : | " | ENTER | | END | + |____________|________|________|________|________|________|________|________|________|________|________|________|____________|___|________| + | | | | | | | | | , | . | / | | | + | SHIFT | Z | X | C | V | B | N | M | < | > | ? | SHIFT | UP | + |________________|________|________|________|________|________|________|________|________|________|________|____________|________|_________ + | | | | | | | | | | | | | | + | FN | CTRL | LALT | LGUI | SPACE | FN | RCTRL | RALT | FN | | LEFT | DOWN | RIGHT | + |____________|________|_______|________|_________________|_________________|________|________|_____________| |________|________|________| +*/ + + [1] = LAYOUT( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_HOME, + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_PGUP, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGDN, + KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_END, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, + MO(2), KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, MO(2), KC_RCTL, KC_RALT, MO(2), KC_LEFT, KC_DOWN, KC_RIGHT + ), + + /* Layer 2, function layer +__________________________________________________________________________________________________________________________________ ________ +| | | | | | | | | | | | | | || | +| QK_BOOT| | | Insert | | | | | | | | | | || Dvorak | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | LED | LED | LED | || | +| | | | | | | | | | | TOGGLE | DOWN | UP | || Qwerty | +|________|________|________|________|________|________|________|________|________|________|________|________|________|____________||________| +| | | | | | | | | | | | | | || | +| | Home | Up | End | PgUp | | PgUp | Home | Up | End | | | | PrtScr || | +|____________|________|________|________|________|________|________|________|________|________|________|________|________|________||________| + | | | | | | | | | | | | | | | | + | | Left | Down | Right | PgDn | | PgDn | Left | Down | Right | | | | | | + |____________|________|________|________|________|________|________|________|________|________|________|________|____________|___|________| + | | | | | | | | | | | | | | + | |PlayPaus| Prev | Next | VolDn | VolUp | VolMute| | | | | | PGUP | + |________________|________|________|________|________|________|________|________|________|________|________|____________|________|_________ + | | | | | | | | | | | | | | + | | | | | Backspace | | | | | | HOME | PGDN | END | + |____________|________|_______|________|_________________|_________________|________|________|_____________| |________|________|________| + +* 'QK_BOOT' resets the controller and puts the board into firmware flashing mode. If this key is hit accidentally, just unplug the board +* and plug it back in. +*/ + + [2] = LAYOUT( + QK_BOOT, KC_TRNS, KC_TRNS, KC_INS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, TO(0), + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_TOG, RGB_VAD, RGB_VAI, KC_TRNS, TO(1), + KC_TRNS, KC_HOME, KC_UP, KC_END, KC_PGUP, KC_TRNS, KC_PGUP, KC_HOME, KC_UP, KC_END, KC_TRNS, KC_TRNS, KC_TRNS, KC_PSCR, KC_TRNS, + KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, KC_PGDN, KC_TRNS, KC_PGDN, KC_LEFT, KC_DOWN, KC_RGHT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_MPLY, KC_MPRV, KC_MNXT, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BSPC, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END + ), + + [3] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS + ), +}; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case KC_LCTL: + lctl_pressed = record->event.pressed; + break; + case KC_RCTL: + rctl_pressed = record->event.pressed; + break; + case KC_ESC: + esc_pressed = record ->event.pressed; + break; + }; + return true; +} + +void matrix_scan_user(void) { + if (lctl_pressed && rctl_pressed && esc_pressed) { + system76_ec_unlock(); + } +} diff --git a/keyboards/system76/launch_3/launch_3.c b/keyboards/system76/launch_3/launch_3.c new file mode 100644 index 00000000000..7e0504c3869 --- /dev/null +++ b/keyboards/system76/launch_3/launch_3.c @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2021 System76 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "launch_3.h" +#include "eeprom.h" +#include "usb_mux.h" + +// clang-format off +#ifdef RGB_MATRIX_ENABLE +// LEDs by index +// 0 1 2 3 4 5 6 7 8 9 +// 00 LM4 LL4 LK4 LJ4 LI4 LH4 LG4 LF4 LE4 LD4 +// 10 LC4 LB4 LA4 LA5 LB5 LC5 LD5 LE5 LG5 LH5 +// 20 LI5 LJ5 LK5 LL5 LM5 LO3 LM3 LL3 LK3 LJ3 +// 30 LI3 LH3 LG3 LF3 LE3 LD3 LC3 LB3 LA3 LA2 +// 40 LB2 LC2 LD2 LE2 LF2 LG2 LH2 LI2 LJ2 LK2 +// 50 LL2 LM2 LN2 LO2 LO1 LN1 LM1 LL1 LK1 LJ1 +// 60 LI1 LH1 LG1 LF1 LE1 LD1 LC1 LB1 LA1 LA0 +// 70 LB0 LC0 LD0 LE0 LF0 LG0 LH0 LI0 LJ0 LK0 +// 80 LL0 LM0 LN0 LO0 +led_config_t g_led_config = { { + // Key matrix to LED index +/* A B C D E F G H I J K L M N O */ +/* 0 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, */ +/* 1 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, */ +/* 2 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, */ +/* 3 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, */ +/* 4 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, */ +/* 5 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 */ + { 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82 }, + { 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55 }, + { 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52 }, + { 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 83 }, + { 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 54 }, + { 13, 14, 15, 16, 17, 25, 18, 19, 20, 21, 22, 23, 24, 53 }, +}, { + // LED index to physical position (see leds.sh in `launch' repo) +/* 00 */ {209, 51}, {190, 51}, {171, 51}, {156, 51}, {140, 51}, {125, 51}, {110, 51}, {95, 51}, {80, 51}, {65, 51}, +/* 10 */ {49, 51}, {34, 51}, {11, 51}, {8, 64}, {27, 64}, {42, 64}, {57, 64}, {80, 64}, {110, 64}, {133, 64}, +/* 20 */ {148, 64}, {167, 64}, {194, 64}, {209, 64}, {224, 64}, {224, 38}, {197, 38}, {178, 38}, {163, 38}, {148, 38}, +/* 30 */ {133, 38}, {118, 38}, {103, 38}, {87, 38}, {72, 38}, {57, 38}, {42, 38}, {27, 38}, {8, 38}, {4, 26}, +/* 40 */ {23, 26}, {38, 26}, {53, 26}, {68, 26}, {84, 26}, {99, 26}, {114, 26}, {129, 26}, {144, 26}, {159, 26}, +/* 50 */ {175, 26}, {190, 26}, {205, 26}, {224, 26}, {224, 13}, {201, 13}, {182, 13}, {167, 13}, {152, 13}, {137, 13}, +/* 60 */ {121, 13}, {106, 13}, {91, 13}, {76, 13}, {61, 13}, {46, 13}, {30, 13}, {15, 13}, {0, 13}, {0, 0}, +/* 70 */ {15, 0}, {30, 0}, {46, 0}, {61, 0}, {76, 0}, {91, 0}, {106, 0}, {121, 0}, {137, 0}, {152, 0}, +/* 80 */ {167, 0}, {182, 0}, {201, 0}, {224, 0} +}, { + // LED index to flags (set all to LED_FLAG_KEYLIGHT) + /* 0 1 2 3 4 5 6 7 8 9 */ +/* 00 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +/* 10 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +/* 20 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +/* 30 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +/* 40 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +/* 50 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +/* 60 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +/* 70 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +/* 80 */ 4, 4, 4, 4 +} }; +#endif // RGB_MATRIX_ENABLE + +bool eeprom_is_valid(void) { + return ( + eeprom_read_word(((void *)EEPROM_MAGIC_ADDR)) == EEPROM_MAGIC && + eeprom_read_byte(((void *)EEPROM_VERSION_ADDR)) == EEPROM_VERSION + ); +} +// clang-format on + +void eeprom_set_valid(bool valid) { + eeprom_update_word(((void *)EEPROM_MAGIC_ADDR), valid ? EEPROM_MAGIC : 0xFFFF); + eeprom_update_byte(((void *)EEPROM_VERSION_ADDR), valid ? EEPROM_VERSION : 0xFF); +} + +void bootmagic_lite_reset_eeprom(void) { + // Set the keyboard-specific EEPROM state as invalid + eeprom_set_valid(false); + // Set the TMK/QMK EEPROM state as invalid + eeconfig_disable(); +} + +// The lite version of TMK's bootmagic based on Wilba. +// 100% less potential for accidentally making the keyboard do stupid things. +void bootmagic_lite(void) { + // Perform multiple scans because debouncing can't be turned off. + matrix_scan(); +#if defined(DEBOUNCE) && DEBOUNCE > 0 + wait_ms(DEBOUNCE * 2); +#else + wait_ms(30); +#endif + matrix_scan(); + + // If the configured key (commonly Esc) is held down on power up, + // reset the EEPROM valid state and jump to bootloader. + uint8_t row = 0; // BOOTMAGIC_LITE_ROW; + uint8_t col = 0; // BOOTMAGIC_LITE_COLUMN; + + if (matrix_get_row(row) & (1 << col)) { + bootmagic_lite_reset_eeprom(); + + // Jump to bootloader. + bootloader_jump(); + } +} + +void system76_ec_rgb_eeprom(bool write); +void system76_ec_rgb_layer(layer_state_t layer_state); +void system76_ec_unlock(void); +bool system76_ec_is_unlocked(void); + +rgb_config_t layer_rgb[DYNAMIC_KEYMAP_LAYER_COUNT]; + +void matrix_init_kb(void) { + usb_mux_init(); + + bootmagic_lite(); + if (!eeprom_is_valid()) { + dynamic_keymap_reset(); + dynamic_keymap_macro_reset(); + system76_ec_rgb_eeprom(true); + eeprom_set_valid(true); + } else { + system76_ec_rgb_eeprom(false); + } +} + +void keyboard_post_init_user(void) { + system76_ec_rgb_layer(layer_state); +} + +void matrix_scan_kb(void) { + usb_mux_event(); + + matrix_scan_user(); +} + +#define LEVEL(value) (uint8_t)(((uint16_t)value) * ((uint16_t)RGB_MATRIX_MAXIMUM_BRIGHTNESS) / ((uint16_t)255)) + +// clang-format off +static const uint8_t levels[] = { + LEVEL(48), + LEVEL(72), + LEVEL(96), + LEVEL(144), + LEVEL(192), + LEVEL(255) +}; +// clang-format on + +static uint8_t toggle_level = RGB_MATRIX_MAXIMUM_BRIGHTNESS; +extern bool input_disabled; + +static void set_value_all_layers(uint8_t value) { + if (!system76_ec_is_unlocked()) { + for (int8_t layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) { + layer_rgb[layer].hsv.v = value; + } + system76_ec_rgb_layer(layer_state); + } +} + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + if (input_disabled) { + return false; + } + + if (!process_record_user(keycode, record)) { + return false; + } + + switch (keycode) { + case QK_BOOT: + if (record->event.pressed) { + system76_ec_unlock(); + } + return false; + case RGB_VAD: + if (record->event.pressed) { + uint8_t level = rgb_matrix_config.hsv.v; + for (int i = sizeof(levels) - 1; i >= 0; i--) { + if (levels[i] < level) { + level = levels[i]; + break; + } + } + set_value_all_layers(level); + } + return false; + case RGB_VAI: + if (record->event.pressed) { + uint8_t level = rgb_matrix_config.hsv.v; + for (int i = 0; i < sizeof(levels); i++) { + if (levels[i] > level) { + level = levels[i]; + break; + } + } + set_value_all_layers(level); + } + return false; + case RGB_TOG: + if (record->event.pressed) { + uint8_t level = 0; + if (rgb_matrix_config.hsv.v == 0) { + level = toggle_level; + } else { + toggle_level = rgb_matrix_config.hsv.v; + } + set_value_all_layers(level); + } + return false; + } + + return true; +} + +layer_state_t layer_state_set_kb(layer_state_t layer_state) { + system76_ec_rgb_layer(layer_state); + + return layer_state_set_user(layer_state); +} + +#ifdef CONSOLE_ENABLE +void keyboard_post_init_user(void) { + debug_enable = true; + debug_matrix = false; + debug_keyboard = false; +} +#endif // CONSOLE_ENABLE diff --git a/keyboards/system76/launch_3/launch_3.h b/keyboards/system76/launch_3/launch_3.h new file mode 100644 index 00000000000..335b8ecbdf1 --- /dev/null +++ b/keyboards/system76/launch_3/launch_3.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2021 System76 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "quantum.h" + +// clang-format off +#define LAYOUT( \ + K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, \ + K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \ + K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, \ + K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, \ + K40, K41, K42, K43, K44, K45, K46, K47, K48, K49, K4A, K4B, K4C, \ + K50, K51, K52, K53, K54, K55, K56, K57, K58, K59, K5A, K5B \ +) { \ + { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D }, \ + { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D }, \ + { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D }, \ + { K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K0E }, \ + { K40, K41, K42, K43, K44, K45, K46, K47, K48, K49, K4A, K4B, K4C, K1E }, \ + { K50, K51, K52, K53, K54, K3D, K55, K56, K57, K58, K59, K5A, K5B, K2E }, \ +} +// clang-format on diff --git a/keyboards/system76/launch_3/mcuconf.h b/keyboards/system76/launch_3/mcuconf.h new file mode 100644 index 00000000000..cd074149319 --- /dev/null +++ b/keyboards/system76/launch_3/mcuconf.h @@ -0,0 +1,25 @@ +/* Copyright 2023 System76 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include_next + +#undef RP_I2C_USE_I2C0 +#define RP_I2C_USE_I2C0 FALSE + +#undef RP_I2C_USE_I2C1 +#define RP_I2C_USE_I2C1 TRUE diff --git a/keyboards/system76/launch_3/readme.md b/keyboards/system76/launch_3/readme.md new file mode 100644 index 00000000000..2cb363d62f0 --- /dev/null +++ b/keyboards/system76/launch_3/readme.md @@ -0,0 +1 @@ +# System76 Launch Configurable Keyboard (launch_3) diff --git a/keyboards/system76/launch_3/rgb_matrix_kb.inc b/keyboards/system76/launch_3/rgb_matrix_kb.inc new file mode 100644 index 00000000000..02de10ed500 --- /dev/null +++ b/keyboards/system76/launch_3/rgb_matrix_kb.inc @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2021 System76 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +RGB_MATRIX_EFFECT(active_keys) +RGB_MATRIX_EFFECT(raw_rgb) +RGB_MATRIX_EFFECT(unlocked) + +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +#include "dynamic_keymap.h" + +static bool active_keys_initialized = false; +static uint8_t active_keys_table[RGB_MATRIX_LED_COUNT] = {0}; + +static void active_keys_initialize(void) { + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + uint8_t led = g_led_config.matrix_co[row][col]; + if (led < RGB_MATRIX_LED_COUNT && row < 16 && col < 16) { + active_keys_table[led] = (row << 4) | col; + } + } + } + active_keys_initialized = true; +} + +static bool active_keys(effect_params_t* params) { + if (!active_keys_initialized) { + active_keys_initialize(); + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + uint8_t layer = get_highest_layer(layer_state); + RGB rgb = hsv_to_rgb(rgb_matrix_config.hsv); + + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + + uint8_t rowcol = active_keys_table[i]; + uint8_t row = rowcol >> 4; + uint8_t col = rowcol & 0xF; + uint16_t keycode = dynamic_keymap_get_keycode(layer, row, col); + switch (keycode) { + case KC_NO: + case KC_TRNS: + rgb_matrix_set_color(i, 0, 0, 0); + break; + default: + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + break; + } + } + + return led_max < RGB_MATRIX_LED_COUNT; +} + +RGB raw_rgb_data[RGB_MATRIX_LED_COUNT] = {0}; + +static uint8_t normalize_component(uint8_t component) { + uint16_t x = (uint16_t)component; + x *= rgb_matrix_config.hsv.v; // Multiply by current brightness + x /= 255; // Divide by maximum brightness + return (uint8_t)x; +} + +static RGB normalize_index(uint8_t i) { + RGB raw = raw_rgb_data[i]; + RGB rgb = { + .r = normalize_component(raw.r), + .g = normalize_component(raw.g), + .b = normalize_component(raw.b), + }; + return rgb; +} + +static bool raw_rgb(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + RGB rgb = normalize_index(i); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < RGB_MATRIX_LED_COUNT; +} + +static uint8_t unlocked_keys[8][2] = { + {2, 7}, // U + {4, 6}, // N + {3, 9}, // L + {2, 9}, // O + {4, 3}, // C + {3, 8}, // K + {2, 3}, // E + {3, 3}, // D +}; + +static uint8_t unlocked_ticks = 0; +static uint8_t unlocked_i = 0; +static uint8_t unlocked_leds_count = 0; +static uint8_t unlocked_leds[2] = {0, 0}; + +static bool unlocked(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + unlocked_ticks++; + + if (params->init) { + unlocked_ticks = 0; + unlocked_i = 0; + } + + if (unlocked_ticks == 0) { + if (unlocked_i == 8) { + unlocked_leds_count = 0; + unlocked_i = 0; + } else { + unlocked_leds_count = rgb_matrix_map_row_column_to_led(unlocked_keys[unlocked_i][0], unlocked_keys[unlocked_i][1], unlocked_leds); + unlocked_i++; + } + } + + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + + HSV hsv = { + .h = i + unlocked_ticks, + .s = 0xFF, + .v = 0x70, + }; + for (uint8_t j = 0; j < unlocked_leds_count; j++) { + if (i == unlocked_leds[j]) { + hsv.s = 0; + hsv.v = 0xFF; + } + } + + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); + } + return led_max < RGB_MATRIX_LED_COUNT; +} + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/keyboards/system76/launch_3/rules.mk b/keyboards/system76/launch_3/rules.mk new file mode 100644 index 00000000000..7a825bc7b61 --- /dev/null +++ b/keyboards/system76/launch_3/rules.mk @@ -0,0 +1,26 @@ +# Build options +# change yes to no to disable +BOOTMAGIC_ENABLE = no # Bootmagic Lite +MOUSEKEY_ENABLE = no # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and system control +CONSOLE_ENABLE = no # Console for debug +COMMAND_ENABLE = no # Commands for debug and configuration +DYNAMIC_KEYMAP_ENABLE = yes # Reconfigurable keyboard without flashing firmware +EEPROM_DRIVER = wear_leveling +WEAR_LEVELING_DRIVER = rp2040_flash +NKRO_ENABLE = yes # USB N-key rollover +RAW_ENABLE = yes # Raw HID commands (used by Keyboard Configurator) +BACKLIGHT_ENABLE = no # RGB backlight (conflicts with RGB matrix) +RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow +RGB_MATRIX_ENABLE = yes # RGB matrix +RGB_MATRIX_DRIVER = ws2812 +WS2812_DRIVER = vendor +RGB_MATRIX_CUSTOM_KB = yes # Custom keyboard effects +AUDIO_ENABLE = no # Audio output +LTO_ENABLE = yes # Link-time optimization for smaller binary + +#VIA_ENABLE = yes + +# Add System76 EC command interface as well as I2C and USB mux drivers +SRC += system76_ec.c usb_mux.c +QUANTUM_LIB_SRC += i2c_master.c diff --git a/keyboards/system76/launch_3/usb_mux.c b/keyboards/system76/launch_3/usb_mux.c new file mode 100644 index 00000000000..7123ec77a49 --- /dev/null +++ b/keyboards/system76/launch_3/usb_mux.c @@ -0,0 +1,485 @@ +/* + * Copyright (C) 2021 System76 + * Copyright (C) 2021 Jimmy Cassis + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "usb_mux.h" + +#include + +#include "gpio.h" +#include "i2c_master.h" +#include "wait.h" + +#define GPIO_RESET_USB GP20 + +#define REG_PF1_CTL 0xBF800C04 +#define REG_PIO64_OEN 0xBF800908 +#define REG_PIO64_OUT 0xBF800928 +#define REG_VID 0xBF803000 +#define REG_PRT_SWAP 0xBF8030FA +#define REG_USB3_HUB_VID 0xBFD2E548 +#define REG_RUNTIME_FLAGS2 0xBFD23408 +#define REG_I2S_FEAT_SEL 0xBFD23412 + +struct USB7206 { + uint8_t addr; +}; + +struct USB7206 usb_hub = {.addr = 0x2D}; + +// Perform USB7206 register access. +// Returns zero on success or a negative number on error. +i2c_status_t usb7206_register_access(struct USB7206* self) { + uint8_t register_access[3] = { + 0x99, + 0x37, + 0x00, + }; + + return i2c_transmit(self->addr << 1, register_access, sizeof(register_access), I2C_TIMEOUT); +} + +// Read 32-bit value from USB7206 register region. +// Returns number of bytes read on success or a negative number on error. +i2c_status_t usb7206_read_reg_32(struct USB7206* self, uint32_t addr, uint32_t* data) { + i2c_status_t status; + + uint8_t register_read[9] = { + 0x00, // Buffer address MSB: always 0 + 0x00, // Buffer address LSB: always 0 + 0x06, // Number of bytes to write to command block buffer area + 0x01, // Direction: 0 = write, 1 = read + 4, // Number of bytes to read from register + (uint8_t)(addr >> 24), // Register address byte 3 + (uint8_t)(addr >> 16), // Register address byte 2 + (uint8_t)(addr >> 8), // Register address byte 1 + (uint8_t)(addr >> 0), // Register address byte 0 + }; + + // First byte is available length + uint8_t bytes[5] = {0, 0, 0, 0, 0}; + + status = i2c_transmit(self->addr << 1, register_read, sizeof(register_read), I2C_TIMEOUT); + if (status < 0) { + return status; + } + + status = usb7206_register_access(self); + if (status < 0) { + return status; + } + + status = i2c_readReg16( + (self->addr << 1), + 0x006, // 6 to skip header + bytes, + sizeof(bytes), + I2C_TIMEOUT + ); + if (status < 0) { + return status; + } + + //TODO: check bytes[0] length + + // Convert from little endian + *data = + (((uint32_t)bytes[1]) << 0) | + (((uint32_t)bytes[2]) << 8) | + (((uint32_t)bytes[3]) << 16) | + (((uint32_t)bytes[4]) << 24); + + return 4; +} + +// Write 8-bit value to USB7206 register region. +// Returns number of bytes written on success or a negative number on error. +i2c_status_t usb7206_write_reg_8(struct USB7206* self, uint32_t addr, uint8_t data) { + i2c_status_t status; + + uint8_t register_write[9 + 1] = { + 0x00, // Buffer address MSB: always 0 + 0x00, // Buffer address LSB: always 0 + 1 + 6, // Number of bytes to write to command block buffer area + 0x00, // Direction: 0 = write, 1 = read + 1, // Number of bytes to write to register + (uint8_t)(addr >> 24), // Register address byte 3 + (uint8_t)(addr >> 16), // Register address byte 2 + (uint8_t)(addr >> 8), // Register address byte 1 + (uint8_t)(addr >> 0), // Register address byte 0 + data + }; + + status = i2c_transmit((self->addr << 1), register_write, sizeof(register_write), I2C_TIMEOUT); + if (status < 0) { + return status; + } + + status = usb7206_register_access(self); + if (status < 0) { + return status; + } + + return 1; +} + +// Write 32-bit value to USB7206 register region. +// Returns number of bytes written on success or a negative number on error. +i2c_status_t usb7206_write_reg_32(struct USB7206* self, uint32_t addr, uint32_t data) { + i2c_status_t status; + + uint8_t register_write[9 + 4] = { + 0x00, // Buffer address MSB: always 0 + 0x00, // Buffer address LSB: always 0 + 4 + 6, // Number of bytes to write to command block buffer area + 0x00, // Direction: 0 = write, 1 = read + 4, // Number of bytes to write to register + (uint8_t)(addr >> 24), // Register address byte 3 + (uint8_t)(addr >> 16), // Register address byte 2 + (uint8_t)(addr >> 8), // Register address byte 1 + (uint8_t)(addr >> 0), // Register address byte 0 + (uint8_t)(data >> 0), + (uint8_t)(data >> 8), + (uint8_t)(data >> 16), + (uint8_t)(data >> 24), + }; + + status = i2c_transmit((self->addr << 1), register_write, sizeof(register_write), I2C_TIMEOUT); + if (status < 0) { + return status; + } + + status = usb7206_register_access(self); + if (status < 0) { + return status; + } + + return 4; +} + +// Initialize USB7206. +// Returns zero on success or a negative number on error. +int usb7206_init(struct USB7206* self) { + i2c_status_t status; + uint32_t data; + + // DM and DP are swapped on ports 2 and 3 + status = usb7206_write_reg_8(self, REG_PRT_SWAP, 0x0C); + if (status < 0) { + return status; + } + + // Disable audio + status = usb7206_write_reg_8(self, REG_I2S_FEAT_SEL, 0); + if (status < 0) { + return status; + } + + // Set HFC_DISABLE + data = 0; + status = usb7206_read_reg_32(self, REG_RUNTIME_FLAGS2, &data); + if (status < 0) { + return status; + } + data |= 1; + status = usb7206_write_reg_32(self, REG_RUNTIME_FLAGS2, data); + if (status < 0) { + return status; + } + + // Set Vendor ID and Product ID of USB 2 hub + status = usb7206_write_reg_32(self, REG_VID, 0x00033384); + if (status < 0) { + return status; + } + + // Set Vendor ID and Product ID of USB 3 hub + status = usb7206_write_reg_32(self, REG_USB3_HUB_VID, 0x00043384); + if (status < 0) { + return status; + } + + return 0; +} + +// Attach USB7206. +// Returns bytes written on success or a negative number on error. +i2c_status_t usb7206_attach(struct USB7206* self) { + uint8_t data[3] = { + 0xAA, + 0x56, + 0x00, + }; + + return i2c_transmit(self->addr << 1, data, sizeof(data), I2C_TIMEOUT); +} + +struct USB7206_GPIO { + struct USB7206* usb7206; + uint32_t pf; +}; + +struct USB7206_GPIO usb_gpio_sink = {.usb7206 = &usb_hub, .pf = 29}; // UP_SEL = PF29 = GPIO93 +struct USB7206_GPIO usb_gpio_source_left = {.usb7206 = &usb_hub, .pf = 10}; // CL_SEL = PF10 = GPIO74 +struct USB7206_GPIO usb_gpio_source_right = {.usb7206 = &usb_hub, .pf = 25}; // CR_SEL = PF25 = GPIO88 + +// Set USB7206 GPIO to specified value. +// Returns zero on success or negative number on error. +i2c_status_t usb7206_gpio_set(struct USB7206_GPIO* self, bool value) { + i2c_status_t status; + uint32_t data; + + data = 0; + status = usb7206_read_reg_32(self->usb7206, REG_PIO64_OUT, &data); + if (status < 0) { + return status; + } + + if (value) { + data |= (((uint32_t)1) << self->pf); + } else { + data &= ~(((uint32_t)1) << self->pf); + } + status = usb7206_write_reg_32(self->usb7206, REG_PIO64_OUT, data); + if (status < 0) { + return status; + } + + return 0; +} + +// Initialize USB7206 GPIO. +// Returns zero on success or a negative number on error. +i2c_status_t usb7206_gpio_init(struct USB7206_GPIO* self) { + i2c_status_t status; + uint32_t data; + + // Set programmable function to GPIO + status = usb7206_write_reg_8(self->usb7206, REG_PF1_CTL + (self->pf - 1), 0); + if (status < 0) { + return status; + } + + // Set GPIO to false by default + usb7206_gpio_set(self, false); + + // Set GPIO to output + data = 0; + status = usb7206_read_reg_32(self->usb7206, REG_PIO64_OEN, &data); + if (status < 0) { + return status; + } + + data |= (((uint32_t)1) << self->pf); + status = usb7206_write_reg_32(self->usb7206, REG_PIO64_OEN, data); + if (status < 0) { + return status; + } + + return 0; +} + +#define TCPC_CC_STATUS 0x1D +#define TCPC_ROLE_CONTROL 0x1A +#define TCPC_COMMAND 0x23 + +enum TCPC_TYPE { + TCPC_TYPE_SINK, + TCPC_TYPE_SOURCE, +}; + +struct PTN5110 { + enum TCPC_TYPE type; + uint8_t addr; + uint8_t cc; + struct USB7206_GPIO * gpio; +}; + +struct PTN5110 usb_sink = { .type = TCPC_TYPE_SINK, .addr = 0x51, .gpio = &usb_gpio_sink }; +struct PTN5110 usb_source_left = { .type = TCPC_TYPE_SOURCE, .addr = 0x52, .gpio = &usb_gpio_source_left }; +struct PTN5110 usb_source_right = { .type = TCPC_TYPE_SOURCE, .addr = 0x50, .gpio = &usb_gpio_source_right }; + +// Read PTN5110 CC_STATUS +// Returns bytes read on success or negative number on error +int ptn5110_get_cc_status(struct PTN5110 * self, uint8_t * cc) { + return i2c_readReg(self->addr << 1, TCPC_CC_STATUS, cc, 1, I2C_TIMEOUT); +} + +// Write PTN5110 ROLE_CONTROL +// Returns bytes written on success or negative number on error +int ptn5110_set_role_control(struct PTN5110 * self, uint8_t role_control) { + return i2c_writeReg(self->addr << 1, TCPC_ROLE_CONTROL, &role_control, 1, I2C_TIMEOUT); +} + +// Set PTN5110 SSMUX orientation. +// Returns zero on success or a negative number on error. +i2c_status_t ptn5110_set_ssmux(struct PTN5110* self, bool orientation) { return usb7206_gpio_set(self->gpio, orientation); } + +// Write PTN5110 COMMAND. +// Returns zero on success or negative number on error. +i2c_status_t ptn5110_command(struct PTN5110* self, uint8_t command) { return i2c_writeReg(self->addr << 1, TCPC_COMMAND, &command, 1, I2C_TIMEOUT); } + +// Set orientation of PTN5110 operating as a sink, call this once. +// Returns zero on success or a negative number on error. +i2c_status_t ptn5110_sink_set_orientation(struct PTN5110* self) { + i2c_status_t status; + uint8_t cc; + + status = ptn5110_get_cc_status(self, &cc); + if (status < 0) { + return status; + } + + if ((cc & 0x03) == 0) { + status = ptn5110_set_ssmux(self, false); + if (status < 0) { + return status; + } + } else { + status = ptn5110_set_ssmux(self, true); + if (status < 0) { + return status; + } + } + + return 0; +} + +// Update PTN5110 operating as a source, call this repeatedly. +// Returns zero on success or a negative number on error. +i2c_status_t ptn5110_source_update(struct PTN5110* self) { + i2c_status_t status; + uint8_t cc; + + status = ptn5110_get_cc_status(self, &cc); + if (status < 0) { + return status; + } + + if (cc != self->cc) { + // WARNING: Setting this here will disable retries + self->cc = cc; + + bool connected = false; + bool orientation = false; + if ((cc & 0x03) == 2) { + connected = true; + orientation = true; + } else if (((cc >> 2) & 0x03) == 2) { + connected = true; + orientation = false; + } + + if (connected) { + // Set SS mux orientation + status = ptn5110_set_ssmux(self, orientation); + if (status < 0) { + return status; + } + + // Enable source Vbus command + status = ptn5110_command(self, 0b01110111); + if (status < 0) { + return status; + } + } else { + // Disable source Vbus command + status = ptn5110_command(self, 0b01100110); + if (status < 0) { + return status; + } + } + } + + return 0; +} + +// Initialize PTN5110 +// Returns zero on success or negative number on error +int ptn5110_init(struct PTN5110 * self) { + int res; + + // Set last cc to invalid value, to force update + self->cc = 0xFF; + + // Initialize GPIO + res = usb7206_gpio_init(self->gpio); + if (res < 0) return res; + + switch (self->type) { + case TCPC_TYPE_SINK: + res = ptn5110_sink_set_orientation(self); + if (res < 0) return res; + break; + case TCPC_TYPE_SOURCE: + res = ptn5110_set_role_control(self, 0x05); + if (res < 0) return res; + break; + } + + return 0; +} + +void usb_mux_event(void) { + // Run this on every 1000th matrix scan + static int cycle = 0; + if (cycle >= 1000) { + cycle = 0; + ptn5110_source_update(&usb_source_left); + ptn5110_source_update(&usb_source_right); + } else { + cycle += 1; + } +} + +void usb_mux_init(void) { + // Put the USB hub in reset + setPinOutput(GPIO_RESET_USB); + writePinLow(GPIO_RESET_USB); + + // Run I2C bus at 100 kHz + i2c_init(); + + // Wait for power stable + wait_ms(10); + + // Take the USB hub out of reset + writePinHigh(GPIO_RESET_USB); + + // Wait for USB hub to come out of reset + wait_ms(100); + + // Set up hub + usb7206_init(&usb_hub); + + // Set up sink + ptn5110_init(&usb_sink); + + // Set up sources + ptn5110_init(&usb_source_left); + ptn5110_init(&usb_source_right); + + // Attach hub + usb7206_attach(&usb_hub); + + // Ensure orientation is correct after attaching hub + // TODO: Find reason why GPIO for sink orientation is reset + for (int i = 0; i < 100; i++) { + ptn5110_sink_set_orientation(&usb_sink); + wait_ms(10); + } +} diff --git a/keyboards/system76/launch_3/usb_mux.h b/keyboards/system76/launch_3/usb_mux.h new file mode 100644 index 00000000000..26f84de864b --- /dev/null +++ b/keyboards/system76/launch_3/usb_mux.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2021 System76 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +void usb_mux_init(void); +void usb_mux_event(void); diff --git a/keyboards/system76/system76_ec.c b/keyboards/system76/system76_ec.c index cce60a5deac..cb4bd7d60a1 100644 --- a/keyboards/system76/system76_ec.c +++ b/keyboards/system76/system76_ec.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 System76 + * Copyright (C) 2023 System76 * Copyright (C) 2021 Jimmy Cassis * * This program is free software: you can redistribute it and/or modify @@ -18,33 +18,37 @@ #include -#include "dynamic_keymap.h" -#include "raw_hid.h" -#include "rgb_matrix.h" -#include "version.h" -#include "keyboard.h" #include "eeprom.h" -#include "matrix.h" -#include "action_layer.h" -#include "bootloader.h" -#include "wait.h" +#include "quantum.h" +#include "raw_hid.h" +#include "version.h" +#ifdef DYNAMIC_KEYMAP_ENABLE +# include "dynamic_keymap.h" +#endif // DYNAMIC_KEYMAP_ENABLE + +#include "system76_ec.h" enum Command { - CMD_PROBE = 1, // Probe for System76 EC protocol - CMD_BOARD = 2, // Read board string - CMD_VERSION = 3, // Read version string - CMD_RESET = 6, // Reset to bootloader - CMD_KEYMAP_GET = 9, // Get keyboard map index - CMD_KEYMAP_SET = 10, // Set keyboard map index - CMD_LED_GET_VALUE = 11, // Get LED value by index - CMD_LED_SET_VALUE = 12, // Set LED value by index - CMD_LED_GET_COLOR = 13, // Get LED color by index - CMD_LED_SET_COLOR = 14, // Set LED color by index - CMD_LED_GET_MODE = 15, // Get LED matrix mode and speed - CMD_LED_SET_MODE = 16, // Set LED matrix mode and speed - CMD_MATRIX_GET = 17, // Get currently pressed keys - CMD_LED_SAVE = 18, // Save LED settings to ROM - CMD_SET_NO_INPUT = 19, // Enable/disable no input mode + CMD_PROBE = 1, // Probe for System76 EC protocol + CMD_BOARD = 2, // Read board string + CMD_VERSION = 3, // Read version string + CMD_RESET = 6, // Reset to bootloader + CMD_FAN_GET = 7, // Get fan speeds + CMD_FAN_SET = 8, // Set fan speeds + CMD_KEYMAP_GET = 9, // Get keyboard map index + CMD_KEYMAP_SET = 10, // Set keyboard map index + CMD_LED_GET_VALUE = 11, // Get LED value by index + CMD_LED_SET_VALUE = 12, // Set LED value by index + CMD_LED_GET_COLOR = 13, // Get LED color by index + CMD_LED_SET_COLOR = 14, // Set LED color by index + CMD_LED_GET_MODE = 15, // Get LED matrix mode and speed + CMD_LED_SET_MODE = 16, // Set LED matrix mode and speed + CMD_MATRIX_GET = 17, // Get currently pressed keys + CMD_LED_SAVE = 18, // Save LED settings to ROM + CMD_SET_NO_INPUT = 19, // Enable/disable no input mode + CMD_SECURITY_GET = 20, // Get security state + CMD_SECURITY_SET = 21, // Set security state + CMD_FAN_TACH = 22, // Get fan tachometer }; bool input_disabled = false; @@ -52,6 +56,7 @@ bool input_disabled = false; #define CMD_LED_INDEX_ALL 0xFF static bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *value) { +#ifdef DYNAMIC_KEYMAP_ENABLE if (layer < dynamic_keymap_get_layer_count()) { if (output < MATRIX_ROWS) { if (input < MATRIX_COLS) { @@ -60,10 +65,12 @@ static bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *v } } } +#endif // DYNAMIC_KEYMAP_ENABLE return false; } static bool keymap_set(uint8_t layer, uint8_t output, uint8_t input, uint16_t value) { +#ifdef DYNAMIC_KEYMAP_ENABLE if (layer < dynamic_keymap_get_layer_count()) { if (output < MATRIX_ROWS) { if (input < MATRIX_COLS) { @@ -72,6 +79,7 @@ static bool keymap_set(uint8_t layer, uint8_t output, uint8_t input, uint16_t va } } } +#endif // DYNAMIC_KEYMAP_ENABLE return false; } @@ -82,18 +90,46 @@ void system76_ec_unlock(void) { #ifdef RGB_MATRIX_CUSTOM_KB rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_unlocked); #endif -#ifdef SYSTEM76_EC bootloader_unlocked = true; -#endif } -bool system76_ec_is_unlocked(void) { return bootloader_unlocked; } +bool system76_ec_is_unlocked(void) { + return bootloader_unlocked; +} + +__attribute__((weak)) bool system76_ec_fan_get(uint8_t index, uint8_t *duty) { + return false; +} + +__attribute__((weak)) bool system76_ec_fan_set(uint8_t index, uint8_t duty) { + return false; +} + +__attribute__((weak)) bool system76_ec_fan_tach(uint8_t index, uint16_t *tach) { + return false; +} + +__attribute__((weak)) bool system76_ec_led_get_mode(uint8_t layer, uint8_t *mode, uint8_t *speed) { + return false; +} + +__attribute__((weak)) bool system76_ec_led_set_mode(uint8_t layer, uint8_t mode, uint8_t speed) { + return false; +} + +__attribute__((weak)) bool system76_ec_security_get(enum SecurityState *security_state) { + return false; +} + +__attribute__((weak)) bool system76_ec_security_set(enum SecurityState security_state) { + return false; +} #ifdef RGB_MATRIX_CUSTOM_KB enum Mode { MODE_SOLID_COLOR = 0, MODE_PER_KEY, - #ifndef DISABLE_RGB_MATRIX_ANIMATIONS +# ifndef DISABLE_RGB_MATRIX_ANIMATIONS MODE_CYCLE_ALL, MODE_CYCLE_LEFT_RIGHT, MODE_CYCLE_UP_DOWN, @@ -105,7 +141,7 @@ enum Mode { MODE_RAINDROPS, MODE_SPLASH, MODE_MULTISPLASH, - #endif // DISABLE_RGB_MATRIX_ANIMATIONS +# endif // DISABLE_RGB_MATRIX_ANIMATIONS MODE_ACTIVE_KEYS, MODE_DISABLED, MODE_LAST, @@ -135,7 +171,7 @@ static enum rgb_matrix_effects mode_map[] = { _Static_assert(sizeof(mode_map) == MODE_LAST, "mode_map_length"); -rgb_t raw_rgb_data[RGB_MATRIX_LED_COUNT]; +RGB raw_rgb_data[RGB_MATRIX_LED_COUNT]; // clang-format off rgb_config_t layer_rgb[DYNAMIC_KEYMAP_LAYER_COUNT] = { @@ -191,9 +227,9 @@ rgb_config_t layer_rgb[DYNAMIC_KEYMAP_LAYER_COUNT] = { // clang-format on // Read or write EEPROM data with checks for being inside System76 EC region. -static bool system76_ec_eeprom_op(void *buf, uint16_t size, uint16_t offset, bool write) { - uint16_t addr = SYSTEM76_EC_EEPROM_ADDR + offset; - uint16_t end = addr + size; +static bool system76_ec_eeprom_op(void *buf, size_t size, size_t offset, bool write) { + size_t addr = SYSTEM76_EC_EEPROM_ADDR + offset; + size_t end = addr + size; // Check for overflow and zero size if ((end > addr) && (addr >= SYSTEM76_EC_EEPROM_ADDR) && (end <= (SYSTEM76_EC_EEPROM_ADDR + SYSTEM76_EC_EEPROM_SIZE))) { if (write) { @@ -223,7 +259,7 @@ void system76_ec_rgb_layer(layer_state_t layer_state) { } } } -#endif // RGB_MATRIX_CUSTOM_KB +#endif // RGB_MATRIX_CUSTOM_KB void raw_hid_receive(uint8_t *data, uint8_t length) { // Error response by default, set to success by commands @@ -248,10 +284,20 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { break; case CMD_RESET: if (bootloader_unlocked) { - data[1] = 0; + data[1] = 0; bootloader_reset = true; } break; + case CMD_FAN_GET: + if (system76_ec_fan_get(data[2], &data[3])) { + data[1] = 0; + } + break; + case CMD_FAN_SET: + if (system76_ec_fan_set(data[2], data[3])) { + data[1] = 0; + } + break; case CMD_KEYMAP_GET: { uint16_t value = 0; if (keymap_get(data[2], data[3], data[4], &value)) { @@ -290,7 +336,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { for (uint8_t layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) { if (index == (0xF0 | layer)) { layer_rgb[layer].hsv.v = value; - data[1] = 0; + data[1] = 0; system76_ec_rgb_layer(layer_state); break; } @@ -322,7 +368,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { if (!bootloader_unlocked) { uint8_t index = data[2]; - rgb_t rgb = { + RGB rgb = { .r = data[3], .g = data[4], .b = data[5], @@ -330,7 +376,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { if (index < RGB_MATRIX_LED_COUNT) { raw_rgb_data[index] = rgb; - data[1] = 0; + data[1] = 0; } else { for (uint8_t layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) { if (index == (0xF0 | layer)) { @@ -369,7 +415,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && mode < MODE_LAST) { layer_rgb[layer].mode = mode_map[mode]; layer_rgb[layer].speed = speed; - data[1] = 0; + data[1] = 0; system76_ec_rgb_layer(layer_state); } } @@ -380,7 +426,18 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { data[1] = 0; } break; -#endif // RGB_MATRIX_CUSTOM_KB +#else // RGB_MATRIX_CUSTOM_KB + case CMD_LED_GET_MODE: + if (system76_ec_led_get_mode(data[2], &data[3], &data[4])) { + data[1] = 0; + } + break; + case CMD_LED_SET_MODE: + if (system76_ec_led_set_mode(data[2], data[3], data[4])) { + data[1] = 0; + } + break; +#endif // RGB_MATRIX_CUSTOM_KB case CMD_MATRIX_GET: { // TODO: Improve performance? data[2] = matrix_rows(); @@ -411,8 +468,26 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { case CMD_SET_NO_INPUT: { clear_keyboard(); input_disabled = data[2] != 0; - data[1] = 0; + data[1] = 0; } break; + case CMD_FAN_TACH: { + uint16_t tach = 0; + if (system76_ec_fan_tach(data[2], &tach)) { + data[3] = (uint8_t)tach; + data[4] = (uint8_t)(tach >> 8); + data[1] = 0; + } + } break; + case CMD_SECURITY_GET: + if (system76_ec_security_get(&data[2])) { + data[1] = 0; + } + break; + case CMD_SECURITY_SET: + if (system76_ec_security_set(data[2])) { + data[1] = 0; + } + break; } raw_hid_send(data, length); diff --git a/keyboards/system76/system76_ec.h b/keyboards/system76/system76_ec.h new file mode 100644 index 00000000000..fa6390a2d1b --- /dev/null +++ b/keyboards/system76/system76_ec.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2023 System76 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +enum SecurityState { + // Default value, flashing is prevented, cannot be set with CMD_SECURITY_SET + SECURITY_STATE_LOCK = 0, + // Flashing is allowed, cannot be set with CMD_SECURITY_SET + SECURITY_STATE_UNLOCK = 1, + // Flashing will be prevented on the next reboot + SECURITY_STATE_PREPARE_LOCK = 2, + // Flashing will be allowed on the next reboot + SECURITY_STATE_PREPARE_UNLOCK = 3, +}; + +extern bool input_disabled; + +void system76_ec_unlock(void); +bool system76_ec_is_unlocked(void); + +bool system76_ec_fan_get(uint8_t index, uint8_t * duty); +bool system76_ec_fan_set(uint8_t index, uint8_t duty); +bool system76_ec_fan_tach(uint8_t index, uint16_t * tach); + +bool system76_ec_led_get_mode(uint8_t layer, uint8_t * mode, uint8_t * speed); +bool system76_ec_led_set_mode(uint8_t layer, uint8_t mode, uint8_t speed); + +bool system76_ec_security_get(enum SecurityState * state); +bool system76_ec_security_set(enum SecurityState state); \ No newline at end of file