shutdown button

This commit is contained in:
2025-03-02 23:33:37 +01:00
parent 336531699e
commit bebae2a367
6 changed files with 59 additions and 16 deletions

View File

@@ -6,5 +6,6 @@ idf_component_register(SRCS
src/i2c_global.cpp
src/disp_tools.cpp
src/disp_tty.cpp
src/shutdowner.cpp
PRIV_REQUIRES spi_flash esp_driver_i2c driver
INCLUDE_DIRS "include")

View File

@@ -1,8 +1,8 @@
#ifndef CB_CONFIG_HPP
#define CB_CONFIG_HPP
#include "soc/gpio_num.h"
#include "hal/spi_types.h"
#include "soc/gpio_num.h"
#define I2C_SCL GPIO_NUM_8
#define I2C_SDA GPIO_NUM_9
@@ -14,7 +14,10 @@
#define SPI_BUS SPI2_HOST
#define DISP_WIDTH 400
#define DISP_WIDTH 400
#define DISP_HEIGHT 240
#endif
#define PWR_INT GPIO_NUM_10
#define PWR_KILL GPIO_NUM_12
#endif

View File

@@ -0,0 +1,18 @@
//
// Created by Stepan Usatiuk on 02.03.2025.
//
#ifndef CB_SHUTDOWNER_HPP
#define CB_SHUTDOWNER_HPP
class Shutdowner {
public:
static Shutdowner& get();
private:
Shutdowner();
};
#endif // CB_SHUTDOWNER_HPP

View File

@@ -8,18 +8,6 @@
#include "driver/spi_master.h"
spi_device_interface_config_t devcfg = {
.command_bits = 0,
.address_bits = 0,
.mode = 0, // SPI mode 0
.clock_speed_hz = 4 * 1000 * 1000, // Clock out at 10 MHz
.spics_io_num = SPI_DISP_CS, // CS pin
.flags = SPI_DEVICE_POSITIVE_CS,
.queue_size = 1, // We want to be able to queue 7 transactions at a time
// .pre_cb = lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line
};
// This solution is attributed to Rich Schroeppel in the Programming Hacks section
// TODO: Why does the device flag not work?
unsigned char reverse_bits3(unsigned char b) { return (b * 0x0202020202ULL & 0x010884422010ULL) % 0x3ff; }
@@ -35,7 +23,6 @@ std::array<uint8_t, SMD::kLineBytes> SMD::prep_line(const SMD::disp_line_t& line
return data;
}
SMD& SMD::get() {
static SMD smd;
return smd;

View File

@@ -25,6 +25,7 @@
#include "i2c_global.hpp"
#include <memory>
#include <shutdowner.hpp>
#include <spi_global.hpp>
#include <string>
@@ -35,6 +36,7 @@ extern "C" void app_main() {
// .max_freq_mhz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ, .min_freq_mhz = 16, .light_sleep_enable = true};
// ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
printf("Hello world!\n");
Shutdowner::get();
I2cGlobal::get();
BatMon::get();
SpiGlobal::get();

View File

@@ -0,0 +1,32 @@
//
// 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_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));
gpio_isr_handler_add(PWR_INT, shutdown, nullptr);
}