Skip to content

Commit

Permalink
Merge pull request dlktdr#150 from dlktdr/xaio_zephyr_2.7
Browse files Browse the repository at this point in the history
Merging to main. So I can work on hwfeatures branch and clean up various board specific things in the code
  • Loading branch information
dlktdr authored Jun 17, 2023
2 parents 39c554a + 95a9f8b commit f5cdad9
Show file tree
Hide file tree
Showing 32 changed files with 1,359 additions and 35 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/build-firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: 'true'

- name: Cache pip
uses: actions/cache@v2
Expand All @@ -56,6 +57,11 @@ jobs:
pip install --upgrade platformio
# Runs a single command using the runners shell

- name: Workaround bug in github actions issue 6775
run: |
git config --global --add safe.directory '*'
- name: Build Firmware Nano 33 BLE
run: |
cd /src/firmware/src
Expand All @@ -71,12 +77,23 @@ jobs:
cd /src/firmware/src
pio run -e Head_Tracker-Nano33_BLE_Sense_Rev_2
- name: Build XIAO Sense Firmware
run: |
gitrevshort=$(git rev-parse --short HEAD)
gitlasttag=$(git describe --tags --abbrev=0)
gitlasttag=`echo $gitlasttag | tr '.' '_'`
cd /src/firmware/src
pio run -e Head_Tracker-XIAOSense
cd /src/firmware/src/.pio/build/Head_Tracker-XIAOSense
python ../../../tools/uf2conv.py XIA_${gitlasttag}_${gitrevshort}.bin -o ./XIAO_${gitlasttag}_${gitrevshort}.uf2 -f 0xADA52840 -c -b 0x27000
# Runs a set of commands using the runners shell
- name: Package Firmware
uses: 'actions/upload-artifact@v2'
with:
name: Firmware_Binaries
path: |
/src/firmware/src/.pio/build/*/*.bin
retention-days: 60
/src/firmware/src/.pio/build/*/*.uf2
retention-days: 90
if-no-files-found: error
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "web_configurator"]
path = web_configurator
url = https://github.com/dlktdr/HeadTracker_WebBLE.git
[submodule "firmware/src/src/LSM6DS3"]
path = firmware/src/src/LSM6DS3
url = https://github.com/STMicroelectronics/LSM6DS3TR-C-PID
62 changes: 62 additions & 0 deletions firmware/src/boards/xiao_sense.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"build": {
"arduino":{
"ldscript": "linker_script.ld"
},
"core": "nRF5",
"cpu": "cortex-m4",
"extra_flags": "-DNRF52840_XXAA",
"f_cpu": "64000000L",
"hwids": [
[
"0x2886",
"0x0045"
],
[
"0x2886",
"0x8045"
]
],
"mcu": "nrf52840",
"variant": "xiao_sense",
"zephyr": {
"variant": "xiao_sense"
},
"softdevice": {
"sd_flags": "-DS140",
"sd_name": "s140",
"sd_version": "7.3.0",
"sd_fwid": "0x0123"
}
},
"connectivity": [
"bluetooth"
],
"debug": {
"jlink_device": "nRF52840_xxAA",
"openocd_target": "nrf52.cfg",
"svd_path": "nrf52840.svd"
},
"frameworks": [
"zephyr"
],
"name": "XIAO Sense",
"upload": {
"maximum_ram_size": 262144,
"maximum_size": 983040,
"protocol": "sam-ba",
"protocols": [
"jlink",
"nrfjprog",
"nrfutil",
"cmsis-dap",
"sam-ba",
"blackmagic"
],
"use_1200bps_touch": true,
"require_upload_port": true,
"wait_for_upload_port": true
},
"url": "https://wiki.seeedstudio.com/XIAO_BLE",
"vendor": "Seeed Studio"
}
20 changes: 16 additions & 4 deletions firmware/src/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
[platformio]
description = "Head Tracker"
# default_envs = Head_Tracker-Nano33_BLE
# default_envs = Head_Tracker-Nano33_BLE_Sense_Rev_2
# default_envs = Head_Tracker-DTQSys
# default_envs = Head_Tracker-Nano33_BLE_Sense2
# default_envs = Head_Tracker-XIAOSense

