Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherkinyua committed Nov 7, 2024
1 parent f3964de commit 2bd4690
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
19 changes: 12 additions & 7 deletions firmware/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
INCLUDE_DIRS ${FINAL_INCLUDE_DIRS}
REQUIRES driver esp_timer freertos)
6 changes: 4 additions & 2 deletions firmware/Core/Inc/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif

void GPIO_init(void);
void GPIO_init(void);
void i2c_init(void);

#ifdef __cplusplus
}
Expand Down
Empty file.
14 changes: 13 additions & 1 deletion firmware/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
21 changes: 18 additions & 3 deletions firmware/Core/Src/IO.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
#include "IO.h"
#include "main.h"

#include "driver/gpio.h"
#include "driver/i2c_master.h"
#include <stdio.h>

/// @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);
}
Empty file.

0 comments on commit 2bd4690

Please sign in to comment.