Fixed broken imports after dir structure rework & added stm32 i2c

This commit is contained in:
dvdb97
2023-06-24 15:44:56 +02:00
parent 6b4acfd27b
commit e7ddbbf365
26 changed files with 224 additions and 150 deletions

View File

@@ -11,22 +11,25 @@ namespace sta
*
* @ingroup sta_core_i2c
*/
class I2cDevice : public Device
class I2CDevice : public Device
{
public:
/**
* @param intf %I2C hardware interface
* @param csPin The peripheral's address.
*/
I2cDevice(I2c * intf, int addr);
I2CDevice(I2C * intf, int address, bool master=false, bool blocking=true);
protected:
void select() override;
void deselect() override;
private:
int addr_; /**< device address */
I2C * intf_;
int address_; /**< device address */
int master_;
int blocking_;
};
} // namespace sta
@@ -34,4 +37,4 @@ namespace sta
#endif // STA_CORE_I2C_DEVICE_HPP
#endif // STA_CORE_I2C_DEVICE_HPP

View File

@@ -16,18 +16,24 @@ namespace sta
*
* @ingroup sta_core_i2c
*/
class I2c : public Interface
class I2C : public Interface
{
public:
I2c(Mutex * mutex=nullptr);
I2C(Mutex * mutex=nullptr);
/**
* @brief Address selection for the I2C bus.
*
* @param address The address to select.
* @brief Specify the mode of communication via the bus.
*
* @param master
* @param blocking
*/
virtual void selectAddress(uint16_t address) = 0;
void setSettings(uint16_t address, bool master, bool blocking);
protected:
uint16_t address_;
bool master_;
bool blocking_;
};
} // namespace sta
#endif // STA_CORE_I2C_I2C_HPP
#endif // STA_CORE_I2C_I2C_HPP

View File

@@ -83,4 +83,4 @@ namespace sta
} // namespace sta
#endif // STA_CORE_BUS_SERIAL_INTERFACE_HPP
#endif // STA_CORE_BUS_SERIAL_INTERFACE_HPP

View File

@@ -1,11 +0,0 @@
#ifndef STA_CONFIG
#define STA_CONFIG
// Use the raspberry pi for this project.
#include <sta/devices/raspi/mcu/common.hpp>
// #define DEBUG
#define STA_PRINTF_USE_STDLIB
#define STA_DEBUG_PRINTF
#endif

View File

@@ -0,0 +1,44 @@
#ifndef STA_CORE_STM32_I2C_HPP
#define STA_CORE_STM32_I2C_HPP
#include <sta/config.hpp>
#ifdef STA_PLATFORM_STM32
# include <sta/devices/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/bus/i2c/i2c.hpp>
#include <sta/bus/i2c/device.hpp>
namespace sta
{
class STM32I2C : public I2C
{
public:
STM32I2C(I2C_HandleTypeDef * handle, Mutex * mutex=nullptr);
void transfer(uint8_t value) override;
void transfer16(uint16_t value) override;
void transfer(const uint8_t * buffer, size_t size) override;
void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) override;
void receive(uint8_t * buffer, size_t size) override;
void fill(uint8_t value, size_t count) override;
private:
I2C_HandleTypeDef * handle_;
const uint32_t timeout_ = HAL_MAX_DELAY;
};
class STM32I2CDevice : public I2CDevice
{
STM32I2CDevice();
};
}
#endif // STA_STM32_I2C_ENABLED
#endif // STA_CORE_STM32_I2C_HPP

View File

@@ -19,7 +19,7 @@
// Only enable module on STM32 platform w/ HAL CAN module enabled
#include <sta/config.hpp>
#ifdef STA_PLATFORM_STM32
# include <sta/stm32/hal.hpp>
# include <sta/devices/stm32/hal.hpp>
# ifdef HAL_CAN_MODULE_ENABLED
# define STA_STM32_CAN_ENABLED
# endif // HAL_CAN_MODULE_ENABLED

View File

@@ -12,7 +12,7 @@
#if defined(STA_PLATFORM_STM32) || defined(DOXYGEN)
#include <sta/stm32/hal.hpp>
#include <sta/devices/stm32/hal.hpp>
/**

View File

@@ -9,7 +9,7 @@
// Only enable module on STM32 platform w/ HAL GPIO module enabled
#include <sta/config.hpp>
#ifdef STA_PLATFORM_STM32
# include <sta/stm32/hal.hpp>
# include <sta/devices/stm32/hal.hpp>
# ifdef HAL_GPIO_MODULE_ENABLED
# define STA_STM32_GPIO_ENABLED
# endif // HAL_GPIO_MODULE_ENABLED

View File

@@ -1,39 +0,0 @@
#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

View File

@@ -11,7 +11,7 @@
#endif // !STM32F411xE
#include <sta/stm32/mcu/common.hpp>
#include <sta/devices/stm32/mcu/common.hpp>
// Peripheral clock mappings

View File

@@ -9,7 +9,7 @@
// Only enable module on STM32 platform w/ HAL SPI module enabled
#include <sta/config.hpp>
#ifdef STA_PLATFORM_STM32
# include <sta/stm32/hal.hpp>
# include <sta/devices/stm32/hal.hpp>
# ifndef HAL_GPIO_MODULE_ENABLED
# error "STM32 GPIO module required!"
# endif // !HAL_GPIO_MODULE_ENABLED

View File

@@ -9,7 +9,7 @@
// Only enable module on STM32 platform w/ HAL UART module enabled
#include <sta/config.hpp>
#ifdef STA_PLATFORM_STM32
# include <sta/stm32/hal.hpp>
# include <sta/devices/stm32/hal.hpp>
# ifdef HAL_UART_MODULE_ENABLED
# define STA_STM32_UART_ENABLED
# endif // HAL_UART_MODULE_ENABLED

View File

@@ -100,7 +100,7 @@
* crash with the appropriate error message if the code is executed.
*/
#ifndef STA_NOT_IMPLEMENTED
# define STA_NOT_IMPLEMENTED() throw "myFunction is not implemented yet.";
# define STA_NOT_IMPLEMENTED() // throw "myFunction is not implemented yet.";
#endif // !STA_NOT_IMPLEMENTED
/**