Skip to content

Commit 405865e

Browse files
author
cynosure
committed
pre driver refactor
1 parent 308c2b8 commit 405865e

31 files changed

Lines changed: 29952 additions & 572 deletions

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
build
2-
.vscode
2+
.vscode
3+
.clangd
4+
compile_commands.json
5+
.cache
6+
AGENTS.md

.mxproject

Lines changed: 34 additions & 20 deletions
Large diffs are not rendered by default.

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ endif()
2222
set(CMAKE_PROJECT_NAME MSB-FW-2)
2323

2424
# NER Include toolchain file
25-
include("cmake/gcc-arm-none-eabi.cmake")
2625

2726
# Enable compile command to ease indexing with e.g. clangd
2827
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

Core/Inc/RTE_Components.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file
5+
* @author MCD Application Team
6+
* @version V2.0.0
7+
******************************************************************************
8+
* @attention
9+
*
10+
* Copyright (c) 2026 STMicroelectronics.
11+
* All rights reserved.
12+
*
13+
* This software is licensed under terms that can be found in the LICENSE file
14+
* in the root directory of this software component.
15+
* If no LICENSE file comes with this software, it is provided AS-IS.
16+
*
17+
******************************************************************************
18+
*/
19+
/* USER CODE END Header */
20+
/* Define to prevent recursive inclusion -------------------------------------*/
21+
#ifndef __RTE_COMPONENTS_H__
22+
#define __RTE_COMPONENTS_H__
23+
24+
/* Defines ------------------------------------------------------------------*/
25+
/* STMicroelectronics.X-CUBE-TOF1.3.4.3 */
26+
#define VL53L7CX
27+
28+
#endif /* __RTE_COMPONENTS_H__ */

Core/Inc/custom_bus.h

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file : custom_bus.h
5+
* @brief : header file for the BSP BUS IO driver
6+
******************************************************************************
7+
* @attention
8+
*
9+
* Copyright (c) 2026 STMicroelectronics.
10+
* All rights reserved.
11+
*
12+
* This software is licensed under terms that can be found in the LICENSE file
13+
* in the root directory of this software component.
14+
* If no LICENSE file comes with this software, it is provided AS-IS.
15+
*
16+
******************************************************************************
17+
*/
18+
/* USER CODE END Header */
19+
20+
/* Define to prevent recursive inclusion -------------------------------------*/
21+
#ifndef CUSTOM_BUS_H
22+
#define CUSTOM_BUS_H
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
/* Includes ------------------------------------------------------------------*/
29+
#include "custom_conf.h"
30+
#include "custom_errno.h"
31+
32+
/** @addtogroup BSP
33+
* @{
34+
*/
35+
36+
/** @addtogroup CUSTOM
37+
* @{
38+
*/
39+
40+
/** @defgroup CUSTOM_BUS CUSTOM BUS
41+
* @{
42+
*/
43+
44+
/** @defgroup CUSTOM_BUS_Exported_Constants CUSTOM BUS Exported Constants
45+
* @{
46+
*/
47+
48+
#define BUS_I2C1_INSTANCE I2C1
49+
#define BUS_I2C1_SCL_GPIO_PORT GPIOB
50+
#define BUS_I2C1_SCL_GPIO_AF GPIO_AF4_I2C1
51+
#define BUS_I2C1_SCL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
52+
#define BUS_I2C1_SCL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
53+
#define BUS_I2C1_SCL_GPIO_PIN GPIO_PIN_8
54+
#define BUS_I2C1_SDA_GPIO_PIN GPIO_PIN_9
55+
#define BUS_I2C1_SDA_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
56+
#define BUS_I2C1_SDA_GPIO_PORT GPIOB
57+
#define BUS_I2C1_SDA_GPIO_AF GPIO_AF4_I2C1
58+
#define BUS_I2C1_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
59+
60+
#ifndef BUS_I2C1_POLL_TIMEOUT
61+
#define BUS_I2C1_POLL_TIMEOUT 0x1000U
62+
#endif
63+
/* I2C1 Frequency in Hz */
64+
#ifndef BUS_I2C1_FREQUENCY
65+
#define BUS_I2C1_FREQUENCY 1000000U /* Frequency of I2Cn = 100 KHz*/
66+
#endif
67+
68+
/**
69+
* @}
70+
*/
71+
72+
/** @defgroup CUSTOM_BUS_Private_Types CUSTOM BUS Private types
73+
* @{
74+
*/
75+
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1U)
76+
typedef struct
77+
{
78+
pI2C_CallbackTypeDef pMspInitCb;
79+
pI2C_CallbackTypeDef pMspDeInitCb;
80+
}BSP_I2C_Cb_t;
81+
#endif /* (USE_HAL_I2C_REGISTER_CALLBACKS == 1U) */
82+
/**
83+
* @}
84+
*/
85+
86+
/** @defgroup CUSTOM_LOW_LEVEL_Exported_Variables LOW LEVEL Exported Constants
87+
* @{
88+
*/
89+
90+
extern I2C_HandleTypeDef hi2c1;
91+
92+
/**
93+
* @}
94+
*/
95+
96+
/** @addtogroup CUSTOM_BUS_Exported_Functions
97+
* @{
98+
*/
99+
100+
/* BUS IO driver over I2C Peripheral */
101+
HAL_StatusTypeDef MX_I2C1_Init(I2C_HandleTypeDef* hi2c);
102+
int32_t BSP_I2C1_Init(void);
103+
int32_t BSP_I2C1_DeInit(void);
104+
int32_t BSP_I2C1_IsReady(uint16_t DevAddr, uint32_t Trials);
105+
int32_t BSP_I2C1_WriteReg(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length);
106+
int32_t BSP_I2C1_ReadReg(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length);
107+
int32_t BSP_I2C1_WriteReg16(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length);
108+
int32_t BSP_I2C1_ReadReg16(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length);
109+
int32_t BSP_I2C1_Send(uint16_t DevAddr, uint8_t *pData, uint16_t Length);
110+
int32_t BSP_I2C1_Recv(uint16_t DevAddr, uint8_t *pData, uint16_t Length);
111+
int32_t BSP_I2C1_SendRecv(uint16_t DevAddr, uint8_t *pTxdata, uint8_t *pRxdata, uint16_t Length);
112+
#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1U)
113+
int32_t BSP_I2C1_RegisterDefaultMspCallbacks (void);
114+
int32_t BSP_I2C1_RegisterMspCallbacks (BSP_I2C_Cb_t *Callbacks);
115+
#endif /* (USE_HAL_I2C_REGISTER_CALLBACKS == 1U) */
116+
117+
int32_t BSP_GetTick(void);
118+
119+
/**
120+
* @}
121+
*/
122+
123+
/**
124+
* @}
125+
*/
126+
127+
/**
128+
* @}
129+
*/
130+
131+
/**
132+
* @}
133+
*/
134+
#ifdef __cplusplus
135+
}
136+
#endif
137+
138+
#endif /* CUSTOM_BUS_H */
139+

