Hook up battery debugging to power switch
This commit is contained in:
parent
1cefcbbfcb
commit
f50b8feb83
@ -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
|
// 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);
|
void ac_adapter() {
|
||||||
struct Gpio __code PWR_BTN_N = GPIO(D, 5);
|
static struct Gpio __code ACIN_N = GPIO(B, 6);
|
||||||
struct Gpio __code DD_ON = GPIO(E, 4);
|
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() {
|
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;
|
static bool last = false;
|
||||||
|
|
||||||
// Check if the power switch goes low
|
// Check if the power switch goes low
|
||||||
bool new = gpio_get(&PWR_SW_N);
|
bool new = gpio_get(&PWR_SW_N);
|
||||||
if (!new && last) {
|
if (!new && last) {
|
||||||
printf("Power Switch\n");
|
printf("Power switch\n");
|
||||||
|
|
||||||
|
battery_debug();
|
||||||
//gpio_set(&DD_ON, true);
|
//gpio_set(&DD_ON, true);
|
||||||
}
|
}
|
||||||
last = new;
|
last = new;
|
||||||
@ -74,29 +99,29 @@ void touchpad_event(struct Ps2 * ps2) {
|
|||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Gpio __code ACIN_N = GPIO(B, 6);
|
|
||||||
|
|
||||||
struct Gpio __code LED_BAT_CHG = GPIO(A, 5);
|
//struct Gpio __code LED_PWR = GPIO(A, 7);
|
||||||
struct Gpio __code LED_BAT_FULL = GPIO(A, 6);
|
//struct Gpio __code LED_AIRPLANE_N = GPIO(G, 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);
|
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
init();
|
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)
|
// Set the battery full LED (to know our firmware is loading)
|
||||||
gpio_set(&LED_BAT_CHG, true);
|
gpio_set(&LED_BAT_CHG, true);
|
||||||
|
|
||||||
gpio_debug();
|
gpio_debug();
|
||||||
|
|
||||||
|
battery_debug();
|
||||||
|
|
||||||
// Set the battery full LED (to know our firmware is loaded)
|
// Set the battery full LED (to know our firmware is loaded)
|
||||||
gpio_set(&LED_BAT_FULL, true);
|
gpio_set(&LED_BAT_FULL, true);
|
||||||
printf("Hello from System76 EC for %s!\n", xstr(__BOARD__));
|
printf("Hello from System76 EC for %s!\n", xstr(__BOARD__));
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
gpio_set(&LED_ACIN, !gpio_get(&ACIN_N));
|
ac_adapter();
|
||||||
|
|
||||||
power_button();
|
power_button();
|
||||||
touchpad_event(&PS2_3);
|
touchpad_event(&PS2_3);
|
||||||
kbc_event(&KBC);
|
kbc_event(&KBC);
|
||||||
|
@ -17,7 +17,7 @@ void i2c_write(unsigned char value) {
|
|||||||
HOCTL2A = (1 << 1) | (1 << 0);
|
HOCTL2A = (1 << 1) | (1 << 0);
|
||||||
|
|
||||||
// Write value to 0x76
|
// Write value to 0x76
|
||||||
TRASLAA = (0x76 << 1) | (0 << 1);
|
TRASLAA = 0x76 << 1;
|
||||||
HOCMDA = value;
|
HOCMDA = value;
|
||||||
|
|
||||||
// Start command
|
// Start command
|
||||||
@ -33,6 +33,9 @@ void i2c_write(unsigned char value) {
|
|||||||
uint8_t status = HOSTAA;
|
uint8_t status = HOSTAA;
|
||||||
HOSTAA = status;
|
HOSTAA = status;
|
||||||
|
|
||||||
|
// Disable host interface
|
||||||
|
HOCTL2A = 0;
|
||||||
|
|
||||||
// If there were no errors, return
|
// If there were no errors, return
|
||||||
uint8_t error = (1 << 6) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
|
uint8_t error = (1 << 6) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
|
||||||
if (!(status & error)) {
|
if (!(status & error)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user