STM32F4xx_HAL_Driver  1.8.3
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 
34 #if defined (FMPI2C1)
35 
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
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))
69 /* Private function prototypes -----------------------------------------------*/
70 
71 /* Exported functions --------------------------------------------------------*/
87 ErrorStatus 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 
118 ErrorStatus 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  */
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  {
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 
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 
210 #endif /* FMPI2C1 */
211 
216 #endif /* FMPI2C_CR1_PE */
217 #endif /* USE_FULL_LL_DRIVER */
__STATIC_INLINE void LL_APB1_GRP1_ForceReset(uint32_t Periphs)
Force APB1 peripherals reset. @rmtoll APB1RSTR TIM2RST LL_APB1_GRP1_ForceReset APB1RSTR TIM3RST LL_A...
__STATIC_INLINE void LL_APB1_GRP1_ReleaseReset(uint32_t Periphs)
Release APB1 peripherals reset. @rmtoll APB1RSTR TIM2RST LL_APB1_GRP1_ReleaseReset APB1RSTR TIM3RST ...
__STATIC_INLINE void LL_FMPI2C_Disable(FMPI2C_TypeDef *FMPI2Cx)
Disable FMPI2C peripheral (PE = 0).
__STATIC_INLINE void LL_FMPI2C_EnableOwnAddress1(FMPI2C_TypeDef *FMPI2Cx)
Enable acknowledge on Own Address1 match address. @rmtoll OAR1 OA1EN LL_FMPI2C_EnableOwnAddress1.
__STATIC_INLINE void LL_FMPI2C_ConfigFilters(FMPI2C_TypeDef *FMPI2Cx, uint32_t AnalogFilter, uint32_t DigitalFilter)
Configure Noise Filters (Analog and Digital).
__STATIC_INLINE void LL_FMPI2C_DisableOwnAddress1(FMPI2C_TypeDef *FMPI2Cx)
Disable acknowledge on Own Address1 match address. @rmtoll OAR1 OA1EN LL_FMPI2C_DisableOwnAddress1.
__STATIC_INLINE void LL_FMPI2C_SetOwnAddress1(FMPI2C_TypeDef *FMPI2Cx, uint32_t OwnAddress1, uint32_t OwnAddrSize)
Set the Own Address1. @rmtoll OAR1 OA1 LL_FMPI2C_SetOwnAddress1 OAR1 OA1MODE LL_FMPI2C_SetOwnAddress...
__STATIC_INLINE void LL_FMPI2C_Enable(FMPI2C_TypeDef *FMPI2Cx)
Enable FMPI2C peripheral (PE = 1). @rmtoll CR1 PE LL_FMPI2C_Enable.
__STATIC_INLINE void LL_FMPI2C_SetMode(FMPI2C_TypeDef *FMPI2Cx, uint32_t PeripheralMode)
Configure peripheral mode.
__STATIC_INLINE void LL_FMPI2C_SetTiming(FMPI2C_TypeDef *FMPI2Cx, uint32_t Timing)
Configure the SDA setup, hold time and the SCL high, low period.
__STATIC_INLINE void LL_FMPI2C_AcknowledgeNextData(FMPI2C_TypeDef *FMPI2Cx, uint32_t TypeAcknowledge)
Prepare the generation of a ACKnowledge or Non ACKnowledge condition after the address receive match ...
ErrorStatus LL_FMPI2C_DeInit(const FMPI2C_TypeDef *FMPI2Cx)
De-initialize the FMPI2C registers to their default reset values.
void LL_FMPI2C_StructInit(LL_FMPI2C_InitTypeDef *FMPI2C_InitStruct)
Set each LL_FMPI2C_InitTypeDef field to default value.
ErrorStatus LL_FMPI2C_Init(FMPI2C_TypeDef *FMPI2Cx, const LL_FMPI2C_InitTypeDef *FMPI2C_InitStruct)
Initialize the FMPI2C registers according to the specified parameters in FMPI2C_InitStruct.
Header file of BUS LL module.
Header file of FMPI2C LL module.