Files
cardboy/Firmware/main/src/shutdowner.cpp
2025-03-03 01:09:21 +01:00

35 lines
977 B
C++

//
// Created by Stepan Usatiuk on 02.03.2025.
//
#include "shutdowner.hpp"
#include <driver/gpio.h>
#include "config.hpp"
Shutdowner& Shutdowner::get() {
static Shutdowner instance;
return instance;
}
static void shutdown(void* arg) {
// printf("Shutting down...\n");
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_INT));
ESP_ERROR_CHECK(gpio_reset_pin(PWR_KILL));
ESP_ERROR_CHECK(gpio_set_direction(PWR_INT, GPIO_MODE_INPUT));
ESP_ERROR_CHECK(gpio_set_direction(PWR_KILL, GPIO_MODE_OUTPUT));
ESP_ERROR_CHECK(gpio_set_level(PWR_KILL, 1));
ESP_ERROR_CHECK(gpio_set_pull_mode(PWR_INT, GPIO_FLOATING));
ESP_ERROR_CHECK(gpio_set_intr_type(PWR_INT, GPIO_INTR_NEGEDGE));
ESP_ERROR_CHECK(gpio_install_isr_service(0));
ESP_ERROR_CHECK(gpio_hold_en(PWR_KILL));
gpio_isr_handler_add(PWR_INT, shutdown, nullptr);
}