mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Merge branch 'raspi-support' of ssh://git.intern.spaceteamaachen.de:22222/ALPAKA/sta-core into raspi-support
This commit is contained in:
commit
3259a98f11
@ -18,11 +18,10 @@ namespace sta
|
||||
* @param intf %I2C hardware interface
|
||||
* @param csPin The peripheral's address.
|
||||
*/
|
||||
I2CDevice(I2C * intf, int address, bool master=false, bool blocking=true);
|
||||
I2CDevice(I2C * intf, int address, bool master=true, bool blocking=true);
|
||||
|
||||
protected:
|
||||
void select() override;
|
||||
|
||||
void deselect() override;
|
||||
|
||||
private:
|
||||
|
@ -1,7 +1,8 @@
|
||||
#ifndef STA_CONFIG_HPP
|
||||
#define STA_CONFIG_HPP
|
||||
|
||||
#include <sta/devices/stm32/mcu/STM32F411xE.hpp>
|
||||
// #include <sta/devices/stm32/mcu/STM32F411xE.hpp>
|
||||
#include <sta/devices/raspi/mcu/common.hpp>
|
||||
|
||||
#define STA_DEBUGGING_ENABLED
|
||||
#define STA_PRINTF_USE_STDLIB
|
||||
|
@ -28,6 +28,7 @@ namespace sta
|
||||
void transfer(const uint8_t * buffer, size_t size) override;
|
||||
void receive(uint8_t * buffer, size_t size) override;
|
||||
|
||||
void selectAddress();
|
||||
void acquire() override;
|
||||
void release() override;
|
||||
|
||||
@ -41,7 +42,8 @@ namespace sta
|
||||
|
||||
class RaspiI2CDevice : public I2CDevice
|
||||
{
|
||||
RaspiI2CDevice(RaspiI2C * intf, uint16_t address_10bit, Mutex* mutex=nullptr, bool master=false, bool blocking=true);
|
||||
public:
|
||||
RaspiI2CDevice(RaspiI2C * intf, uint16_t address_10bit, bool master=true, bool blocking=true);
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
@ -12,16 +12,14 @@ namespace sta
|
||||
|
||||
void Interface::acquire()
|
||||
{
|
||||
if (mutex_ != nullptr)
|
||||
mutex_->acquire();
|
||||
acquired_ = true;
|
||||
mutex_->acquire();
|
||||
acquired_ = true;
|
||||
}
|
||||
|
||||
void Interface::release()
|
||||
{
|
||||
if (mutex_ != nullptr)
|
||||
acquired_ = false;
|
||||
mutex_->release();
|
||||
mutex_->release();
|
||||
acquired_ = false;
|
||||
}
|
||||
|
||||
bool Interface::isAcquired()
|
||||
|
@ -3,6 +3,7 @@
|
||||
#ifdef STA_PLATFORM_RASPI
|
||||
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <sta/debug/debug.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string.h>
|
||||
@ -11,6 +12,7 @@
|
||||
#include <linux/i2c-dev.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
@ -41,46 +43,67 @@ namespace sta
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
write(i2cfd_, &value, 1);
|
||||
selectAddress();
|
||||
ssize_t n_out = write(i2cfd_, &value, 1);
|
||||
|
||||
STA_ASSERT(n_out == 1);
|
||||
}
|
||||
|
||||
void RaspiI2C::transfer16(uint16_t value)
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
write(i2cfd_, &value, 2);
|
||||
selectAddress();
|
||||
ssize_t n_out = write(i2cfd_, &value, 2);
|
||||
|
||||
STA_ASSERT(n_out == 2);
|
||||
}
|
||||
|
||||
void RaspiI2C::transfer(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
write(i2cfd_, buffer, size);
|
||||
selectAddress();
|
||||
ssize_t n_out = write(i2cfd_, buffer, size);
|
||||
|
||||
STA_ASSERT(n_out == size);
|
||||
}
|
||||
|
||||
void RaspiI2C::receive(uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
if (read(i2cfd_, buffer, size) <= 0)
|
||||
{
|
||||
printf("Error while reading i2c bus.");
|
||||
}
|
||||
selectAddress();
|
||||
ssize_t n_in = read(i2cfd_, buffer, size);
|
||||
|
||||
STA_ASSERT(n_in >= 0);
|
||||
}
|
||||
|
||||
void RaspiI2C::fill(uint8_t value, size_t count)
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
selectAddress();
|
||||
|
||||
// Initialize a buffer of size count and fill it with the value.
|
||||
uint8_t *buffer = new uint8_t[count];
|
||||
memset(buffer, value, count);
|
||||
|
||||
write(i2cfd_, buffer, count);
|
||||
ssize_t n_out = write(i2cfd_, buffer, count);
|
||||
|
||||
STA_ASSERT(n_out == count);
|
||||
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
void RaspiI2C::selectAddress()
|
||||
{
|
||||
// Select the slave with the given address.
|
||||
int rslt = ioctl(i2cfd_, I2C_SLAVE, address_);
|
||||
|
||||
STA_ASSERT(rslt != -1);
|
||||
}
|
||||
|
||||
void RaspiI2C::acquire()
|
||||
{
|
||||
I2C::acquire();
|
||||
@ -99,16 +122,19 @@ namespace sta
|
||||
{
|
||||
if (!persistent_open_ && open_) {
|
||||
close(i2cfd_);
|
||||
open_ = false;
|
||||
}
|
||||
|
||||
I2C::release();
|
||||
}
|
||||
|
||||
RaspiI2CDevice::RaspiI2CDevice(RaspiI2C * intf, uint16_t address_10bit, Mutex* mutex, bool master, bool blocking)
|
||||
: I2CDevice { intf, address_10bit }
|
||||
RaspiI2CDevice::RaspiI2CDevice(RaspiI2C * intf, uint16_t address_10bit, bool master, bool blocking)
|
||||
: I2CDevice { intf, address_10bit, master, blocking }
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_PLATFORM_RASPI
|
||||
|
Loading…
x
Reference in New Issue
Block a user