move things around
This commit is contained in:
12
firmware/app/CMakeLists.txt
Normal file
12
firmware/app/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Zephyr Example Application
|
||||
#
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
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)
|
15
firmware/app/Kconfig
Normal file
15
firmware/app/Kconfig
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# This file is the application Kconfig entry point. All application Kconfig
|
||||
# options can be defined here or included via other application Kconfig files.
|
||||
# You can browse these options using the west targets menuconfig (terminal) or
|
||||
# guiconfig (GUI).
|
||||
|
||||
menu "Zephyr"
|
||||
source "Kconfig.zephyr"
|
||||
endmenu
|
||||
|
||||
module = APP
|
||||
module-str = APP
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
5
firmware/app/VERSION
Normal file
5
firmware/app/VERSION
Normal file
@ -0,0 +1,5 @@
|
||||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 0
|
||||
PATCHLEVEL = 0
|
||||
VERSION_TWEAK = 0
|
||||
EXTRAVERSION =
|
27
firmware/app/boards/nrf52dk_nrf52832.overlay
Normal file
27
firmware/app/boards/nrf52dk_nrf52832.overlay
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/* This devicetree overlay file will be automatically picked by the Zephyr
|
||||
* build system when building the sample for the nucleo_f302r8 board. It shows
|
||||
* how the example-application can be built on sample boards already provided
|
||||
* by Zephyr.
|
||||
*/
|
||||
|
||||
/ {
|
||||
example_sensor: example-sensor {
|
||||
compatible = "zephyr,example-sensor";
|
||||
input-gpios = <&gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
};
|
||||
|
||||
blink_led: blink-led {
|
||||
compatible = "blink-gpio-led";
|
||||
led-gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>;
|
||||
blink-period-ms = <500>;
|
||||
};
|
||||
};
|
||||
|
||||
&gpio0 {
|
||||
status = "okay";
|
||||
};
|
27
firmware/app/boards/nucleo_f302r8.overlay
Normal file
27
firmware/app/boards/nucleo_f302r8.overlay
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/* This devicetree overlay file will be automatically picked by the Zephyr
|
||||
* build system when building the sample for the nucleo_f302r8 board. It shows
|
||||
* how the example-application can be built on sample boards already provided
|
||||
* by Zephyr.
|
||||
*/
|
||||
|
||||
/ {
|
||||
example_sensor: example-sensor {
|
||||
compatible = "zephyr,example-sensor";
|
||||
input-gpios = <&gpioc 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
};
|
||||
|
||||
blink_led: blink-led {
|
||||
compatible = "blink-gpio-led";
|
||||
led-gpios = <&gpiob 13 GPIO_ACTIVE_HIGH>;
|
||||
blink-period-ms = <1000>;
|
||||
};
|
||||
};
|
||||
|
||||
&gpioc {
|
||||
status = "okay";
|
||||
};
|
16
firmware/app/boards/nucleo_h723zg.overlay
Normal file
16
firmware/app/boards/nucleo_h723zg.overlay
Normal file
@ -0,0 +1,16 @@
|
||||
/ {
|
||||
example_sensor: example-sensor {
|
||||
compatible = "zephyr,example-sensor";
|
||||
input-gpios = <&gpioc 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
};
|
||||
|
||||
blink_led: blink-led {
|
||||
compatible = "blink-gpio-led";
|
||||
led-gpios = <&gpioe 1 GPIO_ACTIVE_HIGH>;
|
||||
blink-period-ms = <1000>;
|
||||
};
|
||||
};
|
||||
|
||||
&gpioc {
|
||||
status = "okay";
|
||||
};
|
16
firmware/app/boards/nucleo_h743zi.overlay
Normal file
16
firmware/app/boards/nucleo_h743zi.overlay
Normal file
@ -0,0 +1,16 @@
|
||||
/ {
|
||||
example_sensor: example-sensor {
|
||||
compatible = "zephyr,example-sensor";
|
||||
input-gpios = <&gpioc 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
};
|
||||
|
||||
blink_led: blink-led {
|
||||
compatible = "blink-gpio-led";
|
||||
led-gpios = <&gpiob 0 GPIO_ACTIVE_HIGH>;
|
||||
blink-period-ms = <1000>;
|
||||
};
|
||||
};
|
||||
|
||||
&gpioc {
|
||||
status = "okay";
|
||||
};
|
12
firmware/app/debug.conf
Normal file
12
firmware/app/debug.conf
Normal file
@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# This is a Kconfig fragment which can be used to enable debug-related options
|
||||
# in the application. See the README for more details.
|
||||
|
||||
# compiler
|
||||
CONFIG_DEBUG_OPTIMIZATIONS=y
|
||||
|
||||
# logging
|
||||
CONFIG_LOG=y
|
||||
CONFIG_APP_LOG_LEVEL_DBG=y
|
28
firmware/app/prj.conf
Normal file
28
firmware/app/prj.conf
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# This file contains selected Kconfig options for the application.
|
||||
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_BLINK=y
|
||||
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=16384
|
||||
|
||||
CONFIG_DISPLAY=y
|
||||
|
||||
CONFIG_LOG=y
|
||||
|
||||
CONFIG_CFB_LOG_LEVEL_DBG=y
|
||||
CONFIG_CHARACTER_FRAMEBUFFER=y
|
||||
CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||
|
||||
CONFIG_BT=y
|
||||
CONFIG_BT_SMP=y
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
CONFIG_BT_GATT_CLIENT=y
|
||||
CONFIG_BT_DEVICE_NAME="Mellifera"
|
||||
|
||||
CONFIG_BOOTLOADER_MCUBOOT=y
|
||||
CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE=y
|
16
firmware/app/sample.yaml
Normal file
16
firmware/app/sample.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
# This file is provided so that the application can be compiled using Twister,
|
||||
# the Zephyr testing tool. In this file, multiple combinations can be specified,
|
||||
# so that you can easily test all of them locally or in CI.
|
||||
sample:
|
||||
description: Example application
|
||||
name: example-application
|
||||
common:
|
||||
build_only: true
|
||||
integration_platforms:
|
||||
- custom_plank
|
||||
- nucleo_f302r8
|
||||
tests:
|
||||
app.default: {}
|
||||
app.debug:
|
||||
extra_overlay_confs:
|
||||
- debug.conf
|
373
firmware/app/src/main.c
Normal file
373
firmware/app/src/main.c
Normal file
@ -0,0 +1,373 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/display/cfb.h>
|
||||
|
||||
#include <app/drivers/blink.h>
|
||||
|
||||
#include <app_version.h>
|
||||
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/bluetooth/hci.h>
|
||||
|
||||
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
|
||||
|
||||
#define BLINK_PERIOD_MS_STEP 100U
|
||||
#define BLINK_PERIOD_MS_MAX 1000U
|
||||
|
||||
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
|
||||
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
|
||||
|
||||
/*
|
||||
* Set Advertisement data. Based on the Eddystone specification:
|
||||
* https://github.com/google/eddystone/blob/master/protocol-specification.md
|
||||
* https://github.com/google/eddystone/tree/master/eddystone-url
|
||||
*/
|
||||
static const struct bt_data ad[] = {
|
||||
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
|
||||
BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0xaa, 0xfe),
|
||||
BT_DATA_BYTES(BT_DATA_SVC_DATA16,
|
||||
0xaa, 0xfe, /* Eddystone UUID */
|
||||
0x10, /* Eddystone-URL frame type */
|
||||
0x00, /* Calibrated Tx power at 0m */
|
||||
0x00, /* URL Scheme Prefix http://www. */
|
||||
'z', 'e', 'p', 'h', 'y', 'r',
|
||||
'p', 'r', 'o', 'j', 'e', 'c', 't',
|
||||
0x08) /* .org */
|
||||
};
|
||||
|
||||
/* Set Scan Response data */
|
||||
static const struct bt_data sd[] = {
|
||||
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
|
||||
};
|
||||
|
||||
static void bt_ready(int err)
|
||||
{
|
||||
char addr_s[BT_ADDR_LE_STR_LEN];
|
||||
bt_addr_le_t addr = {0};
|
||||
size_t count = 1;
|
||||
|
||||
if (err)
|
||||
{
|
||||
LOG_ERR("Bluetooth init failed (err %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INF("Bluetooth initialized");
|
||||
|
||||
// Start advertising
|
||||
err = bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),
|
||||
sd, ARRAY_SIZE(sd));
|
||||
if (err)
|
||||
{
|
||||
LOG_ERR("Advertising failed to start (err %d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
/* For connectable advertising you would use
|
||||
* bt_le_oob_get_local(). For non-connectable non-identity
|
||||
* advertising an non-resolvable private address is used;
|
||||
* there is no API to retrieve that.
|
||||
*/
|
||||
|
||||
bt_id_get(&addr, &count);
|
||||
bt_addr_le_to_str(&addr, addr_s, sizeof(addr_s));
|
||||
|
||||
LOG_INF("Beacon started, advertising as %s", addr_s);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct device *display, *ina, *baro, *accel, *gyro, *mag, *lis, *hdc;
|
||||
int err;
|
||||
uint16_t x_res;
|
||||
uint16_t y_res;
|
||||
uint16_t rows;
|
||||
uint8_t ppt;
|
||||
uint8_t font_width;
|
||||
uint8_t font_height;
|
||||
struct sensor_value voltage, current, pressure, temperature, accel_x, accel_y, accel_z, accel_z_ref, gyro_x, gyro_y, gyro_z, mag_x, mag_y, mag_z, humidity;
|
||||
|
||||
char str_v[15] = {0};
|
||||
char str_i[15] = {0};
|
||||
char str_p[16] = {0};
|
||||
char str_t[16] = {0};
|
||||
char str_ax[16] = {0};
|
||||
char str_ay[16] = {0};
|
||||
char str_az[16] = {0};
|
||||
char str_az_ref[16] = {0};
|
||||
char str_gx[16] = {0};
|
||||
char str_gy[16] = {0};
|
||||
char str_gz[16] = {0};
|
||||
char str_mx[16] = {0};
|
||||
char str_my[16] = {0};
|
||||
char str_mz[16] = {0};
|
||||
char str_h[16] = {0};
|
||||
|
||||
LOG_INF("Starting Mellifera version %s...", APP_VERSION_STRING);
|
||||
// LOG_INF("Board: %s", BOARD);
|
||||
|
||||
// Initialize the Bluetooth Subsystem
|
||||
err = bt_enable(bt_ready);
|
||||
if (err)
|
||||
{
|
||||
LOG_ERR("Bluetooth init failed (err %d)", err);
|
||||
}
|
||||
|
||||
display = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
|
||||
if (!device_is_ready(display))
|
||||
{
|
||||
LOG_ERR("Device %s not ready", display->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (display_set_pixel_format(display, PIXEL_FORMAT_MONO10) != 0)
|
||||
{
|
||||
if (display_set_pixel_format(display, PIXEL_FORMAT_MONO01) != 0)
|
||||
{
|
||||
LOG_ERR("Failed to set required pixel format");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_INF("Initialized %s", display->name);
|
||||
|
||||
if (cfb_framebuffer_init(display))
|
||||
{
|
||||
LOG_ERR("Framebuffer initialization failed!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
cfb_framebuffer_clear(display, true);
|
||||
|
||||
display_blanking_off(display);
|
||||
|
||||
x_res = cfb_get_display_parameter(display, CFB_DISPLAY_WIDTH);
|
||||
y_res = cfb_get_display_parameter(display, CFB_DISPLAY_HEIGH);
|
||||
rows = cfb_get_display_parameter(display, CFB_DISPLAY_ROWS);
|
||||
ppt = cfb_get_display_parameter(display, CFB_DISPLAY_PPT);
|
||||
|
||||
for (int idx = 0; idx < 42; idx++)
|
||||
{
|
||||
if (cfb_get_font_size(display, idx, &font_width, &font_height))
|
||||
{
|
||||
break;
|
||||
}
|
||||
cfb_framebuffer_set_font(display, idx);
|
||||
LOG_INF("font width %d, font height %d",
|
||||
font_width, font_height);
|
||||
}
|
||||
cfb_framebuffer_set_font(display, 0);
|
||||
|
||||
LOG_INF("x_res %d, y_res %d, ppt %d, rows %d, cols %d",
|
||||
x_res,
|
||||
y_res,
|
||||
ppt,
|
||||
rows,
|
||||
cfb_get_display_parameter(display, CFB_DISPLAY_COLS));
|
||||
|
||||
cfb_set_kerning(display, 3);
|
||||
|
||||
ina = DEVICE_DT_GET(DT_NODELABEL(ina231));
|
||||
if (!device_is_ready(ina))
|
||||
{
|
||||
LOG_ERR("Device %s not ready", ina->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
baro = DEVICE_DT_GET(DT_NODELABEL(bmp388));
|
||||
if (!device_is_ready(baro))
|
||||
{
|
||||
LOG_ERR("Device %s not ready", baro->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
accel = DEVICE_DT_GET(DT_NODELABEL(bmx055_accel));
|
||||
if (!device_is_ready(accel))
|
||||
{
|
||||
LOG_ERR("Device %s not ready", accel->name);
|
||||
return 0;
|
||||
}
|
||||
LOG_INF("Initialized %s", accel->name);
|
||||
|
||||
gyro = DEVICE_DT_GET(DT_NODELABEL(bmx055_gyro));
|
||||
if (!device_is_ready(gyro))
|
||||
{
|
||||
LOG_ERR("Device %s not ready", gyro->name);
|
||||
return 0;
|
||||
}
|
||||
LOG_INF("Initialized %s", gyro->name);
|
||||
|
||||
mag = DEVICE_DT_GET(DT_NODELABEL(bmx055_mag));
|
||||
if (!device_is_ready(mag))
|
||||
{
|
||||
LOG_ERR("Device %s not ready", mag->name);
|
||||
return 0;
|
||||
}
|
||||
LOG_INF("Initialized %s", mag->name);
|
||||
|
||||
lis = DEVICE_DT_GET(DT_NODELABEL(lis2dh));
|
||||
if (!device_is_ready(lis))
|
||||
{
|
||||
LOG_ERR("Device %s not ready", lis->name);
|
||||
return 0;
|
||||
}
|
||||
LOG_INF("Initialized %s", lis->name);
|
||||
|
||||
hdc = DEVICE_DT_GET(DT_NODELABEL(hdc1080));
|
||||
if (!device_is_ready(hdc))
|
||||
{
|
||||
LOG_ERR("Device %s not ready", hdc->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (sensor_sample_fetch(ina) < 0)
|
||||
{
|
||||
LOG_ERR("Could not fetch sample");
|
||||
}
|
||||
if (sensor_channel_get(ina, SENSOR_CHAN_VOLTAGE, &voltage) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get voltage");
|
||||
}
|
||||
if (sensor_channel_get(ina, SENSOR_CHAN_CURRENT, ¤t) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get current");
|
||||
}
|
||||
|
||||
if (sensor_sample_fetch(baro) < 0)
|
||||
{
|
||||
LOG_ERR("Could not fetch sample");
|
||||
}
|
||||
if (sensor_channel_get(baro, SENSOR_CHAN_PRESS, &pressure) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get pressure");
|
||||
}
|
||||
if (sensor_channel_get(baro, SENSOR_CHAN_AMBIENT_TEMP, &temperature) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get temperature");
|
||||
}
|
||||
|
||||
if (sensor_sample_fetch(accel) < 0)
|
||||
{
|
||||
LOG_ERR("Could not fetch sample from accel");
|
||||
}
|
||||
if (sensor_channel_get(accel, SENSOR_CHAN_ACCEL_X, &accel_x) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get acceleration");
|
||||
}
|
||||
if (sensor_channel_get(accel, SENSOR_CHAN_ACCEL_Y, &accel_y) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get acceleration");
|
||||
}
|
||||
if (sensor_channel_get(accel, SENSOR_CHAN_ACCEL_Z, &accel_z) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get acceleration");
|
||||
}
|
||||
|
||||
if (sensor_sample_fetch(gyro) < 0)
|
||||
{
|
||||
LOG_ERR("Could not fetch sample from gyro");
|
||||
}
|
||||
if (sensor_channel_get(gyro, SENSOR_CHAN_GYRO_X, &gyro_x) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get gyro");
|
||||
}
|
||||
if (sensor_channel_get(gyro, SENSOR_CHAN_GYRO_Y, &gyro_y) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get gyro");
|
||||
}
|
||||
if (sensor_channel_get(gyro, SENSOR_CHAN_GYRO_Z, &gyro_z) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get gyro");
|
||||
}
|
||||
|
||||
if (sensor_sample_fetch(mag) < 0)
|
||||
{
|
||||
LOG_ERR("Could not fetch sample from mag");
|
||||
}
|
||||
if (sensor_channel_get(mag, SENSOR_CHAN_MAGN_X, &mag_x) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get mag");
|
||||
}
|
||||
if (sensor_channel_get(mag, SENSOR_CHAN_MAGN_Y, &mag_y) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get mag");
|
||||
}
|
||||
if (sensor_channel_get(mag, SENSOR_CHAN_MAGN_Z, &mag_z) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get mag");
|
||||
}
|
||||
|
||||
if (sensor_sample_fetch(lis) < 0)
|
||||
{
|
||||
LOG_ERR("Could not fetch sample");
|
||||
}
|
||||
if (sensor_channel_get(lis, SENSOR_CHAN_ACCEL_Z, &accel_z_ref) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get acceleration");
|
||||
}
|
||||
|
||||
if (sensor_sample_fetch(hdc) < 0)
|
||||
{
|
||||
LOG_ERR("Could not fetch sample");
|
||||
}
|
||||
if (sensor_channel_get(hdc, SENSOR_CHAN_AMBIENT_TEMP, &temperature) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get sample");
|
||||
}
|
||||
if (sensor_channel_get(hdc, SENSOR_CHAN_HUMIDITY, &humidity) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get sample");
|
||||
}
|
||||
|
||||
sprintf(str_v, "V :%7.5f", voltage.val1 + voltage.val2 * 1e-6);
|
||||
sprintf(str_i, "I :%7.5f", current.val1 + current.val2 * 1e-6);
|
||||
sprintf(str_p, "P :%7.4f", pressure.val1 + pressure.val2 * 1e-6);
|
||||
sprintf(str_t, "T :%7.4f", temperature.val1 + temperature.val2 * 1e-6);
|
||||
sprintf(str_ax, "AX:%+7.3f", accel_x.val1 + accel_x.val2 * 1e-6);
|
||||
sprintf(str_ay, "AY:%+7.3f", accel_y.val1 + accel_y.val2 * 1e-6);
|
||||
sprintf(str_az, "AZ:%+7.3f", accel_z.val1 + accel_z.val2 * 1e-6);
|
||||
sprintf(str_gx, "GX:%+7.3f", gyro_x.val1 + gyro_x.val2 * 1e-6);
|
||||
sprintf(str_gy, "GY:%+7.3f", gyro_y.val1 + gyro_y.val2 * 1e-6);
|
||||
sprintf(str_gz, "GZ:%+7.3f", gyro_z.val1 + gyro_z.val2 * 1e-6);
|
||||
sprintf(str_mx, "MX:%+7.3f", mag_x.val1 + mag_x.val2 * 1e-6);
|
||||
sprintf(str_my, "MY:%+7.3f", mag_y.val1 + mag_y.val2 * 1e-6);
|
||||
sprintf(str_mz, "MZ:%+7.3f", mag_z.val1 + mag_z.val2 * 1e-6);
|
||||
sprintf(str_az_ref, "Zr:%+7.3f", accel_z_ref.val1 + accel_z_ref.val2 * 1e-6);
|
||||
sprintf(str_h, "H :%7.3f", humidity.val1 + humidity.val2 * 1e-6);
|
||||
|
||||
// LOG_INF("%s\t%s\t%s\t%s", str_v, str_i, str_p, str_t);
|
||||
|
||||
cfb_framebuffer_clear(display, false);
|
||||
if (cfb_print(display, str_mx, 0, 0))
|
||||
{
|
||||
LOG_ERR("Failed to print a string");
|
||||
}
|
||||
if (cfb_print(display, str_gy, 0, 16))
|
||||
{
|
||||
LOG_ERR("Failed to print a string");
|
||||
}
|
||||
if (cfb_print(display, str_gz, 0, 16 * 2))
|
||||
{
|
||||
LOG_ERR("Failed to print a string");
|
||||
}
|
||||
if (cfb_print(display, str_ax, 0, 16 * 3))
|
||||
{
|
||||
LOG_ERR("Failed to print a string");
|
||||
}
|
||||
|
||||
cfb_framebuffer_finalize(display);
|
||||
#if defined(CONFIG_ARCH_POSIX)
|
||||
k_sleep(K_MSEC(20));
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
17
firmware/boards/bh/mellifera_rev1/Kconfig
Normal file
17
firmware/boards/bh/mellifera_rev1/Kconfig
Normal file
@ -0,0 +1,17 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if BOARD_MELLIFERA_REV1
|
||||
|
||||
config BOARD_ENABLE_DCDC
|
||||
bool "Enable DCDC mode"
|
||||
select SOC_DCDC_NRF52X
|
||||
default y
|
||||
depends on BOARD_MELLIFERA_REV1
|
||||
|
||||
# BT_CTLR depends on BT. When BT is enabled we should default to also
|
||||
# enabling the controller.
|
||||
config BT_CTLR
|
||||
default y if BT
|
||||
|
||||
endif # BOARD_MELLIFERA_REV1
|
5
firmware/boards/bh/mellifera_rev1/Kconfig.mellifera_rev1
Normal file
5
firmware/boards/bh/mellifera_rev1/Kconfig.mellifera_rev1
Normal file
@ -0,0 +1,5 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config BOARD_MELLIFERA_REV1
|
||||
select SOC_NRF52832_QFAA
|
6
firmware/boards/bh/mellifera_rev1/README.md
Normal file
6
firmware/boards/bh/mellifera_rev1/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Custom Plank Board
|
||||
|
||||
`custom_plank` board is used to demonstrate how to create custom boards. It is
|
||||
in fact a simplified version of the nRF52840-DK board, so the
|
||||
`example-application` can be run on that development kit when using
|
||||
`custom_plank`.
|
12
firmware/boards/bh/mellifera_rev1/board.cmake
Normal file
12
firmware/boards/bh/mellifera_rev1/board.cmake
Normal file
@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
board_runner_args(jlink "--device=nrf52" "--speed=4000")
|
||||
board_runner_args(pyocd "--target=nrf52832" "--frequency=4000000")
|
||||
|
||||
set(OPENOCD_NRF5_SUBFAMILY "nrf52")
|
||||
|
||||
include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake)
|
||||
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
|
||||
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
|
||||
include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake)
|
8
firmware/boards/bh/mellifera_rev1/board.yml
Normal file
8
firmware/boards/bh/mellifera_rev1/board.yml
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
board:
|
||||
name: mellifera_rev1
|
||||
vendor: bh
|
||||
socs:
|
||||
- name: nrf52832
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&pinctrl {
|
||||
|
||||
uart0_default: uart0_default {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(UART_TX, 0, 5)>,
|
||||
<NRF_PSEL(UART_RX, 0, 11)>;
|
||||
};
|
||||
};
|
||||
|
||||
uart0_sleep: uart0_sleep {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(UART_TX, 0, 5)>,
|
||||
<NRF_PSEL(UART_RX, 0, 11)>;
|
||||
low-power-enable;
|
||||
};
|
||||
};
|
||||
|
||||
i2c0_default: i2c0_default {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(TWIM_SDA, 0, 29)>,
|
||||
<NRF_PSEL(TWIM_SCL, 0, 28)>;
|
||||
};
|
||||
};
|
||||
|
||||
i2c0_sleep: i2c0_sleep {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(TWIM_SDA, 0, 29)>,
|
||||
<NRF_PSEL(TWIM_SCL, 0, 28)>;
|
||||
low-power-enable;
|
||||
};
|
||||
};
|
||||
|
||||
spi1_default: spi1_default {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(SPIM_SCK, 0, 16)>,
|
||||
<NRF_PSEL(SPIM_MOSI, 0, 20)>,
|
||||
<NRF_PSEL(SPIM_MISO, 0, 18)>;
|
||||
};
|
||||
};
|
||||
|
||||
spi1_sleep: spi1_sleep {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(SPIM_SCK, 0, 16)>,
|
||||
<NRF_PSEL(SPIM_MOSI, 0, 20)>,
|
||||
<NRF_PSEL(SPIM_MISO, 0, 18)>;
|
||||
low-power-enable;
|
||||
};
|
||||
};
|
||||
|
||||
};
|
250
firmware/boards/bh/mellifera_rev1/mellifera_rev1.dts
Normal file
250
firmware/boards/bh/mellifera_rev1/mellifera_rev1.dts
Normal file
@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/dts-v1/;
|
||||
#include <nordic/nrf52832_qfaa.dtsi>
|
||||
#include "mellifera_rev1-pinctrl.dtsi"
|
||||
|
||||
/ {
|
||||
model = "Mellifera rev1";
|
||||
compatible = "bh,mellifera_rev1";
|
||||
|
||||
chosen {
|
||||
zephyr,console = &uart0;
|
||||
zephyr,shell-uart = &uart0;
|
||||
zephyr,uart-mcumgr = &uart0;
|
||||
zephyr,bt-mon-uart = &uart0;
|
||||
zephyr,bt-c2h-uart = &uart0;
|
||||
zephyr,sram = &sram0;
|
||||
zephyr,flash = &flash0;
|
||||
zephyr,display = &ssd1306;
|
||||
zephyr,code-partition = &slot0_partition;
|
||||
};
|
||||
|
||||
example_sensor: example-sensor {
|
||||
compatible = "zephyr,example-sensor";
|
||||
input-gpios = <&gpio0 2 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
};
|
||||
|
||||
leds {
|
||||
compatible = "gpio-leds";
|
||||
led0: led_0 {
|
||||
gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>;
|
||||
label = "Yellow LED 0";
|
||||
};
|
||||
led1: led_1 {
|
||||
gpios = <&gpio0 8 GPIO_ACTIVE_HIGH>;
|
||||
label = "Yellow LED 1";
|
||||
};
|
||||
led2: led_2 {
|
||||
gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>;
|
||||
label = "Yellow LED 2";
|
||||
};
|
||||
led3: led_3 {
|
||||
gpios = <&gpio0 13 GPIO_ACTIVE_HIGH>;
|
||||
label = "Yellow LED 3";
|
||||
};
|
||||
led_rx: led_rx {
|
||||
gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
|
||||
label = "RX LED";
|
||||
};
|
||||
led_tx: led_tx {
|
||||
gpios = <&gpio0 3 GPIO_ACTIVE_HIGH>;
|
||||
label = "TX LED";
|
||||
};
|
||||
led_rx_ok: led_rx_ok {
|
||||
gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
|
||||
label = "RX OK LED";
|
||||
};
|
||||
led_sfd: led_sfd {
|
||||
gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
|
||||
label = "SFD LED";
|
||||
};
|
||||
};
|
||||
|
||||
buttons {
|
||||
compatible = "gpio-keys";
|
||||
button0: button_0 {
|
||||
gpios = <&gpio0 2 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
label = "Pushbutton";
|
||||
zephyr,code = <INPUT_KEY_0>;
|
||||
};
|
||||
int_drdy: int_drdy {
|
||||
gpios = <&gpio0 22 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
label = "DRDYM from BMX055 9-DOF";
|
||||
zephyr,code = <INPUT_KEY_0>;
|
||||
};
|
||||
int1: int_1 {
|
||||
gpios = <&gpio0 12 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
label = "Interrupt 1 from BMX055 9-DOF";
|
||||
zephyr,code = <INPUT_KEY_0>;
|
||||
};
|
||||
int2: int_2 {
|
||||
gpios = <&gpio0 14 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
label = "Interrupt 2 from BMX055 9-DOF";
|
||||
zephyr,code = <INPUT_KEY_0>;
|
||||
};
|
||||
int3: int_3 {
|
||||
gpios = <&gpio0 10 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
label = "Interrupt 3 from BMX055 9-DOF";
|
||||
zephyr,code = <INPUT_KEY_0>;
|
||||
};
|
||||
int4: int_4 {
|
||||
gpios = <&gpio0 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
label = "Interrupt 4 from BMX055 9-DOF";
|
||||
zephyr,code = <INPUT_KEY_0>;
|
||||
};
|
||||
int5: int_5 {
|
||||
gpios = <&gpio0 30 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
label = "Interrupt 5 from BMX055 9-DOF";
|
||||
zephyr,code = <INPUT_KEY_0>;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
blink_led: blink-led {
|
||||
compatible = "blink-gpio-led";
|
||||
led-gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>;
|
||||
blink-period-ms = <1000>;
|
||||
};
|
||||
|
||||
/* These aliases are provided for compatibility with samples */
|
||||
aliases {
|
||||
led0 = &led0;
|
||||
led1 = &led1;
|
||||
led2 = &led2;
|
||||
led3 = &led3;
|
||||
// pwm-led0 = &pwm_led0;
|
||||
sw0 = &button0;
|
||||
// sw1 = &button1;
|
||||
// sw2 = &button2;
|
||||
// sw3 = &button3;
|
||||
bootloader-led0 = &led0;
|
||||
mcuboot-button0 = &button0;
|
||||
mcuboot-led0 = &led0;
|
||||
watchdog0 = &wdt0;
|
||||
};
|
||||
};
|
||||
|
||||
&uicr {
|
||||
gpio-as-nreset;
|
||||
};
|
||||
|
||||
&gpiote {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&gpio0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&uart0 {
|
||||
compatible = "nordic,nrf-uarte";
|
||||
status = "okay";
|
||||
current-speed = <115200>;
|
||||
pinctrl-0 = <&uart0_default>;
|
||||
pinctrl-1 = <&uart0_sleep>;
|
||||
pinctrl-names = "default", "sleep";
|
||||
};
|
||||
|
||||
&i2c0 {
|
||||
compatible = "nordic,nrf-twi";
|
||||
status = "okay";
|
||||
pinctrl-0 = <&i2c0_default>;
|
||||
pinctrl-1 = <&i2c0_sleep>;
|
||||
pinctrl-names = "default", "sleep";
|
||||
|
||||
ssd1306: ssd1306@3d {
|
||||
compatible = "solomon,ssd1306fb";
|
||||
reg = <0x3d>;
|
||||
width = <128>;
|
||||
height = <64>;
|
||||
segment-offset = <0>;
|
||||
page-offset = <0>;
|
||||
display-offset = <0>;
|
||||
multiplex-ratio = <63>;
|
||||
segment-remap;
|
||||
com-invdir;
|
||||
prechargep = <0x22>;
|
||||
};
|
||||
|
||||
ina231: ina231@45 {
|
||||
compatible = "ti,ina230";
|
||||
reg = <0x45>;
|
||||
// irq-gpios = <&gpio0 31 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
current-lsb-microamps = <7>;
|
||||
rshunt-micro-ohms = <50000>;
|
||||
adc-mode = "Bus and shunt voltage continuous";
|
||||
};
|
||||
|
||||
bmp388: bmp388@76 {
|
||||
compatible = "bosch,bmp388";
|
||||
reg = <0x76>;
|
||||
int-gpios = <&gpio0 27 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
// odr = "1.563";
|
||||
osr-press = <1>;
|
||||
};
|
||||
|
||||
hdc1080: hdc1080@40 {
|
||||
compatible = "ti,hdc1080";
|
||||
reg = <0x40>;
|
||||
};
|
||||
|
||||
// BMX055 = BMA255 + BMG160 + BMM150
|
||||
bmx055_accel: bma255@18 {
|
||||
compatible = "bosch,bma255";
|
||||
reg = <0x18>;
|
||||
};
|
||||
|
||||
bmx055_gyro: bmg160@68 {
|
||||
compatible = "bosch,bmg160";
|
||||
reg = <0x68>;
|
||||
};
|
||||
|
||||
bmx055_mag: bmm150@10 {
|
||||
compatible = "bosch,bmm150";
|
||||
reg = <0x10>;
|
||||
};
|
||||
|
||||
lis2dh: lis2dh@19 {
|
||||
// This is built into the DWM1001 module
|
||||
compatible = "st,lis2dh";
|
||||
reg = <0x19>;
|
||||
};
|
||||
};
|
||||
|
||||
&spi1 {
|
||||
compatible = "nordic,nrf-spi";
|
||||
status = "okay";
|
||||
pinctrl-0 = <&spi1_default>;
|
||||
pinctrl-1 = <&spi1_sleep>;
|
||||
pinctrl-names = "default", "sleep";
|
||||
};
|
||||
|
||||
&flash0 {
|
||||
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
boot_partition: partition@0 {
|
||||
label = "mcuboot";
|
||||
reg = <0x00000000 0xc000>;
|
||||
};
|
||||
slot0_partition: partition@c000 {
|
||||
label = "image-0";
|
||||
reg = <0x0000C000 0x37000>;
|
||||
};
|
||||
slot1_partition: partition@43000 {
|
||||
label = "image-1";
|
||||
reg = <0x00043000 0x37000>;
|
||||
};
|
||||
storage_partition: partition@7a000 {
|
||||
label = "storage";
|
||||
reg = <0x0007a000 0x00006000>;
|
||||
};
|
||||
};
|
||||
};
|
23
firmware/boards/bh/mellifera_rev1/mellifera_rev1.yaml
Normal file
23
firmware/boards/bh/mellifera_rev1/mellifera_rev1.yaml
Normal file
@ -0,0 +1,23 @@
|
||||
identifier: mellifera_rev1
|
||||
name: Mellifera-Rev1
|
||||
type: mcu
|
||||
arch: arm
|
||||
toolchain:
|
||||
- zephyr
|
||||
- gnuarmemb
|
||||
- xtools
|
||||
ram: 64
|
||||
flash: 512
|
||||
supported:
|
||||
- adc
|
||||
- arduino_gpio
|
||||
- arduino_i2c
|
||||
- arduino_spi
|
||||
- gpio
|
||||
- counter
|
||||
- nvs
|
||||
- i2c
|
||||
- pwm
|
||||
- spi
|
||||
- watchdog
|
||||
vendor: nordic
|
19
firmware/boards/bh/mellifera_rev1/mellifera_rev1_defconfig
Normal file
19
firmware/boards/bh/mellifera_rev1/mellifera_rev1_defconfig
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
# Enable MPU
|
||||
CONFIG_ARM_MPU=y
|
||||
|
||||
# Enable hardware stack protection
|
||||
CONFIG_HW_STACK_PROTECTION=y
|
||||
|
||||
# Enable RTT
|
||||
CONFIG_USE_SEGGER_RTT=y
|
||||
|
||||
# enable GPIO
|
||||
CONFIG_GPIO=y
|
||||
|
||||
# enable uart driver
|
||||
CONFIG_SERIAL=y
|
||||
|
||||
# enable console
|
||||
CONFIG_CONSOLE=y
|
||||
CONFIG_UART_CONSOLE=y
|
2735
firmware/doc/Doxyfile
Normal file
2735
firmware/doc/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
20
firmware/doc/Makefile
Normal file
20
firmware/doc/Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line, and also
|
||||
# from the environment for the first two.
|
||||
SPHINXOPTS ?=
|
||||
SPHINXBUILD ?= sphinx-build
|
||||
SOURCEDIR = .
|
||||
BUILDDIR = _build_sphinx
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
17
firmware/doc/_doxygen/groups.dox
Normal file
17
firmware/doc/_doxygen/groups.dox
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @defgroup drivers Custom driver classes
|
||||
* @{
|
||||
*
|
||||
* @brief Custom driver classes
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup lib Custom libraries
|
||||
* @{
|
||||
*
|
||||
* @brief Custom libraries
|
||||
*
|
||||
* @}
|
||||
*/
|
5
firmware/doc/_doxygen/main.md
Normal file
5
firmware/doc/_doxygen/main.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Introduction
|
||||
|
||||
This is the Doxygen documentation for [example-application].
|
||||
|
||||
[example-application]: https://github.com/zephyrproject-rtos/example-application
|
40
firmware/doc/conf.py
Normal file
40
firmware/doc/conf.py
Normal file
@ -0,0 +1,40 @@
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# For the full list of built-in configuration values, see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
||||
|
||||
project = 'Example Application'
|
||||
copyright = '2024, The Zephyr Community'
|
||||
author = 'The Zephyr Community'
|
||||
release = '1.0.0'
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||
|
||||
extensions = ['sphinx.ext.intersphinx', 'breathe']
|
||||
|
||||
templates_path = ['_templates']
|
||||
exclude_patterns = ['_build_sphinx', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
||||
|
||||
html_theme = 'alabaster'
|
||||
|
||||
# -- Options for Intersphinx -------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html
|
||||
|
||||
intersphinx_mapping = {'zephyr': ('https://docs.zephyrproject.org/latest/', None)}
|
||||
|
||||
## -- Options for Breathe ----------------------------------------------------
|
||||
# https://breathe.readthedocs.io/en/latest/index.html
|
||||
#
|
||||
# WARNING: please, check breathe maintainership status before using this
|
||||
# extension in production!
|
||||
|
||||
breathe_projects = {'example-application': '_build_doxygen/xml'}
|
||||
breathe_default_project = 'example-application'
|
||||
breathe_default_members = ('members', )
|
14
firmware/doc/drivers/blink.rst
Normal file
14
firmware/doc/drivers/blink.rst
Normal file
@ -0,0 +1,14 @@
|
||||
Blink
|
||||
=====
|
||||
|
||||
.. doxygengroup:: drivers_blink
|
||||
|
||||
Driver operations
|
||||
-----------------
|
||||
|
||||
.. doxygengroup:: drivers_blink_ops
|
||||
|
||||
Public API
|
||||
----------
|
||||
|
||||
.. doxygengroup:: drivers_blink_api
|
9
firmware/doc/drivers/index.rst
Normal file
9
firmware/doc/drivers/index.rst
Normal file
@ -0,0 +1,9 @@
|
||||
Drivers
|
||||
=======
|
||||
|
||||
.. doxygengroup:: drivers
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
blink
|
18
firmware/doc/index.rst
Normal file
18
firmware/doc/index.rst
Normal file
@ -0,0 +1,18 @@
|
||||
Welcome to Example Application's documentation!
|
||||
===============================================
|
||||
|
||||
This is a simple Sphinx documentation setup for ``example-application``.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Contents
|
||||
|
||||
drivers/index
|
||||
lib/index
|
||||
zephyr
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`search`
|
11
firmware/doc/lib/custom.rst
Normal file
11
firmware/doc/lib/custom.rst
Normal file
@ -0,0 +1,11 @@
|
||||
Custom
|
||||
======
|
||||
|
||||
.. doxygengroup:: lib_custom
|
||||
:desc-only:
|
||||
|
||||
Public API
|
||||
----------
|
||||
|
||||
.. doxygengroup:: lib_custom
|
||||
:content-only:
|
9
firmware/doc/lib/index.rst
Normal file
9
firmware/doc/lib/index.rst
Normal file
@ -0,0 +1,9 @@
|
||||
Libraries
|
||||
=========
|
||||
|
||||
.. doxygengroup:: lib
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
custom
|
35
firmware/doc/make.bat
Normal file
35
firmware/doc/make.bat
Normal file
@ -0,0 +1,35 @@
|
||||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set SOURCEDIR=.
|
||||
set BUILDDIR=_build_sphinx
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.https://www.sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
|
||||
:end
|
||||
popd
|
2
firmware/doc/requirements.txt
Normal file
2
firmware/doc/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Sphinx
|
||||
breathe
|
5
firmware/doc/zephyr.rst
Normal file
5
firmware/doc/zephyr.rst
Normal file
@ -0,0 +1,5 @@
|
||||
Zephyr
|
||||
======
|
||||
|
||||
You can reference Zephyr documentation items, like
|
||||
:external+zephyr:ref:`getting_started` or :external+zephyr:c:func:`k_sleep`.
|
8
firmware/drivers/CMakeLists.txt
Normal file
8
firmware/drivers/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Out-of-tree drivers for custom classes
|
||||
add_subdirectory_ifdef(CONFIG_BLINK blink)
|
||||
|
||||
# Out-of-tree drivers for existing driver classes
|
||||
add_subdirectory_ifdef(CONFIG_SENSOR sensor)
|
7
firmware/drivers/Kconfig
Normal file
7
firmware/drivers/Kconfig
Normal file
@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menu "Drivers"
|
||||
rsource "blink/Kconfig"
|
||||
rsource "sensor/Kconfig"
|
||||
endmenu
|
5
firmware/drivers/blink/CMakeLists.txt
Normal file
5
firmware/drivers/blink/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_library()
|
||||
zephyr_library_sources_ifdef(CONFIG_BLINK_GPIO_LED gpio_led.c)
|
23
firmware/drivers/blink/Kconfig
Normal file
23
firmware/drivers/blink/Kconfig
Normal file
@ -0,0 +1,23 @@
|
||||
# Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menuconfig BLINK
|
||||
bool "Blink device drivers"
|
||||
help
|
||||
This option enables the blink custom driver class.
|
||||
|
||||
if BLINK
|
||||
|
||||
config BLINK_INIT_PRIORITY
|
||||
int "Blink device drivers init priority"
|
||||
default KERNEL_INIT_PRIORITY_DEVICE
|
||||
help
|
||||
Blink device drivers init priority.
|
||||
|
||||
module = BLINK
|
||||
module-str = blink
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
rsource "Kconfig.gpio_led"
|
||||
|
||||
endif # BLINK
|
11
firmware/drivers/blink/Kconfig.gpio_led
Normal file
11
firmware/drivers/blink/Kconfig.gpio_led
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config BLINK_GPIO_LED
|
||||
bool "GPIO-controlled LED blink driver"
|
||||
default y
|
||||
depends on DT_HAS_BLINK_GPIO_LED_ENABLED
|
||||
select GPIO
|
||||
help
|
||||
Enable this option to use the GPIO-controlled LED blink driver. This
|
||||
demonstrates how to implement a driver for a custom driver class.
|
101
firmware/drivers/blink/gpio_led.c
Normal file
101
firmware/drivers/blink/gpio_led.c
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT blink_gpio_led
|
||||
|
||||
#include <zephyr/device.h>
|
||||
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include <app/drivers/blink.h>
|
||||
|
||||
LOG_MODULE_REGISTER(blink_gpio_led, CONFIG_BLINK_LOG_LEVEL);
|
||||
|
||||
struct blink_gpio_led_data {
|
||||
struct k_timer timer;
|
||||
};
|
||||
|
||||
struct blink_gpio_led_config {
|
||||
struct gpio_dt_spec led;
|
||||
unsigned int period_ms;
|
||||
};
|
||||
|
||||
static void blink_gpio_led_on_timer_expire(struct k_timer *timer)
|
||||
{
|
||||
const struct device *dev = k_timer_user_data_get(timer);
|
||||
const struct blink_gpio_led_config *config = dev->config;
|
||||
int ret;
|
||||
|
||||
ret = gpio_pin_toggle_dt(&config->led);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Could not toggle LED GPIO (%d)", ret);
|
||||
}
|
||||
}
|
||||
|
||||
static int blink_gpio_led_set_period_ms(const struct device *dev,
|
||||
unsigned int period_ms)
|
||||
{
|
||||
const struct blink_gpio_led_config *config = dev->config;
|
||||
struct blink_gpio_led_data *data = dev->data;
|
||||
|
||||
if (period_ms == 0) {
|
||||
k_timer_stop(&data->timer);
|
||||
return gpio_pin_set_dt(&config->led, 0);
|
||||
}
|
||||
|
||||
k_timer_start(&data->timer, K_MSEC(period_ms), K_MSEC(period_ms));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct blink_driver_api blink_gpio_led_api = {
|
||||
.set_period_ms = &blink_gpio_led_set_period_ms,
|
||||
};
|
||||
|
||||
static int blink_gpio_led_init(const struct device *dev)
|
||||
{
|
||||
const struct blink_gpio_led_config *config = dev->config;
|
||||
struct blink_gpio_led_data *data = dev->data;
|
||||
int ret;
|
||||
|
||||
if (!gpio_is_ready_dt(&config->led)) {
|
||||
LOG_ERR("LED GPIO not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = gpio_pin_configure_dt(&config->led, GPIO_OUTPUT_INACTIVE);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Could not configure LED GPIO (%d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
k_timer_init(&data->timer, blink_gpio_led_on_timer_expire, NULL);
|
||||
k_timer_user_data_set(&data->timer, (void *)dev);
|
||||
|
||||
if (config->period_ms > 0) {
|
||||
k_timer_start(&data->timer, K_MSEC(config->period_ms),
|
||||
K_MSEC(config->period_ms));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BLINK_GPIO_LED_DEFINE(inst) \
|
||||
static struct blink_gpio_led_data data##inst; \
|
||||
\
|
||||
static const struct blink_gpio_led_config config##inst = { \
|
||||
.led = GPIO_DT_SPEC_INST_GET(inst, led_gpios), \
|
||||
.period_ms = DT_INST_PROP_OR(inst, blink_period_ms, 0U), \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, blink_gpio_led_init, NULL, &data##inst, \
|
||||
&config##inst, POST_KERNEL, \
|
||||
CONFIG_BLINK_INIT_PRIORITY, \
|
||||
&blink_gpio_led_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(BLINK_GPIO_LED_DEFINE)
|
6
firmware/drivers/sensor/CMakeLists.txt
Normal file
6
firmware/drivers/sensor/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
add_subdirectory_ifdef(CONFIG_EXAMPLE_SENSOR example_sensor)
|
||||
add_subdirectory_ifdef(CONFIG_BMA255 bma255)
|
||||
add_subdirectory_ifdef(CONFIG_HDC1080 hdc1080)
|
8
firmware/drivers/sensor/Kconfig
Normal file
8
firmware/drivers/sensor/Kconfig
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if SENSOR
|
||||
rsource "example_sensor/Kconfig"
|
||||
rsource "bma255/Kconfig"
|
||||
rsource "hdc1080/Kconfig"
|
||||
endif # SENSOR
|
2
firmware/drivers/sensor/bma255/CMakeLists.txt
Normal file
2
firmware/drivers/sensor/bma255/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
zephyr_library()
|
||||
zephyr_library_sources(bma255.c)
|
17
firmware/drivers/sensor/bma255/Kconfig
Normal file
17
firmware/drivers/sensor/bma255/Kconfig
Normal file
@ -0,0 +1,17 @@
|
||||
config BMA255
|
||||
bool "BMA255"
|
||||
default y
|
||||
depends on DT_HAS_BOSCH_BMA255_ENABLED
|
||||
help
|
||||
Enable driver for BMA255.
|
||||
|
||||
if BMA255
|
||||
|
||||
config BMA255_TRIGGER
|
||||
bool "BMA255 trigger mode"
|
||||
depends on BMA255
|
||||
help
|
||||
Set to enable trigger mode using gpio interrupt, where
|
||||
interrupts are configured to line ALERT PIN.
|
||||
|
||||
endif # BMA255
|
257
firmware/drivers/sensor/bma255/bma255.c
Normal file
257
firmware/drivers/sensor/bma255/bma255.c
Normal file
@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Brendan Haines
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT bosch_bma255
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(bma255, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
// Accelerometer registers
|
||||
const uint8_t ACCEL_REG_BWG_CHIPID = 0x00;
|
||||
const uint8_t ACCEL_REG_ACCD_X_LSB = 0x02;
|
||||
const uint8_t ACCEL_REG_ACCD_X_MSB = 0x03;
|
||||
const uint8_t ACCEL_REG_ACCD_Y_LSB = 0x04;
|
||||
const uint8_t ACCEL_REG_ACCD_Y_MSB = 0x05;
|
||||
const uint8_t ACCEL_REG_ACCD_Z_LSB = 0x06;
|
||||
const uint8_t ACCEL_REG_ACCD_Z_MSB = 0x07;
|
||||
const uint8_t ACCEL_REG_ACCD_TEMP = 0x08;
|
||||
const uint8_t ACCEL_REG_INT_STATUS_0 = 0x09;
|
||||
const uint8_t ACCEL_REG_INT_STATUS_1 = 0x0A;
|
||||
const uint8_t ACCEL_REG_INT_STATUS_2 = 0x0B;
|
||||
const uint8_t ACCEL_REG_INT_STATUS_3 = 0x0C;
|
||||
const uint8_t ACCEL_REG_FIFO_STATUS = 0x0E;
|
||||
const uint8_t ACCEL_REG_PMU_RANGE = 0x0F;
|
||||
typedef enum accel_pmu_range_t
|
||||
{
|
||||
PMU_RANGE_2G = 0b0011, ///< DEFAULT
|
||||
PMU_RANGE_4G = 0b0101,
|
||||
PMU_RANGE_8G = 0b1000,
|
||||
PMU_RANGE_16G = 0b1100,
|
||||
} accel_pmu_range_t;
|
||||
const uint8_t ACCEL_REG_PMU_BW = 0x10;
|
||||
typedef enum accel_pmu_bw_t
|
||||
{
|
||||
PMU_BW_8HZ = 0b01000,
|
||||
PMU_BW_16HZ = 0b01001,
|
||||
PMU_BW_31HZ = 0b01010,
|
||||
PMU_BW_63HZ = 0b01011,
|
||||
PMU_BW_125HZ = 0b01100,
|
||||
PMU_BW_250HZ = 0b01101,
|
||||
PMU_BW_500HZ = 0b01110,
|
||||
PMU_BW_1000HZ = 0b01111,
|
||||
} accel_pmu_bw_t;
|
||||
const uint8_t ACCEL_REG_PMU_LPW = 0x11;
|
||||
const uint8_t ACCEL_REG_PMU_LOW_POWER = 0x12;
|
||||
const uint8_t ACCEL_REG_ACCD_HBW = 0x13;
|
||||
const uint8_t ACCEL_REG_BGW_SOFTRESET = 0x14;
|
||||
const uint8_t BGW_SOFTRESET = 0xB6; ///< Soft reset occurs when this value is written to ACCEL_REG_BGW_SOFTRESET
|
||||
const uint8_t ACCEL_REG_INT_EN_0 = 0x16;
|
||||
const uint8_t ACCEL_REG_INT_EN_1 = 0x17;
|
||||
const uint8_t ACCEL_REG_INT_EN_2 = 0x18;
|
||||
const uint8_t ACCEL_REG_INT_MAP_0 = 0x19;
|
||||
const uint8_t ACCEL_REG_INT_MAP_1 = 0x1A;
|
||||
const uint8_t ACCEL_REG_INT_MAP_2 = 0x1B;
|
||||
const uint8_t ACCEL_REG_INT_SRC = 0x1E;
|
||||
const uint8_t ACCEL_REG_INT_OUT_CTRL = 0x20;
|
||||
const uint8_t ACCEL_REG_INT_RST_LATCH = 0x21;
|
||||
const uint8_t ACCEL_REG_INT_0 = 0x22;
|
||||
const uint8_t ACCEL_REG_INT_1 = 0x23;
|
||||
const uint8_t ACCEL_REG_INT_2 = 0x24;
|
||||
const uint8_t ACCEL_REG_INT_3 = 0x25;
|
||||
const uint8_t ACCEL_REG_INT_4 = 0x26;
|
||||
const uint8_t ACCEL_REG_INT_5 = 0x27;
|
||||
const uint8_t ACCEL_REG_INT_6 = 0x28;
|
||||
const uint8_t ACCEL_REG_INT_7 = 0x29;
|
||||
const uint8_t ACCEL_REG_INT_8 = 0x2A;
|
||||
const uint8_t ACCEL_REG_INT_9 = 0x2B;
|
||||
const uint8_t ACCEL_REG_INT_A = 0x2C;
|
||||
const uint8_t ACCEL_REG_INT_B = 0x2D;
|
||||
const uint8_t ACCEL_REG_INT_C = 0x2E;
|
||||
const uint8_t ACCEL_REG_INT_D = 0x2F;
|
||||
const uint8_t ACCEL_REG_FIFO_CONFIG_0 = 0x30;
|
||||
const uint8_t ACCEL_REG_PMU_SELF_TEST = 0x32;
|
||||
const uint8_t ACCEL_REG_TRIM_NVM_CTRL = 0x33;
|
||||
const uint8_t ACCEL_REG_BGW_SPI3_WDT = 0x34;
|
||||
const uint8_t ACCEL_REG_OFC_CTRL = 0x36;
|
||||
const uint8_t ACCEL_REG_OFC_SETTING = 0x37;
|
||||
const uint8_t ACCEL_REG_OFC_OFFSET_X = 0x38;
|
||||
const uint8_t ACCEL_REG_OFC_OFFSET_Y = 0x39;
|
||||
const uint8_t ACCEL_REG_OFC_OFFSET_Z = 0x3A;
|
||||
const uint8_t ACCEL_REG_TRIM_GP0 = 0x3B;
|
||||
const uint8_t ACCEL_REG_TRIM_GP1 = 0x3C;
|
||||
const uint8_t ACCEL_REG_FIFO_CONFIG_1 = 0x3E;
|
||||
const uint8_t ACCEL_REG_FIFO_DATA = 0x3F;
|
||||
|
||||
struct bma255_data
|
||||
{
|
||||
int16_t accel_x;
|
||||
int16_t accel_y;
|
||||
int16_t accel_z;
|
||||
int8_t temperature;
|
||||
};
|
||||
|
||||
struct bma255_config
|
||||
{
|
||||
struct i2c_dt_spec bus;
|
||||
#ifdef CONFIG_INA230_TRIGGER
|
||||
bool trig_enabled;
|
||||
uint16_t mask;
|
||||
const struct gpio_dt_spec alert_gpio;
|
||||
uint16_t alert_limit;
|
||||
#endif /* CONFIG_INA230_TRIGGER */
|
||||
};
|
||||
|
||||
static int bma255_sample_fetch(const struct device *dev,
|
||||
enum sensor_channel chan)
|
||||
{
|
||||
const struct bma255_config *config = dev->config;
|
||||
struct bma255_data *data = dev->data;
|
||||
int ret;
|
||||
|
||||
uint8_t accel[6];
|
||||
ret = i2c_burst_read_dt(&config->bus, ACCEL_REG_ACCD_X_LSB, accel, sizeof(accel));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read acceleration registers!");
|
||||
return ret;
|
||||
}
|
||||
data->accel_x = ((int16_t)sys_get_le16(&accel[0])) >> 4;
|
||||
data->accel_y = ((int16_t)sys_get_le16(&accel[2])) >> 4;
|
||||
data->accel_z = ((int16_t)sys_get_le16(&accel[4])) >> 4;
|
||||
|
||||
ret = i2c_burst_read_dt(&config->bus, ACCEL_REG_ACCD_TEMP, &data->temperature, sizeof(data->temperature));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read temperature register!");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bma255_channel_get(const struct device *dev,
|
||||
enum sensor_channel chan,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct bma255_data *data = dev->data;
|
||||
|
||||
switch (chan)
|
||||
{
|
||||
// degrees C
|
||||
case SENSOR_CHAN_DIE_TEMP:
|
||||
// 0.5K/LSB, center temperature is 23C
|
||||
val->val1 = 23 + data->temperature / 2;
|
||||
val->val2 = 0; // TODO: don't throw out LSB
|
||||
break;
|
||||
// m/s^2
|
||||
case SENSOR_CHAN_ACCEL_X:
|
||||
{
|
||||
float accel = data->accel_x * 0.00098 * 9.80665; // to gees, to m/s^2
|
||||
val->val1 = accel;
|
||||
val->val2 = (accel - val->val1) * 1000000;
|
||||
break;
|
||||
}
|
||||
case SENSOR_CHAN_ACCEL_Y:
|
||||
{
|
||||
float accel = data->accel_y * 0.00098 * 9.80665; // to gees, to m/s^2
|
||||
val->val1 = accel;
|
||||
val->val2 = (accel - val->val1) * 1000000;
|
||||
break;
|
||||
}
|
||||
case SENSOR_CHAN_ACCEL_Z:
|
||||
{
|
||||
// For now assume 2g since that's the default value
|
||||
// 2g 0.98mg/LSB
|
||||
// 4g 1.95mg/LSB
|
||||
// 8g 3.91mg/LSB
|
||||
// 16g 7.81mg/LSB
|
||||
// 1 g = 9.80665 m/s^2
|
||||
float accel = data->accel_z * 0.00098 * 9.80665; // to gees, to m/s^2
|
||||
val->val1 = accel;
|
||||
val->val2 = (accel - val->val1) * 1000000;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct sensor_driver_api bma255_api = {
|
||||
.sample_fetch = &bma255_sample_fetch,
|
||||
.channel_get = &bma255_channel_get,
|
||||
};
|
||||
|
||||
static int bma255_init(const struct device *dev)
|
||||
{
|
||||
const struct bma255_config *const config = dev->config;
|
||||
int ret;
|
||||
|
||||
if (!device_is_ready(config->bus.bus))
|
||||
{
|
||||
LOG_ERR("I2C bus %s is not ready", config->bus.bus->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
uint8_t chip_id;
|
||||
ret = i2c_burst_read_dt(&config->bus, ACCEL_REG_BWG_CHIPID, &chip_id, sizeof(chip_id));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read chip ID register!");
|
||||
return ret;
|
||||
}
|
||||
const uint8_t CHIP_ID = 0xfa;
|
||||
if (chip_id != CHIP_ID)
|
||||
{
|
||||
LOG_ERR("Chip ID read from %s incorrect. Read 0x%02X, expected 0x%02X", dev->name, chip_id, CHIP_ID);
|
||||
}
|
||||
|
||||
// // Reset the sensor
|
||||
// uint8_t reset_val = BGW_SOFTRESET;
|
||||
// i2c_burst_write_dt(&config->bus, ACCEL_REG_BGW_SOFTRESET, &reset_val, sizeof(reset_val));
|
||||
|
||||
// // Wait for device to reset
|
||||
|
||||
uint8_t lpw;
|
||||
ret = i2c_burst_read_dt(&config->bus, ACCEL_REG_PMU_LPW, &lpw, sizeof(lpw));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read LPW register!");
|
||||
return ret;
|
||||
}
|
||||
LOG_INF("LPW register: 0x%02X", lpw);
|
||||
|
||||
// Write configuration
|
||||
uint8_t accel_range = PMU_RANGE_2G;
|
||||
i2c_burst_write_dt(&config->bus, ACCEL_REG_PMU_RANGE, &accel_range, sizeof(accel_range));
|
||||
|
||||
uint8_t accel_bw = PMU_BW_8HZ;
|
||||
i2c_burst_write_dt(&config->bus, ACCEL_REG_PMU_BW, &accel_bw, sizeof(accel_bw));
|
||||
|
||||
uint8_t hbw = (1 << 7); // data_high_bw (read filtered data) and enable lsb/msb shadowing
|
||||
i2c_burst_write_dt(&config->bus, ACCEL_REG_ACCD_HBW, &hbw, sizeof(hbw));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BMA255_INIT(i) \
|
||||
static struct bma255_data bma255_data_##i; \
|
||||
\
|
||||
static const struct bma255_config bma255_config_##i = { \
|
||||
.bus = I2C_DT_SPEC_INST_GET(i), \
|
||||
}; \
|
||||
\
|
||||
SENSOR_DEVICE_DT_INST_DEFINE(i, &bma255_init, NULL, \
|
||||
&bma255_data_##i, \
|
||||
&bma255_config_##i, POST_KERNEL, \
|
||||
CONFIG_SENSOR_INIT_PRIORITY, &bma255_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(BMA255_INIT)
|
5
firmware/drivers/sensor/example_sensor/CMakeLists.txt
Normal file
5
firmware/drivers/sensor/example_sensor/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_library()
|
||||
zephyr_library_sources(example_sensor.c)
|
10
firmware/drivers/sensor/example_sensor/Kconfig
Normal file
10
firmware/drivers/sensor/example_sensor/Kconfig
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config EXAMPLE_SENSOR
|
||||
bool "Example sensor"
|
||||
default y
|
||||
depends on DT_HAS_ZEPHYR_EXAMPLE_SENSOR_ENABLED
|
||||
select GPIO
|
||||
help
|
||||
Enable example sensor
|
86
firmware/drivers/sensor/example_sensor/example_sensor.c
Normal file
86
firmware/drivers/sensor/example_sensor/example_sensor.c
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT zephyr_example_sensor
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(example_sensor, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
struct example_sensor_data {
|
||||
int state;
|
||||
};
|
||||
|
||||
struct example_sensor_config {
|
||||
struct gpio_dt_spec input;
|
||||
};
|
||||
|
||||
static int example_sensor_sample_fetch(const struct device *dev,
|
||||
enum sensor_channel chan)
|
||||
{
|
||||
const struct example_sensor_config *config = dev->config;
|
||||
struct example_sensor_data *data = dev->data;
|
||||
|
||||
data->state = gpio_pin_get_dt(&config->input);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int example_sensor_channel_get(const struct device *dev,
|
||||
enum sensor_channel chan,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct example_sensor_data *data = dev->data;
|
||||
|
||||
if (chan != SENSOR_CHAN_PROX) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
val->val1 = data->state;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct sensor_driver_api example_sensor_api = {
|
||||
.sample_fetch = &example_sensor_sample_fetch,
|
||||
.channel_get = &example_sensor_channel_get,
|
||||
};
|
||||
|
||||
static int example_sensor_init(const struct device *dev)
|
||||
{
|
||||
const struct example_sensor_config *config = dev->config;
|
||||
|
||||
int ret;
|
||||
|
||||
if (!device_is_ready(config->input.port)) {
|
||||
LOG_ERR("Input GPIO not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = gpio_pin_configure_dt(&config->input, GPIO_INPUT);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Could not configure input GPIO (%d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define EXAMPLE_SENSOR_INIT(i) \
|
||||
static struct example_sensor_data example_sensor_data_##i; \
|
||||
\
|
||||
static const struct example_sensor_config example_sensor_config_##i = {\
|
||||
.input = GPIO_DT_SPEC_INST_GET(i, input_gpios), \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(i, example_sensor_init, NULL, \
|
||||
&example_sensor_data_##i, \
|
||||
&example_sensor_config_##i, POST_KERNEL, \
|
||||
CONFIG_SENSOR_INIT_PRIORITY, &example_sensor_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(EXAMPLE_SENSOR_INIT)
|
2
firmware/drivers/sensor/hdc1080/CMakeLists.txt
Normal file
2
firmware/drivers/sensor/hdc1080/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
zephyr_library()
|
||||
zephyr_library_sources(hdc1080.c)
|
6
firmware/drivers/sensor/hdc1080/Kconfig
Normal file
6
firmware/drivers/sensor/hdc1080/Kconfig
Normal file
@ -0,0 +1,6 @@
|
||||
config HDC1080
|
||||
bool "HDC1080"
|
||||
default y
|
||||
depends on DT_HAS_TI_HDC1080_ENABLED
|
||||
help
|
||||
Enable driver for HDC1080.
|
227
firmware/drivers/sensor/hdc1080/hdc1080.c
Normal file
227
firmware/drivers/sensor/hdc1080/hdc1080.c
Normal file
@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT ti_hdc1080
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(hdc1080, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
const uint8_t REG_TEMPERATURE = 0x00;
|
||||
const uint8_t REG_HUMIDITY = 0x01;
|
||||
const uint8_t REG_CONFIGURATION = 0x02;
|
||||
const uint8_t REG_SERIAL_ID_0 = 0xFB;
|
||||
const uint8_t REG_SERIAL_ID_1 = 0xFC;
|
||||
const uint8_t REG_SERIAL_ID_2 = 0xFD;
|
||||
const uint8_t REG_MANUFACTURER_ID = 0xFE;
|
||||
const uint8_t REG_DEVICE_ID = 0xFF;
|
||||
|
||||
#define CONFIG_RST (1 << 15) ///< Software reset. This bit self clears
|
||||
#define CONFIG_HEAT (1 << 13) ///< Enable heater
|
||||
#define CONFIG_MODE_SEQUENTIAL (1 << 12) ///< Temperature and humidity measured in sequence, temperature first
|
||||
#define CONFIG_BTST (1 << 11) ///< 1 = battery voltage < 2.8V
|
||||
#define CONFIG_TRES_14BIT (0 << 10) ///< Temperature resolution
|
||||
#define CONFIG_TRES_11BIT (1 << 10) ///< Temperature resolution
|
||||
#define CONFIG_HRES_14BIT (0b00 << 8) ///< Humidity resolution
|
||||
#define CONFIG_HRES_11BIT (0b01 << 8) ///< Humidity resolution
|
||||
#define CONFIG_HRES_8BIT (0b10 << 8) ///< Humidity resolution
|
||||
|
||||
struct hdc1080_data
|
||||
{
|
||||
int16_t temperature;
|
||||
uint16_t humidity;
|
||||
};
|
||||
|
||||
struct hdc1080_config
|
||||
{
|
||||
struct i2c_dt_spec bus;
|
||||
uint8_t temperature_bits;
|
||||
uint8_t humidity_bits;
|
||||
};
|
||||
|
||||
static int hdc1080_sample_fetch(const struct device *dev,
|
||||
enum sensor_channel chan)
|
||||
{
|
||||
const struct hdc1080_config *config = dev->config;
|
||||
struct hdc1080_data *data = dev->data;
|
||||
int ret;
|
||||
|
||||
// Trigger measurement
|
||||
uint8_t reg_addr = REG_TEMPERATURE;
|
||||
i2c_write_dt(&config->bus, ®_addr, 1);
|
||||
|
||||
// Wait for conversion
|
||||
float temperature_conversion_time; ///< microseconds
|
||||
switch (config->temperature_bits)
|
||||
{
|
||||
case 11:
|
||||
temperature_conversion_time = 3650;
|
||||
break;
|
||||
case 14:
|
||||
temperature_conversion_time = 6350;
|
||||
break;
|
||||
default:
|
||||
temperature_conversion_time = 0;
|
||||
break;
|
||||
}
|
||||
float humidity_conversion_time; ///< microseconds
|
||||
switch (config->humidity_bits)
|
||||
{
|
||||
case 8:
|
||||
humidity_conversion_time = 2500;
|
||||
break;
|
||||
case 11:
|
||||
humidity_conversion_time = 3850;
|
||||
break;
|
||||
case 14:
|
||||
humidity_conversion_time = 6500;
|
||||
break;
|
||||
default:
|
||||
humidity_conversion_time = 0;
|
||||
break;
|
||||
}
|
||||
k_busy_wait(temperature_conversion_time + humidity_conversion_time);
|
||||
|
||||
// Read data
|
||||
uint8_t rdata[4];
|
||||
ret = i2c_read_dt(&config->bus, rdata, sizeof(rdata));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read temperature and humidity!");
|
||||
return ret;
|
||||
}
|
||||
data->temperature = sys_get_be16(&rdata[0]);
|
||||
data->humidity = sys_get_be16(&rdata[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hdc1080_channel_get(const struct device *dev,
|
||||
enum sensor_channel chan,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct hdc1080_data *data = dev->data;
|
||||
|
||||
switch (chan)
|
||||
{
|
||||
case SENSOR_CHAN_AMBIENT_TEMP:
|
||||
{
|
||||
double temperature = data->temperature * 160.0 / (1 << 16) - 40;
|
||||
val->val1 = temperature;
|
||||
val->val2 = (temperature - val->val1) * 1e6;
|
||||
break;
|
||||
}
|
||||
case SENSOR_CHAN_HUMIDITY:
|
||||
{
|
||||
double humidity = data->humidity * 100.0 / (1 << 16);
|
||||
val->val1 = humidity;
|
||||
val->val2 = (humidity - val->val1) * 1e6;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct sensor_driver_api hdc1080_api = {
|
||||
.sample_fetch = &hdc1080_sample_fetch,
|
||||
.channel_get = &hdc1080_channel_get,
|
||||
};
|
||||
|
||||
static int hdc1080_init(const struct device *dev)
|
||||
{
|
||||
const struct hdc1080_config *const config = dev->config;
|
||||
int ret;
|
||||
|
||||
if (!device_is_ready(config->bus.bus))
|
||||
{
|
||||
LOG_ERR("I2C bus %s is not ready", config->bus.bus->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
uint8_t id[2];
|
||||
ret = i2c_burst_read_dt(&config->bus, REG_MANUFACTURER_ID, id, sizeof(id));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read manufacturer/device ID registers");
|
||||
return ret;
|
||||
}
|
||||
uint16_t manufacturer_id = sys_get_be16(&id[0]);
|
||||
const uint16_t MANUFACTURER_ID = 0x5449;
|
||||
if (manufacturer_id != MANUFACTURER_ID)
|
||||
{
|
||||
LOG_ERR("Manufacturer ID read from %s incorrect. Read 0x%02X, expected 0x%02X", dev->name, manufacturer_id, MANUFACTURER_ID);
|
||||
}
|
||||
|
||||
ret = i2c_burst_read_dt(&config->bus, REG_DEVICE_ID, id, sizeof(id));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read manufacturer/device ID registers");
|
||||
return ret;
|
||||
}
|
||||
uint16_t device_id = sys_get_be16(&id[0]);
|
||||
const uint16_t DEVICE_ID = 0x1050;
|
||||
if (device_id != DEVICE_ID)
|
||||
{
|
||||
LOG_ERR("Device ID read from %s incorrect. Read 0x%02X, expected 0x%02X", dev->name, device_id, DEVICE_ID);
|
||||
}
|
||||
|
||||
// Write configuration
|
||||
uint16_t cfg = 0;
|
||||
switch (config->temperature_bits)
|
||||
{
|
||||
case 14:
|
||||
cfg |= CONFIG_TRES_14BIT;
|
||||
break;
|
||||
case 11:
|
||||
cfg |= CONFIG_TRES_11BIT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERR("Invalid temperature resolution: %d bits", config->temperature_bits);
|
||||
return -1;
|
||||
}
|
||||
switch (config->humidity_bits)
|
||||
{
|
||||
case 14:
|
||||
cfg |= CONFIG_HRES_14BIT;
|
||||
break;
|
||||
case 11:
|
||||
cfg |= CONFIG_HRES_11BIT;
|
||||
break;
|
||||
case 8:
|
||||
cfg |= CONFIG_HRES_8BIT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERR("Invalid humidity resolution: %d bits", config->humidity_bits);
|
||||
return -1;
|
||||
}
|
||||
uint8_t wdata[2];
|
||||
sys_put_be16(cfg, wdata);
|
||||
i2c_burst_write_dt(&config->bus, REG_CONFIGURATION, wdata, sizeof(wdata));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define HDC1080_INIT(i) \
|
||||
static struct hdc1080_data hdc1080_data_##i; \
|
||||
\
|
||||
static const struct hdc1080_config hdc1080_config_##i = { \
|
||||
.bus = I2C_DT_SPEC_INST_GET(i), \
|
||||
.temperature_bits = 14, \
|
||||
.humidity_bits = 14, \
|
||||
}; \
|
||||
\
|
||||
SENSOR_DEVICE_DT_INST_DEFINE(i, &hdc1080_init, NULL, \
|
||||
&hdc1080_data_##i, \
|
||||
&hdc1080_config_##i, POST_KERNEL, \
|
||||
CONFIG_SENSOR_INIT_PRIORITY, &hdc1080_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(HDC1080_INIT)
|
28
firmware/dts/bindings/blink/blink-gpio-leds.yaml
Normal file
28
firmware/dts/bindings/blink/blink-gpio-leds.yaml
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
A generic binding for a GPIO-controlled blinking LED. Note that this binding
|
||||
has no vendor prefix, as it does not target a specific device or vendor.
|
||||
|
||||
Example definition in devicetree:
|
||||
|
||||
blink-gpio-led {
|
||||
compatible = "blink-gpio-led";
|
||||
led-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
|
||||
blink-period-ms = <1000>;
|
||||
};
|
||||
|
||||
compatible: "blink-gpio-led"
|
||||
|
||||
include: base.yaml
|
||||
|
||||
properties:
|
||||
led-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: GPIO-controlled LED.
|
||||
|
||||
blink-period-ms:
|
||||
type: int
|
||||
description: Initial blinking period in milliseconds.
|
12
firmware/dts/bindings/sensor/bosch,bma255.yaml
Normal file
12
firmware/dts/bindings/sensor/bosch,bma255.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
description: |
|
||||
TODO: add a description
|
||||
|
||||
compatible: "bosch,bma255"
|
||||
|
||||
include: [sensor-device.yaml, i2c-device.yaml]
|
||||
|
||||
# properties:
|
||||
# input-gpios:
|
||||
# type: phandle-array
|
||||
# required: true
|
||||
# description: Input GPIO to be sensed.
|
7
firmware/dts/bindings/sensor/ti,hdc1080.yaml
Normal file
7
firmware/dts/bindings/sensor/ti,hdc1080.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
description: |
|
||||
TODO: add a description
|
||||
|
||||
compatible: "ti,hdc1080"
|
||||
|
||||
include: [sensor-device.yaml, i2c-device.yaml]
|
||||
|
23
firmware/dts/bindings/sensor/zephyr,example-sensor.yaml
Normal file
23
firmware/dts/bindings/sensor/zephyr,example-sensor.yaml
Normal file
@ -0,0 +1,23 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
An example sensor that reads the GPIO level defined in input-gpios. The
|
||||
purpose of this sensor is to demonstrate how to create out-of-tree drivers.
|
||||
|
||||
Example definition in devicetree:
|
||||
|
||||
example-sensor {
|
||||
compatible = "zephyr,example-sensor";
|
||||
input-gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
};
|
||||
|
||||
compatible: "zephyr,example-sensor"
|
||||
|
||||
include: base.yaml
|
||||
|
||||
properties:
|
||||
input-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: Input GPIO to be sensed.
|
113
firmware/include/app/drivers/blink.h
Normal file
113
firmware/include/app/drivers/blink.h
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef APP_DRIVERS_BLINK_H_
|
||||
#define APP_DRIVERS_BLINK_H_
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/toolchain.h>
|
||||
|
||||
/**
|
||||
* @defgroup drivers_blink Blink drivers
|
||||
* @ingroup drivers
|
||||
* @{
|
||||
*
|
||||
* @brief A custom driver class to blink LEDs
|
||||
*
|
||||
* This driver class is provided as an example of how to create custom driver
|
||||
* classes. It provides an interface to blink an LED at a configurable rate.
|
||||
* Implementations could include simple GPIO-controlled LEDs, addressable LEDs,
|
||||
* etc.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup drivers_blink_ops Blink driver operations
|
||||
* @{
|
||||
*
|
||||
* @brief Operations of the blink driver class.
|
||||
*
|
||||
* Each driver class tipically provides a set of operations that need to be
|
||||
* implemented by each driver. These are used to implement the public API. If
|
||||
* support for system calls is needed, the operations structure must be tagged
|
||||
* with `__subsystem` and follow the `${class}_driver_api` naming scheme.
|
||||
*/
|
||||
|
||||
/** @brief Blink driver class operations */
|
||||
__subsystem struct blink_driver_api {
|
||||
/**
|
||||
* @brief Configure the LED blink period.
|
||||
*
|
||||
* @param dev Blink device instance.
|
||||
* @param period_ms Period of the LED blink in milliseconds, 0 to
|
||||
* disable blinking.
|
||||
*
|
||||
* @retval 0 if successful.
|
||||
* @retval -EINVAL if @p period_ms can not be set.
|
||||
* @retval -errno Other negative errno code on failure.
|
||||
*/
|
||||
int (*set_period_ms)(const struct device *dev, unsigned int period_ms);
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup drivers_blink_api Blink driver API
|
||||
* @{
|
||||
*
|
||||
* @brief Public API provided by the blink driver class.
|
||||
*
|
||||
* The public API is the interface that is used by applications to interact with
|
||||
* devices that implement the blink driver class. If support for system calls is
|
||||
* needed, functions accessing device fields need to be tagged with `__syscall`
|
||||
* and provide an implementation that follows the `z_impl_${function_name}`
|
||||
* naming scheme.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure the LED blink period.
|
||||
*
|
||||
*
|
||||
* @param dev Blink device instance.
|
||||
* @param period_ms Period of the LED blink in milliseconds.
|
||||
*
|
||||
* @retval 0 if successful.
|
||||
* @retval -EINVAL if @p period_ms can not be set.
|
||||
* @retval -errno Other negative errno code on failure.
|
||||
*/
|
||||
__syscall int blink_set_period_ms(const struct device *dev,
|
||||
unsigned int period_ms);
|
||||
|
||||
static inline int z_impl_blink_set_period_ms(const struct device *dev,
|
||||
unsigned int period_ms)
|
||||
{
|
||||
const struct blink_driver_api *api =
|
||||
(const struct blink_driver_api *)dev->api;
|
||||
|
||||
return api->set_period_ms(dev, period_ms);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turn LED blinking off.
|
||||
*
|
||||
* This is a convenience function to turn off the LED blinking. It also shows
|
||||
* how to create convenience functions that re-use other driver functions, or
|
||||
* driver operations, to provide a higher-level API.
|
||||
*
|
||||
* @param dev Blink device instance.
|
||||
*
|
||||
* @return See blink_set_period_ms().
|
||||
*/
|
||||
static inline int blink_off(const struct device *dev)
|
||||
{
|
||||
return blink_set_period_ms(dev, 0);
|
||||
}
|
||||
|
||||
#include <syscalls/blink.h>
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* APP_DRIVERS_BLINK_H_ */
|
37
firmware/include/app/lib/custom.h
Normal file
37
firmware/include/app/lib/custom.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Legrand North America, LLC.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef APP_LIB_CUSTOM_H_
|
||||
#define APP_LIB_CUSTOM_H_
|
||||
|
||||
/**
|
||||
* @defgroup lib_custom Custom library
|
||||
* @ingroup lib
|
||||
* @{
|
||||
*
|
||||
* @brief An example of a custom out-of-tree library.
|
||||
*
|
||||
* This library illustrates how create custom out-of-tree libraries. Splitting
|
||||
* code in libraries enables code reuse and modularity, also easing testing.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return @p val if non-zero, or Kconfig-controlled default.
|
||||
*
|
||||
* Function returns the provided value if non-zero, or a Kconfig-controlled
|
||||
* default value if the parameter is zero. This trivial function is provided in
|
||||
* order to have a library interface example that is trivial to test.
|
||||
*
|
||||
* @param val Value to return if non-zero
|
||||
*
|
||||
* @retval val if @p val is non-zero
|
||||
* @retval CONFIG_CUSTOM_GET_VALUE_DEFAULT if @p val is zero
|
||||
*/
|
||||
int custom_get_value(int val);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* APP_LIB_CUSTOM_H_ */
|
3
firmware/lib/CMakeLists.txt
Normal file
3
firmware/lib/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
add_subdirectory_ifdef(CONFIG_CUSTOM custom)
|
8
firmware/lib/Kconfig
Normal file
8
firmware/lib/Kconfig
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021 Legrand North America, LLC.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menu "Custom libraries"
|
||||
|
||||
rsource "custom/Kconfig"
|
||||
|
||||
endmenu
|
5
firmware/lib/custom/CMakeLists.txt
Normal file
5
firmware/lib/custom/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# Copyright (c) 2021, Legrand North America, LLC.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_library()
|
||||
zephyr_library_sources(custom.c)
|
19
firmware/lib/custom/Kconfig
Normal file
19
firmware/lib/custom/Kconfig
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2021, Legrand North America, LLC.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config CUSTOM
|
||||
bool "Support for custom library"
|
||||
help
|
||||
This option enables the 'custom' library
|
||||
|
||||
config CUSTOM_GET_VALUE_DEFAULT
|
||||
int "custom_get_value() default return value"
|
||||
depends on CUSTOM
|
||||
default 0
|
||||
help
|
||||
This option primarily exists as an example of a library Kconfig
|
||||
setting.
|
||||
|
||||
This option specifies the value for custom_get_value() to return
|
||||
when the input parameter is zero. (Otherwise the function returns the
|
||||
input parameter value.)
|
12
firmware/lib/custom/custom.c
Normal file
12
firmware/lib/custom/custom.c
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Legrand North America, LLC.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <app/lib/custom.h>
|
||||
|
||||
int custom_get_value(int val)
|
||||
{
|
||||
return (val != 0) ? val : CONFIG_CUSTOM_GET_VALUE_DEFAULT;
|
||||
}
|
49
firmware/scripts/example_west_command.py
Normal file
49
firmware/scripts/example_west_command.py
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright (c) 2019 Foundries.io
|
||||
# Copyright (c) 2022 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'''example_west_command.py
|
||||
|
||||
Example of a west extension in the example-application repository.'''
|
||||
|
||||
from west.commands import WestCommand # your extension must subclass this
|
||||
from west import log # use this for user output
|
||||
|
||||
class ExampleWestCommand(WestCommand):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
'example-west-command', # gets stored as self.name
|
||||
'an example west extension command', # self.help
|
||||
# self.description:
|
||||
'''\
|
||||
A multi-line description of example-west-command.
|
||||
|
||||
You can split this up into multiple paragraphs and they'll get
|
||||
reflowed for you. You can also pass
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter when calling
|
||||
parser_adder.add_parser() below if you want to keep your line
|
||||
endings.''')
|
||||
|
||||
def do_add_parser(self, parser_adder):
|
||||
# This is a bit of boilerplate, which allows you full control over the
|
||||
# type of argparse handling you want. The "parser_adder" argument is
|
||||
# the return value of an argparse.ArgumentParser.add_subparsers() call.
|
||||
parser = parser_adder.add_parser(self.name,
|
||||
help=self.help,
|
||||
description=self.description)
|
||||
|
||||
# Add some example options using the standard argparse module API.
|
||||
parser.add_argument('-o', '--optional', help='an optional argument')
|
||||
parser.add_argument('required', help='a required argument')
|
||||
|
||||
return parser # gets stored as self.parser
|
||||
|
||||
def do_run(self, args, unknown_args):
|
||||
# This gets called when the user runs the command, e.g.:
|
||||
#
|
||||
# $ west my-command-name -o FOO BAR
|
||||
# --optional is FOO
|
||||
# required is BAR
|
||||
log.inf('--optional is', args.optional)
|
||||
log.inf('required is', args.required)
|
34
firmware/scripts/log_data.py
Normal file
34
firmware/scripts/log_data.py
Normal file
@ -0,0 +1,34 @@
|
||||
import asyncio
|
||||
import struct
|
||||
|
||||
import numpy as np
|
||||
from bleak import BleakClient
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
address = "65:72:31:D7:E2:12"
|
||||
MODEL_NBR_UUID = "2A24"
|
||||
|
||||
batt = []
|
||||
|
||||
|
||||
async def main(address):
|
||||
async with BleakClient(address) as client:
|
||||
model_number = await client.read_gatt_char(MODEL_NBR_UUID)
|
||||
print("Model Number: {0}".format("".join(map(chr, model_number))))
|
||||
while True:
|
||||
# batt.append(ord(await client.read_gatt_char("2A19")))
|
||||
batt.append(struct.unpack("b", (await client.read_gatt_char("2A19")))[0])
|
||||
print(batt[-1])
|
||||
|
||||
|
||||
try:
|
||||
asyncio.run(main(address))
|
||||
except KeyboardInterrupt:
|
||||
changed = np.diff(batt) != 0
|
||||
print(
|
||||
f"{np.sum(changed)} changes (seconds) in {len(changed)} samples ({len(changed) / np.sum(changed)} samples per second)"
|
||||
)
|
||||
|
||||
plt.plot(batt)
|
||||
plt.show()
|
||||
plt.show()
|
6
firmware/scripts/west-commands.yml
Normal file
6
firmware/scripts/west-commands.yml
Normal file
@ -0,0 +1,6 @@
|
||||
west-commands:
|
||||
- file: scripts/example_west_command.py
|
||||
commands:
|
||||
- name: example-west-command
|
||||
class: ExampleWestCommand
|
||||
help: an example west extension command
|
8
firmware/tests/lib/custom/CMakeLists.txt
Normal file
8
firmware/tests/lib/custom/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, Legrand North America, LLC.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(app_lib_custom_test)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
2
firmware/tests/lib/custom/prj.conf
Normal file
2
firmware/tests/lib/custom/prj.conf
Normal file
@ -0,0 +1,2 @@
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_CUSTOM=y
|
42
firmware/tests/lib/custom/src/main.c
Normal file
42
firmware/tests/lib/custom/src/main.c
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Legrand North America, LLC.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* @file test custom_lib library
|
||||
*
|
||||
* This suite verifies that the methods provided with the custom_lib
|
||||
* library works correctly.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
#include <app/lib/custom.h>
|
||||
|
||||
ZTEST(custom_lib, test_get_value)
|
||||
{
|
||||
/* Verify standard behavior */
|
||||
zassert_equal(custom_get_value(INT_MIN), INT_MIN,
|
||||
"get_value failed input of INT_MIN");
|
||||
zassert_equal(custom_get_value(INT_MIN + 1), INT_MIN + 1,
|
||||
"get_value failed input of INT_MIN + 1");
|
||||
zassert_equal(custom_get_value(-1), -1,
|
||||
"get_value failed input of -1");
|
||||
zassert_equal(custom_get_value(1), 1,
|
||||
"get_value failed input of 1");
|
||||
zassert_equal(custom_get_value(INT_MAX - 1), INT_MAX - 1,
|
||||
"get_value failed input of INT_MAX - 1");
|
||||
zassert_equal(custom_get_value(INT_MAX), INT_MAX,
|
||||
"get_value failed input of INT_MAX");
|
||||
|
||||
/* Verify override behavior */
|
||||
zassert_equal(custom_get_value(0),
|
||||
CONFIG_CUSTOM_GET_VALUE_DEFAULT,
|
||||
"get_value failed input of 0");
|
||||
}
|
||||
|
||||
ZTEST_SUITE(custom_lib, NULL, NULL, NULL, NULL, NULL);
|
9
firmware/tests/lib/custom/testcase.yaml
Normal file
9
firmware/tests/lib/custom/testcase.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
common:
|
||||
tags: extensibility
|
||||
integration_platforms:
|
||||
- custom_plank
|
||||
- qemu_cortex_m0
|
||||
tests:
|
||||
lib.custom: {}
|
||||
lib.custom.non_default:
|
||||
extra_args: CONFIG_CUSTOM_GET_VALUE_DEFAULT=6
|
Reference in New Issue
Block a user