From f50b8feb83eac51bc63018038577f13b6a72ec59 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 1 Oct 2019 13:40:54 -0600 Subject: [PATCH] Hook up battery debugging to power switch --- src/board/system76/galp3-c/main.c | 49 ++++++++++++++++++++++-------- src/board/system76/galp3-c/stdio.c | 5 ++- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/board/system76/galp3-c/main.c b/src/board/system76/galp3-c/main.c index 6fed4ed..f442927 100644 --- a/src/board/system76/galp3-c/main.c +++ b/src/board/system76/galp3-c/main.c @@ -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); diff --git a/src/board/system76/galp3-c/stdio.c b/src/board/system76/galp3-c/stdio.c index 2cd8153..4d42926 100644 --- a/src/board/system76/galp3-c/stdio.c +++ b/src/board/system76/galp3-c/stdio.c @@ -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)) {