From fafe2b4a46839a74cbba7f60eae7ee6ce2008a3f Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Sun, 9 Jun 2024 20:57:16 -0400 Subject: [PATCH 01/28] [Keyboard] add aki27/cocot46plus --- keyboards/aki27/cocot46plus/cocot46plus.c | 295 ++++++++++++++++++ keyboards/aki27/cocot46plus/cocot46plus.h | 65 ++++ keyboards/aki27/cocot46plus/config.h | 26 ++ keyboards/aki27/cocot46plus/glcdfont.c | 232 ++++++++++++++ keyboards/aki27/cocot46plus/keyboard.json | 152 +++++++++ .../cocot46plus/keymaps/default/keymap.c | 163 ++++++++++ .../cocot46plus/keymaps/default/rules.mk | 1 + .../aki27/cocot46plus/layout-reference.md | 29 ++ keyboards/aki27/cocot46plus/matrix.c | 175 +++++++++++ keyboards/aki27/cocot46plus/readme.md | 50 +++ keyboards/aki27/cocot46plus/rules.mk | 6 + 11 files changed, 1194 insertions(+) create mode 100644 keyboards/aki27/cocot46plus/cocot46plus.c create mode 100644 keyboards/aki27/cocot46plus/cocot46plus.h create mode 100644 keyboards/aki27/cocot46plus/config.h create mode 100644 keyboards/aki27/cocot46plus/glcdfont.c create mode 100644 keyboards/aki27/cocot46plus/keyboard.json create mode 100644 keyboards/aki27/cocot46plus/keymaps/default/keymap.c create mode 100644 keyboards/aki27/cocot46plus/keymaps/default/rules.mk create mode 100644 keyboards/aki27/cocot46plus/layout-reference.md create mode 100644 keyboards/aki27/cocot46plus/matrix.c create mode 100644 keyboards/aki27/cocot46plus/readme.md create mode 100644 keyboards/aki27/cocot46plus/rules.mk diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c new file mode 100644 index 00000000000..1245ad2c554 --- /dev/null +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -0,0 +1,295 @@ +/* +Copyright 2022 aki27 + +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 . +*/ + +#include "quantum.h" +#include +#include "cocot46plus.h" +#include "wait.h" +#include "debug.h" +#include + +// Invert vertical scroll direction +#ifndef COCOT_SCROLL_INV_DEFAULT +# define COCOT_SCROLL_INV_DEFAULT 1 +#endif + +#ifndef COCOT_CPI_OPTIONS +# define COCOT_CPI_OPTIONS { 250, 500, 750, 1000, 1250 } +#endif +#ifndef COCOT_CPI_DEFAULT +# define COCOT_CPI_DEFAULT 4 +#endif + +#ifndef COCOT_SCROLL_DIVIDERS +# define COCOT_SCROLL_DIVIDERS { 1, 2, 3, 4, 5, 6 } +#endif +#ifndef COCOT_SCROLL_DIV_DEFAULT +# define COCOT_SCROLL_DIV_DEFAULT 4 +#endif + + +#ifndef COCOT_ROTATION_ANGLE +# define COCOT_ROTATION_ANGLE { -60, -45, -30, -15, 0, 15, 30, 45, 60 } +#endif +#ifndef COCOT_ROTATION_DEFAULT +# define COCOT_ROTATION_DEFAULT 2 +#endif + + +cocot_config_t cocot_config; +uint16_t cpi_array[] = COCOT_CPI_OPTIONS; +uint16_t scrl_div_array[] = COCOT_SCROLL_DIVIDERS; +uint16_t angle_array[] = COCOT_ROTATION_ANGLE; +#define CPI_OPTION_SIZE (sizeof(cpi_array) / sizeof(uint16_t)) +#define SCRL_DIV_SIZE (sizeof(scrl_div_array) / sizeof(uint16_t)) +#define ANGLE_SIZE (sizeof(angle_array) / sizeof(uint16_t)) + + +// Trackball State +bool BurstState = false; // init burst state for Trackball module +uint16_t MotionStart = 0; // Timer for accel, 0 is resting state + +// Scroll Accumulation +static int16_t h_acm = 0; +static int16_t v_acm = 0; + + +void pointing_device_init_kb(void) { + // set the CPI. + pointing_device_set_cpi(cpi_array[cocot_config.cpi_idx]); + adns5050_write_reg(0x22, 0b10000 | 0x80); +} + + +report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { + + double rad = angle_array[cocot_config.rotation_angle] * (M_PI / 180) * -1; + int8_t x_rev = + mouse_report.x * cos(rad) - mouse_report.y * sin(rad); + int8_t y_rev = + mouse_report.x * sin(rad) + mouse_report.y * cos(rad); + + if (cocot_get_scroll_mode()) { + // rock scroll direction + if (abs(x_rev) > abs(y_rev)) { + y_rev = 0; + } else { + x_rev = 0; + } + + // accumulate scroll + h_acm += x_rev * cocot_config.scrl_inv; + v_acm += y_rev * cocot_config.scrl_inv * -1; + + int8_t h_rev = h_acm >> scrl_div_array[cocot_config.scrl_div]; + int8_t v_rev = v_acm >> scrl_div_array[cocot_config.scrl_div]; + + // clear accumulated scroll on assignment + + if (h_rev != 0) { + if (mouse_report.h + h_rev > 127) { + h_rev = 127 - mouse_report.h; + } else if (mouse_report.h + h_rev < -127) { + h_rev = -127 - mouse_report.h; + } + mouse_report.h += h_rev; + h_acm -= h_rev << scrl_div_array[cocot_config.scrl_div]; + } + if (v_rev != 0) { + if (mouse_report.v + v_rev > 127) { + v_rev = 127 - mouse_report.v; + } else if (mouse_report.v + v_rev < -127) { + v_rev = -127 - mouse_report.v; + } + mouse_report.v += v_rev; + v_acm -= v_rev << scrl_div_array[cocot_config.scrl_div]; + } + + mouse_report.x = 0; + mouse_report.y = 0; + } else { + mouse_report.x = x_rev; + mouse_report.y = y_rev; + } + + return pointing_device_task_user(mouse_report); +} + + + +bool process_record_kb(uint16_t keycode, keyrecord_t* record) { + // 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; + + switch (keycode) { +#ifndef MOUSEKEY_ENABLE + // process KC_MS_BTN1~8 by myself + // See process_action() in quantum/action.c for details. + case KC_MS_BTN1 ... KC_MS_BTN8: { + extern void register_button(bool, enum mouse_buttons); + register_button(record->event.pressed, MOUSE_BTN_MASK(keycode - KC_MS_BTN1)); + return false; + } +#endif + + } + + if (keycode == CPI_SW && record->event.pressed) { + cocot_config.cpi_idx = (cocot_config.cpi_idx + 1) % CPI_OPTION_SIZE; + eeconfig_update_kb(cocot_config.raw); + pointing_device_set_cpi(cpi_array[cocot_config.cpi_idx]); + } + + if (keycode == SCRL_SW && record->event.pressed) { + cocot_config.scrl_div = (cocot_config.scrl_div + 1) % SCRL_DIV_SIZE; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == ROT_R15 && record->event.pressed) { + cocot_config.rotation_angle = (cocot_config.rotation_angle + 1) % ANGLE_SIZE; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == ROT_L15 && record->event.pressed) { + cocot_config.rotation_angle = (ANGLE_SIZE + cocot_config.rotation_angle - 1) % ANGLE_SIZE; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == SCRL_IN && record->event.pressed) { + cocot_config.scrl_inv = - cocot_config.scrl_inv; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == SCRL_TO && record->event.pressed) { + { cocot_config.scrl_mode ^= 1; } + } + + if (keycode == SCRL_MO) { + { cocot_config.scrl_mode ^= 1; } + } + + return true; +} + + +void eeconfig_init_kb(void) { + cocot_config.cpi_idx = COCOT_CPI_DEFAULT; + cocot_config.scrl_div = COCOT_SCROLL_DIV_DEFAULT; + cocot_config.rotation_angle = COCOT_ROTATION_DEFAULT; + cocot_config.scrl_inv = COCOT_SCROLL_INV_DEFAULT; + cocot_config.scrl_mode = false; + eeconfig_update_kb(cocot_config.raw); + eeconfig_init_user(); + adns5050_write_reg(0x22, 0b10000 | 0x80); +} + + +void matrix_init_kb(void) { + // is safe to just read CPI setting since matrix init + // comes before pointing device init. + cocot_config.raw = eeconfig_read_kb(); + if (cocot_config.cpi_idx > CPI_OPTION_SIZE) // || cocot_config.scrl_div > SCRL_DIV_SIZE || cocot_config.rotation_angle > ANGLE_SIZE) + { + eeconfig_init_kb(); + } + matrix_init_user(); +} + + +bool cocot_get_scroll_mode(void) { + return cocot_config.scrl_mode; +} + +void cocot_set_scroll_mode(bool mode) { + cocot_config.scrl_mode = mode; +} + + + +// OLED utility +#ifdef OLED_ENABLE + +oled_rotation_t oled_init_user(oled_rotation_t rotation) { + return OLED_ROTATION_0; +} + +static const char PROGMEM cocot_logo[] = { + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, + 0}; + +void render_logo(void) { + oled_write_P(cocot_logo, false); +}; + +void oled_write_layer_state(void) { + + oled_write_P(PSTR(" "), false); + // int cpi = pointing_device_get_cpi(); + int cpi = cpi_array[cocot_config.cpi_idx]; + int scroll_div = scrl_div_array[cocot_config.scrl_div]; + int angle = angle_array[cocot_config.rotation_angle]; + + char buf1[5]; + char buf2[3]; + char buf3[4]; + snprintf(buf1, 5, "%4d", cpi); + snprintf(buf2, 3, "%2d", scroll_div); + snprintf(buf3, 4, "%3d", angle); + + switch (get_highest_layer(layer_state | default_layer_state)) { + case 0: + oled_write_P(PSTR("Base "), false); + break; + case 1: + oled_write_P(PSTR("Lower"), false); + break; + case 2: + oled_write_P(PSTR("Raise"), false); + break; + case 3: + oled_write_P(PSTR("Mouse"), false); + break; + case 4: + oled_write_P(PSTR("L4 "), false); + break; + case 5: + oled_write_P(PSTR("L5 "), false); + break; + case 6: + oled_write_P(PSTR("L6 "), false); + break; + default: + oled_write_P(PSTR("Undef"), false); + break; + } + oled_write_P(PSTR("/"), false); + if (cocot_get_scroll_mode()){ + oled_write_P(PSTR("S"), false); + } else{ + oled_write_P(PSTR("C"), false); + } + oled_write_P(PSTR("/"), false); + oled_write(buf1, false); + oled_write_P(PSTR("/"), false); + oled_write(buf2, false); + oled_write_P(PSTR("/"), false); + oled_write(buf3, false); +} + +#endif + diff --git a/keyboards/aki27/cocot46plus/cocot46plus.h b/keyboards/aki27/cocot46plus/cocot46plus.h new file mode 100644 index 00000000000..c22ea029fff --- /dev/null +++ b/keyboards/aki27/cocot46plus/cocot46plus.h @@ -0,0 +1,65 @@ +/* +Copyright 2022 aki27 + +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 "quantum.h" + +typedef union { + uint32_t raw; + struct { + uint8_t cpi_idx; + uint8_t scrl_div; + uint8_t rotation_angle; + int8_t scrl_inv; + bool scrl_mode; + report_mouse_t last_mouse; + }; +} cocot_config_t; + + + +extern cocot_config_t cocot_config; + +enum cocot_keycodes { + + COCOT_SAFE_RANGE = SAFE_RANGE, + CPI_SW, + SCRL_SW, + ROT_R15, + ROT_L15, + SCRL_MO, + SCRL_TO, + SCRL_IN, + +}; + +#define CPI_SW QK_USER_0 +#define SCRL_SW QK_USER_1 +#define ROT_R15 QK_USER_2 +#define ROT_L15 QK_USER_3 +#define SCRL_MO QK_USER_4 +#define SCRL_TO QK_USER_5 +#define SCRL_IN QK_USER_6 + +bool encoder_update_user(uint8_t index, bool clockwise); +bool encoder_update_kb(uint8_t index, bool clockwise); +bool cocot_get_scroll_mode(void); +void cocot_set_scroll_mode(bool mode); + +void render_logo(void); +void oled_write_layer_state(void); diff --git a/keyboards/aki27/cocot46plus/config.h b/keyboards/aki27/cocot46plus/config.h new file mode 100644 index 00000000000..e5806c38853 --- /dev/null +++ b/keyboards/aki27/cocot46plus/config.h @@ -0,0 +1,26 @@ +/* +Copyright 2022 aki27 + +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 + +// These do not seem to have keyboard.json support yet. +#define ADNS5050_SCLK_PIN B2 +#define ADNS5050_SDIO_PIN B4 +#define ADNS5050_CS_PIN B5 + +#define POINTING_DEVICE_ROTATION_180 +#define OLED_FONT_H "keyboards/aki27/cocot46plus/glcdfont.c" diff --git a/keyboards/aki27/cocot46plus/glcdfont.c b/keyboards/aki27/cocot46plus/glcdfont.c new file mode 100644 index 00000000000..bd7d8bae003 --- /dev/null +++ b/keyboards/aki27/cocot46plus/glcdfont.c @@ -0,0 +1,232 @@ +// This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0. +// See gfxfont.h for newer custom bitmap font info. + +#include "progmem.h" + +// Standard ASCII 5x7 font +const unsigned char font[] PROGMEM = { +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00, +0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00, +0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00, +0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x00, +0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00, +0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, +0x00, 0x18, 0x3C, 0x18, 0x00, 0x00, +0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, +0x00, 0x18, 0x24, 0x18, 0x00, 0x00, +0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00, +0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00, +0x26, 0x29, 0x79, 0x29, 0x26, 0x00, +0x40, 0x7F, 0x05, 0x05, 0x07, 0x00, +0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00, +0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x00, +0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00, +0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00, +0x14, 0x22, 0x7F, 0x22, 0x14, 0x00, +0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00, +0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, +0x00, 0x66, 0x89, 0x95, 0x6A, 0x00, +0x60, 0x60, 0x60, 0x60, 0x60, 0x00, +0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00, +0x08, 0x04, 0x7E, 0x04, 0x08, 0x00, +0x10, 0x20, 0x7E, 0x20, 0x10, 0x00, +0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, +0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, +0x1E, 0x10, 0x10, 0x10, 0x10, 0x00, +0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00, +0x30, 0x38, 0x3E, 0x38, 0x30, 0x00, +0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, +0x00, 0x07, 0x00, 0x07, 0x00, 0x00, +0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, +0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, +0x23, 0x13, 0x08, 0x64, 0x62, 0x00, +0x36, 0x49, 0x56, 0x20, 0x50, 0x00, +0x00, 0x08, 0x07, 0x03, 0x00, 0x00, +0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, +0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, +0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00, +0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, +0x00, 0x80, 0x70, 0x30, 0x00, 0x00, +0x08, 0x08, 0x08, 0x08, 0x08, 0x00, +0x00, 0x00, 0x60, 0x60, 0x00, 0x00, +0x20, 0x10, 0x08, 0x04, 0x02, 0x00, +0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, +0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, +0x72, 0x49, 0x49, 0x49, 0x46, 0x00, +0x21, 0x41, 0x49, 0x4D, 0x33, 0x00, +0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, +0x27, 0x45, 0x45, 0x45, 0x39, 0x00, +0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00, +0x41, 0x21, 0x11, 0x09, 0x07, 0x00, +0x36, 0x49, 0x49, 0x49, 0x36, 0x00, +0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, +0x00, 0x00, 0x14, 0x00, 0x00, 0x00, +0x00, 0x40, 0x34, 0x00, 0x00, 0x00, +0x00, 0x08, 0x14, 0x22, 0x41, 0x00, +0x14, 0x14, 0x14, 0x14, 0x14, 0x00, +0x00, 0x41, 0x22, 0x14, 0x08, 0x00, +0x02, 0x01, 0x59, 0x09, 0x06, 0x00, +0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00, +0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00, +0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, +0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, +0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, +0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, +0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, +0x3E, 0x41, 0x41, 0x51, 0x73, 0x00, +0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, +0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, +0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, +0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, +0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, +0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00, +0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, +0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, +0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, +0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, +0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, +0x26, 0x49, 0x49, 0x49, 0x32, 0x00, +0x03, 0x01, 0x7F, 0x01, 0x03, 0x00, +0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, +0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, +0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, +0x63, 0x14, 0x08, 0x14, 0x63, 0x00, +0x03, 0x04, 0x78, 0x04, 0x03, 0x00, +0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, +0x00, 0x7F, 0x41, 0x41, 0x41, 0x00, +0x02, 0x04, 0x08, 0x10, 0x20, 0x00, +0x00, 0x41, 0x41, 0x41, 0x7F, 0x00, +0x04, 0x02, 0x01, 0x02, 0x04, 0x00, +0x40, 0x40, 0x40, 0x40, 0x40, 0x00, +0x00, 0x03, 0x07, 0x08, 0x00, 0x00, +0x20, 0x54, 0x54, 0x78, 0x40, 0x00, +0x7F, 0x28, 0x44, 0x44, 0x38, 0x00, +0x38, 0x44, 0x44, 0x44, 0x28, 0x00, +0x38, 0x44, 0x44, 0x28, 0x7F, 0x00, +0x38, 0x54, 0x54, 0x54, 0x18, 0x00, +0x00, 0x08, 0x7E, 0x09, 0x02, 0x00, +0x18, 0x24, 0x24, 0x1C, 0x78, 0x00, +0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, +0x00, 0x44, 0x7D, 0x40, 0x00, 0x00, +0x20, 0x40, 0x40, 0x3D, 0x00, 0x00, +0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, +0x00, 0x41, 0x7F, 0x40, 0x00, 0x00, +0x7C, 0x04, 0x78, 0x04, 0x78, 0x00, +0x7C, 0x08, 0x04, 0x04, 0x78, 0x00, +0x38, 0x44, 0x44, 0x44, 0x38, 0x00, +0x7C, 0x18, 0x24, 0x24, 0x18, 0x00, +0x18, 0x24, 0x24, 0x18, 0x7C, 0x00, +0x7C, 0x08, 0x04, 0x04, 0x08, 0x00, +0x48, 0x54, 0x54, 0x54, 0x24, 0x00, +0x04, 0x04, 0x3F, 0x44, 0x24, 0x00, +0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00, +0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, +0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00, +0x44, 0x28, 0x10, 0x28, 0x44, 0x00, +0x4C, 0x90, 0x90, 0x90, 0x7C, 0x00, +0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, +0x00, 0x08, 0x36, 0x41, 0x00, 0x00, +0x00, 0x00, 0x77, 0x00, 0x00, 0x00, +0x00, 0x41, 0x36, 0x08, 0x00, 0x00, +0x02, 0x01, 0x02, 0x04, 0x02, 0x00, +0x3C, 0x26, 0x23, 0x26, 0x3C, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0xC0, 0x60, 0xC0, 0xD0, +0xC8, 0xE8, 0x6C, 0x64, 0x64, 0x64, +0x6C, 0x68, 0x68, 0x98, 0xD0, 0x60, +0x00, 0x80, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x80, +0x80, 0x80, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x80, 0x80, +0x80, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x80, 0x80, +0x80, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x80, 0x80, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, +0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x80, 0xE0, 0xE0, +0x20, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xE0, 0xF0, 0xF0, 0xF0, 0xE0, 0xEC, +0xEE, 0xF7, 0xF3, 0x70, 0x20, 0x00, +0x7C, 0x7C, 0x7C, 0x7E, 0x00, 0x7E, +0x7E, 0x7E, 0x7F, 0x7F, 0x7F, 0x00, +0x00, 0x80, 0xC0, 0xE0, 0x7E, 0x5B, +0x4F, 0x5B, 0xFE, 0xC0, 0x00, 0x00, +0xC0, 0x00, 0xDC, 0xD7, 0xDE, 0xDE, +0xDE, 0xD7, 0xDC, 0x00, 0xC0, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xFC, 0x87, 0x78, 0xFE, 0xFE, 0x01, +0x01, 0x78, 0x84, 0x82, 0x02, 0x02, +0x86, 0x86, 0x03, 0x01, 0x87, 0xFF, +0xFC, 0x03, 0xFE, 0x00, 0x00, 0x00, +0x00, 0xFC, 0xFE, 0xCF, 0x03, 0x03, +0x03, 0x03, 0x87, 0xC7, 0x86, 0x00, +0x78, 0xFE, 0xFF, 0x87, 0x03, 0x03, +0x03, 0x03, 0xCF, 0xFE, 0xFC, 0x00, +0x38, 0xFE, 0xFF, 0x87, 0x03, 0x03, +0x03, 0x03, 0xC7, 0x86, 0x84, 0x00, +0xFC, 0xFE, 0x87, 0x03, 0x03, 0x03, +0x03, 0x87, 0xFE, 0xFC, 0x30, 0x03, +0x03, 0xFF, 0xFF, 0x83, 0x03, 0x00, +0x00, 0x70, 0x78, 0x7E, 0x6F, 0x63, +0x61, 0xFF, 0xFF, 0x60, 0x60, 0x00, +0xF0, 0xFC, 0xFF, 0x0F, 0x0F, 0x0E, +0x8E, 0xFC, 0xF8, 0x60, 0x00, 0x30, +0x30, 0x30, 0x30, 0x30, 0xFF, 0xFF, +0x30, 0x30, 0x30, 0x30, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0x7F, +0x7F, 0x7F, 0x3F, 0x1E, 0x0C, 0x00, +0x1F, 0x1F, 0x1F, 0x3F, 0x00, 0x3F, +0x3F, 0x3F, 0x7F, 0x7F, 0x7F, 0x00, +0x30, 0x7B, 0x7F, 0x78, 0x30, 0x20, +0x20, 0x30, 0x78, 0x7F, 0x3B, 0x00, +0x03, 0x00, 0x0F, 0x7F, 0x0F, 0x0F, +0x0F, 0x7F, 0x0F, 0x00, 0x03, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x03, 0x04, 0x19, 0x3F, 0x27, +0x42, 0x58, 0x58, 0xD9, 0x99, 0x99, +0xD8, 0x5D, 0x5F, 0x6E, 0x2C, 0x19, +0x0C, 0x07, 0x01, 0x00, 0x00, 0x00, +0x00, 0x00, 0x01, 0x03, 0x03, 0x03, +0x03, 0x03, 0x03, 0x03, 0x01, 0x00, +0x00, 0x01, 0x01, 0x03, 0x03, 0x03, +0x03, 0x03, 0x03, 0x01, 0x00, 0x00, +0x00, 0x00, 0x01, 0x03, 0x03, 0x03, +0x03, 0x03, 0x03, 0x01, 0x00, 0x00, +0x00, 0x01, 0x03, 0x03, 0x03, 0x03, +0x03, 0x03, 0x01, 0x00, 0x00, 0x00, +0x00, 0x01, 0x03, 0x03, 0x03, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x03, 0x03, 0x00, 0x00, 0x00, +0x00, 0x01, 0x03, 0x03, 0x03, 0x03, +0x03, 0x03, 0x01, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x03, 0x03, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; diff --git a/keyboards/aki27/cocot46plus/keyboard.json b/keyboards/aki27/cocot46plus/keyboard.json new file mode 100644 index 00000000000..2e919547095 --- /dev/null +++ b/keyboards/aki27/cocot46plus/keyboard.json @@ -0,0 +1,152 @@ +{ + "keyboard_name": "cocot46plus", + "manufacturer": "aki27", + "maintainer": "markstos", + "tags": ["unibody","ergo","corne","trackball","encoder","rgb"] + "usb": { + "device_version": "1.0.0", + "pid": "0x0003", + "vid": "0x1727" + }, + "processor": "atmega32u4", + "bootloader": "caterina", + "qmk": { + "locking": { + "enabled": false, + "resync": false + } + }, + "build": { + "lto": true + }, + "features": { + "audio": false, + "backlight": false, + "bootmagic": true, + "command": false, + "console": false, + "encoder":true, + "extrakey": true, + "mousekey": true, + "nkro": false, + "oled": true, + "pointing_device": true, + "rgblight": true + }, + "debounce": 5, + "matrix_pins": { + "cols": ["F4", "F5", "F6", "F7", "B1", "B3"], + "rows": ["D4", "C6", "D7", "E6", "NO_PIN"], + "custom": true, + "custom_lite": true, + "direct": [ + [ "A00", "A01", "A02", "A03", "A04", "A05" ], + [ "A10", "A11", "A12", "A13", "A14", "A15" ], + [ "A20", "A21", "A22", "A23", "A24", "A25" ], + [ "A30", "A31", "A32", "A33", "A34", "A35" ], + [ null, null, "A42", null, null, "A45" ], + [ "B00", "B01", "B02", "B03", "B04", "B05" ], + [ "B10", "B11", "B12", "B13", "B14", "B15" ], + [ "B20", "B21", "B22", "B23", "B24", "B25" ], + [ "B30", "B31", "B32", "B33", "B34", "B35" ], + [ null, null, "B42", null, null, "B45" ] + ] + }, + "ws2812": { + "pin": "B6" + }, + "tapping": { + "term": 200, + }, + "encoder": { + "rotary": [ + { "pin_a": "D3", "pin_b": "D2", "resolution": 4 } + ] + }, + "rgblight": { + "led_count": 12, + "animations": { + "breathing": true, + "rainbow_mood": true, + "rainbow_swirl": true, + "snake": true, + "static_gradient": true, + "twinkle": true, + }, + "brightness_steps": 17, + "hue_steps": 10, + "saturation_steps": 17, + "max_brightness": 120, + }, + "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": [0,5], "x": 5, "y": 0}, + + { "matrix": [5,5], "x": 9, "y": 0}, + { "matrix": [5,4], "x": 10, "y": 0}, + { "matrix": [5,3], "x": 11, "y": 0}, + { "matrix": [5,2], "x": 12, "y": 0}, + { "matrix": [5,1], "x": 13, "y": 0}, + { "matrix": [5,0], "x": 14, "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": [1,5], "x": 5, "y": 1}, + + { "matrix": [6,5], "x": 9, "y": 1}, + { "matrix": [6,4], "x": 10, "y": 1}, + { "matrix": [6,3], "x": 11, "y": 1}, + { "matrix": [6,2], "x": 12, "y": 1}, + { "matrix": [6,1], "x": 13, "y": 1}, + { "matrix": [6,0], "x": 14, "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}, + { "matrix": [2,5], "x": 5, "y": 2}, + + { "matrix": [7,5], "x": 9, "y": 2}, + { "matrix": [7,4], "x": 10, "y": 2}, + { "matrix": [7,3], "x": 11, "y": 2}, + { "matrix": [7,2], "x": 12, "y": 2}, + { "matrix": [7,1], "x": 13, "y": 2}, + { "matrix": [7,0], "x": 14, "y": 2}, + + + { "matrix": [3,0], "x": 2, "y": 3}, + { "matrix": [3,1], "x": 3, "y": 3}, + { "matrix": [3,2], "x": 4, "y": 3}, + { "matrix": [3,3], "x": 5, "y": 3}, + + { "matrix": [3,5], "x": 6, "y": 3}, + { "matrix": [8,5], "x": 8, "y": 3}, + + { "matrix": [8,3], "x": 9, "y": 3}, + { "matrix": [8,2], "x": 10, "y": 3}, + { "matrix": [8,1], "x": 11, "y": 3}, + { "matrix": [8,0], "x": 12, "y": 3}, + + { "matrix": [4,2], "x": 6, "y": 4}, + { "matrix": [3,4], "x": 7, "y": 4}, + { "matrix": [4,4], "x": 8, "y": 4}, + + { "matrix": [9,2], "x": 9, "y": 4}, + { "matrix": [8,4], "x": 10, "y": 4}, + { "matrix": [9,5], "x": 11, "y": 4}, + ] + } + } +} diff --git a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c new file mode 100644 index 00000000000..55a2eda90b5 --- /dev/null +++ b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c @@ -0,0 +1,163 @@ +/* +Copyright 2022 aki27 + +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 . +*/ + +#include QMK_KEYBOARD_H +#include +#include "quantum.h" + + +// Defines names for use in layer keycodes and the keymap +enum layer_number { + _BASE = 0, + _LOWER = 1, + _RAISE = 2, + _TRACKBALL = 3, +}; + + +#define LW_MHEN LT(1,KC_INT5) // lower +#define RS_HENK LT(2,KC_INT4) // raise +#define DEL_ALT ALT_T(KC_DEL) + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_BASE] = LAYOUT( + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, + //|-------------------------------------------------------| |-------------------------------------------------------| + 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_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_MINS, + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_LGUI, DEL_ALT, LW_MHEN, KC_SPC, KC_MS_BTN1, KC_MS_BTN2, KC_ENT, RS_HENK, KC_BSPC, KC_ESC, + KC_PGUP, KC_MS_BTN3, KC_PGDN, XXXXXXX, XXXXXXX, XXXXXXX + //`--------------' `--------------' + ), + [_LOWER] = LAYOUT( + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_ESC, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_LCTL, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_LCBR, KC_RCBR, KC_LBRC, KC_RBRC, KC_COLN, KC_DQUO, + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_LSFT, KC_GRV, KC_TILD, KC_NUBS, KC_PIPE, XXXXXXX, KC_EQL, KC_PLUS, KC_LABK, KC_RABK, KC_QUES, KC_UNDS, + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_LGUI, DEL_ALT, KC_TRNS, KC_SPC, KC_MS_BTN4, KC_MS_BTN5, KC_ENT, TT(3), KC_BSPC, KC_ESC, + KC_PGUP, KC_MS_BTN3, KC_PGDN, XXXXXXX, XXXXXXX, XXXXXXX + //`--------------' `--------------' + ), + [_RAISE] = LAYOUT( + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_LCTL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_APP, KC_UP,S(KC_INT1), KC_UNDS, KC_DQUO, KC_COLN, + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_LSFT, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_LEFT, KC_DOWN, KC_RGHT, KC_DOT, KC_SLSH, KC_MINS, + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_LGUI, DEL_ALT, TT(3), KC_SPC, KC_MS_BTN4, KC_MS_BTN5, KC_ENT, KC_TRNS, KC_BSPC, KC_ESC, + KC_PGUP, KC_MS_BTN3, KC_PGDN, XXXXXXX, XXXXXXX, XXXXXXX + //`--------------' `--------------' + ), + [_TRACKBALL] = LAYOUT( + //|-------------------------------------------------------| |-------------------------------------------------------| + QK_BOOT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_TOG, SCRL_TO, CPI_SW, SCRL_SW, ROT_L15, ROT_R15, XXXXXXX, + //|-------------------------------------------------------| |-------------------------------------------------------| + XXXXXXX, XXXXXXX, RGB_VAI, RGB_SAI, RGB_HUI, RGB_MOD, SCRL_MO, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + //|-------------------------------------------------------| |-------------------------------------------------------| + XXXXXXX, XXXXXXX, RGB_VAD, RGB_SAD, RGB_HUD,RGB_RMOD, SCRL_IN, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + //|-------------------------------------------------------| |-------------------------------------------------------| + KC_LGUI, DEL_ALT, KC_TRNS, KC_SPC, KC_MS_BTN1, KC_MS_BTN2, KC_ENT, RS_HENK, KC_BSPC, KC_ESC, + KC_PGUP, KC_MS_BTN3, KC_PGDN, XXXXXXX, XXXXXXX, XXXXXXX + //`--------------' `--------------' + ) +}; + +keyevent_t encoder1_ccw = { + .key = (keypos_t){.row = 4, .col = 2}, + .pressed = false +}; + +keyevent_t encoder1_cw = { + .key = (keypos_t){.row = 4, .col = 5}, + .pressed = false +}; + +bool encoder_update_user(uint8_t index, bool clockwise) { + if (index == 0) { /* First encoder */ + if (clockwise) { + encoder1_cw.pressed = true; + encoder1_cw.time = (timer_read() | 1); + action_exec(encoder1_cw); + } else { + encoder1_ccw.pressed = true; + encoder1_ccw.time = (timer_read() | 1); + action_exec(encoder1_ccw); + } + } + + return true; +} + + +void matrix_scan_user(void) { + + if (encoder1_ccw.pressed) { + encoder1_ccw.pressed = false; + encoder1_ccw.time = (timer_read() | 1); + action_exec(encoder1_ccw); + } + + if (encoder1_cw.pressed) { + encoder1_cw.pressed = false; + encoder1_cw.time = (timer_read() | 1); + action_exec(encoder1_cw); + } + +} + + + +layer_state_t layer_state_set_user(layer_state_t state) { + switch (get_highest_layer(state)) { + case _LOWER: + rgblight_sethsv_range(HSV_BLUE, 0, 2); + cocot_set_scroll_mode(true); + break; + case _RAISE: + rgblight_sethsv_range(HSV_RED, 0, 2); + cocot_set_scroll_mode(true); + break; + case _TRACKBALL: + rgblight_sethsv_range(HSV_GREEN, 0, 2); + cocot_set_scroll_mode(false); + break; + default: + rgblight_sethsv_range( 0, 0, 0, 0, 2); + cocot_set_scroll_mode(false); + break; + } + rgblight_set_effect_range( 2, 10); + return state; +}; + + +#ifdef OLED_ENABLE +bool oled_task_user(void) { + render_logo(); + oled_write_layer_state(); + return false; +} +#endif + diff --git a/keyboards/aki27/cocot46plus/keymaps/default/rules.mk b/keyboards/aki27/cocot46plus/keymaps/default/rules.mk new file mode 100644 index 00000000000..9d2c49d933e --- /dev/null +++ b/keyboards/aki27/cocot46plus/keymaps/default/rules.mk @@ -0,0 +1 @@ +VIA_ENABLE = no diff --git a/keyboards/aki27/cocot46plus/layout-reference.md b/keyboards/aki27/cocot46plus/layout-reference.md new file mode 100644 index 00000000000..8a58540efa4 --- /dev/null +++ b/keyboards/aki27/cocot46plus/layout-reference.md @@ -0,0 +1,29 @@ + +This was the original layout definition showing how the physical key locations map +to the matrix grid. + +* A3 and B35 are the trackball keys +* A42, A34, A45 are for the encoder CCW, click and CW bindings + +The last three, B42, B34 and B45 don't seem to used. + +```` +define LAYOUT( \ + A00, A01, A02, A03, A04, A05, B05, B04, B03, B02, B01, B00, \ + A10, A11, A12, A13, A14, A15, B15, B14, B13, B12, B11, B10, \ + A20, A21, A22, A23, A24, A25, B25, B24, B23, B22, B21, B20, \ + A30, A31, A32, A33, A35, B35, B33, B32, B31, B30, \ + A42, A34, A45, B42, B34, B45 \ + ) \ + { \ + { A00, A01, A02, A03, A04, A05 }, \ + { A10, A11, A12, A13, A14, A15 }, \ + { A20, A21, A22, A23, A24, A25 }, \ + { A30, A31, A32, A33, A34, A35 }, \ + { KC_NO, KC_NO, A42, KC_NO, KC_NO, A45 }, \ + { B00, B01, B02, B03, B04, B05 }, \ + { B10, B11, B12, B13, B14, B15 }, \ + { B20, B21, B22, B23, B24, B25 }, \ + { B30, B31, B32, B33, B34, B35 }, \ + { KC_NO, KC_NO, B42, KC_NO, KC_NO, B45 } \ +``` diff --git a/keyboards/aki27/cocot46plus/matrix.c b/keyboards/aki27/cocot46plus/matrix.c new file mode 100644 index 00000000000..57cbdab3945 --- /dev/null +++ b/keyboards/aki27/cocot46plus/matrix.c @@ -0,0 +1,175 @@ +/* +Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar + +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 . +*/ +#include "matrix.h" +#include "quantum.h" + +#if (MATRIX_COLS <= 8) +# define print_matrix_header() print("\nr/c 01234567\n") +# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) +# define matrix_bitpop(i) bitpop(matrix[i]) +# define ROW_SHIFTER ((uint8_t)1) +#elif (MATRIX_COLS <= 16) +# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n") +# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row)) +# define matrix_bitpop(i) bitpop16(matrix[i]) +# define ROW_SHIFTER ((uint16_t)1) +#elif (MATRIX_COLS <= 32) +# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n") +# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row)) +# define matrix_bitpop(i) bitpop32(matrix[i]) +# define ROW_SHIFTER ((uint32_t)1) +#endif + +static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; + +static void select_row(uint8_t row) +{ + setPinOutput(row_pins[row]); + writePinLow(row_pins[row]); +} + +static void unselect_row(uint8_t row) +{ + setPinInputHigh(row_pins[row]); +} + +static void unselect_rows(void) +{ + for(uint8_t x = 0; x < MATRIX_ROWS; x++) { + setPinInputHigh(row_pins[x]); + } +} + +static void select_col(uint8_t col) +{ + setPinOutput(col_pins[col]); + writePinLow(col_pins[col]); +} + +static void unselect_col(uint8_t col) +{ + setPinInputHigh(col_pins[col]); +} + +static void unselect_cols(void) +{ + for(uint8_t x = 0; x < MATRIX_COLS; x++) { + setPinInputHigh(col_pins[x]); + } +} + +static void init_pins(void) { + unselect_rows(); + unselect_cols(); + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + setPinInputHigh(col_pins[x]); + } + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + setPinInputHigh(row_pins[x]); + } +} + +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) +{ + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[current_row]; + + // Clear data in matrix row + current_matrix[current_row] = 0; + + // Select row and wait for row selecton to stabilize + select_row(current_row); + wait_us(30); + + // For each col... + for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + + // Select the col pin to read (active low) + uint8_t pin_state = readPin(col_pins[col_index]); + + // Populate the matrix row with the state of the col pin + current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); + } + + // Unselect row + unselect_row(current_row); + + return (last_row_value != current_matrix[current_row]); +} + +static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) +{ + bool matrix_changed = false; + + // Select col and wait for col selecton to stabilize + select_col(current_col); + wait_us(30); + + // For each row... + for(uint8_t row_index = 0; row_index < MATRIX_ROWS/2; row_index++) + { + uint8_t tmp = row_index + MATRIX_ROWS/2; + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[tmp]; + + // Check row pin state + if (readPin(row_pins[row_index]) == 0) + { + // Pin LO, set col bit + current_matrix[tmp] |= (ROW_SHIFTER << current_col); + } + else + { + // Pin HI, clear col bit + current_matrix[tmp] &= ~(ROW_SHIFTER << current_col); + } + + // Determine if the matrix changed state + if ((last_row_value != current_matrix[tmp]) && !(matrix_changed)) + { + matrix_changed = true; + } + } + + // Unselect col + unselect_col(current_col); + + return matrix_changed; +} + +void matrix_init_custom(void) { + // initialize key pins + init_pins(); +} + +bool matrix_scan_custom(matrix_row_t current_matrix[]) +{ + bool changed = false; + + // Set row, read cols + for (uint8_t current_row = 0; current_row < MATRIX_ROWS / 2; current_row++) { + changed |= read_cols_on_row(current_matrix, current_row); + } + //else + // Set col, read rows + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + changed |= read_rows_on_col(current_matrix, current_col); + } + + return (uint8_t)changed; +} diff --git a/keyboards/aki27/cocot46plus/readme.md b/keyboards/aki27/cocot46plus/readme.md new file mode 100644 index 00000000000..60b9e443162 --- /dev/null +++ b/keyboards/aki27/cocot46plus/readme.md @@ -0,0 +1,50 @@ +# cocot46plus + +![cocot46plus_photo15](https://user-images.githubusercontent.com/88039287/171889114-53163c9f-4ef2-492d-b12b-7b6a23578bdf.jpg) + + +cocot46plus is a column-staggered keyboard with 46 keys, a 34mm-trackball and a rotary encoder. + +- Keyboard Maintainer: [markstos](https://github.com/markstos) +- Hardware Supported: cocot46plus PCB, ProMicro +- Hardware Availability: [BOOTH](https://aki27.booth.pm/items/3879034) + Go on sale in June 2022. + +Detailed information is available from the links below: + + - [JP](https://www.notion.so/aki27/cocot46plus-55775bf44a664dae9d6ca342e79e8312) + - [EN](https://aki27.notion.site/cocot46plus-Introduction-e6261b0a5ce045f8a0d8535a74844929) + +## Build Guides + + - [JP](https://github.com/aki27kbd/cocot46plus/blob/main/doc/buildguide.md) + - [EN](https://github.com/aki27kbd/cocot46plus/blob/main/doc/v1/buildguide_en.md) + +### Special keycodes + +Value | Keycode |Description +---------|-----------|----------- +`0x5DA7` | `CPI_SW` |Switch CPI +`0x5DA8` | `SCRL_SW` |Switch scroll divider +`0x5DA9` | `ROT_R15` |Rotate sensor coordinate by 15 degrees clockwise +`0x5DAA` | `ROT_L15` |Rotate sensor coordinate by 15 degrees counterclockwise +`0x5DAB` | `SCRL_MO` |Enable scroll mode while being pressed +`0x5DAC` | `SCRL_TO` |Toggle scroll mode. Once pushed, mouse mode and scroll mode are switched. +`0x5DAD` | `SCRL_IN` |Invert scroll direction + +# VIA Support + + * [aki27 provides VIA JSON files](https://github.com/aki27kbd/cocot46plus/tree/main/firmware) + + +### Gallery + +![cocot46plus_photo12](https://user-images.githubusercontent.com/88039287/170438554-630e1c55-a0de-4021-96c9-22d9bfee850e.jpg) + +![cocot46plus_photo14](https://user-images.githubusercontent.com/88039287/170669470-d258e0f5-6dba-4e6a-8008-43c8c6c1f1b2.jpg) + +![cocot46plus_photo05](https://user-images.githubusercontent.com/88039287/170669586-f97a07f9-cc3e-4ec8-8144-de095594974b.jpg) + +![cocot46plus_photo02](https://user-images.githubusercontent.com/88039287/170669653-933e0ebc-dbf4-4f3d-9d89-2d6171de5415.jpg) + +![cocot46plus_photo10](https://user-images.githubusercontent.com/88039287/170669715-810a73a1-d12f-4cf3-9f66-493bf0615beb.jpg) diff --git a/keyboards/aki27/cocot46plus/rules.mk b/keyboards/aki27/cocot46plus/rules.mk new file mode 100644 index 00000000000..67010d4a716 --- /dev/null +++ b/keyboards/aki27/cocot46plus/rules.mk @@ -0,0 +1,6 @@ + + +# Not sure how to translate these into keyboard.json +SRC += matrix.c +POINTING_DEVICE_DRIVER = adns5050 +OLED_DRIVER = ssd1306 From aa62687d3b70c343d46fe3ab3617e0a608a572f7 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Mon, 10 Jun 2024 21:50:42 -0400 Subject: [PATCH 02/28] Apply suggestions from code review Co-authored-by: Joel Challis Co-authored-by: jack <0x6a73@protonmail.com> --- keyboards/aki27/cocot46plus/cocot46plus.h | 2 -- keyboards/aki27/cocot46plus/keyboard.json | 22 ++----------------- .../cocot46plus/keymaps/default/keymap.c | 3 --- keyboards/aki27/cocot46plus/rules.mk | 4 ---- 4 files changed, 2 insertions(+), 29 deletions(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.h b/keyboards/aki27/cocot46plus/cocot46plus.h index c22ea029fff..e0f530dff63 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.h +++ b/keyboards/aki27/cocot46plus/cocot46plus.h @@ -56,8 +56,6 @@ enum cocot_keycodes { #define SCRL_TO QK_USER_5 #define SCRL_IN QK_USER_6 -bool encoder_update_user(uint8_t index, bool clockwise); -bool encoder_update_kb(uint8_t index, bool clockwise); bool cocot_get_scroll_mode(void); void cocot_set_scroll_mode(bool mode); diff --git a/keyboards/aki27/cocot46plus/keyboard.json b/keyboards/aki27/cocot46plus/keyboard.json index 2e919547095..1a35be8a1e7 100644 --- a/keyboards/aki27/cocot46plus/keyboard.json +++ b/keyboards/aki27/cocot46plus/keyboard.json @@ -8,32 +8,19 @@ "pid": "0x0003", "vid": "0x1727" }, - "processor": "atmega32u4", - "bootloader": "caterina", - "qmk": { - "locking": { - "enabled": false, - "resync": false - } - }, + "development_board": "promicro", "build": { "lto": true }, "features": { - "audio": false, - "backlight": false, "bootmagic": true, - "command": false, - "console": false, "encoder":true, "extrakey": true, "mousekey": true, - "nkro": false, "oled": true, "pointing_device": true, "rgblight": true }, - "debounce": 5, "matrix_pins": { "cols": ["F4", "F5", "F6", "F7", "B1", "B3"], "rows": ["D4", "C6", "D7", "E6", "NO_PIN"], @@ -55,12 +42,9 @@ "ws2812": { "pin": "B6" }, - "tapping": { - "term": 200, - }, "encoder": { "rotary": [ - { "pin_a": "D3", "pin_b": "D2", "resolution": 4 } + { "pin_a": "D3", "pin_b": "D2"} ] }, "rgblight": { @@ -73,9 +57,7 @@ "static_gradient": true, "twinkle": true, }, - "brightness_steps": 17, "hue_steps": 10, - "saturation_steps": 17, "max_brightness": 120, }, "layouts": { diff --git a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c index 55a2eda90b5..cb5f61f3266 100644 --- a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c +++ b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c @@ -16,9 +16,6 @@ along with this program. If not, see . */ #include QMK_KEYBOARD_H -#include -#include "quantum.h" - // Defines names for use in layer keycodes and the keymap enum layer_number { diff --git a/keyboards/aki27/cocot46plus/rules.mk b/keyboards/aki27/cocot46plus/rules.mk index 67010d4a716..f92348b1dd3 100644 --- a/keyboards/aki27/cocot46plus/rules.mk +++ b/keyboards/aki27/cocot46plus/rules.mk @@ -1,6 +1,2 @@ - - -# Not sure how to translate these into keyboard.json SRC += matrix.c POINTING_DEVICE_DRIVER = adns5050 -OLED_DRIVER = ssd1306 From 828e315899ca19f2333d97a0983235303dcf8985 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Tue, 11 Jun 2024 08:49:37 -0400 Subject: [PATCH 03/28] remove unnecessary custom_lite key --- keyboards/aki27/cocot46plus/keyboard.json | 1 - 1 file changed, 1 deletion(-) diff --git a/keyboards/aki27/cocot46plus/keyboard.json b/keyboards/aki27/cocot46plus/keyboard.json index 1a35be8a1e7..10a01ba8e4c 100644 --- a/keyboards/aki27/cocot46plus/keyboard.json +++ b/keyboards/aki27/cocot46plus/keyboard.json @@ -25,7 +25,6 @@ "cols": ["F4", "F5", "F6", "F7", "B1", "B3"], "rows": ["D4", "C6", "D7", "E6", "NO_PIN"], "custom": true, - "custom_lite": true, "direct": [ [ "A00", "A01", "A02", "A03", "A04", "A05" ], [ "A10", "A11", "A12", "A13", "A14", "A15" ], From 804ec15ee935ff8dc82b290245bc1c8429361bb6 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Tue, 11 Jun 2024 08:50:12 -0400 Subject: [PATCH 04/28] encoders: use encoder_map instead of custom code --- .../cocot46plus/keymaps/default/keymap.c | 61 ++++--------------- 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c index cb5f61f3266..df3c4e4ba12 100644 --- a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c +++ b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c @@ -30,6 +30,7 @@ enum layer_number { #define RS_HENK LT(2,KC_INT4) // raise #define DEL_ALT ALT_T(KC_DEL) +// In the buttom row, KC_MS_BTN3 binds middle-click to the encoder's button press const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [_BASE] = LAYOUT( //|-------------------------------------------------------| |-------------------------------------------------------| @@ -40,7 +41,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_MINS, //|-------------------------------------------------------| |-------------------------------------------------------| KC_LGUI, DEL_ALT, LW_MHEN, KC_SPC, KC_MS_BTN1, KC_MS_BTN2, KC_ENT, RS_HENK, KC_BSPC, KC_ESC, - KC_PGUP, KC_MS_BTN3, KC_PGDN, XXXXXXX, XXXXXXX, XXXXXXX + XXXXXXX, KC_MS_BTN3, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX //`--------------' `--------------' ), [_LOWER] = LAYOUT( @@ -52,7 +53,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_LSFT, KC_GRV, KC_TILD, KC_NUBS, KC_PIPE, XXXXXXX, KC_EQL, KC_PLUS, KC_LABK, KC_RABK, KC_QUES, KC_UNDS, //|-------------------------------------------------------| |-------------------------------------------------------| KC_LGUI, DEL_ALT, KC_TRNS, KC_SPC, KC_MS_BTN4, KC_MS_BTN5, KC_ENT, TT(3), KC_BSPC, KC_ESC, - KC_PGUP, KC_MS_BTN3, KC_PGDN, XXXXXXX, XXXXXXX, XXXXXXX + XXXXXXX, KC_MS_BTN3, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX //`--------------' `--------------' ), [_RAISE] = LAYOUT( @@ -64,7 +65,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_LSFT, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_LEFT, KC_DOWN, KC_RGHT, KC_DOT, KC_SLSH, KC_MINS, //|-------------------------------------------------------| |-------------------------------------------------------| KC_LGUI, DEL_ALT, TT(3), KC_SPC, KC_MS_BTN4, KC_MS_BTN5, KC_ENT, KC_TRNS, KC_BSPC, KC_ESC, - KC_PGUP, KC_MS_BTN3, KC_PGDN, XXXXXXX, XXXXXXX, XXXXXXX + XXXXXXX, KC_MS_BTN3, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX //`--------------' `--------------' ), [_TRACKBALL] = LAYOUT( @@ -76,55 +77,20 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { XXXXXXX, XXXXXXX, RGB_VAD, RGB_SAD, RGB_HUD,RGB_RMOD, SCRL_IN, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, //|-------------------------------------------------------| |-------------------------------------------------------| KC_LGUI, DEL_ALT, KC_TRNS, KC_SPC, KC_MS_BTN1, KC_MS_BTN2, KC_ENT, RS_HENK, KC_BSPC, KC_ESC, - KC_PGUP, KC_MS_BTN3, KC_PGDN, XXXXXXX, XXXXXXX, XXXXXXX + XXXXXXX, KC_MS_BTN3, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX //`--------------' `--------------' ) }; -keyevent_t encoder1_ccw = { - .key = (keypos_t){.row = 4, .col = 2}, - .pressed = false +// Same function on all layers for now. +#if defined(ENCODER_MAP_ENABLE) +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { + [0] = { ENCODER_CCW_CW(KC_PGUP, KC_PGDN) }, + [1] = { ENCODER_CCW_CW(KC_PGUP, KC_PGDN) }, + [2] = { ENCODER_CCW_CW(KC_PGUP, KC_PGDN) }, + [3] = { ENCODER_CCW_CW(KC_PGUP, KC_PGDN) }, }; - -keyevent_t encoder1_cw = { - .key = (keypos_t){.row = 4, .col = 5}, - .pressed = false -}; - -bool encoder_update_user(uint8_t index, bool clockwise) { - if (index == 0) { /* First encoder */ - if (clockwise) { - encoder1_cw.pressed = true; - encoder1_cw.time = (timer_read() | 1); - action_exec(encoder1_cw); - } else { - encoder1_ccw.pressed = true; - encoder1_ccw.time = (timer_read() | 1); - action_exec(encoder1_ccw); - } - } - - return true; -} - - -void matrix_scan_user(void) { - - if (encoder1_ccw.pressed) { - encoder1_ccw.pressed = false; - encoder1_ccw.time = (timer_read() | 1); - action_exec(encoder1_ccw); - } - - if (encoder1_cw.pressed) { - encoder1_cw.pressed = false; - encoder1_cw.time = (timer_read() | 1); - action_exec(encoder1_cw); - } - -} - - +#endif layer_state_t layer_state_set_user(layer_state_t state) { switch (get_highest_layer(state)) { @@ -157,4 +123,3 @@ bool oled_task_user(void) { return false; } #endif - From 520f74fc3940286aa528f0fe850856a65e79b6d9 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Wed, 12 Jun 2024 21:35:59 -0400 Subject: [PATCH 05/28] simplify layer definitions Co-authored-by: Ryan --- keyboards/aki27/cocot46plus/keymaps/default/keymap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c index df3c4e4ba12..602e6fa8bd7 100644 --- a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c +++ b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c @@ -19,10 +19,10 @@ along with this program. If not, see . // Defines names for use in layer keycodes and the keymap enum layer_number { - _BASE = 0, - _LOWER = 1, - _RAISE = 2, - _TRACKBALL = 3, + _BASE, + _LOWER, + _RAISE, + _TRACKBALL }; From c973d682ce4f4086d54b1f4095c8bf66406b5313 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Wed, 12 Jun 2024 21:39:27 -0400 Subject: [PATCH 06/28] minimize includes in cocot46plus.c Co-authored-by: Ryan --- keyboards/aki27/cocot46plus/cocot46plus.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index 1245ad2c554..46170597a00 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -15,12 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "quantum.h" -#include #include "cocot46plus.h" -#include "wait.h" -#include "debug.h" -#include +#include // Invert vertical scroll direction #ifndef COCOT_SCROLL_INV_DEFAULT From 3ff7fcced586bbf138f5012642e8b30f70a74f7a Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Wed, 12 Jun 2024 21:42:49 -0400 Subject: [PATCH 07/28] code review suggestions: use alternate functions in matrix.c Co-authored-by: Ryan --- keyboards/aki27/cocot46plus/matrix.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/keyboards/aki27/cocot46plus/matrix.c b/keyboards/aki27/cocot46plus/matrix.c index 57cbdab3945..4abe8797ed8 100644 --- a/keyboards/aki27/cocot46plus/matrix.c +++ b/keyboards/aki27/cocot46plus/matrix.c @@ -39,37 +39,37 @@ static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; static void select_row(uint8_t row) { - setPinOutput(row_pins[row]); - writePinLow(row_pins[row]); + gpio_set_pin_output(row_pins[row]); + gpio_write_pin_low(row_pins[row]); } static void unselect_row(uint8_t row) { - setPinInputHigh(row_pins[row]); + gpio_set_pin_input_high(row_pins[row]); } static void unselect_rows(void) { for(uint8_t x = 0; x < MATRIX_ROWS; x++) { - setPinInputHigh(row_pins[x]); + gpio_set_pin_input_high(row_pins[x]); } } static void select_col(uint8_t col) { - setPinOutput(col_pins[col]); - writePinLow(col_pins[col]); + gpio_set_pin_output(col_pins[col]); + gpio_write_pin_low(col_pins[col]); } static void unselect_col(uint8_t col) { - setPinInputHigh(col_pins[col]); + gpio_set_pin_input_high(col_pins[col]); } static void unselect_cols(void) { for(uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinInputHigh(col_pins[x]); + gpio_set_pin_input_high(col_pins[x]); } } @@ -77,10 +77,10 @@ static void init_pins(void) { unselect_rows(); unselect_cols(); for (uint8_t x = 0; x < MATRIX_COLS; x++) { - setPinInputHigh(col_pins[x]); + gpio_set_pin_input_high(col_pins[x]); } for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - setPinInputHigh(row_pins[x]); + gpio_set_pin_input_high(row_pins[x]); } } @@ -100,7 +100,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { // Select the col pin to read (active low) - uint8_t pin_state = readPin(col_pins[col_index]); + uint8_t pin_state = gpio_read_pin(col_pins[col_index]); // Populate the matrix row with the state of the col pin current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); @@ -128,7 +128,7 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) matrix_row_t last_row_value = current_matrix[tmp]; // Check row pin state - if (readPin(row_pins[row_index]) == 0) + if (gpio_read_pin(row_pins[row_index]) == 0) { // Pin LO, set col bit current_matrix[tmp] |= (ROW_SHIFTER << current_col); From cd36b630281e2f8689293e08200fec532210065f Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Tue, 18 Jun 2024 21:12:56 -0400 Subject: [PATCH 08/28] refinements: right half no longer works After this round of refinements, the left half of keyboard and the pointing device work, but no keycodes are emitted from the right half at all. --- keyboards/aki27/cocot46plus/cocot46plus.c | 23 ++++++--------- keyboards/aki27/cocot46plus/cocot46plus.h | 22 -------------- keyboards/aki27/cocot46plus/config.h | 10 +++++++ keyboards/aki27/cocot46plus/keyboard.json | 29 +++++++------------ .../cocot46plus/keymaps/default/keymap.c | 1 - .../cocot46plus/keymaps/default/rules.mk | 1 - .../aki27/cocot46plus/layout-reference.md | 29 ------------------- keyboards/aki27/cocot46plus/matrix.c | 25 +++------------- keyboards/aki27/cocot46plus/readme.md | 16 ++++------ 9 files changed, 39 insertions(+), 117 deletions(-) delete mode 100644 keyboards/aki27/cocot46plus/keymaps/default/rules.mk delete mode 100644 keyboards/aki27/cocot46plus/layout-reference.md diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index 46170597a00..ed4751ca756 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -15,6 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include QMK_KEYBOARD_H #include "cocot46plus.h" #include @@ -235,18 +236,7 @@ void render_logo(void) { void oled_write_layer_state(void) { oled_write_P(PSTR(" "), false); - // int cpi = pointing_device_get_cpi(); - int cpi = cpi_array[cocot_config.cpi_idx]; - int scroll_div = scrl_div_array[cocot_config.scrl_div]; - int angle = angle_array[cocot_config.rotation_angle]; - char buf1[5]; - char buf2[3]; - char buf3[4]; - snprintf(buf1, 5, "%4d", cpi); - snprintf(buf2, 3, "%2d", scroll_div); - snprintf(buf3, 4, "%3d", angle); - switch (get_highest_layer(layer_state | default_layer_state)) { case 0: oled_write_P(PSTR("Base "), false); @@ -279,12 +269,17 @@ void oled_write_layer_state(void) { } else{ oled_write_P(PSTR("C"), false); } + + int cpi = cpi_array[cocot_config.cpi_idx]; + int scroll_div = scrl_div_array[cocot_config.scrl_div]; + int angle = angle_array[cocot_config.rotation_angle]; + oled_write_P(PSTR("/"), false); - oled_write(buf1, false); + oled_write(get_u16_str(cpi,' '), false); oled_write_P(PSTR("/"), false); - oled_write(buf2, false); + oled_write(get_u8_str(scroll_div,' '), false); oled_write_P(PSTR("/"), false); - oled_write(buf3, false); + oled_write(get_u16_str(angle,' '), false); } #endif diff --git a/keyboards/aki27/cocot46plus/cocot46plus.h b/keyboards/aki27/cocot46plus/cocot46plus.h index e0f530dff63..dba6ac69d9b 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.h +++ b/keyboards/aki27/cocot46plus/cocot46plus.h @@ -31,30 +31,8 @@ typedef union { }; } cocot_config_t; - - extern cocot_config_t cocot_config; -enum cocot_keycodes { - - COCOT_SAFE_RANGE = SAFE_RANGE, - CPI_SW, - SCRL_SW, - ROT_R15, - ROT_L15, - SCRL_MO, - SCRL_TO, - SCRL_IN, - -}; - -#define CPI_SW QK_USER_0 -#define SCRL_SW QK_USER_1 -#define ROT_R15 QK_USER_2 -#define ROT_L15 QK_USER_3 -#define SCRL_MO QK_USER_4 -#define SCRL_TO QK_USER_5 -#define SCRL_IN QK_USER_6 bool cocot_get_scroll_mode(void); void cocot_set_scroll_mode(bool mode); diff --git a/keyboards/aki27/cocot46plus/config.h b/keyboards/aki27/cocot46plus/config.h index e5806c38853..d8ffbd74f51 100644 --- a/keyboards/aki27/cocot46plus/config.h +++ b/keyboards/aki27/cocot46plus/config.h @@ -22,5 +22,15 @@ along with this program. If not, see . #define ADNS5050_SDIO_PIN B4 #define ADNS5050_CS_PIN B5 +/* key matrix size */ +#define MATRIX_ROWS 10 +#define MATRIX_COLS 6 + +// wiring of each half +#define MATRIX_ROW_PINS { D4, C6, D7, E6, NO_PIN } +#define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3 } + +#define DIODE_DIRECTION COL2ROW + #define POINTING_DEVICE_ROTATION_180 #define OLED_FONT_H "keyboards/aki27/cocot46plus/glcdfont.c" diff --git a/keyboards/aki27/cocot46plus/keyboard.json b/keyboards/aki27/cocot46plus/keyboard.json index 10a01ba8e4c..b8dd276056e 100644 --- a/keyboards/aki27/cocot46plus/keyboard.json +++ b/keyboards/aki27/cocot46plus/keyboard.json @@ -2,7 +2,7 @@ "keyboard_name": "cocot46plus", "manufacturer": "aki27", "maintainer": "markstos", - "tags": ["unibody","ergo","corne","trackball","encoder","rgb"] + "tags": ["unibody","ergo","corne","trackball","encoder","rgb"], "usb": { "device_version": "1.0.0", "pid": "0x0003", @@ -17,27 +17,9 @@ "encoder":true, "extrakey": true, "mousekey": true, - "oled": true, "pointing_device": true, "rgblight": true }, - "matrix_pins": { - "cols": ["F4", "F5", "F6", "F7", "B1", "B3"], - "rows": ["D4", "C6", "D7", "E6", "NO_PIN"], - "custom": true, - "direct": [ - [ "A00", "A01", "A02", "A03", "A04", "A05" ], - [ "A10", "A11", "A12", "A13", "A14", "A15" ], - [ "A20", "A21", "A22", "A23", "A24", "A25" ], - [ "A30", "A31", "A32", "A33", "A34", "A35" ], - [ null, null, "A42", null, null, "A45" ], - [ "B00", "B01", "B02", "B03", "B04", "B05" ], - [ "B10", "B11", "B12", "B13", "B14", "B15" ], - [ "B20", "B21", "B22", "B23", "B24", "B25" ], - [ "B30", "B31", "B32", "B33", "B34", "B35" ], - [ null, null, "B42", null, null, "B45" ] - ] - }, "ws2812": { "pin": "B6" }, @@ -59,6 +41,15 @@ "hue_steps": 10, "max_brightness": 120, }, + "keycodes":[ + {"key": "CPI_SW"}, + {"key": "SCRL_SW"}, + {"key": "ROT_R15"}, + {"key": "ROT_L15"}, + {"key": "SCRL_MO"}, + {"key": "SCRL_TO"}, + {"key": "SCRL_IN"} + ], "layouts": { "LAYOUT": { "layout": [ diff --git a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c index 602e6fa8bd7..099a067a94f 100644 --- a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c +++ b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c @@ -25,7 +25,6 @@ enum layer_number { _TRACKBALL }; - #define LW_MHEN LT(1,KC_INT5) // lower #define RS_HENK LT(2,KC_INT4) // raise #define DEL_ALT ALT_T(KC_DEL) diff --git a/keyboards/aki27/cocot46plus/keymaps/default/rules.mk b/keyboards/aki27/cocot46plus/keymaps/default/rules.mk deleted file mode 100644 index 9d2c49d933e..00000000000 --- a/keyboards/aki27/cocot46plus/keymaps/default/rules.mk +++ /dev/null @@ -1 +0,0 @@ -VIA_ENABLE = no diff --git a/keyboards/aki27/cocot46plus/layout-reference.md b/keyboards/aki27/cocot46plus/layout-reference.md deleted file mode 100644 index 8a58540efa4..00000000000 --- a/keyboards/aki27/cocot46plus/layout-reference.md +++ /dev/null @@ -1,29 +0,0 @@ - -This was the original layout definition showing how the physical key locations map -to the matrix grid. - -* A3 and B35 are the trackball keys -* A42, A34, A45 are for the encoder CCW, click and CW bindings - -The last three, B42, B34 and B45 don't seem to used. - -```` -define LAYOUT( \ - A00, A01, A02, A03, A04, A05, B05, B04, B03, B02, B01, B00, \ - A10, A11, A12, A13, A14, A15, B15, B14, B13, B12, B11, B10, \ - A20, A21, A22, A23, A24, A25, B25, B24, B23, B22, B21, B20, \ - A30, A31, A32, A33, A35, B35, B33, B32, B31, B30, \ - A42, A34, A45, B42, B34, B45 \ - ) \ - { \ - { A00, A01, A02, A03, A04, A05 }, \ - { A10, A11, A12, A13, A14, A15 }, \ - { A20, A21, A22, A23, A24, A25 }, \ - { A30, A31, A32, A33, A34, A35 }, \ - { KC_NO, KC_NO, A42, KC_NO, KC_NO, A45 }, \ - { B00, B01, B02, B03, B04, B05 }, \ - { B10, B11, B12, B13, B14, B15 }, \ - { B20, B21, B22, B23, B24, B25 }, \ - { B30, B31, B32, B33, B34, B35 }, \ - { KC_NO, KC_NO, B42, KC_NO, KC_NO, B45 } \ -``` diff --git a/keyboards/aki27/cocot46plus/matrix.c b/keyboards/aki27/cocot46plus/matrix.c index 4abe8797ed8..c5e93d9b76e 100644 --- a/keyboards/aki27/cocot46plus/matrix.c +++ b/keyboards/aki27/cocot46plus/matrix.c @@ -15,24 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "matrix.h" -#include "quantum.h" - -#if (MATRIX_COLS <= 8) -# define print_matrix_header() print("\nr/c 01234567\n") -# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop(matrix[i]) -# define ROW_SHIFTER ((uint8_t)1) -#elif (MATRIX_COLS <= 16) -# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n") -# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop16(matrix[i]) -# define ROW_SHIFTER ((uint16_t)1) -#elif (MATRIX_COLS <= 32) -# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n") -# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop32(matrix[i]) -# define ROW_SHIFTER ((uint32_t)1) -#endif +#include "wait.h" static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; @@ -103,7 +86,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) uint8_t pin_state = gpio_read_pin(col_pins[col_index]); // Populate the matrix row with the state of the col pin - current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); + current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); } // Unselect row @@ -131,12 +114,12 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) if (gpio_read_pin(row_pins[row_index]) == 0) { // Pin LO, set col bit - current_matrix[tmp] |= (ROW_SHIFTER << current_col); + current_matrix[tmp] |= (MATRIX_ROW_SHIFTER << current_col); } else { // Pin HI, clear col bit - current_matrix[tmp] &= ~(ROW_SHIFTER << current_col); + current_matrix[tmp] &= ~(MATRIX_ROW_SHIFTER << current_col); } // Determine if the matrix changed state diff --git a/keyboards/aki27/cocot46plus/readme.md b/keyboards/aki27/cocot46plus/readme.md index 60b9e443162..518fcef6b97 100644 --- a/keyboards/aki27/cocot46plus/readme.md +++ b/keyboards/aki27/cocot46plus/readme.md @@ -1,6 +1,6 @@ # cocot46plus -![cocot46plus_photo15](https://user-images.githubusercontent.com/88039287/171889114-53163c9f-4ef2-492d-b12b-7b6a23578bdf.jpg) +![cocot46plus_photo15](https://i.imgur.com/yCvbMgo.jpeg) cocot46plus is a column-staggered keyboard with 46 keys, a 34mm-trackball and a rotary encoder. @@ -39,12 +39,8 @@ Value | Keycode |Description ### Gallery -![cocot46plus_photo12](https://user-images.githubusercontent.com/88039287/170438554-630e1c55-a0de-4021-96c9-22d9bfee850e.jpg) - -![cocot46plus_photo14](https://user-images.githubusercontent.com/88039287/170669470-d258e0f5-6dba-4e6a-8008-43c8c6c1f1b2.jpg) - -![cocot46plus_photo05](https://user-images.githubusercontent.com/88039287/170669586-f97a07f9-cc3e-4ec8-8144-de095594974b.jpg) - -![cocot46plus_photo02](https://user-images.githubusercontent.com/88039287/170669653-933e0ebc-dbf4-4f3d-9d89-2d6171de5415.jpg) - -![cocot46plus_photo10](https://user-images.githubusercontent.com/88039287/170669715-810a73a1-d12f-4cf3-9f66-493bf0615beb.jpg) +![cocot46plus_photo12](https://i.imgur.com/hPOB98H.jpeg) +![cocot46plus_photo14](https://i.imgur.com/HrtI9w1.jpeg) +![cocot46plus_photo05](https://i.imgur.com/LOcxHIV.jpeg) +![cocot46plus_photo02](https://i.imgur.com/b5O9tKq.jpeg) +![cocot46plus_photo10](https://i.imgur.com/gDx5e64.jpeg) From b6ae3bf23ce41091ff87b5d224103da99e4e7a43 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Thu, 20 Jun 2024 09:51:22 -0400 Subject: [PATCH 09/28] fixup: remove unnecesssary header include --- keyboards/aki27/cocot46plus/cocot46plus.c | 1 - 1 file changed, 1 deletion(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index ed4751ca756..8645452e1e3 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -16,7 +16,6 @@ along with this program. If not, see . */ #include QMK_KEYBOARD_H -#include "cocot46plus.h" #include // Invert vertical scroll direction From 9a3182015a328734af73ccbbf51b3f6448786398 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Thu, 20 Jun 2024 09:52:01 -0400 Subject: [PATCH 10/28] fixup: remove apparently unnecessary MOUSEKEY section and re-indent --- keyboards/aki27/cocot46plus/cocot46plus.c | 83 ++++++++++------------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index 8645452e1e3..fb8e79fab95 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -131,56 +131,47 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { if (!process_record_user(keycode, record)) return false; switch (keycode) { -#ifndef MOUSEKEY_ENABLE - // process KC_MS_BTN1~8 by myself - // See process_action() in quantum/action.c for details. - case KC_MS_BTN1 ... KC_MS_BTN8: { - extern void register_button(bool, enum mouse_buttons); - register_button(record->event.pressed, MOUSE_BTN_MASK(keycode - KC_MS_BTN1)); - return false; + if (keycode == CPI_SW && record->event.pressed) { + cocot_config.cpi_idx = (cocot_config.cpi_idx + 1) % CPI_OPTION_SIZE; + eeconfig_update_kb(cocot_config.raw); + pointing_device_set_cpi(cpi_array[cocot_config.cpi_idx]); } -#endif + if (keycode == SCRL_SW && record->event.pressed) { + cocot_config.scrl_div = (cocot_config.scrl_div + 1) % SCRL_DIV_SIZE; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == ROT_R15 && record->event.pressed) { + cocot_config.rotation_angle = (cocot_config.rotation_angle + 1) % ANGLE_SIZE; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == ROT_L15 && record->event.pressed) { + cocot_config.rotation_angle = (ANGLE_SIZE + cocot_config.rotation_angle - 1) % ANGLE_SIZE; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == SCRL_IN && record->event.pressed) { + cocot_config.scrl_inv = -cocot_config.scrl_inv; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == SCRL_TO && record->event.pressed) { + { + cocot_config.scrl_mode ^= 1; + } + } + + if (keycode == SCRL_MO) { + { + cocot_config.scrl_mode ^= 1; + } + } + + return true; } - if (keycode == CPI_SW && record->event.pressed) { - cocot_config.cpi_idx = (cocot_config.cpi_idx + 1) % CPI_OPTION_SIZE; - eeconfig_update_kb(cocot_config.raw); - pointing_device_set_cpi(cpi_array[cocot_config.cpi_idx]); - } - - if (keycode == SCRL_SW && record->event.pressed) { - cocot_config.scrl_div = (cocot_config.scrl_div + 1) % SCRL_DIV_SIZE; - eeconfig_update_kb(cocot_config.raw); - } - - if (keycode == ROT_R15 && record->event.pressed) { - cocot_config.rotation_angle = (cocot_config.rotation_angle + 1) % ANGLE_SIZE; - eeconfig_update_kb(cocot_config.raw); - } - - if (keycode == ROT_L15 && record->event.pressed) { - cocot_config.rotation_angle = (ANGLE_SIZE + cocot_config.rotation_angle - 1) % ANGLE_SIZE; - eeconfig_update_kb(cocot_config.raw); - } - - if (keycode == SCRL_IN && record->event.pressed) { - cocot_config.scrl_inv = - cocot_config.scrl_inv; - eeconfig_update_kb(cocot_config.raw); - } - - if (keycode == SCRL_TO && record->event.pressed) { - { cocot_config.scrl_mode ^= 1; } - } - - if (keycode == SCRL_MO) { - { cocot_config.scrl_mode ^= 1; } - } - - return true; -} - - void eeconfig_init_kb(void) { cocot_config.cpi_idx = COCOT_CPI_DEFAULT; cocot_config.scrl_div = COCOT_SCROLL_DIV_DEFAULT; From 65adcb3656dacfde39a7711ab42ec354cb4e6847 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Thu, 20 Jun 2024 09:52:29 -0400 Subject: [PATCH 11/28] fixup: remove necesesary DIODE_DIRECTION due to custom matrix code --- keyboards/aki27/cocot46plus/config.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/keyboards/aki27/cocot46plus/config.h b/keyboards/aki27/cocot46plus/config.h index d8ffbd74f51..684755a2166 100644 --- a/keyboards/aki27/cocot46plus/config.h +++ b/keyboards/aki27/cocot46plus/config.h @@ -30,7 +30,5 @@ along with this program. If not, see . #define MATRIX_ROW_PINS { D4, C6, D7, E6, NO_PIN } #define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3 } -#define DIODE_DIRECTION COL2ROW - #define POINTING_DEVICE_ROTATION_180 #define OLED_FONT_H "keyboards/aki27/cocot46plus/glcdfont.c" From b2f50528e6126a748eb6374f7f18e636a0bf0de8 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Thu, 20 Jun 2024 09:53:03 -0400 Subject: [PATCH 12/28] docs: Refine docs --- keyboards/aki27/cocot46plus/readme.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/keyboards/aki27/cocot46plus/readme.md b/keyboards/aki27/cocot46plus/readme.md index 518fcef6b97..0a846f598d7 100644 --- a/keyboards/aki27/cocot46plus/readme.md +++ b/keyboards/aki27/cocot46plus/readme.md @@ -7,8 +7,7 @@ cocot46plus is a column-staggered keyboard with 46 keys, a 34mm-trackball and a - Keyboard Maintainer: [markstos](https://github.com/markstos) - Hardware Supported: cocot46plus PCB, ProMicro -- Hardware Availability: [BOOTH](https://aki27.booth.pm/items/3879034) - Go on sale in June 2022. +- Hardware Availability: [Yushakobo.jp](https://shop.yushakobo.jp/en/products/6955) Detailed information is available from the links below: @@ -24,8 +23,8 @@ Detailed information is available from the links below: Value | Keycode |Description ---------|-----------|----------- -`0x5DA7` | `CPI_SW` |Switch CPI -`0x5DA8` | `SCRL_SW` |Switch scroll divider +`0x5DA7` | `CPI_SW` |Switch CPI. Low for precision, high for large movements. +`0x5DA8` | `SCRL_SW` |Switch scroll divider. Larger value equals smaller scroll motion `0x5DA9` | `ROT_R15` |Rotate sensor coordinate by 15 degrees clockwise `0x5DAA` | `ROT_L15` |Rotate sensor coordinate by 15 degrees counterclockwise `0x5DAB` | `SCRL_MO` |Enable scroll mode while being pressed From c0217b2fecf1a8693ea2fcb5f73cb8f7efa81280 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Thu, 20 Jun 2024 09:53:19 -0400 Subject: [PATCH 13/28] Re-enable OLED. Was not working before. But now it displays a random pattern instead of soemthing useful --- keyboards/aki27/cocot46plus/keyboard.json | 1 + 1 file changed, 1 insertion(+) diff --git a/keyboards/aki27/cocot46plus/keyboard.json b/keyboards/aki27/cocot46plus/keyboard.json index b8dd276056e..295b1f05585 100644 --- a/keyboards/aki27/cocot46plus/keyboard.json +++ b/keyboards/aki27/cocot46plus/keyboard.json @@ -17,6 +17,7 @@ "encoder":true, "extrakey": true, "mousekey": true, + "oled": true, "pointing_device": true, "rgblight": true }, From 3fd506068c4cf03c5c377add2052d29c7f99a910 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Thu, 20 Jun 2024 09:54:03 -0400 Subject: [PATCH 14/28] fixup: make sure custom matrix code is loaded --- keyboards/aki27/cocot46plus/rules.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/keyboards/aki27/cocot46plus/rules.mk b/keyboards/aki27/cocot46plus/rules.mk index f92348b1dd3..b6069b77376 100644 --- a/keyboards/aki27/cocot46plus/rules.mk +++ b/keyboards/aki27/cocot46plus/rules.mk @@ -1,2 +1,3 @@ SRC += matrix.c +CUSTOM_MATRIX = lite POINTING_DEVICE_DRIVER = adns5050 From 38ed4a10eba4210209bfd2ff478f5b15ac196f2e Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Thu, 20 Jun 2024 21:46:10 -0400 Subject: [PATCH 15/28] refinemts: OLED is working better, but new problems. Now the OLED display is no longer scrambled, but there are two new problems with it: 1. The number "506" is printed over the design 2. The screen never refreshes. As originally submitted, the OLED would update to reflect layer changes. --- keyboards/aki27/cocot46plus/cocot46plus.c | 85 ++++++++++--------- keyboards/aki27/cocot46plus/keyboard.json | 2 +- .../cocot46plus/keymaps/default/keymap.c | 10 +++ keyboards/aki27/cocot46plus/rules.mk | 2 + 4 files changed, 56 insertions(+), 43 deletions(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index fb8e79fab95..5d9b8ea0a65 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -128,50 +128,51 @@ report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { bool process_record_kb(uint16_t keycode, keyrecord_t* record) { // 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; - - switch (keycode) { - if (keycode == CPI_SW && record->event.pressed) { - cocot_config.cpi_idx = (cocot_config.cpi_idx + 1) % CPI_OPTION_SIZE; - eeconfig_update_kb(cocot_config.raw); - pointing_device_set_cpi(cpi_array[cocot_config.cpi_idx]); - } - - if (keycode == SCRL_SW && record->event.pressed) { - cocot_config.scrl_div = (cocot_config.scrl_div + 1) % SCRL_DIV_SIZE; - eeconfig_update_kb(cocot_config.raw); - } - - if (keycode == ROT_R15 && record->event.pressed) { - cocot_config.rotation_angle = (cocot_config.rotation_angle + 1) % ANGLE_SIZE; - eeconfig_update_kb(cocot_config.raw); - } - - if (keycode == ROT_L15 && record->event.pressed) { - cocot_config.rotation_angle = (ANGLE_SIZE + cocot_config.rotation_angle - 1) % ANGLE_SIZE; - eeconfig_update_kb(cocot_config.raw); - } - - if (keycode == SCRL_IN && record->event.pressed) { - cocot_config.scrl_inv = -cocot_config.scrl_inv; - eeconfig_update_kb(cocot_config.raw); - } - - if (keycode == SCRL_TO && record->event.pressed) { - { - cocot_config.scrl_mode ^= 1; - } - } - - if (keycode == SCRL_MO) { - { - cocot_config.scrl_mode ^= 1; - } - } - - return true; + if (!process_record_user(keycode, record)) { + return false; } + if (keycode == CPI_SW && record->event.pressed) { + cocot_config.cpi_idx = (cocot_config.cpi_idx + 1) % CPI_OPTION_SIZE; + eeconfig_update_kb(cocot_config.raw); + pointing_device_set_cpi(cpi_array[cocot_config.cpi_idx]); + } + + if (keycode == SCRL_SW && record->event.pressed) { + cocot_config.scrl_div = (cocot_config.scrl_div + 1) % SCRL_DIV_SIZE; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == ROT_R15 && record->event.pressed) { + cocot_config.rotation_angle = (cocot_config.rotation_angle + 1) % ANGLE_SIZE; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == ROT_L15 && record->event.pressed) { + cocot_config.rotation_angle = (ANGLE_SIZE + cocot_config.rotation_angle - 1) % ANGLE_SIZE; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == SCRL_IN && record->event.pressed) { + cocot_config.scrl_inv = -cocot_config.scrl_inv; + eeconfig_update_kb(cocot_config.raw); + } + + if (keycode == SCRL_TO && record->event.pressed) { + { + cocot_config.scrl_mode ^= 1; + } + } + + if (keycode == SCRL_MO) { + { + cocot_config.scrl_mode ^= 1; + } + } + + return true; +} + void eeconfig_init_kb(void) { cocot_config.cpi_idx = COCOT_CPI_DEFAULT; cocot_config.scrl_div = COCOT_SCROLL_DIV_DEFAULT; diff --git a/keyboards/aki27/cocot46plus/keyboard.json b/keyboards/aki27/cocot46plus/keyboard.json index 295b1f05585..9ed3db6a060 100644 --- a/keyboards/aki27/cocot46plus/keyboard.json +++ b/keyboards/aki27/cocot46plus/keyboard.json @@ -14,7 +14,7 @@ }, "features": { "bootmagic": true, - "encoder":true, + "encoder": true, "extrakey": true, "mousekey": true, "oled": true, diff --git a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c index 099a067a94f..02c9110219d 100644 --- a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c +++ b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c @@ -94,23 +94,33 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { layer_state_t layer_state_set_user(layer_state_t state) { switch (get_highest_layer(state)) { case _LOWER: + #ifdef RGBLIGHT_ENABLE rgblight_sethsv_range(HSV_BLUE, 0, 2); + #endif cocot_set_scroll_mode(true); break; case _RAISE: + #ifdef RGBLIGHT_ENABLE rgblight_sethsv_range(HSV_RED, 0, 2); + #endif cocot_set_scroll_mode(true); break; case _TRACKBALL: + #ifdef RGBLIGHT_ENABLE rgblight_sethsv_range(HSV_GREEN, 0, 2); + #endif cocot_set_scroll_mode(false); break; default: + #ifdef RGBLIGHT_ENABLE rgblight_sethsv_range( 0, 0, 0, 0, 2); + #endif cocot_set_scroll_mode(false); break; } + #ifdef RGBLIGHT_ENABLE rgblight_set_effect_range( 2, 10); + #endif return state; }; diff --git a/keyboards/aki27/cocot46plus/rules.mk b/keyboards/aki27/cocot46plus/rules.mk index b6069b77376..bd106213001 100644 --- a/keyboards/aki27/cocot46plus/rules.mk +++ b/keyboards/aki27/cocot46plus/rules.mk @@ -1,3 +1,5 @@ SRC += matrix.c CUSTOM_MATRIX = lite POINTING_DEVICE_DRIVER = adns5050 +# NO room in firmware +SPACE_CADET_ENABLE = no From 554dc6bc0bcf1c419e7f3aa79b7e4a1417f0a15f Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Wed, 17 Jul 2024 09:48:38 -0400 Subject: [PATCH 16/28] fixup: comment, whitespace --- keyboards/aki27/cocot46plus/cocot46plus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index 5d9b8ea0a65..1ca35040c40 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -23,6 +23,9 @@ along with this program. If not, see . # define COCOT_SCROLL_INV_DEFAULT 1 #endif +// All the default values here refer to O-based array indexes +// not actual values + #ifndef COCOT_CPI_OPTIONS # define COCOT_CPI_OPTIONS { 250, 500, 750, 1000, 1250 } #endif @@ -70,7 +73,6 @@ void pointing_device_init_kb(void) { adns5050_write_reg(0x22, 0b10000 | 0x80); } - report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { double rad = angle_array[cocot_config.rotation_angle] * (M_PI / 180) * -1; @@ -123,8 +125,6 @@ report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { return pointing_device_task_user(mouse_report); } - - bool process_record_kb(uint16_t keycode, keyrecord_t* record) { // xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed); @@ -227,7 +227,7 @@ void render_logo(void) { void oled_write_layer_state(void) { oled_write_P(PSTR(" "), false); - + switch (get_highest_layer(layer_state | default_layer_state)) { case 0: oled_write_P(PSTR("Base "), false); From f56cf311cde165c2da855166681f9732e6a89235 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Wed, 17 Jul 2024 09:49:45 -0400 Subject: [PATCH 17/28] BugFixes: Typing, switch to RP2040 & sprintf - The angle of -30 was not displaying correctly with unsigned type - Explicitly cast a result to a double for consistent typing - The code without snprintf didn't work. Revert to snprintf, but also switch to RP2040 which has room for it. --- keyboards/aki27/cocot46plus/cocot46plus.c | 21 ++++++++++++--------- keyboards/aki27/cocot46plus/readme.md | 2 +- keyboards/aki27/cocot46plus/rules.mk | 4 +++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index 1ca35040c40..3ee10e5994d 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -52,10 +52,10 @@ along with this program. If not, see . cocot_config_t cocot_config; uint16_t cpi_array[] = COCOT_CPI_OPTIONS; uint16_t scrl_div_array[] = COCOT_SCROLL_DIVIDERS; -uint16_t angle_array[] = COCOT_ROTATION_ANGLE; +int8_t angle_array[] = COCOT_ROTATION_ANGLE; #define CPI_OPTION_SIZE (sizeof(cpi_array) / sizeof(uint16_t)) #define SCRL_DIV_SIZE (sizeof(scrl_div_array) / sizeof(uint16_t)) -#define ANGLE_SIZE (sizeof(angle_array) / sizeof(uint16_t)) +#define ANGLE_SIZE (sizeof(angle_array) / sizeof(int8_t)) // Trackball State @@ -75,7 +75,7 @@ void pointing_device_init_kb(void) { report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { - double rad = angle_array[cocot_config.rotation_angle] * (M_PI / 180) * -1; + double rad = (double)angle_array[cocot_config.rotation_angle] * (M_PI / 180) * -1; int8_t x_rev = + mouse_report.x * cos(rad) - mouse_report.y * sin(rad); int8_t y_rev = + mouse_report.x * sin(rad) + mouse_report.y * cos(rad); @@ -261,16 +261,19 @@ void oled_write_layer_state(void) { oled_write_P(PSTR("C"), false); } - int cpi = cpi_array[cocot_config.cpi_idx]; - int scroll_div = scrl_div_array[cocot_config.scrl_div]; - int angle = angle_array[cocot_config.rotation_angle]; + char cpi[5]; + char scroll_div[3]; + char angle[4]; + snprintf(cpi, 5, "%4d", cpi_array[cocot_config.cpi_idx]); + snprintf(scroll_div, 3, "%2d", scrl_div_array[cocot_config.scrl_div]); + snprintf(angle, 4, "%3d", angle_array[cocot_config.rotation_angle]); oled_write_P(PSTR("/"), false); - oled_write(get_u16_str(cpi,' '), false); + oled_write(cpi, false); oled_write_P(PSTR("/"), false); - oled_write(get_u8_str(scroll_div,' '), false); + oled_write(scroll_div, false); oled_write_P(PSTR("/"), false); - oled_write(get_u16_str(angle,' '), false); + oled_write(angle, false); } #endif diff --git a/keyboards/aki27/cocot46plus/readme.md b/keyboards/aki27/cocot46plus/readme.md index 0a846f598d7..9e5058f46dc 100644 --- a/keyboards/aki27/cocot46plus/readme.md +++ b/keyboards/aki27/cocot46plus/readme.md @@ -6,7 +6,7 @@ cocot46plus is a column-staggered keyboard with 46 keys, a 34mm-trackball and a rotary encoder. - Keyboard Maintainer: [markstos](https://github.com/markstos) -- Hardware Supported: cocot46plus PCB, ProMicro +- Hardware Supported: cocot46plus PCB, SparkFun Pro Micro - RP2040 - Hardware Availability: [Yushakobo.jp](https://shop.yushakobo.jp/en/products/6955) Detailed information is available from the links below: diff --git a/keyboards/aki27/cocot46plus/rules.mk b/keyboards/aki27/cocot46plus/rules.mk index bd106213001..94a66b4ead4 100644 --- a/keyboards/aki27/cocot46plus/rules.mk +++ b/keyboards/aki27/cocot46plus/rules.mk @@ -1,5 +1,7 @@ SRC += matrix.c CUSTOM_MATRIX = lite POINTING_DEVICE_DRIVER = adns5050 -# NO room in firmware SPACE_CADET_ENABLE = no +# A regular Pro Micro may work if this line is removed +# but some features may need to be disabled for the firmware to fit in the storage. +CONVERT_TO=promicro_rp2040 From c26c021c46e0283adb52d00fe638ed5bb7973109 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Tue, 23 Jul 2024 10:13:16 -0400 Subject: [PATCH 18/28] WIP: getting rid of CONVERT_TO Encoder and lights are currently not working correctly. --- keyboards/aki27/cocot46plus/config.h | 13 ++++++------- keyboards/aki27/cocot46plus/keyboard.json | 11 ++++++++--- keyboards/aki27/cocot46plus/rules.mk | 3 --- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/keyboards/aki27/cocot46plus/config.h b/keyboards/aki27/cocot46plus/config.h index 684755a2166..a6154485190 100644 --- a/keyboards/aki27/cocot46plus/config.h +++ b/keyboards/aki27/cocot46plus/config.h @@ -18,17 +18,16 @@ along with this program. If not, see . #pragma once // These do not seem to have keyboard.json support yet. -#define ADNS5050_SCLK_PIN B2 -#define ADNS5050_SDIO_PIN B4 -#define ADNS5050_CS_PIN B5 +#define ADNS5050_SCLK_PIN 23U +#define ADNS5050_SDIO_PIN 8U +#define ADNS5050_CS_PIN 9U + +#define I2C1_SDA_PIN GP2 +#define I2C1_SCL_PIN GP3 /* key matrix size */ #define MATRIX_ROWS 10 #define MATRIX_COLS 6 -// wiring of each half -#define MATRIX_ROW_PINS { D4, C6, D7, E6, NO_PIN } -#define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3 } - #define POINTING_DEVICE_ROTATION_180 #define OLED_FONT_H "keyboards/aki27/cocot46plus/glcdfont.c" diff --git a/keyboards/aki27/cocot46plus/keyboard.json b/keyboards/aki27/cocot46plus/keyboard.json index 9ed3db6a060..bef9b599177 100644 --- a/keyboards/aki27/cocot46plus/keyboard.json +++ b/keyboards/aki27/cocot46plus/keyboard.json @@ -8,7 +8,11 @@ "pid": "0x0003", "vid": "0x1727" }, - "development_board": "promicro", + "development_board": "promicro_rp2040", + "matrix_pins": { + "cols": ["GP29", "GP28", "GP27", "GP26", "GP22", "GP20"], + "rows": ["GP4", "GP5", "GP6", "GP7", "NO_PIN"] + }, "build": { "lto": true }, @@ -22,11 +26,12 @@ "rgblight": true }, "ws2812": { - "pin": "B6" + "pin": "GP7", + "driver": "vendor" }, "encoder": { "rotary": [ - { "pin_a": "D3", "pin_b": "D2"} + { "pin_a": "GP0", "pin_b": "GP0"} ] }, "rgblight": { diff --git a/keyboards/aki27/cocot46plus/rules.mk b/keyboards/aki27/cocot46plus/rules.mk index 94a66b4ead4..2fda4c7226b 100644 --- a/keyboards/aki27/cocot46plus/rules.mk +++ b/keyboards/aki27/cocot46plus/rules.mk @@ -2,6 +2,3 @@ SRC += matrix.c CUSTOM_MATRIX = lite POINTING_DEVICE_DRIVER = adns5050 SPACE_CADET_ENABLE = no -# A regular Pro Micro may work if this line is removed -# but some features may need to be disabled for the firmware to fit in the storage. -CONVERT_TO=promicro_rp2040 From 7571b3ed514944fd3cf6874b1a276367a11571b8 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Tue, 23 Jul 2024 14:52:13 -0400 Subject: [PATCH 19/28] Update config.h Co-authored-by: Joel Challis --- keyboards/aki27/cocot46plus/config.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keyboards/aki27/cocot46plus/config.h b/keyboards/aki27/cocot46plus/config.h index a6154485190..357f5e14765 100644 --- a/keyboards/aki27/cocot46plus/config.h +++ b/keyboards/aki27/cocot46plus/config.h @@ -18,9 +18,9 @@ along with this program. If not, see . #pragma once // These do not seem to have keyboard.json support yet. -#define ADNS5050_SCLK_PIN 23U -#define ADNS5050_SDIO_PIN 8U -#define ADNS5050_CS_PIN 9U +#define ADNS5050_SCLK_PIN GP23 +#define ADNS5050_SDIO_PIN GP8 +#define ADNS5050_CS_PIN GP9 #define I2C1_SDA_PIN GP2 #define I2C1_SCL_PIN GP3 From 0224fc0fc7f7770a576c0362c4f29287c601e5a3 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Tue, 23 Jul 2024 21:42:06 -0400 Subject: [PATCH 20/28] fixup: quite disabling Space Cadet There's room for it now in the RP2040 storage. --- keyboards/aki27/cocot46plus/rules.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/keyboards/aki27/cocot46plus/rules.mk b/keyboards/aki27/cocot46plus/rules.mk index 2fda4c7226b..b6069b77376 100644 --- a/keyboards/aki27/cocot46plus/rules.mk +++ b/keyboards/aki27/cocot46plus/rules.mk @@ -1,4 +1,3 @@ SRC += matrix.c CUSTOM_MATRIX = lite POINTING_DEVICE_DRIVER = adns5050 -SPACE_CADET_ENABLE = no From c2819aa57a87e5a2df25b19fae9092b2e2800e23 Mon Sep 17 00:00:00 2001 From: Yudai NAKATA Date: Sat, 3 Aug 2024 15:18:30 +0900 Subject: [PATCH 21/28] fix: fix incorrect pin assignments --- keyboards/aki27/cocot46plus/keyboard.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards/aki27/cocot46plus/keyboard.json b/keyboards/aki27/cocot46plus/keyboard.json index bef9b599177..53442206a81 100644 --- a/keyboards/aki27/cocot46plus/keyboard.json +++ b/keyboards/aki27/cocot46plus/keyboard.json @@ -26,12 +26,12 @@ "rgblight": true }, "ws2812": { - "pin": "GP7", + "pin": "GP21", "driver": "vendor" }, "encoder": { "rotary": [ - { "pin_a": "GP0", "pin_b": "GP0"} + { "pin_a": "GP0", "pin_b": "GP1"} ] }, "rgblight": { From df351506ad143e30b8ca8600823c25da7f20cbd8 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Thu, 19 Sep 2024 14:21:05 -0400 Subject: [PATCH 22/28] fixup: Update vid to be unique. --- keyboards/aki27/cocot46plus/keyboard.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards/aki27/cocot46plus/keyboard.json b/keyboards/aki27/cocot46plus/keyboard.json index 53442206a81..9f3b89366af 100644 --- a/keyboards/aki27/cocot46plus/keyboard.json +++ b/keyboards/aki27/cocot46plus/keyboard.json @@ -5,8 +5,8 @@ "tags": ["unibody","ergo","corne","trackball","encoder","rgb"], "usb": { "device_version": "1.0.0", - "pid": "0x0003", - "vid": "0x1727" + "pid": "0x4600", + "vid": "0x4600" }, "development_board": "promicro_rp2040", "matrix_pins": { From 73a96b246f41e3fd06ee32fd427efe7920239a65 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Thu, 19 Sep 2024 14:27:04 -0400 Subject: [PATCH 23/28] fixup: move OLED task logic from default keyboard to keyboard level. Thanks to @drasha suggestion. --- keyboards/aki27/cocot46plus/cocot46plus.c | 9 +++++++++ keyboards/aki27/cocot46plus/keymaps/default/keymap.c | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index 3ee10e5994d..88a3a5c75f0 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -210,6 +210,15 @@ void cocot_set_scroll_mode(bool mode) { // OLED utility #ifdef OLED_ENABLE +bool oled_task_kb(void) { + if (!oled_task_user()) { + return false; + } + render_logo(); + oled_write_layer_state(); + return false; +} + oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_0; } diff --git a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c index 02c9110219d..85b4e959bf6 100644 --- a/keyboards/aki27/cocot46plus/keymaps/default/keymap.c +++ b/keyboards/aki27/cocot46plus/keymaps/default/keymap.c @@ -123,12 +123,3 @@ layer_state_t layer_state_set_user(layer_state_t state) { #endif return state; }; - - -#ifdef OLED_ENABLE -bool oled_task_user(void) { - render_logo(); - oled_write_layer_state(); - return false; -} -#endif From 0e2439e00f9f299653619ca016e6a4c607f9bd2b Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Wed, 13 Nov 2024 20:15:14 -0500 Subject: [PATCH 24/28] linting: qmk format-c on matrix.c No other changes --- keyboards/aki27/cocot46plus/matrix.c | 91 ++++++++++++---------------- 1 file changed, 38 insertions(+), 53 deletions(-) diff --git a/keyboards/aki27/cocot46plus/matrix.c b/keyboards/aki27/cocot46plus/matrix.c index c5e93d9b76e..5f30e382cdf 100644 --- a/keyboards/aki27/cocot46plus/matrix.c +++ b/keyboards/aki27/cocot46plus/matrix.c @@ -20,55 +20,48 @@ along with this program. If not, see . static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; -static void select_row(uint8_t row) -{ +static void select_row(uint8_t row) { gpio_set_pin_output(row_pins[row]); gpio_write_pin_low(row_pins[row]); } -static void unselect_row(uint8_t row) -{ +static void unselect_row(uint8_t row) { gpio_set_pin_input_high(row_pins[row]); } -static void unselect_rows(void) -{ - for(uint8_t x = 0; x < MATRIX_ROWS; x++) { +static void unselect_rows(void) { + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { gpio_set_pin_input_high(row_pins[x]); } } -static void select_col(uint8_t col) -{ +static void select_col(uint8_t col) { gpio_set_pin_output(col_pins[col]); gpio_write_pin_low(col_pins[col]); } -static void unselect_col(uint8_t col) -{ +static void unselect_col(uint8_t col) { gpio_set_pin_input_high(col_pins[col]); } -static void unselect_cols(void) -{ - for(uint8_t x = 0; x < MATRIX_COLS; x++) { +static void unselect_cols(void) { + for (uint8_t x = 0; x < MATRIX_COLS; x++) { gpio_set_pin_input_high(col_pins[x]); } } static void init_pins(void) { - unselect_rows(); - unselect_cols(); - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - gpio_set_pin_input_high(col_pins[x]); - } - for (uint8_t x = 0; x < MATRIX_ROWS; x++) { - gpio_set_pin_input_high(row_pins[x]); - } + unselect_rows(); + unselect_cols(); + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + gpio_set_pin_input_high(col_pins[x]); + } + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + gpio_set_pin_input_high(row_pins[x]); + } } -static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) -{ +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { // Store last value of row prior to reading matrix_row_t last_row_value = current_matrix[current_row]; @@ -80,13 +73,12 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) wait_us(30); // For each col... - for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { - + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { // Select the col pin to read (active low) uint8_t pin_state = gpio_read_pin(col_pins[col_index]); // Populate the matrix row with the state of the col pin - current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); + current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); } // Unselect row @@ -95,8 +87,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) return (last_row_value != current_matrix[current_row]); } -static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) -{ +static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { bool matrix_changed = false; // Select col and wait for col selecton to stabilize @@ -104,27 +95,22 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) wait_us(30); // For each row... - for(uint8_t row_index = 0; row_index < MATRIX_ROWS/2; row_index++) - { - uint8_t tmp = row_index + MATRIX_ROWS/2; + for (uint8_t row_index = 0; row_index < MATRIX_ROWS / 2; row_index++) { + uint8_t tmp = row_index + MATRIX_ROWS / 2; // Store last value of row prior to reading matrix_row_t last_row_value = current_matrix[tmp]; // Check row pin state - if (gpio_read_pin(row_pins[row_index]) == 0) - { + if (gpio_read_pin(row_pins[row_index]) == 0) { // Pin LO, set col bit current_matrix[tmp] |= (MATRIX_ROW_SHIFTER << current_col); - } - else - { + } else { // Pin HI, clear col bit current_matrix[tmp] &= ~(MATRIX_ROW_SHIFTER << current_col); } // Determine if the matrix changed state - if ((last_row_value != current_matrix[tmp]) && !(matrix_changed)) - { + if ((last_row_value != current_matrix[tmp]) && !(matrix_changed)) { matrix_changed = true; } } @@ -140,19 +126,18 @@ void matrix_init_custom(void) { init_pins(); } -bool matrix_scan_custom(matrix_row_t current_matrix[]) -{ - bool changed = false; +bool matrix_scan_custom(matrix_row_t current_matrix[]) { + bool changed = false; - // Set row, read cols - for (uint8_t current_row = 0; current_row < MATRIX_ROWS / 2; current_row++) { - changed |= read_cols_on_row(current_matrix, current_row); - } - //else - // Set col, read rows - for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - changed |= read_rows_on_col(current_matrix, current_col); - } - - return (uint8_t)changed; + // Set row, read cols + for (uint8_t current_row = 0; current_row < MATRIX_ROWS / 2; current_row++) { + changed |= read_cols_on_row(current_matrix, current_row); + } + // else + // Set col, read rows + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + changed |= read_rows_on_col(current_matrix, current_col); + } + + return (uint8_t)changed; } From 2be1ec65c75f4131dfaa702d6875d05457d74e35 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Wed, 13 Nov 2024 20:27:09 -0500 Subject: [PATCH 25/28] fixup: recommended change from drashna --- keyboards/aki27/cocot46plus/cocot46plus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index 88a3a5c75f0..4becf2f1024 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -219,7 +219,7 @@ bool oled_task_kb(void) { return false; } -oled_rotation_t oled_init_user(oled_rotation_t rotation) { +oled_rotation_t oled_init_kb(oled_rotation_t rotation) { return OLED_ROTATION_0; } From 692472f4b76d75f818fe0ef99647c2a14017e142 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Sat, 22 Feb 2025 08:32:05 -0500 Subject: [PATCH 26/28] docs: clarify that two fields don't fit into uint8_t eeprom --- keyboards/aki27/cocot46plus/cocot46plus.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.h b/keyboards/aki27/cocot46plus/cocot46plus.h index dba6ac69d9b..ca690c4b258 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.h +++ b/keyboards/aki27/cocot46plus/cocot46plus.h @@ -26,8 +26,8 @@ typedef union { uint8_t scrl_div; uint8_t rotation_angle; int8_t scrl_inv; - bool scrl_mode; - report_mouse_t last_mouse; + bool scrl_mode; // Not saved to EEPROM + report_mouse_t last_mouse; // Not saved to EEPROM }; } cocot_config_t; From a0a55bab9010d6aa85254cb8d643e2c5cf314a3a Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Sat, 31 May 2025 10:19:29 -0400 Subject: [PATCH 27/28] fixup: configure optical sensor only during pointing device initialization. --- keyboards/aki27/cocot46plus/cocot46plus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index 4becf2f1024..12772830864 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -70,6 +70,7 @@ static int16_t v_acm = 0; void pointing_device_init_kb(void) { // set the CPI. pointing_device_set_cpi(cpi_array[cocot_config.cpi_idx]); + // Configure ADNS5050 sensor hardware adns5050_write_reg(0x22, 0b10000 | 0x80); } @@ -181,7 +182,6 @@ void eeconfig_init_kb(void) { cocot_config.scrl_mode = false; eeconfig_update_kb(cocot_config.raw); eeconfig_init_user(); - adns5050_write_reg(0x22, 0b10000 | 0x80); } @@ -286,4 +286,3 @@ void oled_write_layer_state(void) { } #endif - From f5aa0bf3f05a3461172c488c7a16701fa68063f6 Mon Sep 17 00:00:00 2001 From: Mark Stosberg Date: Tue, 3 Jun 2025 17:54:52 -0400 Subject: [PATCH 28/28] keyboard:aki27/cocot46plus smooth trackball scrolling From upstream, which updated their mouse handling: https://github.com/aki27kbd/qmk_firmware/blob/master/keyboards/aki27/cocot46plus/cocot46plus.c#L71 --- keyboards/aki27/cocot46plus/cocot46plus.c | 103 ++++++++++++++-------- 1 file changed, 64 insertions(+), 39 deletions(-) diff --git a/keyboards/aki27/cocot46plus/cocot46plus.c b/keyboards/aki27/cocot46plus/cocot46plus.c index 12772830864..dad0e164a11 100644 --- a/keyboards/aki27/cocot46plus/cocot46plus.c +++ b/keyboards/aki27/cocot46plus/cocot46plus.c @@ -62,11 +62,6 @@ int8_t angle_array[] = COCOT_ROTATION_ANGLE; bool BurstState = false; // init burst state for Trackball module uint16_t MotionStart = 0; // Timer for accel, 0 is resting state -// Scroll Accumulation -static int16_t h_acm = 0; -static int16_t v_acm = 0; - - void pointing_device_init_kb(void) { // set the CPI. pointing_device_set_cpi(cpi_array[cocot_config.cpi_idx]); @@ -75,52 +70,82 @@ void pointing_device_init_kb(void) { } report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { + static float x_accumulator = 0.0; + static float y_accumulator = 0.0; + static float prev_x = 0.0, prev_y = 0.0; + float sensitivity = 0.5; // Movement sensitivity + float smoothing_factor = 0.7; // Smoothing factor + float sensitivity_multiplier = 1.5; // Sensitivity adjustment multiplier + + // Apply rotation angle adjustment double rad = (double)angle_array[cocot_config.rotation_angle] * (M_PI / 180) * -1; - int8_t x_rev = + mouse_report.x * cos(rad) - mouse_report.y * sin(rad); - int8_t y_rev = + mouse_report.x * sin(rad) + mouse_report.y * cos(rad); + float rotated_x = mouse_report.x * cos(rad) - mouse_report.y * sin(rad); + float rotated_y = mouse_report.x * sin(rad) + mouse_report.y * cos(rad); + // Apply smoothing to the rotated values + float smoothed_x = prev_x * smoothing_factor + rotated_x * (1.0 - smoothing_factor); + float smoothed_y = prev_y * smoothing_factor + rotated_y * (1.0 - smoothing_factor); + prev_x = smoothed_x; + prev_y = smoothed_y; + + // Apply sensitivity multiplier + smoothed_x *= sensitivity_multiplier; + smoothed_y *= sensitivity_multiplier; + + // Scroll mode handling if (cocot_get_scroll_mode()) { - // rock scroll direction - if (abs(x_rev) > abs(y_rev)) { - y_rev = 0; + static int h_acm = 0, v_acm = 0; + + // Determine scroll direction + if (abs((int)smoothed_x) > abs((int)smoothed_y)) { + smoothed_y = 0; // Horizontal scroll } else { - x_rev = 0; + smoothed_x = 0; // Vertical scroll } - // accumulate scroll - h_acm += x_rev * cocot_config.scrl_inv; - v_acm += y_rev * cocot_config.scrl_inv * -1; - - int8_t h_rev = h_acm >> scrl_div_array[cocot_config.scrl_div]; - int8_t v_rev = v_acm >> scrl_div_array[cocot_config.scrl_div]; - - // clear accumulated scroll on assignment - - if (h_rev != 0) { - if (mouse_report.h + h_rev > 127) { - h_rev = 127 - mouse_report.h; - } else if (mouse_report.h + h_rev < -127) { - h_rev = -127 - mouse_report.h; - } - mouse_report.h += h_rev; - h_acm -= h_rev << scrl_div_array[cocot_config.scrl_div]; - } - if (v_rev != 0) { - if (mouse_report.v + v_rev > 127) { - v_rev = 127 - mouse_report.v; - } else if (mouse_report.v + v_rev < -127) { - v_rev = -127 - mouse_report.v; - } - mouse_report.v += v_rev; - v_acm -= v_rev << scrl_div_array[cocot_config.scrl_div]; + // Accumulate scroll values + if (cocot_config.scrl_inv > 0) { + h_acm += smoothed_x; + v_acm -= smoothed_y; + } else { + h_acm -= smoothed_x; + v_acm += smoothed_y; } + // Calculate scroll values with division factor + int8_t h_scroll = h_acm >> scrl_div_array[cocot_config.scrl_div]; + int8_t v_scroll = v_acm >> scrl_div_array[cocot_config.scrl_div]; + + // Apply scroll to mouse report + if (h_scroll != 0) { + mouse_report.h += h_scroll; + h_acm -= h_scroll << scrl_div_array[cocot_config.scrl_div]; + } + if (v_scroll != 0) { + mouse_report.v += v_scroll; + v_acm -= v_scroll << scrl_div_array[cocot_config.scrl_div]; + } + + // Reset X/Y movement in scroll mode mouse_report.x = 0; mouse_report.y = 0; } else { - mouse_report.x = x_rev; - mouse_report.y = y_rev; + // Movement smoothing and accumulation for normal mode + x_accumulator += smoothed_x * sensitivity; + y_accumulator += smoothed_y * sensitivity; + if (fabs(x_accumulator) >= 1.0) { + mouse_report.x = (int8_t)x_accumulator; + x_accumulator -= mouse_report.x; + } else { + mouse_report.x = 0; + } + if (fabs(y_accumulator) >= 1.0) { + mouse_report.y = (int8_t)y_accumulator; + y_accumulator -= mouse_report.y; + } else { + mouse_report.y = 0; + } } return pointing_device_task_user(mouse_report);