Add kbled control

This commit is contained in:
Jeremy Soller 2020-01-29 14:50:46 -07:00
parent 884c9916e4
commit 2b8b1a3d20
No known key found for this signature in database
GPG Key ID: E988B49EE78A7FB1
4 changed files with 55 additions and 6 deletions

View File

@ -1,7 +1,7 @@
#include <board/acpi.h>
#include <board/battery.h>
#include <board/dac.h>
#include <board/gpio.h>
#include <board/kbled.h>
#include <board/peci.h>
#include <common/debug.h>
@ -9,9 +9,9 @@ extern bool lid_wake;
extern uint8_t sci_extra;
uint8_t fcmd = 0;
uint8_t fdat = 0;
uint8_t fbuf[4] = { 0, 0, 0, 0 };
static uint8_t fcmd = 0;
static uint8_t fdat = 0;
static uint8_t fbuf[4] = { 0, 0, 0, 0 };
void fcommand(void) {
switch (fcmd) {
@ -20,11 +20,11 @@ void fcommand(void) {
switch (fdat) {
// Set white LED brightness
case 0x00:
DACDAT2 = fbuf[0];
kbled_set(fbuf[0]);
break;
// Get white LED brightness
case 0x01:
fbuf[0] = DACDAT2;
fbuf[0] = kbled_get();
break;
}
break;

View File

@ -0,0 +1,9 @@
#ifndef _BOARD_KBLED_H
#define _BOARD_KBLED_H
#include <stdint.h>
uint8_t kbled_get(void);
void kbled_set(uint8_t level);
#endif // _BOARD_KBLED_H

View File

@ -0,0 +1,31 @@
#include <board/dac.h>
#include <board/kbled.h>
#include <common/macro.h>
static uint8_t __code levels[] = {
0,
48,
72,
96,
192,
255
};
uint8_t kbled_get(void) {
uint8_t level;
uint8_t raw = DACDAT2;
for (level = 0; level < ARRAY_SIZE(levels); level++) {
if (raw <= levels[level]) {
return level;
}
}
return 0;
}
void kbled_set(uint8_t level) {
if (level < ARRAY_SIZE(levels)) {
DACDAT2 = levels[level];
} else {
DACDAT2 = 0;
}
}

View File

@ -3,6 +3,7 @@
#include <arch/delay.h>
#include <board/gpio.h>
#include <board/kbc.h>
#include <board/kbled.h>
#include <board/kbscan.h>
#include <board/keymap.h>
#include <board/pmc.h>
@ -104,6 +105,14 @@ void kbscan_event(void) {
if (new_b) {
uint8_t sci = SCI_EXTRA;
sci_extra = (uint8_t)(key & 0xFF);
// HACK FOR HARDWARE HOTKEYS
switch (sci_extra) {
case SCI_EXTRA_KBD_BKL:
kbled_set(kbled_get() + 1);
break;
}
if (!pmc_sci(&PMC_1, sci)) {
// In the case of ignored SCI, reset bit
new &= ~(1 << j);