Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ported driver to zephyr
  • Loading branch information
vid553 committed Sep 3, 2020
commit 32331662b1f0a9ecfddddf71ffd7ba37b9b507ee
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ Temporary Items
*~
[._]*.un~
*.swp

# Zephyr build files
examples/Example_Zephyr/build/*
12 changes: 12 additions & 0 deletions examples/Example_Zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)

find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
project(sparkfun_ublox_zephyr_library)

zephyr_include_directories(../../src/)
target_sources(app PRIVATE ../../src/SparkFun_Ublox_Zephyr_Library.cpp)
target_sources(app PRIVATE ../../src/ublox_lib_interface.cpp)

target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c)
4 changes: 4 additions & 0 deletions examples/Example_Zephyr/nrf52840dk_nrf52840.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&i2c0 {
status = "okay";
compatible = "nordic,nrf-twim";
};
7 changes: 7 additions & 0 deletions examples/Example_Zephyr/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#turn on c++ support
CONFIG_CPLUSPLUS=y

# turn on peripherals
CONFIG_GPIO=y
CONFIG_I2C=y
CONFIG_I2C_0=y
95 changes: 95 additions & 0 deletions examples/Example_Zephyr/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Read NMEA sentences over I2C using Ublox module SAM-M8Q, NEO-M8P, ZED-F9P, etc
By: Nathan Seidle
SparkFun Electronics
Date: August 22nd, 2018
License: MIT. See license file for more information but you can
basically do whatever you want with this code.

This example reads the NMEA setences from the Ublox module over I2c and outputs
them to the serial port

Open the serial monitor at 115200 baud to see the output
I2C clock speed: 100 kHz
*/

#include <zephyr/types.h>
#include <zephyr.h>
#include <device.h>
#include <drivers/i2c.h>

#include "ublox_lib_interface.h"


#define I2C_DEV "I2C_0"

struct device *gpio_dev;
struct device *i2c_dev;
/* I2C pins used are defaults for I2C_0 on nrf52840
SDA: 26
SCL: 27
*/

uint8_t init_gpio(void) {
const char* const gpioName = "GPIO_0";
gpio_dev = device_get_binding(gpioName);
if (gpio_dev == NULL) {
printk("Could not get %s device\n", gpioName);
return -1;
}
int err = set_gpio_dev(gpio_dev);
if (err) {
return -1;
}
return 0;
}

uint8_t init_i2c(void) {
i2c_dev = device_get_binding(I2C_DEV);
if (!i2c_dev)
{
printk("I2C_0 error\n");
return -1;
}
else
{
printk("I2C_0 Init OK\n");
return 0;
}
}

uint8_t init_gps(void) {
if (gps_begin(i2c_dev) != 0)
{
printk("Ublox GPS init error!\n");
return -1;
}
return 0;
}


void main(void) {
printk("UBlox i2c test\n");

int err;
err = init_gpio();
if (err) {
return;
}
err = init_i2c();
if (err) {
return;
}

err = init_gps();
if (err) {
return;
}

while(1) {
//check_ublox(); // See if new data is available. Process bytes as they come in.
get_position();
get_datetime();
k_msleep(250); // Don't pound too hard on the I2C bus
}
}
Loading