Skip to content

Commit

Permalink
add personal 3w6 & cantor keymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
qysp committed Jan 20, 2024
1 parent c8dcd92 commit 52a6e11
Show file tree
Hide file tree
Showing 9 changed files with 481 additions and 1 deletion.
22 changes: 22 additions & 0 deletions keyboards/3w6/rev2/keymaps/qysp/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright 2021 weteor
*
* 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 <http://www.gnu.org/licenses/>.
*/

#pragma once

#define PIMORONI_TRACKBALL_INVERT_Y
#define PIMORONI_TRACKBALL_ROTATE

#define BOTH_SHIFTS_TURNS_ON_CAPS_WORD
147 changes: 147 additions & 0 deletions keyboards/3w6/rev2/keymaps/qysp/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
Copyright 2021 weteor
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 <http://www.gnu.org/licenses/>.
*/

#include QMK_KEYBOARD_H
#include "pimoroni_trackball.h"

enum layers
{
_ALPHA_QWERTY = 0,
_ALPHA_QWERTY_HRM,
_ALPHA_COLEMAK_DH,
_SYM,
_NAV,
_NUM,
_WM,
_MISC,
};

enum custom_keycodes
{
BALL_SCR = SAFE_RANGE,
COPY,
PASTE,
};

#define DF_QWRTHRM DF(_ALPHA_QWERTY_HRM)
#define DF_QWRT DF(_ALPHA_QWERTY)
#define DF_CLMK DF(_ALPHA_COLEMAK_DH)

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_ALPHA_QWERTY] = LAYOUT(
KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LSFT_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, RSFT_T(KC_SLSH),
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LCTL_T(KC_LGUI), LT(_NAV, KC_TAB), LT(_NUM, KC_SPC), LALT_T(KC_ENT), LT(_SYM, KC_BSPC), XXXXXXX
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
),
[_ALPHA_QWERTY_HRM] = LAYOUT(
KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LGUI_T(KC_A), LALT_T(KC_S), LCTL_T(KC_D), LSFT_T(KC_F), KC_G, KC_H, RSFT_T(KC_J), RCTL_T(KC_K), LALT_T(KC_L), RGUI_T(KC_SCLN),
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
RALT_T(KC_ESC), LT(_NAV, KC_TAB), LT(_NUM, KC_SPC), KC_ENT, LT(_SYM, KC_BSPC), XXXXXXX
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
),
[_ALPHA_COLEMAK_DH] = LAYOUT(
KC_Q, KC_W, KC_F, KC_P, KC_B, KC_J, KC_L, KC_U, KC_Y, KC_SCLN,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LGUI_T(KC_A), LALT_T(KC_R), LCTL_T(KC_S), LSFT_T(KC_T), KC_G, KC_M, RSFT_T(KC_N), RCTL_T(KC_E), LALT_T(KC_I), RGUI_T(KC_O),
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
KC_Z, KC_X, KC_C, KC_D, KC_V, KC_K, KC_H, KC_COMM, KC_DOT, KC_SLSH,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
RALT_T(KC_ESC), LT(_NAV, KC_TAB), LT(_NUM, KC_SPC), KC_ENT, LT(_SYM, KC_BSPC), XXXXXXX
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
),
[_SYM] = LAYOUT(
KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, XXXXXXX, KC_GRV,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
KC_SLSH, KC_LBRC, KC_LCBR, SC_LSPO, KC_EQL, KC_MINS, SC_RSPC, KC_RCBR, KC_RBRC, KC_QUOT,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, OSM(MOD_RALT), XXXXXXX, XXXXXXX, KC_BSLS,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
KC_ESC, LM(_WM, MOD_LGUI), LCTL(KC_SPC), XXXXXXX, XXXXXXX, XXXXXXX
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
),
[_NAV] = LAYOUT(
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_HOME, KC_END, KC_PGDN, KC_PGUP,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BALL_SCR, KC_LALT, KC_LCTL, KC_LSFT, XXXXXXX, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, XXXXXXX,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, COPY, PASTE, XXXXXXX, XXXXXXX,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XXXXXXX, XXXXXXX, XXXXXXX, KC_DEL, MO(_MISC), XXXXXXX
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
),
[_NUM] = LAYOUT(
KC_NUM, KC_F9, KC_F10, KC_F11, KC_F12, KC_PPLS, KC_P7, KC_P8, KC_P9, KC_PSLS,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XXXXXXX, KC_F5, KC_F6, KC_F7, KC_F8, KC_P0, KC_P4, KC_P5, KC_P6, KC_PDOT,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XXXXXXX, KC_F1, KC_F2, KC_F3, KC_F4, KC_PMNS, KC_P1, KC_P2, KC_P3, KC_PAST,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XXXXXXX, XXXXXXX, XXXXXXX, KC_PEQL, KC_PENT, XXXXXXX
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
),
[_WM] = LAYOUT(
KC_Q, RGUI(KC_7), RGUI(KC_8), RGUI(KC_9), KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
KC_A, RGUI(KC_4), RGUI(KC_5), RGUI(KC_6), KC_ENTER, KC_H, KC_J, KC_K, KC_L, XXXXXXX,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
KC_LSFT, RGUI(KC_1), RGUI(KC_2), RGUI(KC_3), KC_B, KC_N, KC_M, XXXXXXX, XXXXXXX, KC_RSFT,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
),
[_MISC] = LAYOUT(
XXXXXXX, KC_VOLD, KC_MUTE, KC_VOLU, XXXXXXX, XXXXXXX, XXXXXXX, DF_QWRTHRM, DF_QWRT, DF_CLMK,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
KC_MPRV, KC_MPLY, KC_MSTP, KC_MNXT, XXXXXXX, XXXXXXX, KC_BTN1, KC_BTN2, XXXXXXX, XXXXXXX,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
),
};


bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case BALL_SCR:
if(record->event.pressed)
trackball_set_scrolling(true);
else
trackball_set_scrolling(false);
break;
case COPY:
if (record->event.pressed)
SEND_STRING(SS_LCTL("c"));
break;
case PASTE:
if (record->event.pressed)
SEND_STRING(SS_LCTL("v"));
break;
}

return true;
}
177 changes: 177 additions & 0 deletions keyboards/3w6/rev2/keymaps/qysp/pimoroni_trackball.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "pimoroni_trackball.h"
#include "i2c_master.h"

static uint8_t scrolling = 0;
static int16_t x_offset = 0;
static int16_t y_offset = 0;
static int16_t h_offset = 0;
static int16_t v_offset = 0;
static float precisionSpeed = 1;

static uint16_t i2c_timeout_timer;

#ifndef I2C_TIMEOUT
# define I2C_TIMEOUT 100
#endif
#ifndef I2C_WAITCHECK
# define I2C_WAITCHECK 1000
#endif
#ifndef MOUSE_DEBOUNCE
# define MOUSE_DEBOUNCE 5
#endif

void trackball_set_rgbw(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) {
uint8_t data[] = {0x00, red, green, blue, white};
i2c_transmit(TRACKBALL_WRITE, data, sizeof(data), I2C_TIMEOUT);
}

int16_t mouse_offset(uint8_t positive, uint8_t negative, int16_t scale) {
int16_t offset = (int16_t)positive - (int16_t)negative;
int16_t magnitude = (int16_t)(scale * offset * offset * precisionSpeed);
return offset < 0 ? -magnitude : magnitude;
}

void update_member(int8_t* member, int16_t* offset) {
if (*offset > XY_REPORT_MAX) {
*member = XY_REPORT_MAX;
*offset -= XY_REPORT_MAX;
} else if (*offset < XY_REPORT_MIN) {
*member = XY_REPORT_MIN;
*offset += XY_REPORT_MAX;
} else {
*member = *offset;
*offset = 0;
}
}

