ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_interface_spi_bme280.c
Go to the documentation of this file.
2 #if (RI_BME280_ENABLED && RI_BME280_SPI_ENABLED) || DOXYGEN
17 #include <stdint.h>
18 #include <string.h>
19 
20 #include "ruuvi_driver_error.h"
21 #include "ruuvi_driver_sensor.h"
22 #include "ruuvi_interface_gpio.h"
23 #include "ruuvi_interface_spi.h"
24 #include "ruuvi_interface_yield.h"
25 
26 
27 int8_t ri_spi_bme280_write (uint8_t dev_id, uint8_t reg_addr,
28  uint8_t * reg_data, uint16_t len)
29 {
30  rd_status_t err_code = RD_SUCCESS;
31  ri_gpio_id_t ss;
32  ss = RD_HANDLE_TO_GPIO (dev_id);
33  err_code |= ri_gpio_write (ss, RI_GPIO_LOW);
34  err_code |= ri_spi_xfer_blocking (&reg_addr, 1, NULL, 0);
35  err_code |= ri_spi_xfer_blocking (reg_data, len, NULL, 0);
36  err_code |= ri_gpio_write (ss, RI_GPIO_HIGH);
37  return (RD_SUCCESS == err_code) ? 0 : -1;
38 }
39 
40 int8_t ri_spi_bme280_read (uint8_t dev_id, uint8_t reg_addr,
41  uint8_t * reg_data, uint16_t len)
42 {
43  rd_status_t err_code = RD_SUCCESS;
44  ri_gpio_id_t ss;
45  ss = RD_HANDLE_TO_GPIO (dev_id);
46  err_code |= ri_gpio_write (ss, RI_GPIO_LOW);
47  err_code |= ri_spi_xfer_blocking (&reg_addr, 1, NULL, 0);
48  err_code |= ri_spi_xfer_blocking (NULL, 0, reg_data, len);
49  err_code |= ri_gpio_write (ss, RI_GPIO_HIGH);
50  return (RD_SUCCESS == err_code) ? 0 : -1;
51 }
53 #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 ...
int8_t ri_spi_bme280_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
SPI write function for BME280.
int8_t ri_spi_bme280_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
SPI Read function for BME280.
#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.