[common]
build_flags =
Expand Down Expand Up @@ -87,6 +88,17 @@
-DPCB_DTQSYS=y
-DFNAME=DTQ




# Zephyr OS + XAIO Sense
[env:Head_Tracker-XIAOSense]
#build_type = debug
extends = nrf52common
platform = [email protected]
board = xiao_sense
framework = zephyr
lib_deps = bblanchon/[email protected]
debug_tool = jlink
build_flags =
${common.build_flags}
-DRTOS_ZEPHYR=y
-DPCB_XIAOSENSE=y
-DFNAME=XIA
1 change: 1 addition & 0 deletions firmware/src/src/LSM6DS3
Submodule LSM6DS3 added at 1b4f9e
46 changes: 46 additions & 0 deletions firmware/src/src/LSMCommon/lsm_common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <zephyr.h>

#include "io.h"
#include "lsm_common.h"
#include "defines.h"

int32_t platform_read_lsm6(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len)
{
const struct device *i2c_dev = device_get_binding("I2C_1");
return i2c_burst_read(i2c_dev, LSM6DS3TR_C_ID, reg, bufp, len);
}

int32_t platform_write_lsm6(void *handle, uint8_t reg, const uint8_t *bufp, uint16_t len)
{
const struct device *i2c_dev = device_get_binding("I2C_1");
return i2c_burst_write(i2c_dev, LSM6DS3TR_C_ID, reg, bufp, len);
}

int initailizeLSM6DS3(stmdev_ctx_t *dev_ctx)
{
uint8_t whoamI=0, rst;
/* Initialize mems driver interface */
dev_ctx->write_reg = platform_write_lsm6;
dev_ctx->read_reg = platform_read_lsm6;
/* Wait sensor boot time */
k_msleep(BOOT_TIME);
/* Check device ID */
lsm6ds3tr_c_device_id_get(dev_ctx, &whoamI);
if (whoamI != LSM6DS3TR_C_ID)
return -1;
/* Restore default configuration */
lsm6ds3tr_c_reset_set(dev_ctx, PROPERTY_ENABLE);
do {
lsm6ds3tr_c_reset_get(dev_ctx, &rst);
} while (rst);
/* Enable Block Data Update */
lsm6ds3tr_c_block_data_update_set(dev_ctx, PROPERTY_ENABLE);
/* Set full scale */
lsm6ds3tr_c_xl_full_scale_set(dev_ctx, LSM6DS3TR_C_2g);
lsm6ds3tr_c_gy_full_scale_set(dev_ctx, LSM6DS3TR_C_2000dps);
/* Set Output Data Rate for Acc and Gyro */
lsm6ds3tr_c_xl_data_rate_set(dev_ctx, LSM6DS3TR_C_XL_ODR_208Hz);
lsm6ds3tr_c_gy_data_rate_set(dev_ctx, LSM6DS3TR_C_GY_ODR_208Hz);

return 0;
}
12 changes: 12 additions & 0 deletions firmware/src/src/LSMCommon/lsm_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <drivers/i2c.h>
#include <zephyr.h>

#include "LSM6DS3/lsm6ds3tr-c_reg.h"

#define BOOT_TIME 30

int32_t platform_read_lsm6(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len);
int32_t platform_write_lsm6(void *handle, uint8_t reg, const uint8_t *bufp, uint16_t len);
int initailizeLSM6DS3(stmdev_ctx_t *dev_ctx);
78 changes: 78 additions & 0 deletions firmware/src/src/boards/xiaosense.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#pragma once

#include <stdint.h>

#include "boardsdefs.h"

// Pull up pin mode
#define INPUT_PULLUP (GPIO_INPUT | GPIO_PULL_UP)

// Board Features
#define HAS_3DIODE_RGB
#define HAS_NOTIFYLED
#define HAS_LSM6DS3
#define HAS_CENTERBTN

