mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-13 01:55: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
|
* @ingroup sta_core_spi
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief %SPI clock polarity.
|
* @brief %SPI clock polarity.
|
||||||
*/
|
*/
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <sta/bus/spi/device.hpp>
|
#include <sta/bus/spi/device.hpp>
|
||||||
#include <sta/bus/spi/spi.hpp>
|
#include <sta/bus/spi/spi.hpp>
|
||||||
|
|
||||||
|
#include <sta/devices/arduino/gpio_pin.hpp>
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
class ArduinoSPI : public SPI
|
class ArduinoSPI : public SPI
|
||||||
@ -31,7 +33,7 @@ namespace sta
|
|||||||
class ArduinoSPIDevice : public SPIDevice
|
class ArduinoSPIDevice : public SPIDevice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ArduinoSPIDevice(ArduinoSPI * intf);
|
ArduinoSPIDevice(ArduinoSPI * intf, ArduinoGpioPin * csPin);
|
||||||
};
|
};
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
@ -16,6 +16,16 @@
|
|||||||
|
|
||||||
namespace sta
|
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.
|
* @brief A wrapper class for Arduino GPIO pins.
|
||||||
*
|
*
|
||||||
@ -24,10 +34,11 @@ namespace sta
|
|||||||
class ArduinoGpioPin : public GpioPin
|
class ArduinoGpioPin : public GpioPin
|
||||||
{
|
{
|
||||||
public:
|
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;
|
void setState(GpioPinState state) override;
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ namespace sta
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief GPIO pin state.
|
* @brief GPIO pin state.
|
||||||
*/
|
*/
|
||||||
|
@ -54,6 +54,8 @@ namespace sta
|
|||||||
|
|
||||||
void ArduinoSPI::acquire()
|
void ArduinoSPI::acquire()
|
||||||
{
|
{
|
||||||
|
SPI::acquire();
|
||||||
|
|
||||||
const SPISettings & set = settings();
|
const SPISettings & set = settings();
|
||||||
|
|
||||||
uint8_t dataMode;
|
uint8_t dataMode;
|
||||||
@ -98,5 +100,13 @@ namespace sta
|
|||||||
void ArduinoSPI::release()
|
void ArduinoSPI::release()
|
||||||
{
|
{
|
||||||
SPIClass::endTransaction();
|
SPIClass::endTransaction();
|
||||||
|
|
||||||
|
SPI::release();
|
||||||
|
}
|
||||||
|
|
||||||
|
ArduinoSPIDevice::ArduinoSPIDevice(ArduinoSPI * intf, ArduinoGpioPin * csPin)
|
||||||
|
: SPIDevice{intf, csPin}
|
||||||
|
{
|
||||||
|
csPin->setState(GpioPinState::GPIO_HIGH);
|
||||||
}
|
}
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
@ -6,7 +6,11 @@
|
|||||||
|
|
||||||
namespace sta
|
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)
|
void ArduinoGpioPin::setState(GpioPinState state)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user