Do not duplicate kbled support. Add kbled_max and kbled_get_color functions

This commit is contained in:
Jeremy Soller 2021-01-05 13:15:59 -07:00 committed by Jeremy Soller
parent 9309efb3e0
commit 5bab59a526
28 changed files with 148 additions and 309 deletions

View File

@ -6,6 +6,9 @@ EC=it8587e
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=rgb_pwm
# Set discrete GPU I2C bus
CFLAGS+=-DI2C_DGPU=I2C_1

View File

@ -6,6 +6,9 @@ EC=it5570e
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=rgb_pwm
# Set discrete GPU I2C bus
CFLAGS+=-DI2C_DGPU=I2C_1

View File

@ -1,36 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <board/kbled.h>
#include <ec/pwm.h>
void kbled_init(void) {
//TODO: enable PWMs
kbled_reset();
}
void kbled_reset(void) {
// Set brightness and color
kbled_set_color(0xFFFFFF);
kbled_set(0x00);
}
uint8_t kbled_get(void) {
// Get PWM for power
return DCR0;
}
void kbled_set(uint8_t level) {
// Set PWM for power
DCR0 = level;
}
void kbled_set_color(uint32_t color) {
// Set PWM for blue component
DCR7 = (uint8_t)(color);
// Set PWM for green component
DCR6 = (uint8_t)(color >> 8);
// Set PWM for red component
DCR5 = (uint8_t)(color >> 16);
}

View File

@ -6,6 +6,9 @@ EC=it5570e
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=bonw14
# Set discrete GPU I2C bus
CFLAGS+=-DI2C_DGPU=I2C_1

View File

@ -28,6 +28,10 @@ CFLAGS+=-I$(SYSTEM76_COMMON_DIR)/include
CHARGER?=bq24780s
SRC+=$(SYSTEM76_COMMON_DIR)/charger/$(CHARGER).c
# Add kbled
KBLED?=none
SRC+=$(SYSTEM76_COMMON_DIR)/kbled/$(KBLED).c
# Add scratch ROM
include $(SYSTEM76_COMMON_DIR)/scratch/scratch.mk

View File

@ -9,7 +9,9 @@
void kbled_init(void);
void kbled_reset(void);
uint8_t kbled_get(void);
uint8_t kbled_max(void);
void kbled_set(uint8_t level);
uint32_t kbled_get_color(void);
void kbled_set_color(uint32_t color);
// Provided by common code

View File

@ -27,16 +27,13 @@ void kbled_reset(void) {
kbled_set(0x00);
}
uint8_t kbled_get(void) {
return 0;
}
// Keep the following functions for compatibility - they are set via USB HID
uint8_t kbled_get(void) { /*Always off*/ return 0; }
void kbled_set(uint8_t level) {
// Keep function for compatibility - this is set via USB HID
level = level;
}
uint8_t kbled_max(void) { /*Always off*/ return 0; }
void kbled_set_color(uint32_t color) {
// Keep function for compatibility - this is set via USB HID
color = color;
}
void kbled_set(uint8_t level) { /*Fix unused variable*/ level = level; }
uint32_t kbled_get_color(void) { /*Always black*/ return 0; }
void kbled_set_color(uint32_t color) { /*Fix unused variable*/ color = color; }

View File

