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

Commit

Permalink
Add embedded STS driver
Browse files Browse the repository at this point in the history
* Support for STS3x temperature sensors
* Support measurement in low, medium and high power mode
* Support heater on/off commands for plausability check
  • Loading branch information
psachs committed May 10, 2019
0 parents commit 35203cd
Show file tree
Hide file tree
Showing 16 changed files with 736 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2

jobs:
build:

docker:
- image: gcc:5.5.0

steps:

- checkout

- run:
name: update common repo
command: git submodule update --init
- run: apt update
- run: apt install -y zip
- run: make release
- run: make
- run:
name: make driver
command: |
cd release/sts3x && make && make clean && cd -
11 changes: 11 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 4
AlignAfterOpenBracket: Align
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
IndentCaseLabels: true
SpacesBeforeTrailingComments: 2
...
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.o
/release
/sts3x/sts3x_example_usage_hw_i2c
/sts3x/sts3x_example_usage_sw_i2c
/sts-common/git_version.c
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "embedded-common"]
path = embedded-common
url = https://github.com/Sensirion/embedded-common
9 changes: 9 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Andreas Brauchli <andreas.brauchli@sensirion.com>
Christian Jaeggi <christian.jaeggi@sensirion.com>
Pascal Sachs <pascal.sachs@sensirion.com>
Daniel Lehmann <Daniel.Lehmann@sensirion.com>
David Frey <david.frey@sensirion.com>
Jerome Sieber <jsieber@sensirion.com>
Salomon Diether <salomon.diether@sensirion.com>
Silvan Fischer <silvan.fischer@sensirion.com>
Sven Gruebel <Sven.Gruebel@sensirion.com>
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2019, Sensirion AG
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 changes: 63 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
drivers=sts3x
clean_drivers=$(foreach d, $(drivers), clean_$(d))
release_drivers=$(foreach d, $(drivers), release/$(d))

.PHONY: FORCE all $(release_drivers) $(clean_drivers) style-check style-fix

all: $(drivers)

$(drivers): sts-common/git_version.c FORCE
cd $@ && $(MAKE) $(MFLAGS)

sts-common/git_version.c: FORCE
[ -d ".git" ] && git describe --always --dirty | \
awk 'BEGIN \
{print "/* THIS FILE IS AUTOGENERATED */"} \
{print "#include \"git_version.h\""} \
{print "const char * STS_DRV_VERSION_STR = \"" $$0"\";"} \
END {}' > $@ || echo "Can't update version, not a git repository"


$(release_drivers): sts-common/git_version.c
export rel=$@ && \
export driver=$${rel#release/} && \
export tag="$$(git describe --always --dirty)" && \
export pkgname="$${driver}-$${tag}" && \
export pkgdir="release/$${pkgname}" && \
rm -rf "$${pkgdir}" && mkdir -p "$${pkgdir}" && \
cp -r embedded-common/* "$${pkgdir}" && \
cp -r sts-common/* "$${pkgdir}" && \
cp -r $${driver}/* "$${pkgdir}" && \
perl -pi -e 's/^sensirion_common_dir :=.*$$/sensirion_common_dir := ./' "$${pkgdir}/Makefile" && \
perl -pi -e 's/^sts_common_dir :=.*$$/sts_common_dir := ./' "$${pkgdir}/Makefile" && \
cd "$${pkgdir}" && $(MAKE) $(MFLAGS) && $(MAKE) clean $(MFLAGS) && cd - && \
cd release && zip -r "$${pkgname}.zip" "$${pkgname}" && cd - && \
ln -sf $${pkgname} $@

release: clean $(release_drivers)

$(clean_drivers):
export rel=$@ && \
export driver=$${rel#clean_} && \
cd $${driver} && $(MAKE) clean $(MFLAGS) && cd -

clean: $(clean_drivers)
rm -rf release sts-common/git_version.c

style-fix:
@if [ $$(git status --porcelain -uno 2> /dev/null | wc -l) -gt "0" ]; \
then \
echo "Refusing to run on dirty git state. Commit your changes first."; \
exit 1; \
fi; \
git ls-files | grep -e '\.\(c\|h\|cpp\)$$' | xargs clang-format -i -style=file;

style-check: style-fix
@if [ $$(git status --porcelain -uno 2> /dev/null | wc -l) -gt "0" ]; \
then \
echo "Style check failed:"; \
git diff; \
git checkout -f; \
exit 1; \
fi;

48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# embedded-sts
This repository contains the embedded driver sources for Sensirion's
STS product line.

## Clone this repository
```
git clone --recursive https://github.com/Sensirion/embedded-sts.git
```

## Repository content
* embedded-common (submodule repository for the common embedded driver HAL)
* sts-common (common files for all STSxx drivers)
* sts3x (STS3x driver related)

## Collecting resources
```
make release
```
This will create the `release` folder with the necessary driver files in it,
including a Makefile. That way, you have just ONE folder with all the sources
ready to build your driver for your platform.

## Files to adjust (from embedded-common)
You only need to touch the following files:

* `sensirion_arch_config.h` (architecture specifics, you need to specify
the integer sizes)

and depending on your i2c implementation either of the following:

* `embedded-common/hw_i2c/sensirion_hw_i2c_implementation.c`
functions for hardware i2c communication if your platform supports that
* `embedded-common/sw_i2c/sensirion_sw_i2c_implementation.c`
functions for software i2c communication via GPIOs

## Building the driver
1. Adjust sensirion\_arch\_config.h if you don't have the `<stdint.h>` header
file available
2. Implement necessary functions in one of the `*_implementation.c` files
described above
3. make

---

Please check the [embedded-common](https://github.com/Sensirion/embedded-common)
repository for further information and sample implementations.

---
1 change: 1 addition & 0 deletions embedded-common
Submodule embedded-common added at da2e3c
71 changes: 71 additions & 0 deletions sts-common/example_usage.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2019, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Sensirion AG nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/* #include <stdio.h> // printf
* #include <unistd.h> // sleep
*/
#include "sts.h"

/**
* TO USE CONSOLE OUTPUT (PRINTF) AND WAIT (SLEEP) PLEASE ADAPT THEM TO YOUR
* PLATFORM
*/

int main(void) {

/* Busy loop for initialization, because the main loop does not work without
* a sensor.
*/
while (sts_probe() != STATUS_OK) {
/* printf("STS sensor probing failed\n"); */
/* sleep(1); */
}
/* printf("STS sensor probing successful\n"); */

while (1) {
s32 temperature;
float temperature_degree;
/* Measure temperature and store into variable temperature
* (output is multiplied by 1000).
*/
s8 ret = sts_measure_blocking_read(&temperature);
if (ret == STATUS_OK) {
temperature_degree = temperature / 1000.0f;
/* printf("measured temperature: %0.2f degreeCelsius\n",
temperature_degree); */
} else {
/* printf("error reading measurement\n"); */
}

/* sleep(1); */
}
return 0;
}
37 changes: 37 additions & 0 deletions sts-common/git_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2019, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Sensirion AG nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef GIT_VERSION_H
#define GIT_VERSION_H

extern const char *STS_DRV_VERSION_STR;

#endif /* GIT_VERSION_H */
Loading

0 comments on commit 35203cd

Please sign in to comment.