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

Auto formatting #6

Merged
merged 19 commits into from
Jun 19, 2024
4 changes: 2 additions & 2 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ jobs:
run-build:
runs-on: ubuntu-latest
container:
image: nwdepatie/ner-gcc-arm:latest
image: ghcr.io/northeastern-electric-racing/embedded-base:main
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive

Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Code Style Check

on: [push]

jobs:
formatting-check:
name: Check format of C
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Run clang-format style check for C/C++ sources
uses: Northeastern-Electric-Racing/clang-format-action@main
with:
clang-format-version: '18'
# only check core, embedded base covered internally
check-path: "Core/"
# use the clang-format from embedded base
format-filepath: "./Drivers/Embedded-Base/clang-format"
5 changes: 5 additions & 0 deletions Core/.clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
./*/stm32*
./*/sys*
./*/FreeRTOS*
./*/freertos*
./*/main*
47 changes: 23 additions & 24 deletions Core/Inc/msb.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@
#ifndef MSB_CENTRAL_H
#define MSB_CENTRAL_H

#include "cmsis_os.h"
#include "lsm6dso.h"
#include "sht30.h"
#include "stm32f405xx.h"
#include "cmsis_os.h"
#include "vl6180x_api.h"

typedef enum
{
DEVICE_FRONT_LEFT,
DEVICE_FRONT_RIGHT,
DEVICE_BACK_RIGHT,
DEVICE_BACK_LEFT,
typedef enum {
DEVICE_FRONT_LEFT,
DEVICE_FRONT_RIGHT,
DEVICE_BACK_RIGHT,
DEVICE_BACK_LEFT,
} device_loc_t;

typedef struct
{
I2C_HandleTypeDef *hi2c;
sht30_t *temp_sensor;
lsm6dso_t *imu;
VL6180xDev_t tof;
ADC_HandleTypeDef *adc1;
uint32_t adc1_buf[3];
GPIO_TypeDef *debug_led1_gpio;
uint16_t *debug_led1_pin;
GPIO_TypeDef *debug_led2_gpio;
uint16_t *debug_led2_pin;
device_loc_t *device_loc;
osMutexId_t *i2c_mutex;
typedef struct {
I2C_HandleTypeDef *hi2c;
sht30_t *temp_sensor;
lsm6dso_t *imu;
VL6180xDev_t tof;
ADC_HandleTypeDef *adc1;
uint32_t adc1_buf[3];
GPIO_TypeDef *debug_led1_gpio;
uint16_t *debug_led1_pin;
GPIO_TypeDef *debug_led2_gpio;
uint16_t *debug_led2_pin;
device_loc_t *device_loc;
osMutexId_t *i2c_mutex;
} msb_t;

msb_t *init_msb(I2C_HandleTypeDef *hi2c, ADC_HandleTypeDef *adc1, GPIO_TypeDef *debug_led1_gpio,
uint16_t *debug_led1_pin, GPIO_TypeDef *debug_led2_gpio, uint16_t *debug_led2_pin,
device_loc_t *device_loc);
msb_t *init_msb(I2C_HandleTypeDef *hi2c, ADC_HandleTypeDef *adc1,
GPIO_TypeDef *debug_led1_gpio, uint16_t *debug_led1_pin,
GPIO_TypeDef *debug_led2_gpio, uint16_t *debug_led2_pin,
device_loc_t *device_loc);

int8_t measure_central_temp(msb_t *msb, uint16_t *temp, uint16_t *humidity);

Expand Down
24 changes: 12 additions & 12 deletions Core/Inc/msb_conf.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/// All commonly changed settings and constants that could effect multiple factors, esp. in telemetry

// DELAYS
#define DELAY_CAN_DISPATCH 5
#define DELAY_CAN_DISPATCH 5
#define DELAY_TEMP_SENSOR_REFRESH 500
#define DELAY_IMU_REFRESH 500
#define DELAY_SHOCKPOT_REFRESH 500
#define DELAY_STRAIN_REFRESH 500
#define DELAY_TOF_REFRESH 500
#define DELAY_WHEEL_TEMP_REFRESH 500
#define DELAY_IMU_REFRESH 500
#define DELAY_SHOCKPOT_REFRESH 500
#define DELAY_STRAIN_REFRESH 500
#define DELAY_TOF_REFRESH 500
#define DELAY_WHEEL_TEMP_REFRESH 500

#define DELAY_DEBUG_LED_REFRESH 250

// CAN IDS
#define CANID_TEMP_SENSOR 0x602
#define CANID_IMU_ACCEL 0x603
#define CANID_IMU_GYRO 0x604
#define CANID_TEMP_SENSOR 0x602
#define CANID_IMU_ACCEL 0x603
#define CANID_IMU_GYRO 0x604
#define CANID_STRAIN_SENSE 0x605
#define CANID_SHOCK_SENSE 0x606
#define CANID_TOF 0x607
#define CANID_WHEEL_TEMP 0x608
#define CANID_SHOCK_SENSE 0x606
#define CANID_TOF 0x607
#define CANID_WHEEL_TEMP 0x608
26 changes: 12 additions & 14 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include "msb_conf.h"
#include "serial_monitor.h"

#include "stdio.h"
#include <assert.h>
#include <stdlib.h>
#include "stdio.h"
#include <string.h>

#define CAN_MSG_QUEUE_SIZE 25 /* messages */
Expand All @@ -35,7 +35,8 @@ void init_can1(CAN_HandleTypeDef *hcan)

