Run peci and battery events every 256 cycles
This commit is contained in:
parent
9f02b8d67d
commit
27f1dccc9e
@ -16,6 +16,8 @@
|
|||||||
#include <common/debug.h>
|
#include <common/debug.h>
|
||||||
#include <common/macro.h>
|
#include <common/macro.h>
|
||||||
|
|
||||||
|
static uint8_t main_cycle = 0;
|
||||||
|
|
||||||
void external_0(void) __interrupt(0) {
|
void external_0(void) __interrupt(0) {
|
||||||
TRACE("external_0\n");
|
TRACE("external_0\n");
|
||||||
}
|
}
|
||||||
@ -77,6 +79,9 @@ void ac_adapter() {
|
|||||||
battery_charger_enable();
|
battery_charger_enable();
|
||||||
}
|
}
|
||||||
battery_debug();
|
battery_debug();
|
||||||
|
|
||||||
|
// Reset main loop cycle to force reading PECI and battery
|
||||||
|
main_cycle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
last = new;
|
last = new;
|
||||||
@ -150,7 +155,7 @@ void power_button() {
|
|||||||
bool new = gpio_get(&PWR_SW_N);
|
bool new = gpio_get(&PWR_SW_N);
|
||||||
if (!new && last) {
|
if (!new && last) {
|
||||||
// Ensure press is not spurious
|
// Ensure press is not spurious
|
||||||
delay_ms(100);
|
delay_ms(10);
|
||||||
if (gpio_get(&PWR_SW_N) != new) {
|
if (gpio_get(&PWR_SW_N) != new) {
|
||||||
DEBUG("Spurious press\n");
|
DEBUG("Spurious press\n");
|
||||||
return;
|
return;
|
||||||
@ -251,6 +256,7 @@ void power_button() {
|
|||||||
|
|
||||||
// enable pnp devices
|
// enable pnp devices
|
||||||
pnp_enable();
|
pnp_enable();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
DEBUG("Disabling power\n");
|
DEBUG("Disabling power\n");
|
||||||
|
|
||||||
@ -297,6 +303,9 @@ void power_button() {
|
|||||||
delay_ms(1);
|
delay_ms(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset main loop cycle to force reading PECI and battery
|
||||||
|
main_cycle = 0;
|
||||||
|
|
||||||
TRACE("LED_PWR: %d\n", power);
|
TRACE("LED_PWR: %d\n", power);
|
||||||
gpio_set(&LED_PWR, power);
|
gpio_set(&LED_PWR, power);
|
||||||
}
|
}
|
||||||
@ -375,14 +384,25 @@ void main(void) {
|
|||||||
gpio_set(&LED_BAT_FULL, true);
|
gpio_set(&LED_BAT_FULL, true);
|
||||||
INFO("Hello from System76 EC for %s!\n", xstr(__BOARD__));
|
INFO("Hello from System76 EC for %s!\n", xstr(__BOARD__));
|
||||||
|
|
||||||
for(;;) {
|
for(main_cycle = 0; ; main_cycle++) {
|
||||||
peci_event();
|
// Enables or disables battery charging based on AC adapter
|
||||||
ac_adapter();
|
ac_adapter();
|
||||||
battery_event();
|
// Checks for power button press
|
||||||
power_button();
|
power_button();
|
||||||
|
// Scans keyboard and sends keyboard packets
|
||||||
kbscan_event();
|
kbscan_event();
|
||||||
|
// Passes through touchpad packets
|
||||||
touchpad_event(&PS2_3);
|
touchpad_event(&PS2_3);
|
||||||
|
// Checks for keyboard/mouse packets from host
|
||||||
kbc_event(&KBC);
|
kbc_event(&KBC);
|
||||||
|
// Only run the following once out of every 256 loops
|
||||||
|
if (main_cycle == 0) {
|
||||||
|
// Updates fan status and temps
|
||||||
|
peci_event();
|
||||||
|
// Updates battery status
|
||||||
|
battery_event();
|
||||||
|
}
|
||||||
|
// Handles ACPI communication
|
||||||
pmc_event(&PMC_1);
|
pmc_event(&PMC_1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user