Add COSPAD to QMK and add functions to read HSV (#2156)

* Added functions to read HSV values

I have added three functions to rgb_light.c to be able to read the hue, saturation and value from other places.
They are rgblight_get_hue(), rgblight_get_sat(), adn rgblight_get_val().

* Create keymap.c

* Add COSPAD support to QMK

I have ported the COSPAD numpad to qmk.

* Update readme.md

* Update cospad.c
This commit is contained in:
kamisamamizu 2017-12-17 17:44:13 +01:00 committed by Jack Humbert
parent d91c9858c5
commit 12e66330c5
8 changed files with 401 additions and 0 deletions

94
keyboards/cospad/config.h Normal file
View File

@ -0,0 +1,94 @@
/*
Copyright 2012 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONFIG_H
#define CONFIG_H
#include "config_common.h"
/* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x6060
#define DEVICE_VER 0x0001
#define MANUFACTURER KPREPUBLIC
#define PRODUCT COSPAD
#define DESCRIPTION QMK keyboard firmware for COSPAD
/* key matrix size */
#define MATRIX_ROWS 6
#define MATRIX_COLS 4
// ROWS: Top to bottom, COLS: Left to right
#define MATRIX_ROW_PINS { D0, D1, D2, D3, D4, D5 }
#define MATRIX_COL_PINS { F0, F1, E6, C7 }
#define UNUSED_PINS
#define BACKLIGHT_PIN F7
/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW
/* define if matrix has ghost */
//#define MATRIX_HAS_GHOST
/* Set 0 if debouncing isn't needed */
#define DEBOUNCING_DELAY 5
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
//#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
#define LOCKING_RESYNC_ENABLE
/* key combination for command */
#define IS_COMMAND() ( \
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
)
/* Backlight configuration
*/
#define BACKLIGHT_LEVELS 4
/* Underlight configuration
*/
#define RGB_DI_PIN F6
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 4 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
#define RGBLIGHT_VAL_STEP 17
/*
* 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 NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION
#endif

37
keyboards/cospad/cospad.c Normal file
View File

@ -0,0 +1,37 @@
#include "cospad.h"
#include "led.h"
extern inline void cospad_bl_led_on(void);
extern inline void cospad_bl_led_off(void);
extern inline void cospad_bl_led_togg(void);
void matrix_init_kb(void) {
// put your keyboard start-up code here
// runs once when the firmware starts up
matrix_init_user();
led_init_ports();
};
void matrix_scan_kb(void) {
// put your looping keyboard code here
// runs every cycle (a lot)
matrix_scan_user();
};
void led_init_ports(void) {
// * Set our LED pins as output
DDRB |= (1<<2);
DDRF |= (1<<7);
// * Setting BL LEDs to init as off
PORTF |= (1<<7);
}
void led_set_kb(uint8_t usb_led) {
if (usb_led & (1<<USB_LED_NUM_LOCK)) {
// Turn numlock on
PORTB &= ~(1<<2);
} else {
// Turn numlock off
PORTB |= (1<<2);
}
}

77
keyboards/cospad/cospad.h Normal file
View File

@ -0,0 +1,77 @@
#ifndef COSPAD_H
#define COSPAD_H
#include "quantum.h"
// readability
#define XXX KC_NO
/* COSPAD ortho matrix layout
* ,-------------------.
* | 00 | 01 | 02 | 03 |
* |----|----|----|----|
* | 10 | 11 | 12 | 13 |
* |----|----|----|----|
* | 20 | 21 | 22 | 23 |
* |----|----|----|----|
* | 30 | 31 | 32 | 33 |
* |----|----|----|----|
* | 40 | 41 | 42 | 43 |
* |----|----|----|----|
* | 50 | 51 | 52 | 53 |
* `-------------------'
*/
/* COSPAD numpad matrix layout
* ,-------------------.
* | 00 | 01 | 02 | 03 |
* |----|----|----|----|
* | 10 | 11 | 12 | 13 |
* |----|----|----|----|
* | 20 | 21 | 22 | |
* |----|----|----| 23 |
* | 30 | 31 | 32 | |
* |----|----|----|----|
* | 40 | 41 | 42 | |
* |----|----|----| 43 |
* | 50 | 52 | |
* `-------------------'
*/
// The first section contains all of the arguments
// The second converts the arguments into a two-dimensional array
#define KEYMAP( \
k00, k01, k02, k03, \
k10, k11, k12, k13, \
k20, k21, k22, k23, \
k30, k31, k32, k33, \
k40, k41, k42, k43, \
k50, k51, k52, k53 \
) \
{ \
{k00, k01, k02, k03}, \
{k10, k11, k12, k13}, \
{k20, k21, k22, k23}, \
{k30, k31, k32, k33}, \
{k40, k41, k42, k43}, \
{k50, k51, k52, k53} \
}
void matrix_init_user(void);
void matrix_scan_user(void);
/*
inline void cospad_bl_led_on(void) { DDRF |= (1<<7); PORTF &= ~(1<<7); }
inline void cospad_bl_led_off(void) { DDRF &= ~(1<<7); PORTF &= ~(1<<7); }
*/
inline void cospad_bl_led_on(void) { PORTF &= ~(1<<7); }
inline void cospad_bl_led_off(void) { PORTF |= (1<<7); }
inline void cospad_bl_led_togg(void) {
uint8_t bl_mask = PORTF&(1<<7);
if (bl_mask) {
PORTF &= ~(1<<7);
} else {
PORTF |= (1<<7);
}
}
#endif

View File

