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

Commit fb99d8f

Browse files
authored
Merge pull request #145 from IRNAS/ZephyrPort
Zephyr port of this library (I2C only)
2 parents eca9868 + a2ad45f commit fb99d8f

9 files changed

+4652
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ Temporary Items
5353
*~
5454
[._]*.un~
5555
*.swp
56+
57+
# Zephyr build files
58+
examples/Zephyr/*/build/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
5+
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
6+
project(sparkfun_ublox_zephyr_library)
7+
8+
zephyr_compile_options(-fdiagnostics-color=always)
9+
10+
zephyr_include_directories(.)
11+
target_sources(app PRIVATE src/SparkFun_Ublox_Zephyr_Library.cpp)
12+
target_sources(app PRIVATE src/SparkFun_Ublox_Zephyr_Interface.cpp)
13+
14+
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
&i2c0 {
2+
status = "okay";
3+
compatible = "nordic,nrf-twim";
4+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#turn on c++ support
2+
CONFIG_CPLUSPLUS=y
3+
4+
# turn on peripherals
5+
CONFIG_GPIO=y
6+
CONFIG_I2C=y
7+
CONFIG_I2C_0=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
This is an interface that connects the CPP Ublox library with the main C code.
3+
Added to make it possible to run Ublox lib on Zephyr (NCS)
4+
5+
This port was made by Vid Rajtmajer <[email protected]>, www.irnas.eu
6+
*/
7+
#include "SparkFun_Ublox_Zephyr_Interface.h"
8+
9+
#include <errno.h>
10+
#include <stdio.h>
11+
#include <string.h>
12+
#include <time.h>
13+
14+
#include "SparkFun_Ublox_Zephyr_Library.h"
15+
16+
17+
SFE_UBLOX_GPS myGPS; // driver class instance
18+
long lastTime = 0; // Simple local timer. Limits amount if I2C traffic to Ublox module.
19+
20+
// init GPIO checksumFailurePin and load GPIO device pointer to the driver
21+
uint8_t set_gpio_dev(struct device *gpio_dev, uint8_t enable_debug)
22+
{
23+
if (myGPS.init_gpio_pins(*gpio_dev) == false)
24+
{
25+
return -EIO;
26+
}
27+
// turn on debugging if enable_debug is set
28+
if (enable_debug)
29+
{
30+
myGPS.enableDebugging();
31+
}
32+
return 0;
33+
}
34+
35+
// initialize I2C and check if GPS device respons
36+
uint8_t gps_begin(struct device *i2c_dev)
37+
{
38+
if (myGPS.begin(*i2c_dev) == false)
39+
{
40+
return -EIO;
41+
}
42+
return 0;
43+
}
44+
45+
// This will pipe all NMEA sentences to UART so we can see them
46+
void pipe_nmea_sentences(void)
47+
{
48+
myGPS.setNMEAOutputPort();
49+
}
50+
51+
// Check for available bytes from the device
52+
void check_ublox(void)
53+
{
54+
myGPS.checkUblox();
55+
}
56+
57+
// Get position information when requested, also display number of satellites used in the fix
58+
int get_position(void)
59+
{
60+
//Query module only every second. Doing it more often will just cause I2C traffic.
61+
//The module only responds when a new position is available, print it to console
62+
if (k_uptime_get_32() - lastTime > 1000)
63+
{
64+
lastTime = k_uptime_get_32(); //Update the timer
65+
66+
long latitude = myGPS.getLatitude();
67+
long longitude = myGPS.getLongitude();
68+
long altitude = myGPS.getAltitude();
69+
uint8_t SIV = myGPS.getSIV();
70+
71+
printk("Position: Lat: %ld, Lon: %ld, Alt: %ld, SIV: %d", latitude, longitude, altitude, SIV);
72+
return 0;
73+
}
74+
return -EBUSY;
75+
}
76+
77+
// Get date and time information when requested, check if they are valid and print info to console, it returns UNIX time
78+
void get_datetime(void)
79+
{
80+
int year = myGPS.getYear();
81+
int month = myGPS.getMonth();
82+
int day = myGPS.getDay();
83+
int hour = myGPS.getHour();
84+
int minute = myGPS.getMinute();
85+
int second = myGPS.getSecond();
86+
87+
printk("DateTime: %d-%d-%d %d:%d:%d\n", year, month, day, hour, minute, second);
88+
89+
printk("Time is ");
90+
if (myGPS.getTimeValid() == false)
91+
{
92+
printk("not ");
93+
}
94+
printk("valid. Date is ");
95+
if (myGPS.getDateValid() == false)
96+
{
97+
printk("not ");
98+
}
99+
printk("valid.\n");
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
This is an interface that connects the CPP Ublox library with the main C code.
3+
Added to make it possible to run Ublox lib on Zephyr (NCS)
4+
5+
This port was made by Vid Rajtmajer <[email protected]>, www.irnas.eu
6+
*/
7+
#include <time.h>
8+
#include <zephyr.h>
9+
10+
#ifndef _UBLOX_LIB_INTERFACE_H_
11+
#define _UBLOX_LIB_INTERFACE_H_
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
uint8_t set_gpio_dev(struct device *gpio_dev, uint8_t enable_debug); // init GPIO
18+
uint8_t gps_begin(struct device *i2c_dev); // initialize I2C and check if GPS device respons
19+
void pipe_nmea_sentences(void); // print NMEA sentences
20+
21+
void check_ublox(void); // Check for available bytes from the device
22+
int get_position(void); // Get position information
23+
void get_datetime(void); // Get date and time information
24+
25+
#ifdef __cplusplus
26+
}
27+
#endif
28+
29+
#endif //UBLOX_LIB_INTERFACE_H_

0 commit comments

Comments
 (0)