Skip to content

Commit

Permalink
Update Zephyr board files
Browse files Browse the repository at this point in the history
Working towards more supported boards
  • Loading branch information
dlktdr committed May 27, 2023
1 parent cd78706 commit d2f1dac
Show file tree
Hide file tree
Showing 24 changed files with 300 additions and 301 deletions.
7 changes: 2 additions & 5 deletions firmware/src/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
extra_scripts = pre:extra_script.py
build_src_filter = +<*> -<.git/> -<.svn/> -<targets/*>

# Zephyr OS + Arduino Nano33BLE (NRF52840)
# Zephyr OS + Arduino Nano33BLE
[env:Head_Tracker-Nano33_BLE]
extends = nrf52common
platform = nordicnrf52@9.4
Expand All @@ -46,21 +46,19 @@
debug_tool = jlink
build_flags =
${common.build_flags}
-DRTOS_ZEPHYR=y
-DPCB_NANO33BLE=y
-DFNAME=BLE

# Zephyr OS + Arduino Nano33BLE Sense Rev2
[env:Head_Tracker-Nano33_BLE_Sense2]
extends = nrf52common
platform = nordicnrf52@9.4
board = arduino_nano_33_ble_sense_r2
board = arduino_nano_33_ble
framework = zephyr
lib_deps = bblanchon/ArduinoJson@6.20
debug_tool = jlink
build_flags =
${common.build_flags}
-DRTOS_ZEPHYR=y
-DPCB_NANO33BLE_SENSE2=y
-DFNAME=BLE

Expand All @@ -74,7 +72,6 @@
debug_tool = jlink
build_flags =
${common.build_flags}
-DRTOS_ZEPHYR=y
-DPCB_DTQSYS=y
-DFNAME=DTQ

Expand Down
13 changes: 0 additions & 13 deletions firmware/src/src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
#define GYRO_FLASH_IF_OFFSET 0.5 // Save to flash if gyro is off more than 0.5 degrees/sec from flash value

// RTOS Specifics
#if defined(RTOS_ZEPHYR)
#include "zephyr.h"
#define millis() k_cyc_to_ms_floor32(k_cycle_get_32())
#define millis64() k_uptime_get()
Expand All @@ -131,18 +130,6 @@
#define rt_sleep_ms(x) k_msleep(x)
#define rt_sleep_us(x) k_usleep(x)

#elif defined(RTOS_FREERTOS)
#error("FREE RTOS NOT IMPLEMENTED")
#define micros()
#define micros64()
#define millis()
#define rt_sleep_s(x)
#define rt_sleep_ms(x)
#define rt_sleep_us(x)
#else
#error("NO RTOS DECLARED")
#endif

#if defined(PCB_NANO33BLE)
#include "boards/nano33board.h"
#elif defined(PCB_DTQSYS)
Expand Down
38 changes: 0 additions & 38 deletions firmware/src/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,7 @@
#include "io.h"
#include "nano33ble.h"

#ifdef DISABLE_SLEEP_STATES

static int disable_ds_1(const struct device *dev)
{
ARG_UNUSED(dev);

// Disable all power states
pm_ctrl_disable_state(PM_STATE_SOFT_OFF);
pm_ctrl_disable_state(PM_STATE_SUSPEND_TO_RAM);
pm_ctrl_disable_state(PM_STATE_SUSPEND_TO_IDLE);
pm_ctrl_disable_state(PM_STATE_SUSPEND_TO_DISK);
pm_ctrl_disable_state(PM_STATE_RUNTIME_IDLE);
pm_ctrl_disable_state(PM_STATE_STANDBY);

return 0;
}
SYS_INIT(disable_ds_1, PRE_KERNEL_2, 0);

#endif

extern "C" void main(void)
{
start(); // Call Our C++ Main
}

static int board_internal_sensors_init(const struct device *dev)
{
ARG_UNUSED(dev);

io_init();

NRF_PWM_Type *PWM[] = {NRF_PWM0, NRF_PWM1, NRF_PWM2, NRF_PWM3};

for (unsigned int i = 0; i < (ARRAY_SIZE(PWM)); i++) {
PWM[i]->ENABLE = 0;
PWM[i]->PSEL.OUT[0] = 0xFFFFFFFFUL;
}

return 0;
}

SYS_INIT(board_internal_sensors_init, PRE_KERNEL_1, 32);
35 changes: 9 additions & 26 deletions firmware/src/src/nano33ble.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@

#include "nano33ble.h"

#include <drivers/clock_control.h>
#include <drivers/clock_control/nrf_clock_control.h>
#include <drivers/counter.h>
#include <nrfx_clock.h>

#include "PPMIn.h"
#include "PPMOut.h"
#include "uart_mode.h"
#include "analog.h"
#include "ble.h"
#include "io.h"
Expand All @@ -19,25 +16,16 @@
#include "serial.h"
#include "soc_flash.h"
#include "trackersettings.h"

#define CLOCK_NODE DT_INST(0, nordic_nrf_clock)
static const struct device *clock0;

bool led_is_on = false;
#include "uart_mode.h"

TrackerSettings trkset;

K_SEM_DEFINE(saveToFlash_sem, 0, 1);

void start(void)
{
// Force High Accuracy Clock
const char *clock_label = DT_LABEL(CLOCK_NODE);
clock0 = DEVICE_DT_GET(DT_NODELABEL(clock));
if (clock0 == NULL) {
printk("Failed to fetch clock %s\n", clock_label);
}
clock_control_on(clock0, CLOCK_CONTROL_NRF_SUBSYS_HF);
// Initalize IO
io_init();

// USB Joystick
joystick_init();
Expand All @@ -61,7 +49,7 @@ void start(void)
trkset.loadFromEEPROM();

// Check if center button is held down, force BT Configuration mode
if(readCenterButton()) {
if (readCenterButton()) {
trkset.setBtMode(BTPARAHEAD);
setLEDFlag(LED_BTCONFIGURATOR);
}
Expand All @@ -70,14 +58,13 @@ void start(void)
bt_init();

// Monitor if saving to EEPROM is required
while(1) {
while (1) {
if (!k_sem_take(&saveToFlash_sem, K_FOREVER)) {
trkset.saveToEEPROM();
}
}
}

#if defined(RTOS_ZEPHYR)
// Threads
K_THREAD_DEFINE(io_Thread_id, 512, io_Thread, NULL, NULL, NULL, IO_THREAD_PRIO, 0, 0);
K_THREAD_DEFINE(serial_Thread_id, 4096, serial_Thread, NULL, NULL, NULL, SERIAL_THREAD_PRIO,
Expand All @@ -87,11 +74,7 @@ K_THREAD_DEFINE(sensor_Thread_id, 1024, sensor_Thread, NULL, NULL, NULL, SENSOR_
K_FP_REGS, 500);
K_THREAD_DEFINE(calculate_Thread_id, 1024, calculate_Thread, NULL, NULL, NULL,
CALCULATE_THREAD_PRIO, K_FP_REGS, 1000);
K_THREAD_DEFINE(uartTx_Thread_ID, 1024, uartTx_Thread, NULL, NULL, NULL, UARTTX_THREAD_PRIO, 0, 1000);
K_THREAD_DEFINE(uartRx_Thread_ID, 512, uartRx_Thread, NULL, NULL, NULL, UARTRX_THREAD_PRIO, 0, 1000);

#elif defined(RTOS_FREERTOS)
#error "TODO... Add tasks for FreeRTOS"
#else
#error "RTOS NOT SPECIFIED"
#endif
K_THREAD_DEFINE(uartTx_Thread_ID, 1024, uartTx_Thread, NULL, NULL, NULL, UARTTX_THREAD_PRIO, 0,
1000);
K_THREAD_DEFINE(uartRx_Thread_ID, 512, uartRx_Thread, NULL, NULL, NULL, UARTRX_THREAD_PRIO, 0,
1000);
76 changes: 0 additions & 76 deletions firmware/src/zephyr/arduino_nano_33_ble.overlay

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) 2020 Jefferson Lee.
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_BOARD_ARDUINO_NANO_33_BLE_INIT)
zephyr_library()
zephyr_library_sources("${CMAKE_CURRENT_SOURCE_DIR}/src/init.c")
endif()
10 changes: 10 additions & 0 deletions firmware/src/zephyr/boards/arm/arduino_nano_33_ble/Kconfig.board
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2020 Jefferson Lee.
# SPDX-License-Identifier: Apache-2.0

config BOARD_ARDUINO_NANO_33_BLE
bool "Arduino Nano 33 BLE board"
depends on SOC_NRF52840_QIAA

config BOARD_ARDUINO_NANO_33_BLE_INIT
bool "Initialize the board"
depends on BOARD_ARDUINO_NANO_33_BLE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ config BOARD
config BT_CTLR
default BT

config BOARD_ARDUINO_NANO_33_BLE_INIT
default y

if I2C
config I2C_NRFX
default y
Expand All @@ -17,8 +20,6 @@ config I2C_0
default y
config I2C_1
default y
config BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS
default y
endif #I2C

if SPI
Expand Down
Loading

0 comments on commit d2f1dac

Please sign in to comment.