Skip to content

Commit

Permalink
add cheapino
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-bravo-yahoo committed Feb 23, 2024
1 parent b15b449 commit 806014a
Show file tree
Hide file tree
Showing 15 changed files with 1,289 additions and 0 deletions.
75 changes: 75 additions & 0 deletions keyboards/cheapino/cheapino.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "wait.h"
#include "quantum.h"

// This is to keep state between callbacks, when it is 0 the
// initial RGB flash is finished
uint8_t _hue_countdown = 50;

// These are to keep track of user selected color, so we
// can restore it after RGB flash
uint8_t _hue;
uint8_t _saturation;
uint8_t _value;

// Do a little 2.5 seconds display of the different colors
// Use the deferred executor so the LED flash dance does not
// stop us from using the keyboard.
// https://docs.qmk.fm/#/custom_quantum_functions?id=deferred-executor-registration
uint32_t flash_led(uint32_t next_trigger_time, void *cb_arg) {
rgblight_sethsv(_hue_countdown * 5, 230, 70);
_hue_countdown--;
if (_hue_countdown == 0) {
// Finished, reset to user chosen led color
rgblight_sethsv(_hue, _saturation, _value);
return 0;
} else {
return 50;
}
}

void keyboard_post_init_user(void) {
//debug_enable=true;
//debug_matrix=true;
//debug_keyboard=true;
//debug_mouse=true;

// Store user selected rgb hsv:
_hue = rgblight_get_hue();
_saturation = rgblight_get_sat();
_value = rgblight_get_val();

// Flash a little on start
defer_exec(50, flash_led, NULL);
}

// Make the builtin RGB led show different colors per layer:
// This seemed like a good idea but turned out pretty annoying,
// to me at least... Uncomment the lines below to enable
/*
uint8_t get_hue(uint8_t layer) {
switch (layer) {
case 6:
return 169;
case 5:
return 43;
case 4:
return 85;
case 3:
return 120;
case 2:
return 180;
case 1:
return 220;
default:
return 0;
}
}
layer_state_t layer_state_set_user(layer_state_t state) {
uint8_t sat = rgblight_get_sat();
uint8_t val = rgblight_get_val();
uint8_t hue = get_hue(get_highest_layer(state));
rgblight_sethsv(hue, sat, val);
return state;
}
*/
38 changes: 38 additions & 0 deletions keyboards/cheapino/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023 Thomas Haukland (@tompi)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

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

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

/* disable print */
//#define NO_PRINT

/* disable action features */
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT

#define BOTH_SHIFTS_TURNS_ON_CAPS_WORD
#define WS2812_PIO_USE_PIO1 // Force the usage of PIO1 peripheral, by default the WS2812 implementation uses the PIO0 peripheral
//#define WS2812_TRST_US 80
#define WS2812_BYTE_ORDER WS2812_BYTE_ORDER_RGB
#define RGB_MATRIX_DEFAULT_VAL 32


// Pick good defaults for enabling homerow modifiers
#define TAPPING_TERM 225
#define PERMISSIVE_HOLD


#define WS2812_DI_PIN GP16 // The pin connected to the data pin of the LEDs
#define RGBLED_NUM 1 // The number of LEDs connected


#define MAX_DEFERRED_EXECUTORS 32
72 changes: 72 additions & 0 deletions keyboards/cheapino/encoder.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "matrix.h"
#include "quantum.h"

#define COL_SHIFTER ((uint16_t)1)

static bool colABpressed = false;
static bool encoderPressed = false;

void clicked(void) {
tap_code(KC_MUTE);
}

void turned(bool clockwise) {
tap_code(clockwise ? KC_VOLU : KC_VOLD);
}

void blank_column(matrix_row_t current_matrix[], uint8_t col) {
uint16_t column_index_bitmask = COL_SHIFTER << col;
for (uint8_t row_index = 0; row_index < MATRIX_ROWS-1; row_index++) {
current_matrix[row_index] &= ~column_index_bitmask;
}
}

bool is_entire_column_held(matrix_row_t current_matrix[], uint8_t col) {
uint16_t column_index_bitmask = COL_SHIFTER << col;
for (uint8_t row_index = 0; row_index < MATRIX_ROWS-1; row_index++) {
if (!(current_matrix[row_index] & column_index_bitmask)) return false;
}
return true;
}

