Skip to content

Commit

Permalink
Merge pull request qmk#15 from sekigon-gonnoc/yushakobo-quick-paint-o…
Browse files Browse the repository at this point in the history
…fficial

Add yushakobo/quick_paint
  • Loading branch information
MakotoKurauchi authored Sep 4, 2022
2 parents 2888085 + dc086cc commit 4f8cf6b
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 0 deletions.
32 changes: 32 additions & 0 deletions keyboards/yushakobo/quick_paint/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2022 yushakobo (@yushakobo)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET
#define RP2040_BOOTLOADER_DOUBLE_TAP_RESET_TIMEOUT 500U

#define WS2812_PIO_USE_PIO1

// map encoder to matrix (col, row)
#define ENCODERS_CCW_KEY { { 4, 1 } }
#define ENCODERS_CW_KEY { { 4, 2 } }


#define LAYER_STATE_32BIT

/*
* Feature disable options
* These options are also useful to firmware size reduction.
*/

/* disable debug print */
//#define NO_DEBUG

/* disable print */
//#define NO_PRINT

/* disable action features */
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT
69 changes: 69 additions & 0 deletions keyboards/yushakobo/quick_paint/encoder_action.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Copyright 2020 Neil Brian Ramirez
* Copyright 2021 monksoffunk
* Copyright 2022 sekigon-gonnoc
*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "encoder_action.h"

static uint8_t encoder_state[NUM_ENCODERS] = {0};
static keypos_t encoder_cw[NUM_ENCODERS] = ENCODERS_CW_KEY;
static keypos_t encoder_ccw[NUM_ENCODERS] = ENCODERS_CCW_KEY;
bool is_encoder_action = false;

void encoder_action_unregister(uint8_t *locklayer) {
bool layerlocked = false;
for (int index = 0; index < NUM_ENCODERS; ++index) {
if (encoder_state[index]) {
if ((get_highest_layer(layer_state) == 0) &&
(locklayer[index] > 0)) {
layer_on(locklayer[index]);
layerlocked = true;
}
keyevent_t encoder_event = (keyevent_t){
.key = encoder_state[index] >> 1 ? encoder_cw[index]
: encoder_ccw[index],
.pressed = false,
.time = (timer_read() | 1)};
encoder_state[index] = 0;
is_encoder_action = true;
action_exec(encoder_event);
is_encoder_action = false;
if (layerlocked) {
layer_off(locklayer[index]);
}
}
}
}

void encoder_action_register(uint8_t index, bool clockwise,
uint8_t *locklayer) {
bool layerlocked = false;
if ((get_highest_layer(layer_state) == 0) && (locklayer[index] > 0)) {
layer_on(locklayer[index]);
layerlocked = true;
}
keyevent_t encoder_event =
(keyevent_t){.key = clockwise ? encoder_cw[index] : encoder_ccw[index],
.pressed = true,
.time = (timer_read() | 1)};
encoder_state[index] = (clockwise ^ 1) | (clockwise << 1);
is_encoder_action = true;
action_exec(encoder_event);
is_encoder_action = false;
if (layerlocked) {
layer_off(locklayer[index]);
}
}
22 changes: 22 additions & 0 deletions keyboards/yushakobo/quick_paint/encoder_action.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright 2020 Neil Brian Ramirez
* Copyright 2021 monksoffunk
*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "quantum.h"

void encoder_action_unregister(uint8_t *locklayer);

void encoder_action_register(uint8_t index, bool clockwise, uint8_t *locklayer);
70 changes: 70 additions & 0 deletions keyboards/yushakobo/quick_paint/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"manufacturer": "yushakobo",
"keyboard_name": "Quick Paint",
"maintainer": "yushakobo",
"bootloader": "rp2040",
"features": {
"bootmagic": true,
"command": false,
"console": false,
"extrakey": true,
"mousekey": true,
"nkro": true,
"encoder": true,
"rgblight": true,
"via": true
},
"matrix_pins": {
"direct":[
[28, 27, 26, 25, 11],
[24, 23, 22, 21, null],
[20, 19, 18, 17, null]
]
},
"processor": "RP2040",
"rgblight": {
"led_count": 12,
"pin": 29,
"animations": {
"all": true
}
},
"encoder": {
"rotary": [
{
"pin_a": "GP12",
"pin_b": "GP13"
}
]
},
"dynamic_keymap": {
"layer_count": 32
},
"url": "",
"usb": {
"device_version": "1.0.0",
"pid": "0x0009",
"vid": "0x3265"
},
"layouts": {
"LAYOUT": {
"layout": [
{ "matrix": [0, 0], "x": 0, "y": 0 },
{ "matrix": [0, 1], "x": 1, "y": 0 },
{ "matrix": [0, 2], "x": 2, "y": 0 },
{ "matrix": [0, 3], "x": 3, "y": 0 },
{ "matrix": [0, 4], "x": 4, "y": 0 },
{ "matrix": [1, 0], "x": 0, "y": 1 },
{ "matrix": [1, 1], "x": 1, "y": 1 },
{ "matrix": [1, 2], "x": 2, "y": 1 },
{ "matrix": [1, 3], "x": 3, "y": 1 },
{ "matrix": [1, 4], "x": 4, "y": 1 },
{ "matrix": [2, 0], "x": 0, "y": 2 },
{ "matrix": [2, 1], "x": 1, "y": 2 },
{ "matrix": [2, 2], "x": 2, "y": 2 },
{ "matrix": [2, 3], "x": 3, "y": 2 },
{ "matrix": [2, 4], "x": 4, "y": 2 }
]
}
}
}
10 changes: 10 additions & 0 deletions keyboards/yushakobo/quick_paint/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include QMK_KEYBOARD_H

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
LCTL(KC_Z), LCTL(KC_Y), KC_G, KC_P, KC_LALT,
KC_M, LCTL(KC_SPC), KC_E, KC_B, KC_RBRC,
KC_W, LSFT(KC_SPC), KC_K, KC_SPC, KC_LBRC
)
};

