mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Added first implementations for Arduino
This commit is contained in:
parent
e7ddbbf365
commit
8c5f0a3f29
36
include/sta/devices/arduino/bus/i2c.hpp
Normal file
36
include/sta/devices/arduino/bus/i2c.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef STA_CORE_ARDUINO_I2C_HPP
|
||||
#define STA_CORE_ARDUINO_I2C_HPP
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_PLATFORM_ARDUINO
|
||||
|
||||
#include <sta/bus/i2c/device.hpp>
|
||||
#include <sta/bus/i2c/i2c.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
class ArduinoI2C : public I2C
|
||||
{
|
||||
public:
|
||||
ArduinoI2C(Mutex * mutex=nullptr, uint16_t address);
|
||||
|
||||
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;
|
||||
|
||||
void acquire();
|
||||
void release();
|
||||
};
|
||||
|
||||
class ArduinoI2CDevice : public I2CDevice
|
||||
{
|
||||
public:
|
||||
ArduinoI2CDevice(I2C * intf, int address, bool master=false, bool blocking=true);
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_PLATFORM_ARDUINO
|
||||
|
||||
#endif // STA_CORE_ARDUINO_I2C_HPP
|
0
include/sta/devices/arduino/bus/spi.hpp
Normal file
0
include/sta/devices/arduino/bus/spi.hpp
Normal file
28
include/sta/devices/arduino/delay.hpp
Normal file
28
include/sta/devices/arduino/delay.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef STA_CORE_ARDUINO_DELAY_HPP
|
||||
#define STA_CORE_ARDUINO_DELAY_HPP
|
||||
|
||||
// Only enable module on Arduino platform
|
||||
#include <sta/config.hpp>
|
||||
|
||||
#if defined(STA_PLATFORM_ARDUINO) || defined(DOXYGEN)
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Millisecond delay.
|
||||
*
|
||||
* @param ms Milliseconds
|
||||
*/
|
||||
void delayMs(uint32_t ms);
|
||||
|
||||
/**
|
||||
* @brief Microsecond delay.
|
||||
*
|
||||
* @param us Microseconds
|
||||
*/
|
||||
void delayUs(uint32_t us);
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_PLATFORM_ARDUINO
|
||||
|
||||
#endif // STA_CORE_ARDUINO_DELAY_HPP
|
44
include/sta/devices/arduino/gpio_pin.hpp
Normal file
44
include/sta/devices/arduino/gpio_pin.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Wrapper for Arduino GPIO pins.
|
||||
*/
|
||||
#ifndef STA_CORE_ARDUINO_GPIO_PIN_HPP
|
||||
#define STA_CORE_ARDUINO_GPIO_PIN_HPP
|
||||
|
||||
// Only enable module on Arduino platform w/ HAL GPIO module enabled
|
||||
#include <sta/config.hpp>
|
||||
|
||||
#if defined(STA_PLATFORM_ARDUINO) || defined(DOXYGEN)
|
||||
|
||||
#include <sta/gpio_pin.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
class ArduinoGpioPin : public GpioPin
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param port GPIO port
|
||||
* @param pin Pin index
|
||||
*/
|
||||
ArduinoGpioPin(uint16_t pin);
|
||||
|
||||
void setState(GpioPinState state) override;
|
||||
|
||||
GpioPinState getState() override;
|
||||
|
||||
/**
|
||||
* @brief Get pin index for pin.
|
||||
*
|
||||
* @return Pin index
|
||||
*/
|
||||
uint16_t getPin() const;
|
||||
private:
|
||||
uint16_t pin_; /**< GPIO pin */
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_ARDUINO_GPIO_ENABLED
|
||||
|
||||
#endif // STA_CORE_ARDUINO_GPIO_PIN_HPP
|
8
include/sta/devices/arduino/hal.hpp
Normal file
8
include/sta/devices/arduino/hal.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef STA_CORE_ARDUINO_HAL_HPP
|
||||
#define STA_CORE_ARDUINO_HAL_HPP
|
||||
|
||||
#include<Arduino.h>
|
||||
#include<Wire.h>
|
||||
#include<SPI.h>
|
||||
|
||||
#endif // STA_CORE_ARDUINO_HAL_HPP
|
7
include/sta/devices/arduino/mcu/common.hpp
Normal file
7
include/sta/devices/arduino/mcu/common.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef STA_CORE_ARDUINO_MCU_COMMON_HPP
|
||||
#define STA_CORE_ARDUINO_MCU_COMMON_HPP
|
||||
|
||||
// Enable Arduino platform
|
||||
#define STA_PLATFORM_ARDUINO
|
||||
|
||||
#endif // STA_CORE_ARDUINO_MCU_COMMON_HPP
|
6
include/sta/devices/arduino/mcu/uno_r3.hpp
Normal file
6
include/sta/devices/arduino/mcu/uno_r3.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef STA_CORE_ARDUINO_MCU_UNO_R3_HPP
|
||||
#define STA_CORE_ARDUINO_MCU_UNO_R3_HPP
|
||||
|
||||
#include <sta/devices/arduino/mcu/common.hpp>
|
||||
|
||||
#endif // STA_CORE_ARDUINO_MCU_UNO_R3_HPPs
|
@ -1,12 +0,0 @@
|
||||
#ifndef STA_CORE_ARDUINO_NOT_IMPLEMENTED_HPP
|
||||
#define STA_CORE_ARDUINO_NOT_IMPLEMENTED_HPP
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup sta_core_arduino Arduino
|
||||
* @ingroup sta_core_platforms
|
||||
* @brief Modules implemented for the Arduino platform.
|
||||
*/
|
||||
|
||||
|
||||
#endif // STA_CORE_ARDUINO_NOT_IMPLEMENTED_HPP
|
68
src/devices/arduino/bus/i2c.cpp
Normal file
68
src/devices/arduino/bus/i2c.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include <sta/devices/arduino/bus/i2c.hpp>
|
||||
|
||||
#ifdef STA_PLATFORM_ARDUINO
|
||||
|
||||
#include <sta/devices/arduino/hal.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
ArduinoI2C::ArduinoI2C(Mutex * mutex, uint16_t address)
|
||||
: I2C{mutex}
|
||||
{
|
||||
Wire.begin(address);
|
||||
}
|
||||
|
||||
void ArduinoI2C::transfer16(uint16_t value)
|
||||
{
|
||||
Wire.write(value);
|
||||
}
|
||||
|
||||
void ArduinoI2C::transfer(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
Wire.write(buffer, size);
|
||||
}
|
||||
|
||||
void ArduinoI2C::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size)
|
||||
{
|
||||
// NOT REALLY A THING HERE, IS IT?
|
||||
}
|
||||
|
||||
void ArduinoI2C::receive(uint8_t * buffer, size_t size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ArduinoI2C::fill(uint8_t value, size_t count)
|
||||
{
|
||||
// Initialize a buffer of size count and fill it with the value.
|
||||
uint8_t *buffer = new uint8_t[count];
|
||||
memset(buffer, value, count);
|
||||
|
||||
Serial.write(buffer, count);
|
||||
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
void ArduinoI2C::acquire()
|
||||
{
|
||||
I2C::acquire();
|
||||
|
||||
Wire.beginTransmission(address_);
|
||||
}
|
||||
|
||||
void ArduinoI2C::release()
|
||||
{
|
||||
Wire.endTransmission();
|
||||
|
||||
I2C::release();
|
||||
}
|
||||
|
||||
ArduinoI2CDevice::ArduinoI2CDevice(I2C * intf, int address, bool master, bool blocking)
|
||||
: I2CDevice{intf, address, master, blocking}
|
||||
{
|
||||
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_PLATFORM_ARDUINO
|
0
src/devices/arduino/bus/spi.cpp
Normal file
0
src/devices/arduino/bus/spi.cpp
Normal file
20
src/devices/arduino/delay.cpp
Normal file
20
src/devices/arduino/delay.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include <sta/devices/arduino/delay.hpp>
|
||||
|
||||
#ifdef STA_PLATFORM_ARDUINO
|
||||
|
||||
#include <sta/devices/arduino/hal.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
void delayMs(uint32_t ms)
|
||||
{
|
||||
delay(ms);
|
||||
}
|
||||
|
||||
void delayUs(uint32_t us)
|
||||
{
|
||||
delayMicroseconds(us);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_PLATFORM_ARDUINO
|
28
src/devices/arduino/gpio_pin.cpp
Normal file
28
src/devices/arduino/gpio_pin.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <sta/devices/arduino/gpio_pin.hpp>
|
||||
|
||||
#ifdef STA_PLATFORM_ARDUINO
|
||||
|
||||
#include <sta/devices/arduino/hal.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
ArduinoGpioPin::ArduinoGpioPin(uint16_t pin) : pin_{pin} { }
|
||||
|
||||
void ArduinoGpioPin::setState(GpioPinState state)
|
||||
{
|
||||
digitalWrite(pin_, (state == GpioPinState::GPIO_LOW) ? LOW : HIGH);
|
||||
}
|
||||
|
||||
GpioPinState ArduinoGpioPin::getState()
|
||||
{
|
||||
return digitalRead(pin_) == HIGH ? GpioPinState::GPIO_HIGH : GpioPinState::GPIO_LOW;
|
||||
}
|
||||
|
||||
uint16_t ArduinoGpioPin::getPin() const
|
||||
{
|
||||
return pin_;
|
||||
}
|
||||
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_PLATFORM_ARDUINO
|
Loading…
x
Reference in New Issue
Block a user