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/initial-driver
Browse files Browse the repository at this point in the history
Initial SCD30 driver
  • Loading branch information
abrauchli committed Jul 20, 2018
2 parents 61275d0 + f57d29c commit 5642169
Show file tree
Hide file tree
Showing 12 changed files with 767 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
*.o
/release
/scd30/scd_git_version.c
/scd30/scd30_example_usage_hw_i2c
/scd30/scd30_example_usage_sw_i2c
2 changes: 1 addition & 1 deletion .gitmodules
@@ -1,3 +1,3 @@
[submodule "embedded-common"]
path = embedded-common
url = ./embedded-common
url = https://github.com/Sensirion/embedded-common.git
1 change: 1 addition & 0 deletions AUTHORS
@@ -0,0 +1 @@
Andreas Brauchli <andreas.brauchli@sensirion.com>
29 changes: 29 additions & 0 deletions LICENSE
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2018, 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.
42 changes: 42 additions & 0 deletions Makefile
@@ -0,0 +1,42 @@
drivers=scd30
clean_drivers=$(foreach d, $(drivers), clean_$(d))
release_drivers=$(foreach d, $(drivers), release/$(d))

.PHONY: FORCE all $(release_drivers) $(clean_drivers)

all: $(drivers)

$(drivers): scd30/scd_git_version.c FORCE
cd $@ && $(MAKE) $(MFLAGS)

scd30/scd_git_version.c: FORCE
git describe --always --dirty | \
awk 'BEGIN \
{print "/* THIS FILE IS AUTOGENERATED */"} \
{print "#include \"scd_git_version.h\""} \
{print "const char * SCD_DRV_VERSION_STR = \"" $$0"\";"} \
END {}' > $@

$(release_drivers): scd30/scd_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 $${driver}/* "$${pkgdir}" && \
perl -pi -e 's/^sensirion_common_dir :=.*$$/sensirion_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 scd30/scd_git_version.c
47 changes: 47 additions & 0 deletions README.md
@@ -0,0 +1,47 @@
# embedded-scd
This repository contains the embedded driver sources for Sensirion's SCD product
line.

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

## Repository content
* embedded-common (submodule repository for the common embedded driver HAL)
* scd30 (SCD30 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.

---
42 changes: 42 additions & 0 deletions scd30/Makefile
@@ -0,0 +1,42 @@
sensirion_common_dir := ../embedded-common
scd_common_dir := .
sw_i2c_dir := ${sensirion_common_dir}/sw_i2c
hw_i2c_dir := ${sensirion_common_dir}/hw_i2c

CFLAGS := -Os -Wall -Werror -I. -I${sensirion_common_dir}

sensirion_common_objects := sensirion_common.o
scd_common_objects := scd_git_version.o
scd30_binaries := scd30_example_usage_sw_i2c scd30_example_usage_hw_i2c
scd_binaries += ${scd30_binaries}

sw_objects := sensirion_sw_i2c.o sensirion_sw_i2c_implementation.o
hw_objects := sensirion_hw_i2c_implementation.o
all_objects := ${sensirion_common_objects} ${scd_common_objects} ${hw_objects} ${sw_objects} scd30.o

.PHONY: all

all: ${scd_binaries}

scd_git_version.o: ${scd_common_dir}/scd_git_version.c
$(CC) $(CFLAGS) -c -o $@ $^
sensirion_common.o: ${sensirion_common_dir}/sensirion_common.c
$(CC) $(CFLAGS) -c -o $@ $^
sensirion_sw_i2c_implementation.o: ${sw_i2c_dir}/sample-implementations/linux_user_space/sensirion_sw_i2c_implementation.c
$(CC) -I${sw_i2c_dir} $(CFLAGS) -c -o $@ $^
sensirion_hw_i2c_implementation.o: ${hw_i2c_dir}/sensirion_hw_i2c_implementation.c
$(CC) $(CFLAGS) -c -o $@ $^

sensirion_sw_i2c.o: ${sw_i2c_dir}/sensirion_sw_i2c.c
$(CC) -I${sw_i2c_dir} $(CFLAGS) -c -o $@ $^

scd30.o: ${sensirion_common_dir}/sensirion_arch_config.h ${sensirion_common_dir}/sensirion_i2c.h ${scd_common_dir}/scd_git_version.c scd30.h scd30.c

scd30_example_usage_sw_i2c: ${sensirion_common_objects} ${scd_common_objects} ${sw_objects} scd30.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS) scd30_example_usage.c

scd30_example_usage_hw_i2c: ${sensirion_common_objects} ${scd_common_objects} ${hw_objects} scd30.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS) scd30_example_usage.c

clean:
$(RM) ${all_objects} ${scd_binaries}

0 comments on commit 5642169

Please sign in to comment.