From 12e66330c5fad6dccc1e7be34f68f2db200b9f6e Mon Sep 17 00:00:00 2001 From: kamisamamizu Date: Sun, 17 Dec 2017 17:44:13 +0100 Subject: [PATCH] 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 --- keyboards/cospad/config.h | 94 +++++++++++++++++++++++ keyboards/cospad/cospad.c | 37 +++++++++ keyboards/cospad/cospad.h | 77 +++++++++++++++++++ keyboards/cospad/keymaps/default/keymap.c | 91 ++++++++++++++++++++++ keyboards/cospad/readme.md | 21 +++++ keyboards/cospad/rules.mk | 66 ++++++++++++++++ quantum/rgblight.c | 12 +++ quantum/rgblight.h | 3 + 8 files changed, 401 insertions(+) create mode 100644 keyboards/cospad/config.h create mode 100644 keyboards/cospad/cospad.c create mode 100644 keyboards/cospad/cospad.h create mode 100644 keyboards/cospad/keymaps/default/keymap.c create mode 100644 keyboards/cospad/readme.md create mode 100644 keyboards/cospad/rules.mk diff --git a/keyboards/cospad/config.h b/keyboards/cospad/config.h new file mode 100644 index 0000000000..4bdf434a47 --- /dev/null +++ b/keyboards/cospad/config.h @@ -0,0 +1,94 @@ +/* +Copyright 2012 Jun Wako + +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 . +*/ + +#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 diff --git a/keyboards/cospad/cospad.c b/keyboards/cospad/cospad.c new file mode 100644 index 0000000000..48d752a84b --- /dev/null +++ b/keyboards/cospad/cospad.c @@ -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<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; + } +} diff --git a/keyboards/cospad/readme.md b/keyboards/cospad/readme.md new file mode 100644 index 0000000000..436b87dcee --- /dev/null +++ b/keyboards/cospad/readme.md @@ -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. diff --git a/keyboards/cospad/rules.mk b/keyboards/cospad/rules.mk new file mode 100644 index 0000000000..3c5913d0d9 --- /dev/null +++ b/keyboards/cospad/rules.mk @@ -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 diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 63eda47cda..ab218b8c50 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -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; } diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 6d362e1d51..73dd899469 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -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);