Skip to content

Commit

Permalink
Add IFDEFs and extern all structs (#7)
Browse files Browse the repository at this point in the history
* ifdef and extern

* format

* change naming syntax
  • Loading branch information
jr1221 authored Jun 21, 2024
1 parent 2435eb9 commit 00e6462
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 284 deletions.
4 changes: 2 additions & 2 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include "can.h"
#include "cmsis_os.h"

void can1_callback(CAN_HandleTypeDef *hcan);
//void can1_callback(CAN_HandleTypeDef *hcan);

void vCanDispatch(void *pv_params);
extern osThreadId_t can_dispatch_handle;
extern const osThreadAttr_t can_dispatch_attributes;

int8_t queue_can_msg(can_msg_t msg);
void init_can1(CAN_HandleTypeDef *hcan);
void can1_init();

#endif
11 changes: 11 additions & 0 deletions Core/Inc/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,38 @@

#include "cmsis_os.h"
#include "stm32f4xx_hal.h"
#include "msb_conf.h"

#ifdef SENSOR_TEMP
/* Defining Temperature Monitor Task */
void vTempMonitor(void *pv_params);
extern osThreadId_t temp_monitor_handle;
extern const osThreadAttr_t temp_monitor_attributes;
#endif

#ifdef SENSOR_IMU
/* Task for Monitoring the IMU */
void vIMUMonitor(void *pv_params);
extern osThreadId_t imu_monitor_handle;
extern const osThreadAttr_t imu_monitor_attributes;
#endif

#ifdef SENSOR_TOF
void vTOFMonitor(void *pv_params);
extern osThreadId_t tof_monitor_handle;
extern const osThreadAttr_t tof_monitor_attributes;
#endif

#ifdef SENSOR_SHOCKPOT
void vShockpotMonitor(void *pv_params);
extern osThreadId_t shockpot_monitor_handle;
extern const osThreadAttr_t shockpot_monitor_attributes;
#endif

#ifdef SENSOR_STRAIN
void vStrainMonitor(void *pv_params);
extern osThreadId_t strain_monitor_handle;
extern const osThreadAttr_t strain_monitor_attributes;
#endif

#endif
50 changes: 23 additions & 27 deletions Core/Inc/msb.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sht30.h"
#include "stm32f405xx.h"
#include "vl6180x_api.h"
#include "msb_conf.h"

typedef enum {
DEVICE_FRONT_LEFT,
Expand All @@ -15,40 +16,35 @@ typedef enum {
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;
} msb_t;
int8_t msb_init();

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);
#ifdef SENSOR_TEMP
int8_t central_temp_measure(uint16_t *temp, uint16_t *humidity);
#endif

#ifdef SENSOR_IMU
int8_t accel_read(uint16_t accel[3]);

int8_t measure_central_temp(msb_t *msb, uint16_t *temp, uint16_t *humidity);
int8_t gyro_read(uint16_t gyro[3]);
#endif

int8_t read_accel(msb_t *msb, uint16_t accel[3]);
#ifdef SENSOR_TOF
int8_t distance_read(int32_t *range_mm);
#endif

int8_t read_gyro(msb_t *msb, uint16_t gyro[3]);
int8_t debug1_write(bool status);

int8_t read_distance(msb_t *msb, int32_t *range_mm);
int8_t debug2_write(bool status);

int8_t write_debug1(msb_t *msb, bool status);
int8_t vcc5_en_write(bool status);

int8_t write_debug2(msb_t *msb, bool status);
#ifdef SENSOR_SHOCKPOT
void shockpot_read(uint32_t shockpot_sense);
#endif

void read_shockpot(msb_t *msb, uint32_t shockpot_sense);
void read_strain1(msb_t *msb, uint32_t strain1);
void read_strain2(msb_t *msb, uint32_t strain2);
#ifdef SENSOR_STRAIN
void strain1_read(uint32_t strain1);
void strain2_read(uint32_t strain2);
#endif

#endif
21 changes: 20 additions & 1 deletion Core/Inc/msb_conf.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
/// All commonly changed settings and constants that could effect multiple factors, esp. in telemetry

// DELAYS
#define DELAY_CAN_DISPATCH 5

// MONITOR
#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

// CONTROLLER
#define DELAY_DEBUG_LED_REFRESH 250

#define DELAY_CAN_DISPATCH 5

// CAN IDS
#define CANID_TEMP_SENSOR 0x602
#define CANID_IMU_ACCEL 0x603
Expand All @@ -19,3 +23,18 @@
#define CANID_SHOCK_SENSE 0x606
#define CANID_TOF 0x607
#define CANID_WHEEL_TEMP 0x608

// Sensors to use, comment out to disable

//on central
#define SENSOR_TEMP
#define SENSOR_SHOCKPOT
#define SENSOR_STRAIN
#define SENSOR_TOF

// on knuckle or wheel
#define SENSOR_IMU
//#define SENSOR_WHEEL_TEMP

// VERBOSE LOGGING
#define LOG_VERBOSE
8 changes: 4 additions & 4 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
#define CAN_MSG_QUEUE_SIZE 25 /* messages */
static osMessageQueueId_t can_outbound_queue;

extern CAN_HandleTypeDef hcan1;

can_t *can1;

void init_can1(CAN_HandleTypeDef *hcan)
void can1_init()
{
assert(hcan);

can1 = malloc(sizeof(can_t));
assert(can1);

can1->hcan = hcan;
can1->hcan = &hcan1;

assert(!can_init(can1));

Expand Down
22 changes: 11 additions & 11 deletions Core/Src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "msb.h"
#include "msb_conf.h"

extern device_loc_t device_loc;

osThreadId_t led_controller_handle;
const osThreadAttr_t led_controller_attributes = {
.name = "LedController",
Expand All @@ -11,24 +13,22 @@ const osThreadAttr_t led_controller_attributes = {

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

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

Expand Down
Loading

0 comments on commit 00e6462

Please sign in to comment.