Skip to content

Commit 9a6924a

Browse files
authored
Merge pull request #24 from Sensirion/stdint
Automated type conversion
2 parents 4823308 + e970128 commit 9a6924a

File tree

7 files changed

+79
-75
lines changed

7 files changed

+79
-75
lines changed

embedded-common

sht-common/example_usage.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ int main(void) {
5050
/* printf("SHT sensor probing successful\n"); */
5151

5252
while (1) {
53-
s32 temperature, humidity;
53+
int32_t temperature, humidity;
5454
/* Measure temperature and relative humidity and store into variables
5555
* temperature, humidity (each output multiplied by 1000).
5656
*/
57-
s8 ret = sht_measure_blocking_read(&temperature, &humidity);
57+
int8_t ret = sht_measure_blocking_read(&temperature, &humidity);
5858
if (ret == STATUS_OK) {
5959
/* printf("measured temperature: %0.2f degreeCelsius, "
6060
"measured humidity: %0.2f percentRH\n",

sht-common/sht.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extern "C" {
6060
*
6161
* @return 0 if a sensor was detected
6262
*/
63-
s8 sht_probe(void);
63+
int8_t sht_probe(void);
6464

6565
/**
6666
* Starts a measurement and then reads out the results. This function blocks
@@ -75,7 +75,7 @@ s8 sht_probe(void);
7575
* measurement
7676
* @return 0 if the command was successful, else an error code.
7777
*/
78-
s8 sht_measure_blocking_read(s32 *temperature, s32 *humidity);
78+
int8_t sht_measure_blocking_read(int32_t *temperature, int32_t *humidity);
7979

8080
/**
8181
* Starts a measurement in high precision mode. Use sht_read() to read out the
@@ -84,7 +84,7 @@ s8 sht_measure_blocking_read(s32 *temperature, s32 *humidity);
8484
*
8585
* @return 0 if the command was successful, else an error code.
8686
*/
87-
s8 sht_measure(void);
87+
int8_t sht_measure(void);
8888

8989
/**
9090
* Reads out the results of a measurement that was previously started by
@@ -99,7 +99,7 @@ s8 sht_measure(void);
9999
* measurement
100100
* @return 0 if the command was successful, else an error code.
101101
*/
102-
s8 sht_read(s32 *temperature, s32 *humidity);
102+
int8_t sht_read(int32_t *temperature, int32_t *humidity);
103103

104104
/**
105105
* Enable or disable the SHT's sleep mode between measurements, if supported.
@@ -110,14 +110,14 @@ s8 sht_read(s32 *temperature, s32 *humidity);
110110
* @return 0 if the command was successful,
111111
* 1 if an error occured or if sleep mode is not supported
112112
*/
113-
s8 sht_disable_sleep(u8 disable_sleep);
113+
int8_t sht_disable_sleep(uint8_t disable_sleep);
114114

115115
/**
116116
* Enable or disable the SHT's low power mode
117117
*
118118
* @param enable_low_power_mode 1 to enable low power mode, 0 to disable
119119
*/
120-
void sht_enable_low_power_mode(u8 enable_low_power_mode);
120+
void sht_enable_low_power_mode(uint8_t enable_low_power_mode);
121121

122122
/**
123123
* sht_get_driver_version() - Return the driver version
@@ -131,7 +131,7 @@ const char *sht_get_driver_version(void);
131131
*
132132
* @return SHTxx_ADDRESS
133133
*/
134-
u8 sht_get_configured_sht_address(void);
134+
uint8_t sht_get_configured_sht_address(void);
135135

136136
#ifdef __cplusplus
137137
}

sht-common/sht_common.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,26 @@
4141
#include "sensirion_i2c.h"
4242
#include "sht.h"
4343

44-
s8 sht_common_read_ticks(u8 address, s32 *temperature_ticks,
45-
s32 *humidity_ticks) {
46-
u8 data[6];
47-
s8 ret = sensirion_i2c_read(address, data, sizeof(data));
44+
int8_t sht_common_read_ticks(uint8_t address, int32_t *temperature_ticks,
45+
int32_t *humidity_ticks) {
46+
uint8_t data[6];
47+
int8_t ret = sensirion_i2c_read(address, data, sizeof(data));
4848
if (ret)
4949
return ret;
5050
if (sensirion_common_check_crc(data, 2, data[2]) ||
5151
sensirion_common_check_crc(data + 3, 2, data[5])) {
5252
return STATUS_CRC_FAIL;
5353
}
5454

55-
*temperature_ticks = (data[1] & 0xff) | ((s32)data[0] << 8);
56-
*humidity_ticks = (data[4] & 0xff) | ((s32)data[3] << 8);
55+
*temperature_ticks = (data[1] & 0xff) | ((int32_t)data[0] << 8);
56+
*humidity_ticks = (data[4] & 0xff) | ((int32_t)data[3] << 8);
5757

5858
return STATUS_OK;
5959
}
6060

61-
s8 sht_common_read_measurement(u8 address, s32 *temperature, s32 *humidity) {
62-
s8 ret = sht_common_read_ticks(address, temperature, humidity);
61+
int8_t sht_common_read_measurement(uint8_t address, int32_t *temperature,
62+
int32_t *humidity) {
63+
int8_t ret = sht_common_read_ticks(address, temperature, humidity);
6364
/**
6465
* formulas for conversion of the sensor signals, optimized for fixed point
6566
* algebra: Temperature = 175 * S_T / 2^16 - 45 Relative Humidity =

sht-common/sht_common.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
extern "C" {
3939
#endif
4040

41-
s8 sht_common_read_ticks(u8 address, s32 *temperature_ticks,
42-
s32 *humidity_ticks);
41+
int8_t sht_common_read_ticks(uint8_t address, int32_t *temperature_ticks,
42+
int32_t *humidity_ticks);
4343

44-
s8 sht_common_read_measurement(u8 address, s32 *temperature, s32 *humidity);
44+
int8_t sht_common_read_measurement(uint8_t address, int32_t *temperature,
45+
int32_t *humidity);
4546

4647
#ifdef __cplusplus
4748
}

sht3x/sht3x.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,45 +46,45 @@
4646

4747
/* all measurement commands return T (CRC) RH (CRC) */
4848
#if USE_SENSIRION_CLOCK_STRETCHING
49-
static const u8 CMD_MEASURE_HPM[] = {0x2C, 0x06};
50-
static const u8 CMD_MEASURE_LPM[] = {0x2C, 0x10};
49+
static const uint8_t CMD_MEASURE_HPM[] = {0x2C, 0x06};
50+
static const uint8_t CMD_MEASURE_LPM[] = {0x2C, 0x10};
5151
#else
52-
static const u8 CMD_MEASURE_HPM[] = {0x24, 0x00};
53-
static const u8 CMD_MEASURE_LPM[] = {0x24, 0x16};
52+
static const uint8_t CMD_MEASURE_HPM[] = {0x24, 0x00};
53+
static const uint8_t CMD_MEASURE_LPM[] = {0x24, 0x16};
5454
#endif /* USE_SENSIRION_CLOCK_STRETCHING */
55-
static const u8 CMD_READ_STATUS_REG[] = {0xF3, 0x2D};
56-
static const u8 COMMAND_SIZE = sizeof(CMD_MEASURE_HPM);
55+
static const uint8_t CMD_READ_STATUS_REG[] = {0xF3, 0x2D};
56+
static const uint8_t COMMAND_SIZE = sizeof(CMD_MEASURE_HPM);
5757
#ifdef SHT_ADDRESS
58-
static const u8 SHT3X_ADDRESS = SHT_ADDRESS;
58+
static const uint8_t SHT3X_ADDRESS = SHT_ADDRESS;
5959
#else
60-
static const u8 SHT3X_ADDRESS = 0x44;
60+
static const uint8_t SHT3X_ADDRESS = 0x44;
6161
#endif
6262

63-
static const u16 MEASUREMENT_DURATION_USEC = 15000;
63+
static const uint16_t MEASUREMENT_DURATION_USEC = 15000;
6464

65-
static const u8 *cmd_measure = CMD_MEASURE_HPM;
65+
static const uint8_t *cmd_measure = CMD_MEASURE_HPM;
6666

67-
s8 sht_measure_blocking_read(s32 *temperature, s32 *humidity) {
68-
s8 ret = sht_measure();
67+
int8_t sht_measure_blocking_read(int32_t *temperature, int32_t *humidity) {
68+
int8_t ret = sht_measure();
6969
if (ret == STATUS_OK) {
7070
sensirion_sleep_usec(MEASUREMENT_DURATION_USEC);
7171
ret = sht_read(temperature, humidity);
7272
}
7373
return ret;
7474
}
7575

76-
s8 sht_measure() {
76+
int8_t sht_measure() {
7777
return sensirion_i2c_write(SHT3X_ADDRESS, CMD_MEASURE_HPM, COMMAND_SIZE);
7878
}
7979

80-
s8 sht_read(s32 *temperature, s32 *humidity) {
80+
int8_t sht_read(int32_t *temperature, int32_t *humidity) {
8181
return sht_common_read_measurement(SHT3X_ADDRESS, temperature, humidity);
8282
}
8383

84-
s8 sht_probe() {
85-
u8 data[3];
84+
int8_t sht_probe() {
85+
uint8_t data[3];
8686
sensirion_i2c_init();
87-
s8 ret =
87+
int8_t ret =
8888
sensirion_i2c_write(SHT3X_ADDRESS, CMD_READ_STATUS_REG, COMMAND_SIZE);
8989
if (ret)
9090
return ret;
@@ -99,18 +99,18 @@ s8 sht_probe() {
9999
return STATUS_OK;
100100
}
101101

102-
s8 sht_disable_sleep(u8 disable_sleep) {
102+
int8_t sht_disable_sleep(uint8_t disable_sleep) {
103103
return STATUS_FAIL; /* sleep mode not supported */
104104
}
105105

106-
void sht_enable_low_power_mode(u8 enable_low_power_mode) {
106+
void sht_enable_low_power_mode(uint8_t enable_low_power_mode) {
107107
cmd_measure = enable_low_power_mode ? CMD_MEASURE_LPM : CMD_MEASURE_HPM;
108108
}
109109

110110
const char *sht_get_driver_version() {
111111
return SHT_DRV_VERSION_STR;
112112
}
113113

114-
u8 sht_get_configured_sht_address() {
114+
uint8_t sht_get_configured_sht_address() {
115115
return SHT3X_ADDRESS;
116116
}

shtc1/shtc1.c

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,30 @@
4848

4949
/* all measurement commands return T (CRC) RH (CRC) */
5050
#if USE_SENSIRION_CLOCK_STRETCHING
51-
static const u8 CMD_MEASURE_HPM[] = {0x7C, 0xA2};
52-
static const u8 CMD_MEASURE_LPM[] = {0x64, 0x58};
51+
static const uint8_t CMD_MEASURE_HPM[] = {0x7C, 0xA2};
52+
static const uint8_t CMD_MEASURE_LPM[] = {0x64, 0x58};
5353
#else
54-
static const u8 CMD_MEASURE_HPM[] = {0x78, 0x66};
55-
static const u8 CMD_MEASURE_LPM[] = {0x60, 0x9C};
56-
static const u16 MEASUREMENT_DURATION_USEC = 14400;
54+
static const uint8_t CMD_MEASURE_HPM[] = {0x78, 0x66};
55+
static const uint8_t CMD_MEASURE_LPM[] = {0x60, 0x9C};
56+
static const uint16_t MEASUREMENT_DURATION_USEC = 14400;
5757
#endif /* USE_SENSIRION_CLOCK_STRETCHING */
58-
static const u8 CMD_READ_ID_REG[] = {0xef, 0xc8};
59-
static const u8 COMMAND_SIZE = sizeof(CMD_MEASURE_HPM);
58+
static const uint8_t CMD_READ_ID_REG[] = {0xef, 0xc8};
59+
static const uint8_t COMMAND_SIZE = sizeof(CMD_MEASURE_HPM);
6060

61-
static const u8 SHTC3_CMD_SLEEP[] = {0xB0, 0x98};
62-
static const u8 SHTC3_CMD_WAKEUP[] = {0x35, 0x17};
61+
static const uint8_t SHTC3_CMD_SLEEP[] = {0xB0, 0x98};
62+
static const uint8_t SHTC3_CMD_WAKEUP[] = {0x35, 0x17};
6363
#ifdef SHT_ADDRESS
64-
static const u8 SHTC1_ADDRESS = SHT_ADDRESS;
64+
static const uint8_t SHTC1_ADDRESS = SHT_ADDRESS;
6565
#else
66-
static const u8 SHTC1_ADDRESS = 0x70;
66+
static const uint8_t SHTC1_ADDRESS = 0x70;
6767
#endif
6868

69-
static const u16 SHTC1_PRODUCT_CODE_MASK = 0x001F;
70-
static const u16 SHTC1_PRODUCT_CODE = 0x0007;
71-
static const u16 SHTC3_PRODUCT_CODE_MASK = 0x083F;
72-
static const u16 SHTC3_PRODUCT_CODE = 0x0807;
69+
static const uint16_t SHTC1_PRODUCT_CODE_MASK = 0x001F;
70+
static const uint16_t SHTC1_PRODUCT_CODE = 0x0007;
71+
static const uint16_t SHTC3_PRODUCT_CODE_MASK = 0x083F;
72+
static const uint16_t SHTC3_PRODUCT_CODE = 0x0807;
7373

74-
static const u8 *cmd_measure = CMD_MEASURE_HPM;
74+
static const uint8_t *cmd_measure = CMD_MEASURE_HPM;
7575

7676
/**
7777
* PM_SLEEP is equivalent to
@@ -98,25 +98,25 @@ static const u8 *cmd_measure = CMD_MEASURE_HPM;
9898
(((ret) = sht_wakeup()) ? (sht_sleep(), (ret)) \
9999
: ((ret) = (cmd) ? sht_sleep(), (ret) : (ret)))
100100

101-
static u8 supports_sleep = 1;
102-
static u8 sleep_enabled = 1;
101+
static uint8_t supports_sleep = 1;
102+
static uint8_t sleep_enabled = 1;
103103

104-
static u8 sht_sleep() {
104+
static uint8_t sht_sleep() {
105105
if (!supports_sleep || !sleep_enabled)
106106
return STATUS_OK;
107107

108108
return sensirion_i2c_write(SHTC1_ADDRESS, SHTC3_CMD_SLEEP, COMMAND_SIZE);
109109
}
110110

111-
static u8 sht_wakeup() {
111+
static uint8_t sht_wakeup() {
112112
if (!supports_sleep || !sleep_enabled)
113113
return STATUS_OK;
114114

115115
return sensirion_i2c_write(SHTC1_ADDRESS, SHTC3_CMD_WAKEUP, COMMAND_SIZE);
116116
}
117117

118-
s8 sht_measure_blocking_read(s32 *temperature, s32 *humidity) {
119-
s8 ret;
118+
int8_t sht_measure_blocking_read(int32_t *temperature, int32_t *humidity) {
119+
int8_t ret;
120120

121121
PM_WAKE(ret, sht_measure());
122122
#if !defined(USE_SENSIRION_CLOCK_STRETCHING) || !USE_SENSIRION_CLOCK_STRETCHING
@@ -126,25 +126,27 @@ s8 sht_measure_blocking_read(s32 *temperature, s32 *humidity) {
126126
return PM_SLEEP(ret);
127127
}
128128

129-
s8 sht_measure() {
130-
s8 ret;
129+
int8_t sht_measure() {
130+
int8_t ret;
131131

132132
return PM_WAKE(
133133
ret, sensirion_i2c_write(SHTC1_ADDRESS, cmd_measure, COMMAND_SIZE));
134134
}
135135

136-
s8 sht_read(s32 *temperature, s32 *humidity) {
137-
s8 ret = sht_common_read_measurement(SHTC1_ADDRESS, temperature, humidity);
136+
int8_t sht_read(int32_t *temperature, int32_t *humidity) {
137+
int8_t ret =
138+
sht_common_read_measurement(SHTC1_ADDRESS, temperature, humidity);
138139

139140
return PM_SLEEP(ret);
140141
}
141142

142-
s8 sht_probe() {
143-
u8 data[3];
144-
u16 id;
143+
int8_t sht_probe() {
144+
uint8_t data[3];
145+
uint16_t id;
145146

146147
sensirion_i2c_init();
147-
s8 ret = sensirion_i2c_write(SHTC1_ADDRESS, CMD_READ_ID_REG, COMMAND_SIZE);
148+
int8_t ret =
149+
sensirion_i2c_write(SHTC1_ADDRESS, CMD_READ_ID_REG, COMMAND_SIZE);
148150
if (ret) {
149151
/* SHTC3 that's sleeping? */
150152
if (sht_wakeup())
@@ -163,7 +165,7 @@ s8 sht_probe() {
163165
if (ret)
164166
return ret;
165167

166-
id = ((u16)data[0] << 8) | data[1];
168+
id = ((uint16_t)data[0] << 8) | data[1];
167169
if ((id & SHTC3_PRODUCT_CODE_MASK) == SHTC3_PRODUCT_CODE) {
168170
supports_sleep = 1;
169171
return sht_sleep();
@@ -177,7 +179,7 @@ s8 sht_probe() {
177179
return STATUS_UNKNOWN_DEVICE;
178180
}
179181

180-
s8 sht_disable_sleep(u8 disable_sleep) {
182+
int8_t sht_disable_sleep(uint8_t disable_sleep) {
181183
if (!supports_sleep)
182184
return STATUS_FAIL;
183185

@@ -189,14 +191,14 @@ s8 sht_disable_sleep(u8 disable_sleep) {
189191
return sht_sleep();
190192
}
191193

192-
void sht_enable_low_power_mode(u8 enable_low_power_mode) {
194+
void sht_enable_low_power_mode(uint8_t enable_low_power_mode) {
193195
cmd_measure = enable_low_power_mode ? CMD_MEASURE_LPM : CMD_MEASURE_HPM;
194196
}
195197

196198
const char *sht_get_driver_version() {
197199
return SHT_DRV_VERSION_STR;
198200
}
199201

200-
u8 sht_get_configured_sht_address() {
202+
uint8_t sht_get_configured_sht_address() {
201203
return SHTC1_ADDRESS;
202204
}

0 commit comments

Comments
 (0)