13#if defined(STM32F4) && defined (HAL_I2C_MODULE_ENABLED)
17void Stm32F4I2cSlave::clearBusyFlagErratum(GPIO_TypeDef* sclPort, uint16_t sclPin,
18 GPIO_TypeDef* sdaPort, uint16_t sdaPin, uint8_t alternate)
20 if (__HAL_I2C_GET_FLAG(hardwareHandle(), I2C_FLAG_BUSY) == RESET)
23 GPIO_InitTypeDef GPIO_InitStructure;
26 hardwareHandle()->Instance->CR1 &= ~(0x0001);
29 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_OD;
31 GPIO_InitStructure.Pull = GPIO_PULLUP;
32 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
34 GPIO_InitStructure.Pin = sclPin;
35 HAL_GPIO_Init(sclPort, &GPIO_InitStructure);
36 HAL_GPIO_WritePin(sclPort, sclPin, GPIO_PIN_SET);
38 GPIO_InitStructure.Pin = sdaPin;
39 HAL_GPIO_Init(sdaPort, &GPIO_InitStructure);
40 HAL_GPIO_WritePin(sdaPort, sdaPin, GPIO_PIN_SET);
43 while (GPIO_PIN_SET != HAL_GPIO_ReadPin(sclPort, sclPin))
48 while (GPIO_PIN_SET != HAL_GPIO_ReadPin(sdaPort, sdaPin))
54 HAL_GPIO_WritePin(sdaPort, sdaPin, GPIO_PIN_RESET);
57 while (GPIO_PIN_RESET != HAL_GPIO_ReadPin(sdaPort, sdaPin))
63 HAL_GPIO_WritePin(sclPort, sclPin, GPIO_PIN_RESET);
66 while (GPIO_PIN_RESET != HAL_GPIO_ReadPin(sclPort, sclPin))
72 HAL_GPIO_WritePin(sclPort, sclPin, GPIO_PIN_SET);
75 while (GPIO_PIN_SET != HAL_GPIO_ReadPin(sclPort, sclPin))
81 HAL_GPIO_WritePin(sdaPort, sdaPin, GPIO_PIN_SET);
84 while (GPIO_PIN_SET != HAL_GPIO_ReadPin(sdaPort, sdaPin))
90 GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
91 GPIO_InitStructure.Alternate = alternate;
93 GPIO_InitStructure.Pin = sclPin;
94 HAL_GPIO_Init(sclPort, &GPIO_InitStructure);
96 GPIO_InitStructure.Pin = sdaPin;
97 HAL_GPIO_Init(sdaPort, &GPIO_InitStructure);
100 hardwareHandle()->Instance->CR1 |= 0x8000;
105 hardwareHandle()->Instance->CR1 &= ~0x8000;
110 hardwareHandle()->Instance->CR1 |= 0x0001;
113 HAL_I2C_Init(hardwareHandle());
116void Stm32F4I2cSlave::setFrequencyHardware(uint32_t hz)
120 SEMF_ERROR(
"frequency not supported, max frequency is 400kHz");
121 onError(Error(kSemfClassId,
static_cast<uint8_t
>(ErrorCode::SetFrequencyHardware_FrequencyNotSupported)));
125 hardwareHandle()->Init.ClockSpeed = hz;