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

Commit 3233166

Browse files
committed
ported driver to zephyr
1 parent d9769a6 commit 3233166

File tree

9 files changed

+4678
-0
lines changed

9 files changed

+4678
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
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/Example_Zephyr/build/*
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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_include_directories(../../src/)
9+
target_sources(app PRIVATE ../../src/SparkFun_Ublox_Zephyr_Library.cpp)
10+
target_sources(app PRIVATE ../../src/ublox_lib_interface.cpp)
11+
12+
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
&i2c0 {
2+
status = "okay";
3+
compatible = "nordic,nrf-twim";
4+
};

examples/Example_Zephyr/prj.conf

Lines changed: 7 additions & 0 deletions
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

examples/Example_Zephyr/src/main.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Read NMEA sentences over I2C using Ublox module SAM-M8Q, NEO-M8P, ZED-F9P, etc
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: August 22nd, 2018
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example reads the NMEA setences from the Ublox module over I2c and outputs
10+
them to the serial port
11+
12+
Open the serial monitor at 115200 baud to see the output
13+
I2C clock speed: 100 kHz
14+
*/
15+
16+
#include <zephyr/types.h>
17+
#include <zephyr.h>
18+
#include <device.h>
19+
#include <drivers/i2c.h>
20+
21+
#include "ublox_lib_interface.h"
22+
23+
24+
#define I2C_DEV "I2C_0"
25+
26+
struct device *gpio_dev;
27+
struct device *i2c_dev;
28+
/* I2C pins used are defaults for I2C_0 on nrf52840
29+
SDA: 26
30+
SCL: 27
31+
*/
32+
33+
uint8_t init_gpio(void) {
34+
const char* const gpioName = "GPIO_0";
35+
gpio_dev = device_get_binding(gpioName);
36+
if (gpio_dev == NULL) {
37+
printk("Could not get %s device\n", gpioName);
38+
return -1;
39+
}
40+
int err = set_gpio_dev(gpio_dev);
41+
if (err) {
42+
return -1;
43+
}
44+
return 0;
45+
}
46+
47+
uint8_t init_i2c(void) {
48+
i2c_dev = device_get_binding(I2C_DEV);
49+
if (!i2c_dev)
50+
{
51+
printk("I2C_0 error\n");
52+
return -1;
53+
}
54+
else
55+
{
56+
printk("I2C_0 Init OK\n");
57+
return 0;
58+
}
59+
}
60+
61+
uint8_t init_gps(void) {
62+
if (gps_begin(i2c_dev) != 0)
63+
{
64+
printk("Ublox GPS init error!\n");
65+
return -1;
66+
}
67+
return 0;
68+
}
69+
70+
71+
void main(void) {
72+
printk("UBlox i2c test\n");
73+
74+
int err;
75+
err = init_gpio();
76+
if (err) {
77+
return;
78+
}
79+
err = init_i2c();
80+
if (err) {
81+
return;
82+
}
83+
84+
err = init_gps();
85+
if (err) {
86+
return;
87+
}
88+
89+
while(1) {
90+
//check_ublox(); // See if new data is available. Process bytes as they come in.
91+
get_position();
92+
get_datetime();
93+
k_msleep(250); // Don't pound too hard on the I2C bus
94+
}
95+
}

0 commit comments

Comments
 (0)