diff --git a/src/board/system76/addw1/board.mk b/src/board/system76/addw1/board.mk index 2115a0e..cae834c 100644 --- a/src/board/system76/addw1/board.mk +++ b/src/board/system76/addw1/board.mk @@ -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 diff --git a/src/board/system76/addw2/board.mk b/src/board/system76/addw2/board.mk index 3a6bd21..19e99f1 100644 --- a/src/board/system76/addw2/board.mk +++ b/src/board/system76/addw2/board.mk @@ -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 diff --git a/src/board/system76/addw2/kbled.c b/src/board/system76/addw2/kbled.c deleted file mode 100644 index 0f262e4..0000000 --- a/src/board/system76/addw2/kbled.c +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#include -#include - -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); -} diff --git a/src/board/system76/bonw14/board.mk b/src/board/system76/bonw14/board.mk index f5b4438..74ff771 100644 --- a/src/board/system76/bonw14/board.mk +++ b/src/board/system76/bonw14/board.mk @@ -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 diff --git a/src/board/system76/common/common.mk b/src/board/system76/common/common.mk index 83fcd43..93fe9f4 100644 --- a/src/board/system76/common/common.mk +++ b/src/board/system76/common/common.mk @@ -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 diff --git a/src/board/system76/common/include/board/kbled.h b/src/board/system76/common/include/board/kbled.h index afa76fe..28ffeac 100644 --- a/src/board/system76/common/include/board/kbled.h +++ b/src/board/system76/common/include/board/kbled.h @@ -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 diff --git a/src/board/system76/bonw14/kbled.c b/src/board/system76/common/kbled/bonw14.c similarity index 61% rename from src/board/system76/bonw14/kbled.c rename to src/board/system76/common/kbled/bonw14.c index b651279..802e165 100644 --- a/src/board/system76/bonw14/kbled.c +++ b/src/board/system76/common/kbled/bonw14.c @@ -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; } diff --git a/src/board/system76/darp5/kbled.c b/src/board/system76/common/kbled/darp5.c similarity index 77% rename from src/board/system76/darp5/kbled.c rename to src/board/system76/common/kbled/darp5.c index f1178bf..66b16c2 100644 --- a/src/board/system76/darp5/kbled.c +++ b/src/board/system76/common/kbled/darp5.c @@ -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); diff --git a/src/board/system76/common/kbled/none.c b/src/board/system76/common/kbled/none.c new file mode 100644 index 0000000..453d526 --- /dev/null +++ b/src/board/system76/common/kbled/none.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-3.0-only + +#include + +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; } diff --git a/src/board/system76/oryp5/kbled.c b/src/board/system76/common/kbled/oryp5.c similarity index 78% rename from src/board/system76/oryp5/kbled.c rename to src/board/system76/common/kbled/oryp5.c index 1caf217..36391f4 100644 --- a/src/board/system76/oryp5/kbled.c +++ b/src/board/system76/common/kbled/oryp5.c @@ -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); diff --git a/src/board/system76/addw1/kbled.c b/src/board/system76/common/kbled/rgb_pwm.c similarity index 68% rename from src/board/system76/addw1/kbled.c rename to src/board/system76/common/kbled/rgb_pwm.c index 0f262e4..5f86c59 100644 --- a/src/board/system76/addw1/kbled.c +++ b/src/board/system76/common/kbled/rgb_pwm.c @@ -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); diff --git a/src/board/system76/galp5/kbled.c b/src/board/system76/common/kbled/white_dac.c similarity index 76% rename from src/board/system76/galp5/kbled.c rename to src/board/system76/common/kbled/white_dac.c index b384b13..8f37198 100644 --- a/src/board/system76/galp5/kbled.c +++ b/src/board/system76/common/kbled/white_dac.c @@ -4,8 +4,11 @@ #include #include -#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; } diff --git a/src/board/system76/darp5/board.mk b/src/board/system76/darp5/board.mk index 8dcfc9a..1eda786 100644 --- a/src/board/system76/darp5/board.mk +++ b/src/board/system76/darp5/board.mk @@ -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 diff --git a/src/board/system76/darp7/board.mk b/src/board/system76/darp7/board.mk index 54d92e7..d001b25 100644 --- a/src/board/system76/darp7/board.mk +++ b/src/board/system76/darp7/board.mk @@ -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 diff --git a/src/board/system76/darp7/kbled.c b/src/board/system76/darp7/kbled.c deleted file mode 100644 index 0f262e4..0000000 --- a/src/board/system76/darp7/kbled.c +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#include -#include - -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); -} diff --git a/src/board/system76/galp3-c/board.mk b/src/board/system76/galp3-c/board.mk index cbc0f19..b365bfe 100644 --- a/src/board/system76/galp3-c/board.mk +++ b/src/board/system76/galp3-c/board.mk @@ -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 diff --git a/src/board/system76/galp3-c/kbled.c b/src/board/system76/galp3-c/kbled.c deleted file mode 100644 index ccef22a..0000000 --- a/src/board/system76/galp3-c/kbled.c +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#include -#include -#include - -#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; } diff --git a/src/board/system76/galp5/board.mk b/src/board/system76/galp5/board.mk index 0b23d63..66d6ed3 100644 --- a/src/board/system76/galp5/board.mk +++ b/src/board/system76/galp5/board.mk @@ -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 diff --git a/src/board/system76/gaze15/board.mk b/src/board/system76/gaze15/board.mk index 7452964..ccc7719 100644 --- a/src/board/system76/gaze15/board.mk +++ b/src/board/system76/gaze15/board.mk @@ -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 diff --git a/src/board/system76/gaze15/kbled.c b/src/board/system76/gaze15/kbled.c deleted file mode 100644 index 0f262e4..0000000 --- a/src/board/system76/gaze15/kbled.c +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#include -#include - -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); -} diff --git a/src/board/system76/lemp10/board.mk b/src/board/system76/lemp10/board.mk index 54d92e7..0dcf306 100644 --- a/src/board/system76/lemp10/board.mk +++ b/src/board/system76/lemp10/board.mk @@ -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 diff --git a/src/board/system76/lemp10/kbled.c b/src/board/system76/lemp10/kbled.c deleted file mode 100644 index b384b13..0000000 --- a/src/board/system76/lemp10/kbled.c +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#include -#include -#include - -#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; } diff --git a/src/board/system76/lemp9/board.mk b/src/board/system76/lemp9/board.mk index 5d111a1..c2f8d80 100644 --- a/src/board/system76/lemp9/board.mk +++ b/src/board/system76/lemp9/board.mk @@ -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 diff --git a/src/board/system76/lemp9/kbled.c b/src/board/system76/lemp9/kbled.c deleted file mode 100644 index 1ef92d1..0000000 --- a/src/board/system76/lemp9/kbled.c +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#include -#include -#include - -#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; } diff --git a/src/board/system76/oryp5/board.mk b/src/board/system76/oryp5/board.mk index 59ac2cf..38ff03b 100644 --- a/src/board/system76/oryp5/board.mk +++ b/src/board/system76/oryp5/board.mk @@ -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 diff --git a/src/board/system76/oryp6/board.mk b/src/board/system76/oryp6/board.mk index 05a14d2..b880fc1 100644 --- a/src/board/system76/oryp6/board.mk +++ b/src/board/system76/oryp6/board.mk @@ -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 diff --git a/src/board/system76/oryp6/kbled.c b/src/board/system76/oryp6/kbled.c deleted file mode 100644 index 0f262e4..0000000 --- a/src/board/system76/oryp6/kbled.c +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only - -#include -#include - -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); -} diff --git a/src/common/include/common/macro.h b/src/common/include/common/macro.h index 4509fa4..5fe6fe1 100644 --- a/src/common/include/common/macro.h +++ b/src/common/include/common/macro.h @@ -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