// Mapping Analog numbers to Analog pins
#define AN0 7 // Battery Voltage
#define AN1 1 //
#define AN2 4 //
#define AN3 5 //

// Pins (name, number, description)
// NOTE: These pins are an enum entry. e.g. IO_D2 = 0
// - Use PIN_NAME_TO_NUM(IO_D2) to get actual the pin number
// - The pin number can be converted back into the NRF port/pin
// using functions PIN_TO_NRFPORT & PIN_TO_NRFPIN
// - The string descrition for D2 would be StrPins[IO_D2]

#define PIN_X \
PIN(AN0, NRFPIN(0, 31), "Analog Battery Voltage") \
PIN(ANBATT_ENA, NRFPIN(0, 14), "Battery Monitor Enable") \
PIN(AN1, NRFPIN(0, 3), "Analog 1 (AIN_1)") \
PIN(AN2, NRFPIN(0, 28), "Analog 2 (AIN_4)") \
PIN(AN3, NRFPIN(0, 29), "Analog 3 (AIN_5)") \
PIN(CENTER_BTN, NRFPIN(1, 13), "Center Button, D8") \
PIN(LEDR, NRFPIN(0, 26), "Red LED") \
PIN(LEDG, NRFPIN(0, 30), "Green LED") \
PIN(LEDB, NRFPIN(0, 6), "Blue LED") \
PIN(LED, NRFPIN(0, 14), "Notification LED") \
PIN(PPMOUT, NRFPIN(1, 15), "PPM Output Pin [D10]") \
PIN(PPMIN, NRFPIN(1, 14), "PPM In Pin [D9]") \
PIN(TX, NRFPIN(1, 11), "UART Transmit [TX]") \
PIN(RX, NRFPIN(1, 12), "UART Receive [RX]") \
PIN(TXINV, NRFPIN(0, 19), "UART TX, Inv Pin") \
PIN(RXINVO, NRFPIN(0, 10), "UART RX, Out Inv") \
PIN(RXINVI, NRFPIN(0, 9), "UART RX, Inp Inv") \
PIN(SCK, NRFPIN(0, 21), "SPI Clock - Flash") \
PIN(MOSI, NRFPIN(0, 20), "SPI Data Out - Flash") \
PIN(MISO, NRFPIN(0, 24), "SPI Data In - Flash") \
PIN(FLSH_WP, NRFPIN(0, 22), "Flash Write Protect") \
PIN(FLSH_HLD, NRFPIN(0, 23), "Flash Hold") \
PIN(LSM6DS3PWR, NRFPIN(1, 8), "LSM6DS3 Power 6DPWR") \
PIN(LSM6DS3INT, NRFPIN(0, 11), "LSM6DS3 Interrupt") \
PIN(I2CSCL, NRFPIN(0, 27), "I2C - SCL") \
PIN(I2CSDA, NRFPIN(0, 7), "I2C - SDA") \
END_IO_PINS \

typedef enum {
#define PIN(NAME, PINNO, DESC) IO_##NAME,
PIN_X
#undef PIN
} pins_e;

const int8_t PinNumber[] = {
#define PIN(NAME, PINNO, DESC) PINNO,
PIN_X
#undef PIN
};

// Required pin setting functions
#define pinMode(pin, mode) gpio_pin_configure(gpios[PIN_TO_NRFPORT(PIN_NAME_TO_NUM(pin))], PIN_TO_NRFPIN(PIN_NAME_TO_NUM(pin)), mode)
#define digitalWrite(pin, value) gpio_pin_set(gpios[PIN_TO_NRFPORT(PIN_NAME_TO_NUM(pin))], PIN_TO_NRFPIN(PIN_NAME_TO_NUM(pin)), value)
#define digitalRead(pin) gpio_pin_get(gpios[PIN_TO_NRFPORT(PIN_NAME_TO_NUM(pin))], PIN_TO_NRFPIN(PIN_NAME_TO_NUM(pin)))

