1
0

fantastic60: Implement simple controlling of RGB LED

This commit is contained in:
Kai Ryu 2014-12-05 12:31:42 +09:00
parent 7f0496bc81
commit ce4722ef25
7 changed files with 146 additions and 19 deletions

View File

@ -52,7 +52,8 @@ SRC = keymap_common.c \
matrix.c \ matrix.c \
led.c \ led.c \
backlight.c \ backlight.c \
ledmap.c ledmap.c \
fantastic.c
ifdef KEYMAP ifdef KEYMAP
SRC := keymap_$(KEYMAP).c $(SRC) 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_IN_EEPROM_ENABLE = yes # Read keymap from eeprom
#KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor #KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight 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 BREATHING_LED_ENABLE = yes # Enable breathing backlight
LEDMAP_ENABLE = yes # Enable LED mapping LEDMAP_ENABLE = yes # Enable LED mapping
LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom

View File

@ -52,7 +52,8 @@ SRC = keymap_common.c \
matrix.c \ matrix.c \
led.c \ led.c \
backlight.c \ backlight.c \
ledmap.c ledmap.c \
fantastic.c
ifdef KEYMAP ifdef KEYMAP
SRC := keymap_$(KEYMAP).c $(SRC) SRC := keymap_$(KEYMAP).c $(SRC)

View File

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
#include <avr/interrupt.h>
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0x6C4E #define VENDOR_ID 0x6C4E
@ -51,8 +52,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#else #else
#define BACKLIGHT_LEVELS 3 #define BACKLIGHT_LEVELS 3
#endif #endif
#define BACKLIGHT_CUSTOM
#define LED_COUNT 2 /* number of leds */
#define LED_COUNT 3
/* ledmap in eeprom */ /* ledmap in eeprom */
#define EECONFIG_LEDMAP_IN_EEPROM 8 #define EECONFIG_LEDMAP_IN_EEPROM 8
@ -95,8 +98,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* disable action features */ /* disable action features */
//#define NO_ACTION_LAYER //#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING //#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT #define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO #define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION //#define NO_ACTION_FUNCTION
#endif #endif

View File

@ -0,0 +1,69 @@
/*
Copyright 2014 Kai Ryu <kai1103@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/>.
*/
#include "fantastic.h"
void shift_register_init(void)
{
SR_DDR |= (1<<SR_CLK_BIT | 1<<SR_DATA_BIT | 1<<SR_LATCH_BIT);
SR_PORT &= ~(1<<SR_CLK_BIT | 1<<SR_DATA_BIT | 1<<SR_LATCH_BIT);
}
void shift_register_write_byte(uint8_t byte)
{
uint8_t i = 7;
do {
shift_register_data((byte >> 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<<SR_CLK_BIT);
SR_PORT &= ~(1<<SR_CLK_BIT);
}
inline
void shift_register_data(uint8_t bit)
{
if (bit) {
SR_PORT |= (1<<SR_DATA_BIT);
}
else {
SR_PORT &= ~(1<<SR_DATA_BIT);
}
}
inline
void shift_register_latch(void)
{
SR_PORT &= ~(1<<SR_LATCH_BIT);
SR_PORT |= (1<<SR_LATCH_BIT);
}

View File

@ -0,0 +1,37 @@
/*
Copyright 2014 Kai Ryu <kai1103@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 FANTASTIC_H
#define FANTASTIC_H
#include <avr/io.h>
#include <stdint.h>
#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

View File

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "keymap_common.h" #include "keymap_common.h"
/* translates key to keycode */ /* 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 #ifndef KEYMAP_IN_EEPROM_ENABLE
return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);

View File

@ -17,31 +17,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include "ledmap.h" #include "ledmap.h"
#include "fantastic.h"
#ifdef LEDMAP_ENABLE #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 [0] = LEDMAP_CAPS_LOCK | LEDMAP_BACKLIGHT, // CapsLock
[1] = LEDMAP_BACKLIGHT, // Backlight [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 /* LED pin configration
* CapsLock: PC7 * CapsLock: PE6
* NumLock: PE6 * Backlight: PF7
* Logo: PC6 * RGB R: PE2
* Backlight: PB7 * RGB G: PC6
* RGB B: PC7
*/ */
void ledmap_led_init(void) void ledmap_led_init(void)
{ {
DDRE |= (1<<PE6); DDRE |= (1<<PE6 | 1<<PE2);
PORTE |= (1<<PE6); PORTE |= (1<<PE6 | 1<<PE2);
DDRF |= (1<<PF7); DDRF |= (1<<PF7);
PORTF &= ~(1<<PF7); PORTF |= (1<<PF7);
DDRC |= (1<<PC7 | 1<<PC6);
PORTF |= (1<<PC7 | 1<<PC6);
shift_register_init();
shift_register_write_word(0x0000);
} }
void ledmap_led_on(uint8_t index) void ledmap_led_on(uint8_t index)
@ -51,7 +58,12 @@ void ledmap_led_on(uint8_t index)
PORTE &= ~(1<<PE6); PORTE &= ~(1<<PE6);
break; break;
case 1: case 1:
PORTF |= (1<<PF7); PORTF &= ~(1<<PF7);
break;
case 2:
PORTE &= ~(1<<PE2);
PORTC &= ~(1<<PC7 | 1<<PC6);
break;
} }
} }
@ -62,7 +74,11 @@ void ledmap_led_off(uint8_t index)
PORTE |= (1<<PE6); PORTE |= (1<<PE6);
break; break;
case 1: case 1:
PORTF &= ~(1<<PF7); PORTF |= (1<<PF7);
break;
case 2:
PORTE |= (1<<PE2);
PORTC |= (1<<PC7 | 1<<PC6);
break; break;
} }
} }