Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flex-stacker): Bring up the internal/external status led bars and add gcode to control them. #495

Merged
merged 12 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 22 additions & 17 deletions stm32-modules/flex-stacker/firmware/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "FreeRTOS.h"
#include "firmware/firmware_tasks.hpp"
#include "firmware/freertos_tasks.hpp"
#include "firmware/i2c_comms.hpp"
#include "firmware/i2c_hardware.h"
#include "firmware/motor_hardware.h"
#include "firmware/system_stm32g4xx.h"
#include "flex-stacker/messages.hpp"
Expand All @@ -15,50 +17,51 @@
#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);

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
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);

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto system_task_entry = EntryPoint(system_control_task::run);

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto aggregator = tasks::FirmwareTasks::QueueAggregator();

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto driver_task =
ot_utils::freertos_task::FreeRTOSTask<tasks::MOTOR_DRIVER_STACK_SIZE,
EntryPoint>(motor_driver_task_entry);

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto motor_task =
ot_utils::freertos_task::FreeRTOSTask<tasks::MOTOR_STACK_SIZE, EntryPoint>(
motor_task_entry);

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto host_comms_task =
ot_utils::freertos_task::FreeRTOSTask<tasks::COMMS_STACK_SIZE, EntryPoint>(
host_comms_entry);

// 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)
static auto system_task =
ot_utils::freertos_task::FreeRTOSTask<tasks::SYSTEM_STACK_SIZE, EntryPoint>(
system_task_entry);

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto aggregator = tasks::FirmwareTasks::QueueAggregator();

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto i2c2_comms = i2c::hardware::I2C();
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto i2c3_comms = i2c::hardware::I2C();
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto i2c_handles = I2CHandlerStruct{};

extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
switch (GPIO_Pin) {
case MOTOR_DIAG0_PIN:
Expand All @@ -74,15 +77,17 @@ extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
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);

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 "firmware/i2c_comms.hpp"

#include <cstdint>

#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->bus = i2c_bus;
i2c_register_handle(i2c_handle, i2c_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);
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);
return RxTxReturn(ret, resp);
}
Loading
Loading