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 #1 from Sensirion/stdint
Browse files Browse the repository at this point in the history
Automated type conversion
  • Loading branch information
abrauchli committed May 13, 2019
2 parents 35203cd + e1a6914 commit f7b9b7f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 44 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
+557 −553 hw_i2c/sample-implementations/arduino-alt-i2c/i2c_master_lib.cpp
+34 −41 hw_i2c/sample-implementations/arduino-alt-i2c/i2c_master_lib.h
+19 −20 hw_i2c/sample-implementations/arduino-alt-i2c/sensirion_hw_i2c_implementation.cpp
+0 −40 hw_i2c/sample-implementations/arduino/README.md
+0 −103 hw_i2c/sample-implementations/arduino/sensirion_arch_config.h
+23 −24 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
4 changes: 2 additions & 2 deletions sts-common/example_usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ int main(void) {
/* printf("STS sensor probing successful\n"); */

while (1) {
s32 temperature;
int32_t temperature;
float temperature_degree;
/* Measure temperature and store into variable temperature
* (output is multiplied by 1000).
*/
s8 ret = sts_measure_blocking_read(&temperature);
int8_t ret = sts_measure_blocking_read(&temperature);
if (ret == STATUS_OK) {
temperature_degree = temperature / 1000.0f;
/* printf("measured temperature: %0.2f degreeCelsius\n",
Expand Down
16 changes: 8 additions & 8 deletions sts-common/sts.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extern "C" {
*
* @return 0 if a sensor was detected
*/
s8 sts_probe(void);
int8_t sts_probe(void);

/**
* Starts a measurement and then reads out the results. This function blocks
Expand All @@ -72,7 +72,7 @@ s8 sts_probe(void);
* measurement
* @return 0 if the command was successful, else an error code.
*/
s8 sts_measure_blocking_read(s32 *temperature);
int8_t sts_measure_blocking_read(int32_t *temperature);

/**
* Starts a measurement in high precision mode. Use sts_read() to read out the
Expand All @@ -81,7 +81,7 @@ s8 sts_measure_blocking_read(s32 *temperature);
*
* @return 0 if the command was successful, else an error code.
*/
s8 sts_measure(void);
int8_t sts_measure(void);

/**
* Reads out the results of a measurement that was previously started by
Expand All @@ -93,7 +93,7 @@ s8 sts_measure(void);
* measurement
* @return 0 if the command was successful, else an error code.
*/
s8 sts_read(s32 *temperature);
int8_t sts_read(int32_t *temperature);

/**
* Set repeatability of the STS
Expand All @@ -102,23 +102,23 @@ s8 sts_read(s32 *temperature);
* 1 for medium repeatability mode
* 2 for low repeatability mode
*/
void sts_set_repeatability(u8 repeatability);
void sts_set_repeatability(uint8_t repeatability);

/**
* Enable internal heater. The heater is meant for plausibility check only.
*
* @return 0 if the command was successful,
* 1 if an error occured
*/
s8 sts_heater_on(void);
int8_t sts_heater_on(void);

/**
* Disable internal heater
*
* @return 0 if the command was successful,
* 1 if an error occured
*/
s8 sts_heater_off(void);
int8_t sts_heater_off(void);

/**
* sts_get_driver_version() - Return the driver version
Expand All @@ -132,7 +132,7 @@ const char *sts_get_driver_version(void);
*
* @return STSxx_ADDRESS
*/
u8 sts_get_configured_sts_address(void);
uint8_t sts_get_configured_sts_address(void);

#ifdef __cplusplus
}
Expand Down
12 changes: 6 additions & 6 deletions sts-common/sts_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@
#include "sensirion_i2c.h"
#include "sts.h"

s8 sts_common_read_ticks(u8 address, s32 *temperature_ticks) {
u8 data[3];
s8 ret = sensirion_i2c_read(address, data, sizeof(data));
int8_t sts_common_read_ticks(uint8_t address, int32_t *temperature_ticks) {
uint8_t data[3];
int8_t ret = sensirion_i2c_read(address, data, sizeof(data));
if (ret)
return ret;
if (sensirion_common_check_crc(data, 2, data[2])) {
return STATUS_CRC_FAIL;
}

*temperature_ticks = (data[1] & 0xff) | ((s32)data[0] << 8);
*temperature_ticks = (data[1] & 0xff) | ((int32_t)data[0] << 8);

return STATUS_OK;
}

s8 sts_common_read_measurement(u8 address, s32 *temperature) {
s8 ret = sts_common_read_ticks(address, temperature);
int8_t sts_common_read_measurement(uint8_t address, int32_t *temperature) {
int8_t ret = sts_common_read_ticks(address, temperature);
/**
* formulas for conversion of the sensor signals, optimized for fixed point
* algebra: Temperature = 175 * S_T / 2^16 - 45
Expand Down
4 changes: 2 additions & 2 deletions sts-common/sts_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
extern "C" {
#endif

s8 sts_common_read_ticks(u8 address, s32 *temperature_ticks);
int8_t sts_common_read_ticks(uint8_t address, int32_t *temperature_ticks);

s8 sts_common_read_measurement(u8 address, s32 *temperature);
int8_t sts_common_read_measurement(uint8_t address, int32_t *temperature);

#ifdef __cplusplus
}
Expand Down
50 changes: 25 additions & 25 deletions sts3x/sts3x.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,49 @@

/* all measurement commands return T (CRC) RH (CRC) */
#if USE_SENSIRION_CLOCK_STRETCHING
static const u8 CMD_MEASURE_HPM[] = {0x2C, 0x06};
static const u8 CMD_MEASURE_MPM[] = {0x2C, 0x0D};
static const u8 CMD_MEASURE_LPM[] = {0x2C, 0x10};
static const uint8_t CMD_MEASURE_HPM[] = {0x2C, 0x06};
static const uint8_t CMD_MEASURE_MPM[] = {0x2C, 0x0D};
static const uint8_t CMD_MEASURE_LPM[] = {0x2C, 0x10};
#else
static const u8 CMD_MEASURE_HPM[] = {0x24, 0x00};
static const u8 CMD_MEASURE_MPM[] = {0x24, 0x0B};
static const u8 CMD_MEASURE_LPM[] = {0x24, 0x16};
static const uint8_t CMD_MEASURE_HPM[] = {0x24, 0x00};
static const uint8_t CMD_MEASURE_MPM[] = {0x24, 0x0B};
static const uint8_t CMD_MEASURE_LPM[] = {0x24, 0x16};
#endif /* USE_SENSIRION_CLOCK_STRETCHING */
static const u8 CMD_READ_STATUS_REG[] = {0xF3, 0x2D};
static const u8 CMD_HEATER_ON[] = {0x30, 0x6D};
static const u8 CMD_HEATER_OFF[] = {0x30, 0x66};
static const u8 COMMAND_SIZE = sizeof(CMD_MEASURE_HPM);
static const uint8_t CMD_READ_STATUS_REG[] = {0xF3, 0x2D};
static const uint8_t CMD_HEATER_ON[] = {0x30, 0x6D};
static const uint8_t CMD_HEATER_OFF[] = {0x30, 0x66};
static const uint8_t COMMAND_SIZE = sizeof(CMD_MEASURE_HPM);
#ifdef STS_ADDRESS
static const u8 STS3X_ADDRESS = STS_ADDRESS;
static const uint8_t STS3X_ADDRESS = STS_ADDRESS;
#else
static const u8 STS3X_ADDRESS = 0x4A;
static const uint8_t STS3X_ADDRESS = 0x4A;
#endif

static const u16 MEASUREMENT_DURATION_USEC = 15000;
static const uint16_t MEASUREMENT_DURATION_USEC = 15000;

static const u8 *cmd_measure = CMD_MEASURE_HPM;
static const uint8_t *cmd_measure = CMD_MEASURE_HPM;

s8 sts_measure_blocking_read(s32 *temperature) {
s8 ret = sts_measure();
int8_t sts_measure_blocking_read(int32_t *temperature) {
int8_t ret = sts_measure();
if (ret == STATUS_OK) {
sensirion_sleep_usec(MEASUREMENT_DURATION_USEC);
ret = sts_read(temperature);
}
return ret;
}

s8 sts_measure() {
int8_t sts_measure() {
return sensirion_i2c_write(STS3X_ADDRESS, CMD_MEASURE_HPM, COMMAND_SIZE);
}

s8 sts_read(s32 *temperature) {
int8_t sts_read(int32_t *temperature) {
return sts_common_read_measurement(STS3X_ADDRESS, temperature);
}

s8 sts_probe() {
u8 data[3];
int8_t sts_probe() {
uint8_t data[3];
sensirion_i2c_init();
s8 ret =
int8_t ret =
sensirion_i2c_write(STS3X_ADDRESS, CMD_READ_STATUS_REG, COMMAND_SIZE);
if (ret)
return ret;
Expand All @@ -103,7 +103,7 @@ s8 sts_probe() {
return STATUS_OK;
}

void sts_set_repeatability(u8 repeatability) {
void sts_set_repeatability(uint8_t repeatability) {
switch (repeatability) {
case 2:
cmd_measure = CMD_MEASURE_LPM;
Expand All @@ -118,18 +118,18 @@ void sts_set_repeatability(u8 repeatability) {
}
}

s8 sts_heater_on(void) {
int8_t sts_heater_on(void) {
return sensirion_i2c_write(STS3X_ADDRESS, CMD_HEATER_ON, COMMAND_SIZE);
}

s8 sts_heater_off(void) {
int8_t sts_heater_off(void) {
return sensirion_i2c_write(STS3X_ADDRESS, CMD_HEATER_OFF, COMMAND_SIZE);
}

const char *sts_get_driver_version() {
return STS_DRV_VERSION_STR;
}

u8 sts_get_configured_sts_address() {
uint8_t sts_get_configured_sts_address() {
return STS3X_ADDRESS;
}

0 comments on commit f7b9b7f

Please sign in to comment.