// Because of a bug in the routing of the cheapino, encoder action
// triggers entire columns... fix it in software here, assumption is that
// you never press an entire column, sounds safe?
void fix_encoder_action(matrix_row_t current_matrix[]) {

// 7th column means encoder was pressed
if (is_entire_column_held(current_matrix, 7)) {
encoderPressed = true;
blank_column(current_matrix, 7);
current_matrix[3] |= COL_SHIFTER;
} else {
current_matrix[3] &= ~COL_SHIFTER;
// Only trigger click on release
if (encoderPressed) {
encoderPressed = false;
clicked();
}
}

// Now check rotary action:
bool colA = is_entire_column_held(current_matrix, 9);
bool colB = is_entire_column_held(current_matrix, 11);

if (colA && colB) {
colABpressed = true;
blank_column(current_matrix, 9);
blank_column(current_matrix, 11);
} else if (colA) {
if (colABpressed) {
colABpressed = false;
turned(true);
}
blank_column(current_matrix, 9);
} else if (colB) {
if (colABpressed) {
colABpressed = false;
turned(false);
}
blank_column(current_matrix, 11);
}
}
5 changes: 5 additions & 0 deletions keyboards/cheapino/encoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Created by Thomas Haukland on 25/03/2023.
//

void fix_encoder_action(matrix_row_t current_matrix[]);
8 changes: 8 additions & 0 deletions keyboards/cheapino/halconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#pragma once

#define HAL_USE_PWM TRUE
#define HAL_USE_PAL TRUE
#define HAL_USE_I2C TRUE

#include_next <halconf.h>
71 changes: 71 additions & 0 deletions keyboards/cheapino/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"manufacturer": "Thomas Haukland",
"keyboard_name": "cheapino",
"maintainer": "tompi",
"bootloader": "rp2040",
"diode_direction": "ROW2COL",
"features": {
"bootmagic": true,
"command": false,
"console": true,
"extrakey": true,
"mousekey": true,
"nkro": false
},
"community_layouts": [
"split_3x5_3"
],
"matrix_pins": {
"cols": ["GP0", "GP0", "GP1", "GP1", "GP2", "GP2", "GP29", "GP29", "GP28", "GP28", "GP27", "GP27"],
"rows": ["GP6", "GP5", "GP4", "GP3"]
},
"processor": "RP2040",
"url": "",
"usb": {
"device_version": "1.0.0",
"pid": "0x0000",
"vid": "0xFEED"
},
"layouts": {
"LAYOUT_split_3x5_3": {
"layout": [
{ "matrix": [0, 4], "x": 0, "y": 0.25 },
{ "matrix": [0, 3], "x": 1, "y": 0.125 },
{ "matrix": [0, 2], "x": 2, "y": 0 },
{ "matrix": [0, 1], "x": 3, "y": 0.125 },
{ "matrix": [0, 0], "x": 4, "y": 0.25 },
{ "matrix": [2, 6], "x": 7, "y": 0.25 },
{ "matrix": [2, 7], "x": 8, "y": 0.125 },
{ "matrix": [2, 8], "x": 9, "y": 0 },
{ "matrix": [2, 9], "x": 10, "y": 0.125 },
{ "matrix": [2, 10], "x": 11, "y": 0.25 },
{ "matrix": [1, 4], "x": 0, "y": 1.25 },
{ "matrix": [1, 3], "x": 1, "y": 1.125 },
{ "matrix": [1, 2], "x": 2, "y": 1 },
{ "matrix": [1, 1], "x": 3, "y": 1.125 },
{ "matrix": [1, 0], "x": 4, "y": 1.25 },
{ "matrix": [1, 6], "x": 7, "y": 1.25 },
{ "matrix": [1, 7], "x": 8, "y": 1.125 },
{ "matrix": [1, 8], "x": 9, "y": 1 },
{ "matrix": [1, 9], "x": 10, "y": 1.125 },
{ "matrix": [1, 10], "x": 11, "y": 1.25 },
{ "matrix": [2, 4], "x": 0, "y": 2.25 },
{ "matrix": [2, 3], "x": 1, "y": 2.125 },
{ "matrix": [2, 2], "x": 2, "y": 2 },
{ "matrix": [2, 1], "x": 3, "y": 2.125 },
{ "matrix": [2, 0], "x": 4, "y": 2.25 },
{ "matrix": [0, 6], "x": 7, "y": 2.25 },
{ "matrix": [0, 7], "x": 8, "y": 2.125 },
{ "matrix": [0, 8], "x": 9, "y": 2 },
{ "matrix": [0, 9], "x": 10, "y": 2.125 },
{ "matrix": [0, 10], "x": 11, "y": 2.25 },
{ "matrix": [2, 5], "x": 2.5, "y": 3.25 },
{ "matrix": [1, 5], "x": 3.5, "y": 3.5 },
{ "matrix": [0, 5], "x": 4.5, "y": 3.75 },
{ "matrix": [2, 11], "x": 6.5, "y": 3.75 },
{ "matrix": [1, 11], "x": 7.5, "y": 3.5 },
{ "matrix": [0, 11], "x": 8.5, "y": 3.25 }
]
}
}
}
Loading

0 comments on commit 806014a

Please sign in to comment.