Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated type conversion #23

Merged
merged 1 commit into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
76 changes: 38 additions & 38 deletions sps30-i2c/sps30.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "sensirion_i2c.h"
#include "sps_git_version.h"

static const u8 SPS_I2C_ADDRESS = 0x69;
static const uint8_t SPS_I2C_ADDRESS = 0x69;

#define SPS_CMD_START_MEASUREMENT 0x0010
#define SPS_CMD_START_MEASUREMENT_ARG 0x0300
Expand All @@ -51,24 +51,24 @@ const char *sps_get_driver_version() {
return SPS_DRV_VERSION_STR;
}

s16 sps30_probe() {
int16_t sps30_probe() {
char serial[SPS_MAX_SERIAL_LEN];

sensirion_i2c_init();

return sps30_get_serial(serial);
}

s16 sps30_get_serial(char *serial) {
u16 i;
s16 ret;
int16_t sps30_get_serial(char *serial) {
uint16_t i;
int16_t ret;
union {
char serial[SPS_MAX_SERIAL_LEN];
u16 __enforce_alignment;
uint16_t __enforce_alignment;
} buffer;

ret = sensirion_i2c_read_cmd(SPS_I2C_ADDRESS, SPS_CMD_GET_SERIAL,
(u16 *)buffer.serial,
(uint16_t *)buffer.serial,
SENSIRION_NUM_WORDS(buffer.serial));
if (ret != STATUS_OK)
return ret;
Expand All @@ -83,38 +83,38 @@ s16 sps30_get_serial(char *serial) {
return 0;
}

s16 sps30_start_measurement() {
const u16 arg = SPS_CMD_START_MEASUREMENT_ARG;
int16_t sps30_start_measurement() {
const uint16_t arg = SPS_CMD_START_MEASUREMENT_ARG;

return sensirion_i2c_write_cmd_with_args(SPS_I2C_ADDRESS,
SPS_CMD_START_MEASUREMENT, &arg,
SENSIRION_NUM_WORDS(arg));
}

s16 sps30_stop_measurement() {
int16_t sps30_stop_measurement() {
return sensirion_i2c_write_cmd(SPS_I2C_ADDRESS, SPS_CMD_STOP_MEASUREMENT);
}

s16 sps30_read_data_ready(u16 *data_ready) {
int16_t sps30_read_data_ready(uint16_t *data_ready) {
return sensirion_i2c_read_cmd(SPS_I2C_ADDRESS, SPS_CMD_GET_DATA_READY,
data_ready, SENSIRION_NUM_WORDS(*data_ready));
}

s16 sps30_read_measurement(struct sps30_measurement *measurement) {
s16 ret;
u16 idx;
int16_t sps30_read_measurement(struct sps30_measurement *measurement) {
int16_t ret;
uint16_t idx;
union {
u16 u16[2];
u32 u;
f32 f;
uint16_t uint16_t[2];
uint32_t u;
float32_t f;
} val, data[10];

ret = sensirion_i2c_read_cmd(SPS_I2C_ADDRESS, SPS_CMD_READ_MEASUREMENT,
data->u16, SENSIRION_NUM_WORDS(data));
data->uint16_t, SENSIRION_NUM_WORDS(data));
if (ret != STATUS_OK)
return ret;

SENSIRION_WORDS_TO_BYTES(data->u16, SENSIRION_NUM_WORDS(data));
SENSIRION_WORDS_TO_BYTES(data->uint16_t, SENSIRION_NUM_WORDS(data));

idx = 0;
val.u = be32_to_cpu(data[idx].u);
Expand Down Expand Up @@ -151,27 +151,27 @@ s16 sps30_read_measurement(struct sps30_measurement *measurement) {
return 0;
}

s16 sps30_get_fan_auto_cleaning_interval(u32 *interval_seconds) {
int16_t sps30_get_fan_auto_cleaning_interval(uint32_t *interval_seconds) {
union {
u16 u16[2];
u32 u32;
uint16_t uint16_t[2];
uint32_t uint32_t;
} data;
s16 ret =
sensirion_i2c_read_cmd(SPS_I2C_ADDRESS, SPS_CMD_AUTOCLEAN_INTERVAL,
data.u16, SENSIRION_NUM_WORDS(data.u16));
int16_t ret = sensirion_i2c_read_cmd(
SPS_I2C_ADDRESS, SPS_CMD_AUTOCLEAN_INTERVAL, data.uint16_t,
SENSIRION_NUM_WORDS(data.uint16_t));
if (ret != STATUS_OK)
return ret;

SENSIRION_WORDS_TO_BYTES(data.u16, SENSIRION_NUM_WORDS(data.u16));
*interval_seconds = be32_to_cpu(data.u32);
SENSIRION_WORDS_TO_BYTES(data.uint16_t, SENSIRION_NUM_WORDS(data.uint16_t));
*interval_seconds = be32_to_cpu(data.uint32_t);

return 0;
}

s16 sps30_set_fan_auto_cleaning_interval(u32 interval_seconds) {
s16 ret;
const u16 data[] = {(interval_seconds & 0xFFFF0000) >> 16,
(interval_seconds & 0x0000FFFF) >> 0};
int16_t sps30_set_fan_auto_cleaning_interval(uint32_t interval_seconds) {
int16_t ret;
const uint16_t data[] = {(interval_seconds & 0xFFFF0000) >> 16,
(interval_seconds & 0x0000FFFF) >> 0};

ret = sensirion_i2c_write_cmd_with_args(SPS_I2C_ADDRESS,
SPS_CMD_AUTOCLEAN_INTERVAL, data,
Expand All @@ -180,9 +180,9 @@ s16 sps30_set_fan_auto_cleaning_interval(u32 interval_seconds) {
return ret;
}

s16 sps30_get_fan_auto_cleaning_interval_days(u8 *interval_days) {
s16 ret;
u32 interval_seconds;
int16_t sps30_get_fan_auto_cleaning_interval_days(uint8_t *interval_days) {
int16_t ret;
uint32_t interval_seconds;

ret = sps30_get_fan_auto_cleaning_interval(&interval_seconds);
if (ret < 0)
Expand All @@ -192,11 +192,11 @@ s16 sps30_get_fan_auto_cleaning_interval_days(u8 *interval_days) {
return ret;
}

s16 sps30_set_fan_auto_cleaning_interval_days(u8 interval_days) {
return sps30_set_fan_auto_cleaning_interval((u32)interval_days * 24 * 60 *
60);
int16_t sps30_set_fan_auto_cleaning_interval_days(uint8_t interval_days) {
return sps30_set_fan_auto_cleaning_interval((uint32_t)interval_days * 24 *
60 * 60);
}

s16 sps30_reset() {
int16_t sps30_reset() {
return sensirion_i2c_write_cmd(SPS_I2C_ADDRESS, SPS_CMD_RESET);
}
42 changes: 21 additions & 21 deletions sps30-i2c/sps30.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ extern "C" {
#define SPS_MAX_SERIAL_LEN 32

struct sps30_measurement {
f32 mc_1p0;
f32 mc_2p5;
f32 mc_4p0;
f32 mc_10p0;
f32 nc_0p5;
f32 nc_1p0;
f32 nc_2p5;
f32 nc_4p0;
f32 nc_10p0;
f32 typical_particle_size;
float32_t mc_1p0;
float32_t mc_2p5;
float32_t mc_4p0;
float32_t mc_10p0;
float32_t nc_0p5;
float32_t nc_1p0;
float32_t nc_2p5;
float32_t nc_4p0;
float32_t nc_10p0;
float32_t typical_particle_size;
};

/**
Expand All @@ -68,7 +68,7 @@ const char *sps_get_driver_version(void);
*
* Return: 0 on success, an error code otherwise
*/
s16 sps30_probe();
int16_t sps30_probe();

/**
* sps30_get_serial() - retrieve the serial number
Expand All @@ -79,7 +79,7 @@ s16 sps30_probe();
* terminated). Must be at least SPS_MAX_SERIAL_LEN long.
* Return: 0 on success, an error code otherwise
*/
s16 sps30_get_serial(char *serial);
int16_t sps30_get_serial(char *serial);

/**
* sps30_start_measurement() - start measuring
Expand All @@ -89,14 +89,14 @@ s16 sps30_get_serial(char *serial);
*
* Return: 0 on success, an error code otherwise
*/
s16 sps30_start_measurement();
int16_t sps30_start_measurement();

/**
* sps30_stop_measurement() - stop measuring
*
* Return: 0 on success, an error code otherwise
*/
s16 sps30_stop_measurement();
int16_t sps30_stop_measurement();

/**
* sps30_read_datda_ready() - reads the current data-ready flag
Expand All @@ -107,7 +107,7 @@ s16 sps30_stop_measurement();
* @data_ready: Memory where the data-ready flag (0|1) is stored.
* Return: 0 on success, an error code otherwise
*/
s16 sps30_read_data_ready(u16 *data_ready);
int16_t sps30_read_data_ready(uint16_t *data_ready);

/**
* sps30_read_measurement() - read a measurement
Expand All @@ -116,7 +116,7 @@ s16 sps30_read_data_ready(u16 *data_ready);
*
* Return: 0 on success, an error code otherwise
*/
s16 sps30_read_measurement(struct sps30_measurement *measurement);
int16_t sps30_read_measurement(struct sps30_measurement *measurement);

/**
* sps30_get_fan_auto_cleaning_interval() - read the current(*) auto-cleaning
Expand All @@ -133,7 +133,7 @@ s16 sps30_read_measurement(struct sps30_measurement *measurement);
* @interval_seconds: Memory where the interval in seconds is stored
* Return: 0 on success, an error code otherwise
*/
s16 sps30_get_fan_auto_cleaning_interval(u32 *interval_seconds);
int16_t sps30_get_fan_auto_cleaning_interval(uint32_t *interval_seconds);

/**
* sps30_set_fan_auto_cleaning_interval() - set the current auto-cleaning
Expand All @@ -143,7 +143,7 @@ s16 sps30_get_fan_auto_cleaning_interval(u32 *interval_seconds);
* interval, 0 to disable auto cleaning
* Return: 0 on success, an error code otherwise
*/
s16 sps30_set_fan_auto_cleaning_interval(u32 interval_seconds);
int16_t sps30_set_fan_auto_cleaning_interval(uint32_t interval_seconds);

/**
* sps30_get_fan_auto_cleaning_interval_days() - convenience function to read
Expand All @@ -164,7 +164,7 @@ s16 sps30_set_fan_auto_cleaning_interval(u32 interval_seconds);
* @interval_days: Memory where the interval in days is stored
* Return: 0 on success, an error code otherwise
*/
s16 sps30_get_fan_auto_cleaning_interval_days(u8 *interval_days);
int16_t sps30_get_fan_auto_cleaning_interval_days(uint8_t *interval_days);

/**
* sps30_set_fan_auto_cleaning_interval_days() - convenience function to set the
Expand All @@ -174,7 +174,7 @@ s16 sps30_get_fan_auto_cleaning_interval_days(u8 *interval_days);
* disable auto cleaning
* Return: 0 on success, an error code otherwise
*/
s16 sps30_set_fan_auto_cleaning_interval_days(u8 interval_days);
int16_t sps30_set_fan_auto_cleaning_interval_days(uint8_t interval_days);

/**
* sps30_reset() - reset the SGP30
Expand All @@ -188,7 +188,7 @@ s16 sps30_set_fan_auto_cleaning_interval_days(u8 interval_days);
*
* Return: 0 on success, an error code otherwise
*/
s16 sps30_reset();
int16_t sps30_reset();

#ifdef __cplusplus
}
Expand Down
8 changes: 4 additions & 4 deletions sps30-i2c/sps30_example_usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
int main(void) {
struct sps30_measurement m;
char serial[SPS_MAX_SERIAL_LEN];
u8 auto_clean_days = 4;
u32 auto_clean;
u16 data_ready;
s16 ret;
uint8_t auto_clean_days = 4;
uint32_t auto_clean;
uint16_t data_ready;
int16_t ret;

/* Busy loop for initialization, because the main loop does not work without
* a sensor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void setup() {

void loop() {
struct sps30_measurement measurement;
s16 ret;
int16_t ret;

while (sps30_probe() != 0) {
Serial.write("probe failed\n");
Expand Down