Browse Source

staryu: Update codes to support v1.4 hardware

master
Kai Ryu 7 years ago
parent
commit
42bf46523a

+ 1
- 1
keyboard/staryu/backlight.c View File

@@ -35,7 +35,7 @@ uint8_t backlight_brightness;

void backlight_set(uint8_t level)
{
softpwm_led_enable();
softpwm_enable();
switch (level) {
case 1:
case 2:

+ 6
- 4
keyboard/staryu/config.h View File

@@ -20,10 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.


/* USB Device descriptor parameter */
#define VENDOR_ID 0x8133
#define PRODUCT_ID 0x0120
#define DEVICE_VER 0x0103
#define MANUFACTURER Noukensha
#define VENDOR_ID 0x1209
#define PRODUCT_ID 0x2333
#define DEVICE_VER 0x0104
#define MANUFACTURER K.T.E.C.
#define PRODUCT Staryu
#define DESCRIPTION t.m.k. keyboard firmware for Staryu

@@ -43,6 +43,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

/* number of backlight levels */
#define BACKLIGHT_LEVELS 7
#define CUSTOM_LED_ENABLE
#define RGB_LED_ENABLE

/* number of LEDs */
#define LED_COUNT 6

+ 7
- 5
keyboard/staryu/config_lite.h View File

@@ -20,11 +20,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.


/* USB Device descriptor parameter */
#define VENDOR_ID 0x8133
#define PRODUCT_ID 0x0120
#define DEVICE_VER 0x0103
#define MANUFACTURER Noukensha
#define PRODUCT Staryu
#define VENDOR_ID 0x1209
#define PRODUCT_ID 0x2333
#define DEVICE_VER 0x0104
#define MANUFACTURER K.T.E.C.
#define PRODUCT Staryu Lite
#define DESCRIPTION t.m.k. keyboard firmware for Staryu

/* key matrix size */
@@ -43,6 +43,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

/* number of backlight levels */
#define BACKLIGHT_LEVELS 7
#define CUSTOM_LED_ENABLE
#define RGB_LED_ENABLE

/* number of LEDs */
#define LED_COUNT 6

+ 44
- 10
keyboard/staryu/rgb.c View File

@@ -22,11 +22,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "rgb.h"
#include "light_ws2812.h"

#ifdef RGB_LED_ENABLE

volatile static uint8_t rgb_fading_enable = 0;
static rgb_config_t rgb_config;
static struct cRGB rgb_color[RGB_LED_COUNT];
static uint16_t rgb_hue = 0;
static uint8_t rgb_saturation = 255;
static uint8_t rgb_brightness = 16;
static uint8_t rgb_rainbow = 0;

extern backlight_config_t backlight_config;
extern uint8_t backlight_brightness;
@@ -118,12 +122,21 @@ void rgb_step(void)

void rgb_set_level(uint8_t level)
{
if (level == RGB_OFF) {
rgb_brightness = 0;
}
else if (backlight_config.enable) {
if (backlight_config.level >= 1 && backlight_config.level <= 3) {
rgb_brightness = backlight_brightness;
}
}
else {
rgb_brightness = 16;
}
if (level <= RGB_WHITE) {
rgb_fading_enable = 0;
if (level == RGB_OFF) {
rgb_brightness = 0;
}
else {
rgb_rainbow = 0;
if (level != RGB_OFF) {
if (level == RGB_WHITE) {
rgb_saturation = 0;
}
@@ -144,23 +157,41 @@ void rgb_set_level(uint8_t level)
}
else {
rgb_saturation = 255;
rgb_fading_enable = 3 - (level - RGB_FADE_SLOW);
rgb_fading_enable = 1;
rgb_rainbow = (level >= RGB_RAINBOW) ? 1 : 0;
}
}

void rgb_set_brightness(uint8_t brightness)
{
rgb_brightness = brightness;
rgb_refresh();
if (rgb_config.enable) {
rgb_brightness = brightness;
rgb_refresh();
}
}

void rgb_refresh(void)
{
struct cRGB rgb_color[1];
hsb_to_rgb(rgb_hue, rgb_saturation, rgb_brightness, rgb_color);
ws2812_setleds(rgb_color, 1);
struct cRGB rgb;
uint16_t hue;
uint8_t i;
if (rgb_rainbow) {
for (i = 0; i < RGB_LED_COUNT; i++) {
hue = rgb_hue + (768 / RGB_LED_COUNT) * i;
hsb_to_rgb(hue, rgb_saturation, rgb_brightness, &rgb);
rgb_color[i] = rgb;
}
}
else {
hsb_to_rgb(rgb_hue, rgb_saturation, rgb_brightness, &rgb);
for (i = 0; i < RGB_LED_COUNT; i++) {
rgb_color[i] = rgb;
}
}
ws2812_setleds(rgb_color, RGB_LED_COUNT);
}

#if 0
void hue_to_rgb(uint16_t hue, struct cRGB *rgb)
{
uint8_t hi = hue / 60;
@@ -175,6 +206,7 @@ void hue_to_rgb(uint16_t hue, struct cRGB *rgb)
case 5: rgb->r = 255; rgb->g = 0; rgb->b = q; break;
}
}
#endif

/*
* original code: https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/
@@ -208,3 +240,5 @@ void rgb_fading(void)
}
}
}

#endif

+ 4
- 4
keyboard/staryu/rgb.h View File

@@ -38,14 +38,14 @@ enum {
RGB_BLUE,
RGB_MAGENTA,
RGB_WHITE,
RGB_FADE_SLOW,
RGB_FADE_MID,
RGB_FADE_FAST,
RGB_LEVELS = RGB_FADE_FAST
RGB_FADE,
RGB_RAINBOW,
RGB_LEVELS = RGB_RAINBOW
};

#define EECONFIG_RGB (uint8_t *)7
#define RGB_UNCONFIGURED 0xFF
#define RGB_LED_COUNT 16

void rgb_init(void);
void rgb_toggle(void);