feat: state path to switch into standalone mode#208
Conversation
Reviewer's GuideThis PR introduces an experimental standalone operating mode triggered by an SD card configuration file, wiring it into the system state machine and SD card mounting logic. Sequence diagram for standalone mode initialization at bootsequenceDiagram
participant main
participant SYSTEM
participant SDCARD
participant FATFS
main->>SYSTEM: SYSTEM_Initialize()
main->>SDCARD: SDCARD_standalone_check()
SDCARD->>SDCARD: SD_SPI_IsMediaPresent()
alt SD card not present
SDCARD-->>main: FAILED
main->>main: current_state = STATE_STANDBY
else SD card present
SDCARD->>FATFS: f_mount(drive, SDCARD_DRIVE, 1)
alt mount failed
SDCARD-->>main: FAILED
main->>main: current_state = STATE_STANDBY
else mount success
SDCARD->>SDCARD: read_config_file()
alt config invalid or missing
SDCARD->>SDCARD: SDCARD_standalone_unmount()
SDCARD-->>main: FAILED
main->>main: current_state = STATE_STANDBY
else config valid
SDCARD-->>main: SUCCESS
main->>main: current_state = STATE_STANDALONE
end
end
end
loop main loop
main->>main: STATES_RunState(current_state)
end
State diagram for updated system states with standalone modestateDiagram-v2
[*] --> STATE_STANDBY
STATE_STANDBY --> STATE_RUNCOMMAND: RunCommand()
STATE_STANDALONE --> STATE_STANDALONE: Standalone() / [!UART_IsRxReady(U1SELECT)]
STATE_STANDALONE --> STATE_RUNCOMMAND: Standalone() / UART_IsRxReady(U1SELECT)
STATE_RUNCOMMAND --> STATE_STANDBY: RunCommand()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Pull request overview
Adds an experimental boot-time path to enter a new standalone state when an SD card with a valid PSLAB.CFG configuration is detected, otherwise continuing into the existing standby/serial-command flow. This extends the firmware state machine and introduces an SD-card config probe intended to support future standalone animation/display behavior.
Changes:
- Introduces a new
STATE_STANDALONEand corresponding state handler that runs until serial RX activity is detected. - Adds an SD-card “standalone config present” check for
PSLAB.CFGduring boot, and uses it to select the initial state. - Adds SD-card mount tracking and an unmount helper for the standalone config check path.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/states.h | Adds STATE_STANDALONE to the state enum. |
| src/states.c | Implements the standalone state and extends the state dispatch table. |
| src/sdcard/sdcard.h | Declares the standalone SD-card config check API (and should also declare unmount if intended public). |
| src/sdcard/sdcard.c | Implements config file probing and (un)mount handling for the standalone check. |
| src/main.c | Chooses initial boot state based on the SD-card standalone config check result. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| response_t SDCARD_standalone_check(void) { | ||
| if (!SD_SPI_IsMediaPresent()) { | ||
| return FAILED; | ||
| } | ||
|
|
||
| FATFS drive; | ||
| if (f_mount(&drive, SDCARD_DRIVE, 1) != FR_OK) { | ||
| return FAILED; | ||
| } | ||
| s_mounted = true; | ||
|
|
||
| if (!read_config_file()) { | ||
| SDCARD_standalone_unmount(); | ||
| return FAILED; | ||
| } | ||
|
|
||
| return SUCCESS; | ||
| } | ||
|
|
||
| void SDCARD_standalone_unmount(void) { | ||
| if (s_mounted) { | ||
| f_mount(0, SDCARD_DRIVE, 0); | ||
| s_mounted = false; | ||
| } | ||
| } |
| state_t Standalone(void) { | ||
| if (UART_IsRxReady(U1SELECT)) { | ||
| return STATE_RUNCOMMAND; | ||
| } | ||
|
|
||
| return STATE_STANDALONE; | ||
| } |
| /** | ||
| * @brief Check if SD-card is present and can be mounted. | ||
| * | ||
| * @details Checks if the SD-card can be mounted and if the configuration file is present and valid. | ||
| * If the configuration file is not present or invalid, or if the SD-card is not mounted, the function returns FAILED. | ||
| * The configuration file is expected to be named "PSLAB.CFG" and contain a magic header of 5 bytes with a null terminator. | ||
| * | ||
| * @return SUCCESS | ||
| */ | ||
| response_t SDCARD_standalone_check(void); |
| state_t Standalone(void) { | ||
| if (UART_IsRxReady(U1SELECT)) { | ||
| return STATE_RUNCOMMAND; | ||
| } | ||
|
|
||
| return STATE_STANDALONE; | ||
| } |
|
|
||
| return SUCCESS; | ||
| } | ||
|
|
| FATFS drive; | ||
| if (f_mount(&drive, SDCARD_DRIVE, 1) != FR_OK) { | ||
| return FAILED; | ||
| } | ||
| s_mounted = true; |
| * If the configuration file is not present or invalid, or if the SD-card is not mounted, the function returns FAILED. | ||
| * The configuration file is expected to be named "PSLAB.CFG" and contain a magic header of 5 bytes with a null terminator. | ||
| * | ||
| * @return SUCCESS | ||
| */ |
| * | ||
| * @return SUCCESS | ||
| */ | ||
| response_t SDCARD_standalone_check(void); |
| * If the configuration file is not present or invalid, or if the SD-card is not mounted, the function returns FAILED. | ||
| * The configuration file is expected to be named "PSLAB.CFG" and contain a magic header of 5 bytes with a null terminator. | ||
| * | ||
| * @return SUCCESS | ||
| */ |
| /** | ||
| * @brief Read the configuration file from the SD card. | ||
| * @return true if the config file was read successfully, false otherwise or if the config structure is invalid. | ||
| */ |
Important
This is baby steps towards #46 and a purely experimental WIP pull request
When the PSLab boots, it will check for the presence of an SD card with a valid configuration file named
PSLAB.CFG. If there is such a combination, PSLab will switch to astandalonemode; until serial traffic begins to appear.If there is no such combination, then the device goes into stand by mode as usual.
Currently, the plan is to read from the SD card a set of bitmap images (or pre-conditioned image data) to display on an I2C OLED display as an animation. I expect the SD card to contain all the necessary parameters such as animation delay, duration, cycles etc to make the animation rendering possible.
Summary by Sourcery
Introduce a standalone operational state that is activated on boot when a valid SD card configuration file is present, otherwise falling back to standby.
New Features:
Enhancements: