Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
vegano1 committed Dec 12, 2024
1 parent 3310394 commit 6560aa6
Show file tree
Hide file tree
Showing 18 changed files with 739 additions and 49 deletions.
3 changes: 3 additions & 0 deletions stm32-modules/flex-stacker/firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ set(${TARGET_MODULE_NAME}_FW_LINTABLE_SRCS
${SYSTEM_DIR}/freertos_idle_timer_task.cpp
${SYSTEM_DIR}/freertos_system_task.cpp
${SYSTEM_DIR}/system_policy.cpp
${SYSTEM_DIR}/i2c_comms.cpp
${UI_DIR}/freertos_ui_task.cpp
${UI_DIR}/ui_policy.cpp
${MOTOR_CONTROL_DIR}/freertos_motor_task.cpp
${MOTOR_CONTROL_DIR}/freertos_motor_driver_task.cpp
${MOTOR_CONTROL_DIR}/motor_driver_policy.cpp
Expand All @@ -36,6 +38,7 @@ set(${TARGET_MODULE_NAME}_FW_NONLINTABLE_SRCS
${SYSTEM_DIR}/hal_tick.c
${SYSTEM_DIR}/system_serial_number.c
${SYSTEM_DIR}/system_hardware.c
${SYSTEM_DIR}/i2c_hardware.c
${UI_DIR}/ui_hardware.c
${COMMS_DIR}/usbd_conf.c
${COMMS_DIR}/usbd_desc.c
Expand Down
29 changes: 19 additions & 10 deletions stm32-modules/flex-stacker/firmware/main.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include "FreeRTOS.h"
#include "task.h"

#include "ot_utils/freertos/freertos_task.hpp"
#include "firmware/firmware_tasks.hpp"
#include "firmware/freertos_tasks.hpp"
#include "firmware/motor_hardware.h"
#include "firmware/i2c_comms.hpp"
#include "firmware/i2c_hardware.h"
#include "firmware/system_stm32g4xx.h"
#include "flex-stacker/messages.hpp"
#include "ot_utils/freertos/freertos_task.hpp"
#include "systemwide.h"
#include "task.h"

#pragma GCC diagnostic push
// NOLINTNEXTLINE(clang-diagnostic-unknown-warning-option)
Expand All @@ -15,6 +18,8 @@
#pragma GCC diagnostic pop

using EntryPoint = std::function<void(tasks::FirmwareTasks::QueueAggregator *)>;
using EntryPointUI = std::function<void(
tasks::FirmwareTasks::QueueAggregator *, i2c::hardware::I2C *)>;

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto motor_driver_task_entry = EntryPoint(motor_driver_task::run);
Expand All @@ -23,7 +28,7 @@ static auto motor_driver_task_entry = EntryPoint(motor_driver_task::run);
static auto motor_task_entry = EntryPoint(motor_control_task::run);

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto ui_task_entry = EntryPoint(ui_control_task::run);
static auto ui_task_entry = EntryPointUI(ui_control_task::run);

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto host_comms_entry = EntryPoint(host_comms_control_task::run);
Expand Down Expand Up @@ -51,7 +56,7 @@ static auto host_comms_task =

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto ui_task =
ot_utils::freertos_task::FreeRTOSTask<tasks::UI_STACK_SIZE, EntryPoint>(
ot_utils::freertos_task::FreeRTOSTask<tasks::UI_STACK_SIZE, EntryPointUI>(
ui_task_entry);

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
Expand All @@ -71,18 +76,22 @@ extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
}
}

static auto i2c2_comms = i2c::hardware::I2C();
static auto i2c3_comms = i2c::hardware::I2C();
static auto i2c_handles = I2CHandlerStruct{};

auto main() -> int {
HardwareInit();

system_task.start(tasks::SYSTEM_TASK_PRIORITY, "System", &aggregator);
i2c_hardware_init(&i2c_handles);
i2c2_comms.set_handle(i2c_handles.i2c2, I2C_BUS_2);
i2c3_comms.set_handle(i2c_handles.i2c3, I2C_BUS_3);

driver_task.start(tasks::MOTOR_DRIVER_TASK_PRIORITY, "Motor Driver",
&aggregator);
system_task.start(tasks::SYSTEM_TASK_PRIORITY, "System", &aggregator);
driver_task.start(tasks::MOTOR_DRIVER_TASK_PRIORITY, "Motor Driver", &aggregator);
motor_task.start(tasks::MOTOR_TASK_PRIORITY, "Motor", &aggregator);

host_comms_task.start(tasks::COMMS_TASK_PRIORITY, "Comms", &aggregator);

ui_task.start(tasks::UI_TASK_PRIORITY, "UI", &aggregator);
ui_task.start(tasks::UI_TASK_PRIORITY, "UI", &aggregator, &i2c2_comms);

vTaskStartScheduler();
return 0;
Expand Down
27 changes: 27 additions & 0 deletions stm32-modules/flex-stacker/firmware/system/i2c_comms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdint.h>

#include "firmware/i2c_comms.hpp"
#include "firmware/i2c_hardware.h"
#include "systemwide.h"

using namespace i2c::hardware;

auto I2C::set_handle(HAL_I2C_HANDLE i2c_handle, I2C_BUS i2c_bus) -> void {
this->handle = i2c_handle;
this->bus = i2c_bus;
i2c_register_handle(this->handle, this->bus);
}

auto I2C::i2c_write(uint16_t dev_addr, uint16_t reg, uint8_t* data,
uint16_t size) -> RxTxReturn {
MessageT resp{0};
auto ret = hal_i2c_write(bus, dev_addr, reg, data, size, TIMEOUT);
return RxTxReturn(ret, resp);
}

auto I2C::i2c_read(uint16_t dev_addr, uint16_t reg, uint16_t size)
-> RxTxReturn {
MessageT resp{0};
auto ret = hal_i2c_read(bus, dev_addr, reg, resp.data(), size, TIMEOUT);
return RxTxReturn(ret, resp);
}
Loading

0 comments on commit 6560aa6

Please sign in to comment.