From ad6d85ef5a77f0fb810f5c850c24499a4886e458 Mon Sep 17 00:00:00 2001 From: Yang Hu Date: Fri, 5 Nov 2021 02:10:15 -0700 Subject: [PATCH] Add a new keyboard "Unicorne" (#12993) * Add keyboards/yanghu/unicorne initial files. * add default keymap to yanghu/unicorne * use slow i2c and enable internal pullup resistor * add oled to default keymaps * fix unicorne default keymap * fix encoder pad direction * fix marauder * add led matrix configs. * add encoder code to default keymap. * fix encoder direction * add readme, info.json and update copyright for c files. * fix build error by clean up include in unicorne.c * fix images in readme files * Fix various issues in PR #12993 feedback. * Added copyright in glcdfont, fix include in that file. * Removed `_kc` layout and renamed layout with generic style. * Moved capslock oled update to oled.c inside `oled_task_user()`. * Update keyboards/yanghu/unicorne/keymaps/default/rules.mk Always include oled.c Co-authored-by: Drashna Jaelre * Update keyboards/yanghu/unicorne/keymaps/default/oled.c Wrap `oled.c` with ifdef. Co-authored-by: Drashna Jaelre * Update keyboards/yanghu/unicorne/keymaps/default/oled.c Co-authored-by: Drashna Jaelre * move oled code to unicorne.c, and set weakly. * Update keyboards/yanghu/unicorne/config.h Co-authored-by: Drashna Jaelre * Update keyboards/yanghu/unicorne/keymaps/default/keymap.c Co-authored-by: Drashna Jaelre * Update keyboards/yanghu/unicorne/keymaps/default/keymap.c Co-authored-by: Drashna Jaelre * Update keyboards/yanghu/unicorne/keymaps/default/keymap.c Co-authored-by: Drashna Jaelre * Update keyboards/yanghu/unicorne/unicorne.c Co-authored-by: Drashna Jaelre * Update keyboards/yanghu/unicorne/readme.md Co-authored-by: Ryan * Update keyboards/yanghu/unicorne/readme.md Co-authored-by: Ryan * Update keyboards/yanghu/unicorne/readme.md Co-authored-by: Ryan * Update keyboards/yanghu/unicorne/readme.md Co-authored-by: Ryan * Update keyboards/yanghu/unicorne/keymaps/default/oled.c Co-authored-by: Ryan * Update keyboards/yanghu/unicorne/f411/rules.mk Co-authored-by: Ryan * Update keyboards/yanghu/unicorne/rules.mk Co-authored-by: Ryan * remove oled.h * remove include of oled.h after the file is deleted. * Apply suggestions from code review: remove redundant macros and reformat. Co-authored-by: Drashna Jaelre Co-authored-by: Ryan * Apply suggestions from code review: change OLED driver macro. Use `OLED_ENABLE` instead of `OLED_DRIVER_ENABLE`. Co-authored-by: Jonathan Rascher Co-authored-by: Drashna Jaelre Co-authored-by: Ryan Co-authored-by: Jonathan Rascher --- keyboards/yanghu/unicorne/config.h | 76 ++++++ keyboards/yanghu/unicorne/f411/halconf.h | 27 ++ keyboards/yanghu/unicorne/f411/mcuconf.h | 34 +++ keyboards/yanghu/unicorne/f411/rules.mk | 5 + keyboards/yanghu/unicorne/glcdfont.c | 247 ++++++++++++++++++ keyboards/yanghu/unicorne/info.json | 62 +++++ .../yanghu/unicorne/keymaps/default/config.h | 22 ++ .../yanghu/unicorne/keymaps/default/keymap.c | 92 +++++++ .../yanghu/unicorne/keymaps/default/layers.h | 24 ++ .../yanghu/unicorne/keymaps/default/oled.c | 67 +++++ .../yanghu/unicorne/keymaps/default/readme.md | 10 + .../yanghu/unicorne/keymaps/default/rules.mk | 1 + keyboards/yanghu/unicorne/readme.md | 17 ++ keyboards/yanghu/unicorne/rules.mk | 26 ++ keyboards/yanghu/unicorne/unicorne.c | 148 +++++++++++ keyboards/yanghu/unicorne/unicorne.h | 50 ++++ 16 files changed, 908 insertions(+) create mode 100644 keyboards/yanghu/unicorne/config.h create mode 100644 keyboards/yanghu/unicorne/f411/halconf.h create mode 100644 keyboards/yanghu/unicorne/f411/mcuconf.h create mode 100644 keyboards/yanghu/unicorne/f411/rules.mk create mode 100644 keyboards/yanghu/unicorne/glcdfont.c create mode 100644 keyboards/yanghu/unicorne/info.json create mode 100644 keyboards/yanghu/unicorne/keymaps/default/config.h create mode 100644 keyboards/yanghu/unicorne/keymaps/default/keymap.c create mode 100644 keyboards/yanghu/unicorne/keymaps/default/layers.h create mode 100644 keyboards/yanghu/unicorne/keymaps/default/oled.c create mode 100644 keyboards/yanghu/unicorne/keymaps/default/readme.md create mode 100644 keyboards/yanghu/unicorne/keymaps/default/rules.mk create mode 100644 keyboards/yanghu/unicorne/readme.md create mode 100644 keyboards/yanghu/unicorne/rules.mk create mode 100644 keyboards/yanghu/unicorne/unicorne.c create mode 100644 keyboards/yanghu/unicorne/unicorne.h diff --git a/keyboards/yanghu/unicorne/config.h b/keyboards/yanghu/unicorne/config.h new file mode 100644 index 0000000000..652afeb3b4 --- /dev/null +++ b/keyboards/yanghu/unicorne/config.h @@ -0,0 +1,76 @@ +/* Copyright 2021 Yang Hu + * + * 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 "config_common.h" + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x0204 +#define DEVICE_VER 0x0001 +#define MANUFACTURER yanghu +#define PRODUCT unicorne + +/* key matrix size */ +#define MATRIX_ROWS 4 +#define MATRIX_COLS 12 + +#define MATRIX_COL_PINS \ + { A14, A15, B13, B14, B15, A13, A0, A1, A2, A3, A6, A7 } +#define MATRIX_ROW_PINS \ + { B9, B8, A10, A9 } + +/* COL2ROW, ROW2COL*/ +#define DIODE_DIRECTION COL2ROW + +#define ENCODERS_PAD_A \ + { B10, B2 } +#define ENCODERS_PAD_B \ + { B12, B0 } + +/* Audio */ +#define AUDIO_PIN A8 +#define AUDIO_PWM_PAL_MODE 1 +#define AUDIO_PWM_DRIVER PWMD1 +#define AUDIO_PWM_CHANNEL 1 +#define AUDIO_STATE_TIMER GPTD4 + +/* RGB LED */ +#define RGB_DI_PIN B1 +#define RGBLED_NUM 8 +#define DRIVER_LED_TOTAL RGBLED_NUM +#define RGBLIGHT_EFFECT_BREATHING +#define RGBLIGHT_EFFECT_RAINBOW_MOOD +#define RGBLIGHT_EFFECT_RAINBOW_SWIRL +#define RGBLIGHT_EFFECT_SNAKE +#define RGBLIGHT_EFFECT_KNIGHT +#define RGBLIGHT_EFFECT_CHRISTMAS +#define RGBLIGHT_EFFECT_STATIC_GRADIENT +#define RGBLIGHT_EFFECT_RGB_TEST +#define RGBLIGHT_EFFECT_ALTERNATING +#define RGBLIGHT_EFFECT_TWINKLE + +#define WS2812_PWM_DRIVER PWMD3 +#define WS2812_PWM_CHANNEL 4 +#define WS2812_PWM_PAL_MODE 2 +#define WS2812_DMA_STREAM STM32_DMA1_STREAM2 +#define WS2812_DMA_CHANNEL 5 +#define WS2812_EXTERNAL_PULLUP + + +/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ +#define DEBOUNCE 5 diff --git a/keyboards/yanghu/unicorne/f411/halconf.h b/keyboards/yanghu/unicorne/f411/halconf.h new file mode 100644 index 0000000000..d28ae12fde --- /dev/null +++ b/keyboards/yanghu/unicorne/f411/halconf.h @@ -0,0 +1,27 @@ +/* Copyright 2020 QMK + * + * 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 + +/* PWM for AUDIO and RGB LED */ +#define HAL_USE_PWM TRUE +/* GPT and PAL for Audio */ +#define HAL_USE_GPT TRUE +#define HAL_USE_PAL TRUE +/* I2C for OLED display */ +#define HAL_USE_I2C TRUE + +#include_next diff --git a/keyboards/yanghu/unicorne/f411/mcuconf.h b/keyboards/yanghu/unicorne/f411/mcuconf.h new file mode 100644 index 0000000000..f4dc31bff2 --- /dev/null +++ b/keyboards/yanghu/unicorne/f411/mcuconf.h @@ -0,0 +1,34 @@ +/* Copyright 2020 QMK + * + * 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_next + +/* TIM1 PWM used for audio driver */ +#undef STM32_PWM_USE_TIM1 +#define STM32_PWM_USE_TIM1 TRUE +/* TIM5 GPT used for audio driver */ +#undef STM32_GPT_USE_TIM4 +#define STM32_GPT_USE_TIM4 TRUE + +/* TIM3 used for WS2812 driver */ +#undef STM32_PWM_USE_TIM3 +#define STM32_PWM_USE_TIM3 TRUE + +/* I2C used for OLED display */ +#undef STM32_I2C_USE_I2C1 +#define STM32_I2C_USE_I2C1 TRUE diff --git a/keyboards/yanghu/unicorne/f411/rules.mk b/keyboards/yanghu/unicorne/f411/rules.mk new file mode 100644 index 0000000000..b32a8b7f5b --- /dev/null +++ b/keyboards/yanghu/unicorne/f411/rules.mk @@ -0,0 +1,5 @@ +# MCU name +MCU = STM32F411 + +# Bootloader selection +BOOTLOADER = stm32-dfu diff --git a/keyboards/yanghu/unicorne/glcdfont.c b/keyboards/yanghu/unicorne/glcdfont.c new file mode 100644 index 0000000000..24c06471ff --- /dev/null +++ b/keyboards/yanghu/unicorne/glcdfont.c @@ -0,0 +1,247 @@ +/* Copyright 2021 Yang Hu + * + * 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 "progmem.h" + +// clang-format off +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, + 0x58, 0xA4, 0xA4, 0x9C, 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, + 0xFC, 0x18, 0x24, 0x24, 0x18, 0x00, + 0x18, 0x24, 0x24, 0x18, 0xFC, 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, 0x10, 0x10, 0x10, 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, 0xF0, 0xF8, 0x9C, 0x0C, + 0x0C, 0x1C, 0xF8, 0xE0, 0x00, 0x00, + 0x00, 0xE0, 0xF8, 0x1C, 0x0C, 0x0C, + 0x9C, 0xF8, 0x60, 0x00, 0x00, 0x00, + 0x00, 0x0C, 0x0C, 0x0C, 0x3C, 0xF8, + 0xC0, 0x00, 0x00, 0x00, 0x00, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, + 0xF0, 0xF8, 0xFC, 0xFC, 0xF8, 0xF0, + 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xC0, 0xE0, 0x70, 0x38, + 0x1C, 0x0C, 0x06, 0x86, 0x86, 0x86, + 0x86, 0x86, 0xC6, 0xC6, 0x0C, 0x1C, + 0x38, 0xF0, 0xE0, 0xC0, 0x00, 0x00, + 0x00, 0x60, 0xF8, 0x0C, 0x24, 0xE6, + 0xE6, 0x24, 0x06, 0x06, 0x24, 0xE6, + 0xE6, 0x24, 0x06, 0x06, 0x24, 0xE6, + 0xE6, 0x24, 0x0C, 0xF8, 0x60, 0x00, + 0x00, 0xE0, 0xF0, 0x18, 0x0C, 0x04, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x86, 0x86, 0xC6, 0x46, 0xE6, 0x66, + 0x04, 0x0C, 0x18, 0xF0, 0xE0, 0x00, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xFE, 0x8A, 0x92, 0xA2, 0xC2, + 0xFE, 0xC2, 0xA2, 0x92, 0x0A, 0x02, + 0x82, 0xE2, 0x7A, 0x5A, 0x42, 0x42, + 0x42, 0xC2, 0xC2, 0x42, 0xFE, 0x00, + 0xFE, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x82, 0xE2, 0xFA, 0x7A, + 0xFA, 0xE2, 0x82, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0xFE, 0x00, + 0x00, 0x00, 0x00, 0x81, 0x81, 0xC3, + 0xC3, 0xC3, 0xFF, 0xFF, 0xC3, 0xC3, + 0xC3, 0xFF, 0xFF, 0xC3, 0xC3, 0xC3, + 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x0F, 0x3C, 0xF0, 0xC0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x06, 0x07, 0x07, 0x07, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x07, 0x07, 0x07, 0x06, 0x00, + 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0x00, 0x7F, 0xFF, 0xC1, 0xC1, + 0xC1, 0xC1, 0xFF, 0x7F, 0xE0, 0x80, + 0x80, 0xC0, 0xFF, 0x7F, 0x00, 0x00, + 0x00, 0xDB, 0xFF, 0x00, 0x00, 0x1F, + 0x3F, 0x70, 0xE0, 0xC0, 0xC0, 0xFF, + 0xFF, 0xC0, 0xC0, 0xE0, 0x70, 0x3F, + 0x1F, 0x00, 0x00, 0xFF, 0xDB, 0x00, + 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0xC0, 0xF8, 0xFE, 0xFF, 0xF9, 0xF1, + 0x61, 0x60, 0x3C, 0x07, 0x01, 0x00, + 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, + 0x00, 0x00, 0xC0, 0xF0, 0x3C, 0x0E, + 0x0E, 0x3C, 0xF0, 0xC0, 0x00, 0x00, + 0x00, 0xFF, 0x48, 0x44, 0xC2, 0xE1, + 0x7F, 0x51, 0xC2, 0xC4, 0x4C, 0x06, + 0x03, 0x0F, 0x38, 0x60, 0xC0, 0xE0, + 0x38, 0x0F, 0x00, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0x00, 0x80, 0xE0, + 0xF8, 0x7E, 0x67, 0x63, 0x60, 0x60, + 0x60, 0x63, 0x67, 0x7E, 0xF8, 0xE0, + 0x80, 0x00, 0x00, 0x00, 0xFF, 0x00, + 0x00, 0x00, 0x0F, 0x1F, 0x39, 0x30, + 0x30, 0x18, 0x1F, 0x07, 0x00, 0x00, + 0x00, 0x07, 0x1F, 0x38, 0x30, 0x30, + 0x39, 0x1F, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, + 0x3C, 0x30, 0x30, 0x30, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, + 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, + 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x07, 0x0E, + 0x1C, 0x38, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x38, 0x18, 0x18, 0x01, + 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x06, 0x1F, 0x30, 0x20, 0x60, + 0x60, 0x20, 0x64, 0x64, 0x26, 0x67, + 0x67, 0x26, 0x64, 0x64, 0x20, 0x60, + 0x60, 0x20, 0x30, 0x1F, 0x06, 0x00, + 0x00, 0x07, 0x0F, 0x18, 0x30, 0x23, + 0x63, 0x61, 0x61, 0x60, 0x60, 0x60, + 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, + 0x20, 0x30, 0x18, 0x0F, 0x07, 0x00, + 0x0C, 0x0F, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x0F, 0x0C, + 0x00, 0x7F, 0x60, 0x71, 0x53, 0x5E, + 0x4C, 0x4E, 0x5B, 0x50, 0x60, 0x70, + 0x58, 0x4C, 0x46, 0x43, 0x41, 0x43, + 0x4E, 0x78, 0x70, 0x60, 0x7F, 0x00, + 0x7F, 0x40, 0x4C, 0x4E, 0x4F, 0x43, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x43, + 0x4F, 0x4E, 0x4C, 0x40, 0x7F, 0x00, +}; +// clang-format on diff --git a/keyboards/yanghu/unicorne/info.json b/keyboards/yanghu/unicorne/info.json new file mode 100644 index 0000000000..995bed8a03 --- /dev/null +++ b/keyboards/yanghu/unicorne/info.json @@ -0,0 +1,62 @@ +{ + "keyboard_name": "Unicorne", + "url": "https://github.com/yanghu/unicorne", + "maintainer": "yanghu", + "layouts": { + "LAYOUT_unicorne": { + "layout": [ + {"label":"Tab", "x":0, "y":0.8}, + {"label":"Q", "x":1, "y":0.8}, + {"label":"W", "x":2, "y":0.1}, + {"label":"E", "x":3, "y":0}, + {"label":"R", "x":4, "y":0.1}, + {"label":"T", "x":5, "y":0.2}, + + {"label":"Y", "x":9, "y":0.2}, + {"label":"U", "x":10, "y":0.1}, + {"label":"I", "x":11, "y":0}, + {"label":"O", "x":12, "y":0.1}, + {"label":"P", "x":13, "y":0.8}, + {"label":"Back Space", "x":14, "y":0.8}, + + {"label":"Ctrl / Esc", "x":0, "y":1.8}, + {"label":"A", "x":1, "y":1.8}, + {"label":"S", "x":2, "y":1.1}, + {"label":"D", "x":3, "y":1}, + {"label":"F", "x":4, "y":1.1}, + {"label":"G", "x":5, "y":1.2}, + + {"label":"H", "x":9, "y":1.2}, + {"label":"J", "x":10, "y":1.1}, + {"label":"K", "x":11, "y":1}, + {"label":"L", "x":12, "y":1.1}, + {"label":";", "x":13, "y":1.8}, + {"label":"'", "x":14, "y":1.8}, + + {"label":"Shift", "x":0, "y":2.8}, + {"label":"Z", "x":1, "y":2.8}, + {"label":"X", "x":2, "y":2.1}, + {"label":"C", "x":3, "y":2}, + {"label":"V", "x":4, "y":2.1}, + {"label":"B", "x":5, "y":2.2}, + + {"label":"N", "x":9, "y":2.2}, + {"label":"M", "x":10, "y":2.1}, + {"label":",", "x":11, "y":2}, + {"label":".", "x":12, "y":2.1}, + {"label":"/", "x":13, "y":2.8}, + {"label":"Shift / Enter", "x":14, "y":2.8}, + + {"label":"Ctrl", "x":3, "y":3.7}, + {"label":"Alt", "x":4, "y":3.7}, + {"label":"Lower", "x":5, "y":3.7}, + {"label":"Enter", "x":6, "y":3.2, "h":1.5}, + + {"label":"Backspace", "x":8, "y":3.2, "h":1.5}, + {"label":"Space", "x":9, "y":3.7}, + {"label":"Raise", "x":10, "y":3.7}, + {"label":"RGUI", "x":11, "y":3.7} + ] + } + } +} diff --git a/keyboards/yanghu/unicorne/keymaps/default/config.h b/keyboards/yanghu/unicorne/keymaps/default/config.h new file mode 100644 index 0000000000..e7ee9814ef --- /dev/null +++ b/keyboards/yanghu/unicorne/keymaps/default/config.h @@ -0,0 +1,22 @@ +/* Copyright 2021 Yang Hu + * + * 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 + +#define OLED_FONT_H "keyboards/yanghu/unicorne/glcdfont.c" +#define ENCODER_RESOLUTION 4 +#define RGBLIGHT_DEFAULT_MODE RGBLIGHT_MODE_BREATHING +#define RGBLIGHT_DEFAULT_COLOR HSV_BLUE diff --git a/keyboards/yanghu/unicorne/keymaps/default/keymap.c b/keyboards/yanghu/unicorne/keymaps/default/keymap.c new file mode 100644 index 0000000000..26fb014260 --- /dev/null +++ b/keyboards/yanghu/unicorne/keymaps/default/keymap.c @@ -0,0 +1,92 @@ +/* Copyright 2021 Yang Hu + * + * 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 "layers.h" + +#define LOWER MO(_LOWER) +#define RAISE MO(_RAISE) +#define ADJUST MO(_ADJUST) + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_BASE] = LAYOUT_split_3x6_4( + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, + LCTL_T(KC_ESC), 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, RSFT_T(KC_ENT), + KC_LCTL, KC_LALT, LOWER, KC_ENT, KC_BSPC, KC_SPC, RAISE, KC_RGUI + ), + + [_LOWER] = LAYOUT_split_3x6_4( + _______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL, + _______, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_GRV, KC_TILD, + _______, KC_ESC, KC_LGUI, KC_LALT, KC_CAPS, KC_DQUO, KC_HOME, KC_END, KC_PGUP, KC_PGDN, KC_PSCR, RSFT_T(KC_SPC), + _______, _______, _______, _______, _______, _______, _______, _______ + ), + + [_RAISE] = LAYOUT_split_3x6_4( + _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, + _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, + _______, KC_ESC, KC_RGUI, KC_RALT, KC_CAPS, KC_QUOT, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, + _______, _______, _______, _______, _______, _______, _______, _______ + ), + + [_ADJUST] = LAYOUT_split_3x6_4( + RGB_VAI, RGB_SAI, RGB_HUI, RGB_MOD, XXXXXXX, RGB_TOG, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + RGB_VAD, RGB_SAD, RGB_HUD, RGB_RMOD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RESET, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + _______, _______, _______, _______, _______, _______, _______, _______ + ), +}; +// clang-format on +layer_state_t layer_state_set_user(layer_state_t state) { return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST); } + +// Left encoder scrolls the mousewheel. Right encoder adjusts underglow hue. +bool encoder_update_user(uint8_t index, bool clockwise) { + if (index == 0) { + if (clockwise) { +#ifdef MOUSEKEY_ENABLE + tap_code(KC_MS_WH_DOWN); +#else + tap_code(KC_PGDN); +#endif + } else { +#ifdef MOUSEKEY_ENABLE + tap_code(KC_MS_WH_UP); +#else + tap_code(KC_PGUP); +#endif + } + } else { // index = 1: right encoder + if (clockwise) { +#ifdef RGB_MATRIX_ENABLE + rgb_matrix_step(); +#else + rgblight_increase_hue_noeeprom(); +#endif + } else { +#ifdef RGB_MATRIX_ENABLE + rgb_matrix_step_reverse(); +#else + rgblight_decrease_hue_noeeprom(); +#endif + } + } + return false; +} + +// Set underglow color to blue. +void keyboard_post_init_user(void) { rgblight_sethsv_noeeprom(RGBLIGHT_DEFAULT_COLOR); } diff --git a/keyboards/yanghu/unicorne/keymaps/default/layers.h b/keyboards/yanghu/unicorne/keymaps/default/layers.h new file mode 100644 index 0000000000..0505d4956b --- /dev/null +++ b/keyboards/yanghu/unicorne/keymaps/default/layers.h @@ -0,0 +1,24 @@ +/* Copyright 2021 Yang Hu + * + * 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 +// Defines names for use in layer keycodes and the keymap +enum layer_names { + _BASE, + _LOWER, + _RAISE, + _ADJUST, +}; diff --git a/keyboards/yanghu/unicorne/keymaps/default/oled.c b/keyboards/yanghu/unicorne/keymaps/default/oled.c new file mode 100644 index 0000000000..417f573ff0 --- /dev/null +++ b/keyboards/yanghu/unicorne/keymaps/default/oled.c @@ -0,0 +1,67 @@ +/* Copyright 2021 Yang Hu + * + * 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 . + */ +#ifdef OLED_ENABLE +# include QMK_KEYBOARD_H +# include "layers.h" + +// Some characters position: +// alt: 84 85 86/a..../c... +// shift:87 88 89/a.../c... +// ctrl: b6 b6/d.../ +// capslock: 9c-9f/b.../d... +// numlock: 98-9b/b.../d... +// navigation logo: 92-95/b2.../d2... +// symbol logo: 8a-8d/aa..../ca.... +// qmk logos; 8e-91/ae..../ce.... +void oled_render_layer(void) { + /* static const char PROGMEM cmd_logo[] = { */ + /* 0x80, 0x81, 0x82, 0x83, 10, */ + /* 0xa0, 0xa1, 0xa2, 0xa3, 10, */ + /* 0xc0, 0xc1, 0xc2, 0xc3, 10, */ + /* 0}; */ + // clang-format off + static const char PROGMEM numlock_logo[] = { + 0x98, 0x99, 0x9a, 0x9b, 10, + 0xb8, 0xb9, 0xba, 0xbb, 10, + 0xd8, 0xd9, 0xda, 0xdb, 10, 0}; + static const char PROGMEM symbol_logo[] = { + 0x8a, 0x8b, 0x8c, 0x8d, 10, + 0xaa, 0xab, 0xac, 0xad, 10, + 0xca, 0xcb, 0xcc, 0xcd, 10, 0}; + static const char PROGMEM qmk_logo[] = { + 0x8e, 0x8f, 0x90, 0x91, 10, + 0xae, 0xaf, 0xb0, 0xb1, 10, + 0xce, 0xcf, 0xd0, 0xd1, 10, 0}; + // clang-format on + if (IS_LAYER_ON(_LOWER)) { + oled_write_P(symbol_logo, false); + } else if (IS_LAYER_ON(_RAISE)) { + oled_write_P(numlock_logo, false); + } else if (IS_LAYER_ON(_BASE)) { + oled_write_P(qmk_logo, false); + } else { + if (IS_LAYER_ON(_ADJUST)) { + oled_write_ln("ADJ", false); + } else { + oled_write_ln("?????", false); + } + oled_write_ln(" ", false); + oled_write_ln(" ", false); + oled_write_ln(" ", false); + } +} + +#endif diff --git a/keyboards/yanghu/unicorne/keymaps/default/readme.md b/keyboards/yanghu/unicorne/keymaps/default/readme.md new file mode 100644 index 0000000000..b6ce9e4237 --- /dev/null +++ b/keyboards/yanghu/unicorne/keymaps/default/readme.md @@ -0,0 +1,10 @@ +![keymap](https://imgur.com/48cFzA5.jpg) + +# Default Unicorne Layout + +This is the default layout for Unicorne. The "lower" layer consists of symbols +and navigation, while "raises' has numbers, some other symbols and function +keys. + +Press `lower` and `raise` together activates `adjust` layer, with RGB controls, +as well as access to reset/bootloader. diff --git a/keyboards/yanghu/unicorne/keymaps/default/rules.mk b/keyboards/yanghu/unicorne/keymaps/default/rules.mk new file mode 100644 index 0000000000..dbfa81b6ce --- /dev/null +++ b/keyboards/yanghu/unicorne/keymaps/default/rules.mk @@ -0,0 +1 @@ +SRC += oled.c diff --git a/keyboards/yanghu/unicorne/readme.md b/keyboards/yanghu/unicorne/readme.md new file mode 100644 index 0000000000..3da5e97bf4 --- /dev/null +++ b/keyboards/yanghu/unicorne/readme.md @@ -0,0 +1,17 @@ +# Unicorne + +![Unicorne](https://imgur.com/g1nN3b4h.jpg) + +A compact 40% (3x6\_4) single-piece angled ortholinear ergo keyboard kit inspired by crkbd, Kyria, Ferris and Reviung41. Features OLED display, audio buzzer, RGB LED underglow as well as encoders. + +* Keyboard Maintainer: [Yang Hu](https://github.com/yanghu) +* Hardware Supported: Unicorne PCB 1.0 +* Hardware Availability: Open source design at https://github.com/yanghu/unicorne + +To enter bootloader, long press the reset button for 3-5 seconds then release. More details can be found at [keyboard wiki](https://github.com/yanghu/unicorne/wiki/Build-guide#testing-the-board). + +Make example for this keyboard (after setting up your build environment): + + make yanghu/unicorne:default + +See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). diff --git a/keyboards/yanghu/unicorne/rules.mk b/keyboards/yanghu/unicorne/rules.mk new file mode 100644 index 0000000000..17296a9bc2 --- /dev/null +++ b/keyboards/yanghu/unicorne/rules.mk @@ -0,0 +1,26 @@ +# Build Options +# change yes to no to disable +# +BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite +MOUSEKEY_ENABLE = yes # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = no # Console for debug +COMMAND_ENABLE = no # Commands for debug and configuration +# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend +# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +NKRO_ENABLE = yes # USB Nkey Rollover +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow +AUDIO_ENABLE = yes # Audio output +ENCODER_ENABLE = yes +OLED_ENABLE = yes +OLED_DRIVER = SSD1306 + +WS2812_DRIVER = pwm +AUDIO_DRIVER = pwm_hardware + +RGB_MATRIX_ENABLE = no # Do not enable with RGBLIGHT +RGB_MATRIX_DRIVER = WS2812 + +DEFAULT_FOLDER = yanghu/unicorne/f411 diff --git a/keyboards/yanghu/unicorne/unicorne.c b/keyboards/yanghu/unicorne/unicorne.c new file mode 100644 index 0000000000..27b87253df --- /dev/null +++ b/keyboards/yanghu/unicorne/unicorne.c @@ -0,0 +1,148 @@ +/* Copyright 2021 Yang Hu + * + * 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 "unicorne.h" + + +// Custom i2c init to enable internal pull up resistor for i2c. +void i2c_init(void) { + static bool is_initialised = false; + if (!is_initialised) { + is_initialised = true; + + // Try releasing special pins for a short time + palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT); + palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT); + + chThdSleepMilliseconds(10); + // Use internal pull up since we do not have pull up on i2c pins in v1 design. + palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); + palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); + } +} + +// LED matrix +// physical location +// 2 3 4 5 +// +// 1 6 +// 0 7 +#ifdef RGB_MATRIX_ENABLE +// clang-format off +led_config_t g_led_config = {{ + // Key Matrix to LED Index + // Since we only have 8 LEDs, map the keys near them to the same LED. + {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5}, + {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5}, + {1, 1, 1, 0, 0, 0, 7, 7, 7, 6, 6, 6}, + {NO_LED, NO_LED, NO_LED, 0, 0, 0, 7, 7, 7, NO_LED, NO_LED, NO_LED}, +}, {// LED Index to Physical Position + {94, 60}, + {18, 44}, + {8, 10}, + {94, 10}, + {130,10}, + {216, 10}, + {208, 44}, + {130, 60} +}, {// LED Index to Flag + LED_FLAG_ALL, LED_FLAG_ALL, LED_FLAG_ALL, LED_FLAG_ALL, LED_FLAG_ALL, + LED_FLAG_ALL, LED_FLAG_ALL, LED_FLAG_ALL +}}; +// clang-format on +#endif + +#ifdef OLED_ENABLE +// OLED shared code +// The oled is vertical. Need to rotate 270 degrees. +__attribute__((weak)) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_270; } + +// Render layer status on OLED. To be re-implemented by keymaps since layers are +// defined there. +__attribute__((weak)) void oled_render_layer(void) { return; } + +// Oneshot mods status +uint8_t osmods; + +__attribute__((weak)) void oled_render_mods(void) { + static const char PROGMEM ctrl[] = {0xb6, 0xb7, 10, 0xd6, 0xd7, 10, 0x20, 0x20, 10, 0}; + static const char PROGMEM shift[] = {0x87, 0x88, 0x89, 10, 0xa7, 0xa8, 0xa9, 10, 0xc7, 0xc8, 0xc9, 10, 0}; + static const char PROGMEM alt[] = {0x84, 0x85, 0x86, 10, 0xa4, 0xa5, 0xa6, 10, 0xc4, 0xc5, 0xc6, 10, 0}; + static const char PROGMEM ctrl_alt[] = {0xb6, 0xb7, 0x84, 0x85, 0x86, 0xd6, 0xd7, 0xa4, 0xa5, 0xa6, 0x20, 0x20, 0xc4, 0xc5, 0xc6, 0}; + + static const char PROGMEM ctrl_shift[] = {0xb6, 0xb7, 0x87, 0x88, 0x89, 0xd6, 0xd7, 0xa7, 0xa8, 0xa9, 0x20, 0x20, 0xc7, 0xc8, 0xc9, 0}; + static const char PROGMEM c_a_shift[] = {0xb6, 0xb7, 0x84, 0x85, 0x86, 0xd6, 0xd7, 0xa4, 0xa5, 0xa6, 0x20, 0x20, 0xc4, 0xc5, 0xc6, 0x87, 0x88, 0x89, 10, 0xa7, 0xa8, 0xa9, 10, 0xc7, 0xc8, 0xc9, 10, 0}; + // Now check mod status and render. + static uint8_t mods; + mods = get_mods() | osmods; + if ((mods & MOD_MASK_CTRL) && (mods & MOD_MASK_ALT) && (mods & MOD_MASK_SHIFT)) { + oled_write_P(c_a_shift, false); + } else if ((mods & MOD_MASK_CTRL) && (mods & MOD_MASK_ALT)) { + oled_write_P(ctrl_alt, false); + } else if ((mods & MOD_MASK_CTRL) && (mods & MOD_MASK_SHIFT)) { + oled_write_P(ctrl_shift, false); + } else if ((mods & MOD_MASK_SHIFT) && (mods & MOD_MASK_ALT)) { + oled_write_P(alt, false); + oled_write_P(shift, false); + } else if (mods & MOD_MASK_CTRL) { + oled_write_P(ctrl, false); + } else if (mods & MOD_MASK_ALT) { + oled_write_P(alt, false); + } else if (mods & MOD_MASK_SHIFT) { + oled_write_P(shift, false); + } else { + for (int i = 0; i < 6; ++i) { + oled_write_ln(" ", false); + } + } + return; +} + +void oneshot_mods_changed_user(uint8_t mods) { osmods = mods; } + +// Call this from "led_update_user" and use `led_state.caps_lock` to check +// the status of capslock. +__attribute__((weak)) void oled_render_capslock(bool caps_on) { + static const char PROGMEM capslock_logo[] = {0x9c, 0x9d, 0x9e, 0x9f, 10, 0xbc, 0xbd, 0xbe, 0xbf, 10, 0xdc, 0xdd, 0xde, 0xdf, 10, 0}; + if (caps_on) { + oled_write_P(capslock_logo, false); + } else { + for (int i = 0; i < 3; ++i) { + oled_write_ln(" ", false); + } + } +} + +char keylog_str[24] = {}; + +const char code_to_name[60] = {' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\', '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '}; + +void set_keylog(uint16_t keycode, keyrecord_t *record) { + if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { + keycode = keycode & 0xFF; + } +} + +__attribute__((weak)) void oled_render_keylog(void) { oled_write(keylog_str, false); } + +// Keymaps can override this function +__attribute__((weak)) void oled_task_user(void) { + /* oled_render_keylog(); */ + oled_render_layer(); + oled_render_mods(); + led_t led_state = host_keyboard_led_state(); + oled_render_capslock(led_state.caps_lock); +} +#endif diff --git a/keyboards/yanghu/unicorne/unicorne.h b/keyboards/yanghu/unicorne/unicorne.h new file mode 100644 index 0000000000..f0b5685f1d --- /dev/null +++ b/keyboards/yanghu/unicorne/unicorne.h @@ -0,0 +1,50 @@ +/* Copyright 2021 Yang Hu + * + * 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" + +#ifdef OLED_ENABLE +void oled_render_capslock(bool caps_on); +void oled_render_mods(void); +void oled_render_keylog(void); +#endif +/* This a shortcut to help you visually see your layout. + * + * The first section contains all of the arguments representing the physical + * layout of the board and position of the keys. + * + * The second converts the arguments into a two-dimensional array which + * represents the switch matrix. + */ + +// clang-format off +#define LAYOUT_split_3x6_4( \ + K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, \ + K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, \ + K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, \ + K30, K31, K32, K33, K34, K35, K36, K37 \ +) \ +{ \ + { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B }, \ + { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B }, \ + { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B }, \ + { KC_NO, KC_NO, K30, K31, K32, K33, K34, K35, K36, K37, KC_NO, KC_NO} \ +} +// clang-format on + +#define LAYOUT LAYOUT_split_3x6_4