@ -39,10 +39,31 @@ uint8_t kbled_get(void) {
return level;
}
uint8_t kbled_max(void) {
return 255;
}
void kbled_set(uint8_t level) {
kbled_i2c_set(0x12, &level, 1);
}
uint32_t kbled_get_color(void) {
// Get blue component from channel 0
uint8_t value;
kbled_i2c_get(0x02, &value, 1);
uint32_t color = (uint32_t)value;
// Get green component from channel 3
kbled_i2c_get(0x05, &value, 1);
color |= ((uint32_t)value) << 8;
// Get red component from channel 6
kbled_i2c_get(0x08, &value, 1);
color |= ((uint32_t)value) << 16;
return color;
}
void kbled_set_color(uint32_t color) {
// Set channel 0 - 2 to blue component
uint8_t value = (uint8_t)(color);

View File

@ -0,0 +1,17 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <board/kbled.h>
void kbled_init(void) {}
void kbled_reset(void) {}
uint8_t kbled_get(void) { /*Always off*/ return 0; }
uint8_t kbled_max(void) { /*Always off*/ return 0; }
void kbled_set(uint8_t level) { /*Fix unused variable*/ level = level; }
uint32_t kbled_get_color(void) { /*Always black*/ return 0; }
void kbled_set_color(uint32_t color) { /*Fix unused variable*/ color = color; }

View File

@ -39,10 +39,31 @@ uint8_t kbled_get(void) {
return level;
}
uint8_t kbled_max(void) {
return 255;
}
void kbled_set(uint8_t level) {
kbled_i2c_set(0x12, &level, 1);
}
uint32_t kbled_get_color(void) {
// Get blue component
uint8_t value;
kbled_i2c_get(0x02, &value, 1);
uint32_t color = (uint32_t)value;
// Get green component
kbled_i2c_get(0x03, &value, 1);
color |= ((uint32_t)value) << 8;
// Get red component
kbled_i2c_get(0x04, &value, 1);
color |= ((uint32_t)value) << 16;
return color;
}
void kbled_set_color(uint32_t color) {
// Set blue component
uint8_t value = (uint8_t)(color);
@ -50,13 +71,13 @@ void kbled_set_color(uint32_t color) {
kbled_i2c_set(0x05, &value, 1);
kbled_i2c_set(0x08, &value, 1);
// Set red component
// Set green component
value = (uint8_t)(color >> 8);
kbled_i2c_set(0x03, &value, 1);
kbled_i2c_set(0x06, &value, 1);
kbled_i2c_set(0x09, &value, 1);
// Set green component
// Set red component
value = (uint8_t)(color >> 16);
kbled_i2c_set(0x04, &value, 1);
kbled_i2c_set(0x07, &value, 1);

View File

@ -19,11 +19,28 @@ uint8_t kbled_get(void) {
return DCR0;
}
uint8_t kbled_max(void) {
return 255;
}
void kbled_set(uint8_t level) {
// Set PWM for power
DCR0 = level;
}
uint32_t kbled_get_color(void) {
// Get PWM of blue component
uint32_t color = (uint32_t)DCR7;
// Get PWM of green component
color |= ((uint32_t)DCR6) << 8;
// Get PWM of red component
color |= ((uint32_t)DCR5) << 16;
return color;
}
void kbled_set_color(uint32_t color) {
// Set PWM for blue component
DCR7 = (uint8_t)(color);

View File

@ -4,8 +4,11 @@
#include <common/macro.h>
#include <ec/dac.h>
#define KBLED_DAC 2
#define KBLED_DACDAT DACDAT2
#if !defined(KBLED_DAC)
#error "KBLED_DAC must be defined"
#endif
#define KBLED_DACDAT xconcat(DACDAT, KBLED_DAC)
static uint8_t __code levels[] = {
0x00,
@ -37,6 +40,10 @@ uint8_t kbled_get(void) {
return 0;
}
uint8_t kbled_max(void) {
return ARRAY_SIZE(levels) - 1;
}
void kbled_set(uint8_t level) {
uint8_t raw = 0;
if (level < ARRAY_SIZE(levels)) {
@ -45,4 +52,6 @@ void kbled_set(uint8_t level) {
KBLED_DACDAT = raw;
}
uint32_t kbled_get_color(void) { /* Always white */ return 0xFFFFFF; }
void kbled_set_color(uint32_t color) { /*Fix unused variable*/ color = color; }

View File

@ -6,12 +6,13 @@ EC=it8587e
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=darp5
CFLAGS+=-DI2C_KBLED=I2C_1
# Set battery I2C bus
CFLAGS+=-DI2C_SMBUS=I2C_0
# Set keyboard LED I2C bus
CFLAGS+=-DI2C_KBLED=I2C_1
# Set touchpad PS2 bus
CFLAGS+=-DPS2_TOUCHPAD=PS2_3

View File

@ -9,6 +9,9 @@ CFLAGS+=-DEC_ESPI=1
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=rgb_pwm
# Set battery I2C bus
CFLAGS+=-DI2C_SMBUS=I2C_4

View File

@ -1,36 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <board/kbled.h>
#include <ec/pwm.h>
void kbled_init(void) {
//TODO: enable PWMs
kbled_reset();
}
void kbled_reset(void) {
// Set brightness and color
kbled_set_color(0xFFFFFF);
kbled_set(0x00);
}
uint8_t kbled_get(void) {
// Get PWM for power
return DCR0;
}
void kbled_set(uint8_t level) {
// Set PWM for power
DCR0 = level;
}
void kbled_set_color(uint32_t color) {
// Set PWM for blue component
DCR7 = (uint8_t)(color);
// Set PWM for green component
DCR6 = (uint8_t)(color >> 8);
// Set PWM for red component
DCR5 = (uint8_t)(color >> 16);
}

View File

@ -6,6 +6,10 @@ EC=it8587e
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=white_dac
CFLAGS+=-DKBLED_DAC=5
# Set battery I2C bus
CFLAGS+=-DI2C_SMBUS=I2C_0

View File

@ -1,48 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <board/kbled.h>
#include <common/macro.h>
#include <ec/dac.h>
#define KBLED_DAC 5
#define KBLED_DACDAT DACDAT5
static uint8_t __code levels[] = {
0x00,
0x80,
0x90,
0xA8,
0xC0,
0xFF
};
void kbled_init(void) {
// Enable DAC used for KBLIGHT_ADJ
DACPDREG &= ~(1 << KBLED_DAC);
kbled_reset();
}
void kbled_reset(void) {
kbled_set(0);
}
uint8_t kbled_get(void) {
uint8_t level;
uint8_t raw = KBLED_DACDAT;
for (level = 0; level < ARRAY_SIZE(levels); level++) {
if (raw <= levels[level]) {
return level;
}
}
return 0;
}
void kbled_set(uint8_t level) {
uint8_t raw = 0;
if (level < ARRAY_SIZE(levels)) {
raw = levels[level];
}
KBLED_DACDAT = raw;
}
void kbled_set_color(uint32_t color) { /*Fix unused variable*/ color = color; }

View File

@ -9,6 +9,10 @@ CFLAGS+=-DEC_ESPI=1
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=white_dac
CFLAGS+=-DKBLED_DAC=2
# Set discrete GPU I2C bus
CFLAGS+=-DI2C_DGPU=I2C_1

View File

@ -6,6 +6,9 @@ EC=it5570e
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=rgb_pwm
# Set discrete GPU I2C bus
CFLAGS+=-DI2C_DGPU=I2C_1

View File

@ -1,36 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <board/kbled.h>
#include <ec/pwm.h>
void kbled_init(void) {
//TODO: enable PWMs
kbled_reset();
}
void kbled_reset(void) {
// Set brightness and color
kbled_set_color(0xFFFFFF);
kbled_set(0x00);
}
uint8_t kbled_get(void) {
// Get PWM for power
return DCR0;
}
void kbled_set(uint8_t level) {
// Set PWM for power
DCR0 = level;
}
void kbled_set_color(uint32_t color) {
// Set PWM for blue component
DCR7 = (uint8_t)(color);
// Set PWM for green component
DCR6 = (uint8_t)(color >> 8);
// Set PWM for red component
DCR5 = (uint8_t)(color >> 16);
}

View File

@ -9,6 +9,10 @@ CFLAGS+=-DEC_ESPI=1
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=white_dac
CFLAGS+=-DKBLED_DAC=2
# Set battery I2C bus
CFLAGS+=-DI2C_SMBUS=I2C_4

View File

@ -1,48 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <board/kbled.h>
#include <common/macro.h>
#include <ec/dac.h>
#define KBLED_DAC 2
#define KBLED_DACDAT DACDAT2
static uint8_t __code levels[] = {
0x00,
0x80,
0x90,
0xA8,
0xC0,
0xFF
};
void kbled_init(void) {
// Enable DAC used for KBLIGHT_ADJ
DACPDREG &= ~BIT(KBLED_DAC);
kbled_reset();
}
void kbled_reset(void) {
kbled_set(0);
}
uint8_t kbled_get(void) {
uint8_t level;
uint8_t raw = KBLED_DACDAT;
for (level = 0; level < ARRAY_SIZE(levels); level++) {
if (raw <= levels[level]) {
return level;
}
}
return 0;
}
void kbled_set(uint8_t level) {
uint8_t raw = 0;
if (level < ARRAY_SIZE(levels)) {
raw = levels[level];
}
KBLED_DACDAT = raw;
}
void kbled_set_color(uint32_t color) { /*Fix unused variable*/ color = color; }

View File

@ -6,6 +6,10 @@ EC=it5570e
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=white_dac
CFLAGS+=-DKBLED_DAC=2
# Set battery I2C bus
CFLAGS+=-DI2C_SMBUS=I2C_4

View File

@ -1,48 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <board/kbled.h>
#include <common/macro.h>
#include <ec/dac.h>
#define KBLED_DAC 2
#define KBLED_DACDAT DACDAT2
static uint8_t __code levels[] = {
0x00,
0x80,
0x90,
0xA8,
0xC0,
0xFF
};
void kbled_init(void) {
// Enable DAC used for KBLIGHT_ADJ
DACPDREG &= ~(1 << KBLED_DAC);
kbled_reset();
}
void kbled_reset(void) {
kbled_set(0);
}
uint8_t kbled_get(void) {
uint8_t level;
uint8_t raw = KBLED_DACDAT;
for (level = 0; level < ARRAY_SIZE(levels); level++) {
if (raw <= levels[level]) {
return level;
}
}
return 0;
}
void kbled_set(uint8_t level) {
uint8_t raw = 0;
if (level < ARRAY_SIZE(levels)) {
raw = levels[level];
}
KBLED_DACDAT = raw;
}
void kbled_set_color(uint32_t color) { /*Fix unused variable*/ color = color; }

View File

@ -6,15 +6,16 @@ EC=it8587e
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=oryp5
CFLAGS+=-DI2C_KBLED=I2C_1
# Set discrete GPU I2C bus
CFLAGS+=-DI2C_DGPU=I2C_1
# Set battery I2C bus
CFLAGS+=-DI2C_SMBUS=I2C_0
# Set keyboard LED I2C bus
CFLAGS+=-DI2C_KBLED=I2C_1
# Set touchpad PS2 bus
CFLAGS+=-DPS2_TOUCHPAD=PS2_3

View File

@ -6,6 +6,9 @@ EC=it5570e
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set keyboard LED mechanism
KBLED=rgb_pwm
# Set discrete GPU I2C bus
CFLAGS+=-DI2C_DGPU=I2C_1

View File

@ -1,36 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <board/kbled.h>
#include <ec/pwm.h>
void kbled_init(void) {
//TODO: enable PWMs
kbled_reset();
}
void kbled_reset(void) {
// Set brightness and color
kbled_set_color(0xFFFFFF);
kbled_set(0x00);
}
uint8_t kbled_get(void) {
// Get PWM for power
return DCR0;
}
void kbled_set(uint8_t level) {
// Set PWM for power
DCR0 = level;
}
void kbled_set_color(uint32_t color) {
// Set PWM for blue component
DCR7 = (uint8_t)(color);
// Set PWM for green component
DCR6 = (uint8_t)(color >> 8);
// Set PWM for red component
DCR5 = (uint8_t)(color >> 16);
}

View File

@ -3,6 +3,9 @@
#ifndef _COMMON_MACRO_H
#define _COMMON_MACRO_H
#define xconcat(a, b) concat(a, b)
#define concat(a, b) a ## b
#define xstr(s) str(s)
#define str(s) #s