Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
fcd2e82
Update device tree overlay and driver enable functions for stepper co…
andre-stefanov Nov 22, 2025
4d26f3e
Update workflow triggers to only run on main branch for push events
andre-stefanov Nov 22, 2025
1093619
Update device tree overlay for stepper control and adjust project con…
andre-stefanov Nov 22, 2025
1c47763
Update device tree overlays and configurations for stepper control an…
andre-stefanov Nov 24, 2025
2045d45
Refactor thread management and update device configuration structure …
andre-stefanov Nov 27, 2025
815cc02
Merge branch 'main' into feature/stepper-overlay-update
andre-stefanov Nov 27, 2025
bbdade6
Refactor focuser initialization to include firmware version and remov…
andre-stefanov Nov 28, 2025
ab9ea2a
Add setup action for Zephyr project and update build workflow to use it
andre-stefanov Nov 29, 2025
d7ce4b1
Fix setup action path for Zephyr project in build workflow
andre-stefanov Nov 29, 2025
b4c04b1
Remove unnecessary path specification in checkout step of build workflow
andre-stefanov Nov 29, 2025
cc324b6
Update build workflow to use correct paths for Zephyr project and fir…
andre-stefanov Nov 29, 2025
07adbca
Fix toolchain specification format in Zephyr setup action
andre-stefanov Nov 29, 2025
6efce72
Update build workflow to use official Zephyr setup action and restric…
andre-stefanov Dec 18, 2025
feb2342
Update app/boards/esp32s3_devkitc_procpu.overlay
andre-stefanov Dec 18, 2025
d7dca8d
Update tests/app/focuser/boards/qemu_cortex_m0.overlay
andre-stefanov Dec 18, 2025
9c57d34
Update app/boards/esp32s3_devkitc_procpu.overlay
andre-stefanov Dec 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ on:
permissions:
contents: read

env:
ZEPHYR_SDK_VERSION: 0.17.4
ZEPHYR_TOOLCHAINS: |
arm-zephyr-eabi
xtensa-espressif_esp32s3_zephyr-elf

jobs:
build:
name: Build app and tests
Expand All @@ -25,9 +31,10 @@ jobs:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: 3.12
cache: "pip"

- name: Install system dependencies
shell: bash
Expand All @@ -47,21 +54,34 @@ jobs:
fi

- name: Install west
shell: bash
run: |
pip install west

- name: Initialize Zephyr workspace
shell: bash
run: |
west init -l OpenAstroFocuser
west update

- name: Install pip dependencies
shell: bash
run: |
west packages pip --install --ignore-venv-check || pip3 install -r zephyr/scripts/requirements.txt

- name: Zephyr SDK cache
id: cache
uses: actions/cache@v5
with:
path: ~/zephyr-sdk-${{ env.ZEPHYR_SDK_VERSION }}
key: zephyr-sdk-${{ env.ZEPHYR_SDK_VERSION }}-${{ matrix.os }}

- name: Install Zephyr SDK
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
west sdk install -t arm-zephyr-eabi xtensa-espressif_esp32s3_zephyr-elf
TOOLCHAINS="$(echo "${{ env.ZEPHYR_TOOLCHAINS }}" | xargs)"
west sdk install --version ${{ env.ZEPHYR_SDK_VERSION }} -t ${TOOLCHAINS}

- name: Build firmware
working-directory: OpenAstroFocuser
Expand Down
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ target_sources(app PRIVATE
src/FocuserThread.cpp
src/UartHandler.cpp
src/UartThread.cpp
src/Thread.cpp
src/ZephyrStepper.cpp)
12 changes: 0 additions & 12 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ endmenu

menu "OpenAstroFocuser options"

config FOCUSER_THREAD_STACK_SIZE
int "Focuser thread stack size"
default 2048
help
Stack allocation used by the focuser control thread.

config SERIAL_THREAD_STACK_SIZE
int "Serial thread stack size"
default 2048
help
Stack allocation used by the Moonlite UART handler thread.

endmenu

module = APP
Expand Down
39 changes: 27 additions & 12 deletions app/boards/esp32s3_devkitc_procpu.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
*/

/* Devicetree overlay enabling the Moonlite focuser firmware on ESP32-S3 DevKitC
* (PROCPU). The zephyr,gpio-step-dir-controller drives the step/dir pins
* referenced by the "stepper" alias, while the dedicated TMC2209 device is
* referenced by the "stepper-drv" alias so the application can toggle the
* external driver rails. The zephyr,user node supplies the UART phandle
* consumed by the application.
* (PROCPU). Device configuration is performed using chosen nodes:
* - focuser,uart: selects the UART device for the focuser console
* - focuser,stepper: selects the step/dir controller for the stepper motor
* - focuser,stepper-drv: selects the TMC2209 stepper driver device
* These chosen nodes are used by the application to access the appropriate hardware.
*/

