diff --git a/boards/arm/cxd56xx/common/CMakeLists.txt b/boards/arm/cxd56xx/common/CMakeLists.txt index 4ed42aa228..65bbb9e36c 100644 --- a/boards/arm/cxd56xx/common/CMakeLists.txt +++ b/boards/arm/cxd56xx/common/CMakeLists.txt @@ -179,5 +179,9 @@ if(CONFIG_ARCH_BOARD_COMMON) list(APPEND SRCS src/cxd56_usbdevserialstr.c) endif() + if(CONFIG_CXD56_GNSS_ADDON) + list(APPEND SRCS src/cxd56_gnss_addon.c) + endif() + target_sources(board PRIVATE ${SRCS}) endif() diff --git a/boards/arm/cxd56xx/common/src/Make.defs b/boards/arm/cxd56xx/common/src/Make.defs index f118b89607..cfa132ed09 100644 --- a/boards/arm/cxd56xx/common/src/Make.defs +++ b/boards/arm/cxd56xx/common/src/Make.defs @@ -184,6 +184,10 @@ ifeq ($(CONFIG_PM),y) CSRCS += cxd56_pm.c endif +ifeq ($(CONFIG_CXD56_GNSS_ADDON),y) + CSRCS += cxd56_gnss_addon.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/cxd56xx/common/src/cxd56_gnss_addon.c b/boards/arm/cxd56xx/common/src/cxd56_gnss_addon.c new file mode 100644 index 0000000000..4820ae9ea5 --- /dev/null +++ b/boards/arm/cxd56xx/common/src/cxd56_gnss_addon.c @@ -0,0 +1,163 @@ +/**************************************************************************** + * boards/arm/cxd56xx/common/src/cxd56_gnss_addon.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 +#include +#include +#include "cxd56_i2c.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* I2C interface */ + +#define CXD5610_I2C_ADDR 0x24 +#define CXD5610_I2C_FREQ 400000 +#define CXD5610_INT_PIN PIN_SEN_IRQ_IN + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int cxd5610_gnss_i2csend(struct cxd5610_gnss_lowerhalf_s *lower, + uint8_t *buffer, int buflen); +static int cxd5610_gnss_i2crecv(struct cxd5610_gnss_lowerhalf_s *lower, + uint8_t *buffer, int buflen); +static int cxd5610_gnss_enableint(struct cxd5610_gnss_lowerhalf_s *lower, + void (*handler)(void)); +static int cxd5610_gnss_disableint(struct cxd5610_gnss_lowerhalf_s *lower); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct cxd5610_gnss_lowerops_s g_gnss_addon_ops = +{ + cxd5610_gnss_i2csend, + cxd5610_gnss_i2crecv, + cxd5610_gnss_enableint, + cxd5610_gnss_disableint +}; + +static struct cxd5610_gnss_lowerhalf_s g_gnss_addon_lowerhalf = +{ + &g_gnss_addon_ops +}; + +static struct i2c_master_s *g_i2c; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int cxd5610_gnss_i2csend(struct cxd5610_gnss_lowerhalf_s *lower, + uint8_t *buffer, int buflen) +{ + struct i2c_msg_s msg; + int ret; + + msg.frequency = CXD5610_I2C_FREQ; + msg.addr = CXD5610_I2C_ADDR; + msg.flags = 0; + msg.buffer = buffer; + msg.length = buflen; + + ret = I2C_TRANSFER(g_i2c, &msg, 1); + + return ret; +} + +static int cxd5610_gnss_i2crecv(struct cxd5610_gnss_lowerhalf_s *lower, + uint8_t *buffer, int buflen) +{ + struct i2c_msg_s msg; + int ret; + + msg.frequency = CXD5610_I2C_FREQ; + msg.addr = CXD5610_I2C_ADDR; + msg.flags = I2C_M_READ; + msg.buffer = buffer; + msg.length = buflen; + + ret = I2C_TRANSFER(g_i2c, &msg, 1); + return ret; +} + +static int cxd5610_gnss_enableint(struct cxd5610_gnss_lowerhalf_s *lower, + void (*handler)(void)) +{ + /* Enable interrupt from CXD5610 device */ + + board_gpio_config(CXD5610_INT_PIN, 0, true, false, PIN_PULLDOWN); + board_gpio_intconfig(CXD5610_INT_PIN, INT_RISING_EDGE, false, + (xcpt_t)handler); + board_gpio_int(CXD5610_INT_PIN, true); + + return OK; +} + +static int cxd5610_gnss_disableint(struct cxd5610_gnss_lowerhalf_s *lower) +{ + /* Disable interrupt */ + + board_gpio_int(CXD5610_INT_PIN, false); + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int board_gnss_addon_initialize(const char *devpath, int bus) +{ + int ret; + + sninfo("Initializing CXD5610 GNSS...\n"); + + /* Initialize i2c device */ + + g_i2c = cxd56_i2cbus_initialize(bus); + if (!g_i2c) + { + snerr("ERROR: Failed to initialize i2c%d.\n", bus); + return -ENODEV; + } + + ret = cxd5610_gnss_register(devpath, &g_gnss_addon_lowerhalf); + if (ret < 0) + { + snerr("ERROR: registering CXD5610 GNSS.\n"); + } + + return ret; +} diff --git a/boards/arm/cxd56xx/spresense/Kconfig b/boards/arm/cxd56xx/spresense/Kconfig index d988d0c641..1b6fded184 100644 --- a/boards/arm/cxd56xx/spresense/Kconfig +++ b/boards/arm/cxd56xx/spresense/Kconfig @@ -838,4 +838,22 @@ config CXD56_EMMC_POWER_PIN_UART2_CTS endchoice +config CXD56_GNSS_ADDON + bool "CXD5610 GNSS Add-on board" + default n + depends on SENSORS_CXD5610_GNSS && CXD56_I2C0 && !CXD56_I2C0_SCUSEQ + ---help--- + The CXD5610 GNSS Add-on driver can be registered. + +if CXD56_GNSS_ADDON + +config CXD56_GNSS_ADDON_LATE_INITIALIZE + bool "CXD5610 GNSS driver late initialization" + default n + ---help--- + The CXD5610 gnss driver can be initialized on an application code + after system booted up by enabling this configuration switch. + +endif # CXD56_GNSS_ADDON + endif diff --git a/boards/arm/cxd56xx/spresense/include/cxd56_gnss_addon.h b/boards/arm/cxd56xx/spresense/include/cxd56_gnss_addon.h new file mode 100644 index 0000000000..3d0b34724c --- /dev/null +++ b/boards/arm/cxd56xx/spresense/include/cxd56_gnss_addon.h @@ -0,0 +1,71 @@ +/**************************************************************************** + * boards/arm/cxd56xx/spresense/include/cxd56_gnss_addon.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_CXD56XX_SPRESENSE_INCLUDE_CXD56_GNSS_ADDON_H +#define __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_GNSS_ADDON_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: board_gnss_addon_initialize + * + * Description: + * Initialize CXD5610 GNSS i2c driver and register the CXD5610 GNSS device. + * + ****************************************************************************/ + +#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_CXD5610_GNSS) +int board_gnss_addon_initialize(const char *devpath, int bus); +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_GNSS_ADDON_H */