Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

launch_2 #27

Merged
merged 10 commits into from
Sep 7, 2022
62 changes: 47 additions & 15 deletions keyboards/system76/launch_1/usb_mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,29 +279,36 @@ int usb7206_gpio_init(struct USB7206_GPIO * self) {
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 = { .addr = 0x51, .gpio = &usb_gpio_sink };
struct PTN5110 usb_source_left = { .addr = 0x52, .gpio = &usb_gpio_source_left };
struct PTN5110 usb_source_right = { .addr = 0x50, .gpio = &usb_gpio_source_right };

// Initialize PTN5110
// Returns zero on success or negative number on error
int ptn5110_init(struct PTN5110 * self) {
// Set last cc to invalid value, to force update
self->cc = 0xFF;
// Initialize GPIO
return usb7206_gpio_init(self->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_get(self->addr, 0x1D, cc, 1);
return i2c_get(self->addr, TCPC_CC_STATUS, cc, 1);
}

// 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_set(self->addr, TCPC_ROLE_CONTROL, &role_control, 1);
}

// Set PTN5110 SSMUX orientation
Expand All @@ -313,7 +320,7 @@ int ptn5110_set_ssmux(struct PTN5110 * self, bool orientation) {
// Write PTN5110 COMMAND
// Returns bytes written on success or negative number on error
int ptn5110_command(struct PTN5110 * self, uint8_t command) {
return i2c_set(self->addr, 0x23, &command, 1);
return i2c_set(self->addr, TCPC_COMMAND, &command, 1);
}

// Set orientation of PTN5110 operating as a sink, call this once
Expand Down Expand Up @@ -377,6 +384,32 @@ int ptn5110_source_update(struct PTN5110 * self) {
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;
Expand All @@ -398,7 +431,6 @@ void usb_mux_init(void) {

// Set up sink
ptn5110_init(&usb_sink);
ptn5110_sink_set_orientation(&usb_sink);

// Set up sources
ptn5110_init(&usb_source_left);
Expand Down
40 changes: 40 additions & 0 deletions keyboards/system76/launch_2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Flashing firmware:
* Clone this repository and `cd` into the `qmk_firmware` directory.
* After cloning, you probably need to run `make git-submodule` as well as `./util/qmk_install`.
- You may also need to install dependencies: `sudo apt install avrdude gcc-avr avr-libc`
* To build the firmware without flashing the keyboard, use `make (keyboard name):(layout name)`
- For example, if you want to build the `default` layout for the Launch keyboard, run:
```
make system76/launch_2:default
```
* To flash the firmware, you'll use the same build command, but with `dfu` added to the end:
```
make system76/launch_2:default:dfu
```
- After it builds, you will see a repeating message that says:
```
dfu-programmer: no device present.
ERROR: Bootloader not found. Trying again in 5s.
```
Next, unplug your keyboard from your computer, hold the ESC key (while the keyboard is unplugged), and plug the keyboard back in while holding the ESC key. Once the keyboard is plugged in, the ESC key can be released.
* Note: on some distros, dfu-programmer has trouble detecting the keyboard unless you run the `make` command with `sudo`.
* To flash the firmware using ISP, you will need a USBasp device, and a tag connect cable.
- Build the firmware and bootloader with:
```
make system76/launch_2:default:production
```
- Run avrdude to flash the fuses:
```
avrdude -c usbasp -p at90usb646 -U lfuse:w:0x5E:m -U hfuse:w:0xDB:m -U efuse:w:0xFB:m -U lock:w:0xFF:m
```
- Run avrdude to flash the ROM:
```
avrdude -c usbasp -p at90usb646 -U flash:w:system76_launch_2_default_production.hex
```

## Making your own layout:
If you want to create your own layout, go to the `keymaps` directory and copy one of the maps in there. It will likely be easiest to start with the default layout, but the other layouts in there may be helpful references. The name of the directory you create will be the name of your layout. To prevent build errors, it is recommended to use only lowercase letters, underscores, and numbers for the name of your layout.

Inside of each layout directory, there is a file called `keymap.c`. The commented out grid area in this file is a visual reference for the actual key assignments below it. When modifying a layout, modifying this visual reference first makes it easier to design a layout, as well as keeping the actual layout below it organized.

Once your layout is designed, change the keycodes below to match your design. A full list of available keycodes can be found in the [QMK docs](https://beta.docs.qmk.fm/reference/keycodes). Use the shorter keycode alias to help keep these lined up (e.g. use `KC_ESC` instead of `KC_ESCAPE`).
94 changes: 94 additions & 0 deletions keyboards/system76/launch_2/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#ifndef CONFIG_H
#define CONFIG_H

#include "config_common.h"

/* USB Device descriptor parameter */
#define VENDOR_ID 0x3384
#define PRODUCT_ID 0x0006
#define DEVICE_VER 0x0001
#define MANUFACTURER System76
#define PRODUCT Launch Configurable Keyboard (launch_2)
#define DESCRIPTION Launch Configurable Keyboard (launch_2)

/* key matrix size */
#define MATRIX_ROWS 6
#define MATRIX_COLS 14

/* key matrix pins */
#define MATRIX_ROW_PINS { F0, F1, F2, F3, F4, F5 }
#define MATRIX_COL_PINS { C6, C5, C4, C3, C2, C1, C7, A7, A6, A5, A4, E6, C0, E7 }
#define UNUSED_PINS

/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW

/* Set 0 if debouncing isn't needed */
#define DEBOUNCE 5

// NKRO must be used
#define FORCE_NKRO

#if RGBLIGHT_ENABLE
#define RGB_DI_PIN F7
#define RGBLED_NUM 70
#define RGBLIGHT_ANIMATIONS
// Limit brightness to support USB-A at 0.5A
//TODO: do this dynamically based on power source
#define RGBLIGHT_LIMIT_VAL 176
#endif

#if RGB_MATRIX_ENABLE
#define RGB_DI_PIN F7
#define DRIVER_LED_TOTAL 84
#define RGB_MATRIX_KEYPRESSES // reacts to keypresses
//#define RGB_MATRIX_KEYRELEASES // reacts to keyreleases (instead of keypresses)
//#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
#define RGB_DISABLE_TIMEOUT 0 // number of milliseconds to wait until rgb automatically turns off
#define RGB_DISABLE_AFTER_TIMEOUT 0 // OBSOLETE: number of ticks to wait until disabling effects
#define RGB_DISABLE_WHEN_USB_SUSPENDED true // turn off effects when suspended
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 176 // limits maximum brightness of LEDs to 200 out of 255. If not defined maximum brightness is set to 255
#define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_RAINBOW_MOVING_CHEVRON // Sets the default mode, if none has been set
#define RGB_MATRIX_STARTUP_HUE 142 // 200 degrees
#define RGB_MATRIX_STARTUP_SAT 255
#define RGB_MATRIX_STARTUP_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS
#define RGB_MATRIX_STARTUP_SPD 127
#define RGB_MATRIX_DISABLE_KEYCODES // disables control of rgb matrix by keycodes (must use code functions to control the feature)
#endif

/* 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

// 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 keyboard support {
#define DYNAMIC_KEYMAP_LAYER_COUNT 4
// Dynamic keymap starts after EEPROM version
#define DYNAMIC_KEYMAP_EEPROM_ADDR (EEPROM_VERSION_ADDR + 1)
#define DYNAMIC_KEYMAP_EEPROM_SIZE (DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2)
// Dynamic macro starts after dynamic keymaps, it is disabled
#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_EEPROM_ADDR + DYNAMIC_KEYMAP_EEPROM_SIZE)
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE 0
#define DYNAMIC_KEYMAP_MACRO_COUNT 0
// } Dynamic keyboard support

// 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

#endif // CONFIG_H
Loading