Core/Inc/custom_conf.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file : custom_conf.h
5+
* @brief : Configuration file
6+
******************************************************************************
7+
* @attention
8+
*
9+
* Copyright (c) 2026 STMicroelectronics.
10+
* All rights reserved.
11+
*
12+
* This software is licensed under terms that can be found in the LICENSE file
13+
* in the root directory of this software component.
14+
* If no LICENSE file comes with this software, it is provided AS-IS.
15+
*
16+
******************************************************************************
17+
*/
18+
/* USER CODE END Header */
19+
20+
/* Define to prevent recursive inclusion -------------------------------------*/
21+
#ifndef CUSTOM_CONF_H
22+
#define CUSTOM_CONF_H
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
/* Includes ------------------------------------------------------------------*/
28+
#include "stm32h5xx_hal.h"
29+
30+
/** @addtogroup BSP
31+
* @{
32+
*/
33+
34+
/** @addtogroup CUSTOM
35+
* @{
36+
*/
37+
38+
/** @defgroup CUSTOM_CONFIG Config
39+
* @{
40+
*/
41+
42+
/** @defgroup CUSTOM_CONFIG_Exported_Constants
43+
* @{
44+
*/
45+
/* COM Feature define */
46+
#define USE_BSP_COM_FEATURE 0U
47+
48+
/* COM define */
49+
#define USE_COM_LOG 1U
50+
51+
/* IRQ priorities */
52+
#define BSP_BUTTON_USER_IT_PRIORITY 14U
53+
54+
/* I2C1 Frequency in Hz */
55+
#define BUS_I2C1_FREQUENCY 100000U /* Frequency of I2C1 = 100 KHz*/
56+
57+
/* SPI1 Baud rate in bps */
58+
#define BUS_SPI1_BAUDRATE 16000000U /* baud rate of SPIn = 16 Mbps */
59+
60+
/* UART1 Baud rate in bps */
61+
#define BUS_UART1_BAUDRATE 9600U /* baud rate of UARTn = 9600 baud */
62+
63+
/**
64+
* @}
65+
*/
66+
67+
/**
68+
* @}
69+
*/
70+
71+
/**
72+
* @}
73+
*/
74+
75+
/**
76+
* @}
77+
*/
78+
79+
#ifdef __cplusplus
80+
}
81+
#endif
82+
#endif /* CUSTOM_CONF_H */
83+

