forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
boards: cxd56xx: Add cxd5610 gnss lowerhalf driver
Add cxd5610 gnss lowerhalf driver with i2c interface.
- Loading branch information
Showing
5 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <nuttx/config.h> | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <errno.h> | ||
#include <debug.h> | ||
#include <nuttx/sensors/cxd5610_gnss.h> | ||
#include <nuttx/i2c/i2c_master.h> | ||
#include <arch/chip/pin.h> | ||
#include <arch/board/board.h> | ||
#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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <nuttx/config.h> | ||
|
||
/**************************************************************************** | ||
* 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 */ |