__attribute__((weak)) void trackball_check_click(bool pressed, report_mouse_t* mouse) {
if (pressed) {
mouse->buttons |= MOUSE_BTN1;
} else {
mouse->buttons &= ~MOUSE_BTN1;
}
}

bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
if (true) {
xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
}


if (!process_record_user(keycode, record)) { return false; }

/* If Mousekeys is disabled, then use handle the mouse button
* keycodes. This makes things simpler, and allows usage of
* the keycodes in a consistent manner. But only do this if
* Mousekeys is not enable, so it's not handled twice.
*/
#ifndef MOUSEKEY_ENABLE
if (IS_MOUSEKEY_BUTTON(keycode)) {
report_mouse_t currentReport = pointing_device_get_report();
if (record->event.pressed) {
currentReport.buttons |= 1 << (keycode - KC_MS_BTN1);
} else {
currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1));
}
pointing_device_set_report(currentReport);
pointing_device_send();
}
#endif

return true;
}

void trackball_register_button(bool pressed, enum mouse_buttons button) {
report_mouse_t currentReport = pointing_device_get_report();
if (pressed) {
currentReport.buttons |= button;
} else {
currentReport.buttons &= ~button;
}
pointing_device_set_report(currentReport);
}

float trackball_get_precision(void) { return precisionSpeed; }
void trackball_set_precision(float precision) { precisionSpeed = precision; }
bool trackball_is_scrolling(void) { return scrolling; }
void trackball_set_scrolling(bool scroll) { scrolling = scroll; }


__attribute__((weak)) void pointing_device_init(void) { trackball_set_rgbw(0x80, 0x00, 0x00, 0x00); }

bool pointing_device_task(void) {
static bool debounce;
static uint16_t debounce_timer;
uint8_t state[5] = {};
if (timer_elapsed(i2c_timeout_timer) > I2C_WAITCHECK) {
if (i2c_readReg(TRACKBALL_WRITE, 0x04, state, 5, I2C_TIMEOUT) == I2C_STATUS_SUCCESS) {
if (!state[4] && !debounce) {
if (scrolling) {
#ifdef PIMORONI_TRACKBALL_INVERT_X
h_offset += mouse_offset(state[2], state[3], 1);
#else
h_offset -= mouse_offset(state[2], state[3], 1);
#endif
#ifdef PIMORONI_TRACKBALL_INVERT_Y
v_offset += mouse_offset(state[1], state[0], 1);
#else
v_offset -= mouse_offset(state[1], state[0], 1);
#endif
} else {
#ifdef PIMORONI_TRACKBALL_INVERT_X
x_offset -= mouse_offset(state[2], state[3], 5);
#else
x_offset += mouse_offset(state[2], state[3], 5);
#endif
#ifdef PIMORONI_TRACKBALL_INVERT_Y
y_offset -= mouse_offset(state[1], state[0], 5);
#else
y_offset += mouse_offset(state[1], state[0], 5);
#endif
}
} else {
if (state[4]) {
debounce = true;
debounce_timer = timer_read();
}
}
} else {
i2c_timeout_timer = timer_read();
}
}

if (timer_elapsed(debounce_timer) > MOUSE_DEBOUNCE) debounce = false;

report_mouse_t mouse = pointing_device_get_report();
// trackball_check_click(state[4] & (1 << 7), &mouse);

#ifndef PIMORONI_TRACKBALL_ROTATE
update_member(&mouse.x, &x_offset);
update_member(&mouse.y, &y_offset);
update_member(&mouse.h, &h_offset);
update_member(&mouse.v, &v_offset);
#else
update_member(&mouse.x, &y_offset);
update_member(&mouse.y, &x_offset);
update_member(&mouse.h, &v_offset);
update_member(&mouse.v, &h_offset);
#endif
pointing_device_set_report(mouse);
return pointing_device_send();
}
Loading

0 comments on commit 52a6e11

Please sign in to comment.