diff --git a/Documentation/platforms/arm/nrf91/boards/thingy91/index.rst b/Documentation/platforms/arm/nrf91/boards/thingy91/index.rst index 7e6c1e2631210..2af89956ef335 100644 --- a/Documentation/platforms/arm/nrf91/boards/thingy91/index.rst +++ b/Documentation/platforms/arm/nrf91/boards/thingy91/index.rst @@ -19,14 +19,14 @@ GPS No Buttons Yes LEDs No COEX No -PMIC No +PMIC (ADP5360) No I2C 0x46 Battery monitoring No Buzzer No -EEPROM (24CW160) No -Low power accelerometer (ADXL362) No -Hi G accelerometer (ADXL372) No -Air quality sensor (HBME680) No -Color sensor (BH1749NUC) No +EEPROM (24CW160) No I2C 0x50 +Low power accelerometer (ADXL362) No SPI +Hi G accelerometer (ADXL372) No SPI +Air quality sensor (BME680) No I2C 0x76 +Color sensor (BH1749NUC) No I2C 0x38 ================================== ======= ============= Serial Console @@ -39,7 +39,11 @@ Serial Console Configurations ============== -TODO +thingy91_rtt +------------ + +Configuration with a console over RTT, enabling available peripherals +on the board (WIP). Flash & Debug ============= diff --git a/boards/arm/nrf91/common/include/nrf91_adxl362.h b/boards/arm/nrf91/common/include/nrf91_adxl362.h new file mode 100644 index 0000000000000..1d177bd30833b --- /dev/null +++ b/boards/arm/nrf91/common/include/nrf91_adxl362.h @@ -0,0 +1,40 @@ +/**************************************************************************** + * boards/arm/nrf91/common/include/nrf91_adxl362.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_ADXL362_H +#define __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_ADXL362_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_adxl362_init + ****************************************************************************/ + +int nrf91_adxl362_init(int devno, int busno); + +#endif /* __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_ADXL362_H */ diff --git a/boards/arm/nrf91/common/include/nrf91_adxl372.h b/boards/arm/nrf91/common/include/nrf91_adxl372.h new file mode 100644 index 0000000000000..8663494a5c7db --- /dev/null +++ b/boards/arm/nrf91/common/include/nrf91_adxl372.h @@ -0,0 +1,40 @@ +/**************************************************************************** + * boards/arm/nrf91/common/include/nrf91_adxl372.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_ADXL372_H +#define __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_ADXL372_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_adxl372_init + ****************************************************************************/ + +int nrf91_adxl372_init(int devno, int busno); + +#endif /* __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_ADXL372_H */ diff --git a/boards/arm/nrf91/common/include/nrf91_bh1749nuc.h b/boards/arm/nrf91/common/include/nrf91_bh1749nuc.h new file mode 100644 index 0000000000000..52045ef833012 --- /dev/null +++ b/boards/arm/nrf91/common/include/nrf91_bh1749nuc.h @@ -0,0 +1,40 @@ +/**************************************************************************** + * boards/arm/nrf91/common/include/nrf91_bh1749nuc.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_BH1749NUC_H +#define __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_BH1749NUC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_bh1749nuc_init + ****************************************************************************/ + +int nrf91_bh1749nuc_init(int devno, int busno, uint8_t addr); + +#endif /* __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_BH1749NUC_H */ diff --git a/boards/arm/nrf91/common/include/nrf91_bme680.h b/boards/arm/nrf91/common/include/nrf91_bme680.h new file mode 100644 index 0000000000000..714595ccf906c --- /dev/null +++ b/boards/arm/nrf91/common/include/nrf91_bme680.h @@ -0,0 +1,40 @@ +/**************************************************************************** + * boards/arm/nrf91/common/include/nrf91_bme680.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_BME680_H +#define __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_BME680_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_bme680_init + ****************************************************************************/ + +int nrf91_bme680_init(int devno, int busno); + +#endif /* __BOARDS_ARM_NRF91_COMMON_INCLUDE_NRF91_BME680_H */ diff --git a/boards/arm/nrf91/common/src/CMakeLists.txt b/boards/arm/nrf91/common/src/CMakeLists.txt index d800cd1bb0aeb..3296b72afa4a9 100644 --- a/boards/arm/nrf91/common/src/CMakeLists.txt +++ b/boards/arm/nrf91/common/src/CMakeLists.txt @@ -38,6 +38,22 @@ if(CONFIG_ARCH_BOARD_COMMON) list(APPEND SRCS nrf91_reset.c) endif() + if(CONFIG_SENSORS_BH1749NUC) + list(APPEND SRCS nrf91_bh1749nuc.c) + endif() + + if(CONFIG_SENSORS_BME680) + list(APPEND SRCS nrf91_bme680.c) + endif() + + if(CONFIG_SENSORS_ADXL372) + list(APPEND SRCS nrf91_adxl372.c) + endif() + + if(CONFIG_SENSORS_ADXL362) + list(APPEND SRCS nrf91_adxl362.c) + endif() + target_sources(board PRIVATE ${SRCS}) endif() diff --git a/boards/arm/nrf91/common/src/Make.defs b/boards/arm/nrf91/common/src/Make.defs index 290b73bfa3ba5..279e7a4072868 100644 --- a/boards/arm/nrf91/common/src/Make.defs +++ b/boards/arm/nrf91/common/src/Make.defs @@ -38,6 +38,22 @@ ifeq ($(CONFIG_BOARDCTL_RESET),y) CSRCS += nrf91_reset.c endif +ifeq ($(CONFIG_SENSORS_BH1749NUC),y) + CSRCS += nrf91_bh1749nuc.c +endif + +ifeq ($(CONFIG_SENSORS_BME680),y) + CSRCS += nrf91_bme680.c +endif + +ifeq ($(CONFIG_SENSORS_ADXL372),y) + CSRCS += nrf91_adxl372.c +endif + +ifeq ($(CONFIG_SENSORS_ADXL362),y) + CSRCS += nrf91_adxl362.c +endif + DEPPATH += --dep-path src VPATH += :src CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src diff --git a/boards/arm/nrf91/common/src/nrf91_adxl362.c b/boards/arm/nrf91/common/src/nrf91_adxl362.c new file mode 100644 index 0000000000000..9c5e33c5bc654 --- /dev/null +++ b/boards/arm/nrf91/common/src/nrf91_adxl362.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * boards/arm/nrf91/common/src/nrf91_adxl362.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "nrf91_spi.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_adxl362_init + ****************************************************************************/ + +int nrf91_adxl362_init(int devno, int busno) +{ + struct spi_dev_s *spi; + int ret; + + sninfo("Initializing ADXL362!\n"); + + /* Initialize SPI */ + + spi = nrf91_spibus_initialize(busno); + if (!spi) + { + return -ENODEV; + } + + /* Then register the barometer sensor */ + + ret = adxl362_register(devno, spi); + if (ret < 0) + { + snerr("ERROR: Error registering ADXL362\n"); + } + + return ret; +} diff --git a/boards/arm/nrf91/common/src/nrf91_adxl372.c b/boards/arm/nrf91/common/src/nrf91_adxl372.c new file mode 100644 index 0000000000000..52c342435f786 --- /dev/null +++ b/boards/arm/nrf91/common/src/nrf91_adxl372.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * boards/arm/nrf91/common/src/nrf91_adxl372.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "nrf91_spi.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_adxl372_init + ****************************************************************************/ + +int nrf91_adxl372_init(int devno, int busno) +{ + struct spi_dev_s *spi; + int ret; + + sninfo("Initializing ADXL372!\n"); + + /* Initialize SPI */ + + spi = nrf91_spibus_initialize(busno); + if (!spi) + { + return -ENODEV; + } + + /* Then register the barometer sensor */ + + ret = adxl372_register_uorb(devno, spi); + if (ret < 0) + { + snerr("ERROR: Error registering ADXL372\n"); + } + + return ret; +} diff --git a/boards/arm/nrf91/common/src/nrf91_bh1749nuc.c b/boards/arm/nrf91/common/src/nrf91_bh1749nuc.c new file mode 100644 index 0000000000000..d8c7006bc7d3a --- /dev/null +++ b/boards/arm/nrf91/common/src/nrf91_bh1749nuc.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * boards/arm/nrf91/common/src/nrf91_bh1749nuc.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "nrf91_i2c.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_SENSORS_BH1749NUC_UORB +# error BH1749NUC UORB is only supported +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_bh1749nuc_init + ****************************************************************************/ + +int nrf91_bh1749nuc_init(int devno, int busno, uint8_t addr) +{ + struct bh1749nuc_config_s config; + struct i2c_master_s *i2c; + int ret; + + sninfo("Initializing BH1749NUC!\n"); + + /* Initialize I2C */ + + i2c = nrf91_i2cbus_initialize(busno); + if (!i2c) + { + return -ENODEV; + } + + /* Then register the barometer sensor */ + + config.i2c = i2c; + config.addr = addr; + + ret = bh1749nuc_register_uorb(devno, &config); + if (ret < 0) + { + snerr("ERROR: Error registering BH1749NUC\n"); + } + + return ret; +} diff --git a/boards/arm/nrf91/common/src/nrf91_bme680.c b/boards/arm/nrf91/common/src/nrf91_bme680.c new file mode 100644 index 0000000000000..5b0417589d069 --- /dev/null +++ b/boards/arm/nrf91/common/src/nrf91_bme680.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * boards/arm/nrf91/common/src/nrf91_bme680.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "nrf91_i2c.h" + +/**************************************************************************** + * Private data + ****************************************************************************/ + +/* Default measurement configuration. Without a configuration the driver + * never leaves the "not calibrated" state and no measurements are taken. + * Oversampling follows the Bosch "indoor navigation" recommendation; the + * gas heater profile targets 320 C for 150 ms. + */ + +struct bme680_config_s g_bme680_config = +{ + .temp_os = BME680_OS_8X, + .press_os = BME680_OS_4X, + .hum_os = BME680_OS_2X, + .target_temp = 320, + .heater_duration = 150, + .nb_conv = 0, + .amb_temp = 25, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_bme680_init + ****************************************************************************/ + +int nrf91_bme680_init(int devno, int busno) +{ + struct i2c_master_s *i2c; + int ret; + + sninfo("Initializing BME680!\n"); + + /* Initialize I2C */ + + i2c = nrf91_i2cbus_initialize(busno); + if (!i2c) + { + return -ENODEV; + } + + /* Then register the barometer sensor */ + + ret = bme680_register(devno, i2c, &g_bme680_config); + if (ret < 0) + { + snerr("ERROR: Error registering BME680\n"); + } + + return ret; +} diff --git a/boards/arm/nrf91/thingy91/configs/thingy91_rtt/defconfig b/boards/arm/nrf91/thingy91/configs/thingy91_rtt/defconfig new file mode 100644 index 0000000000000..5476f2c9f4eac --- /dev/null +++ b/boards/arm/nrf91/thingy91/configs/thingy91_rtt/defconfig @@ -0,0 +1,67 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_NSH_DISABLE_IFCONFIG is not set +# CONFIG_NSH_DISABLE_PS is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="thingy91" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_THINGY91=y +CONFIG_ARCH_CHIP="nrf91" +CONFIG_ARCH_CHIP_NRF9160=y +CONFIG_ARCH_CHIP_NRF91=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_STDARG_H=y +CONFIG_ARCH_TRUSTZONE_SECURE=y +CONFIG_BOARD_LOOPSPERMSEC=5500 +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SENSORS=y +CONFIG_DEBUG_SENSORS_ERROR=y +CONFIG_DEBUG_SENSORS_INFO=y +CONFIG_DEBUG_SENSORS_WARN=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEBUG_UORB=y +CONFIG_EXPERIMENTAL=y +CONFIG_IDLETHREAD_STACKSIZE=2048 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_MM_REGIONS=2 +CONFIG_NDEBUG=y +CONFIG_NRF91_SPI1_MASTER=y +CONFIG_NRF91_SPI_MASTER_INTERRUPTS=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=262144 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_SENSORS=y +CONFIG_SENSORS_ADXL372=y +CONFIG_SENSORS_ADXL372_UORB=y +CONFIG_SERIAL_RTT0=y +CONFIG_STACK_CANARIES=y +CONFIG_STACK_COLORATION=y +CONFIG_STACK_USAGE=y +CONFIG_START_DAY=26 +CONFIG_START_MONTH=3 +CONFIG_SYMTAB_ORDEREDBYNAME=y +CONFIG_SYSLOG_RTT=y +CONFIG_SYSTEM_NSH=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_UORB=y +CONFIG_UORB_ALERT=y +CONFIG_UORB_ERROR=y +CONFIG_UORB_INFO=y +CONFIG_UORB_LISTENER=y +CONFIG_UORB_WARN=y +CONFIG_USENSOR=y diff --git a/boards/arm/nrf91/thingy91/src/CMakeLists.txt b/boards/arm/nrf91/thingy91/src/CMakeLists.txt index 991764c8e7854..b3ec909aaf512 100644 --- a/boards/arm/nrf91/thingy91/src/CMakeLists.txt +++ b/boards/arm/nrf91/thingy91/src/CMakeLists.txt @@ -20,12 +20,20 @@ # # ############################################################################## -set(SRCS nrf91_boot.c nrf91_bringup.c) +set(SRCS nrf91_boot.c nrf91_bringup.c nrf91_sensors.c) if(CONFIG_ARCH_BUTTONS) list(APPEND SRCS nrf91_buttons.c) endif() +if(CONFIG_NRF91_SPI_MASTER) + list(APPEND SRCS nrf91_spi.c) +endif() + +if(CONFIG_I2C) + list(APPEND SRCS nrf91_i2c.c) +endif() + if(CONFIG_NRF91_MODEM) list(APPEND SRCS nrf91_modem.c) endif() diff --git a/boards/arm/nrf91/thingy91/src/Make.defs b/boards/arm/nrf91/thingy91/src/Make.defs index 599f6f5a9b836..d68245956ef36 100644 --- a/boards/arm/nrf91/thingy91/src/Make.defs +++ b/boards/arm/nrf91/thingy91/src/Make.defs @@ -22,7 +22,7 @@ include $(TOPDIR)/Make.defs -CSRCS = nrf91_boot.c nrf91_bringup.c +CSRCS = nrf91_boot.c nrf91_bringup.c nrf91_sensors.c ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += nrf91_buttons.c @@ -32,6 +32,14 @@ ifeq ($(CONFIG_NRF91_MODEM),y) CSRCS += nrf91_modem.c endif +ifeq ($(CONFIG_NRF91_SPI_MASTER),y) +CSRCS += nrf91_spi.c +endif + +ifeq ($(CONFIG_I2C),y) +CSRCS += nrf91_i2c.c +endif + DEPPATH += --dep-path board VPATH += :board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board diff --git a/boards/arm/nrf91/thingy91/src/nrf91_boot.c b/boards/arm/nrf91/thingy91/src/nrf91_boot.c index 0450484bb9581..a5e2cdcf4f350 100644 --- a/boards/arm/nrf91/thingy91/src/nrf91_boot.c +++ b/boards/arm/nrf91/thingy91/src/nrf91_boot.c @@ -56,6 +56,12 @@ void nrf91_board_initialize(void) #ifdef CONFIG_ARCH_LEDS board_autoled_initialize(); #endif + +#ifdef CONFIG_NRF91_SPI_MASTER + /* Configure SPI chip selects */ + + nrf91_spidev_initialize(); +#endif } /**************************************************************************** diff --git a/boards/arm/nrf91/thingy91/src/nrf91_bringup.c b/boards/arm/nrf91/thingy91/src/nrf91_bringup.c index 9c80e57eb4406..4d52425598db1 100644 --- a/boards/arm/nrf91/thingy91/src/nrf91_bringup.c +++ b/boards/arm/nrf91/thingy91/src/nrf91_bringup.c @@ -87,6 +87,10 @@ int nrf91_bringup(void) { int ret; +#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL) + nrf91_i2ctool(); +#endif + #ifdef CONFIG_FS_PROCFS /* Mount the procfs file system */ @@ -120,6 +124,16 @@ int nrf91_bringup(void) } #endif + /* Initialzie on-board sensors */ + + ret = nrf91_sensors_init(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize sensors: %d\n", + ret); + } + #ifdef CONFIG_NRF91_MODEM /* Initialize modem */ diff --git a/boards/arm/nrf91/thingy91/src/nrf91_i2c.c b/boards/arm/nrf91/thingy91/src/nrf91_i2c.c new file mode 100644 index 0000000000000..d76554d13182d --- /dev/null +++ b/boards/arm/nrf91/thingy91/src/nrf91_i2c.c @@ -0,0 +1,118 @@ +/**************************************************************************** + * boards/arm/nrf91/thingy91/src/nrf91_i2c.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#ifdef CONFIG_I2C +# include "nrf91_i2c.h" +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_I2CTOOL +int nrf91_i2c_register(int bus) +{ + struct i2c_master_s *i2c; + int ret = OK; + + i2c = nrf91_i2cbus_initialize(bus); + if (i2c == NULL) + { + syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n", + bus, ret); + nrf91_i2cbus_uninitialize(i2c); + } + } + + return ret; +} +#endif + +/**************************************************************************** + * Name: nrf91_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_I2CTOOL +int nrf91_i2ctool(void) +{ + int ret = OK; + +#ifdef CONFIG_NRF91_I2C0_MASTER + ret = nrf91_i2c_register(0); + if (ret != OK) + { + return ret; + } +#endif + +#ifdef CONFIG_NRF91_I2C1_MASTER + ret = nrf91_i2c_register(1); + if (ret != OK) + { + return ret; + } +#endif + +#ifdef CONFIG_NRF91_I2C2_MASTER + ret = nrf91_i2c_register(2); + if (ret != OK) + { + return ret; + } +#endif + +#ifdef CONFIG_NRF91_I2C3_MASTER + ret = nrf91_i2c_register(3); + if (ret != OK) + { + return ret; + } +#endif + + return ret; +} +#endif diff --git a/boards/arm/nrf91/thingy91/src/nrf91_sensors.c b/boards/arm/nrf91/thingy91/src/nrf91_sensors.c new file mode 100644 index 0000000000000..880c3bb61d75f --- /dev/null +++ b/boards/arm/nrf91/thingy91/src/nrf91_sensors.c @@ -0,0 +1,130 @@ +/**************************************************************************** + * boards/arm/nrf91/thingy91/src/nrf91_sensors.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#ifdef CONFIG_SENSORS_BH1749NUC +# include "nrf91_bh1749nuc.h" +#endif + +#ifdef CONFIG_SENSORS_BME680 +# include "nrf91_bme680.h" +#endif + +#ifdef CONFIG_SENSORS_ADXL362 +# include "nrf91_adxl362.h" +#endif + +#ifdef CONFIG_SENSORS_ADXL372 +# include "nrf91_adxl372.h" +#endif + +#include "thingy91.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BH1749NUC_I2C_ADDR 0x38 +#define BH1749NUC_I2C_BUS 2 + +#define BME680_I2C_BUS 2 + +#define ADXL372_SPI_BUS 1 +#define ADXL362_SPI_BUS 1 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_sensors_init + * + * Description: + * Initialzie on-board sensors + * + ****************************************************************************/ + +int nrf91_sensors_init(void) +{ + int ret = OK; + + UNUSED(ret); + +#ifdef CONFIG_SENSORS_BH1749NUC + nrf91_gpio_config(GPIO_BH1749_INT); + + /* Initialize BH1749NUC */ + + ret = nrf91_bh1749nuc_init(0, BH1749NUC_I2C_BUS, BH1749NUC_I2C_ADDR); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf91_bh1749nuc_init failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_BME680 + /* Initialize BME680 */ + + ret = nrf91_bme680_init(0, BME680_I2C_BUS); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf91_bme680_init failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_ADXL372 + nrf91_gpio_config(GPIO_ADXL372_INT1); + + /* Initialize ADXL372 */ + + ret = nrf91_adxl372_init(ADXL372_SPI_DEVNO, ADXL372_SPI_BUS); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf91_adxl372_init failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_ADXL362 + nrf91_gpio_config(GPIO_ADXL362_INT1); + + /* Initialize ADXL362 */ + + ret = nrf91_adxl362_init(ADXL362_SPI_DEVNO, ADXL362_SPI_BUS); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf91_adxl362_init failed: %d\n", ret); + } +#endif + + return ret; +} diff --git a/boards/arm/nrf91/thingy91/src/nrf91_spi.c b/boards/arm/nrf91/thingy91/src/nrf91_spi.c new file mode 100644 index 0000000000000..420b19d6ec9cf --- /dev/null +++ b/boards/arm/nrf91/thingy91/src/nrf91_spi.c @@ -0,0 +1,208 @@ +/**************************************************************************** + * boards/arm/nrf91/thingy91/src/nrf91_spi.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#include "arm_internal.h" +#include "chip.h" +#include "nrf91_gpio.h" +#include "nrf91_spi.h" + +#include "thingy91.h" +#include + +#ifdef CONFIG_NRF91_SPI_MASTER + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf91_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the Nucleo-144 board. + * + ****************************************************************************/ + +void nrf91_spidev_initialize(void) +{ +#ifdef CONFIG_NRF91_SPI1_MASTER + nrf91_gpio_config(GPIO_ADXL372_CS); + nrf91_gpio_write(GPIO_ADXL372_CS, true); + + nrf91_gpio_config(GPIO_ADXL362_CS); + nrf91_gpio_write(GPIO_ADXL362_CS, true); +#endif +} + +/**************************************************************************** + * Name: nrf91_spi0/1/2/3/select and nrf91_spi0/1/2/3/status + * + * Description: + * The external functions, nrf91_spi0/1/2/3select and + * nrf91_spi0/1/2/3status must be provided by board-specific logic. + * They are implementations of the select and status methods of the SPI + * interface defined by struct spi_ops_s (see include/nuttx/spi/spi.h). + * All other methods (including nrf91_spibus_initialize()) are provided + * by common NRF91 logic. To use this common SPI logic on your board: + * + * 1. Provide logic in nrf91_boardinitialize() to configure SPI chip select + * pins. + * 2. Provide nrf91_spi0/1/2/3select() and nrf91_spi0/1/2/3status() + * functions in your board-specific logic. These functions will perform + * chip selection and status operations using GPIOs in the way your + * board is configured. + * 3. Add a calls to nrf91_spibus_initialize() in your low level + * application initialization logic + * 4. The handle returned by nrf91_spibus_initialize() may then be used to + * bind the SPI driver to higher level logic (e.g., calling + * mmcsd_spislotinitialize(), for example, will bind the SPI driver to + * the SPI MMC/SD driver). + * + ****************************************************************************/ + +#ifdef CONFIG_NRF91_SPI0_MASTER +void nrf91_spi0select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %08lx CS: %s\n", + (unsigned long)devid, selected ? "assert" : "de-assert"); +} + +uint8_t nrf91_spi0status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_NRF91_SPI1_MASTER +void nrf91_spi1select(struct spi_dev_s *dev, uint32_t devid, bool selected) +{ + spiinfo("devid: %08lx CS: %s\n", (unsigned long)devid, + selected ? "assert" : "de-assert"); + + switch (devid) + { +#ifdef CONFIG_SENSORS_ADXL372 + case SPIDEV_ACCELEROMETER(ADXL372_SPI_DEVNO): + { + spiinfo("ADXL372 device %s\n", + selected ? "asserted" : "de-asserted"); + + /* Set the GPIO low to select and high to de-select */ + + nrf91_gpio_write(GPIO_ADXL372_CS, !selected); + break; + } +#endif + +#ifdef CONFIG_SENSORS_ADXL362 + case SPIDEV_ACCELEROMETER(ADXL362_SPI_DEVNO): + { + spiinfo("ADXL372 device %s\n", + selected ? "asserted" : "de-asserted"); + + /* Set the GPIO low to select and high to de-select */ + + nrf91_gpio_write(GPIO_ADXL362_CS, !selected); + break; + } +#endif + + default: + { + break; + } + } +} + +uint8_t nrf91_spi1status(struct spi_dev_s *dev, uint32_t devid) +{ + uint8_t status = 0; + + switch (devid) + { +#ifdef CONFIG_SENSORS_ADXL372 + case SPIDEV_ACCELEROMETER(ADXL372_SPI_DEVNO): + { + status |= SPI_STATUS_PRESENT; + break; + } +#endif + +#ifdef CONFIG_SENSORS_ADXL362 + case SPIDEV_ACCELEROMETER(ADXL362_SPI_DEVNO): + { + status |= SPI_STATUS_PRESENT; + break; + } +#endif + + default: + { + break; + } + } + + return status; +} +#endif + +#ifdef CONFIG_nrf91_SPI2_MASTER +void nrf91_spi2select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %08lx CS: %s\n", + (unsigned long)devid, selected ? "assert" : "de-assert"); +} + +uint8_t nrf91_spi2status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_NRF91_SPI3_MASTER +void nrf91_spi3select(struct spi_dev_s *dev, uint32_t devid, + bool selected) +{ + spiinfo("devid: %08lx CS: %s\n", + (unsigned long)devid, selected ? "assert" : "de-assert"); +} + +uint8_t nrf91_spi3status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#endif /* CONFIG_NRF91_SPI_MASTER */ diff --git a/boards/arm/nrf91/thingy91/src/thingy91.h b/boards/arm/nrf91/thingy91/src/thingy91.h index 381e90736c2ad..26cef5ca96234 100644 --- a/boards/arm/nrf91/thingy91/src/thingy91.h +++ b/boards/arm/nrf91/thingy91/src/thingy91.h @@ -67,12 +67,13 @@ /* Supported devices ********************************************************/ /* ADXL372 - * INT1 - P0.09 - * CS - P0.08 + * INT1 - P0.06 + * CS - P0.07 */ #define GPIO_ADXL372_INT1 (GPIO_INPUT | GPIO_PORT0 | GPIO_PIN(6)) #define GPIO_ADXL372_CS (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(7)) +#define ADXL372_SPI_DEVNO 0 /* ADXL362 * INT1 - P0.09 @@ -81,8 +82,9 @@ #define GPIO_ADXL362_INT1 (GPIO_INPUT | GPIO_PORT0 | GPIO_PIN(9)) #define GPIO_ADXL362_CS (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(8)) +#define ADXL362_SPI_DEVNO 1 -/* BH1749 +/* BH1749NUC * INT - P0.27 */ @@ -121,5 +123,52 @@ int nrf91_bringup(void); +/**************************************************************************** + * Name: nrf91_sensors_init + * + * Description: + * Initialzie on-board sensors + * + ****************************************************************************/ + +int nrf91_sensors_init(void); + +/**************************************************************************** + * Name: nrf91_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef CONFIG_I2C +int nrf91_i2c_register(int bus); +#endif + +/**************************************************************************** + * Name: nrf91_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_I2CTOOL +int nrf91_i2ctool(void); +#endif + +/**************************************************************************** + * Name: nrf91_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the + * thingy91 board. + * + ****************************************************************************/ + +#ifdef CONFIG_NRF91_SPI_MASTER +void nrf91_spidev_initialize(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_ARM_NRF91_THINGY91_SRC_THINGY91_H */ diff --git a/drivers/sensors/adxl372_uorb.c b/drivers/sensors/adxl372_uorb.c index 168c3e21d01d5..d9267755f1cbd 100644 --- a/drivers/sensors/adxl372_uorb.c +++ b/drivers/sensors/adxl372_uorb.c @@ -111,7 +111,7 @@ static const struct sensor_ops_s g_adxl372_accel_ops = NULL, /* selftest */ NULL, /* set_calibvalue */ NULL, /* calibrate */ - NULL /* get_info */ + NULL, /* get_info */ NULL, /* set_nonwakeup */ NULL /* control */ };