mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-12 01:25:59 +00:00
Fixed gpio pin implementation and SPI chip select
This commit is contained in:
parent
ec83b7026e
commit
5d1fef1b53
@ -24,8 +24,7 @@ namespace sta
|
||||
* @ingroup sta_core_spi
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief %SPI clock polarity.
|
||||
*/
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <sta/bus/spi/device.hpp>
|
||||
#include <sta/bus/spi/spi.hpp>
|
||||
|
||||
#include <sta/devices/arduino/gpio_pin.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
class ArduinoSPI : public SPI
|
||||
@ -31,7 +33,7 @@ namespace sta
|
||||
class ArduinoSPIDevice : public SPIDevice
|
||||
{
|
||||
public:
|
||||
ArduinoSPIDevice(ArduinoSPI * intf);
|
||||
ArduinoSPIDevice(ArduinoSPI * intf, ArduinoGpioPin * csPin);
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
@ -16,6 +16,16 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Describes the pin mode of the GPIO pin.
|
||||
*
|
||||
*/
|
||||
enum class PinMode
|
||||
{
|
||||
GPIO_INPUT,
|
||||
GPIO_OUTPUT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A wrapper class for Arduino GPIO pins.
|
||||
*
|
||||
@ -24,10 +34,11 @@ namespace sta
|
||||
class ArduinoGpioPin : public GpioPin
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param pin Pin index
|
||||
/**
|
||||
* @param pin Pin index
|
||||
* @param pinMode The pin mode
|
||||
*/
|
||||
ArduinoGpioPin(uint16_t pin);
|
||||
ArduinoGpioPin(uint16_t pin, PinMode mode);
|
||||
|
||||
void setState(GpioPinState state) override;
|
||||
|
||||
|
@ -15,7 +15,6 @@ namespace sta
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief GPIO pin state.
|
||||
*/
|
||||
|
@ -54,6 +54,8 @@ namespace sta
|
||||
|
||||
void ArduinoSPI::acquire()
|
||||
{
|
||||
SPI::acquire();
|
||||
|
||||
const SPISettings & set = settings();
|
||||
|
||||
uint8_t dataMode;
|
||||
@ -98,5 +100,13 @@ namespace sta
|
||||
void ArduinoSPI::release()
|
||||
{
|
||||
SPIClass::endTransaction();
|
||||
|
||||
SPI::release();
|
||||
}
|
||||
|
||||
ArduinoSPIDevice::ArduinoSPIDevice(ArduinoSPI * intf, ArduinoGpioPin * csPin)
|
||||
: SPIDevice{intf, csPin}
|
||||
{
|
||||
csPin->setState(GpioPinState::GPIO_HIGH);
|
||||
}
|
||||
} // namespace sta
|
||||
|
@ -6,7 +6,11 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
ArduinoGpioPin::ArduinoGpioPin(uint16_t pin) : pin_{pin} { }
|
||||
ArduinoGpioPin::ArduinoGpioPin(uint16_t pin, PinMode mode)
|
||||
: pin_{pin}
|
||||
{
|
||||
pinMode(pin, (mode == PinMode::GPIO_OUTPUT) ? OUTPUT : INPUT);
|
||||
}
|
||||
|
||||
void ArduinoGpioPin::setState(GpioPinState state)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user