Skip to content

Commit 2b8b5d1

Browse files
docs: update copilot instructions for Zephyr RTOS v4.2.0 and enhance clarity on development workflow
1 parent 7837a35 commit 2b8b5d1

File tree

1 file changed

+113
-60
lines changed

1 file changed

+113
-60
lines changed

.github/copilot-instructions.md

Lines changed: 113 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,109 @@
11
````instructions
22
# OpenAstroFirmware AI Agent Instructions
33
4-
This is firmware for DIY astronomical telescope mounts, built on Zephyr RTOS. It's a modern C++20 rewrite of the successful OpenAstroTracker v1 firmware, emphasizing maintainability and advanced features.
4+
This is firmware for DIY astronomical telescope mounts, built on Zephyr RTOS v4.2.0. It's a modern C++20 rewrite of the successful OpenAstroTracker v1 firmware, emphasizing maintainability and advanced features.
55
66
## Architecture Overview
77
8-
**Build System**: Zephyr RTOS v4.1.0 with west build tool
9-
**Target Hardware**: MKS Robin Nano (STM32F407-based) boards
10-
**Languages**: C++20 primary, with C for low-level protocol implementations
11-
**Structure**: Dual-app architecture - `app/` (main firmware) + `lib/` (reusable components)
8+
**Build System**: Zephyr RTOS v4.2.0 with west workspace management
9+
**Target Hardware**: MKS Robin Nano (STM32F407-based) boards + native simulation
10+
**Languages**: C++20 application layer, C protocol/driver layer
11+
**Module Structure**: Zephyr module with reusable components (`zephyr/module.yml`)
1212
13-
Key directories:
13+
### Key Directories
1414
- `app/` - Main Zephyr application with mount control logic
1515
- `lib/lx200/` - LX200 telescope protocol implementation (C)
16-
- `boards/mks/robin_nano/` - Custom board definition and device tree
16+
- `boards/mks/robin_nano/` - Custom board definition and device tree
17+
- `drivers/` - Stepper motor and hardware drivers
1718
- `tests/` - Comprehensive test suites using Zephyr Twister
18-
- `zephyr/module.yml` - Zephyr module configuration
19+
- `include/` - Public headers (e.g., `include/lx200/lx200.h`)
1920
2021
## Development Workflow
2122
23+
### West Workspace Setup (Required)
24+
This project uses west workspace management. Must be initialized properly:
25+
```bash
26+
# Initialize workspace (REQUIRED for first setup)
27+
west init -m https://github.com/OpenAstroTech/OpenAstroFirmware --mr main .
28+
west update # Downloads Zephyr v4.2.0 + STM32 HAL modules
29+
```
30+
2231
### Building & Testing
2332
```bash
24-
west build -b robin_nano # Standard build
33+
# From app/ directory
34+
west build -b robin_nano # Production build
35+
west build -b native_sim # Development/simulation
2536
west build -b robin_nano -- -DEXTRA_CONF_FILE=debug.conf # Debug build
26-
west twister -T . -p robin_nano # Run all tests
27-
west twister -T tests/lib/lx200/ # Run specific test suite
37+
west build -t pristine # Clean build
38+
39+
# Testing
40+
west twister -T . -p robin_nano # All tests on hardware
41+
west twister -T tests/lib/lx200/ # Specific test suite
42+
west twister -T . -p native_sim # Simulation tests
2843
```
2944
30-
### Configuration Layers
45+
### Configuration System
3146
- **Kconfig**: `prj.conf` (base) + `debug.conf` (debug overlay)
3247
- **Device Tree**: Custom STM32F407 board in `boards/mks/robin_nano/`
33-
- **Build Configs**: Use `-DEXTRA_CONF_FILE=debug.conf` for development
48+
- **Board Configs**: `app/boards/native_sim.conf` for simulation
49+
- **Interactive**: `west build -t menuconfig` / `west build -t guiconfig`
3450
3551
## Code Patterns & Conventions
3652
37-
### Language Split Pattern
53+
### Language Separation Pattern
3854
**C++20 Application Layer** (`app/src/`):
3955
```cpp
4056
#include <mount/Mount.hpp>
4157
Mount mount; // Main astronomical mount controller
58+
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL); // Structured logging
4259
```
4360
44-
**C Protocol Layer** (`lib/lx200/`):
61+
**C Protocol/Driver Layer** (`lib/lx200/`, `drivers/`):
4562
```c
63+
#include <lx200/lx200.h>
4664
lx200_parser_state_t parser_state;
47-
lx200_parse_command_string(cmd_string, &command);
65+
LOG_MODULE_REGISTER(lx200, CONFIG_LX200_LOG_LEVEL); // Module logging
4866
```
4967
50-
### Logging Infrastructure
51-
Every module uses Zephyr structured logging:
52-
```cpp
53-
LOG_MODULE_REGISTER(ModuleName, CONFIG_APP_LOG_LEVEL);
54-
// Available: LOG_DBG(), LOG_INF(), LOG_WRN(), LOG_ERR()
55-
```
56-
57-
### LX200 Protocol Implementation
58-
Commands follow `:COMMAND[params]#` format. Current implementation status:
59-
- ✅ **Parser Framework**: Command parsing, family classification
60-
- ⏳ **Coordinate Functions**: All `lx200_parse_*_coordinate()` are stubs
61-
- ⏳ **Formatting Functions**: All `lx200_format_*()` are stubs
68+
### Zephyr Module Architecture
69+
Project structure follows Zephyr module conventions:
70+
- `zephyr/module.yml` - Module definition with board_root/dts_root
71+
- `CMakeLists.txt` - Top-level module integration
72+
- `Kconfig` - Module configuration options
73+
- Device tree overlays in `dts/` and board-specific `boards/`
6274
63-
Example of incomplete implementation pattern:
75+
### Stepper Motor Driver Architecture
76+
Multi-layer abstraction for telescope motor control:
6477
```c
65-
lx200_parse_result_t lx200_parse_ra_coordinate(const char *str, lx200_coordinate_t *coord) {
66-
LOG_WRN("Function not implemented yet");
67-
return LX200_PARSE_ERROR; // All coordinate functions are stubs
68-
}
78+
// Zephyr stepper driver API (include/zephyr/drivers/stepper.h)
79+
stepper_move_by(dev, steps);
80+
stepper_set_event_callback(dev, callback, user_data);
81+
82+
// TMC driver implementations (drivers/stepper/adi_tmc/)
83+
// - TMC22xx: GPIO-based (step/dir pins)
84+
// - TMC50xx/51xx: SPI-based with advanced features
85+
```
86+
87+
### Device Tree Patterns
88+
Hardware abstraction through device tree:
89+
```dts
90+
// boards/mks/robin_nano/robin_nano.dts
91+
&spi1 {
92+
tmc_stepper: tmc5072@0 {
93+
compatible = "adi,tmc50xx";
94+
reg = <0>;
95+
// Stepper motor controller configuration
96+
};
97+
};
6998
```
7099
71100
## Testing Strategy
72101
73102
### Test-Driven Development Pattern
74-
Tests serve as specifications for unimplemented features in `tests/lib/lx200/`:
103+
Tests serve as **specifications** for unimplemented features:
75104
76105
**Working Tests** (verify current functionality):
77-
- Parser state management
106+
- Parser state management in `tests/lib/lx200/`
78107
- Command family identification (A,B,C,D,F,G,g,H,I,L,M,P,Q,R,S,T,U)
79108
- Basic command/parameter separation
80109
@@ -83,42 +112,66 @@ Tests serve as specifications for unimplemented features in `tests/lib/lx200/`:
83112
- Time/date parsing (`HH:MM:SS`, `MM/DD/YY`)
84113
- Response formatting functions
85114
86-
Run with: `west twister -T tests/lib/lx200/`
87-
88-
### Configuration Testing
89-
Two build configurations tested via `sample.yaml`:
115+
### Multi-Configuration Testing
116+
`app/sample.yaml` defines test configurations:
90117
- `app.default`: Production configuration
91-
- `app.debug`: Debug configuration with `CONFIG_APP_LOG_LEVEL_DBG=y`
118+
- `app.debug`: Debug with `CONFIG_APP_LOG_LEVEL_DBG=y`
92119
93-
## Project-Specific Context
120+
## LX200 Protocol Implementation
94121
95-
### Astronomical Domain Knowledge
96-
- **Coordinate Systems**: RA/Dec (celestial), Alt/Az (horizontal)
97-
- **Precision Modes**: High (`HH:MM:SS`) vs Low (`HH:MM.T`) coordinate formats
98-
- **LX200 Compatibility**: Industry standard for telescope communication
99-
- **Mount Types**: Equatorial tracking, Alt-azimuth positioning
122+
### Current Implementation Status
123+
Commands follow `:COMMAND[params]#` format with **structured incompleteness**:
124+
- ✅ **Parser Framework**: Command parsing, family classification
125+
- ⏳ **Coordinate Functions**: All `lx200_parse_*_coordinate()` are stubs
126+
- ⏳ **Formatting Functions**: All `lx200_format_*()` return errors
100127
101-
### Critical Implementation Details
102-
**Parameter Detection Logic** (needs improvement):
128+
### Critical Implementation Pattern
129+
All coordinate parsing stubs follow this pattern:
103130
```c
104-
// Current: oversimplified - only checks 'S' commands
131+
lx200_parse_result_t lx200_parse_ra_coordinate(const char *str, lx200_coordinate_t *coord) {
132+
LOG_WRN("Function not implemented yet");
133+
return LX200_PARSE_ERROR; // All coordinate functions are stubs
134+
}
135+
```
136+
137+
### Parameter Detection Issue
138+
Current parameter detection is oversimplified:
139+
```c
140+
// NEEDS EXPANSION - only checks 'S' commands
105141
bool lx200_command_has_parameter(const char *command) {
106142
return (command[0] == 'S'); // Missing many parameter commands
107143
}
108144
```
109145
110-
**Command Parsing Edge Cases**:
111-
- Special commands: `B+`, `B-`, `F+`, `F-`, `T+`, `T-`
112-
- Rate commands: `R0` through `R9`
113-
- Library commands and GPS commands also take parameters
146+
Missing parameter commands include: Rate commands (`R0`-`R9`), Special commands (`B+`, `B-`, `F+`, `F-`, `T+`, `T-`), Library commands, GPS commands.
147+
148+
## Astronomical Domain Context
149+
150+
### Coordinate Systems & Precision
151+
- **RA/Dec**: Celestial coordinates for star tracking
152+
- **Alt/Az**: Horizontal coordinates for mount positioning
153+
- **Precision Modes**: High (`HH:MM:SS`) vs Low (`HH:MM.T`) formats
154+
- **LX200 Compatibility**: Industry standard for ASCOM/INDI/Stellarium
155+
156+
### Hardware Integration
157+
- **Stepper Motors**: RA/Dec axes with TMC drivers for precision
158+
- **STM32F407**: 32-bit performance for real-time tracking calculations
159+
- **Native Simulation**: PC-based development without hardware
160+
161+
## Development Guidelines
162+
163+
**When implementing new LX200 features:**
164+
1. Check corresponding tests in `tests/lib/lx200/` first
165+
2. Follow the established stub → implementation pattern
166+
3. Use C for protocol layer, C++20 for application layer
167+
4. Maintain Zephyr module structure for reusability
114168
115-
### Development Status
116-
Early development phase. Focus on:
117-
1. Implementing coordinate parsing stubs in `lib/lx200/`
118-
2. Following existing test specifications in `tests/lib/lx200/`
119-
3. Using C for protocol layer, C++20 for application layer
120-
4. Maintaining Zephyr module structure for reusability
169+
**When adding hardware support:**
170+
1. Extend device tree in `boards/` or `dts/`
171+
2. Follow Zephyr driver model conventions
172+
3. Test with both hardware and native simulation
173+
4. Update configuration in `Kconfig` files
121174
122-
When implementing new features, always check corresponding tests first to understand expected behavior and formats.
175+
This codebase is in **early development** - expect many stubs that define interfaces but await implementation. Always check tests to understand expected behavior before implementing.
123176
124177
````

0 commit comments

Comments
 (0)