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