Hook up battery debugging to power switch

This commit is contained in:
Jeremy Soller 2019-10-01 13:40:54 -06:00
parent 1cefcbbfcb
commit f50b8feb83
No known key found for this signature in database
GPG Key ID: E988B49EE78A7FB1
2 changed files with 41 additions and 13 deletions

View File

@ -51,18 +51,43 @@ void init(void) {
// PECI information can be found here: https://www.intel.com/content/dam/www/public/us/en/documents/design-guides/core-i7-lga-2011-guide.pdf
}
struct Gpio __code PWR_SW_N = GPIO(D, 0);
struct Gpio __code PWR_BTN_N = GPIO(D, 5);
struct Gpio __code DD_ON = GPIO(E, 4);
void ac_adapter() {
static struct Gpio __code ACIN_N = GPIO(B, 6);
static struct Gpio __code LED_ACIN = GPIO(C, 7);
static bool last = false;
// Check if the adapter line goes low
bool new = gpio_get(&ACIN_N);
// Set ACIN LED
gpio_set(&LED_ACIN, !new);
// If there has been a change, print
if (new != last) {
printf("Power adapter ");
if (new) {
printf("unplugged\n");
} else {
printf("plugged in\n");
}
}
last = new;
}
void power_button() {
static struct Gpio __code PWR_SW_N = GPIO(D, 0);
static struct Gpio __code PWR_BTN_N = GPIO(D, 5);
//static struct Gpio __code DD_ON = GPIO(E, 4);
static bool last = false;
// Check if the power switch goes low
bool new = gpio_get(&PWR_SW_N);
if (!new && last) {
printf("Power Switch\n");
printf("Power switch\n");
battery_debug();
//gpio_set(&DD_ON, true);
}
last = new;
@ -74,29 +99,29 @@ void touchpad_event(struct Ps2 * ps2) {
//TODO
}
struct Gpio __code ACIN_N = GPIO(B, 6);
struct Gpio __code LED_BAT_CHG = GPIO(A, 5);
struct Gpio __code LED_BAT_FULL = GPIO(A, 6);
struct Gpio __code LED_PWR = GPIO(A, 7);
struct Gpio __code LED_ACIN = GPIO(C, 7);
struct Gpio __code LED_AIRPLANE_N = GPIO(G, 6);
//struct Gpio __code LED_PWR = GPIO(A, 7);
//struct Gpio __code LED_AIRPLANE_N = GPIO(G, 6);
void main(void) {
init();
static struct Gpio __code LED_BAT_CHG = GPIO(A, 5);
static struct Gpio __code LED_BAT_FULL = GPIO(A, 6);
// Set the battery full LED (to know our firmware is loading)
gpio_set(&LED_BAT_CHG, true);
gpio_debug();
battery_debug();
// Set the battery full LED (to know our firmware is loaded)
gpio_set(&LED_BAT_FULL, true);
printf("Hello from System76 EC for %s!\n", xstr(__BOARD__));
for(;;) {
gpio_set(&LED_ACIN, !gpio_get(&ACIN_N));
ac_adapter();
power_button();
touchpad_event(&PS2_3);
kbc_event(&KBC);

View File

@ -17,7 +17,7 @@ void i2c_write(unsigned char value) {
HOCTL2A = (1 << 1) | (1 << 0);
// Write value to 0x76
TRASLAA = (0x76 << 1) | (0 << 1);
TRASLAA = 0x76 << 1;
HOCMDA = value;
// Start command
@ -33,6 +33,9 @@ void i2c_write(unsigned char value) {
uint8_t status = HOSTAA;
HOSTAA = status;
// Disable host interface
HOCTL2A = 0;
// If there were no errors, return
uint8_t error = (1 << 6) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
if (!(status & error)) {