ruuvi.drivers.c ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
Loading...
Searching...
No Matches
ruuvi_interface_i2c_shtcx.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018, Sensirion AG
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * * Neither the name of Sensirion AG nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
33#if RI_SHTCX_ENABLED || DOXYGEN
34#include "ruuvi_driver_error.h"
35#include "ruuvi_interface_i2c.h"
37#include "sensirion_arch_config.h"
38#include "sensirion_common.h"
39#include "sensirion_i2c.h"
40#include "shtc1.h"
41#include <string.h>
42
43
44/*
45 * INSTRUCTIONS
46 * ============
47 *
48 * Implement all functions where they are marked as IMPLEMENT.
49 * Follow the function specification in the comments.
50 */
51
62int16_t sensirion_i2c_select_bus (uint8_t bus_idx)
63{
64 // IMPLEMENT or leave empty if all sensors are located on one single bus
66 return 0;
67}
68
76
81{
82 // IMPLEMENT or leave empty if no resources need to be freed
84}
85
96int8_t sensirion_i2c_read (uint8_t address, uint8_t * data, uint16_t count)
97{
98 rd_status_t err_code = RD_SUCCESS;
99 err_code |= ri_i2c_read_blocking (address, data, count);
100 return (RD_SUCCESS == err_code) ? 0 : -STATUS_ERR_BAD_DATA;
101}
102
114int8_t sensirion_i2c_write (uint8_t address, const uint8_t * data, uint16_t count)
115{
116 rd_status_t err_code = RD_SUCCESS;
117 // Drop const qualification to match Nordic lib signature.
118 // write_blocking does not alter contents of data.
119 err_code |= ri_i2c_write_blocking (address, (uint8_t *) data, count, true);
120 return (RD_SUCCESS == err_code) ? 0 : STATUS_ERR_BAD_DATA;
121}
122
123#endif
#define RD_ERROR_FATAL
Program should always reset after this.
uint32_t rd_status_t
bitfield for representing errors
#define RD_ERROR_CHECK(error, mask)
Shorthand macro for calling the rd_error_check with current file & line.
#define RD_ERROR_NOT_SUPPORTED
Not supported.
#define RD_SUCCESS
Internal Error.
#define STATUS_ERR_BAD_DATA
SHTC driver data invald.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Interface for I2C operations.
rd_status_t ri_i2c_write_blocking(const uint8_t address, uint8_t *const p_tx, const size_t tx_len, const bool stop)
I2C read function.
rd_status_t ri_i2c_read_blocking(const uint8_t address, uint8_t *const p_rx, const size_t rx_len)
I2C read function.
int8_t sensirion_i2c_write(uint8_t address, const uint8_t *data, uint16_t count)
int8_t sensirion_i2c_read(uint8_t address, uint8_t *data, uint16_t count)
void sensirion_i2c_init(void)
void sensirion_i2c_release(void)
int16_t sensirion_i2c_select_bus(uint8_t bus_idx)