assert(!can_init(can1));

can_outbound_queue = osMessageQueueNew(CAN_MSG_QUEUE_SIZE, sizeof(can_msg_t), NULL);
can_outbound_queue =
osMessageQueueNew(CAN_MSG_QUEUE_SIZE, sizeof(can_msg_t), NULL);
}

osThreadId_t can_dispatch_handle;
Expand All @@ -50,24 +51,21 @@ void vCanDispatch(void *pv_params)
can_msg_t msg_from_queue;
HAL_StatusTypeDef msg_status;

for (;;)
{
for (;;) {
/* Send CAN message */
if (osOK == osMessageQueueGet(can_outbound_queue, &msg_from_queue, NULL, osWaitForever))
{
if (osOK == osMessageQueueGet(can_outbound_queue,
&msg_from_queue, NULL,
osWaitForever)) {
msg_status = can_send_msg(can1, &msg_from_queue);
if (msg_status == HAL_ERROR)
{
if (msg_status == HAL_ERROR) {
serial_print("Failed to send CAN message");
}
else if (msg_status == HAL_BUSY)
{
} else if (msg_status == HAL_BUSY) {
serial_print("Outbound mailbox full!");
}
#ifdef LOG_VERBOSE
else
{
printf("Message sent: %lX\r\n", msg_from_queue.id);
else {
printf("Message sent: %lX\r\n",
msg_from_queue.id);
}
#endif
}
Expand Down
56 changes: 26 additions & 30 deletions Core/Src/controller.c
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
#include "controller.h"
#include "msb_conf.h"
#include "msb.h"
#include "msb_conf.h"

osThreadId_t led_controller_handle;
const osThreadAttr_t led_controller_attributes = {
.name = "LedController",
.stack_size = 32 * 8,
.priority = (osPriority_t)osPriorityBelowNormal1,
.name = "LedController",
.stack_size = 32 * 8,
.priority = (osPriority_t)osPriorityBelowNormal1,
};

void vLedController(void *pv_params)
{
msb_t *msb = (msb_t *)pv_params;

msb_t *msb = (msb_t *)pv_params;

switch (*msb->device_loc)
{
case DEVICE_FRONT_LEFT:
write_debug1(msb, true);
write_debug2(msb, true);
break;
case DEVICE_FRONT_RIGHT:
write_debug1(msb, true);
write_debug2(msb, false);
break;
case DEVICE_BACK_LEFT:
write_debug1(msb, false);
write_debug2(msb, true);
break;
case DEVICE_BACK_RIGHT:
write_debug1(msb, false);
write_debug2(msb, false);
break;
}

for (;;)
{
switch (*msb->device_loc) {
case DEVICE_FRONT_LEFT:
write_debug1(msb, true);
write_debug2(msb, true);
break;
case DEVICE_FRONT_RIGHT:
write_debug1(msb, true);
write_debug2(msb, false);
break;
case DEVICE_BACK_LEFT:
write_debug1(msb, false);
write_debug2(msb, true);
break;
case DEVICE_BACK_RIGHT:
write_debug1(msb, false);
write_debug2(msb, false);
break;
}

osDelay(DELAY_DEBUG_LED_REFRESH);
}
for (;;) {
osDelay(DELAY_DEBUG_LED_REFRESH);
}
}
Loading