Nucleo Lora / Mbed 2 deprecated STM32_I2C_Sensiron_SCD41

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sensirion_common.h Source File

sensirion_common.h

00001 /*
00002  * Copyright (c) 2018, Sensirion AG
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * * Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  *
00011  * * Redistributions in binary form must reproduce the above copyright notice,
00012  *   this list of conditions and the following disclaimer in the documentation
00013  *   and/or other materials provided with the distribution.
00014  *
00015  * * Neither the name of Sensirion AG nor the names of its
00016  *   contributors may be used to endorse or promote products derived from
00017  *   this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #ifndef SENSIRION_COMMON_H
00033 #define SENSIRION_COMMON_H
00034 
00035 #include "sensirion_config.h"
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 #define NO_ERROR 0
00042 #define NOT_IMPLEMENTED_ERROR 31
00043 
00044 #ifndef ARRAY_SIZE
00045 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
00046 #endif
00047 
00048 #define SENSIRION_COMMAND_SIZE 2
00049 #define SENSIRION_WORD_SIZE 2
00050 #define SENSIRION_NUM_WORDS(x) (sizeof(x) / SENSIRION_WORD_SIZE)
00051 #define SENSIRION_MAX_BUFFER_WORDS 32
00052 
00053 /**
00054  * sensirion_common_bytes_to_int16_t() - Convert an array of bytes to an int16_t
00055  *
00056  * Convert an array of bytes received from the sensor in big-endian/MSB-first
00057  * format to an int16_t value in the correct system-endianness.
00058  *
00059  * @param bytes An array of at least two bytes (MSB first)
00060  * @return      The byte array represented as int16_t
00061  */
00062 int16_t sensirion_common_bytes_to_int16_t(const uint8_t* bytes);
00063 
00064 /**
00065  * sensirion_common_bytes_to_int32_t() - Convert an array of bytes to an int32_t
00066  *
00067  * Convert an array of bytes received from the sensor in big-endian/MSB-first
00068  * format to an int32_t value in the correct system-endianness.
00069  *
00070  * @param bytes An array of at least four bytes (MSB first)
00071  * @return      The byte array represented as int32_t
00072  */
00073 int32_t sensirion_common_bytes_to_int32_t(const uint8_t* bytes);
00074 
00075 /**
00076  * sensirion_common_bytes_to_uint16_t() - Convert an array of bytes to an
00077  * uint16_t
00078  *
00079  * Convert an array of bytes received from the sensor in big-endian/MSB-first
00080  * format to an uint16_t value in the correct system-endianness.
00081  *
00082  * @param bytes An array of at least two bytes (MSB first)
00083  * @return      The byte array represented as uint16_t
00084  */
00085 uint16_t sensirion_common_bytes_to_uint16_t(const uint8_t* bytes);
00086 
00087 /**
00088  * sensirion_common_bytes_to_uint32_t() - Convert an array of bytes to an
00089  * uint32_t
00090  *
00091  * Convert an array of bytes received from the sensor in big-endian/MSB-first
00092  * format to an uint32_t value in the correct system-endianness.
00093  *
00094  * @param bytes An array of at least four bytes (MSB first)
00095  * @return      The byte array represented as uint32_t
00096  */
00097 uint32_t sensirion_common_bytes_to_uint32_t(const uint8_t* bytes);
00098 
00099 /**
00100  * sensirion_common_bytes_to_float() - Convert an array of bytes to a float
00101  *
00102  * Convert an array of bytes received from the sensor in big-endian/MSB-first
00103  * format to an float value in the correct system-endianness.
00104  *
00105  * @param bytes An array of at least four bytes (MSB first)
00106  * @return      The byte array represented as float
00107  */
00108 float sensirion_common_bytes_to_float(const uint8_t* bytes);
00109 
00110 /**
00111  * sensirion_common_uint32_t_to_bytes() - Convert an uint32_t to an array of
00112  * bytes
00113  *
00114  * Convert an uint32_t value in system-endianness to big-endian/MBS-first
00115  * format to send to the sensor.
00116  *
00117  * @param value Value to convert
00118  * @param bytes An array of at least four bytes
00119  */
00120 void sensirion_common_uint32_t_to_bytes(const uint32_t value, uint8_t* bytes);
00121 
00122 /**
00123  * sensirion_common_uint16_t_to_bytes() - Convert an uint16_t to an array of
00124  * bytes
00125  *
00126  * Convert an uint16_t value in system-endianness to big-endian/MBS-first
00127  * format to send to the sensor.
00128  *
00129  * @param value Value to convert
00130  * @param bytes An array of at least two bytes
00131  */
00132 void sensirion_common_uint16_t_to_bytes(const uint16_t value, uint8_t* bytes);
00133 
00134 /**
00135  * sensirion_common_int32_t_to_bytes() - Convert an int32_t to an array of bytes
00136  *
00137  * Convert an int32_t value in system-endianness to big-endian/MBS-first
00138  * format to send to the sensor.
00139  *
00140  * @param value Value to convert
00141  * @param bytes An array of at least four bytes
00142  */
00143 void sensirion_common_int32_t_to_bytes(const int32_t value, uint8_t* bytes);
00144 
00145 /**
00146  * sensirion_common_int16_t_to_bytes() - Convert an int16_t to an array of bytes
00147  *
00148  * Convert an int16_t value in system-endianness to big-endian/MBS-first
00149  * format to send to the sensor.
00150  *
00151  * @param value Value to convert
00152  * @param bytes An array of at least two bytes
00153  */
00154 void sensirion_common_int16_t_to_bytes(const int16_t value, uint8_t* bytes);
00155 
00156 /**
00157  * sensirion_common_float_to_bytes() - Convert an float to an array of bytes
00158  *
00159  * Convert an float value in system-endianness to big-endian/MBS-first
00160  * format to send to the sensor.
00161  *
00162  * @param value Value to convert
00163  * @param bytes An array of at least four bytes
00164  */
00165 void sensirion_common_float_to_bytes(const float value, uint8_t* bytes);
00166 
00167 /**
00168  * sensirion_common_copy_bytes() - Copy bytes from one array to the other.
00169  *
00170  * @param source      Array of bytes to be copied.
00171  * @param destination Array of bytes to be copied to.
00172  * @param data_length Number of bytes to copy.
00173  */
00174 void sensirion_common_copy_bytes(const uint8_t* source, uint8_t* destination,
00175                                  uint16_t data_length);
00176 
00177 #ifdef __cplusplus
00178 }
00179 #endif
00180 
00181 #endif /* SENSIRION_COMMON_H */