mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Merge branch 'merge-stm32' of gitlab.com:sta-git/avionics/stm32/libs/sta-core into merge-stm32
This commit is contained in:
commit
6f77eeaa7a
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
# IDE settings
|
||||
.settings/
|
||||
.vscode/
|
||||
|
||||
# Contain local paths
|
||||
.mxproject
|
||||
|
69
.vscode/settings.json
vendored
Normal file
69
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"__bit_reference": "cpp",
|
||||
"__bits": "cpp",
|
||||
"__config": "cpp",
|
||||
"__debug": "cpp",
|
||||
"__errc": "cpp",
|
||||
"__hash_table": "cpp",
|
||||
"__locale": "cpp",
|
||||
"__mutex_base": "cpp",
|
||||
"__node_handle": "cpp",
|
||||
"__nullptr": "cpp",
|
||||
"__split_buffer": "cpp",
|
||||
"__string": "cpp",
|
||||
"__threading_support": "cpp",
|
||||
"__tuple": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"bitset": "cpp",
|
||||
"cctype": "cpp",
|
||||
"chrono": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"complex": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"exception": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"ios": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"locale": "cpp",
|
||||
"memory": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"optional": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"variant": "cpp",
|
||||
"vector": "cpp",
|
||||
"__functional_base": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"utility": "cpp"
|
||||
}
|
||||
}
|
11
README.md
11
README.md
@ -96,6 +96,7 @@ Interfaces for the following resources are provided:
|
||||
* Signal
|
||||
* SPI
|
||||
* UART
|
||||
* I2C
|
||||
|
||||
|
||||
## HAL implementations
|
||||
@ -108,6 +109,16 @@ Implementations using the HAL are provided for the following interfaces:
|
||||
To enable these implementations follow the instructions from the individual headers.
|
||||
|
||||
|
||||
## Merge with STM32 Core
|
||||
|
||||
The merge with STM32 Core allows seamless usage of the STM32 implementations for the different Interfaces etc.
|
||||
Notable inclusions:
|
||||
* CAN
|
||||
* I2C
|
||||
* SPI
|
||||
* UART
|
||||
|
||||
|
||||
## Atomic implementations
|
||||
|
||||
Implementations using atomic variables are provided for the following interfaces:
|
||||
|
27
include/sta/i2c.hpp
Normal file
27
include/sta/i2c.hpp
Normal 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
39
include/sta/stm32/i2c.hpp
Normal 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
|
22
src/i2c.cpp
Normal file
22
src/i2c.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <sta/i2c.hpp>
|
||||
|
||||
namespace sta {
|
||||
I2cDevice::I2cDevice(uint16_t address_7bit, Mutex* mutex, bool master, bool blocking) {
|
||||
this->address = address_7bit << 1;
|
||||
this->mutex = mutex;
|
||||
this->master = master;
|
||||
this->blocking = blocking;
|
||||
}
|
||||
|
||||
void I2cDevice::acquire() {
|
||||
if (this->mutex != nullptr) {
|
||||
mutex->acquire();
|
||||
}
|
||||
}
|
||||
|
||||
void I2cDevice::release() {
|
||||
if (this->mutex != nullptr) {
|
||||
mutex->release();
|
||||
}
|
||||
}
|
||||
}
|
53
src/stm32/i2c.cpp
Normal file
53
src/stm32/i2c.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include <sta/stm32/i2c.hpp>
|
||||
|
||||
namespace sta {
|
||||
STM32I2cDevice::STM32I2cDevice(I2C_HandleTypeDef* i2cHandle, uint16_t address, Mutex* mutex, bool master, bool blocking)
|
||||
: I2cDevice(address, mutex, master, blocking) {
|
||||
this->master = master;
|
||||
}
|
||||
|
||||
bool STM32I2cDevice::transmit(uint8_t* data, uint16_t size) {
|
||||
HAL_StatusTypeDef res;
|
||||
|
||||
if (this->blocking) {
|
||||
if (!this->master) {
|
||||
res = HAL_I2C_Master_Transmit(i2cHandle, address, data, size, this->timeout);
|
||||
} else {
|
||||
res = HAL_I2C_Slave_Transmit(i2cHandle , data, size, this->timeout);
|
||||
}
|
||||
} else {
|
||||
if (!this->master) {
|
||||
res = HAL_I2C_Master_Transmit_IT(i2cHandle, address, data, size);
|
||||
} else {
|
||||
res = HAL_I2C_Slave_Transmit_IT(i2cHandle , data, size);
|
||||
}
|
||||
}
|
||||
|
||||
return res == HAL_OK;
|
||||
}
|
||||
|
||||
bool STM32I2cDevice::receive(uint8_t* data, uint16_t size) {
|
||||
HAL_StatusTypeDef res;
|
||||
|
||||
if (this->blocking) {
|
||||
if (!this->master) {
|
||||
res = HAL_I2C_Master_Receive(i2cHandle, address, data, size, this->timeout);
|
||||
} else {
|
||||
res = HAL_I2C_Slave_Receive(i2cHandle , data, size, this->timeout);
|
||||
}
|
||||
} else {
|
||||
if (!this->master) {
|
||||
res = HAL_I2C_Master_Receive_IT(i2cHandle, address, data, size);
|
||||
} else {
|
||||
res = HAL_I2C_Slave_Receive_IT(i2cHandle , data, size);
|
||||
}
|
||||
}
|
||||
|
||||
return res == HAL_OK;
|
||||
}
|
||||
|
||||
bool STM32I2cDevice::deviceReady() {
|
||||
HAL_StatusTypeDef res = HAL_I2C_IsDeviceReady(this->i2cHandle, this->address, 8, this->timeout);
|
||||
return res == HAL_OK;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user