Files
wordclock/code/main/main.cpp
T
Matthias Mitscherlich 4b26e6080f Nothing special
2024-03-19 17:05:25 +01:00

174 lines
6.0 KiB
C++

// --------------------------------------------------------------------------------------------------------------------
/// \file main.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
// ESP includes
#include "driver/uart.h"
#include "esp_log.h"
#include "nvs_flash.h"
// HAL includes
#include "gpio.h"
#include "i2c.h"
#include "uart.h"
// Platform includes
#include "isl29125.h"
#include "logger.h"
#include "Wifi.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
static TaskHandle_t loggerTaskHandle;
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
void loggerTask(void* parameters);
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
extern "C" void app_main(void)
{
esp_log_level_set("*", ESP_LOG_WARN);
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES
|| ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
// -----------------------------------------------------------------------------------------------------------------
// UART
//
uart_config_t uartConfig =
{
.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,
.rx_flow_ctrl_thresh = 0,
.source_clk = UART_SCLK_DEFAULT
};
uart_port_t debugUart = UART_NUM_0;
ESP_ERROR_CHECK(uart_param_config(debugUart, &uartConfig));
ESP_ERROR_CHECK(uart_set_pin(debugUart, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK(uart_driver_install(debugUart, 1024, 1024, 0, NULL, 0));
uart uartDebug = uart(&debugUart);
uartDebug.open();
uartDebug.write(255, 255, (uint8_t*)"START", 5);
// -----------------------------------------------------------------------------------------------------------------
// System-wide Debug Logger
//
logger debugLogger = logger(16, uartDebug);
// Call the logger executable within a dedicated task and forget about it afterwards
xTaskCreate(loggerTask, (const char*)"loggerTask", 3072, &debugLogger, 3, &loggerTaskHandle);
LOGGER_PRINT("\n\r-----------------------------------------------------------------------\n\r");
LOGGER_PRINT("System Start\n\r");
LOGGER_PRINT("\n\r");
LOGGER_PRINT("WordClock\n\r");
LOGGER_PRINT("Release: %d.%d \n\r", MAJORRELEASE, MINORRELEASE);
LOGGER_PRINT("Compiled on %s at %s\n\r\n\r\n\r", __DATE__, __TIME__);
// // -----------------------------------------------------------------------------------------------------------------
// // I2C Masterbus for sensoring peripherals
// //
// i2c_port_t i2c_master_port = I2C_NUM_0;
//
// i2c_config_t i2cConfig = {
// .mode = I2C_MODE_MASTER,
// .sda_io_num = (int)2,
// .scl_io_num = (int)3,
// .sda_pullup_en = GPIO_PULLUP_ENABLE,
// .scl_pullup_en = GPIO_PULLUP_ENABLE,
// .master = 400000,
// .clk_flags = 0
// };
//
// ESP_ERROR_CHECK(i2c_param_config(i2c_master_port, &i2cConfig));
// ESP_ERROR_CHECK(i2c_driver_install(i2c_master_port, i2cConfig.mode, 0, 0, 0));
//
// i2c i2cSensor = i2c(&i2c_master_port);
// i2cSensor.open();
//
// // -----------------------------------------------------------------------------------------------------------------
// // I2C RGB Sensor on I2C MasterBus for sensors
// //
// isl29125 rgbSensor = isl29125(0x44, i2cSensor);
// rgbSensor.initialize();
// vTaskDelay(100);
// rgbSensor.setMode(isl29125::RGB);
// rgbSensor.setRange(isl29125::HIGH);
// rgbSensor.setResolution(isl29125::RES_16BIT);
// vTaskDelay(100);
// struct isl29125::rgb_t rgbValue;
// rgbSensor.getRGB(&rgbValue);
//
// gpio debugIO = gpio(19, gpio::Direction_t::GPIO_DIRECTION_OUTPUT, gpio::Value_t::GPIO_VALUE_LOW);
// -----------------------------------------------------------------------------------------------------------------
// Wifi create and connect
//
Wifi wifi;
wifi.start_client();
while(1)
{
vTaskDelay(1000);
}
}
void loggerTask(void* parameters)
{
logger* debugLogger = (logger*) parameters;
while (1)
{
debugLogger->task();
vTaskDelay(10);
}
}