Skip to content

Commit

Permalink
Merge branch 'sht4x_2.1.1_20240411_1411' into 'master'
Browse files Browse the repository at this point in the history
Generate SHT4x driver from SHT4X model version 2.1.1

See merge request MSO-SW/drivers/raspberry-pi/raspberry-pi-i2c-sht4x!5
  • Loading branch information
psachs committed Apr 11, 2024
2 parents 3e0173e + 419b248 commit ac1153b
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/sht4x_i2c_example_usage
/example-usage/sht4x_i2c_example_usage
/tests/sht4x_test_hw_i2c
/tests/sht4x_test_sw_i2c
27 changes: 18 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
# Changelog
All notable changes to this project will be documented in this file.
# CHANGELOG

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [Unreleased]
## [1.1.0] - 2024-4-10

Updated README
Moved example to subfolder
Added more specific defines for the I2C Addresses of different SHT4x sensors in the sht4x_i2c header.
The I2C address must now be configured with sht4x_init() before communicating with the sensor.
### Fixed

- Fix colliding definitions with other Sensirion sensor drivers
## [1.0.0] - 2024-3-14

## [0.1.0] - 2021-07-27
### Changed

Initial release
- Defined I2C addresses for different sensor models. You must now pass the I2C address to use in the begin() method of SensirionI2cSht4x
- Improved README
## [0.1.0] - 2021-7-27

### Added

- Add product picture
- Add interfaces to start, stop and read measurements.
- Add interfaces to read product name, serial number and version

[Unreleased]: https://github.com/Sensirion/raspberry-pi-i2c-sht4x/compare/1.1.0...HEAD
[1.1.0]: https://github.com/Sensirion/raspberry-pi-i2c-sht4x/compare/1.0.0...1.1.0
[1.0.0]: https://github.com/Sensirion/raspberry-pi-i2c-sht4x/compare/0.1.0...1.0.0
[0.1.0]: https://github.com/Sensirion/raspberry-pi-i2c-sht4x/releases/tag/0.1.0
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2023, Sensirion AG
Copyright (c) 2024, Sensirion AG
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Please refer to the datasheet for proper circuit setup. There are also 3rd party

| *Pin* | *Cable Color* | *Name* | *Description* | *Comments* |
|-------|---------------|:------:|----------------|------------|
| 1 | green | SDA | I2C: Serial data input / output |
| 2 | black | GND | Ground |
| 3 | yellow | SCL | I2C: Serial clock input |
| 1 | green | SDA | I2C: Serial data input / output |
| 2 | black | GND | Ground |
| 3 | yellow | SCL | I2C: Serial clock input |
| 4 | red | VDD | Supply Voltage | 1.1V to 3.6V


Expand All @@ -57,9 +57,9 @@ Please refer to the datasheet for proper circuit setup. There are also 3rd party
- [Enable the I²C interface in the raspi-config](https://www.raspberrypi.org/documentation/configuration/raspi-config.md)
- Download the SHT4X driver from [Github](https://github.com/Sensirion/raspberry-pi-i2c-sht4x) and extract the `.zip` on your Raspberry Pi
- Connect the SHT4X sensor as explained in the [section above](#connect-the-sensor)
- - The provided example is working with a SHT40, I²C address 0x44.
- The provided example is working with a SHT40, I²C address 0x44.
In order to use the code with another product or I²C address you need to change it in the call sht4x_init(ADDRESS) in
`sht4x_i2c_example_usage.c`. The list of supported I²C-addresses is found in the header
`sht4x_i2c_example_usage.c`. The list of supported I²C-addresses is found in the header
`sht4x_i2c.h`.

- Compile the driver
Expand Down
9 changes: 5 additions & 4 deletions example-usage/sht4x_i2c_example_usage.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* THIS FILE IS AUTOMATICALLY GENERATED
*
* Generator: sensirion-driver-generator 0.32.0
* Generator: sensirion-driver-generator 0.40.0
* Product: sht4x
* Model-Version: 2.0.0
* Model-Version: 2.1.1
*/
/*
* Copyright (c) 2023, Sensirion AG
* Copyright (c) 2024, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -38,7 +38,8 @@
#include "sensirion_common.h"
#include "sensirion_i2c_hal.h"
#include "sht4x_i2c.h"
#include <stdio.h> // printf
#include <inttypes.h> // PRIx64
#include <stdio.h> // printf

#define sensirion_hal_sleep_us sensirion_i2c_hal_sleep_usec

Expand Down
6 changes: 3 additions & 3 deletions metadata.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
generator_version: 0.32.0
model_version: 2.0.0
generator_version: 0.40.0
model_version: 2.1.1
dg_status:
- released
is_manually_modified: true
first_generated: '2021-07-06 13:50'
last_generated: '2023-10-18 07:38'
last_generated: '2024-04-11 14:11'
43 changes: 31 additions & 12 deletions sensirion_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,27 @@ float sensirion_common_bytes_to_float(const uint8_t* bytes) {
}

void sensirion_common_uint32_t_to_bytes(const uint32_t value, uint8_t* bytes) {
bytes[0] = value >> 24;
bytes[1] = value >> 16;
bytes[2] = value >> 8;
bytes[3] = value;
bytes[0] = (uint8_t)(value >> 24);
bytes[1] = (uint8_t)(value >> 16);
bytes[2] = (uint8_t)(value >> 8);
bytes[3] = (uint8_t)(value);
}

void sensirion_common_uint16_t_to_bytes(const uint16_t value, uint8_t* bytes) {
bytes[0] = value >> 8;
bytes[1] = value;
bytes[0] = (uint8_t)(value >> 8);
bytes[1] = (uint8_t)value;
}

void sensirion_common_int32_t_to_bytes(const int32_t value, uint8_t* bytes) {
bytes[0] = value >> 24;
bytes[1] = value >> 16;
bytes[2] = value >> 8;
bytes[3] = value;
bytes[0] = (uint8_t)(value >> 24);
bytes[1] = (uint8_t)(value >> 16);
bytes[2] = (uint8_t)(value >> 8);
bytes[3] = (uint8_t)value;
}

void sensirion_common_int16_t_to_bytes(const int16_t value, uint8_t* bytes) {
bytes[0] = value >> 8;
bytes[1] = value;
bytes[0] = (uint8_t)(value >> 8);
bytes[1] = (uint8_t)value;
}

void sensirion_common_float_to_bytes(const float value, uint8_t* bytes) {
Expand All @@ -99,3 +99,22 @@ void sensirion_common_copy_bytes(const uint8_t* source, uint8_t* destination,
destination[i] = source[i];
}
}

void sensirion_common_to_integer(const uint8_t* source, uint8_t* destination,
INT_TYPE int_type, uint8_t data_length) {

if (data_length > int_type) {
data_length = 0; // we do not read at all if data_length is bigger than
// the provided integer!
}

// pad missing bytes
uint8_t offset = int_type - data_length;
for (uint8_t i = 0; i < offset; i++) {
destination[int_type - i - 1] = 0;
}

for (uint8_t i = 1; i <= data_length; i++) {
destination[int_type - offset - i] = source[i - 1];
}
}
16 changes: 16 additions & 0 deletions sensirion_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ extern "C" {
#define SENSIRION_NUM_WORDS(x) (sizeof(x) / SENSIRION_WORD_SIZE)
#define SENSIRION_MAX_BUFFER_WORDS 32

/**
* Enum to describe the type of an integer
*/
typedef enum { BYTE = 1, SHORT = 2, INTEGER = 4, LONG_INTEGER = 8 } INT_TYPE;

/**
* sensirion_common_bytes_to_int16_t() - Convert an array of bytes to an int16_t
*
Expand Down Expand Up @@ -174,6 +179,17 @@ void sensirion_common_float_to_bytes(const float value, uint8_t* bytes);
void sensirion_common_copy_bytes(const uint8_t* source, uint8_t* destination,
uint16_t data_length);

/**
* sensirion_common_to_integer() - Copy bytes from byte array to integer.
*
* @param source Array of bytes to be copied.
* @param int_value Pointer to integer of bytes to be copied to.
* @param int_type Type (size) of the integer to be copied.
* @param data_length Number of bytes to copy.
*/
void sensirion_common_to_integer(const uint8_t* source, uint8_t* destination,
INT_TYPE int_type, uint8_t data_length);

#ifdef __cplusplus
}
#endif
Expand Down
50 changes: 25 additions & 25 deletions sht4x_i2c.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* THIS FILE IS AUTOMATICALLY GENERATED
*
* Generator: sensirion-driver-generator 0.32.0
* Generator: sensirion-driver-generator 0.40.0
* Product: sht4x
* Model-Version: 2.0.0
* Model-Version: 2.1.1
*/
/*
* Copyright (c) 2023, Sensirion AG
* Copyright (c) 2024, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -51,17 +51,17 @@ void sht4x_init(uint8_t i2c_address) {
_i2c_address = i2c_address;
}

float signal_temperature(uint16_t temperature_ticks) {
float sht4x_signal_temperature(uint16_t temperature_ticks) {
float temperature = 0.0;
temperature = (float)(temperature_ticks);
temperature = (float)((temperature * 175.0) / 65535.0) - 45.0;
temperature = ((temperature * 175.0) / 65535.0) - 45.0;
return temperature;
}

float signal_humidity(uint16_t humidity_ticks) {
float sht4x_signal_humidity(uint16_t humidity_ticks) {
float humidity = 0.0;
humidity = (float)(humidity_ticks);
humidity = (float)((humidity * 125.0) / 65535.0) - 6.0;
humidity = ((humidity * 125.0) / 65535.0) - 6.0;
return humidity;
}

Expand All @@ -73,8 +73,8 @@ int16_t sht4x_measure_high_precision(float* a_temperature, float* a_humidity) {
if (local_error != NO_ERROR) {
return local_error;
}
*a_temperature = signal_temperature(temp_ticks);
*a_humidity = signal_humidity(humi_ticks);
*a_temperature = sht4x_signal_temperature(temp_ticks);
*a_humidity = sht4x_signal_humidity(humi_ticks);
return local_error;
}

Expand All @@ -88,8 +88,8 @@ int16_t sht4x_measure_medium_precision(float* a_temperature,
if (local_error != NO_ERROR) {
return local_error;
}
*a_temperature = signal_temperature(temp_ticks);
*a_humidity = signal_humidity(humi_ticks);
*a_temperature = sht4x_signal_temperature(temp_ticks);
*a_humidity = sht4x_signal_humidity(humi_ticks);
return local_error;
}

Expand All @@ -103,8 +103,8 @@ int16_t sht4x_measure_lowest_precision(float* a_temperature,
if (local_error != NO_ERROR) {
return local_error;
}
*a_temperature = signal_temperature(temp_ticks);
*a_humidity = signal_humidity(humi_ticks);
*a_temperature = sht4x_signal_temperature(temp_ticks);
*a_humidity = sht4x_signal_humidity(humi_ticks);
return local_error;
}

Expand All @@ -118,8 +118,8 @@ int16_t sht4x_activate_highest_heater_power_long(float* a_temperature,
if (local_error != NO_ERROR) {
return local_error;
}
*a_temperature = signal_temperature(temp_ticks);
*a_humidity = signal_humidity(humi_ticks);
*a_temperature = sht4x_signal_temperature(temp_ticks);
*a_humidity = sht4x_signal_humidity(humi_ticks);
return local_error;
}

Expand All @@ -133,8 +133,8 @@ int16_t sht4x_activate_highest_heater_power_short(float* a_temperature,
if (local_error != NO_ERROR) {
return local_error;
}
*a_temperature = signal_temperature(temp_ticks);
*a_humidity = signal_humidity(humi_ticks);
*a_temperature = sht4x_signal_temperature(temp_ticks);
*a_humidity = sht4x_signal_humidity(humi_ticks);
return local_error;
}

Expand All @@ -148,8 +148,8 @@ int16_t sht4x_activate_medium_heater_power_long(float* a_temperature,
if (local_error != NO_ERROR) {
return local_error;
}
*a_temperature = signal_temperature(temp_ticks);
*a_humidity = signal_humidity(humi_ticks);
*a_temperature = sht4x_signal_temperature(temp_ticks);
*a_humidity = sht4x_signal_humidity(humi_ticks);
return local_error;
}

Expand All @@ -163,8 +163,8 @@ int16_t sht4x_activate_medium_heater_power_short(float* a_temperature,
if (local_error != NO_ERROR) {
return local_error;
}
*a_temperature = signal_temperature(temp_ticks);
*a_humidity = signal_humidity(humi_ticks);
*a_temperature = sht4x_signal_temperature(temp_ticks);
*a_humidity = sht4x_signal_humidity(humi_ticks);
return local_error;
}

Expand All @@ -178,8 +178,8 @@ int16_t sht4x_activate_lowest_heater_power_long(float* a_temperature,
if (local_error != NO_ERROR) {
return local_error;
}
*a_temperature = signal_temperature(temp_ticks);
*a_humidity = signal_humidity(humi_ticks);
*a_temperature = sht4x_signal_temperature(temp_ticks);
*a_humidity = sht4x_signal_humidity(humi_ticks);
return local_error;
}

Expand All @@ -193,8 +193,8 @@ int16_t sht4x_activate_lowest_heater_power_short(float* a_temperature,
if (local_error != NO_ERROR) {
return local_error;
}
*a_temperature = signal_temperature(temp_ticks);
*a_humidity = signal_humidity(humi_ticks);
*a_temperature = sht4x_signal_temperature(temp_ticks);
*a_humidity = sht4x_signal_humidity(humi_ticks);
return local_error;
}

Expand Down
Loading

0 comments on commit ac1153b

Please sign in to comment.