ruuvi.drivers.c
${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
|
Interface for SPI operations. More...
#include "ruuvi_driver_enabled_modules.h"
#include "ruuvi_driver_error.h"
#include "ruuvi_interface_gpio.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | ri_spi_init_config_t |
Enumerations | |
enum | ri_spi_mode_t { RI_SPI_MODE_0 , RI_SPI_MODE_1 , RI_SPI_MODE_2 , RI_SPI_MODE_3 } |
enum | ri_spi_frequency_t { RI_SPI_FREQUENCY_1M , RI_SPI_FREQUENCY_2M , RI_SPI_FREQUENCY_4M , RI_SPI_FREQUENCY_8M } |
Functions | |
rd_status_t | ri_spi_init (const ri_spi_init_config_t *const config) |
Initialize SPI driver with given settings. More... | |
bool | ri_spi_is_init () |
check if SPI interface is already initialized. More... | |
rd_status_t | ri_spi_uninit () |
Uninitialize SPI driver. More... | |
rd_status_t | ri_spi_xfer_blocking (const uint8_t *const p_tx, const size_t tx_len, uint8_t *const p_rx, const size_t rx_len) |
SPI transfer function. More... | |
Interface for SPI operations.
Definition in file ruuvi_interface_spi.h.
enum ri_spi_frequency_t |
Clock speed
Enumerator | |
---|---|
RI_SPI_FREQUENCY_1M | 1 Mbps |
RI_SPI_FREQUENCY_2M | 2 Mbps |
RI_SPI_FREQUENCY_4M | 4 Mbps |
RI_SPI_FREQUENCY_8M | 8 Mbps |
Definition at line 43 of file ruuvi_interface_spi.h.
enum ri_spi_mode_t |
SPI modes. Defines clock polarity and phase
Enumerator | |
---|---|
RI_SPI_MODE_0 | CPOL = 0, CPHA = 0. |
RI_SPI_MODE_1 | CPOL = 0, CPHA = 1. |
RI_SPI_MODE_2 | CPOL = 1, CPHA = 0. |
RI_SPI_MODE_3 | CPOL = 1, CPHA = 1. |
Definition at line 32 of file ruuvi_interface_spi.h.
rd_status_t ri_spi_init | ( | const ri_spi_init_config_t *const | config | ) |
Initialize SPI driver with given settings.
This function also handles configuring the SS and SPI GPIO pins as outputs
config | Configuration of the SPI peripheral. Will setup given slave select pins as outputs. |
bool ri_spi_is_init | ( | ) |
check if SPI interface is already initialized.
true
if SPI is initialized false
otherwise rd_status_t ri_spi_uninit | ( | ) |
Uninitialize SPI driver.
This function might not uninitialize the SPI GPIO pins, only the underlying peripheral. Uninitialize GPIOs explicitly if that is required.
rd_status_t ri_spi_xfer_blocking | ( | const uint8_t *const | p_tx, |
const size_t | tx_len, | ||
uint8_t *const | p_rx, | ||
const size_t | rx_len | ||
) |
SPI transfer function.
Full-duplex SPI. Clocks out MAX(tx_len, rx_len)
bytes. It is allowed to send different length transactions, tx will clock out 0xFF
if there is less bytes in TX than RX. Does not use slave select pins. RX will start at the same time as TX, i.e. one byte address + read commands will generally have {0x00, data} in rx buffer. Function is blocking and will not sleep while transaction is ongoing.
p_tx | pointer to data to be sent, can be NULL if tx_len is 0. |
tx_len | length of data to be sent |
p_rx | pointer to data to be received, can be NULL if rx_len is 0. |
rx_len | length of data to be received |
0x00
if you're reading external sensor.