ruuvi.drivers.c ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
Loading...
Searching...
No Matches
ruuvi_interface_spi_dps310.c
Go to the documentation of this file.
7#include <stdint.h>
8
9#if RI_DPS310_SPI_ENABLED
10
11uint32_t ri_spi_dps310_write (const void * const comm_ctx, const uint8_t reg_addr,
12 const uint8_t * const data, const uint8_t data_len)
13{
14 rd_status_t err_code = RD_SUCCESS;
15 ri_gpio_id_t ss = * (ri_gpio_id_t *) comm_ctx;
16 ss = RD_HANDLE_TO_GPIO (ss);
17 err_code |= ri_gpio_write (ss, RI_GPIO_LOW);
18 err_code |= ri_spi_xfer_blocking (&reg_addr, 1, NULL, 0);
19 err_code |= ri_spi_xfer_blocking (data, data_len, NULL, 0);
20 err_code |= ri_gpio_write (ss, RI_GPIO_HIGH);
21 return err_code;
22}
23
24uint32_t ri_spi_dps310_read (const void * const comm_ctx, const uint8_t reg_addr,
25 uint8_t * const data, const uint8_t data_len)
26{
27 rd_status_t err_code = RD_SUCCESS;
28 ri_gpio_id_t ss = * (ri_gpio_id_t *) comm_ctx;
29 uint8_t read_cmd = reg_addr | 0x80;
30 ss = RD_HANDLE_TO_GPIO (ss);
31 err_code |= ri_gpio_write (ss, RI_GPIO_LOW);
32 err_code |= ri_spi_xfer_blocking (&read_cmd, 1, NULL, 0);
33 err_code |= ri_spi_xfer_blocking (NULL, 0, data, data_len);
34 err_code |= ri_gpio_write (ss, RI_GPIO_HIGH);
35 return err_code;
36}
37
38#endif
uint32_t rd_status_t
bitfield for representing errors
#define RD_SUCCESS
Internal Error.
rd_status_t ri_gpio_write(const ri_gpio_id_t pin, const ri_gpio_state_t state)
Write a pin of a port into given state If there are several ports the platform driver must implement ...
uint32_t ri_spi_dps310_read(const void *const comm_ctx, const uint8_t reg_addr, uint8_t *const p_reg_data, const uint8_t data_len)
SPI Read function for DPS310.
uint32_t ri_spi_dps310_write(const void *const comm_ctx, const uint8_t reg_addr, const uint8_t *const p_reg_data, const uint8_t data_len)
SPI write function for DPS310.
#define RD_HANDLE_TO_GPIO(handle)
convert uint8_t into Ruuvi GPIO
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Ruuvi sensor interface Lifecycle: Beta
uint16_t ri_gpio_id_t
port<<8 + pin
@ RI_GPIO_LOW
GPIO electrically low.
@ RI_GPIO_HIGH
GPIO electrically high.
Interface for SPI operations.
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.
SPI read/write functions for Infineon DPS310.