21 #ifndef __STM32F4xx_HAL_SMBUS_H
22 #define __STM32F4xx_HAL_SMBUS_H
184 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
194 void (* AddrCallback)(
struct __SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode);
201 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
207 HAL_SMBUS_MASTER_TX_COMPLETE_CB_ID = 0x00U,
208 HAL_SMBUS_MASTER_RX_COMPLETE_CB_ID = 0x01U,
209 HAL_SMBUS_SLAVE_TX_COMPLETE_CB_ID = 0x02U,
210 HAL_SMBUS_SLAVE_RX_COMPLETE_CB_ID = 0x03U,
211 HAL_SMBUS_LISTEN_COMPLETE_CB_ID = 0x04U,
212 HAL_SMBUS_ERROR_CB_ID = 0x07U,
213 HAL_SMBUS_ABORT_CB_ID = 0x08U,
214 HAL_SMBUS_MSPINIT_CB_ID = 0x09U,
215 HAL_SMBUS_MSPDEINIT_CB_ID = 0x0AU
217 } HAL_SMBUS_CallbackIDTypeDef;
223 typedef void (*pSMBUS_AddrCallbackTypeDef)(
SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode);
240 #define HAL_SMBUS_ERROR_NONE 0x00000000U
241 #define HAL_SMBUS_ERROR_BERR 0x00000001U
242 #define HAL_SMBUS_ERROR_ARLO 0x00000002U
243 #define HAL_SMBUS_ERROR_AF 0x00000004U
244 #define HAL_SMBUS_ERROR_OVR 0x00000008U
245 #define HAL_SMBUS_ERROR_TIMEOUT 0x00000010U
246 #define HAL_SMBUS_ERROR_ALERT 0x00000020U
247 #define HAL_SMBUS_ERROR_PECERR 0x00000040U
248 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
249 #define HAL_SMBUS_ERROR_INVALID_CALLBACK 0x00000080U
259 #define SMBUS_ANALOGFILTER_ENABLE 0x00000000U
260 #define SMBUS_ANALOGFILTER_DISABLE I2C_FLTR_ANOFF
268 #define SMBUS_ADDRESSINGMODE_7BIT 0x00004000U
269 #define SMBUS_ADDRESSINGMODE_10BIT (I2C_OAR1_ADDMODE | 0x00004000U)
277 #define SMBUS_DUALADDRESS_DISABLE 0x00000000U
278 #define SMBUS_DUALADDRESS_ENABLE I2C_OAR2_ENDUAL
286 #define SMBUS_GENERALCALL_DISABLE 0x00000000U
287 #define SMBUS_GENERALCALL_ENABLE I2C_CR1_ENGC
295 #define SMBUS_NOSTRETCH_DISABLE 0x00000000U
296 #define SMBUS_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH
304 #define SMBUS_PEC_DISABLE 0x00000000U
305 #define SMBUS_PEC_ENABLE I2C_CR1_ENPEC
313 #define SMBUS_PERIPHERAL_MODE_SMBUS_HOST (uint32_t)(I2C_CR1_SMBUS | I2C_CR1_SMBTYPE | I2C_CR1_ENARP)
314 #define SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE I2C_CR1_SMBUS
315 #define SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP (uint32_t)(I2C_CR1_SMBUS | I2C_CR1_ENARP)
323 #define SMBUS_DIRECTION_RECEIVE 0x00000000U
324 #define SMBUS_DIRECTION_TRANSMIT 0x00000001U
332 #define SMBUS_FIRST_FRAME 0x00000001U
333 #define SMBUS_NEXT_FRAME 0x00000002U
334 #define SMBUS_FIRST_AND_LAST_FRAME_NO_PEC 0x00000003U
335 #define SMBUS_LAST_FRAME_NO_PEC 0x00000004U
336 #define SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC 0x00000005U
337 #define SMBUS_LAST_FRAME_WITH_PEC 0x00000006U
345 #define SMBUS_IT_BUF I2C_CR2_ITBUFEN
346 #define SMBUS_IT_EVT I2C_CR2_ITEVTEN
347 #define SMBUS_IT_ERR I2C_CR2_ITERREN
355 #define SMBUS_FLAG_SMBALERT 0x00018000U
356 #define SMBUS_FLAG_TIMEOUT 0x00014000U
357 #define SMBUS_FLAG_PECERR 0x00011000U
358 #define SMBUS_FLAG_OVR 0x00010800U
359 #define SMBUS_FLAG_AF 0x00010400U
360 #define SMBUS_FLAG_ARLO 0x00010200U
361 #define SMBUS_FLAG_BERR 0x00010100U
362 #define SMBUS_FLAG_TXE 0x00010080U
363 #define SMBUS_FLAG_RXNE 0x00010040U
364 #define SMBUS_FLAG_STOPF 0x00010010U
365 #define SMBUS_FLAG_ADD10 0x00010008U
366 #define SMBUS_FLAG_BTF 0x00010004U
367 #define SMBUS_FLAG_ADDR 0x00010002U
368 #define SMBUS_FLAG_SB 0x00010001U
369 #define SMBUS_FLAG_DUALF 0x00100080U
370 #define SMBUS_FLAG_SMBHOST 0x00100040U
371 #define SMBUS_FLAG_SMBDEFAULT 0x00100020U
372 #define SMBUS_FLAG_GENCALL 0x00100010U
373 #define SMBUS_FLAG_TRA 0x00100004U
374 #define SMBUS_FLAG_BUSY 0x00100002U
375 #define SMBUS_FLAG_MSL 0x00100001U
394 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
395 #define __HAL_SMBUS_RESET_HANDLE_STATE(__HANDLE__) do{ \
396 (__HANDLE__)->State = HAL_SMBUS_STATE_RESET; \
397 (__HANDLE__)->MspInitCallback = NULL; \
398 (__HANDLE__)->MspDeInitCallback = NULL; \
401 #define __HAL_SMBUS_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMBUS_STATE_RESET)
414 #define __HAL_SMBUS_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 |= (__INTERRUPT__))
415 #define __HAL_SMBUS_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR2 &= (~(__INTERRUPT__)))
427 #define __HAL_SMBUS_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
458 #define __HAL_SMBUS_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16U)) == 0x01U)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & SMBUS_FLAG_MASK)) == ((__FLAG__) & SMBUS_FLAG_MASK)): \
459 ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & SMBUS_FLAG_MASK)) == ((__FLAG__) & SMBUS_FLAG_MASK)))
475 #define __HAL_SMBUS_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR1 = ~((__FLAG__) & SMBUS_FLAG_MASK))
482 #define __HAL_SMBUS_CLEAR_ADDRFLAG(__HANDLE__) \
484 __IO uint32_t tmpreg = 0x00U; \
485 tmpreg = (__HANDLE__)->Instance->SR1; \
486 tmpreg = (__HANDLE__)->Instance->SR2; \
495 #define __HAL_SMBUS_CLEAR_STOPFLAG(__HANDLE__) \
497 __IO uint32_t tmpreg = 0x00U; \
498 tmpreg = (__HANDLE__)->Instance->SR1; \
499 (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE; \
508 #define __HAL_SMBUS_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= I2C_CR1_PE)
515 #define __HAL_SMBUS_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~I2C_CR1_PE)
521 #define __HAL_SMBUS_GENERATE_NACK(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_ACK))
543 #if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
585 #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
634 #define SMBUS_FLAG_MASK 0x0000FFFFU
644 #define SMBUS_FREQRANGE(__PCLK__) ((__PCLK__)/1000000U)
646 #define SMBUS_RISE_TIME(__FREQRANGE__) ( ((__FREQRANGE__) + 1U))
648 #define SMBUS_SPEED_STANDARD(__PCLK__, __SPEED__) (((((__PCLK__)/((__SPEED__) << 1U)) & I2C_CCR_CCR) < 4U)? 4U:((__PCLK__) / ((__SPEED__) << 1U)))
650 #define SMBUS_7BIT_ADD_WRITE(__ADDRESS__) ((uint8_t)((__ADDRESS__) & (~I2C_OAR1_ADD0)))
652 #define SMBUS_7BIT_ADD_READ(__ADDRESS__) ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0))
654 #define SMBUS_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)0x00FF)))
656 #define SMBUS_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0x0300)) >> 7) | (uint16_t)0x00F0)))
658 #define SMBUS_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)0x0300)) >> 7) | (uint16_t)(0x00F1))))
660 #define SMBUS_GET_PEC_MODE(__HANDLE__) ((__HANDLE__)->Instance->CR1 & I2C_CR1_ENPEC)
662 #define SMBUS_GET_PEC_VALUE(__HANDLE__) ((__HANDLE__)->XferPEC)
664 #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF)
665 #define IS_SMBUS_ANALOG_FILTER(FILTER) (((FILTER) == SMBUS_ANALOGFILTER_ENABLE) || \
666 ((FILTER) == SMBUS_ANALOGFILTER_DISABLE))
667 #define IS_SMBUS_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU)
669 #define IS_SMBUS_ADDRESSING_MODE(ADDRESS) (((ADDRESS) == SMBUS_ADDRESSINGMODE_7BIT) || \
670 ((ADDRESS) == SMBUS_ADDRESSINGMODE_10BIT))
672 #define IS_SMBUS_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == SMBUS_DUALADDRESS_DISABLE) || \
673 ((ADDRESS) == SMBUS_DUALADDRESS_ENABLE))
675 #define IS_SMBUS_GENERAL_CALL(CALL) (((CALL) == SMBUS_GENERALCALL_DISABLE) || \
676 ((CALL) == SMBUS_GENERALCALL_ENABLE))
678 #define IS_SMBUS_NO_STRETCH(STRETCH) (((STRETCH) == SMBUS_NOSTRETCH_DISABLE) || \
679 ((STRETCH) == SMBUS_NOSTRETCH_ENABLE))
681 #define IS_SMBUS_PEC(PEC) (((PEC) == SMBUS_PEC_DISABLE) || \
682 ((PEC) == SMBUS_PEC_ENABLE))
684 #define IS_SMBUS_PERIPHERAL_MODE(MODE) (((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_HOST) || \
685 ((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE) || \
686 ((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP))
688 #define IS_SMBUS_CLOCK_SPEED(SPEED) (((SPEED) > 0U) && ((SPEED) <= 100000U))
690 #define IS_SMBUS_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & 0xFFFFFC00U) == 0U)
692 #define IS_SMBUS_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & 0xFFFFFF01U) == 0U)
694 #define IS_SMBUS_TRANSFER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == SMBUS_FIRST_FRAME) || \
695 ((REQUEST) == SMBUS_NEXT_FRAME) || \
696 ((REQUEST) == SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) || \
697 ((REQUEST) == SMBUS_LAST_FRAME_NO_PEC) || \
698 ((REQUEST) == SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC) || \
699 ((REQUEST) == SMBUS_LAST_FRAME_WITH_PEC))