diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..603c00c --- /dev/null +++ b/.clang-format @@ -0,0 +1,91 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Note: The list of ForEachMacros can be obtained using: +# +# git grep -h '^#define [^[:space:]]*FOR_EACH[^[:space:]]*(' include/ \ +# | sed "s,^#define \([^[:space:]]*FOR_EACH[^[:space:]]*\)(.*$, - '\1'," \ +# | sort | uniq +# +# References: +# - https://clang.llvm.org/docs/ClangFormatStyleOptions.html + +--- +BasedOnStyle: LLVM +AlignConsecutiveMacros: AcrossComments +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AttributeMacros: + - __aligned + - __deprecated + - __packed + - __printf_like + - __syscall + - __syscall_always_inline + - __subsystem +BitFieldColonSpacing: After +BreakBeforeBraces: Linux +ColumnLimit: 100 +ConstructorInitializerIndentWidth: 8 +ContinuationIndentWidth: 8 +ForEachMacros: + - 'FOR_EACH' + - 'FOR_EACH_FIXED_ARG' + - 'FOR_EACH_IDX' + - 'FOR_EACH_IDX_FIXED_ARG' + - 'FOR_EACH_NONEMPTY_TERM' + - 'RB_FOR_EACH' + - 'RB_FOR_EACH_CONTAINER' + - 'SYS_DLIST_FOR_EACH_CONTAINER' + - 'SYS_DLIST_FOR_EACH_CONTAINER_SAFE' + - 'SYS_DLIST_FOR_EACH_NODE' + - 'SYS_DLIST_FOR_EACH_NODE_SAFE' + - 'SYS_SFLIST_FOR_EACH_CONTAINER' + - 'SYS_SFLIST_FOR_EACH_CONTAINER_SAFE' + - 'SYS_SFLIST_FOR_EACH_NODE' + - 'SYS_SFLIST_FOR_EACH_NODE_SAFE' + - 'SYS_SLIST_FOR_EACH_CONTAINER' + - 'SYS_SLIST_FOR_EACH_CONTAINER_SAFE' + - 'SYS_SLIST_FOR_EACH_NODE' + - 'SYS_SLIST_FOR_EACH_NODE_SAFE' + - '_WAIT_Q_FOR_EACH' + - 'Z_FOR_EACH' + - 'Z_FOR_EACH_ENGINE' + - 'Z_FOR_EACH_EXEC' + - 'Z_FOR_EACH_FIXED_ARG' + - 'Z_FOR_EACH_FIXED_ARG_EXEC' + - 'Z_FOR_EACH_IDX' + - 'Z_FOR_EACH_IDX_EXEC' + - 'Z_FOR_EACH_IDX_FIXED_ARG' + - 'Z_FOR_EACH_IDX_FIXED_ARG_EXEC' + - 'Z_GENLIST_FOR_EACH_CONTAINER' + - 'Z_GENLIST_FOR_EACH_CONTAINER_SAFE' + - 'Z_GENLIST_FOR_EACH_NODE' + - 'Z_GENLIST_FOR_EACH_NODE_SAFE' + - 'STRUCT_SECTION_FOREACH' + - 'TYPE_SECTION_FOREACH' +IfMacros: + - 'CHECKIF' +# Disabled for now, see bug https://github.com/zephyrproject-rtos/zephyr/issues/48520 +#IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^".*\.h"$' + Priority: 0 + - Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|wchar|wctype)\.h>$' + Priority: 1 + - Regex: '^\$' + Priority: 2 + - Regex: '.*' + Priority: 3 +IndentCaseLabels: false +IndentWidth: 8 +InsertBraces: true +SpaceBeforeParens: ControlStatementsExceptControlMacros +SortIncludes: Never +UseTab: ForContinuationAndIndentation +WhitespaceSensitiveMacros: + - STRINGIFY + - Z_STRINGIFY diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0eeffcd --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Vscode +*.code-workspace + +# MacOS +.DS_Store + +# Zephyr +build +twister-out +.west diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5f7bea9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(drivers) diff --git a/Kconfig b/Kconfig new file mode 100644 index 0000000..0896fce --- /dev/null +++ b/Kconfig @@ -0,0 +1 @@ +rsource "drivers/Kconfig" \ No newline at end of file diff --git a/README.md b/README.md index bfee4b8..17b69a5 100644 --- a/README.md +++ b/README.md @@ -1 +1,11 @@ -# atlas-ec-driver-zephyr \ No newline at end of file +# atlas-ec-driver-zephyr + +## Hardware connections +We are connecting the Atlast breakout on i2c0 of the Pico + +1. SDA to GP4 on Pico +2. SCL to GP5 on Pico +3. GND to any of the free GND pins on the Pico +4. VCC to 3V3 out of the Pico + +For easy access to pin information, check out [pico.pinout.xyz](https://pico.pinout.xyz/) diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt new file mode 100644 index 0000000..2ef5da9 --- /dev/null +++ b/drivers/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Arribada Initiative CIC +# SPDX-License-Identifier: MIT + +add_subdirectory_ifdef(CONFIG_SENSOR sensor) diff --git a/drivers/Kconfig b/drivers/Kconfig new file mode 100644 index 0000000..096994a --- /dev/null +++ b/drivers/Kconfig @@ -0,0 +1,6 @@ +# Copyright (c) 2024 Arribada Initiative CIC +# SPDX-License-Identifier: MIT + +menu "Drivers" +rsource "sensor/Kconfig" +endmenu diff --git a/drivers/sensor/CMakeLists.txt b/drivers/sensor/CMakeLists.txt new file mode 100644 index 0000000..66a886c --- /dev/null +++ b/drivers/sensor/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2024 Arribada Initiative CIC +# SPDX-License-Identifier: MIT + +add_subdirectory_ifdef(CONFIG_OEMEC oemec) diff --git a/drivers/sensor/Kconfig b/drivers/sensor/Kconfig new file mode 100644 index 0000000..f375ebb --- /dev/null +++ b/drivers/sensor/Kconfig @@ -0,0 +1,6 @@ +# Copyright (c) 2024 Arribada Initiative CIC +# SPDX-License-Identifier: MIT + +if SENSOR +rsource "oemec/Kconfig" +endif #SENSOR diff --git a/drivers/sensor/oemec/CMakeLists.txt b/drivers/sensor/oemec/CMakeLists.txt new file mode 100644 index 0000000..01775cd --- /dev/null +++ b/drivers/sensor/oemec/CMakeLists.txt @@ -0,0 +1,5 @@ +zephyr_library() +zephyr_library_sources(oemec.c) + +# This shouldn't be needed if we send this driver upstream. +zephyr_include_directories(.) diff --git a/drivers/sensor/oemec/Kconfig b/drivers/sensor/oemec/Kconfig new file mode 100644 index 0000000..37476a7 --- /dev/null +++ b/drivers/sensor/oemec/Kconfig @@ -0,0 +1,7 @@ +menuconfig OEMEC + bool "Enable OEMEC" + default y + depends on DT_HAS_ATLAS_OEMEC_ENABLED + select I2C + help + OEM EC sensor from Atlas \ No newline at end of file diff --git a/drivers/sensor/oemec/oemec.c b/drivers/sensor/oemec/oemec.c new file mode 100644 index 0000000..1545f0d --- /dev/null +++ b/drivers/sensor/oemec/oemec.c @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2023 Arribada Initiative CIC + * + * SPDX-License-Identifier: MIT + */ +#define DT_DRV_COMPAT atlas_oemec + +#include +#include +#include +#include +#include +#include "oemec.h" + +LOG_MODULE_REGISTER(OEMEC, CONFIG_SENSOR_LOG_LEVEL); + +#define OEMEC_DEVICE_TYPE 0x00 +#define OEMEC_FW_VERSION 0x01 +#define OEMEC_ADDR_UNLOCK 0x02 +#define OEMEC_ADDR 0x03 +#define OEMEC_INT_CONTROL 0x04 +#define OEMEC_LED_CONTROL 0x05 +#define OEMEC_ACT_HIBERNATE 0x06 +#define OEMEC_NEW_READING 0x07 +#define OEMEC_PROBE_MSB 0x08 +#define OEMEC_PROBE_LSB 0x09 +#define OEMEC_CALIB_MSB 0x0A +#define OEMEC_CALIB_HIGH_BYTE 0x0B +#define OEMEC_CALIB_LOW_BYTE 0x0C +#define OEMEC_CALIB_LSB 0x0D +#define OEMEC_CALIB_REQUEST 0x0E +#define OEMEC_CALIB_CONFIRM 0x0F +#define OEMEC_TEMP_COMP_MSB 0x10 +#define OEMEC_TEMP_COMP_HIGH_BYTE 0x11 +#define OEMEC_TEMP_COMP_LOW_BYTE 0x12U +#define OEMEC_TEMP_COMP_LSB 0x13 +#define OEMEC_TEMP_CONF_MSB 0x14 +#define OEMEC_TEMP_CONF_HIGH_BYTE 0x15 +#define OEMEC_TEMP_CONF_LOW_BYTE 0x16 +#define OEMEC_TEMP_CONF_LSB 0x17 +#define OEMEC_SENSOR_MSB 0x18 +#define OEMEC_SENSOR_HIGH_BYTE 0x19 +#define OEMEC_SENSOR_LOW_BYTE 0x1A +#define OEMEC_SENSOR_LSB 0x1B +#define OEMEC_TDS_MSB 0x1C +#define OEMEC_TDS_HIGH_BYTE 0x1D +#define OEMEC_TDS_LOW_BYTE 0x1E +#define OEMEC_TDS_LSB 0x1F +#define OEMEC_SALINITY_MSB 0x20 +#define OEMEC_SALINITY_HIGH_BYTE 0x21 +#define OEMEC_SALINITY_LOW_BYTE 0x22 +#define OEMEC_SALINITY_LSB 0x23 + +enum CALIB_TYPES { + CALIB_CLEAR, + CALIB_DRY, + CALIB_SINGLE, + CALIB_DUAL_LOW, + CALIB_DUAL_HIGH +}; + +static int oemec_set_calibration(const struct device *dev, const struct sensor_value *val,enum CALIB_TYPES type); + +struct oemec_config { + struct i2c_dt_spec bus; + /* uint8_t resolution; */ + /* uint8_t mtreg; */ +}; + +struct oemec_data { + float sample; +}; + +static int oemec_read_regs(const struct device *dev, uint8_t addr, void *buf, size_t len) +{ + const struct oemec_config *config = dev->config; + int err; + + err = i2c_write_read_dt(&config->bus, &addr, sizeof(addr), buf, len); + if (err != 0) { + LOG_ERR("failed to read reg addr 0x%02x, len %d (err %d)", addr, len, err); + return err; + } + + return 0; +} + +static int oemec_write_regs(const struct device *dev, uint8_t addr, void *buf, size_t len) +{ + const struct oemec_config *config = dev->config; + uint8_t block[sizeof(addr) + len]; + int err; + + block[0] = addr; + memcpy(&block[1], buf, len); + + err = i2c_write_dt(&config->bus, block, sizeof(block)); + if (err != 0) { + LOG_ERR("failed to write reg addr 0x%02x, len %d (err %d)", addr, len, err); + return err; + } + + return 0; +} + +static int oemec_sample_fetch(const struct device *dev, enum sensor_channel chan) +{ + LOG_INF("Fetching samples"); + /* Initiate sensor read */ + + /* uint8_t devicetype_firmware[2]={0,0}; */ + /* oemec_read_regs(dev,OEMEC_DEVICE_TYPE,&devicetype_firmware,sizeof(devicetype_firmware)); */ + /* LOG_INF("Device type : %d",devicetype_firmware[0]); */ + /* LOG_INF("FW version : %d", devicetype_firmware[1]); */ + + /* Get the values */ + + uint8_t sensor_values[4]={1,2,3,4}; + unsigned long sensor_values_long=0; + float sensor_values_float; + if(chan==SENSOR_CHAN_OEMEC_TDS){ + oemec_read_regs(dev,OEMEC_TDS_MSB,&sensor_values,sizeof(sensor_values)); + } + else if(chan == SENSOR_CHAN_OEMEC_SALINITY){ + oemec_read_regs(dev,OEMEC_SALINITY_MSB,&sensor_values,sizeof(sensor_values)); + } + else{ + oemec_read_regs(dev,OEMEC_SENSOR_MSB,&sensor_values,sizeof(sensor_values)); + } + + + sensor_values_long += sensor_values[0] << 24; + sensor_values_long += sensor_values[1] << 16; + sensor_values_long += sensor_values[2] << 8; + sensor_values_long += sensor_values[3]; + + sensor_values_float = (float)sensor_values_long; + sensor_values_float = sensor_values_float/100; + + LOG_INF("Sensor values as 4 regs :%x %x %x %x",sensor_values[0],sensor_values[1],sensor_values[2],sensor_values[3]); + LOG_INF("Sensor value as long %lu",sensor_values_long); + LOG_INF("Sensor value as float %f",sensor_values_float); + + return 0; +} + +static int oemec_set_probe(const struct device *dev,const struct sensor_value *val) +{ + int t = val->val1; + uint8_t LSB = ((uint16_t)t & 0x00FF); + uint8_t MSB = (((uint16_t)t & 0xFF00) >>8); + LOG_INF("Setting probe regs to %d i.e. | %02x | %02x",t,MSB,LSB); + oemec_write_regs(dev,OEMEC_PROBE_MSB,&MSB,sizeof(MSB)); + oemec_write_regs(dev,OEMEC_PROBE_LSB,&LSB,sizeof(LSB)); + return 0; +} + +static int oemec_set_calibration(const struct device *dev, const struct sensor_value *val,enum CALIB_TYPES type) +{ + if(type!=CALIB_CLEAR){ // if we are clearing, no need to write anything to calib value register + + uint32_t t = (uint32_t)val->val1; + + uint8_t MSB = ((t & 0xFF000000) >>24); + uint8_t highbyte = ((t & 0x00FF0000) >>16); + uint8_t lowbyte = ((t & 0x0000FF00) >>8); + uint8_t LSB = (t & 0x000000FF); + LOG_INF("Setting calibration regs to %d i.e. | %02x | %02x | %02x | %02x",t,MSB,highbyte,lowbyte,LSB); + oemec_write_regs(dev,OEMEC_CALIB_MSB,&MSB,sizeof(MSB)); + oemec_write_regs(dev,OEMEC_CALIB_HIGH_BYTE,&highbyte,sizeof(highbyte)); + oemec_write_regs(dev,OEMEC_CALIB_LOW_BYTE,&lowbyte,sizeof(lowbyte)); + oemec_write_regs(dev,OEMEC_CALIB_LSB,&LSB,sizeof(LSB)); + } + uint8_t cr_value; + switch (type){ + case CALIB_CLEAR: + cr_value = 1; + break; + case CALIB_DRY: + cr_value = 2; + break; + case CALIB_SINGLE: + cr_value = 3; + break; + case CALIB_DUAL_LOW: + cr_value = 4; + break; + case CALIB_DUAL_HIGH: + cr_value = 5; + break; + default: + LOG_ERR("Unexpected calibration type!"); + return -1; + } + // write to request register + oemec_write_regs(dev,OEMEC_CALIB_REQUEST,&cr_value,sizeof(cr_value)); + + // todo read from calibration confirmation register + + return 0; +} + +static int oemec_channel_get(const struct device *dev, enum sensor_channel chan, + struct sensor_value *val) +{ + LOG_INF("Fetching value for channel %d", chan); + return 0; +} + +static int oemec_attr_get(const struct device *dev, enum sensor_channel chan, + enum sensor_attribute attr, struct sensor_value *val) +{ + return 0; +} + + +static int oemec_attr_set(const struct device *dev, enum sensor_channel chan, + enum sensor_attribute attr, const struct sensor_value *val) +{ + + switch((int)attr){ //typecast to int so that we can use our overloaded enum w/o compiler warnings + case SENSOR_ATTR_OEMEC_CALIBRATION_CLEAR: + return oemec_set_calibration(dev,NULL,CALIB_CLEAR); + case SENSOR_ATTR_OEMEC_CALIBRATION_DRY: + return oemec_set_calibration(dev,val,CALIB_DRY); + case SENSOR_ATTR_OEMEC_CALIBRATION_SINGLE: + return oemec_set_calibration(dev,val,CALIB_SINGLE); + case SENSOR_ATTR_OEMEC_CALIBRATION_DUAL_LOW: + return oemec_set_calibration(dev,val,CALIB_DUAL_LOW); + case SENSOR_ATTR_OEMEC_CALIBRATION_DUAL_HIGH: + return oemec_set_calibration(dev,val,CALIB_DUAL_HIGH); + case SENSOR_ATTR_OEMEC_PROBE: + return oemec_set_probe(dev,val); + default: + LOG_ERR("Attribute not supported"); + return -ENOTSUP; + } + return 0; +} + +static const struct sensor_driver_api oemec_driver_api = { + .sample_fetch = oemec_sample_fetch, + .channel_get = oemec_channel_get, + .attr_set = oemec_attr_set, + .attr_get = oemec_attr_get, +}; + +static int oemec_init(const struct device *dev) +{ + LOG_DBG("Inside oemec_init"); + return 0; +} + +#define DEFINE_OEMEC(inst) \ + static struct oemec_data oemec_data_##inst; \ + \ + static const struct oemec_config oemec_config_##inst = { \ + .bus = I2C_DT_SPEC_INST_GET(inst), \ + }; \ + SENSOR_DEVICE_DT_INST_DEFINE(inst, oemec_init, NULL, &oemec_data_##inst, \ + &oemec_config_##inst, POST_KERNEL, \ + CONFIG_SENSOR_INIT_PRIORITY, &oemec_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(DEFINE_OEMEC) diff --git a/drivers/sensor/oemec/oemec.h b/drivers/sensor/oemec/oemec.h new file mode 100644 index 0000000..2d02fbc --- /dev/null +++ b/drivers/sensor/oemec/oemec.h @@ -0,0 +1,23 @@ +#ifdef __cplusplus +extern "C" { +#endif + + +enum sensor_channel_oemec{ + SENSOR_CHAN_OEMEC_CONDUCTIVITY = SENSOR_CHAN_PRIV_START, + SENSOR_CHAN_OEMEC_TDS, + SENSOR_CHAN_OEMEC_SALINITY, +}; + +enum sensor_attribute_oemec{ + SENSOR_ATTR_OEMEC_PROBE = SENSOR_ATTR_PRIV_START, + SENSOR_ATTR_OEMEC_CALIBRATION_CLEAR, + SENSOR_ATTR_OEMEC_CALIBRATION_DRY, + SENSOR_ATTR_OEMEC_CALIBRATION_SINGLE, + SENSOR_ATTR_OEMEC_CALIBRATION_DUAL_LOW, + SENSOR_ATTR_OEMEC_CALIBRATION_DUAL_HIGH , +}; + +#ifdef __cplusplus +} +#endif diff --git a/dts/bindings/sensor/atlas,oemec.yaml b/dts/bindings/sensor/atlas,oemec.yaml new file mode 100644 index 0000000..615cdff --- /dev/null +++ b/dts/bindings/sensor/atlas,oemec.yaml @@ -0,0 +1,10 @@ +# Copyright (c) 2025 Arribada Initiative CIC +# SPDX-License-Identifier: MIT +description: Atlas OEM-EC control board + +compatible: "atlas,oemec" + +include: [sensor-device.yaml, i2c-device.yaml] + + +# TODO - add int-gpios/sqw, clock, etc. diff --git a/dts/bindings/vendor-prefixes.txt b/dts/bindings/vendor-prefixes.txt new file mode 100644 index 0000000..34ee494 --- /dev/null +++ b/dts/bindings/vendor-prefixes.txt @@ -0,0 +1 @@ +atlas Atlas Scientific diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..c01ac80 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(simple) diff --git a/examples/simple/CMakeLists.txt b/examples/simple/CMakeLists.txt new file mode 100644 index 0000000..f5dbb44 --- /dev/null +++ b/examples/simple/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.13.1) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(app LANGUAGES C) + +target_sources(app PRIVATE src/main.c) diff --git a/examples/simple/Kconfig b/examples/simple/Kconfig new file mode 100644 index 0000000..c9a06cd --- /dev/null +++ b/examples/simple/Kconfig @@ -0,0 +1,7 @@ +menu "Zephyr" +source "Kconfig.zephyr" +endmenu + +module = APP +module-str = APP +source "subsys/logging/Kconfig.template.log_config" \ No newline at end of file diff --git a/examples/simple/Makefile b/examples/simple/Makefile new file mode 100644 index 0000000..29359b8 --- /dev/null +++ b/examples/simple/Makefile @@ -0,0 +1,17 @@ + +# This makefile makes it easy to develop using picoprobe as a debugger + +continue: + west build -b rpi_pico -- -DOPENOCD=/usr/bin/openocd -DOPENOCD_DEFAULT_PATH=/usr/share/openocd/scripts -DRPI_PICO_DEBUG_ADAPTER=cmsis-dap + +all: + west build --pristine -b rpi_pico -- -DOPENOCD=/usr/bin/openocd -DOPENOCD_DEFAULT_PATH=/usr/share/openocd/scripts -DRPI_PICO_DEBUG_ADAPTER=cmsis-dap + +flash: + west flash + +fm: + west flash + minicom +clean: + rm -rf build diff --git a/examples/simple/boards/rpi_pico.overlay b/examples/simple/boards/rpi_pico.overlay new file mode 100644 index 0000000..d7b1e6b --- /dev/null +++ b/examples/simple/boards/rpi_pico.overlay @@ -0,0 +1,12 @@ +&i2c0{ + clock-frequency = ; + status = "okay"; + pinctrl-0 = <&i2c0_default>; + pinctrl-names = "default"; +oemec:oemec@64{ + compatible = "atlas,oemec"; + status = "okay"; + reg = <0x64>; + }; + }; + diff --git a/examples/simple/prj.conf b/examples/simple/prj.conf new file mode 100644 index 0000000..95ff9d2 --- /dev/null +++ b/examples/simple/prj.conf @@ -0,0 +1,10 @@ +CONFIG_I2C=y +CONFIG_SHELL=y +CONFIG_I2C_SHELL=y +CONFIG_LOG=y +CONFIG_LOG_PRINTK=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y +CONFIG_SENSOR=y +CONFIG_OEMEC=y +CONFIG_SENSOR_LOG_LEVEL_DBG=y \ No newline at end of file diff --git a/examples/simple/src/main.c b/examples/simple/src/main.c new file mode 100644 index 0000000..141db78 --- /dev/null +++ b/examples/simple/src/main.c @@ -0,0 +1,111 @@ +#include +#include +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(simple_app); + +const struct device * dev; + +static int cmd_calib_clear(const struct shell *sh, + size_t argc, char **argv, void *data) +{ + int rc = sensor_attr_set(dev,SENSOR_CHAN_OEMEC_CONDUCTIVITY,SENSOR_ATTR_OEMEC_CALIBRATION_CLEAR,NULL); + shell_print(sh,"Setting attribute for calibration clear - %d",rc); + return rc; +} + +static int cmd_calib_dry(const struct shell *sh, + size_t argc, char **argv, void *data) +{ + struct sensor_value calib = {}; + calib.val1 = atoi(argv[1]); + int rc = sensor_attr_set(dev,SENSOR_CHAN_OEMEC_CONDUCTIVITY,SENSOR_ATTR_OEMEC_CALIBRATION_DRY,&calib); + shell_print(sh,"Setting attribute for calibration dry - %d",rc); + return 0; +} + +static int cmd_calib_single(const struct shell *sh, + size_t argc, char **argv, void *data) +{ + struct sensor_value calib = {}; + calib.val1 = atoi(argv[1]); + int rc = sensor_attr_set(dev,SENSOR_CHAN_OEMEC_CONDUCTIVITY,SENSOR_ATTR_OEMEC_CALIBRATION_SINGLE,&calib); + shell_print(sh,"Setting attribute for calibration single - %d",rc); + return 0; +} + +static int cmd_calib_dual_low(const struct shell *sh, + size_t argc, char **argv, void *data) +{ + struct sensor_value calib = {}; + calib.val1 = atoi(argv[1]); + int rc = sensor_attr_set(dev,SENSOR_CHAN_OEMEC_CONDUCTIVITY,SENSOR_ATTR_OEMEC_CALIBRATION_DUAL_LOW,&calib); + shell_print(sh,"Setting attribute for calibration dual low - %d",rc); + return 0; +} + +static int cmd_calib_dual_high(const struct shell *sh, + size_t argc, char **argv, void *data) +{ + struct sensor_value calib = {}; + calib.val1 = atoi(argv[1]); + int rc = sensor_attr_set(dev,SENSOR_CHAN_OEMEC_CONDUCTIVITY,SENSOR_ATTR_OEMEC_CALIBRATION_DUAL_HIGH,&calib); + shell_print(sh,"Setting attribute for calibration dual high - %d",rc); + return 0; +} +/* Creating subcommands (level 1 command) array for command "demo". */ +SHELL_STATIC_SUBCMD_SET_CREATE(sub_demo, + SHELL_CMD(clear, NULL, " Clear", + cmd_calib_clear), + SHELL_CMD(dry, NULL, " Dry", cmd_calib_dry), + SHELL_CMD(single, NULL, " Single", cmd_calib_single), + SHELL_CMD(duallow, NULL, " Low val of dual", cmd_calib_dual_low), + SHELL_CMD(dualhigh, NULL, " High val of dual", cmd_calib_dual_high), + SHELL_SUBCMD_SET_END + ); +/* Creating root (level 0) command "demo" */ +SHELL_CMD_REGISTER(demo, &sub_demo, "Calib commands", NULL); + + + +int main(void) +{ + int rc; + LOG_INF("Running OEMEC simple app on %s\n", CONFIG_BOARD); + dev = DEVICE_DT_GET_ANY(atlas_oemec); + if (dev == NULL) { + LOG_INF("No device found"); + return 0; + } + + LOG_INF("Setting attributes"); + + struct sensor_value probe = { // K=4.56 + .val1 = 456, + }; + rc = sensor_attr_set(dev,SENSOR_CHAN_OEMEC_CONDUCTIVITY,SENSOR_ATTR_OEMEC_PROBE,&probe); + LOG_INF("Set probe returned %d",rc); + + struct sensor_value conductivity; + /* while (true) { */ + /* rc = sensor_sample_fetch_chan(dev,SENSOR_CHAN_OEMEC_CONDUCTIVITY); */ + /* if (rc != 0 ){ */ + /* LOG_ERR("OEMEC failed: %d",rc); */ + /* break; */ + /* } */ + /* else { // read channels */ + /* rc = sensor_channel_get(dev, SENSOR_CHAN_OEMEC_CONDUCTIVITY, &conductivity); */ + /* LOG_INF("Conductivity value %f", sensor_value_to_double(&conductivity)); */ + /* } */ + /* k_msleep(2000); */ + /* } */ + + while(true){ + k_msleep(2000); + } + return 0; +} diff --git a/west.yml b/west.yml new file mode 100644 index 0000000..73fe221 --- /dev/null +++ b/west.yml @@ -0,0 +1,27 @@ +# Copyright (c) 2024 Arribada Initiative CIC +# SPDX-License-Identifier: MIT + +manifest: + defaults: + revision: main + + remotes: + - name: zephyr + url-base: https://github.com/zephyrproject-rtos/ + - name: arribada + url-base: https://github.com/arribada/ + projects: + - name: zephyr + remote: zephyr + path: zephyr + revision: v3.5.0 + clone-depth: 1 + import: + # By using name-allowlist we can clone only the modules that are + # strictly needed by the application. + name-allowlist: + - cmsis # required by the ARM port + - hal_rpi_pico + + self: + path: atlas-driver-zephyr diff --git a/zephyr/module.yaml b/zephyr/module.yaml new file mode 100644 index 0000000..e00043f --- /dev/null +++ b/zephyr/module.yaml @@ -0,0 +1,16 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +build: + # Path to the Kconfig file that will be sourced into Zephyr Kconfig tree under + # Zephyr > Modules > example-application. Path is relative from root of this + # repository. + kconfig: Kconfig + # Path to the folder that contains the CMakeLists.txt file to be included by + # Zephyr build system. The `.` is the root of this repository. + cmake: . + settings: + # Zephyr will use the `/dts` for additional dts files and + # `/dts/bindings` for additional dts binding files. The `.` is + # the root of this repository. + dts_root: .