20#ifndef STM32H7xx_HAL_SMBUS_H
21#define STM32H7xx_HAL_SMBUS_H
99#define HAL_SMBUS_STATE_RESET (0x00000000U)
100#define HAL_SMBUS_STATE_READY (0x00000001U)
101#define HAL_SMBUS_STATE_BUSY (0x00000002U)
102#define HAL_SMBUS_STATE_MASTER_BUSY_TX (0x00000012U)
103#define HAL_SMBUS_STATE_MASTER_BUSY_RX (0x00000022U)
104#define HAL_SMBUS_STATE_SLAVE_BUSY_TX (0x00000032U)
105#define HAL_SMBUS_STATE_SLAVE_BUSY_RX (0x00000042U)
106#define HAL_SMBUS_STATE_LISTEN (0x00000008U)
116#define HAL_SMBUS_ERROR_NONE (0x00000000U)
117#define HAL_SMBUS_ERROR_BERR (0x00000001U)
118#define HAL_SMBUS_ERROR_ARLO (0x00000002U)
119#define HAL_SMBUS_ERROR_ACKF (0x00000004U)
120#define HAL_SMBUS_ERROR_OVR (0x00000008U)
121#define HAL_SMBUS_ERROR_HALTIMEOUT (0x00000010U)
122#define HAL_SMBUS_ERROR_BUSTIMEOUT (0x00000020U)
123#define HAL_SMBUS_ERROR_ALERT (0x00000040U)
124#define HAL_SMBUS_ERROR_PECERR (0x00000080U)
125#if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
126#define HAL_SMBUS_ERROR_INVALID_CALLBACK (0x00000100U)
128#define HAL_SMBUS_ERROR_INVALID_PARAM (0x00000200U)
138#if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
139typedef struct __SMBUS_HandleTypeDef
164#if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
165 void (* MasterTxCpltCallback)(
struct __SMBUS_HandleTypeDef *hsmbus);
167 void (* MasterRxCpltCallback)(
struct __SMBUS_HandleTypeDef *hsmbus);
169 void (* SlaveTxCpltCallback)(
struct __SMBUS_HandleTypeDef *hsmbus);
171 void (* SlaveRxCpltCallback)(
struct __SMBUS_HandleTypeDef *hsmbus);
173 void (* ListenCpltCallback)(
struct __SMBUS_HandleTypeDef *hsmbus);
175 void (* ErrorCallback)(
struct __SMBUS_HandleTypeDef *hsmbus);
178 void (* AddrCallback)(
struct __SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode);
181 void (* MspInitCallback)(
struct __SMBUS_HandleTypeDef *hsmbus);
183 void (* MspDeInitCallback)(
struct __SMBUS_HandleTypeDef *hsmbus);
189#if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
195 HAL_SMBUS_MASTER_TX_COMPLETE_CB_ID = 0x00U,
196 HAL_SMBUS_MASTER_RX_COMPLETE_CB_ID = 0x01U,
197 HAL_SMBUS_SLAVE_TX_COMPLETE_CB_ID = 0x02U,
198 HAL_SMBUS_SLAVE_RX_COMPLETE_CB_ID = 0x03U,
199 HAL_SMBUS_LISTEN_COMPLETE_CB_ID = 0x04U,
200 HAL_SMBUS_ERROR_CB_ID = 0x05U,
202 HAL_SMBUS_MSPINIT_CB_ID = 0x06U,
203 HAL_SMBUS_MSPDEINIT_CB_ID = 0x07U
205} HAL_SMBUS_CallbackIDTypeDef;
212typedef void (*pSMBUS_AddrCallbackTypeDef)(
SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection,
213 uint16_t AddrMatchCode);
235#define SMBUS_ANALOGFILTER_ENABLE (0x00000000U)
236#define SMBUS_ANALOGFILTER_DISABLE I2C_CR1_ANFOFF
245#define SMBUS_ADDRESSINGMODE_7BIT (0x00000001U)
246#define SMBUS_ADDRESSINGMODE_10BIT (0x00000002U)
256#define SMBUS_DUALADDRESS_DISABLE (0x00000000U)
257#define SMBUS_DUALADDRESS_ENABLE I2C_OAR2_OA2EN
267#define SMBUS_OA2_NOMASK ((uint8_t)0x00U)
268#define SMBUS_OA2_MASK01 ((uint8_t)0x01U)
269#define SMBUS_OA2_MASK02 ((uint8_t)0x02U)
270#define SMBUS_OA2_MASK03 ((uint8_t)0x03U)
271#define SMBUS_OA2_MASK04 ((uint8_t)0x04U)
272#define SMBUS_OA2_MASK05 ((uint8_t)0x05U)
273#define SMBUS_OA2_MASK06 ((uint8_t)0x06U)
274#define SMBUS_OA2_MASK07 ((uint8_t)0x07U)
284#define SMBUS_GENERALCALL_DISABLE (0x00000000U)
285#define SMBUS_GENERALCALL_ENABLE I2C_CR1_GCEN
294#define SMBUS_NOSTRETCH_DISABLE (0x00000000U)
295#define SMBUS_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH
304#define SMBUS_PEC_DISABLE (0x00000000U)
305#define SMBUS_PEC_ENABLE I2C_CR1_PECEN
314#define SMBUS_PERIPHERAL_MODE_SMBUS_HOST I2C_CR1_SMBHEN
315#define SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE (0x00000000U)
316#define SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP I2C_CR1_SMBDEN
326#define SMBUS_SOFTEND_MODE (0x00000000U)
327#define SMBUS_RELOAD_MODE I2C_CR2_RELOAD
328#define SMBUS_AUTOEND_MODE I2C_CR2_AUTOEND
329#define SMBUS_SENDPEC_MODE I2C_CR2_PECBYTE
339#define SMBUS_NO_STARTSTOP (0x00000000U)
340#define SMBUS_GENERATE_STOP (uint32_t)(0x80000000U | I2C_CR2_STOP)
341#define SMBUS_GENERATE_START_READ (uint32_t)(0x80000000U | I2C_CR2_START | I2C_CR2_RD_WRN)
342#define SMBUS_GENERATE_START_WRITE (uint32_t)(0x80000000U | I2C_CR2_START)
356#define SMBUS_FIRST_FRAME SMBUS_SOFTEND_MODE
357#define SMBUS_NEXT_FRAME ((uint32_t)(SMBUS_RELOAD_MODE | SMBUS_SOFTEND_MODE))
358#define SMBUS_FIRST_AND_LAST_FRAME_NO_PEC SMBUS_AUTOEND_MODE
359#define SMBUS_LAST_FRAME_NO_PEC SMBUS_AUTOEND_MODE
360#define SMBUS_FIRST_FRAME_WITH_PEC ((uint32_t)(SMBUS_SOFTEND_MODE | SMBUS_SENDPEC_MODE))
361#define SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC ((uint32_t)(SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE))
362#define SMBUS_LAST_FRAME_WITH_PEC ((uint32_t)(SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE))
367#define SMBUS_OTHER_FRAME_NO_PEC (0x000000AAU)
368#define SMBUS_OTHER_FRAME_WITH_PEC (0x0000AA00U)
369#define SMBUS_OTHER_AND_LAST_FRAME_NO_PEC (0x00AA0000U)
370#define SMBUS_OTHER_AND_LAST_FRAME_WITH_PEC (0xAA000000U)
382#define SMBUS_IT_ERRI I2C_CR1_ERRIE
383#define SMBUS_IT_TCI I2C_CR1_TCIE
384#define SMBUS_IT_STOPI I2C_CR1_STOPIE
385#define SMBUS_IT_NACKI I2C_CR1_NACKIE
386#define SMBUS_IT_ADDRI I2C_CR1_ADDRIE
387#define SMBUS_IT_RXI I2C_CR1_RXIE
388#define SMBUS_IT_TXI I2C_CR1_TXIE
389#define SMBUS_IT_TX (SMBUS_IT_ERRI | SMBUS_IT_TCI | SMBUS_IT_STOPI | \
390 SMBUS_IT_NACKI | SMBUS_IT_TXI)
391#define SMBUS_IT_RX (SMBUS_IT_ERRI | SMBUS_IT_TCI | SMBUS_IT_NACKI | \
393#define SMBUS_IT_ALERT (SMBUS_IT_ERRI)
394#define SMBUS_IT_ADDR (SMBUS_IT_ADDRI | SMBUS_IT_STOPI | SMBUS_IT_NACKI)
407#define SMBUS_FLAG_TXE I2C_ISR_TXE
408#define SMBUS_FLAG_TXIS I2C_ISR_TXIS
409#define SMBUS_FLAG_RXNE I2C_ISR_RXNE
410#define SMBUS_FLAG_ADDR I2C_ISR_ADDR
411#define SMBUS_FLAG_AF I2C_ISR_NACKF
412#define SMBUS_FLAG_STOPF I2C_ISR_STOPF
413#define SMBUS_FLAG_TC I2C_ISR_TC
414#define SMBUS_FLAG_TCR I2C_ISR_TCR
415#define SMBUS_FLAG_BERR I2C_ISR_BERR
416#define SMBUS_FLAG_ARLO I2C_ISR_ARLO
417#define SMBUS_FLAG_OVR I2C_ISR_OVR
418#define SMBUS_FLAG_PECERR I2C_ISR_PECERR
419#define SMBUS_FLAG_TIMEOUT I2C_ISR_TIMEOUT
420#define SMBUS_FLAG_ALERT I2C_ISR_ALERT
421#define SMBUS_FLAG_BUSY I2C_ISR_BUSY
422#define SMBUS_FLAG_DIR I2C_ISR_DIR
441#if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
442#define __HAL_SMBUS_RESET_HANDLE_STATE(__HANDLE__) do{ \
443 (__HANDLE__)->State = HAL_SMBUS_STATE_RESET; \
444 (__HANDLE__)->MspInitCallback = NULL; \
445 (__HANDLE__)->MspDeInitCallback = NULL; \
448#define __HAL_SMBUS_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMBUS_STATE_RESET)
465#define __HAL_SMBUS_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 |= (__INTERRUPT__))
481#define __HAL_SMBUS_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR1 &= (~(__INTERRUPT__)))
497#define __HAL_SMBUS_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
498 ((((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
523#define SMBUS_FLAG_MASK (0x0001FFFFU)
524#define __HAL_SMBUS_GET_FLAG(__HANDLE__, __FLAG__) \
525 (((((__HANDLE__)->Instance->ISR) & ((__FLAG__) & SMBUS_FLAG_MASK)) == \
526 ((__FLAG__) & SMBUS_FLAG_MASK)) ? SET : RESET)
545#define __HAL_SMBUS_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__FLAG__) == SMBUS_FLAG_TXE) ? \
546 ((__HANDLE__)->Instance->ISR |= (__FLAG__)) : \
547 ((__HANDLE__)->Instance->ICR = (__FLAG__)))
553#define __HAL_SMBUS_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE))
559#define __HAL_SMBUS_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE))
565#define __HAL_SMBUS_GENERATE_NACK(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR2, I2C_CR2_NACK))
580#define IS_SMBUS_ANALOG_FILTER(FILTER) (((FILTER) == SMBUS_ANALOGFILTER_ENABLE) || \
581 ((FILTER) == SMBUS_ANALOGFILTER_DISABLE))
583#define IS_SMBUS_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU)
585#define IS_SMBUS_ADDRESSING_MODE(MODE) (((MODE) == SMBUS_ADDRESSINGMODE_7BIT) || \
586 ((MODE) == SMBUS_ADDRESSINGMODE_10BIT))
588#define IS_SMBUS_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == SMBUS_DUALADDRESS_DISABLE) || \
589 ((ADDRESS) == SMBUS_DUALADDRESS_ENABLE))
591#define IS_SMBUS_OWN_ADDRESS2_MASK(MASK) (((MASK) == SMBUS_OA2_NOMASK) || \
592 ((MASK) == SMBUS_OA2_MASK01) || \
593 ((MASK) == SMBUS_OA2_MASK02) || \
594 ((MASK) == SMBUS_OA2_MASK03) || \
595 ((MASK) == SMBUS_OA2_MASK04) || \
596 ((MASK) == SMBUS_OA2_MASK05) || \
597 ((MASK) == SMBUS_OA2_MASK06) || \
598 ((MASK) == SMBUS_OA2_MASK07))
600#define IS_SMBUS_GENERAL_CALL(CALL) (((CALL) == SMBUS_GENERALCALL_DISABLE) || \
601 ((CALL) == SMBUS_GENERALCALL_ENABLE))
603#define IS_SMBUS_NO_STRETCH(STRETCH) (((STRETCH) == SMBUS_NOSTRETCH_DISABLE) || \
604 ((STRETCH) == SMBUS_NOSTRETCH_ENABLE))
606#define IS_SMBUS_PEC(PEC) (((PEC) == SMBUS_PEC_DISABLE) || \
607 ((PEC) == SMBUS_PEC_ENABLE))
609#define IS_SMBUS_PERIPHERAL_MODE(MODE) (((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_HOST) || \
610 ((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE) || \
611 ((MODE) == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP))
613#define IS_SMBUS_TRANSFER_MODE(MODE) (((MODE) == SMBUS_RELOAD_MODE) || \
614 ((MODE) == SMBUS_AUTOEND_MODE) || \
615 ((MODE) == SMBUS_SOFTEND_MODE) || \
616 ((MODE) == SMBUS_SENDPEC_MODE) || \
617 ((MODE) == (SMBUS_RELOAD_MODE | SMBUS_SENDPEC_MODE)) || \
618 ((MODE) == (SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE)) || \
619 ((MODE) == (SMBUS_AUTOEND_MODE | SMBUS_RELOAD_MODE)) || \
620 ((MODE) == (SMBUS_AUTOEND_MODE | SMBUS_SENDPEC_MODE | \
621 SMBUS_RELOAD_MODE )))
624#define IS_SMBUS_TRANSFER_REQUEST(REQUEST) (((REQUEST) == SMBUS_GENERATE_STOP) || \
625 ((REQUEST) == SMBUS_GENERATE_START_READ) || \
626 ((REQUEST) == SMBUS_GENERATE_START_WRITE) || \
627 ((REQUEST) == SMBUS_NO_STARTSTOP))
630#define IS_SMBUS_TRANSFER_OPTIONS_REQUEST(REQUEST) (IS_SMBUS_TRANSFER_OTHER_OPTIONS_REQUEST(REQUEST) || \
631 ((REQUEST) == SMBUS_FIRST_FRAME) || \
632 ((REQUEST) == SMBUS_NEXT_FRAME) || \
633 ((REQUEST) == SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) || \
634 ((REQUEST) == SMBUS_LAST_FRAME_NO_PEC) || \
635 ((REQUEST) == SMBUS_FIRST_FRAME_WITH_PEC) || \
636 ((REQUEST) == SMBUS_FIRST_AND_LAST_FRAME_WITH_PEC) || \
637 ((REQUEST) == SMBUS_LAST_FRAME_WITH_PEC))
639#define IS_SMBUS_TRANSFER_OTHER_OPTIONS_REQUEST(REQUEST) (((REQUEST) == SMBUS_OTHER_FRAME_NO_PEC) || \
640 ((REQUEST) == SMBUS_OTHER_AND_LAST_FRAME_NO_PEC) || \
641 ((REQUEST) == SMBUS_OTHER_FRAME_WITH_PEC) || \
642 ((REQUEST) == SMBUS_OTHER_AND_LAST_FRAME_WITH_PEC))
644#define SMBUS_RESET_CR1(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= \
645 (uint32_t)~((uint32_t)(I2C_CR1_SMBHEN | I2C_CR1_SMBDEN | \
647#define SMBUS_RESET_CR2(__HANDLE__) ((__HANDLE__)->Instance->CR2 &= \
648 (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_HEAD10R | \
649 I2C_CR2_NBYTES | I2C_CR2_RELOAD | \
652#define SMBUS_GENERATE_START(__ADDMODE__,__ADDRESS__) (((__ADDMODE__) == SMBUS_ADDRESSINGMODE_7BIT) ? \
653 (uint32_t)((((uint32_t)(__ADDRESS__) & (I2C_CR2_SADD)) | \
654 (I2C_CR2_START) | (I2C_CR2_AUTOEND)) & \
655 (~I2C_CR2_RD_WRN)) : \
656 (uint32_t)((((uint32_t)(__ADDRESS__) & \
657 (I2C_CR2_SADD)) | (I2C_CR2_ADD10) | \
658 (I2C_CR2_START)) & (~I2C_CR2_RD_WRN)))
660#define SMBUS_GET_ADDR_MATCH(__HANDLE__) (((__HANDLE__)->Instance->ISR & I2C_ISR_ADDCODE) >> 17U)
661#define SMBUS_GET_DIR(__HANDLE__) (((__HANDLE__)->Instance->ISR & I2C_ISR_DIR) >> 16U)
662#define SMBUS_GET_STOP_MODE(__HANDLE__) ((__HANDLE__)->Instance->CR2 & I2C_CR2_AUTOEND)
663#define SMBUS_GET_PEC_MODE(__HANDLE__) ((__HANDLE__)->Instance->CR2 & I2C_CR2_PECBYTE)
664#define SMBUS_GET_ALERT_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CR1 & I2C_CR1_ALERTEN)
666#define SMBUS_CHECK_FLAG(__ISR__, __FLAG__) ((((__ISR__) & ((__FLAG__) & SMBUS_FLAG_MASK)) == \
667 ((__FLAG__) & SMBUS_FLAG_MASK)) ? SET : RESET)
668#define SMBUS_CHECK_IT_SOURCE(__CR1__, __IT__) ((((__CR1__) & (__IT__)) == (__IT__)) ? SET : RESET)
670#define IS_SMBUS_OWN_ADDRESS1(ADDRESS1) ((ADDRESS1) <= 0x000003FFU)
671#define IS_SMBUS_OWN_ADDRESS2(ADDRESS2) ((ADDRESS2) <= (uint16_t)0x00FFU)
698#if (USE_HAL_SMBUS_REGISTER_CALLBACKS == 1)
700 HAL_SMBUS_CallbackIDTypeDef CallbackID,
701 pSMBUS_CallbackTypeDef pCallback);
703 HAL_SMBUS_CallbackIDTypeDef CallbackID);
706 pSMBUS_AddrCallbackTypeDef pCallback);
733 uint8_t *pData, uint16_t Size, uint32_t XferOptions);
735 uint8_t *pData, uint16_t Size, uint32_t XferOptions);
738 uint32_t XferOptions);
740 uint32_t XferOptions);
760void HAL_SMBUS_AddrCallback(
SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode);
#define __IO
Definition: core_cm4.h:239
This file contains HAL common defines, enumeration, macros and structures definitions.
HAL_StatusTypeDef
HAL Status structures definition.
Definition: stm32h7xx_hal_def.h:47
HAL_LockTypeDef
HAL Lock structures definition.
Definition: stm32h7xx_hal_def.h:58
Header file of SMBUS HAL Extended module.
Inter-integrated Circuit Interface.
Definition: stm32h723xx.h:1133
Definition: stm32h7xx_hal_smbus.h:143
__IO uint32_t PreviousState
Definition: stm32h7xx_hal_smbus.h:156
__IO uint32_t ErrorCode
Definition: stm32h7xx_hal_smbus.h:162
SMBUS_InitTypeDef Init
Definition: stm32h7xx_hal_smbus.h:146
uint16_t XferSize
Definition: stm32h7xx_hal_smbus.h:150
__IO uint32_t XferOptions
Definition: stm32h7xx_hal_smbus.h:154
__IO uint32_t State
Definition: stm32h7xx_hal_smbus.h:160
uint8_t * pBuffPtr
Definition: stm32h7xx_hal_smbus.h:148
HAL_LockTypeDef Lock
Definition: stm32h7xx_hal_smbus.h:158
__IO uint16_t XferCount
Definition: stm32h7xx_hal_smbus.h:152
I2C_TypeDef * Instance
Definition: stm32h7xx_hal_smbus.h:144
Definition: stm32h7xx_hal_smbus.h:50
uint32_t OwnAddress2Masks
Definition: stm32h7xx_hal_smbus.h:69
uint32_t Timing
Definition: stm32h7xx_hal_smbus.h:51
uint32_t PacketErrorCheckMode
Definition: stm32h7xx_hal_smbus.h:79
uint32_t AddressingMode
Definition: stm32h7xx_hal_smbus.h:60
uint32_t SMBusTimeout
Definition: stm32h7xx_hal_smbus.h:85
uint32_t AnalogFilter
Definition: stm32h7xx_hal_smbus.h:54
uint32_t OwnAddress2
Definition: stm32h7xx_hal_smbus.h:66
uint32_t GeneralCallMode
Definition: stm32h7xx_hal_smbus.h:73
uint32_t DualAddressMode
Definition: stm32h7xx_hal_smbus.h:63
uint32_t PeripheralMode
Definition: stm32h7xx_hal_smbus.h:82
uint32_t NoStretchMode
Definition: stm32h7xx_hal_smbus.h:76
uint32_t OwnAddress1
Definition: stm32h7xx_hal_smbus.h:57