STM32F4xx HAL Driver master
STM32CubeF4 HAL / LL Drivers API Reference
Loading...
Searching...
No Matches
stm32f4xx_ll_fmpi2c.c
Go to the documentation of this file.
1
18#if defined(USE_FULL_LL_DRIVER)
19
20#if defined(FMPI2C_CR1_PE)
21/* Includes ------------------------------------------------------------------*/
22#include "stm32f4xx_ll_fmpi2c.h"
23#include "stm32f4xx_ll_bus.h"
24#ifdef USE_FULL_ASSERT
25#include "stm32_assert.h"
26#else
27#define assert_param(expr) ((void)0U)
28#endif /* USE_FULL_ASSERT */
29
33
34#if defined (FMPI2C1)
35
39
40/* Private types -------------------------------------------------------------*/
41/* Private variables ---------------------------------------------------------*/
42/* Private constants ---------------------------------------------------------*/
43/* Private macros ------------------------------------------------------------*/
47
48#define IS_LL_FMPI2C_PERIPHERAL_MODE(__VALUE__) (((__VALUE__) == LL_FMPI2C_MODE_I2C) || \
49 ((__VALUE__) == LL_FMPI2C_MODE_SMBUS_HOST) || \
50 ((__VALUE__) == LL_FMPI2C_MODE_SMBUS_DEVICE) || \
51 ((__VALUE__) == LL_FMPI2C_MODE_SMBUS_DEVICE_ARP))
52
53#define IS_LL_FMPI2C_ANALOG_FILTER(__VALUE__) (((__VALUE__) == LL_FMPI2C_ANALOGFILTER_ENABLE) || \
54 ((__VALUE__) == LL_FMPI2C_ANALOGFILTER_DISABLE))
55
56#define IS_LL_FMPI2C_DIGITAL_FILTER(__VALUE__) ((__VALUE__) <= 0x0000000FU)
57
58#define IS_LL_FMPI2C_OWN_ADDRESS1(__VALUE__) ((__VALUE__) <= 0x000003FFU)
59
60#define IS_LL_FMPI2C_TYPE_ACKNOWLEDGE(__VALUE__) (((__VALUE__) == LL_FMPI2C_ACK) || \
61 ((__VALUE__) == LL_FMPI2C_NACK))
62
63#define IS_LL_FMPI2C_OWN_ADDRSIZE(__VALUE__) (((__VALUE__) == LL_FMPI2C_OWNADDRESS1_7BIT) || \
64 ((__VALUE__) == LL_FMPI2C_OWNADDRESS1_10BIT))
68
69/* Private function prototypes -----------------------------------------------*/
70
71/* Exported functions --------------------------------------------------------*/
75
79
87ErrorStatus LL_FMPI2C_DeInit(const FMPI2C_TypeDef *FMPI2Cx)
88{
89 ErrorStatus status = SUCCESS;
90
91 /* Check the FMPI2C Instance FMPI2Cx */
92 assert_param(IS_FMPI2C_ALL_INSTANCE(FMPI2Cx));
93
94 if (FMPI2Cx == FMPI2C1)
95 {
96 /* Force reset of FMPI2C clock */
97 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_FMPI2C1);
98
99 /* Release reset of FMPI2C clock */
100 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_FMPI2C1);
101 }
102 else
103 {
104 status = ERROR;
105 }
106
107 return status;
108}
109
118ErrorStatus LL_FMPI2C_Init(FMPI2C_TypeDef *FMPI2Cx, const LL_FMPI2C_InitTypeDef *FMPI2C_InitStruct)
119{
120 /* Check the FMPI2C Instance FMPI2Cx */
121 assert_param(IS_FMPI2C_ALL_INSTANCE(FMPI2Cx));
122
123 /* Check the FMPI2C parameters from FMPI2C_InitStruct */
124 assert_param(IS_LL_FMPI2C_PERIPHERAL_MODE(FMPI2C_InitStruct->PeripheralMode));
125 assert_param(IS_LL_FMPI2C_ANALOG_FILTER(FMPI2C_InitStruct->AnalogFilter));
126 assert_param(IS_LL_FMPI2C_DIGITAL_FILTER(FMPI2C_InitStruct->DigitalFilter));
127 assert_param(IS_LL_FMPI2C_OWN_ADDRESS1(FMPI2C_InitStruct->OwnAddress1));
128 assert_param(IS_LL_FMPI2C_TYPE_ACKNOWLEDGE(FMPI2C_InitStruct->TypeAcknowledge));
129 assert_param(IS_LL_FMPI2C_OWN_ADDRSIZE(FMPI2C_InitStruct->OwnAddrSize));
130
131 /* Disable the selected FMPI2Cx Peripheral */
132 LL_FMPI2C_Disable(FMPI2Cx);
133
134 /*---------------------------- FMPI2Cx CR1 Configuration ------------------------
135 * Configure the analog and digital noise filters with parameters :
136 * - AnalogFilter: FMPI2C_CR1_ANFOFF bit
137 * - DigitalFilter: FMPI2C_CR1_DNF[3:0] bits
138 */
139 LL_FMPI2C_ConfigFilters(FMPI2Cx, FMPI2C_InitStruct->AnalogFilter, FMPI2C_InitStruct->DigitalFilter);
140
141 /*---------------------------- FMPI2Cx TIMINGR Configuration --------------------
142 * Configure the SDA setup, hold time and the SCL high, low period with parameter :
143 * - Timing: FMPI2C_TIMINGR_PRESC[3:0], FMPI2C_TIMINGR_SCLDEL[3:0], FMPI2C_TIMINGR_SDADEL[3:0],
144 * FMPI2C_TIMINGR_SCLH[7:0] and FMPI2C_TIMINGR_SCLL[7:0] bits
145 */
146 LL_FMPI2C_SetTiming(FMPI2Cx, FMPI2C_InitStruct->Timing);
147
148 /* Enable the selected FMPI2Cx Peripheral */
149 LL_FMPI2C_Enable(FMPI2Cx);
150
151 /*---------------------------- FMPI2Cx OAR1 Configuration -----------------------
152 * Disable, Configure and Enable FMPI2Cx device own address 1 with parameters :
153 * - OwnAddress1: FMPI2C_OAR1_OA1[9:0] bits
154 * - OwnAddrSize: FMPI2C_OAR1_OA1MODE bit
155 */
156 LL_FMPI2C_DisableOwnAddress1(FMPI2Cx);
157 LL_FMPI2C_SetOwnAddress1(FMPI2Cx, FMPI2C_InitStruct->OwnAddress1, FMPI2C_InitStruct->OwnAddrSize);
158
159 /* OwnAdress1 == 0 is reserved for General Call address */
160 if (FMPI2C_InitStruct->OwnAddress1 != 0U)
161 {
162 LL_FMPI2C_EnableOwnAddress1(FMPI2Cx);
163 }
164
165 /*---------------------------- FMPI2Cx MODE Configuration -----------------------
166 * Configure FMPI2Cx peripheral mode with parameter :
167 * - PeripheralMode: FMPI2C_CR1_SMBDEN and FMPI2C_CR1_SMBHEN bits
168 */
169 LL_FMPI2C_SetMode(FMPI2Cx, FMPI2C_InitStruct->PeripheralMode);
170
171 /*---------------------------- FMPI2Cx CR2 Configuration ------------------------
172 * Configure the ACKnowledge or Non ACKnowledge condition
173 * after the address receive match code or next received byte with parameter :
174 * - TypeAcknowledge: FMPI2C_CR2_NACK bit
175 */
176 LL_FMPI2C_AcknowledgeNextData(FMPI2Cx, FMPI2C_InitStruct->TypeAcknowledge);
177
178 return SUCCESS;
179}
180
186void LL_FMPI2C_StructInit(LL_FMPI2C_InitTypeDef *FMPI2C_InitStruct)
187{
188 /* Set FMPI2C_InitStruct fields to default values */
189 FMPI2C_InitStruct->PeripheralMode = LL_FMPI2C_MODE_I2C;
190 FMPI2C_InitStruct->Timing = 0U;
191 FMPI2C_InitStruct->AnalogFilter = LL_FMPI2C_ANALOGFILTER_ENABLE;
192 FMPI2C_InitStruct->DigitalFilter = 0U;
193 FMPI2C_InitStruct->OwnAddress1 = 0U;
194 FMPI2C_InitStruct->TypeAcknowledge = LL_FMPI2C_NACK;
195 FMPI2C_InitStruct->OwnAddrSize = LL_FMPI2C_OWNADDRESS1_7BIT;
196}
197
201
205
209
210#endif /* FMPI2C1 */
211
215
216#endif /* FMPI2C_CR1_PE */
217#endif /* USE_FULL_LL_DRIVER */
#define assert_param(expr)
Header file of BUS LL module.
Header file of FMPI2C LL module.