|
| 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 | + |
0 commit comments