Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from Sensirion/stdint
Browse files Browse the repository at this point in the history
Automated type conversion
  • Loading branch information
abrauchli authored May 13, 2019
2 parents 7961139 + e0a2440 commit 72335f7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion embedded-common
Submodule embedded-common updated 26 files
+16 −13 README.md
+22 −23 hw_i2c/sample-implementations/Atmel_SAMD2_series/sensirion_hw_i2c_implementation.c
+30 −32 hw_i2c/sample-implementations/Nordic_nRF5_series/sensirion_hw_i2c_implementation.c
+22 −21 hw_i2c/sample-implementations/STM32F1_series/sensirion_hw_i2c_implementation.c
+31 −0 hw_i2c/sample-implementations/arduino-alt-i2c/LICENSE_i2c_master_lib
+719 −0 hw_i2c/sample-implementations/arduino-alt-i2c/i2c_master_lib.cpp
+128 −0 hw_i2c/sample-implementations/arduino-alt-i2c/i2c_master_lib.h
+78 −0 hw_i2c/sample-implementations/arduino-alt-i2c/sensirion_hw_i2c_implementation.cpp
+93 −0 hw_i2c/sample-implementations/arduino/README.md
+24 −29 hw_i2c/sample-implementations/arduino/sensirion_hw_i2c_implementation.cpp
+25 −25 hw_i2c/sample-implementations/linux_user_space/sensirion_hw_i2c_implementation.c
+20 −22 hw_i2c/sample-implementations/mbed/sensirion_hw_i2c_implementation.cpp
+19 −20 hw_i2c/sample-implementations/mbed/sgp30_example_usage.cpp
+18 −19 hw_i2c/sensirion_hw_i2c_implementation.c
+2 −15 sensirion_arch_config.h
+52 −48 sensirion_common.c
+44 −34 sensirion_common.h
+13 −11 sensirion_i2c.h
+13 −12 sw_i2c/sample-implementations/Atmel_SAMD2_series/sensirion_sw_i2c_implementation.c
+32 −30 sw_i2c/sample-implementations/Nordic_nRF5_series/sensirion_sw_i2c_implementation.c
+16 −15 sw_i2c/sample-implementations/STM32F1_series/sensirion_sw_i2c_implementation.c
+30 −44 sw_i2c/sample-implementations/linux_user_space/sensirion_sw_i2c_implementation.c
+18 −26 sw_i2c/sample-implementations/mbed/sensirion_sw_i2c_implementation.cpp
+27 −33 sw_i2c/sensirion_sw_i2c.c
+12 −11 sw_i2c/sensirion_sw_i2c_gpio.h
+18 −24 sw_i2c/sensirion_sw_i2c_implementation.c
57 changes: 29 additions & 28 deletions scd30/scd30.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
#include "sensirion_i2c.h"

#ifdef SCD_ADDRESS
static const u8 SCD_I2C_ADDRESS = SCD_ADDRESS;
static const uint8_t SCD_I2C_ADDRESS = SCD_ADDRESS;
#else
static const u8 SCD_I2C_ADDRESS = 0x61;
static const uint8_t SCD_I2C_ADDRESS = 0x61;
#endif

#define SCD_CMD_START_PERIODIC_MEASUREMENT 0x0010
Expand All @@ -56,7 +56,7 @@ static const u8 SCD_I2C_ADDRESS = 0x61;
#define SCD_CMD_SINGLE_WORD_BUF_LEN \
(SENSIRION_COMMAND_SIZE + SENSIRION_WORD_SIZE + CRC8_LEN)

