LoRaWANCH341 Library
|
Implementation of SPIInterface using Linux spidev. More...
#include <LinuxSPI.hpp>
Public Member Functions | |
LinuxSPI (const std::string &device="/dev/spidev0.0", uint32_t speed=1000000, uint8_t mode=0) | |
Constructs a new LinuxSPI object. | |
~LinuxSPI () | |
Destroys the LinuxSPI object. | |
bool | open () |
Opens the SPI device. | |
void | close () |
Closes the SPI device. | |
std::vector< uint8_t > | transfer (const std::vector< uint8_t > &write_data, size_t read_length=0) |
Transfers data over the SPI interface. | |
bool | digitalWrite (uint8_t pin, bool value) |
Sets the value of a GPIO pin. | |
bool | digitalRead (uint8_t pin) |
Reads the value of a GPIO pin. | |
bool | pinMode (uint8_t pin, uint8_t mode) |
Sets the mode of a GPIO pin. | |
bool | configureInterrupt (uint8_t pin, bool enable) override |
Configure interrupt settings for a GPIO pin. | |
bool | setInterruptCallback (InterruptCallback callback) override |
Set interrupt callback. | |
bool | enableInterrupt (bool enable) override |
Enable or disable interrupts. | |
bool | isActive () const override |
Check if the device is active/connected. | |
![]() | |
virtual | ~SPIInterface ()=default |
Private Member Functions | |
bool | exportGPIO (uint8_t pin) |
Exports a GPIO pin for use. | |
bool | unexportGPIO (uint8_t pin) |
Unexports a GPIO pin. | |
bool | setGPIODirection (uint8_t pin, const std::string &direction) |
Sets the direction of a GPIO pin. | |
bool | writeGPIOValue (uint8_t pin, bool value) |
Writes a value to a GPIO pin. | |
bool | readGPIOValue (uint8_t pin) |
Reads the value of a GPIO pin. | |
void | interruptThread () |
Private Attributes | |
std::string | device_path |
uint32_t | speed_hz |
uint8_t | spi_mode |
int | fd |
std::string | gpio_export_path |
std::string | gpio_unexport_path |
std::map< uint8_t, std::string > | gpio_pin_paths |
InterruptCallback | interruptCallback |
std::atomic< bool > | interrupt_running |
std::thread | interrupt_thread |
int | interrupt_pin |
InterruptCallback | interrupt_callback |
bool | interrupt_enabled = false |
Additional Inherited Members | |
![]() | |
using | InterruptCallback = std::function< void(void)> |
![]() | |
static constexpr uint8_t | INPUT = 0 |
static constexpr uint8_t | OUTPUT = 1 |
static constexpr uint8_t | INPUT_PULLUP = 2 |
Implementation of SPIInterface using Linux spidev.
This class provides an implementation of the SPIInterface using the spidev interface available in Linux. It allows communication with SPI devices and control of GPIO pins for interrupt handling.
device | The SPI device path (default: "/dev/spidev0.0"). |
speed | The SPI communication speed in Hz (default: 1,000,000 Hz). |
mode | The SPI mode (default: 0). |
A class to interface with SPI devices on Linux systems.
This class provides methods to open, close, and transfer data over an SPI interface, as well as control GPIO pins and handle interrupts.
LinuxSPI::LinuxSPI | ( | const std::string & | device = "/dev/spidev0.0" , |
uint32_t | speed = 1000000 , |
||
uint8_t | mode = 0 |
||
) |
Constructs a new LinuxSPI object.
device | The SPI device path (default is "/dev/spidev0.0"). |
speed | The SPI communication speed in Hz (default is 1,000,000 Hz). |
mode | The SPI mode (default is 0). |
LinuxSPI::~LinuxSPI | ( | ) |
|
virtual |
Closes the SPI device.
Implements SPIInterface.
|
inlineoverridevirtual |
Configure interrupt settings for a GPIO pin.
pin | The pin number |
enable | True to enable the interrupt, false to disable it |
Implements SPIInterface.
|
virtual |
Reads the value of a GPIO pin.
pin | The GPIO pin number. |
Implements SPIInterface.
|
virtual |
Sets the value of a GPIO pin.
pin | The GPIO pin number. |
value | The value to set (true for high, false for low). |
Implements SPIInterface.
|
overridevirtual |
Enable or disable interrupts.
enable | True to enable interrupts, false to disable them |
Implements SPIInterface.
|
private |
Exports a GPIO pin for use.
pin | The GPIO pin number. |
|
private |
|
inlineoverridevirtual |
Check if the device is active/connected.
Implements SPIInterface.
|
virtual |
Opens the SPI device.
Implements SPIInterface.
|
virtual |
Sets the mode of a GPIO pin.
pin | The GPIO pin number. |
mode | The mode to set (e.g., input or output). |
Implements SPIInterface.
|
private |
Reads the value of a GPIO pin.
pin | The GPIO pin number. |
|
private |
Sets the direction of a GPIO pin.
pin | The GPIO pin number. |
direction | The direction to set ("in" for input, "out" for output). |
|
overridevirtual |
Set interrupt callback.
callback | Function to call when interrupt occurs |
Implements SPIInterface.
|
virtual |
Transfers data over the SPI interface.
write_data | The data to be written to the SPI device. |
read_length | The number of bytes to read from the SPI device (default is 0). |
Implements SPIInterface.
|
private |
Unexports a GPIO pin.
pin | The GPIO pin number. |
|
private |
Writes a value to a GPIO pin.
pin | The GPIO pin number. |
value | The value to write (true for high, false for low). |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |