Skip to content

GPIO: don't turn off on boot#84

Open
xarantolus wants to merge 2 commits into
mainfrom
fix/gpio-default-state
Open

GPIO: don't turn off on boot#84
xarantolus wants to merge 2 commits into
mainfrom
fix/gpio-default-state

Conversation

@xarantolus
Copy link
Copy Markdown
Contributor

Before this, #82 turned off the LED on boot. Now it takes the default-state value:

leds: leds {
  compatible = "gpio-leds";
  
  green_led_0: led_0 {
	  gpios = <&gpioc 7 GPIO_ACTIVE_HIGH>;
	  label = "User LD1";
	  default-state = "on";
  };
}

Copilot AI review requested due to automatic review settings May 13, 2026 20:38
@xarantolus xarantolus requested a review from thomasw04 May 13, 2026 20:39
Copy link
Copy Markdown
Member

@thomasw04 thomasw04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the gpio-leds pipeline (device-tree codegen → HAL registry → kernel LED driver init) so LEDs no longer get forced off during boot, and instead honor the DTS default-state property (e.g., "on").

Changes:

  • Extend dtgen gpio-leds codegen to parse default-state and emit it in LedRegistryEntry.
  • Add a LedDefaultState enum to the generated device-tree API and the host/test stub API.
  • Update the kernel LED driver to set the initial output level based on default-state (including a best-effort keep behavior).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
xtasks/crates/dtgen/src/codegen/led.rs Parse default-state from DT and emit LedDefaultState + default_state in the registry entries.
src/drivers/led.rs Initialize GPIO output level according to the generated default_state value and log it.
machine/cortex-m/src/stub/device_tree.rs Mirror the new LedDefaultState/default_state API in the stub device tree for host/test builds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/drivers/led.rs Outdated
Comment on lines +101 to +106
// Pre-MODER level from DT `default-state`; `Keep` is only
// meaningful on warm restart (cold reset reads 0 from analog).
let initial = match entry.default_state {
LedDefaultState::Off => level_for(entry, false),
LedDefaultState::On => level_for(entry, true),
LedDefaultState::Keep => hal::gpio::read(pin_of(entry)).unwrap_or(Level::Low),
pub enum LedDefaultState {
Off,
On,
/// Preserve current ODR (warm restart); cold boot reads analog → 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants