Skip to content
Closed
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: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "note-c"]
path = note-c
url = ../note-c.git
url = git@github.com:blues/note-c.git
branch = master
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"isDefault": true
},
"command": [
"west build --board ${config:board} --pristine=always ${workspaceFolder}"
"west build --board ${config:board} --pristine=always ${workspaceFolder}/example"
]
},
{
Expand All @@ -27,7 +27,7 @@
"kind": "build"
},
"command": [
"west build --board ${config:board} ${workspaceFolder}"
"west build --board ${config:board} ${workspaceFolder}/example"
]
},
{
Expand Down Expand Up @@ -90,4 +90,4 @@
]
}
]
}
}
104 changes: 24 additions & 80 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,80 +1,24 @@
# Copyright 2022 Blues Inc. All rights reserved.
# Use of this source code is governed by licenses granted by the
# copyright holder including that found in the LICENSE file.

# SPDX-License-Identifier: MIT

# Set CMake policy behavior
cmake_minimum_required(VERSION 3.20.0)

# Load Zephyr Package
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

# Basic Project Configuration
project(note-zephyr
VERSION 1.0.0
LANGUAGES C ASM
)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON) # required for inline asm

# Create variables to alias path names
set(NOTE_C ${CMAKE_CURRENT_LIST_DIR}/note-c)
set(SRC ${CMAKE_CURRENT_LIST_DIR}/src)

# Set global compile settings
zephyr_get_compile_options_for_lang_as_string(C zephyr_options)
message(STATUS ${zephyr_options})
message(STATUS) # Insert blank line for readability
zephyr_compile_options(
-ggdb
-Og
-Wall
# -Wextra
-Wno-unused-parameter
# -Wpedantic
)
zephyr_get_compile_options_for_lang_as_string(C zephyr_options)
message(STATUS ${zephyr_options})
message(STATUS) # Insert blank line for readability

# Zephyr Example Application
target_sources(app
PRIVATE ${SRC}/main.c
PRIVATE ${SRC}/note_c_hooks.c
)

# Build additional 3rd party libs (e.g. `note-c`) with `app`
target_sources(app
PRIVATE ${NOTE_C}/n_atof.c
PRIVATE ${NOTE_C}/n_b64.c
PRIVATE ${NOTE_C}/n_cjson.c
PRIVATE ${NOTE_C}/n_cjson_helpers.c
PRIVATE ${NOTE_C}/n_const.c
PRIVATE ${NOTE_C}/n_ftoa.c
PRIVATE ${NOTE_C}/n_helpers.c
PRIVATE ${NOTE_C}/n_hooks.c
PRIVATE ${NOTE_C}/n_i2c.c
PRIVATE ${NOTE_C}/n_md5.c
PRIVATE ${NOTE_C}/n_printf.c
PRIVATE ${NOTE_C}/n_request.c
PRIVATE ${NOTE_C}/n_serial.c
PRIVATE ${NOTE_C}/n_str.c
PRIVATE ${NOTE_C}/n_ua.c
)

target_include_directories(app
PRIVATE ${NOTE_C}
)

# WARNING: These options are overriden by `zephyr_compile_options()`
target_compile_options(app
PRIVATE -ggdb
PRIVATE -Og
PRIVATE -Wall
PRIVATE -Wextra
# PRIVATE -Wpedantic
PRIVATE -Wimplicit-fallthrough=2
PRIVATE -Wunused-parameter
)
if(CONFIG_NOTECARD)
set(NOTE_C_DIR ${ZEPHYR_CURRENT_MODULE_DIR}/note-c)
zephyr_include_directories(. ${NOTE_C_DIR})
zephyr_library_sources(
note_c_hooks.c
${NOTE_C_DIR}/n_atof.c
${NOTE_C_DIR}/n_atof.c
${NOTE_C_DIR}/n_b64.c
${NOTE_C_DIR}/n_cjson.c
${NOTE_C_DIR}/n_cjson_helpers.c
${NOTE_C_DIR}/n_cobs.c
${NOTE_C_DIR}/n_const.c
${NOTE_C_DIR}/n_ftoa.c
${NOTE_C_DIR}/n_helpers.c
${NOTE_C_DIR}/n_hooks.c
${NOTE_C_DIR}/n_i2c.c
${NOTE_C_DIR}/n_md5.c
${NOTE_C_DIR}/n_printf.c
${NOTE_C_DIR}/n_request.c
${NOTE_C_DIR}/n_serial.c
${NOTE_C_DIR}/n_str.c
${NOTE_C_DIR}/n_ua.c
)
endif()
6 changes: 6 additions & 0 deletions KConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config NOTECARD
bool "Enable the helper library for the Blues Wireless Notecard"
default n
depends on I2C
help
Module for controlling blues.io notecard using the note-c library. Requires an device tree alias for the notecard.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,44 @@ as `/dev/ttyACM0`.
- Press green triangle at the top of the **Run and Debug** panel.
- Select **Run > Start Debugging** from the application menu.
- Press the function key, `F5`.

Using the West Module
---------------------

To get started with this module, you will need to add it to your Zephyr project's `west.yml` manifest file and then add the required overlay to your Zephyr project's device tree.

### Manifest

To use this module, add the following to your Zephyr project's `west.yml` manifest file, for example:

```yaml
projects:
# Your other modules here
- name: notecard
path: modules/notecard
revision: main
submodules: true
url: https://github.com/blues/note-zephyr
```

Then, run `west update` to pull the module into your project.

### Overlays

The helper functions (`note_c_hooks.c`) provide controls to communicate with a Notecard attached to the Zephyr host via i2c.

As such, the helper functions expect the target device to use a DT alias of `notecard` for the i2c bus.
You should ensure the host device you are targetting has this alias defined in its DT overlay.

```dts
/ {
aliases {
// for example, using the i2c0 bus
notecard = &i2c0;
};
};
```

### Example

Included in this repo is a simple example for using the west module to send a note using the Notecard. See the [example](example/README.md) for more details.
7 changes: 7 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.13.1)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(app LANGUAGES C)

target_sources(app PRIVATE src/main.c)
19 changes: 19 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Example

This example uses the `note-c` library to send a note using the Notecard, to Notehub. Initially the example will configure the notecard and then will send a note every 10 seconds with the state of the onboard LED. This example specifically targets the [Swan MCU](https://blues.com/products/swan/) and one of the Blues [carrier boards](https://blues.com/products/notecarrier/) (when connected via i2c) and provides building / flashing instructions for this board, using the STLINK-V3 debugger.

## Build

To build this example, you can use the following command from the root of this repo:

```bash
west build -b swan_r5 example
```

## Flash

To flash this example to the Swan MCU, you can use the following command:

```bash
west flash
```
6 changes: 6 additions & 0 deletions example/boards/swan_r5.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/ {
aliases {
// for example, using the i2c1 bus on the Blues Swan Feather Board
notecard = &i2c1;
};
};
3 changes: 3 additions & 0 deletions prj.conf → example/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ CONFIG_NEWLIB_LIBC=y

# Debugging Configuration
CONFIG_PRINTK=y

# Notecard Library
CONFIG_NOTECARD=y
119 changes: 119 additions & 0 deletions example/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2023 Blues Inc.
*
* MIT License. Use of this source code is governed by licenses granted
* by the copyright holder including that found in the LICENSE file.
*
* Author: Zachary J. Fields
*/

// Include Zephyr Headers
#include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h>

// Include Notecard note-c library
#include <note.h>

// Notecard node-c helper methods
#include "note_c_hooks.h"

// Uncomment the define below and replace com.your-company:your-product-name
// with your ProductUID.
// #define PRODUCT_UID "com.your-company:your-product-name"

#ifndef PRODUCT_UID
#define PRODUCT_UID ""
#pragma message \
"PRODUCT_UID is not defined in this example. Please ensure your Notecard has a product identifier set before running this example or define it in code here. More details at https://bit.ly/product-uid"
#endif

// 10000 msec = 10 sec
#define SLEEP_TIME_MS 10000

// The devicetree node identifier for the "led0" alias.
#define LED0_NODE DT_ALIAS(led0)

#if DT_NODE_HAS_STATUS(LED0_NODE, okay)

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

#else

// A build error on this line means your board is unsupported.
// See the sample documentation for information on how to fix this.
#error "Unsupported board: led0 devicetree alias is not defined"

#endif

int main(void)
{
int ret;

printk("[INFO] main(): Initializing...\n");

// Initialize note-c hooks
NoteSetUserAgent((char *)"note-zephyr");
NoteSetFnDefault(malloc, free, platform_delay, platform_millis);
NoteSetFnDebugOutput(note_log_print);
NoteSetFnI2C(NOTE_I2C_ADDR_DEFAULT, NOTE_I2C_MAX_DEFAULT, note_i2c_reset, note_i2c_transmit,
note_i2c_receive);

// Send a Notecard hub.set using note-c
J *req = NoteNewRequest("hub.set");
if (req) {
JAddStringToObject(req, "product", PRODUCT_UID);
JAddStringToObject(req, "mode", "continuous");
JAddStringToObject(req, "sn", "zephyr-blink");
if (!NoteRequest(req)) {
printk("Failed to configure Notecard.\n");
return -1;
}
} else {
printk("Failed to allocate memory.\n");
return -1;
}

if (!gpio_is_ready_dt(&led)) {
printk("Failed to activate LED.\n");
return -1;
}

ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
printk("Failed to configure LED.\n");
return ret;
}

// Application Loop
printk("[INFO] main(): Entering loop...\n");
while (1) {
// Toggle LED state
ret = gpio_pin_toggle_dt(&led);
if (ret < 0) {
printk("Failed to toggle LED.\n");
break;
}

// Report LED state to Notehub.io
J *req = NoteNewRequest("note.add");
if (req) {
JAddBoolToObject(req, "sync", true);
J *body = JAddObjectToObject(req, "body");
JAddBoolToObject(body, "LED", gpio_pin_get(led.port, led.pin));
if (!NoteRequest(req)) {
printk("Failed to submit Note to Notecard.\n");
ret = -1;
break;
}
} else {
printk("Failed to allocate memory.\n");
ret = -1;
break;
}

// Wait to iterate
k_msleep(SLEEP_TIME_MS);
}

return ret;
}
2 changes: 1 addition & 1 deletion note-c
Submodule note-c updated 57 files
+22 −3 .github/workflows/ci.yml
+42 −0 .github/workflows/md5srv-tests.yml
+248 −0 .github/workflows/notecard-binary-tests.yml
+40 −0 .github/workflows/publish_docs_site.yml
+2 −1 .gitignore
+16 −0 CMakeLists.txt
+5 −0 Dockerfile
+ assets/blues-wireless.png
+ assets/blues_logo_no_text.png
+26 −0 docs/CMakeLists.txt
+13 −53 docs/Doxyfile.in
+399 −0 docs/_extensions/doxyrunner.py
+157 −0 docs/api_reference.rst
+81 −0 docs/calling_the_notecard_api.rst
+71 −0 docs/conf.py
+20 −0 docs/getting_started.rst
+18 −0 docs/index.rst
+343 −0 docs/library_initialization.rst
+28 −0 docs/ports.rst
+86 −8 n_cjson.c
+34 −4 n_cjson.h
+68 −70 n_hooks.c
+19 −17 n_request.c
+160 −46 note.h
+23 −0 scripts/build_docs.sh
+96 −0 scripts/check_libc_dependencies.sh
+36 −0 scripts/check_runner_config.sh
+2 −2 scripts/git_hooks/pre-push
+0 −7 scripts/run_doxygen.sh
+7 −0 scripts/run_md5srv.sh
+25 −0 scripts/run_tunnelmole.sh
+14 −0 scripts/wait_for_file.sh
+2 −0 test/CMakeLists.txt
+13 −0 test/hitl/card.binary/lib/notecard_binary/NotecardBinary.cpp
+1,184 −0 test/hitl/card.binary/lib/notecard_binary/NotecardBinary.h
+143 −0 test/hitl/card.binary/lib/notecard_binary/NotecardComms.cpp
+48 −0 test/hitl/card.binary/lib/notecard_binary/NotecardComms.h
+5 −0 test/hitl/card.binary/lib/notecard_binary/defines.txt
+4,918 −0 test/hitl/card.binary/lib/notecard_binary/small_img.cpp
+8 −0 test/hitl/card.binary/lib/notecard_binary/small_img.h
+30 −0 test/hitl/card.binary/platformio.ini
+17 −0 test/hitl/card.binary/src/main.cpp
+50 −0 test/hitl/card.binary/test/LOCAL_TESTING.md
+55 −0 test/hitl/card.binary/test/README.md
+88 −0 test/hitl/card.binary/test/test_binary_generators.cpp
+60 −0 test/hitl/card.binary/test/test_binary_generators.h
+442 −0 test/hitl/card.binary/test/test_card_binary.cpp
+2 −0 test/hitl/card.binary/test/test_card_binary.h
+36 −0 test/hitl/card.binary/test/test_main.cpp
+34 −0 test/hitl/card.binary/test/test_unity_util.cpp
+33 −0 test/hitl/card.binary/test/test_unity_util.h
+260 −0 test/hitl/scripts/md5srv.bats
+318 −0 test/hitl/scripts/md5srv.py
+37 −0 test/hitl/scripts/note.json
+1 −0 test/include/test_static.h
+66 −0 test/src/JPrintUnformatted_test.cpp
+73 −0 test/src/Jtolower_test.cpp
Loading