init commit

Signed-off-by: YoungSoo Shin <shinys000114@gmail.com>
This commit is contained in:
2025-08-20 18:56:07 +09:00
commit 2383894664
46 changed files with 7834 additions and 0 deletions

105
main/include/ina226.h Normal file
View File

@@ -0,0 +1,105 @@
#ifndef _INA226_H_
#define _INA226_H_
#include <stdint.h>
#include "esp_err.h"
#include "driver/i2c_master.h"
typedef enum
{
INA226_AVERAGES_1 = 0b000,
INA226_AVERAGES_4 = 0b001,
INA226_AVERAGES_16 = 0b010,
INA226_AVERAGES_64 = 0b011,
INA226_AVERAGES_128 = 0b100,
INA226_AVERAGES_256 = 0b101,
INA226_AVERAGES_512 = 0b110,
INA226_AVERAGES_1024 = 0b111
} ina226_averages_t;
typedef enum
{
INA226_BUS_CONV_TIME_140_US = 0b000,
INA226_BUS_CONV_TIME_204_US = 0b001,
INA226_BUS_CONV_TIME_332_US = 0b010,
INA226_BUS_CONV_TIME_588_US = 0b011,
INA226_BUS_CONV_TIME_1100_US = 0b100,
INA226_BUS_CONV_TIME_2116_US = 0b101,
INA226_BUS_CONV_TIME_4156_US = 0b110,
INA226_BUS_CONV_TIME_8244_US = 0b111
} ina226_bus_conv_time_t;
typedef enum
{
INA226_SHUNT_CONV_TIME_140_US = 0b000,
INA226_SHUNT_CONV_TIME_204_US = 0b001,
INA226_SHUNT_CONV_TIME_332_US = 0b010,
INA226_SHUNT_CONV_TIME_588_US = 0b011,
INA226_SHUNT_CONV_TIME_1100_US = 0b100,
INA226_SHUNT_CONV_TIME_2116_US = 0b101,
INA226_SHUNT_CONV_TIME_4156_US = 0b110,
INA226_SHUNT_CONV_TIME_8244_US = 0b111
} ina226_shunt_conv_time_t;
typedef enum
{
INA226_MODE_POWER_DOWN = 0b000,
INA226_MODE_SHUNT_TRIG = 0b001,
INA226_MODE_BUS_TRIG = 0b010,
INA226_MODE_SHUNT_BUS_TRIG = 0b011,
INA226_MODE_ADC_OFF = 0b100,
INA226_MODE_SHUNT_CONT = 0b101,
INA226_MODE_BUS_CONT = 0b110,
INA226_MODE_SHUNT_BUS_CONT = 0b111,
} ina226_mode_t;
typedef enum
{
INA226_ALERT_SHUNT_OVER_VOLTAGE = 0xf,
INA226_ALERT_SHUNT_UNDER_VOLTAGE = 0xe,
INA226_ALERT_BUS_OVER_VOLTAGE = 0xd,
INA226_ALERT_BUS_UNDER_VOLTAGE = 0xc,
INA226_ALERT_POWER_OVER_LIMIT = 0xb,
INA226_ALERT_CONVERSION_READY = 0xa,
INA226_ALERT_FUNCTION_FLAG = 0x4,
INA226_ALERT_CONVERSION_READY_FLAG = 0x3,
INA226_ALERT_MATH_OVERFLOW_FLAG = 0x2,
INA226_ALERT_POLARITY = 0x1,
INA226_ALERT_LATCH_ENABLE = 0x0
} ina226_alert_t;
typedef struct
{
i2c_port_t i2c_port;
int i2c_addr;
int timeout_ms;
ina226_averages_t averages;
ina226_bus_conv_time_t bus_conv_time;
ina226_shunt_conv_time_t shunt_conv_time;
ina226_mode_t mode;
float r_shunt; /* ohm */
float max_current; /* amps */
} ina226_config_t;
typedef struct
{
i2c_master_dev_handle_t dev_handle;
int timeout_ms;
float current_lsb;
float power_lsb;
} ina226_t;
esp_err_t ina226_get_manufacturer_id(ina226_t *device, uint16_t *manufacturer_id);
esp_err_t ina226_get_die_id(ina226_t *device, uint16_t *die_id);
esp_err_t ina226_get_shunt_voltage(ina226_t *device, float *voltage);
esp_err_t ina226_get_bus_voltage(ina226_t *device, float *voltage);
esp_err_t ina226_get_current(ina226_t *device, float *current);
esp_err_t ina226_get_power(ina226_t *device, float *power);
esp_err_t ina226_get_alert_mask(ina226_t *device, ina226_alert_t *alert_mask);
esp_err_t ina226_set_alert_mask(ina226_t *device, ina226_alert_t alert_mask);
esp_err_t ina226_set_alert_limit(ina226_t *device, float voltage);
esp_err_t ina226_init(ina226_t *device, i2c_master_dev_handle_t dev_handle, const ina226_config_t *config);
#endif

