Fixed ISerialBus interface and added device and register address fields so that future i2c and SPI devices can be addressed, to. Added i2c HAL. Tested, working.

The update on the interface required FunctionStatus and the logger to be updated, too
This commit is contained in:
Matthias Mitscherlich
2024-03-11 17:00:07 +01:00
parent a0d13f08c1
commit d5e389f1bd
11 changed files with 137 additions and 530 deletions
+34 -9
View File
@@ -29,6 +29,7 @@
// HAL includes
#include "gpio.h"
#include "i2c.h"
#include "uart.h"
// Platform includes
@@ -47,8 +48,6 @@
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
static uart_port_t uartPort = UART_NUM_0;
static TaskHandle_t loggerTaskHandle;
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
@@ -72,10 +71,10 @@ extern "C" void app_main(void)
ret = nvs_flash_init();
}
//--------------------------------------------
// -----------------------------------------------------------------------------------------------------------------
// UART
//
const uart_config_t uartConfig =
uart_config_t uartConfig =
{
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
@@ -85,16 +84,17 @@ extern "C" void app_main(void)
.rx_flow_ctrl_thresh = 0,
.source_clk = UART_SCLK_DEFAULT
};
static 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));
ESP_ERROR_CHECK(uart_param_config(uartPort, &uartConfig));
ESP_ERROR_CHECK(uart_set_pin(uartPort, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK(uart_driver_install(uartPort, 1024, 1024, 0, NULL, 0));
uart uartDebug = uart(&uartPort);
uart uartDebug = uart(&debugUart);
uartDebug.open();
// -----------------------------------------------------------------------------------------------------------------
// System-wide Debug Logger
//
logger debugLogger = logger(16, uartDebug);
// Call the logger executable within a dedicated task and forget about it afterwards
@@ -107,6 +107,31 @@ extern "C" void app_main(void)
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)4,
.scl_io_num = (int)5,
.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();
uint8_t i2cData[2] = {0x12, 0x34};
i2cSensor.write(0x40, 0x00, i2cData, 2);
gpio debugIO = gpio(2, gpio::Direction_t::GPIO_DIRECTION_OUTPUT, gpio::Value_t::GPIO_VALUE_LOW);