mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
45 lines
1.4 KiB
C++
45 lines
1.4 KiB
C++
//
|
|
// Created by Stepan Usatiuk on 02.03.2025.
|
|
//
|
|
|
|
#include "cardboy/backend/esp/shutdowner.hpp"
|
|
|
|
#include <driver/gpio.h>
|
|
#include <esp_sleep.h>
|
|
|
|
#include "cardboy/backend/esp/config.hpp"
|
|
|
|
Shutdowner& Shutdowner::get() {
|
|
static Shutdowner instance;
|
|
return instance;
|
|
}
|
|
|
|
static void IRAM_ATTR int_shutdown(void* arg) {
|
|
// printf("Shutting down...\n");
|
|
ESP_ERROR_CHECK(gpio_hold_dis(PWR_KILL));
|
|
ESP_ERROR_CHECK(gpio_set_level(PWR_KILL, 0));
|
|
}
|
|
|
|
void Shutdowner::shutdown() {
|
|
ESP_ERROR_CHECK(gpio_hold_dis(PWR_KILL));
|
|
ESP_ERROR_CHECK(gpio_set_level(PWR_KILL, 0));
|
|
}
|
|
|
|
Shutdowner::Shutdowner() {
|
|
ESP_ERROR_CHECK(gpio_reset_pin(PWR_KILL));
|
|
ESP_ERROR_CHECK(gpio_set_direction(PWR_KILL, GPIO_MODE_OUTPUT));
|
|
ESP_ERROR_CHECK(gpio_set_level(PWR_KILL, 1));
|
|
ESP_ERROR_CHECK(gpio_hold_en(PWR_KILL));
|
|
|
|
ESP_ERROR_CHECK(gpio_reset_pin(PWR_INT));
|
|
ESP_ERROR_CHECK(gpio_set_direction(PWR_INT, GPIO_MODE_INPUT));
|
|
ESP_ERROR_CHECK(gpio_set_pull_mode(PWR_INT, GPIO_FLOATING));
|
|
ESP_ERROR_CHECK(gpio_set_intr_type(PWR_INT, GPIO_INTR_LOW_LEVEL));
|
|
// ESP_ERROR_CHECK(esp_sleep_enable_gpio_wakeup());
|
|
ESP_ERROR_CHECK(gpio_wakeup_enable(PWR_INT, GPIO_INTR_LOW_LEVEL));
|
|
// ESP_ERROR_CHECK(gpio_install_isr_service(0));
|
|
// gpio_isr_handler_add(PWR_INT, shutdown, nullptr);
|
|
}
|
|
|
|
void Shutdowner::install_isr() { gpio_isr_handler_add(PWR_INT, int_shutdown, nullptr); }
|