mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Added gpio pin implementation for raspi
This commit is contained in:
parent
b2a92ea87e
commit
d2806f1651
@ -21,8 +21,8 @@ namespace sta
|
||||
*/
|
||||
enum class GpioPinState
|
||||
{
|
||||
LOW,
|
||||
HIGH
|
||||
GPIO_LOW,
|
||||
GPIO_HIGH
|
||||
};
|
||||
|
||||
/**
|
||||
|
42
include/sta/raspi/gpio_pin.hpp
Normal file
42
include/sta/raspi/gpio_pin.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef STA_CORE_RASPI_GPIO_PIN_HPP
|
||||
#define STA_CORE_RASPI_GPIO_PIN_HPP
|
||||
|
||||
// Only enable module on Raspi platform w/ HAL GPIO module enabled
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_PLATFORM_RASPI
|
||||
# include <sta/raspi/hal.hpp>
|
||||
# define STA_RASPI_GPIO_ENABLED
|
||||
#endif // STA_PLATFORM_RASPI
|
||||
|
||||
#if defined(STA_RASPI_GPIO_ENABLED) || defined(DOXYGEN)
|
||||
|
||||
#include <sta/gpio_pin.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
class RaspiGpioPin : GpioPin
|
||||
{
|
||||
public:
|
||||
enum class GpioMode {
|
||||
GPIO_OUTPUT,
|
||||
GPIO_INPUT
|
||||
};
|
||||
|
||||
/**
|
||||
* @param pin Pin index
|
||||
* @param mode The mode of the GPIO pin. Either INPUT or OUTPUT
|
||||
*/
|
||||
RaspiGpioPin(uint8_t pin, GpioMode mode);
|
||||
|
||||
void setState(GpioPinState state) override;
|
||||
|
||||
private:
|
||||
uint8_t pin_;
|
||||
GpioMode mode_;
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_RASPI_GPIO_ENABLED
|
||||
|
||||
#endif // STA_CORE_RASPI_GPIO_PIN_HPP
|
@ -1,13 +1,8 @@
|
||||
#ifndef STA_CORE_RASPI_HAL_HPP
|
||||
#define STA_CORE_RASPI_HAL_HPP
|
||||
|
||||
namespace sta {
|
||||
|
||||
B
|
||||
A
|
||||
A
|
||||
D
|
||||
D
|
||||
}
|
||||
#include <wiringPi.h>
|
||||
#include <wiringPiSPI.h>
|
||||
#include <wiringPiI2C.h>
|
||||
|
||||
#endif //STA_CORE_RASPI_HAL_HPP
|
||||
|
19
include/sta/raspi/spi.hpp
Normal file
19
include/sta/raspi/spi.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef STA_CORE_RASPI_SPI_HPP
|
||||
#define STA_CORE_RASPI_SPI_HPP
|
||||
|
||||
#include <sta/spi/device.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
class RaspiSPI : SPI
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class RaspiSPIDevice : SPIDevice
|
||||
{
|
||||
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_CORE_RASPI_HPP
|
21
src/raspi/gpio_pin.cpp
Normal file
21
src/raspi/gpio_pin.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <sta/raspi/gpio_pin.hpp>
|
||||
#ifdef STA_RASPI_GPIO_ENABLED
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/lang.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
RaspiGpioPin::RaspiGpioPin(uint8_t pin, GpioMode mode) : pin_{pin}, mode_{mode}
|
||||
{
|
||||
pinMode(pin, mode == GpioMode::GPIO_INPUT ? INPUT : OUTPUT);
|
||||
}
|
||||
|
||||
void RaspiGpioPin::setState(GpioPinState state)
|
||||
{
|
||||
digitalWrite(pin_, state == GpioPinState::GPIO_LOW ? LOW : HIGH);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_ARDUINO_GPIO_ENABLED
|
Loading…
x
Reference in New Issue
Block a user