Core/Inc/custom_errno.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file : custom_errno.h
5+
* @brief : Error Code
6+
******************************************************************************
7+
* @attention
8+
*
9+
* Copyright (c) 2026 STMicroelectronics.
10+
* All rights reserved.
11+
*
12+
* This software is licensed under terms that can be found in the LICENSE file
13+
* in the root directory of this software component.
14+
* If no LICENSE file comes with this software, it is provided AS-IS.
15+
*
16+
******************************************************************************
17+
*/
18+
/* USER CODE END Header */
19+
20+
/* Define to prevent recursive inclusion -------------------------------------*/
21+
#ifndef CUSTOM_ERRNO_H
22+
#define CUSTOM_ERRNO_H
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
/* BSP Common Error codes */
29+
#define BSP_ERROR_NONE 0
30+
#define BSP_ERROR_NO_INIT -1
31+
#define BSP_ERROR_WRONG_PARAM -2
32+
#define BSP_ERROR_BUSY -3
33+
#define BSP_ERROR_PERIPH_FAILURE -4
34+
#define BSP_ERROR_COMPONENT_FAILURE -5
35+
#define BSP_ERROR_UNKNOWN_FAILURE -6
36+
#define BSP_ERROR_UNKNOWN_COMPONENT -7
37+
#define BSP_ERROR_BUS_FAILURE -8
38+
#define BSP_ERROR_CLOCK_FAILURE -9
39+
#define BSP_ERROR_MSP_FAILURE -10
40+
#define BSP_ERROR_FEATURE_NOT_SUPPORTED -11
41+
42+
/* BSP BUS error codes */
43+
44+
#define BSP_ERROR_BUS_TRANSACTION_FAILURE -100
45+
#define BSP_ERROR_BUS_ARBITRATION_LOSS -101
46+
#define BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE -102
47+
#define BSP_ERROR_BUS_PROTOCOL_FAILURE -103
48+
49+
#define BSP_ERROR_BUS_MODE_FAULT -104
50+
#define BSP_ERROR_BUS_FRAME_ERROR -105
51+
#define BSP_ERROR_BUS_CRC_ERROR -106
52+
#define BSP_ERROR_BUS_DMA_FAILURE -107
53+
54+
#ifdef __cplusplus
55+
}
56+
#endif
57+
#endif /*CUSTOM_ERRNO_H */
58+

Core/Inc/u_sensors.h

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
#define MOTION_FX_STATE_SIZE (size_t)(2432)
66

7-
/*
7+
/*
88
* Bias correction thresholds from MotionFX example implementations.
9-
* Lower GBIAS_* = more correction, higher = more stability.
9+
* Lower GBIAS_* = more correction, higher = more stability.
1010
* Adjust if drift or instability occurs.
1111
*/
12-
#define GBIAS_ACC_TH_SC (2.0f * 0.000765f)
12+
#define GBIAS_ACC_TH_SC (2.0f * 0.000765f)
1313
#define GBIAS_GYRO_TH_SC (2.0f * 0.002f)
14-
#define GBIAS_MAG_TH_SC 0.0f
14+
#define GBIAS_MAG_TH_SC 0.0f
1515

1616
/*
17-
* DECIMATION controls how often sensor data is processed.
18-
* 1U = use every sample, higher = skip samples
17+
* DECIMATION controls how often sensor data is processed.
18+
* 1U = use every sample, higher = skip samples
1919
* Increase to ignore more samples if CPU usage is too high.
2020
*/
2121
#define DECIMATION 1U
@@ -33,13 +33,15 @@ uint16_t init_imu();
3333
uint16_t init_magnetometer();
3434

3535
/**
36-
* @brief reads data from the lsm6dsv and lis2mdl, and performs motionfx rotation calculations
36+
* @brief reads data from the lsm6dsv and lis2mdl, and performs motionfx
37+
* rotation calculations
3738
* @return whether there were errors in reading the data
3839
*/
3940
uint16_t read_imu_and_magnometer();
4041

4142
/**
42-
* @brief sends data from the lsm6dsv, lis2mdl, and motionfx rotation data over CAN
43+
* @brief sends data from the lsm6dsv, lis2mdl, and motionfx rotation data over
44+
* CAN
4345
*/
4446
void send_imu_and_magnometer_data();
4547

@@ -68,4 +70,21 @@ uint16_t read_sht30();
6870
/**
6971
* @brief sends temp and humidity data from the sht30 over CAN
7072
*/
71-
void send_sht30_data();
73+
void send_sht30_data();
74+
75+
/**
76+
* @brief sets up vl53l7cx time of flight sensor
77+
* @return if there were errors initalizing the sensor
78+
*/
79+
int32_t init_vl53l7cx(); // QUESTION: should this be 16 bit or something else
80+
81+
/*
82+
* @brief Gets data from the vl53l7cx and updates a global variable accordingly
83+
* @returns if there were any errors in reading the data
84+
*/
85+
int32_t read_vl53l7cx();
86+
87+
/*
88+
* @brief sends time of flight data over CAN
89+
*/
90+
void send_vl53l7cx_data();

0 commit comments

Comments
 (0)