Skip to content

Commit

Permalink
feat: extend I2C for stm32wba family (#324)
Browse files Browse the repository at this point in the history
Extend I2C for stm32wba family
  • Loading branch information
cassio-lazaro committed Jun 7, 2024
1 parent 9a986b6 commit 6030210
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions hal_st/stm32fxxx/I2cStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace hal
EnableClockI2c(instance);

i2cHandle.Instance = peripheralI2c[instance];
#if defined(STM32F0) || defined(STM32F7) || defined(STM32WB) || defined(STM32G4) || defined(STM32G0) || defined(STM32WBA)
#if defined(I2C_TIMINGR_PRESC)
i2cHandle.Init.Timing = config.timing;
i2cHandle.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
#endif
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace hal

__DMB();

#if defined(STM32F0) || defined(STM32F7) || defined(STM32WB) || defined(STM32G4) || defined(STM32G0) || defined(STM32WBA)
#if defined(I2C_CR1_TXIE)
peripheralI2c[instance]->CR2 = ((address.address << 1) & I2C_CR2_SADD) | (continuingPrevious ? 0 : I2C_CR2_START) | (std::min<uint32_t>(sendData.size(), 255) << 16) | (sendData.size() > 255 || nextAction == Action::continueSession ? I2C_CR2_RELOAD : 0);
peripheralI2c[instance]->CR1 |= I2C_CR1_TXIE | I2C_CR1_TCIE | I2C_CR1_NACKIE | I2C_CR1_ERRIE;
#else
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace hal

__DMB();

#if defined(STM32F0) || defined(STM32F7) || defined(STM32WB) || defined(STM32G4) || defined(STM32G0) || defined(STM32WBA)
#if defined(I2C_ICR_STOPCF)
peripheralI2c[instance]->ICR = I2C_ICR_STOPCF;
peripheralI2c[instance]->CR2 = ((address.address << 1) & I2C_CR2_SADD) | I2C_CR2_RD_WRN | (continuingPrevious ? 0 : I2C_CR2_START) | (std::min<uint32_t>(receiveData.size(), 255) << 16) | (receiveData.size() > 255 || nextAction == Action::continueSession ? I2C_CR2_RELOAD : 0);
peripheralI2c[instance]->CR1 |= I2C_CR1_RXIE | I2C_CR1_TCIE | I2C_CR1_NACKIE | I2C_CR1_ERRIE;
Expand Down Expand Up @@ -126,7 +126,7 @@ namespace hal

void I2cStm::EventInterrupt()
{
#if defined(STM32F0) || defined(STM32F7) || defined(STM32WB) || defined(STM32G4) || defined(STM32G0) || defined(STM32WBA)
#if defined(I2C_ISR_TXE)
if ((peripheralI2c[instance]->ISR & I2C_ISR_NACKF) != 0)
{
peripheralI2c[instance]->CR1 &= ~(I2C_CR1_TXIE | I2C_CR1_RXIE | I2C_CR1_TCIE | I2C_CR1_NACKIE | I2C_CR1_ERRIE);
Expand Down Expand Up @@ -308,7 +308,7 @@ namespace hal

void I2cStm::ErrorInterrupt()
{
#if defined(STM32F0) || defined(STM32F7) || defined(STM32WB) || defined(STM32G4) || defined(STM32G0) || defined(STM32WBA)
#if defined(I2C_ISR_BERR)
if ((peripheralI2c[instance]->ISR & I2C_ISR_BERR) != 0)
{
peripheralI2c[instance]->ICR |= I2C_ISR_BERR;
Expand Down Expand Up @@ -372,7 +372,7 @@ namespace hal
#endif
}

#if defined(STM32F0) || defined(STM32F7) || defined(STM32WB) || defined(STM32G4) || defined(STM32G0) || defined(STM32WBA)
#if defined(I2C_ISR_TXE)
void I2cStm::ReadReceivedData()
{
while ((peripheralI2c[instance]->ISR & I2C_ISR_RXNE) != 0)
Expand Down
6 changes: 3 additions & 3 deletions hal_st/stm32fxxx/I2cStm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace hal
constexpr Config()
{}

#if defined(STM32F0) || defined(STM32F7) || defined(STM32WB) || defined(STM32G4) || defined(STM32G0) || defined(STM32WBA)
#if defined(I2C_TIMINGR_PRESC)
uint32_t timing = 0x00304d4d;
#endif
#if defined(STM32F2) || defined(STM32F4)
#if defined(I2C_CCR_CCR)
uint32_t clockSpeed = 400000;
#endif
};
Expand All @@ -40,7 +40,7 @@ namespace hal
private:
void EventInterrupt();
void ErrorInterrupt();
#if defined(STM32F0) || defined(STM32F7) || defined(STM32WB) || defined(STM32G4) || defined(STM32G0) || defined(STM32WBA)
#if defined(I2C_ISR_TXE)
void ReadReceivedData();
#endif

Expand Down

0 comments on commit 6030210

Please sign in to comment.