128 changes: 128 additions & 0 deletions keyboards/yushakobo/quick_paint/quick_paint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/* Copyright 2020 monksoffunk
* Copyright 2022 sekigon-gonnoc
* Copyright 2022 yushakobo
*
* 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 "quick_paint.h"

user_config_t user_config;

uint8_t encoderlocklayer[NUM_ENCODERS] = {0};
uint8_t encoder_modifier = 0;
uint16_t encoder_modifier_pressed_ms = 0;

extern bool is_encoder_action;

#ifndef ENCODER_MODIFIER_TIMEOUT_MS
# define ENCODER_MODIFIER_TIMEOUT_MS 250
#endif

void eeconfig_init_kb(void) {
user_config.raw = 0;
user_config.mac_mode = true;
eeconfig_update_kb(user_config.raw);
eeconfig_init_user();
}

void keyboard_pre_init_kb(void) {
// Read the user config from EEPROM
user_config.raw = eeconfig_read_kb();
keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui =
!user_config.mac_mode;
keyboard_pre_init_user();
}

void keyboard_post_init_kb(void) {
debug_enable = true;
debug_keyboard = true;

keyboard_post_init_user();
}

void matrix_scan_kb(void) {
encoder_action_unregister(encoderlocklayer);
if (encoder_modifier != 0 && timer_elapsed(encoder_modifier_pressed_ms) >
ENCODER_MODIFIER_TIMEOUT_MS) {
unregister_mods(encoder_modifier);
encoder_modifier = 0;
}
matrix_scan_user();
}

bool encoder_update_kb(uint8_t index, bool clockwise) {
encoder_action_register(index, clockwise, encoderlocklayer);
return true;
}

bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
if (encoder_modifier != 0 && !is_encoder_action) {
unregister_mods(encoder_modifier);
encoder_modifier = 0;
}

switch (keycode) {
case QK_MODS ... QK_MODS_MAX:
if (is_encoder_action) {
if (record->event.pressed) {
uint8_t current_mods = keycode >> 8;
encoder_modifier_pressed_ms = timer_read();
if (current_mods != encoder_modifier) {
del_mods(encoder_modifier);
encoder_modifier = current_mods;
add_mods(encoder_modifier);
}
register_code(keycode & 0xff);
} else {
unregister_code(keycode & 0xff);
}
return false;
} else {
return true;
}
break;
case AG_NORM:
if (record->event.pressed) {
if (!user_config.mac_mode) {
user_config.mac_mode = true;
eeconfig_update_kb(user_config.raw);
}
}
return true;
break;
case AG_SWAP:
if (record->event.pressed) {
if (user_config.mac_mode) {
user_config.mac_mode = false;
eeconfig_update_kb(user_config.raw);
}
}
return true;
break;
case ENC_00 ... ENC_09:
if (record->event.pressed) {
if (encoderlocklayer[0] != keycode - ENC_00) {
encoderlocklayer[0] = keycode - ENC_00;
} else {
encoderlocklayer[0] = 0;
}
}
return false;
break;
default:
break;
}
return process_record_user(keycode, record);
}
46 changes: 46 additions & 0 deletions keyboards/yushakobo/quick_paint/quick_paint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Copyright 2020 monksoffunk
* Copyright 2022 sekigon-gonnoc
* Copyright 2022 yushakobo
*
* 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

#include "quantum.h"
#include "encoder_action.h"

typedef union {
uint32_t raw;
struct {
bool mac_mode : 1;
};
} user_config_t;

enum kb_keycodes {
ENCADJ = 0xC0,
UNUSED00,
UNUSED01,
ENC_00,
ENC_01,
ENC_02,
ENC_03,
ENC_04,
ENC_05,
ENC_06,
ENC_07,
ENC_08,
ENC_09,
USR_SAFE_RANGE,
};
Loading

0 comments on commit 4f8cf6b

Please sign in to comment.