Merge branch 'merge-stm32' of gitlab.com:sta-git/avionics/stm32/libs/sta-core into merge-stm32

This commit is contained in:
Henrik Stickann
2023-04-22 13:06:31 +02:00
7 changed files with 222 additions and 0 deletions

27
include/sta/i2c.hpp Normal file
View File

@@ -0,0 +1,27 @@
#ifndef STA_I2C_HPP
#define STA_I2C_HPP
#include <cstdint>
#include <sta/mutex.hpp>
namespace sta {
class I2cDevice {
protected:
uint16_t address;
Mutex* mutex;
bool master;
bool blocking;
public:
I2cDevice(uint16_t address_10bit, Mutex* mutex=nullptr, bool master=false, bool blocking=true);
virtual bool transmit(uint8_t* data, uint16_t size) = 0;
virtual bool receive(uint8_t* data, uint16_t size) = 0;
virtual void acquire();
virtual void release();
};
}
#endif // STA_I2C_HPP

39
include/sta/stm32/i2c.hpp Normal file
View File

@@ -0,0 +1,39 @@
#ifndef STA_STM32_I2C_HPP
#define STA_STM32_I2C_HPP
#include <sta/config.hpp>
#ifdef STA_PLATFORM_STM32
# include <sta/stm32/hal.hpp>
# ifdef HAL_I2C_MODULE_ENABLED
# define STA_STM32_I2C_ENABLED
# endif // HAL_SPI_MODULE_ENABLED
#endif // STA_PLATFORM_STM32
#ifdef STA_STM32_I2C_ENABLED
#include <sta/i2c.hpp>
namespace sta {
class STM32I2cDevice : public I2cDevice {
private:
I2C_HandleTypeDef* i2cHandle;
const uint32_t timeout = HAL_MAX_DELAY;
public:
STM32I2cDevice(
I2C_HandleTypeDef* i2cHandle,
uint16_t address,
Mutex* mutex=nullptr,
bool master=false,
bool blocking=true
);
bool transmit(uint8_t* data, uint16_t size) override;
bool receive(uint8_t* data, uint16_t size) override;
bool deviceReady();
};
}
#endif // STA_STM32_I2C_ENABLED
#endif // STA_STM32_I2C_HPP