s16 scd_start_periodic_measurement(u16 ambient_pressure_mbar) {
int16_t scd_start_periodic_measurement(uint16_t ambient_pressure_mbar) {
if (ambient_pressure_mbar &&
(ambient_pressure_mbar < 700 || ambient_pressure_mbar > 1400)) {
/* out of allowable range */
Expand All @@ -68,17 +68,18 @@ s16 scd_start_periodic_measurement(u16 ambient_pressure_mbar) {
&ambient_pressure_mbar, SENSIRION_NUM_WORDS(ambient_pressure_mbar));
}

s16 scd_stop_periodic_measurement() {
int16_t scd_stop_periodic_measurement() {
return sensirion_i2c_write_cmd(SCD_I2C_ADDRESS,
SCD_CMD_STOP_PERIODIC_MEASUREMENT);
}

s16 scd_read_measurement(f32 *co2_ppm, f32 *temperature, f32 *humidity) {
s16 ret;
int16_t scd_read_measurement(float32_t *co2_ppm, float32_t *temperature,
float32_t *humidity) {
int16_t ret;
union {
u32 u32_value;
f32 float32;
u16 words[2];
uint32_t u32_value;
float32_t float32;
uint16_t words[2];
} tmp, data[3];

ret = sensirion_i2c_read_cmd(SCD_I2C_ADDRESS, SCD_CMD_READ_MEASUREMENT,
Expand All @@ -101,8 +102,8 @@ s16 scd_read_measurement(f32 *co2_ppm, f32 *temperature, f32 *humidity) {
return STATUS_OK;
}

s16 scd_set_measurement_interval(u16 interval_sec) {
s16 ret;
int16_t scd_set_measurement_interval(uint16_t interval_sec) {
int16_t ret;

if (interval_sec < 2 || interval_sec > 1800) {
/* out of allowable range */
Expand All @@ -117,13 +118,13 @@ s16 scd_set_measurement_interval(u16 interval_sec) {
return ret;
}

s16 scd_get_data_ready(u16 *data_ready) {
int16_t scd_get_data_ready(uint16_t *data_ready) {
return sensirion_i2c_read_cmd(SCD_I2C_ADDRESS, SCD_CMD_GET_DATA_READY,
data_ready, SENSIRION_NUM_WORDS(*data_ready));
}

s16 scd_set_temperature_offset(u16 temperature_offset) {
s16 ret;
int16_t scd_set_temperature_offset(uint16_t temperature_offset) {
int16_t ret;

ret = sensirion_i2c_write_cmd_with_args(
SCD_I2C_ADDRESS, SCD_CMD_SET_TEMPERATURE_OFFSET, &temperature_offset,
Expand All @@ -133,8 +134,8 @@ s16 scd_set_temperature_offset(u16 temperature_offset) {
return ret;
}

s16 scd_set_altitude(u16 altitude) {
s16 ret;
int16_t scd_set_altitude(uint16_t altitude) {
int16_t ret;

ret = sensirion_i2c_write_cmd_with_args(SCD_I2C_ADDRESS,
SCD_CMD_SET_ALTITUDE, &altitude,
Expand All @@ -144,23 +145,23 @@ s16 scd_set_altitude(u16 altitude) {
return ret;
}

s16 scd_get_automatic_self_calibration(u8 *asc_enabled) {
u16 word;
s16 ret;
int16_t scd_get_automatic_self_calibration(uint8_t *asc_enabled) {
uint16_t word;
int16_t ret;

ret = sensirion_i2c_read_cmd(SCD_I2C_ADDRESS, SCD_CMD_AUTO_SELF_CALIBRATION,
&word, SENSIRION_NUM_WORDS(word));
if (ret != STATUS_OK)
return ret;

*asc_enabled = (u8)word;
*asc_enabled = (uint8_t)word;

return STATUS_OK;
}

s16 scd_enable_automatic_self_calibration(u8 enable_asc) {
s16 ret;
u16 asc = !!enable_asc;
int16_t scd_enable_automatic_self_calibration(uint8_t enable_asc) {
int16_t ret;
uint16_t asc = !!enable_asc;

ret = sensirion_i2c_write_cmd_with_args(SCD_I2C_ADDRESS,
SCD_CMD_AUTO_SELF_CALIBRATION, &asc,
Expand All @@ -170,8 +171,8 @@ s16 scd_enable_automatic_self_calibration(u8 enable_asc) {
return ret;
}

s16 scd_set_forced_recalibration(u16 co2_ppm) {
s16 ret;
int16_t scd_set_forced_recalibration(uint16_t co2_ppm) {
int16_t ret;

ret = sensirion_i2c_write_cmd_with_args(
SCD_I2C_ADDRESS, SCD_CMD_SET_FORCED_RECALIBRATION, &co2_ppm,
Expand All @@ -185,12 +186,12 @@ const char *scd_get_driver_version() {
return SCD_DRV_VERSION_STR;
}

u8 scd_get_configured_address() {
uint8_t scd_get_configured_address() {
return SCD_I2C_ADDRESS;
}

s16 scd_probe() {
u16 data_ready;
int16_t scd_probe() {
uint16_t data_ready;

/* Initialize I2C */
sensirion_i2c_init();
Expand Down
27 changes: 14 additions & 13 deletions scd30/scd30.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern "C" {
*
* @return 0 on success, an error code otherwise.
*/
s16 scd_probe(void);
int16_t scd_probe(void);

/**
* scd_get_driver_version() - Returns the driver version
Expand All @@ -56,9 +56,9 @@ const char *scd_get_driver_version(void);
/**
* scd_get_configured_address() - Returns the configured I2C address
*
* @return u8 I2C address
* @return uint8_t I2C address
*/
u8 scd_get_configured_address(void);
uint8_t scd_get_configured_address(void);

/**
* scd_start_periodic_measurement() - Start continuous measurement to measure
Expand All @@ -81,14 +81,14 @@ u8 scd_get_configured_address(void);
* @return 0 if the command was successful, an error code
* otherwise
*/
s16 scd_start_periodic_measurement(u16 ambient_pressure_mbar);
int16_t scd_start_periodic_measurement(uint16_t ambient_pressure_mbar);

/**
* scd_stop_periodic_measurement() - Stop the continuous measurement
*
* @return 0 if the command was successful, else an error code
*/
s16 scd_stop_periodic_measurement(void);
int16_t scd_stop_periodic_measurement(void);

/**
* scd_read_measurement() - Read out an available measurement when new
Expand All @@ -104,7 +104,8 @@ s16 scd_stop_periodic_measurement(void);
*
* @return 0 if the command was successful, an error code otherwise
*/
s16 scd_read_measurement(f32 *co2_ppm, f32 *temperature, f32 *humidity);
int16_t scd_read_measurement(float32_t *co2_ppm, float32_t *temperature,
float32_t *humidity);

/**
* scd_set_measurement_interval() - Sets the measurement interval in continuous
Expand All @@ -119,7 +120,7 @@ s16 scd_read_measurement(f32 *co2_ppm, f32 *temperature, f32 *humidity);
*
* @return 0 if the command was successful, an error code otherwise
*/
s16 scd_set_measurement_interval(u16 interval_sec);
int16_t scd_set_measurement_interval(uint16_t interval_sec);

/**
* scd_get_data_ready() - Get data ready status
Expand All @@ -137,7 +138,7 @@ s16 scd_set_measurement_interval(u16 interval_sec);
*
* @return 0 if the command was successful, an error code otherwise
*/
s16 scd_get_data_ready(u16 *data_ready);
int16_t scd_get_data_ready(uint16_t *data_ready);

/**
* scd_set_temperature_offset() - Set the temperature offset
Expand All @@ -157,7 +158,7 @@ s16 scd_get_data_ready(u16 *data_ready);
* @return 0 if the command was successful, an error code
* otherwise
*/
s16 scd_set_temperature_offset(u16 temperature_offset);
int16_t scd_set_temperature_offset(uint16_t temperature_offset);

/**
* scd_set_altitude() - Set the altitude above sea level
Expand All @@ -174,7 +175,7 @@ s16 scd_set_temperature_offset(u16 temperature_offset);
*
* @return 0 if the command was successful, an error code otherwise
*/
s16 scd_set_altitude(u16 altitude);
int16_t scd_set_altitude(uint16_t altitude);

/**
* scd_get_automatic_self_calibration() - Read if the sensor's automatic self
Expand All @@ -188,7 +189,7 @@ s16 scd_set_altitude(u16 altitude);
*
* @return 0 if the command was successful, an error code otherwise
*/
s16 scd_get_automatic_self_calibration(u8 *asc_enabled);
int16_t scd_get_automatic_self_calibration(uint8_t *asc_enabled);

/**
* scd_enable_automatic_self_calibration() - Enable or disable the sensor's
Expand All @@ -207,7 +208,7 @@ s16 scd_get_automatic_self_calibration(u8 *asc_enabled);
*
* @return 0 if the command was successful, an error code otherwise
*/
s16 scd_enable_automatic_self_calibration(u8 enable_asc);
int16_t scd_enable_automatic_self_calibration(uint8_t enable_asc);

/**
* scd_set_forced_recalibration() - Forcibly recalibrate the sensor to a known
Expand All @@ -231,7 +232,7 @@ s16 scd_enable_automatic_self_calibration(u8 enable_asc);
*
* @return 0 if the command was successful, an error code otherwise
*/
s16 scd_set_forced_recalibration(u16 co2_ppm);
int16_t scd_set_forced_recalibration(uint16_t co2_ppm);

#ifdef __cplusplus
}
Expand Down
8 changes: 4 additions & 4 deletions scd30/scd30_example_usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
#define usleep(...)

int main(void) {
f32 co2_ppm, temperature, relative_humidity;
u16 data_ready;
s16 ret;
s16 interval_in_seconds = 2;
float32_t co2_ppm, temperature, relative_humidity;
uint16_t data_ready;
int16_t ret;
int16_t interval_in_seconds = 2;

/* Busy loop for initialization, because the main loop does not work without
* a sensor.
Expand Down

0 comments on commit 72335f7

Please sign in to comment.