wip:
This commit is contained in:
@@ -1 +1 @@
|
||||
idf_component_register(SRCS "ate0004.c" INCLUDE_DIRS "" REQUIRES zh_pcf8574)
|
||||
idf_component_register(SRCS "ate0004.c" INCLUDE_DIRS "" REQUIRES zh_pcf8574 esp_wifi nvs_flash)
|
||||
@@ -10,12 +10,47 @@ static bool is_ts = true;
|
||||
static bool is_ret = false;
|
||||
static bool is_ext = false;
|
||||
|
||||
void zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||
static void zh_wifi_softap_init(void);
|
||||
static void zh_gpio_init(void);
|
||||
static void zh_io_expander_init(void);
|
||||
static void zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// esp_log_level_set("zh_pcf8574", ESP_LOG_ERROR);
|
||||
// esp_log_level_set("zh_vector", ESP_LOG_ERROR);
|
||||
esp_log_level_set("zh_pcf8574", ESP_LOG_NONE);
|
||||
esp_log_level_set("zh_vector", ESP_LOG_NONE);
|
||||
nvs_flash_init();
|
||||
esp_event_loop_create_default();
|
||||
zh_wifi_softap_init();
|
||||
zh_gpio_init();
|
||||
gpio_set_level(TRIAC_GPIO, LOW);
|
||||
zh_io_expander_init();
|
||||
zh_pcf8574_write_gpio(&led_handle, TS_LED_GREEN, LED_ON);
|
||||
zh_pcf8574_write_gpio(&led_handle, RET_LED_BLUE, LED_ON);
|
||||
zh_pcf8574_write_gpio(&led_handle, EXT_LED_BLUE, LED_ON);
|
||||
}
|
||||
|
||||
static void zh_wifi_softap_init(void)
|
||||
{
|
||||
esp_netif_init();
|
||||
esp_netif_create_default_wifi_ap();
|
||||
wifi_init_config_t wifi_config = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_wifi_init(&wifi_config);
|
||||
wifi_config_t ap_config = {
|
||||
.ap = {
|
||||
.ssid = WIFI_SSID,
|
||||
.password = WIFI_PASS,
|
||||
.max_connection = 4,
|
||||
.authmode = WIFI_AUTH_WPA2_PSK,
|
||||
},
|
||||
};
|
||||
esp_wifi_set_mode(WIFI_MODE_AP);
|
||||
esp_wifi_set_config(WIFI_IF_AP, &ap_config);
|
||||
esp_wifi_start();
|
||||
}
|
||||
|
||||
static void zh_gpio_init(void)
|
||||
{
|
||||
gpio_config_t triac_pin_config = {
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
@@ -24,7 +59,10 @@ void app_main(void)
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
};
|
||||
gpio_config(&triac_pin_config);
|
||||
gpio_set_level(TRIAC_GPIO, LOW);
|
||||
}
|
||||
|
||||
static void zh_io_expander_init(void)
|
||||
{
|
||||
i2c_master_bus_config_t i2c_bus_config = {
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.scl_io_num = GPIO_NUM_22,
|
||||
@@ -32,26 +70,22 @@ void app_main(void)
|
||||
.glitch_ignore_cnt = 7,
|
||||
};
|
||||
i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle);
|
||||
esp_event_loop_create_default();
|
||||
esp_event_handler_instance_register(ZH_PCF8574, ESP_EVENT_ANY_ID, &zh_pcf8574_event_handler, NULL, NULL);
|
||||
zh_pcf8574_init_config_t pcf8574_init_config = ZH_PCF8574_INIT_CONFIG_DEFAULT();
|
||||
pcf8574_init_config.i2c_handle = i2c_bus_handle;
|
||||
pcf8574_init_config.i2c_address = LED_I2C_ADDRESS;
|
||||
zh_pcf8574_init(&pcf8574_init_config, &led_handle);
|
||||
pcf8574_init_config.i2c_address = RELAY_I2C_ADDRESS;
|
||||
zh_pcf8574_init(&pcf8574_init_config, &relay_handle);
|
||||
pcf8574_init_config.i2c_address = BUTTON_I2C_ADDRESS;
|
||||
pcf8574_init_config.p0_gpio_work_mode = true;
|
||||
pcf8574_init_config.p1_gpio_work_mode = true;
|
||||
pcf8574_init_config.p2_gpio_work_mode = true;
|
||||
pcf8574_init_config.interrupt_gpio = GPIO_NUM_17;
|
||||
zh_pcf8574_init(&pcf8574_init_config, &button_handle);
|
||||
zh_pcf8574_write_gpio(&led_handle, TS_LED_GREEN, LED_ON);
|
||||
zh_pcf8574_write_gpio(&led_handle, RET_LED_BLUE, LED_ON);
|
||||
zh_pcf8574_write_gpio(&led_handle, EXT_LED_BLUE, LED_ON);
|
||||
zh_pcf8574_init_config_t config = ZH_PCF8574_INIT_CONFIG_DEFAULT();
|
||||
config.i2c_handle = i2c_bus_handle;
|
||||
config.i2c_address = LED_I2C_ADDRESS;
|
||||
zh_pcf8574_init(&config, &led_handle);
|
||||
config.i2c_address = RELAY_I2C_ADDRESS;
|
||||
zh_pcf8574_init(&config, &relay_handle);
|
||||
config.i2c_address = BUTTON_I2C_ADDRESS;
|
||||
config.p0_gpio_work_mode = true;
|
||||
config.p1_gpio_work_mode = true;
|
||||
config.p2_gpio_work_mode = true;
|
||||
config.interrupt_gpio = GPIO_NUM_17;
|
||||
zh_pcf8574_init(&config, &button_handle);
|
||||
}
|
||||
|
||||
void zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
static void zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
{
|
||||
zh_pcf8574_event_on_isr_t *event = event_data;
|
||||
switch (event->gpio_number)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "zh_pcf8574.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_wifi.h"
|
||||
|
||||
#define HIGH true
|
||||
#define LOW false
|
||||
@@ -13,25 +15,30 @@
|
||||
|
||||
#define TRIAC_GPIO GPIO_NUM_4
|
||||
|
||||
#define BUTTON_I2C_ADDRESS 0x22 // U7.
|
||||
#define LED_I2C_ADDRESS 0x21 // U6.
|
||||
#define RELAY_I2C_ADDRESS 0x20 // U5.
|
||||
#define WIFI_SSID "ATE0004"
|
||||
#define WIFI_PASS "repairlab"
|
||||
#define WIFI_CHANNEL 1
|
||||
#define MAX_STA_CONNECTION 4
|
||||
|
||||
#define GROUND_RELAY 0x00 // Relay K1. RL1 pin on U5.
|
||||
#define TS_RELAY 0x04 // Relay K4. RL4 pin on U5.
|
||||
#define RET_RELAY 0x03 // Relay K3. RL3 pin on U5.
|
||||
#define EXT_RELAY 0x02 // Relay K2. RL2 pin on U5.
|
||||
#define BUTTON_I2C_ADDRESS 0x22 /*!< U7. */
|
||||
#define LED_I2C_ADDRESS 0x21 /*!< U6. */
|
||||
#define RELAY_I2C_ADDRESS 0x20 /*!< U5. */
|
||||
|
||||
#define TS_BUTTON 0x00 // Connector BT1. B1-0 on U7.
|
||||
#define RET_BUTTON 0x01 // Connector BT2. B2-1 on U7.
|
||||
#define EXT_BUTTON 0x02 // Connector BT3. B3-2 on U7.
|
||||
#define GROUND_RELAY 0x00 /*!< Relay K1. RL1 pin on U5. */
|
||||
#define TS_RELAY 0x04 /*!< Relay K4. RL4 pin on U5. */
|
||||
#define RET_RELAY 0x03 /*!< Relay K3. RL3 pin on U5. */
|
||||
#define EXT_RELAY 0x02 /*!< Relay K2. RL2 pin on U5. */
|
||||
|
||||
#define TS_LED_RED 0x00 // Connector LE1. 2 PIN. L1-0 pin on U6.
|
||||
#define TS_LED_GREEN 0x01 // Connector LE1. 1 PIN. L1-1 pin on U6.
|
||||
#define RET_LED_BLUE 0x02 // Connector LE2. 2 PIN. L2-2 pin on U6.
|
||||
#define RET_LED_GREEN 0x03 // Connector LE2. 1 PIN. L2-3 pin on U6.
|
||||
#define EXT_LED_BLUE 0x04 // Connector LE3. 2 PIN. L3-4 pin on U6.
|
||||
#define EXT_LED_GREEN 0x05 // Connector LE3. 1 PIN. L3-5 pin on U6.
|
||||
#define TS_BUTTON 0x00 /*!< Connector BT1. B1-0 on U7. */
|
||||
#define RET_BUTTON 0x01 /*!< Connector BT2. B2-1 on U7. */
|
||||
#define EXT_BUTTON 0x02 /*!< Connector BT3. B3-2 on U7. */
|
||||
|
||||
#define TS_LED_RED 0x00 /*!< Connector LE1. 2 PIN. L1-0 pin on U6. */
|
||||
#define TS_LED_GREEN 0x01 /*!< Connector LE1. 1 PIN. L1-1 pin on U6. */
|
||||
#define RET_LED_BLUE 0x02 /*!< Connector LE2. 2 PIN. L2-2 pin on U6. */
|
||||
#define RET_LED_GREEN 0x03 /*!< Connector LE2. 1 PIN. L2-3 pin on U6. */
|
||||
#define EXT_LED_BLUE 0x04 /*!< Connector LE3. 2 PIN. L3-4 pin on U6. */
|
||||
#define EXT_LED_GREEN 0x05 /*!< Connector LE3. 1 PIN. L3-5 pin on U6. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
||||
@@ -401,13 +401,13 @@ CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
|
||||
CONFIG_ESPTOOLPY_FLASHFREQ="40m"
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="8MB"
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||
# CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE is not set
|
||||
CONFIG_ESPTOOLPY_BEFORE_RESET=y
|
||||
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set
|
||||
@@ -666,7 +666,7 @@ CONFIG_DAC_DMA_AUTO_16BIT_ALIGN=y
|
||||
# ESP-Driver:GPIO Configurations
|
||||
#
|
||||
# CONFIG_GPIO_ESP32_SUPPORT_SWITCH_SLP_PULL is not set
|
||||
CONFIG_GPIO_CTRL_FUNC_IN_IRAM=y
|
||||
# CONFIG_GPIO_CTRL_FUNC_IN_IRAM is not set
|
||||
# end of ESP-Driver:GPIO Configurations
|
||||
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user