Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Zephyr port of this library (I2C only) #145

Merged
merged 8 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/Zephyr/*/build/*
14 changes: 14 additions & 0 deletions examples/Zephyr/Example1_GetPositionAndTime_Zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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_compile_options(-fdiagnostics-color=always)

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

target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c)
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/Zephyr/Example1_GetPositionAndTime_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
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
This is an interface that connects the CPP Ublox library with the main C code.
Added to make it possible to run Ublox lib on Zephyr (NCS)

This port was made by Vid Rajtmajer <vid@irnas.eu>, www.irnas.eu
*/
#include "SparkFun_Ublox_Zephyr_Interface.h"

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

#include "SparkFun_Ublox_Zephyr_Library.h"


SFE_UBLOX_GPS myGPS; // driver class instance
long lastTime = 0; // Simple local timer. Limits amount if I2C traffic to Ublox module.

// init GPIO checksumFailurePin and load GPIO device pointer to the driver
uint8_t set_gpio_dev(struct device *gpio_dev, uint8_t enable_debug)
{
if (myGPS.init_gpio_pins(*gpio_dev) == false)
{
return -EIO;
}
// turn on debugging if enable_debug is set
if (enable_debug)
{
myGPS.enableDebugging();
}
return 0;
}

// initialize I2C and check if GPS device respons
uint8_t gps_begin(struct device *i2c_dev)
{
if (myGPS.begin(*i2c_dev) == false)
{
return -EIO;
}
return 0;
}

// This will pipe all NMEA sentences to UART so we can see them
void pipe_nmea_sentences(void)
{
myGPS.setNMEAOutputPort();
}

// Check for available bytes from the device
void check_ublox(void)
{
myGPS.checkUblox();
}

// Get position information when requested, also display number of satellites used in the fix
int get_position(void)
{
//Query module only every second. Doing it more often will just cause I2C traffic.
//The module only responds when a new position is available, print it to console
if (k_uptime_get_32() - lastTime > 1000)
{
lastTime = k_uptime_get_32(); //Update the timer

long latitude = myGPS.getLatitude();
long longitude = myGPS.getLongitude();
long altitude = myGPS.getAltitude();
uint8_t SIV = myGPS.getSIV();

printk("Position: Lat: %ld, Lon: %ld, Alt: %ld, SIV: %d", latitude, longitude, altitude, SIV);
return 0;
}
return -EBUSY;
}

// Get date and time information when requested, check if they are valid and print info to console, it returns UNIX time
void get_datetime(void)
{
int year = myGPS.getYear();
int month = myGPS.getMonth();
int day = myGPS.getDay();
int hour = myGPS.getHour();
int minute = myGPS.getMinute();
int second = myGPS.getSecond();

printk("DateTime: %d-%d-%d %d:%d:%d\n", year, month, day, hour, minute, second);

printk("Time is ");
if (myGPS.getTimeValid() == false)
{
printk("not ");
}
printk("valid. Date is ");
if (myGPS.getDateValid() == false)
{
printk("not ");
}
printk("valid.\n");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
This is an interface that connects the CPP Ublox library with the main C code.
Added to make it possible to run Ublox lib on Zephyr (NCS)

This port was made by Vid Rajtmajer <vid@irnas.eu>, www.irnas.eu
*/
#include <time.h>
#include <zephyr.h>

#ifndef _UBLOX_LIB_INTERFACE_H_
#define _UBLOX_LIB_INTERFACE_H_

#ifdef __cplusplus
extern "C" {
#endif

uint8_t set_gpio_dev(struct device *gpio_dev, uint8_t enable_debug); // init GPIO
uint8_t gps_begin(struct device *i2c_dev); // initialize I2C and check if GPS device respons
void pipe_nmea_sentences(void); // print NMEA sentences

void check_ublox(void); // Check for available bytes from the device
int get_position(void); // Get position information
void get_datetime(void); // Get date and time information

#ifdef __cplusplus
}
#endif

#endif //UBLOX_LIB_INTERFACE_H_
Loading