@ -0,0 +1,91 @@
#include "cospad.h"
#include "led.h"
#ifdef RGBLIGHT_ENABLE
#include "rgblight.h"
#endif
// Each layer gets a name for readability, which is then used in the keymap matrix below.
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
// Layer names don't all need to be of the same length, obviously, and you can also skip them
// entirely and just use numbers.
#define _BL 0
#define _FL 1
#define _______ KC_TRNS
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap _BL: (Base Layer) Default Layer
* ,-------------------.
* |Esc |TAB | FN | BS |
* |----|----|----|----|
* | NL | / | * | - |
* |----|----|----|----|
* | 7 | 8 | 9 | |
* |----|----|----| + |
* | 4 | 5 | 6 | |
* |----|----|----|----|
* | 1 | 2 | 3 | |
* |----|----|----| En |
* | 0 | . | |
* `-------------------'
*/
[_BL] = KEYMAP(
KC_ESC, KC_TAB, MO(_FL), KC_BSPC, \
KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS, \
KC_P7, KC_P8, KC_P9, KC_PPLS, \
KC_P4, KC_P5, KC_P6, KC_NO, \
KC_P1, KC_P2, KC_P3, KC_PENT, \
KC_P0, KC_NO, KC_PDOT, KC_NO),
/* Keymap _FL: Function Layer
* ,-------------------.
* |RGBT|TAB | FN | BS |
* |----|----|----|----|
* |RGBM|RGBP|BTOG| - |
* |----|----|----|----|
* |HUD |HUI |BON | |
* |----|----|----| + |
* |SAD |SAI |BOFF| |
* |----|----|----|----|
* |VAD |VAS | 3 | |
* |----|----|----| En |
* | 0 |RST | |
* `-------------------'
*/
[_FL] = KEYMAP(
RGB_TOG, KC_TAB, KC_TRNS, KC_BSPC, \
RGB_MOD, RGB_M_P, BL_TOGG, KC_PMNS, \
RGB_HUD, RGB_HUI, BL_ON, KC_PPLS, \
RGB_SAD, RGB_SAI, BL_OFF, KC_NO, \
RGB_VAD, RGB_VAI, KC_P3, KC_PENT, \
KC_P0, KC_NO, RESET, KC_NO),
};
const uint16_t PROGMEM fn_actions[] = {
[0] = MO(_FL),
};
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case BL_TOGG:
if (record->event.pressed) {
cospad_bl_led_togg();
}
return false;
case BL_ON:
if (record->event.pressed) {
cospad_bl_led_on();
}
return false;
case BL_OFF:
if(record->event.pressed) {
cospad_bl_led_off();
}
return false;
default:
return true;
}
}

View File

@ -0,0 +1,21 @@
COSPAD
===
A DIY Keypad Kit sold by KPRepublic, runs TKG natively.
Keyboard Maintainer: QMK Community
Hardware Supported: COSPAD
Hardware Availability: https://aliexpress.com/item/cospad-Custom-Mechanical-Keyboard-Kit-up-tp-24-keys-Supports-TKG-TOOLS-Underglow-RGB-PCB-20/32818383873.html
Only supports on and off for the backlight leds, as they are not connected to a PWM pin.
Supported Layouts:
![Numpad Layout of COSPAD](https://i.imgur.com/t03lXJ4.png)
![Ortholinear Layout of COSPAD](https://i.imgur.com/mliUcCc.png)
Make example for this keyboard (after setting up your build environment):
make cospad:default
See [build environment setup](https://docs.qmk.fm/build_environment_setup.html) then the [make instructions](https://docs.qmk.fm/make_instructions.html) for more information.

66
keyboards/cospad/rules.mk Normal file
View File

@ -0,0 +1,66 @@
# MCU name
#MCU = at90usb1287
MCU = atmega32u4
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency in Hz. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
#
# This will be an integer division of F_USB below, as it is sourced by
# F_USB after it has run through any CPU prescalers. Note that this value
# does not *change* the processor frequency - it should merely be updated to
# reflect the processor speed set externally so that the code can use accurate
# software delays.
F_CPU = 16000000
#
# LUFA specific
#
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8
# Input clock frequency.
# This will define a symbol, F_USB, in all source code files equal to the
# input clock frequency (before any prescaling is performed) in Hz. This value may
# differ from F_CPU if prescaling is used on the latter, and is required as the
# raw input clock is fed directly to the PLL sections of the AVR for high speed
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
# at the end, this will be done automatically to create a 32-bit value in your
# source code.
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_USB = $(F_CPU)
# Interrupt driven control endpoint task(+60)
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
# Boot Section Size in *bytes*
# Teensy halfKay 512
# Teensy++ halfKay 1024
# Atmel DFU loader 4096
# LUFA bootloader 4096
# USBaspLoader 2048
OPT_DEFS += -DBOOTLOADER_SIZE=4096
# Build Options
# comment out to disable the options.
#
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = no # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = no # Console for debug(+400)
COMMAND_ENABLE = no # Commands for debug and configuration
NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
RGBLIGHT_ENABLE = yes # Enable keyboard underlight functionality (+4870)
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality (+1150)
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = no
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID

View File

@ -370,6 +370,18 @@ void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
}
}
uint16_t rgblight_get_hue(void) {
return rgblight_config.hue;
}
uint8_t rgblight_get_sat(void) {
return rgblight_config.sat;
}
uint8_t rgblight_get_val(void) {
return rgblight_config.val;
}
void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) {
if (!rgblight_config.enable) { return; }

View File

@ -113,6 +113,9 @@ void rgblight_decrease_sat(void);
void rgblight_increase_val(void);
void rgblight_decrease_val(void);
void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
uint16_t rgblight_get_hue(void);
uint8_t rgblight_get_sat(void);
uint8_t rgblight_get_val(void);
void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b);
void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index);
void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index);