Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
sensirion/sensirion_i2c.h@1:7d24c69d9a0e, 2021-08-16 (annotated)
- Committer:
- Picard22
- Date:
- Mon Aug 16 13:35:58 2021 +0000
- Revision:
- 1:7d24c69d9a0e
- Parent:
- 0:c8ecd653066c
revision_with_med_lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Picard22 | 0:c8ecd653066c | 1 | /* |
Picard22 | 0:c8ecd653066c | 2 | * Copyright (c) 2018, Sensirion AG |
Picard22 | 0:c8ecd653066c | 3 | * All rights reserved. |
Picard22 | 0:c8ecd653066c | 4 | * |
Picard22 | 0:c8ecd653066c | 5 | * Redistribution and use in source and binary forms, with or without |
Picard22 | 0:c8ecd653066c | 6 | * modification, are permitted provided that the following conditions are met: |
Picard22 | 0:c8ecd653066c | 7 | * |
Picard22 | 0:c8ecd653066c | 8 | * * Redistributions of source code must retain the above copyright notice, this |
Picard22 | 0:c8ecd653066c | 9 | * list of conditions and the following disclaimer. |
Picard22 | 0:c8ecd653066c | 10 | * |
Picard22 | 0:c8ecd653066c | 11 | * * Redistributions in binary form must reproduce the above copyright notice, |
Picard22 | 0:c8ecd653066c | 12 | * this list of conditions and the following disclaimer in the documentation |
Picard22 | 0:c8ecd653066c | 13 | * and/or other materials provided with the distribution. |
Picard22 | 0:c8ecd653066c | 14 | * |
Picard22 | 0:c8ecd653066c | 15 | * * Neither the name of Sensirion AG nor the names of its |
Picard22 | 0:c8ecd653066c | 16 | * contributors may be used to endorse or promote products derived from |
Picard22 | 0:c8ecd653066c | 17 | * this software without specific prior written permission. |
Picard22 | 0:c8ecd653066c | 18 | * |
Picard22 | 0:c8ecd653066c | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Picard22 | 0:c8ecd653066c | 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Picard22 | 0:c8ecd653066c | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
Picard22 | 0:c8ecd653066c | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
Picard22 | 0:c8ecd653066c | 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
Picard22 | 0:c8ecd653066c | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
Picard22 | 0:c8ecd653066c | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
Picard22 | 0:c8ecd653066c | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
Picard22 | 0:c8ecd653066c | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
Picard22 | 0:c8ecd653066c | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
Picard22 | 0:c8ecd653066c | 29 | * POSSIBILITY OF SUCH DAMAGE. |
Picard22 | 0:c8ecd653066c | 30 | */ |
Picard22 | 0:c8ecd653066c | 31 | |
Picard22 | 0:c8ecd653066c | 32 | #ifndef SENSIRION_I2C_H |
Picard22 | 0:c8ecd653066c | 33 | #define SENSIRION_I2C_H |
Picard22 | 0:c8ecd653066c | 34 | |
Picard22 | 0:c8ecd653066c | 35 | #include "sensirion_config.h" |
Picard22 | 0:c8ecd653066c | 36 | |
Picard22 | 0:c8ecd653066c | 37 | #ifdef __cplusplus |
Picard22 | 0:c8ecd653066c | 38 | extern "C" { |
Picard22 | 0:c8ecd653066c | 39 | #endif |
Picard22 | 0:c8ecd653066c | 40 | |
Picard22 | 0:c8ecd653066c | 41 | #define CRC_ERROR 1 |
Picard22 | 0:c8ecd653066c | 42 | #define I2C_BUS_ERROR 2 |
Picard22 | 0:c8ecd653066c | 43 | #define I2C_NACK_ERROR 3 |
Picard22 | 0:c8ecd653066c | 44 | #define BYTE_NUM_ERROR 4 |
Picard22 | 0:c8ecd653066c | 45 | |
Picard22 | 0:c8ecd653066c | 46 | #define CRC8_POLYNOMIAL 0x31 |
Picard22 | 0:c8ecd653066c | 47 | #define CRC8_INIT 0xFF |
Picard22 | 0:c8ecd653066c | 48 | #define CRC8_LEN 1 |
Picard22 | 0:c8ecd653066c | 49 | |
Picard22 | 0:c8ecd653066c | 50 | #define SENSIRION_COMMAND_SIZE 2 |
Picard22 | 0:c8ecd653066c | 51 | #define SENSIRION_WORD_SIZE 2 |
Picard22 | 0:c8ecd653066c | 52 | #define SENSIRION_NUM_WORDS(x) (sizeof(x) / SENSIRION_WORD_SIZE) |
Picard22 | 0:c8ecd653066c | 53 | #define SENSIRION_MAX_BUFFER_WORDS 32 |
Picard22 | 0:c8ecd653066c | 54 | |
Picard22 | 0:c8ecd653066c | 55 | uint8_t sensirion_i2c_generate_crc(const uint8_t* data, uint16_t count); |
Picard22 | 0:c8ecd653066c | 56 | |
Picard22 | 0:c8ecd653066c | 57 | int8_t sensirion_i2c_check_crc(const uint8_t* data, uint16_t count, |
Picard22 | 0:c8ecd653066c | 58 | uint8_t checksum); |
Picard22 | 0:c8ecd653066c | 59 | |
Picard22 | 0:c8ecd653066c | 60 | /** |
Picard22 | 0:c8ecd653066c | 61 | * sensirion_i2c_general_call_reset() - Send a general call reset. |
Picard22 | 0:c8ecd653066c | 62 | * |
Picard22 | 0:c8ecd653066c | 63 | * @warning This will reset all attached I2C devices on the bus which support |
Picard22 | 0:c8ecd653066c | 64 | * general call reset. |
Picard22 | 0:c8ecd653066c | 65 | * |
Picard22 | 0:c8ecd653066c | 66 | * @return NO_ERROR on success, an error code otherwise |
Picard22 | 0:c8ecd653066c | 67 | */ |
Picard22 | 0:c8ecd653066c | 68 | int16_t sensirion_i2c_general_call_reset(void); |
Picard22 | 0:c8ecd653066c | 69 | |
Picard22 | 0:c8ecd653066c | 70 | /** |
Picard22 | 0:c8ecd653066c | 71 | * sensirion_i2c_fill_cmd_send_buf() - create the i2c send buffer for a command |
Picard22 | 0:c8ecd653066c | 72 | * and a set of argument words. The output buffer interleaves argument words |
Picard22 | 0:c8ecd653066c | 73 | * with their checksums. |
Picard22 | 0:c8ecd653066c | 74 | * @buf: The generated buffer to send over i2c. Then buffer length must |
Picard22 | 0:c8ecd653066c | 75 | * be at least SENSIRION_COMMAND_LEN + num_args * |
Picard22 | 0:c8ecd653066c | 76 | * (SENSIRION_WORD_SIZE + CRC8_LEN). |
Picard22 | 0:c8ecd653066c | 77 | * @cmd: The i2c command to send. It already includes a checksum. |
Picard22 | 0:c8ecd653066c | 78 | * @args: The arguments to the command. Can be NULL if none. |
Picard22 | 0:c8ecd653066c | 79 | * @num_args: The number of word arguments in args. |
Picard22 | 0:c8ecd653066c | 80 | * |
Picard22 | 0:c8ecd653066c | 81 | * @return The number of bytes written to buf |
Picard22 | 0:c8ecd653066c | 82 | */ |
Picard22 | 0:c8ecd653066c | 83 | uint16_t sensirion_i2c_fill_cmd_send_buf(uint8_t* buf, uint16_t cmd, |
Picard22 | 0:c8ecd653066c | 84 | const uint16_t* args, |
Picard22 | 0:c8ecd653066c | 85 | uint8_t num_args); |
Picard22 | 0:c8ecd653066c | 86 | |
Picard22 | 0:c8ecd653066c | 87 | /** |
Picard22 | 0:c8ecd653066c | 88 | * sensirion_i2c_read_words() - read data words from sensor |
Picard22 | 0:c8ecd653066c | 89 | * |
Picard22 | 0:c8ecd653066c | 90 | * @address: Sensor i2c address |
Picard22 | 0:c8ecd653066c | 91 | * @data_words: Allocated buffer to store the read words. |
Picard22 | 0:c8ecd653066c | 92 | * The buffer may also have been modified in case of an error. |
Picard22 | 0:c8ecd653066c | 93 | * @num_words: Number of data words to read (without CRC bytes) |
Picard22 | 0:c8ecd653066c | 94 | * |
Picard22 | 0:c8ecd653066c | 95 | * @return NO_ERROR on success, an error code otherwise |
Picard22 | 0:c8ecd653066c | 96 | */ |
Picard22 | 0:c8ecd653066c | 97 | int16_t sensirion_i2c_read_words(uint8_t address, uint16_t* data_words, |
Picard22 | 0:c8ecd653066c | 98 | uint16_t num_words); |
Picard22 | 0:c8ecd653066c | 99 | |
Picard22 | 0:c8ecd653066c | 100 | /** |
Picard22 | 0:c8ecd653066c | 101 | * sensirion_i2c_read_words_as_bytes() - read data words as byte-stream from |
Picard22 | 0:c8ecd653066c | 102 | * sensor |
Picard22 | 0:c8ecd653066c | 103 | * |
Picard22 | 0:c8ecd653066c | 104 | * Read bytes without adjusting values to the uP's word-order. |
Picard22 | 0:c8ecd653066c | 105 | * |
Picard22 | 0:c8ecd653066c | 106 | * @address: Sensor i2c address |
Picard22 | 0:c8ecd653066c | 107 | * @data: Allocated buffer to store the read bytes. |
Picard22 | 0:c8ecd653066c | 108 | * The buffer may also have been modified in case of an error. |
Picard22 | 0:c8ecd653066c | 109 | * @num_words: Number of data words(!) to read (without CRC bytes) |
Picard22 | 0:c8ecd653066c | 110 | * Since only word-chunks can be read from the sensor the size |
Picard22 | 0:c8ecd653066c | 111 | * is still specified in sensor-words (num_words = num_bytes * |
Picard22 | 0:c8ecd653066c | 112 | * SENSIRION_WORD_SIZE) |
Picard22 | 0:c8ecd653066c | 113 | * |
Picard22 | 0:c8ecd653066c | 114 | * @return NO_ERROR on success, an error code otherwise |
Picard22 | 0:c8ecd653066c | 115 | */ |
Picard22 | 0:c8ecd653066c | 116 | int16_t sensirion_i2c_read_words_as_bytes(uint8_t address, uint8_t* data, |
Picard22 | 0:c8ecd653066c | 117 | uint16_t num_words); |
Picard22 | 0:c8ecd653066c | 118 | |
Picard22 | 0:c8ecd653066c | 119 | /** |
Picard22 | 0:c8ecd653066c | 120 | * sensirion_i2c_write_cmd() - writes a command to the sensor |
Picard22 | 0:c8ecd653066c | 121 | * @address: Sensor i2c address |
Picard22 | 0:c8ecd653066c | 122 | * @command: Sensor command |
Picard22 | 0:c8ecd653066c | 123 | * |
Picard22 | 0:c8ecd653066c | 124 | * @return NO_ERROR on success, an error code otherwise |
Picard22 | 0:c8ecd653066c | 125 | */ |
Picard22 | 0:c8ecd653066c | 126 | int16_t sensirion_i2c_write_cmd(uint8_t address, uint16_t command); |
Picard22 | 0:c8ecd653066c | 127 | |
Picard22 | 0:c8ecd653066c | 128 | /** |
Picard22 | 0:c8ecd653066c | 129 | * sensirion_i2c_write_cmd_with_args() - writes a command with arguments to the |
Picard22 | 0:c8ecd653066c | 130 | * sensor |
Picard22 | 0:c8ecd653066c | 131 | * @address: Sensor i2c address |
Picard22 | 0:c8ecd653066c | 132 | * @command: Sensor command |
Picard22 | 0:c8ecd653066c | 133 | * @data: Argument buffer with words to send |
Picard22 | 0:c8ecd653066c | 134 | * @num_words: Number of data words to send (without CRC bytes) |
Picard22 | 0:c8ecd653066c | 135 | * |
Picard22 | 0:c8ecd653066c | 136 | * @return NO_ERROR on success, an error code otherwise |
Picard22 | 0:c8ecd653066c | 137 | */ |
Picard22 | 0:c8ecd653066c | 138 | int16_t sensirion_i2c_write_cmd_with_args(uint8_t address, uint16_t command, |
Picard22 | 0:c8ecd653066c | 139 | const uint16_t* data_words, |
Picard22 | 0:c8ecd653066c | 140 | uint16_t num_words); |
Picard22 | 0:c8ecd653066c | 141 | |
Picard22 | 0:c8ecd653066c | 142 | /** |
Picard22 | 0:c8ecd653066c | 143 | * sensirion_i2c_delayed_read_cmd() - send a command, wait for the sensor to |
Picard22 | 0:c8ecd653066c | 144 | * process and read data back |
Picard22 | 0:c8ecd653066c | 145 | * @address: Sensor i2c address |
Picard22 | 0:c8ecd653066c | 146 | * @cmd: Command |
Picard22 | 0:c8ecd653066c | 147 | * @delay: Time in microseconds to delay sending the read request |
Picard22 | 0:c8ecd653066c | 148 | * @data_words: Allocated buffer to store the read data |
Picard22 | 0:c8ecd653066c | 149 | * @num_words: Data words to read (without CRC bytes) |
Picard22 | 0:c8ecd653066c | 150 | * |
Picard22 | 0:c8ecd653066c | 151 | * @return NO_ERROR on success, an error code otherwise |
Picard22 | 0:c8ecd653066c | 152 | */ |
Picard22 | 0:c8ecd653066c | 153 | int16_t sensirion_i2c_delayed_read_cmd(uint8_t address, uint16_t cmd, |
Picard22 | 0:c8ecd653066c | 154 | uint32_t delay_us, uint16_t* data_words, |
Picard22 | 0:c8ecd653066c | 155 | uint16_t num_words); |
Picard22 | 0:c8ecd653066c | 156 | /** |
Picard22 | 0:c8ecd653066c | 157 | * sensirion_i2c_read_cmd() - reads data words from the sensor after a command |
Picard22 | 0:c8ecd653066c | 158 | * is issued |
Picard22 | 0:c8ecd653066c | 159 | * @address: Sensor i2c address |
Picard22 | 0:c8ecd653066c | 160 | * @cmd: Command |
Picard22 | 0:c8ecd653066c | 161 | * @data_words: Allocated buffer to store the read data |
Picard22 | 0:c8ecd653066c | 162 | * @num_words: Data words to read (without CRC bytes) |
Picard22 | 0:c8ecd653066c | 163 | * |
Picard22 | 0:c8ecd653066c | 164 | * @return NO_ERROR on success, an error code otherwise |
Picard22 | 0:c8ecd653066c | 165 | */ |
Picard22 | 0:c8ecd653066c | 166 | int16_t sensirion_i2c_read_cmd(uint8_t address, uint16_t cmd, |
Picard22 | 0:c8ecd653066c | 167 | uint16_t* data_words, uint16_t num_words); |
Picard22 | 0:c8ecd653066c | 168 | |
Picard22 | 0:c8ecd653066c | 169 | /** |
Picard22 | 0:c8ecd653066c | 170 | * sensirion_i2c_add_command_to_buffer() - Add a command to the buffer at |
Picard22 | 0:c8ecd653066c | 171 | * offset. Adds 2 bytes to the buffer. |
Picard22 | 0:c8ecd653066c | 172 | * |
Picard22 | 0:c8ecd653066c | 173 | * @param buffer Pointer to buffer in which the write frame will be prepared. |
Picard22 | 0:c8ecd653066c | 174 | * Caller needs to make sure that there is enough space after |
Picard22 | 0:c8ecd653066c | 175 | * offset left to write the data into the buffer. |
Picard22 | 0:c8ecd653066c | 176 | * @param offset Offset of the next free byte in the buffer. |
Picard22 | 0:c8ecd653066c | 177 | * @param command Command to be written into the buffer. |
Picard22 | 0:c8ecd653066c | 178 | * |
Picard22 | 0:c8ecd653066c | 179 | * @return Offset of next free byte in the buffer after writing the data. |
Picard22 | 0:c8ecd653066c | 180 | */ |
Picard22 | 0:c8ecd653066c | 181 | uint16_t sensirion_i2c_add_command_to_buffer(uint8_t* buffer, uint16_t offset, |
Picard22 | 0:c8ecd653066c | 182 | uint16_t command); |
Picard22 | 0:c8ecd653066c | 183 | |
Picard22 | 0:c8ecd653066c | 184 | /** |
Picard22 | 0:c8ecd653066c | 185 | * sensirion_i2c_add_uint32_t_to_buffer() - Add a uint32_t to the buffer at |
Picard22 | 0:c8ecd653066c | 186 | * offset. Adds 6 bytes to the buffer. |
Picard22 | 0:c8ecd653066c | 187 | * |
Picard22 | 0:c8ecd653066c | 188 | * @param buffer Pointer to buffer in which the write frame will be prepared. |
Picard22 | 0:c8ecd653066c | 189 | * Caller needs to make sure that there is enough space after |
Picard22 | 0:c8ecd653066c | 190 | * offset left to write the data into the buffer. |
Picard22 | 0:c8ecd653066c | 191 | * @param offset Offset of the next free byte in the buffer. |
Picard22 | 0:c8ecd653066c | 192 | * @param data uint32_t to be written into the buffer. |
Picard22 | 0:c8ecd653066c | 193 | * |
Picard22 | 0:c8ecd653066c | 194 | * @return Offset of next free byte in the buffer after writing the data. |
Picard22 | 0:c8ecd653066c | 195 | */ |
Picard22 | 0:c8ecd653066c | 196 | uint16_t sensirion_i2c_add_uint32_t_to_buffer(uint8_t* buffer, uint16_t offset, |
Picard22 | 0:c8ecd653066c | 197 | uint32_t data); |
Picard22 | 0:c8ecd653066c | 198 | |
Picard22 | 0:c8ecd653066c | 199 | /** |
Picard22 | 0:c8ecd653066c | 200 | * sensirion_i2c_add_int32_t_to_buffer() - Add a int32_t to the buffer at |
Picard22 | 0:c8ecd653066c | 201 | * offset. Adds 6 bytes to the buffer. |
Picard22 | 0:c8ecd653066c | 202 | * |
Picard22 | 0:c8ecd653066c | 203 | * @param buffer Pointer to buffer in which the write frame will be prepared. |
Picard22 | 0:c8ecd653066c | 204 | * Caller needs to make sure that there is enough space after |
Picard22 | 0:c8ecd653066c | 205 | * offset left to write the data into the buffer. |
Picard22 | 0:c8ecd653066c | 206 | * @param offset Offset of the next free byte in the buffer. |
Picard22 | 0:c8ecd653066c | 207 | * @param data int32_t to be written into the buffer. |
Picard22 | 0:c8ecd653066c | 208 | * |
Picard22 | 0:c8ecd653066c | 209 | * @return Offset of next free byte in the buffer after writing the data. |
Picard22 | 0:c8ecd653066c | 210 | */ |
Picard22 | 0:c8ecd653066c | 211 | uint16_t sensirion_i2c_add_int32_t_to_buffer(uint8_t* buffer, uint16_t offset, |
Picard22 | 0:c8ecd653066c | 212 | int32_t data); |
Picard22 | 0:c8ecd653066c | 213 | |
Picard22 | 0:c8ecd653066c | 214 | /** |
Picard22 | 0:c8ecd653066c | 215 | * sensirion_i2c_add_uint16_t_to_buffer() - Add a uint16_t to the buffer at |
Picard22 | 0:c8ecd653066c | 216 | * offset. Adds 3 bytes to the buffer. |
Picard22 | 0:c8ecd653066c | 217 | * |
Picard22 | 0:c8ecd653066c | 218 | * @param buffer Pointer to buffer in which the write frame will be prepared. |
Picard22 | 0:c8ecd653066c | 219 | * Caller needs to make sure that there is enough space after |
Picard22 | 0:c8ecd653066c | 220 | * offset left to write the data into the buffer. |
Picard22 | 0:c8ecd653066c | 221 | * @param offset Offset of the next free byte in the buffer. |
Picard22 | 0:c8ecd653066c | 222 | * @param data uint16_t to be written into the buffer. |
Picard22 | 0:c8ecd653066c | 223 | * |
Picard22 | 0:c8ecd653066c | 224 | * @return Offset of next free byte in the buffer after writing the data. |
Picard22 | 0:c8ecd653066c | 225 | */ |
Picard22 | 0:c8ecd653066c | 226 | uint16_t sensirion_i2c_add_uint16_t_to_buffer(uint8_t* buffer, uint16_t offset, |
Picard22 | 0:c8ecd653066c | 227 | uint16_t data); |
Picard22 | 0:c8ecd653066c | 228 | |
Picard22 | 0:c8ecd653066c | 229 | /** |
Picard22 | 0:c8ecd653066c | 230 | * sensirion_i2c_add_int16_t_to_buffer() - Add a int16_t to the buffer at |
Picard22 | 0:c8ecd653066c | 231 | * offset. Adds 3 bytes to the buffer. |
Picard22 | 0:c8ecd653066c | 232 | * |
Picard22 | 0:c8ecd653066c | 233 | * @param buffer Pointer to buffer in which the write frame will be prepared. |
Picard22 | 0:c8ecd653066c | 234 | * Caller needs to make sure that there is enough space after |
Picard22 | 0:c8ecd653066c | 235 | * offset left to write the data into the buffer. |
Picard22 | 0:c8ecd653066c | 236 | * @param offset Offset of the next free byte in the buffer. |
Picard22 | 0:c8ecd653066c | 237 | * @param data int16_t to be written into the buffer. |
Picard22 | 0:c8ecd653066c | 238 | * |
Picard22 | 0:c8ecd653066c | 239 | * @return Offset of next free byte in the buffer after writing the data. |
Picard22 | 0:c8ecd653066c | 240 | */ |
Picard22 | 0:c8ecd653066c | 241 | uint16_t sensirion_i2c_add_int16_t_to_buffer(uint8_t* buffer, uint16_t offset, |
Picard22 | 0:c8ecd653066c | 242 | int16_t data); |
Picard22 | 0:c8ecd653066c | 243 | |
Picard22 | 0:c8ecd653066c | 244 | /** |
Picard22 | 0:c8ecd653066c | 245 | * sensirion_i2c_add_float_to_buffer() - Add a float to the buffer at offset. |
Picard22 | 0:c8ecd653066c | 246 | * Adds 6 bytes to the buffer. |
Picard22 | 0:c8ecd653066c | 247 | * |
Picard22 | 0:c8ecd653066c | 248 | * @param buffer Pointer to buffer in which the write frame will be prepared. |
Picard22 | 0:c8ecd653066c | 249 | * Caller needs to make sure that there is enough space after |
Picard22 | 0:c8ecd653066c | 250 | * offset left to write the data into the buffer. |
Picard22 | 0:c8ecd653066c | 251 | * @param offset Offset of the next free byte in the buffer. |
Picard22 | 0:c8ecd653066c | 252 | * @param data float to be written into the buffer. |
Picard22 | 0:c8ecd653066c | 253 | * |
Picard22 | 0:c8ecd653066c | 254 | * @return Offset of next free byte in the buffer after writing the data. |
Picard22 | 0:c8ecd653066c | 255 | */ |
Picard22 | 0:c8ecd653066c | 256 | uint16_t sensirion_i2c_add_float_to_buffer(uint8_t* buffer, uint16_t offset, |
Picard22 | 0:c8ecd653066c | 257 | float data); |
Picard22 | 0:c8ecd653066c | 258 | |
Picard22 | 0:c8ecd653066c | 259 | /** |
Picard22 | 0:c8ecd653066c | 260 | * sensirion_i2c_add_bytes_to_buffer() - Add a byte array to the buffer at |
Picard22 | 0:c8ecd653066c | 261 | * offset. |
Picard22 | 0:c8ecd653066c | 262 | * |
Picard22 | 0:c8ecd653066c | 263 | * @param buffer Pointer to buffer in which the write frame will be |
Picard22 | 0:c8ecd653066c | 264 | * prepared. Caller needs to make sure that there is |
Picard22 | 0:c8ecd653066c | 265 | * enough space after offset left to write the data |
Picard22 | 0:c8ecd653066c | 266 | * into the buffer. |
Picard22 | 0:c8ecd653066c | 267 | * @param offset Offset of the next free byte in the buffer. |
Picard22 | 0:c8ecd653066c | 268 | * @param data Pointer to data to be written into the buffer. |
Picard22 | 0:c8ecd653066c | 269 | * @param data_length Number of bytes to be written into the buffer. Needs to |
Picard22 | 0:c8ecd653066c | 270 | * be a multiple of SENSIRION_WORD_SIZE otherwise the |
Picard22 | 0:c8ecd653066c | 271 | * function returns BYTE_NUM_ERROR. |
Picard22 | 0:c8ecd653066c | 272 | * |
Picard22 | 0:c8ecd653066c | 273 | * @return Offset of next free byte in the buffer after writing the |
Picard22 | 0:c8ecd653066c | 274 | * data. |
Picard22 | 0:c8ecd653066c | 275 | */ |
Picard22 | 0:c8ecd653066c | 276 | uint16_t sensirion_i2c_add_bytes_to_buffer(uint8_t* buffer, uint16_t offset, |
Picard22 | 0:c8ecd653066c | 277 | uint8_t* data, uint16_t data_length); |
Picard22 | 0:c8ecd653066c | 278 | |
Picard22 | 0:c8ecd653066c | 279 | /** |
Picard22 | 0:c8ecd653066c | 280 | * sensirion_i2c_write_data() - Writes data to the Sensor. |
Picard22 | 0:c8ecd653066c | 281 | * |
Picard22 | 0:c8ecd653066c | 282 | * @note This is just a wrapper for sensirion_i2c_hal_write() to |
Picard22 | 0:c8ecd653066c | 283 | * not need to include the HAL in the drivers. |
Picard22 | 0:c8ecd653066c | 284 | * |
Picard22 | 0:c8ecd653066c | 285 | * @param address I2C address to write to. |
Picard22 | 0:c8ecd653066c | 286 | * @param data Pointer to the buffer containing the data to write. |
Picard22 | 0:c8ecd653066c | 287 | * @param data_length Number of bytes to send to the Sensor. |
Picard22 | 0:c8ecd653066c | 288 | * |
Picard22 | 0:c8ecd653066c | 289 | * @return NO_ERROR on success, error code otherwise |
Picard22 | 0:c8ecd653066c | 290 | */ |
Picard22 | 0:c8ecd653066c | 291 | int16_t sensirion_i2c_write_data(uint8_t address, const uint8_t* data, |
Picard22 | 0:c8ecd653066c | 292 | uint16_t data_length); |
Picard22 | 0:c8ecd653066c | 293 | |
Picard22 | 0:c8ecd653066c | 294 | /** |
Picard22 | 0:c8ecd653066c | 295 | * sensirion_i2c_read_data_inplace() - Reads data from the Sensor. |
Picard22 | 0:c8ecd653066c | 296 | * |
Picard22 | 0:c8ecd653066c | 297 | * @param address Sensor I2C address |
Picard22 | 0:c8ecd653066c | 298 | * @param buffer Allocated buffer to store data as bytes. Needs |
Picard22 | 0:c8ecd653066c | 299 | * to be big enough to store the data including |
Picard22 | 0:c8ecd653066c | 300 | * CRC. Twice the size of data should always |
Picard22 | 0:c8ecd653066c | 301 | * suffice. |
Picard22 | 0:c8ecd653066c | 302 | * @param expected_data_length Number of bytes to read (without CRC). Needs |
Picard22 | 0:c8ecd653066c | 303 | * to be a multiple of SENSIRION_WORD_SIZE, |
Picard22 | 0:c8ecd653066c | 304 | * otherwise the function returns BYTE_NUM_ERROR. |
Picard22 | 0:c8ecd653066c | 305 | * |
Picard22 | 0:c8ecd653066c | 306 | * @return NO_ERROR on success, an error code otherwise |
Picard22 | 0:c8ecd653066c | 307 | */ |
Picard22 | 0:c8ecd653066c | 308 | int16_t sensirion_i2c_read_data_inplace(uint8_t address, uint8_t* buffer, |
Picard22 | 0:c8ecd653066c | 309 | uint16_t expected_data_length); |
Picard22 | 0:c8ecd653066c | 310 | #ifdef __cplusplus |
Picard22 | 0:c8ecd653066c | 311 | } |
Picard22 | 0:c8ecd653066c | 312 | #endif |
Picard22 | 0:c8ecd653066c | 313 | |
Picard22 | 0:c8ecd653066c | 314 | #endif /* SENSIRION_I2C_H */ |