From 027e3df637a9a4cd1397e55287b90bb33a4cc051 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Mon, 10 Jun 2024 13:07:02 +0200 Subject: [PATCH] boards/thingy53: add sensors support Add support for sensors: ADXL362, BH1749NUC, BMI270, BMM150 --- .../arm/nrf53/boards/thingy53/index.rst | 10 +- .../arm/nrf53/common/include/nrf53_adxl362.h | 51 ++++ .../nrf53/common/include/nrf53_bh1749nuc.h | 52 ++++ .../arm/nrf53/common/include/nrf53_bmi270.h | 57 +++++ .../arm/nrf53/common/include/nrf53_bmm150.h | 52 ++++ boards/arm/nrf53/common/src/CMakeLists.txt | 16 ++ boards/arm/nrf53/common/src/Make.defs | 16 ++ boards/arm/nrf53/common/src/nrf53_adxl362.c | 79 ++++++ boards/arm/nrf53/common/src/nrf53_bh1749nuc.c | 92 +++++++ boards/arm/nrf53/common/src/nrf53_bmi270.c | 112 +++++++++ boards/arm/nrf53/common/src/nrf53_bmm150.c | 88 +++++++ boards/arm/nrf53/thingy53/src/CMakeLists.txt | 10 +- boards/arm/nrf53/thingy53/src/Make.defs | 10 +- boards/arm/nrf53/thingy53/src/nrf53_boot.c | 7 +- boards/arm/nrf53/thingy53/src/nrf53_bringup.c | 12 +- boards/arm/nrf53/thingy53/src/nrf53_sensors.c | 137 +++++++++++ boards/arm/nrf53/thingy53/src/nrf53_spi.c | 226 ++++++++++++++++++ boards/arm/nrf53/thingy53/src/thingy53.h | 25 ++ 18 files changed, 1042 insertions(+), 10 deletions(-) create mode 100644 boards/arm/nrf53/common/include/nrf53_adxl362.h create mode 100644 boards/arm/nrf53/common/include/nrf53_bh1749nuc.h create mode 100644 boards/arm/nrf53/common/include/nrf53_bmi270.h create mode 100644 boards/arm/nrf53/common/include/nrf53_bmm150.h create mode 100644 boards/arm/nrf53/common/src/nrf53_adxl362.c create mode 100644 boards/arm/nrf53/common/src/nrf53_bh1749nuc.c create mode 100644 boards/arm/nrf53/common/src/nrf53_bmi270.c create mode 100644 boards/arm/nrf53/common/src/nrf53_bmm150.c create mode 100644 boards/arm/nrf53/thingy53/src/nrf53_sensors.c create mode 100644 boards/arm/nrf53/thingy53/src/nrf53_spi.c diff --git a/Documentation/platforms/arm/nrf53/boards/thingy53/index.rst b/Documentation/platforms/arm/nrf53/boards/thingy53/index.rst index 62ecd18b7b..c9a42d6a0f 100644 --- a/Documentation/platforms/arm/nrf53/boards/thingy53/index.rst +++ b/Documentation/platforms/arm/nrf53/boards/thingy53/index.rst @@ -22,11 +22,11 @@ Battery monitoring No Buzzer No PDM microphone (VM3011) No Front End Module (nRF21540) No -Low power accelerometer (ADXL362) No -IMU (BMI270) No -Magnetometer (BMM150) No -Air quality sensor (HBME688) No -Color sensor (VM3011) No +Low power accelerometer (ADXL362) Yes SPI +IMU (BMI270) Yes SPI or I2C 0x68 +Magnetometer (BMM150) Yes I2C 0x10 +Color sensor (BH1749NUC) Yes I2C 0x38 +Air quality sensor (BME688) No I2C 0x76 ================================== ======= ============= Serial Console diff --git a/boards/arm/nrf53/common/include/nrf53_adxl362.h b/boards/arm/nrf53/common/include/nrf53_adxl362.h new file mode 100644 index 0000000000..fcf5c46728 --- /dev/null +++ b/boards/arm/nrf53/common/include/nrf53_adxl362.h @@ -0,0 +1,51 @@ +/**************************************************************************** + * boards/arm/nrf53/common/include/nrf53_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_NRF53_COMMON_INCLUDE_NRF53_ADXL362_H +#define __BOARDS_ARM_NRF53_COMMON_INCLUDE_NRF53_ADXL362_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_adxl362_initialize + * + * Description: + * Initialize and register the ADXL362 as uorb sensor + * + * Input Parameters: + * devno - The user specifies device number, from 0. + * busno - SPI or I2C bus number + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int nrf53_adxl362_init(int devno, int busno); + +#endif /* __BOARDS_ARM_NRF53_COMMON_INCLUDE_NRF53_ADXL362_H */ diff --git a/boards/arm/nrf53/common/include/nrf53_bh1749nuc.h b/boards/arm/nrf53/common/include/nrf53_bh1749nuc.h new file mode 100644 index 0000000000..689db87a57 --- /dev/null +++ b/boards/arm/nrf53/common/include/nrf53_bh1749nuc.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * boards/arm/nrf53/common/include/nrf53_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_NRF53_COMMON_INCLUDE_NRF53_BH1749NUC_H +#define __BOARDS_ARM_NRF53_COMMON_INCLUDE_NRF53_BH1749NUC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_bh1749nuc_init + * + * Description: + * Initialize and register the BH1749NUC as uorb sensor + * + * Input Parameters: + * devno - The user specifies device number, from 0. + * busno - I2C bus number + * addr - The I2C address + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int nrf53_bh1749nuc_init(int devno, int busno, uint8_t addr); + +#endif /* __BOARDS_ARM_NRF53_COMMON_INCLUDE_NRF53_BH1749NUC_H */ diff --git a/boards/arm/nrf53/common/include/nrf53_bmi270.h b/boards/arm/nrf53/common/include/nrf53_bmi270.h new file mode 100644 index 0000000000..5b9f3bdbaf --- /dev/null +++ b/boards/arm/nrf53/common/include/nrf53_bmi270.h @@ -0,0 +1,57 @@ +/**************************************************************************** + * boards/arm/nrf53/common/include/nrf53_bmi270.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_NRF53_COMMON_INCLUDE_NRF53_BMI270_H +#define __BOARDS_ARM_NRF53_COMMON_INCLUDE_NRF53_BMI270_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_bmi270spi_initialize + * nrf53_bmi270i2c_initialize + * + * Description: + * Initialize and register the BMI270 as uorb sensor + * + * Input Parameters: + * devno - The user specifies device number, from 0. + * busno - SPI or I2C bus number + * addr - (I2C only) The I2C address + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SENSORS_BMI270_SPI +int nrf53_bmi270spi_initialize(int devno, int busno); +#else /* CONFIG_SENSORS_BMI270_I2C */ +int nrf53_bmi270i2c_initialize(int devno, int bus, uint8_t addr); +#endif + +#endif /* __BOARDS_ARM_NRF53_COMMON_INCLUDE_NRF53_BMI270_H */ diff --git a/boards/arm/nrf53/common/include/nrf53_bmm150.h b/boards/arm/nrf53/common/include/nrf53_bmm150.h new file mode 100644 index 0000000000..ddd7742ee7 --- /dev/null +++ b/boards/arm/nrf53/common/include/nrf53_bmm150.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * boards/arm/nrf53/common/include/nrf53_bmm150.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_NRF53_COMMON_INCLUDE_NRF53_BMM150_H +#define __BOARDS_ARM_NRF53_COMMON_INCLUDE_NRF53_BMM150_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_bmm150_init + * + * Description: + * Initialize and register the BMM150 as uorb sensor + * + * Input Parameters: + * devno - The user specifies device number, from 0. + * busno - I2C bus number + * addr - The I2C address + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int nrf53_bmm150_init(int devno, int busno, uint8_t addr); + +#endif /* __BOARDS_ARM_NRF53_COMMON_INCLUDE_NRF53_BMM150_H */ diff --git a/boards/arm/nrf53/common/src/CMakeLists.txt b/boards/arm/nrf53/common/src/CMakeLists.txt index 2dafcbe790..be613cd341 100644 --- a/boards/arm/nrf53/common/src/CMakeLists.txt +++ b/boards/arm/nrf53/common/src/CMakeLists.txt @@ -36,6 +36,22 @@ if(CONFIG_ARCH_BOARD_COMMON) list(APPEND SRCS nrf53_reset.c) endif() + if(CONFIG_SENSORS_BMI270) + list(APPEND SRCS nrf53_bmi270.c) + endif() + + if(CONFIG_SENSORS_ADXL362) + list(APPEND SRCS nrf53_adxl362.c) + endif() + + if(CONFIG_SENSORS_BH1749NUC) + list(APPEND SRCS nrf53_bh1749nuc.c) + endif() + + if(CONFIG_SENSORS_BMM150) + list(APPEND SRCS nrf53_bmm150.c) + endif() + target_sources(board PRIVATE ${SRCS}) endif() diff --git a/boards/arm/nrf53/common/src/Make.defs b/boards/arm/nrf53/common/src/Make.defs index a850bac42b..dc062cc51e 100644 --- a/boards/arm/nrf53/common/src/Make.defs +++ b/boards/arm/nrf53/common/src/Make.defs @@ -36,6 +36,22 @@ ifeq ($(CONFIG_BOARDCTL_RESET),y) CSRCS += nrf53_reset.c endif +ifeq ($(CONFIG_SENSORS_BMI270),y) + CSRCS += nrf53_bmi270.c +endif + +ifeq ($(CONFIG_SENSORS_ADXL362),y) + CSRCS += nrf53_adxl362.c +endif + +ifeq ($(CONFIG_SENSORS_BH1749NUC),y) + CSRCS += nrf53_bh1749nuc.c +endif + +ifeq ($(CONFIG_SENSORS_BMM150),y) + CSRCS += nrf53_bmm150.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/nrf53/common/src/nrf53_adxl362.c b/boards/arm/nrf53/common/src/nrf53_adxl362.c new file mode 100644 index 0000000000..31248b0c16 --- /dev/null +++ b/boards/arm/nrf53/common/src/nrf53_adxl362.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * boards/arm/nrf53/common/src/nrf53_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 "nrf53_spi.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_adxl362_init + * + * Description: + * Initialize and register the ADXL362 device + * + * Input Parameters: + * devno - The user specifies device number, from 0. + * busno - SPI or I2C bus number + * addr - (I2C only) The I2C address + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int nrf53_adxl362_init(int devno, int busno) +{ + struct spi_dev_s *spi; + int ret; + + sninfo("Initializing ADXL362..\n"); + + /* Initialize spi device */ + + spi = nrf53_spibus_initialize(busno); + if (!spi) + { + snerr("ERROR: Failed to initialize spi%d.\n", busno); + return -ENODEV; + } + + ret = adxl362_register(devno, spi); + if (ret < 0) + { + snerr("Error registering ADXL362\n"); + } + + return ret; +} diff --git a/boards/arm/nrf53/common/src/nrf53_bh1749nuc.c b/boards/arm/nrf53/common/src/nrf53_bh1749nuc.c new file mode 100644 index 0000000000..b490c764ff --- /dev/null +++ b/boards/arm/nrf53/common/src/nrf53_bh1749nuc.c @@ -0,0 +1,92 @@ +/**************************************************************************** + * boards/arm/nrf53/common/src/nrf53_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 "nrf53_i2c.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_SENSORS_BH1749NUC_UORB +# error BH1749NUC UORB is only supported +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_bh1749nuc_init + * + * Description: + * Initialize and register the BH1749NUC as uorb sensor + * + * Input Parameters: + * devno - The user specifies device number, from 0. + * busno - I2C bus number + * addr - The I2C address + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int nrf53_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 = nrf53_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/nrf53/common/src/nrf53_bmi270.c b/boards/arm/nrf53/common/src/nrf53_bmi270.c new file mode 100644 index 0000000000..93f5b0ae04 --- /dev/null +++ b/boards/arm/nrf53/common/src/nrf53_bmi270.c @@ -0,0 +1,112 @@ +/**************************************************************************** + * boards/arm/nrf53/common/src/nrf53_bmi270.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 + +#ifdef CONFIG_SENSORS_BMI270_SPI +# include +# include "nrf53_spi.h" +#else +# include "nrf53_i2c.h" +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_bmi270spi_initialize + * nrf53_bmi270i2c_initialize + * + * Description: + * Initialzie and register the BMI270 character device as 'devpath' + * + * Input Parameters: + * devno - The user specifies device number, from 0. + * busno - SPI or I2C bus number + * addr - (I2C only) The I2C address + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SENSORS_BMI270_SPI +int nrf53_bmi270spi_initialize(int devno, int busno) +{ + struct spi_dev_s *spi; + int ret; + + sninfo("Initializing BMI270..\n"); + + /* Initialize spi device */ + + spi = nrf53_spibus_initialize(busno); + if (!spi) + { + snerr("ERROR: Failed to initialize spi%d.\n", busno); + return -ENODEV; + } + + ret = bmi270_register_uorb(devno, spi); + if (ret < 0) + { + snerr("Error registering BMI160\n"); + } + + return ret; +} +#else /* CONFIG_SENSORS_BMI270_I2C */ +int nrf53_bmi270i2c_initialize(int devno, int busno, uint8_t addr) +{ + struct i2c_master_s *i2c; + int ret; + + sninfo("Initializing BMI270!\n"); + + /* Initialize I2C */ + + i2c = nrf53_i2cbus_initialize(busno); + if (!i2c) + { + return -ENODEV; + } + + /* Then register the barometer sensor */ + + ret = bmi270_register_uorb(devno, i2c, addr); + if (ret < 0) + { + snerr("ERROR: Error registering BM180\n"); + } + + return ret; +} +#endif diff --git a/boards/arm/nrf53/common/src/nrf53_bmm150.c b/boards/arm/nrf53/common/src/nrf53_bmm150.c new file mode 100644 index 0000000000..43ffa81999 --- /dev/null +++ b/boards/arm/nrf53/common/src/nrf53_bmm150.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * boards/arm/nrf53/common/src/nrf53_bmm150.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 "nrf53_i2c.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_bmm150_init + * + * Description: + * Initialize and register the BMM150 as uorb sensor + * + * Input Parameters: + * devno - The user specifies device number, from 0. + * busno - I2C bus number + * addr - The I2C address + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int nrf53_bmm150_init(int devno, int busno, uint8_t addr) +{ + struct bmm150_config_s config; + struct i2c_master_s *i2c; + int ret; + + sninfo("Initializing BMM150!\n"); + + /* Initialize I2C */ + + i2c = nrf53_i2cbus_initialize(busno); + if (!i2c) + { + return -ENODEV; + } + + /* Then register the barometer sensor */ + + config.i2c = i2c; + config.addr = addr; + + ret = bmm150_register_uorb(devno, &config); + if (ret < 0) + { + snerr("ERROR: Error registering BMM150\n"); + } + + return ret; +} diff --git a/boards/arm/nrf53/thingy53/src/CMakeLists.txt b/boards/arm/nrf53/thingy53/src/CMakeLists.txt index 8f03024b83..ce08efc044 100644 --- a/boards/arm/nrf53/thingy53/src/CMakeLists.txt +++ b/boards/arm/nrf53/thingy53/src/CMakeLists.txt @@ -18,7 +18,7 @@ # # ############################################################################## -set(SRCS nrf53_boot.c nrf53_bringup.c) +set(SRCS nrf53_boot.c nrf53_bringup.c nrf53_sensors.c) if(CONFIG_BOARDCTL) list(APPEND SRCS nrf53_appinit.c) @@ -32,6 +32,14 @@ if(CONFIG_ARCH_BUTTONS) list(APPEND SRCS nrf53_buttons.c) endif() +if(CONFIG_NRF53_SPI_MASTER) + list(APPEND SRCS nrf53_spi.c) +endif() + +if(CONFIG_I2C) + list(APPEND SRCS nrf53_i2c.c) +endif() + if(CONFIG_USBDEV) list(APPEND SRCS nrf53_usb.c) endif() diff --git a/boards/arm/nrf53/thingy53/src/Make.defs b/boards/arm/nrf53/thingy53/src/Make.defs index 948444c74b..13a097ebd2 100644 --- a/boards/arm/nrf53/thingy53/src/Make.defs +++ b/boards/arm/nrf53/thingy53/src/Make.defs @@ -20,7 +20,7 @@ include $(TOPDIR)/Make.defs -CSRCS = nrf53_boot.c nrf53_bringup.c +CSRCS = nrf53_boot.c nrf53_bringup.c nrf53_sensors.c ifeq ($(CONFIG_BOARDCTL),y) CSRCS += nrf53_appinit.c @@ -34,6 +34,14 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += nrf53_buttons.c endif +ifeq ($(CONFIG_NRF53_SPI_MASTER),y) +CSRCS += nrf53_spi.c +endif + +ifeq ($(CONFIG_I2C),y) +CSRCS += nrf53_i2c.c +endif + ifeq ($(CONFIG_USBDEV),y) CSRCS += nrf53_usb.c endif diff --git a/boards/arm/nrf53/thingy53/src/nrf53_boot.c b/boards/arm/nrf53/thingy53/src/nrf53_boot.c index a0728f7440..b3b75c8255 100644 --- a/boards/arm/nrf53/thingy53/src/nrf53_boot.c +++ b/boards/arm/nrf53/thingy53/src/nrf53_boot.c @@ -29,7 +29,6 @@ #include #include -#include "arm_internal.h" #include "thingy53.h" /**************************************************************************** @@ -54,6 +53,12 @@ void nrf53_board_initialize(void) #ifdef CONFIG_ARCH_LEDS board_autoled_initialize(); #endif + +#ifdef CONFIG_NRF53_SPI_MASTER + /* Configure SPI chip selects */ + + nrf53_spidev_initialize(); +#endif } /**************************************************************************** diff --git a/boards/arm/nrf53/thingy53/src/nrf53_bringup.c b/boards/arm/nrf53/thingy53/src/nrf53_bringup.c index 13a94fd2e0..b78703efdb 100644 --- a/boards/arm/nrf53/thingy53/src/nrf53_bringup.c +++ b/boards/arm/nrf53/thingy53/src/nrf53_bringup.c @@ -67,8 +67,6 @@ * Pre-processor Definitions ****************************************************************************/ -#define NRF53_TIMER (0) - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -260,6 +258,16 @@ int nrf53_bringup(void) } #endif + /* Initialize on-board sensors */ + + ret = nrf53_sensors_init(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize sensors: %d\n", + ret); + } + UNUSED(ret); return OK; } diff --git a/boards/arm/nrf53/thingy53/src/nrf53_sensors.c b/boards/arm/nrf53/thingy53/src/nrf53_sensors.c new file mode 100644 index 0000000000..4efe0eba17 --- /dev/null +++ b/boards/arm/nrf53/thingy53/src/nrf53_sensors.c @@ -0,0 +1,137 @@ +/**************************************************************************** + * boards/arm/nrf53/thingy53/src/nrf53_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_BMI270 +# include "nrf53_bmi270.h" +#endif + +#ifdef CONFIG_SENSORS_ADXL362 +# include "nrf53_adxl362.h" +#endif + +#ifdef CONFIG_SENSORS_BH1749NUC +# include "nrf53_bh1749nuc.h" +#endif + +#ifdef CONFIG_SENSORS_BMM150 +# include "nrf53_bmm150.h" +#endif + +#include "arm_internal.h" + +#include "thingy53.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BMM150_I2C_BUS (2) +#define BMM150_I2C_ADDR (0x10) + +#define BH1749NUC_I2C_BUS (2) +#define BH1749NUC_I2C_ADDR (0x38) + +#define BME688_I2C_BUS (2) +#define BME688_I2C_ADDR (0x76) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_sensors_init + * + * Description: + * Initialize on-board sensors + * + ****************************************************************************/ + +int nrf53_sensors_init(void) +{ + int ret = OK; + + UNUSED(ret); + + /* Enable sensor power. + * TODO: this should be controlled by power management logic + */ + + nrf53_gpio_config(GPIO_SENS_PWRCTRL); + nrf53_gpio_write(GPIO_SENS_PWRCTRL, false); + up_mdelay(10); + nrf53_gpio_write(GPIO_SENS_PWRCTRL, true); + up_mdelay(10); + +#ifdef CONFIG_SENSORS_BMI270 + /* Initialize BMI270 */ + + ret = nrf53_bmi270spi_initialize(0, BMI270_SPIDEV); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf53_bmi270_initialize failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_BH1749NUC + /* Initialize BH1749NUC */ + + ret = nrf53_bh1749nuc_init(0, BH1749NUC_I2C_BUS, BH1749NUC_I2C_ADDR); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf53_bh1749nuc_init failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_BMM150 + /* Initialize BMM150 */ + + ret = nrf53_bmm150_init(0, BMM150_I2C_BUS, BMM150_I2C_ADDR); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf53_bmm150_init failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_SENSORS_ADXL362 + /* Initialize ADXL362 */ + + ret = nrf53_adxl362_init(1, ADXL362_SPIDEV); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: nrf53_adxl362_init failed: %d\n", ret); + } +#endif + + return ret; +} diff --git a/boards/arm/nrf53/thingy53/src/nrf53_spi.c b/boards/arm/nrf53/thingy53/src/nrf53_spi.c new file mode 100644 index 0000000000..8594d6c259 --- /dev/null +++ b/boards/arm/nrf53/thingy53/src/nrf53_spi.c @@ -0,0 +1,226 @@ +/**************************************************************************** + * boards/arm/nrf53/thingy53/src/nrf53_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 "nrf53_gpio.h" +#include "nrf53_spi.h" + +#include "thingy53.h" +#include + +#ifdef CONFIG_NRF53_SPI_MASTER + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nrf53_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the Nucleo-144 board. + * + ****************************************************************************/ + +void nrf53_spidev_initialize(void) +{ +#ifdef CONFIG_NRF53_SPI1_MASTER + nrf53_gpio_config(GPIO_NRF21540_CSN); + nrf53_gpio_write(GPIO_NRF21540_CSN, true); + + nrf53_gpio_config(GPIO_ADXL362_CS); + nrf53_gpio_write(GPIO_ADXL362_CS, true); + + nrf53_gpio_config(GPIO_BMI270_CS); + nrf53_gpio_write(GPIO_BMI270_CS, true); +#endif +} + +/**************************************************************************** + * Name: nrf53_spi0/1/2/3/select and nrf53_spi0/1/2/3/status + * + * Description: + * The external functions, nrf53_spi0/1/2/3select and + * nrf53_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 nrf53_spibus_initialize()) are provided + * by common NRF53 logic. To use this common SPI logic on your board: + * + * 1. Provide logic in nrf53_boardinitialize() to configure SPI chip select + * pins. + * 2. Provide nrf53_spi0/1/2/3select() and nrf53_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 nrf53_spibus_initialize() in your low level + * application initialization logic + * 4. The handle returned by nrf53_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_NRF53_SPI0_MASTER +void nrf53_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 nrf53_spi0status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_NRF53_SPI1_MASTER +void nrf53_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_BMI270 + case SPIDEV_IMU(0): + { + spiinfo("BMI270 device %s\n", + selected ? "asserted" : "de-asserted"); + + /* Set the GPIO low to select and high to de-select */ + + nrf53_gpio_write(GPIO_BMI270_CS, !selected); + break; + } +#endif + +#ifdef CONFIG_SENSORS_ADXL362 + case SPIDEV_ACCELEROMETER(1): + { + spiinfo("ADXL362 device %s\n", + selected ? "asserted" : "de-asserted"); + + /* Set the GPIO low to select and high to de-select */ + + nrf53_gpio_write(GPIO_ADXL362_CS, !selected); + break; + } +#endif + + default: + { + break; + } + } +} + +uint8_t nrf53_spi1status(struct spi_dev_s *dev, uint32_t devid) +{ + uint8_t status = 0; + + switch (devid) + { +#ifdef CONFIG_SENSORS_BMI270 + case SPIDEV_IMU(0): + { + status |= SPI_STATUS_PRESENT; + break; + } +#endif + +#ifdef CONFIG_SENSORS_ADXL362 + case SPIDEV_ACCELEROMETER(0): + { + status |= SPI_STATUS_PRESENT; + break; + } +#endif + + default: + { + break; + } + } + + return status; +} +#endif + +#ifdef CONFIG_nrf53_SPI2_MASTER +void nrf53_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 nrf53_spi2status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_NRF53_SPI3_MASTER +void nrf53_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 nrf53_spi3status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_NRF53_SPI4_MASTER +void nrf53_spi4select(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 nrf53_spi4status(struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#endif /* CONFIG_NRF53_SPI_MASTER */ diff --git a/boards/arm/nrf53/thingy53/src/thingy53.h b/boards/arm/nrf53/thingy53/src/thingy53.h index 348cca8a8c..3ed35f9cc0 100644 --- a/boards/arm/nrf53/thingy53/src/thingy53.h +++ b/boards/arm/nrf53/thingy53/src/thingy53.h @@ -86,6 +86,7 @@ #define GPIO_ADXL362_INT1 (GPIO_INPUT | GPIO_PORT0 | GPIO_PIN(19)) #define GPIO_ADXL362_CS (GPIO_OUTPUT | GPIO_PORT0 | GPIO_PIN(22)) +#define ADXL362_SPIDEV (1) /* BMI270 (I2C address: 0x68) * INT1 - P0.23 @@ -94,6 +95,7 @@ #define GPIO_BMI270_INT1 (GPIO_INPUT | GPIO_PORT0 | GPIO_PIN(23)) #define GPIO_BMI270_CS (GPIO_OUTPUT | GPIO_PORT1 | GPIO_PIN(4)) +#define BMI270_SPIDEV (1) /* BMM150 (I2C address: 0x10) * INT - P0.20 @@ -159,6 +161,16 @@ int nrf53_bringup(void); +/**************************************************************************** + * Name: nrf53_sensors_init + * + * Description: + * Initialize on-board sensors + * + ****************************************************************************/ + +int nrf53_sensors_init(void); + /**************************************************************************** * Name: nrf53_rgbled_initialize * @@ -193,5 +205,18 @@ int nrf53_i2c_register(int bus); int nrf53_i2ctool(void); #endif +/**************************************************************************** + * Name: nrf53_spidev_initialize + * + * Description: + * Called to configure SPI chip select GPIO pins for the + * thingy53 board. + * + ****************************************************************************/ + +#ifdef CONFIG_NRF53_SPI_MASTER +void nrf53_spidev_initialize(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_ARM_NRF53_THINGY53_SRC_THINGY53_H */