29
main/include/indicator.h Normal file
View File

@@ -0,0 +1,29 @@
//
// Created by shinys on 25. 7. 29.
//
#ifndef LED_H
#define LED_H
enum blink_type
{
BLINK_SLOW = 0,
BLINK_FAST,
BLINK_DOUBLE,
BLINK_TRIPLE,
BLINK_SOLID,
BLINK_MAX,
};
enum blink_led
{
LED_RED = 0,
LED_BLU = 1,
LED_MAX,
};
void init_led(void);
void led_set(enum blink_led led, enum blink_type type);
void led_off(enum blink_led led);
#endif //LED_H

46
main/include/nconfig.h Normal file
View File

@@ -0,0 +1,46 @@
//
// Created by shinys on 25. 7. 10.
//
#ifndef NCONFIG_H
#define NCONFIG_H
#include "nvs.h"
#include "esp_err.h"
#define NCONFIG_NVS_NAMESPACE "er"
#define NCONFIG_NOT_FOUND ESP_ERR_NVS_NOT_FOUND
esp_err_t init_nconfig();
enum nconfig_type
{
WIFI_SSID,
WIFI_PASSWORD,
WIFI_MODE,
AP_SSID,
AP_PASSWORD,
NETIF_HOSTNAME,
NETIF_IP,
NETIF_GATEWAY,
NETIF_SUBNET,
NETIF_DNS1,
NETIF_DNS2,
NETIF_TYPE,
UART_BAUD_RATE,
NCONFIG_TYPE_MAX,
};
// Write config
esp_err_t nconfig_write(enum nconfig_type type, const char* data);
// Check config is set and get config value length
esp_err_t nconfig_get_str_len(enum nconfig_type type, size_t *len);
// Read config
esp_err_t nconfig_read(enum nconfig_type type, char* data, size_t len);
// Remove key
esp_err_t nconfig_delete(enum nconfig_type type);
#endif //NCONFIG_H

12
main/include/system.h Normal file
View File

@@ -0,0 +1,12 @@
//
// Created by shinys on 25. 8. 5.
//
#ifndef SYSTEM_H
#define SYSTEM_H
void start_reboot_timer(int sec);
void stop_reboot_timer();
void start_webserver();
#endif //SYSTEM_H

23
main/include/wifi.h Normal file
View File

@@ -0,0 +1,23 @@
//
// Created by shinys on 25. 7. 10.
//
#ifndef WIFI_H
#define WIFI_H
#include "esp_err.h"
#include "esp_netif_types.h"
#include "esp_wifi_types_generic.h"
const char* auth_mode_str(wifi_auth_mode_t mode);
esp_err_t wifi_connect(void);
esp_err_t wifi_disconnect(void);
void wifi_scan_aps(wifi_ap_record_t **ap_records, uint16_t* count);
esp_err_t wifi_get_current_ap_info(wifi_ap_record_t *ap_info);
esp_err_t wifi_get_current_ip_info(esp_netif_ip_info_t *ip_info);
esp_err_t wifi_get_dns_info(esp_netif_dns_type_t type, esp_netif_dns_info_t *dns_info);
esp_err_t wifi_use_dhcp(void);
esp_err_t wifi_use_static(const char *ip, const char *gw, const char *netmask, const char *dns1, const char *dns2);
esp_err_t wifi_switch_mode(const char* mode);
void sync_time();
#endif //WIFI_H