// TODO Find good values here
// Values below were determined by plotting Gyro Output (See sense.cpp, gyroCalibration())
#define GYRO_STABLE_DIFF 200.0f
#define ACC_STABLE_DIFF 2.5f
7 changes: 6 additions & 1 deletion firmware/src/src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@

#if defined(PCB_NANO33BLE)
#define FW_BOARD "NANO33BLE"
#include "boards/nano33board.h"
#elif defined(PCB_DTQSYS)
#define FW_BOARD "DTQSYS"
#include "boards/dtqsys_ht.h"
#elif defined(PCB_XIAOSENSE)
#define FW_BOARD "XIAOSENSE"
#include "boards/xiaosense.h"
#else
#error NO PCB DEFINED
#endif
Expand Down Expand Up @@ -134,4 +139,4 @@
#include "boards/nano33board.h"
#elif defined(PCB_DTQSYS)
#include "boards/dtqsys_ht.h"
#endif
#endif
26 changes: 22 additions & 4 deletions firmware/src/src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <device.h>
#include <drivers/led_strip.h>
#include <drivers/spi.h>

#endif

#include "soc_flash.h"
Expand Down Expand Up @@ -99,9 +98,14 @@ void io_Thread()
digitalWrite(IO_LED, led_is_on);
}
#endif
// Unrecoverable error, Solid Red
if(_ledmode & LED_HARDFAULT) {
led_sequence[0].RGB = RGB_RED;
led_sequence[0].time = 10;
led_sequence[1].time = 0;

// Force BT head configuration mode !Must be priority 1
if (_ledmode & LED_BTCONFIGURATOR) {
// Force BT head configuration mode
} else if (_ledmode & LED_BTCONFIGURATOR) {
led_sequence[0].RGB = RGB_RED;
led_sequence[0].time = 300;
led_sequence[1].RGB = RGB_GREEN;
Expand Down Expand Up @@ -157,7 +161,7 @@ void io_Thread()

// Run the Sequence
uint32_t curcolor = led_sequence[rgb_sequence_no].RGB;
if (led_sequence[rgb_sequence_no].time == 0) curcolor = 0;
if (led_sequence[rgb_sequence_no].time == 0) curcolor = led_sequence[rgb_sequence_no-1].RGB;

#if defined(HAS_3DIODE_RGB)
// TODO - Replace me with PWM control
Expand Down Expand Up @@ -247,6 +251,20 @@ void io_init()
digitalWrite(IO_I2C_PU, 1);
#endif

#if defined(PCB_XIAOSENSE)
// 10K I2C Pull up Resistors on internal LSM6DS3, High Drive Strength
pinMode(IO_LSM6DS3PWR, GPIO_OUTPUT | GPIO_DS_ALT_LOW | GPIO_DS_ALT_HIGH);
// Shut Sensor off
digitalWrite(IO_LSM6DS3PWR, 0);
k_msleep(100);
// Enable Sensor
digitalWrite(IO_LSM6DS3PWR, 1);

// Enable Battery Voltage Monitor
pinMode(IO_ANBATT_ENA, GPIO_OUTPUT);
digitalWrite(IO_ANBATT_ENA, 0);
#endif

#if defined(HAS_CENTERBTN)
pinMode(IO_CENTER_BTN, INPUT_PULLUP);
#endif
Expand Down
1 change: 1 addition & 0 deletions firmware/src/src/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern volatile uint32_t _ledmode;
#define LED_BTSCANNING (1 << 3)
#define LED_MAGCAL (1 << 4)
#define LED_BTCONFIGURATOR (1 << 5)
#define LED_HARDFAULT (1 << 6)

#define RGB_OFF 0
#define RGB_RED (0xFF << 16)
Expand Down
3 changes: 2 additions & 1 deletion firmware/src/src/nano33ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void start(void)
serial_init();

// Actual Calculations - sense.cpp
sense_Init();
if(sense_Init())
setLEDFlag(LED_HARDFAULT);

// Start Externam UART
uart_init();
Expand Down
Loading

0 comments on commit f5cdad9

Please sign in to comment.