/ {
aliases {
stepper = &focuser_stepper;
stepper-drv = &focuser_stepper_drv;
chosen {
zephyr,console = &uart1;
zephyr,log-uart = &focuser_log_uarts;
focuser,uart = &uart0;
focuser,stepper = &focuser_stepper;
focuser,stepper-drv = &focuser_stepper_drv;
};

focuser_log_uarts: focuser_log_uarts {
compatible = "zephyr,log-uart";
uarts = <&uart1>;
};

focuser_stepper_drv: focuser_stepper_drv {
Expand All @@ -31,23 +39,30 @@
step-width-ns = <10000>;
status = "okay";
};

zephyr,user {
uart_handler = <&uart1>;
};
};

/**
* Moonlite focuser console UART configuration
*/
&uart0 {
current-speed = <9600>;
status = "okay";
};

/**
* Moonlite focuser control UART configuration.
* Used for logging and console output.
*/
&uart1 {
status = "okay";
current-speed = <9600>;
pinctrl-0 = <&moonlite_uart1_default>;
pinctrl-names = "default";
};

/**
* Pin control settings
*/
&pinctrl {
moonlite_uart1_default: moonlite_uart1_default {
group1 {
Expand Down
12 changes: 6 additions & 6 deletions app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ CONFIG_MOONLITE=y
# Provide heap storage for std::string and other dynamic allocations.
CONFIG_HEAP_MEM_POOL_SIZE=4096

# Route logs and console I/O over UART for the focuser serial protocol.
# Enable Serial/UART driver
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y

# Enable Console (printk)
CONFIG_CONSOLE=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_PRINTK=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_INTERRUPT_DRIVEN=y

# Enable Logging (LOG_INF, LOG_ERR)
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_LOG_BACKEND_UART=y

# Set the application log level.
CONFIG_APP_LOG_LEVEL_INF=y
Expand Down
76 changes: 30 additions & 46 deletions app/src/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,47 @@

#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>

#include <app_version.h>

#include <cstddef>

#define FOCUSER_NODE DT_PATH(zephyr_user)
#define STEPPER_ALIAS DT_ALIAS(stepper)
#define STEPPER_DRV_ALIAS DT_ALIAS(stepper_drv)
namespace config
{
constexpr const char version[] = STRINGIFY(APP_VERSION_MAJOR) STRINGIFY(APP_VERSION_MINOR);

#if !DT_NODE_EXISTS(FOCUSER_NODE)
#error "zephyr,user node must provide focuser pin assignments"
#endif
namespace devices
{

#if !DT_NODE_HAS_PROP(FOCUSER_NODE, uart_handler)
#error "zephyr,user node requires uart_handler phandle"
#if !DT_HAS_CHOSEN(focuser_uart)
#error "UART device is required for Moonlite serial protocol"
#else
constexpr auto uart = DEVICE_DT_GET(DT_CHOSEN(focuser_uart));
#endif

#if !DT_NODE_HAS_STATUS(STEPPER_ALIAS, okay)
#error "stepper alias must reference an enabled stepper controller"
#if !DT_HAS_CHOSEN(focuser_stepper)
#error "Stepper device is required for Moonlite serial protocol"
#else
constexpr auto stepper = DEVICE_DT_GET(DT_CHOSEN(focuser_stepper));
#endif

#if !DT_NODE_HAS_STATUS(STEPPER_DRV_ALIAS, okay)
#error "stepper-drv alias must reference an enabled stepper driver"
#if !DT_HAS_CHOSEN(focuser_stepper_drv)
#error "Stepper driver device is required for Moonlite serial protocol"
#else
constexpr auto stepper_drv = DEVICE_DT_GET(DT_CHOSEN(focuser_stepper_drv));
#endif

#if !DT_HAS_CHOSEN(zephyr_console)
#error "Console device is required for Moonlite serial protocol"
#endif

namespace config
{

struct ThreadConfig
{
std::size_t stack_size;
int priority;
};

inline constexpr ThreadConfig kFocuserThread{CONFIG_FOCUSER_THREAD_STACK_SIZE, K_PRIO_PREEMPT(4)};
inline constexpr ThreadConfig kSerialThread{CONFIG_SERIAL_THREAD_STACK_SIZE, K_PRIO_PREEMPT(5)};
} // namespace devices

inline const struct device *console_device()
{
return DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
}

inline const struct device *uart_handler_device()
{
return DEVICE_DT_GET(DT_PHANDLE(FOCUSER_NODE, uart_handler));
}

inline const struct device *stepper_device()
{
return DEVICE_DT_GET(STEPPER_ALIAS);
}

inline const struct device *stepper_driver_device()
{
return DEVICE_DT_GET(STEPPER_DRV_ALIAS);
}
namespace threads
{
constexpr auto focuser_priority = K_PRIO_PREEMPT(4);
constexpr auto focuser_stack_size = K_THREAD_STACK_LEN(2048);
inline k_thread_stack_t focuser_stack[focuser_stack_size];

constexpr auto serial_priority = K_PRIO_PREEMPT(5);
constexpr auto serial_stack_size = K_THREAD_STACK_LEN(2048);
inline k_thread_stack_t serial_stack[serial_stack_size];
} // namespace threads
} // namespace config
13 changes: 4 additions & 9 deletions app/src/Focuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

#include <zephyr/logging/log.h>

#include <app_version.h>

#include <errno.h>

LOG_MODULE_DECLARE(focuser, CONFIG_APP_LOG_LEVEL);

namespace
{

constexpr const char kFirmwareVersion[] = STRINGIFY(APP_VERSION_MAJOR) STRINGIFY(APP_VERSION_MINOR);

uint32_t compute_step_period_us(uint8_t multiplier)
{
uint32_t m = (multiplier == 0U) ? 1U : static_cast<uint32_t>(multiplier);
Expand All @@ -27,8 +22,8 @@ namespace

} // namespace

Focuser::Focuser(FocuserStepper &stepper)
: m_stepper(stepper)
Focuser::Focuser(FocuserStepper &stepper, const char *firmware_version)
: m_firmware_version(firmware_version), m_stepper(stepper)
{
(void)set_stepper_driver_enabled(true);
}
Expand Down Expand Up @@ -242,8 +237,8 @@ bool Focuser::isMoving()
std::string Focuser::getFirmwareVersion()
{
LOG_DBG("getFirmwareVersion()");
LOG_DBG("getFirmwareVersion -> %s", kFirmwareVersion);
return std::string(kFirmwareVersion);
LOG_DBG("getFirmwareVersion -> %s", m_firmware_version);
return std::string(m_firmware_version);
}

uint8_t Focuser::getSpeed()
Expand Down
4 changes: 3 additions & 1 deletion app/src/Focuser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Focuser final : public moonlite::Handler
{
public:
explicit Focuser(FocuserStepper &stepper);
explicit Focuser(FocuserStepper &stepper, const char *firmware_version);

int initialise();
void loop();
Expand Down Expand Up @@ -71,6 +71,8 @@ class Focuser final : public moonlite::Handler
int32_t read_actual_position();
int set_stepper_driver_enabled(bool enable);

const char *m_firmware_version;

FocuserState m_state{};
FocuserStepper &m_stepper;
};
21 changes: 7 additions & 14 deletions app/src/FocuserThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@

#include <zephyr/logging/log.h>

#include "Configuration.hpp"
#include "Focuser.hpp"

LOG_MODULE_DECLARE(focuser);

FocuserThread::FocuserThread(Focuser &focuser)
: m_focuser(focuser)
: Thread(config::threads::focuser_stack,
K_THREAD_STACK_SIZEOF(config::threads::focuser_stack),
config::threads::focuser_priority, "focuser"),
m_focuser(focuser)
{
}

void FocuserThread::start()
{
k_thread_create(&m_thread, m_stack, K_THREAD_STACK_SIZEOF(m_stack),
thread_entry, this, nullptr, nullptr, config::kFocuserThread.priority,
0, K_NO_WAIT);
k_thread_name_set(&m_thread, "focuser");
}

void FocuserThread::thread_entry(void *arg1, void *, void *)
{
auto *self = static_cast<FocuserThread *>(arg1);
if (self == nullptr)
if (!start_thread())
{
return;
LOG_ERR("Failed to start focuser thread");
}

self->run();
}

void FocuserThread::run()
Expand Down
13 changes: 3 additions & 10 deletions app/src/FocuserThread.hpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
#pragma once

#include <zephyr/kernel.h>

#include <cstddef>

#include "Configuration.hpp"
#include "Thread.hpp"

class Focuser;

class FocuserThread {
class FocuserThread : public Thread {
public:
explicit FocuserThread(Focuser &focuser);

void start();

private:
static void thread_entry(void *, void *, void *);
void run();
void run() override;

Focuser &m_focuser;
k_thread_stack_t m_stack[K_THREAD_STACK_LEN(config::kFocuserThread.stack_size)];
struct k_thread m_thread;
};
Loading
Loading