#include "driver/gpio.h" #include "driver/uart.h" #include "esp_crc.h" #include "esp_event.h" #include "esp_log.h" #include "esp_mac.h" #include "esp_netif.h" #include "esp_now.h" #include "esp_random.h" #include "esp_wifi.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "hal/gpio_types.h" #include "hal/uart_types.h" #include "nvs_flash.h" #include "portmacro.h" #include #include #include #include #include "espnow_handler.h" #include "main.h" #define BUF_SIZE (1024) #define TXD_PIN (GPIO_NUM_17) #define RXD_PIN (GPIO_NUM_16) void app_main(void) { // Master Slave Detection, default pin is pull up so ground it and check state gpio_reset_pin(Master_SlavePin); gpio_set_direction(Master_SlavePin, GPIO_MODE_INPUT); int checkMaster = gpio_get_level(Master_SlavePin); if (checkMaster == 0) { isMaster = true; setIsMaster(true); } uart_config_t uart_config = {.baud_rate = 115200, .data_bits = UART_DATA_8_BITS, .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE}; uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0); uart_param_config(UART_NUM_2, &uart_config); uart_set_pin(UART_NUM_2, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); char *test_str = "Ok\n"; /*while (1) {*/ /* uart_write_bytes(UART_NUM_2, (const char *)test_str, strlen(test_str));*/ /* ESP_LOGI(tag, "Sending UART\n");*/ /* vTaskDelay(100 / portTICK_PERIOD_MS);*/ /*}*/ ESP_LOGI(tag, "ESP MASTER State %d\n", isMaster); vTaskDelay(500 / portTICK_PERIOD_MS); wifi_init(); espnow_init(); }