From ce4722ef25be5a9c0248485ec52d46f2fcd3c996 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 5 Dec 2014 12:31:42 +0900 Subject: [PATCH] fantastic60: Implement simple controlling of RGB LED --- keyboard/fantastic60/Makefile | 5 +- keyboard/fantastic60/Makefile.pjrc | 3 +- keyboard/fantastic60/config.h | 9 ++-- keyboard/fantastic60/fantastic.c | 69 ++++++++++++++++++++++++++++ keyboard/fantastic60/fantastic.h | 37 +++++++++++++++ keyboard/fantastic60/keymap_common.c | 2 +- keyboard/fantastic60/ledmap.c | 40 +++++++++++----- 7 files changed, 146 insertions(+), 19 deletions(-) create mode 100644 keyboard/fantastic60/fantastic.c create mode 100644 keyboard/fantastic60/fantastic.h diff --git a/keyboard/fantastic60/Makefile b/keyboard/fantastic60/Makefile index 5f82acc8..a8cae939 100644 --- a/keyboard/fantastic60/Makefile +++ b/keyboard/fantastic60/Makefile @@ -52,7 +52,8 @@ SRC = keymap_common.c \ matrix.c \ led.c \ backlight.c \ - ledmap.c + ledmap.c \ + fantastic.c ifdef KEYMAP SRC := keymap_$(KEYMAP).c $(SRC) @@ -135,7 +136,7 @@ BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom #KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight -FADING_LED_ENABLE = yes # Enable fading backlight +#FADING_LED_ENABLE = yes # Enable fading backlight BREATHING_LED_ENABLE = yes # Enable breathing backlight LEDMAP_ENABLE = yes # Enable LED mapping LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom diff --git a/keyboard/fantastic60/Makefile.pjrc b/keyboard/fantastic60/Makefile.pjrc index 326816ba..ddc1b4d1 100644 --- a/keyboard/fantastic60/Makefile.pjrc +++ b/keyboard/fantastic60/Makefile.pjrc @@ -52,7 +52,8 @@ SRC = keymap_common.c \ matrix.c \ led.c \ backlight.c \ - ledmap.c + ledmap.c \ + fantastic.c ifdef KEYMAP SRC := keymap_$(KEYMAP).c $(SRC) diff --git a/keyboard/fantastic60/config.h b/keyboard/fantastic60/config.h index 6f136e77..3f736f75 100644 --- a/keyboard/fantastic60/config.h +++ b/keyboard/fantastic60/config.h @@ -18,6 +18,7 @@ along with this program. If not, see . #ifndef CONFIG_H #define CONFIG_H +#include /* USB Device descriptor parameter */ #define VENDOR_ID 0x6C4E @@ -51,8 +52,10 @@ along with this program. If not, see . #else #define BACKLIGHT_LEVELS 3 #endif +#define BACKLIGHT_CUSTOM -#define LED_COUNT 2 +/* number of leds */ +#define LED_COUNT 3 /* ledmap in eeprom */ #define EECONFIG_LEDMAP_IN_EEPROM 8 @@ -95,8 +98,8 @@ along with this program. If not, see . /* disable action features */ //#define NO_ACTION_LAYER //#define NO_ACTION_TAPPING -//#define NO_ACTION_ONESHOT -//#define NO_ACTION_MACRO +#define NO_ACTION_ONESHOT +#define NO_ACTION_MACRO //#define NO_ACTION_FUNCTION #endif diff --git a/keyboard/fantastic60/fantastic.c b/keyboard/fantastic60/fantastic.c new file mode 100644 index 00000000..42b92521 --- /dev/null +++ b/keyboard/fantastic60/fantastic.c @@ -0,0 +1,69 @@ +/* +Copyright 2014 Kai Ryu + +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 "fantastic.h" + +void shift_register_init(void) +{ + SR_DDR |= (1<> i) & 1); + shift_register_clk(); + } while (i--); + shift_register_latch(); +} + +void shift_register_write_word(uint16_t word) +{ + uint8_t i = 15; + do { + shift_register_data((word >> i) & 1); + shift_register_clk(); + } while (i--); + shift_register_latch(); +} + +inline +void shift_register_clk(void) +{ + SR_PORT |= (1< + +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 FANTASTIC_H +#define FANTASTIC_H + +#include +#include + +#define SR_PORT PORTF +#define SR_DDR DDRF +#define SR_CLK_BIT PF6 +#define SR_DATA_BIT PF5 +#define SR_LATCH_BIT PF4 + +void shift_register_init(void); +void shift_register_write_byte(uint8_t byte); +void shift_register_write_word(uint16_t word); +void shift_register_clk(void); +void shift_register_data(uint8_t bit); +void shift_register_latch(void); + +#endif diff --git a/keyboard/fantastic60/keymap_common.c b/keyboard/fantastic60/keymap_common.c index 6ab88064..5d03cffe 100644 --- a/keyboard/fantastic60/keymap_common.c +++ b/keyboard/fantastic60/keymap_common.c @@ -17,7 +17,7 @@ along with this program. If not, see . #include "keymap_common.h" /* translates key to keycode */ -uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { #ifndef KEYMAP_IN_EEPROM_ENABLE return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); diff --git a/keyboard/fantastic60/ledmap.c b/keyboard/fantastic60/ledmap.c index 788eae0b..279316b0 100644 --- a/keyboard/fantastic60/ledmap.c +++ b/keyboard/fantastic60/ledmap.c @@ -17,31 +17,38 @@ along with this program. If not, see . #include #include "ledmap.h" +#include "fantastic.h" #ifdef LEDMAP_ENABLE -static const uint8_t ledmaps[LED_COUNT] PROGMEM = { +static const uint16_t ledmaps[LED_COUNT] PROGMEM = { [0] = LEDMAP_CAPS_LOCK | LEDMAP_BACKLIGHT, // CapsLock [1] = LEDMAP_BACKLIGHT, // Backlight + [2] = LEDMAP_BACKLIGHT, // RGB Light }; -uint8_t ledmap_get_code(uint8_t index) +ledmap_t ledmap_get_code(uint8_t index) { - return pgm_read_byte(&ledmaps[index]); + return (ledmap_t) { .code = pgm_read_word(&ledmaps[index]) }; } /* LED pin configration - * CapsLock: PC7 - * NumLock: PE6 - * Logo: PC6 - * Backlight: PB7 + * CapsLock: PE6 + * Backlight: PF7 + * RGB R: PE2 + * RGB G: PC6 + * RGB B: PC7 */ void ledmap_led_init(void) { - DDRE |= (1<