From 9c2c2c334d07eea079ac330479cd6e6eb495f8c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Eriksson?= Date: Wed, 28 Feb 2024 00:14:17 +0100 Subject: [PATCH] fixed i2c initialization --- examples/Trill-Craft/Makefile | 12 +++++++++ examples/Trill-Craft/Trill-Craft.cpp | 40 ++++++++++++++++++++++++++++ src/dev/trill/I2c.h | 1 + 3 files changed, 53 insertions(+) create mode 100644 examples/Trill-Craft/Makefile create mode 100644 examples/Trill-Craft/Trill-Craft.cpp diff --git a/examples/Trill-Craft/Makefile b/examples/Trill-Craft/Makefile new file mode 100644 index 000000000..5f5b1b2ef --- /dev/null +++ b/examples/Trill-Craft/Makefile @@ -0,0 +1,12 @@ +# Project Name +TARGET = Trill + +# Sources +CPP_SOURCES = Trill-Craft.cpp + +# Library Locations +LIBDAISY_DIR = ../.. + +# Core location, and generic Makefile. +SYSTEM_FILES_DIR = $(LIBDAISY_DIR)/core +include $(SYSTEM_FILES_DIR)/Makefile diff --git a/examples/Trill-Craft/Trill-Craft.cpp b/examples/Trill-Craft/Trill-Craft.cpp new file mode 100644 index 000000000..89fb7e366 --- /dev/null +++ b/examples/Trill-Craft/Trill-Craft.cpp @@ -0,0 +1,40 @@ +/** + * Read Trill craft capacitive sensor + */ + +#include "daisy_seed.h" +#include "dev/trill/Trill.h" + +using namespace daisy; + +DaisySeed hw; + +int main(void) +{ + // Initialize the Daisy Seed + hw.Init(); + + // Start the Serial Logger + hw.StartLog(); + + // Create a Trill object + Trill trill; + + // Initialize the Trill object + int i2cBus = 1; // only 1 and 4 are properly mapped to pins on the Seed + int ret = trill.setup(i2cBus, Trill::CRAFT); + if(ret) + hw.PrintLine("trill.setup() returned %d", ret); + + // loop forever + while(1) + { + hw.DelayMs(100); + trill.readI2C(); + for(auto &x : trill.rawData ){ + hw.Print("%d ", int(x*100000.f)); + } + hw.PrintLine(""); + } + +} diff --git a/src/dev/trill/I2c.h b/src/dev/trill/I2c.h index d5ee2e45f..fde86a5f0 100644 --- a/src/dev/trill/I2c.h +++ b/src/dev/trill/I2c.h @@ -51,6 +51,7 @@ inline int I2c::initI2C_RW(int bus, int address, int dummy) } cfg.address = i2cAddress; // this seems unused anyhow i2cAddress = address; + i2cHandle.Init(cfg); return 0; }