From 2bd4690f6f86b6b80802b6203da33028f997ae91 Mon Sep 17 00:00:00 2001 From: christopherkinyua Date: Thu, 7 Nov 2024 16:29:13 -0700 Subject: [PATCH] WIP --- firmware/Core/CMakeLists.txt | 19 ++++++++++------- firmware/Core/Inc/IO.h | 6 ++++-- .../Core/Inc/ina219_sensor/ina219_sensor.h | 0 firmware/Core/Inc/main.h | 14 ++++++++++++- firmware/Core/Src/IO.c | 21 ++++++++++++++++--- .../Core/Src/ina219_sensor/ina219_sensor.c | 0 6 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 firmware/Core/Inc/ina219_sensor/ina219_sensor.h create mode 100644 firmware/Core/Src/ina219_sensor/ina219_sensor.c diff --git a/firmware/Core/CMakeLists.txt b/firmware/Core/CMakeLists.txt index 01b7b8f..9e3dcdb 100644 --- a/firmware/Core/CMakeLists.txt +++ b/firmware/Core/CMakeLists.txt @@ -1,11 +1,16 @@ -# Define the source and include directories -set(INCLUDE_DIRS Inc Inc/unit_tests) -set(SRC_DIR Src) +# Define the base source and include directories relative to the component directory +set(INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/Inc") +set(SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/Src") -# Automatically include all .c files in Core/Src and Core/Src/unit_tests -file(GLOB SRC_FILES "${SRC_DIR}/*.c" "${SRC_DIR}/unit_tests/*.c") +# Recursively include all .c files in Src and its subdirectories +file(GLOB_RECURSE SRC_FILES "${SRC_DIR}/*.c") + +# Gather all directories in Inc, excluding files +file(GLOB INCLUDE_DIR_PATHS RELATIVE ${CMAKE_CURRENT_LIST_DIR} "${INCLUDE_DIRS}/*") +list(FILTER INCLUDE_DIR_PATHS INCLUDE REGEX ".*[^\\.h]$") +set(FINAL_INCLUDE_DIRS ${INCLUDE_DIRS} ${INCLUDE_DIR_PATHS}) # Register the component with ESP-IDF idf_component_register(SRCS ${SRC_FILES} - INCLUDE_DIRS ${INCLUDE_DIRS} - REQUIRES driver esp_timer) \ No newline at end of file + INCLUDE_DIRS ${FINAL_INCLUDE_DIRS} + REQUIRES driver esp_timer freertos) \ No newline at end of file diff --git a/firmware/Core/Inc/IO.h b/firmware/Core/Inc/IO.h index ec35bf2..a2175ab 100644 --- a/firmware/Core/Inc/IO.h +++ b/firmware/Core/Inc/IO.h @@ -4,10 +4,12 @@ #include #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void GPIO_init(void); + void GPIO_init(void); + void i2c_init(void); #ifdef __cplusplus } diff --git a/firmware/Core/Inc/ina219_sensor/ina219_sensor.h b/firmware/Core/Inc/ina219_sensor/ina219_sensor.h new file mode 100644 index 0000000..e69de29 diff --git a/firmware/Core/Inc/main.h b/firmware/Core/Inc/main.h index 39789e3..2d3ff4e 100644 --- a/firmware/Core/Inc/main.h +++ b/firmware/Core/Inc/main.h @@ -2,10 +2,22 @@ #ifndef __MAIN_H #define __MAIN_H +#include "driver/i2c.h" + #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif + // These are the default pins for I2C: Can change them later on + +#define I2C_MASTER_SCL_IO 22 +#define I2C_MASTER_SDA_IO 21 +#define I2C_MASTER_NUM I2C_NUM_0 +#define I2C_MASTER_FREQ_HZ 100000 +#define I2C_MASTER_TX_BUF_DISABLE 0 +#define I2C_MASTER_RX_BUF_DISABLE 0 +#define INA219_ADDRESS 0x40 // INA219 I2C address #ifdef __cplusplus } diff --git a/firmware/Core/Src/IO.c b/firmware/Core/Src/IO.c index e145694..212a767 100644 --- a/firmware/Core/Src/IO.c +++ b/firmware/Core/Src/IO.c @@ -1,15 +1,30 @@ #include "IO.h" +#include "main.h" #include "driver/gpio.h" +#include "driver/i2c_master.h" #include /// @brief GPIO Pin Initialization /// @param None /// TODO: Set up pins that will be used as input and outputs for current monitoring -void GPIO_init(void){ +void GPIO_init(void) +{ // Initializing GPIO0 as an input with a pulldown // TODO: Update with appropriate pins that will be used - gpio_set_direction(GPIO_NUM_0,GPIO_MODE_OUTPUT); - gpio_set_pull_mode(GPIO_NUM_0,GPIO_PULLDOWN_ONLY); + gpio_set_direction(GPIO_NUM_0, GPIO_MODE_OUTPUT); + gpio_set_pull_mode(GPIO_NUM_0, GPIO_PULLDOWN_ONLY); } + +/// @brief I2C Initialization +/// @param None +/// TODO: Set up pins that will be used as input and outputs for current monitoring +void i2c_init(void) +{ + + // Initializing GPIO0 as an input with a pulldown + // TODO: Update with appropriate pins that will be used + gpio_set_direction(GPIO_NUM_0, GPIO_MODE_OUTPUT); + gpio_set_pull_mode(GPIO_NUM_0, GPIO_PULLDOWN_ONLY); +} \ No newline at end of file diff --git a/firmware/Core/Src/ina219_sensor/ina219_sensor.c b/firmware/Core/Src/ina219_sensor/ina219_sensor.c new file mode 100644 index 0000000..e69de29