Skip to content

feat(led): Expand LED API some more #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2025
Merged

feat(led): Expand LED API some more #472

merged 1 commit into from
Jul 12, 2025

Conversation

finger563
Copy link
Contributor

Description

  • Allows dynamic frequency control over the LED, making it suitable for driving tones to a buzer

Motivation and Context

Some boards I have have buzzers, and this seems like a reasonable low-level driver for them.

How has this been tested?

Build and run led/example, build as part of a buzzer project which will come later.

Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

@finger563 finger563 requested a review from Copilot July 12, 2025 23:04
@finger563 finger563 self-assigned this Jul 12, 2025
@finger563 finger563 added enhancement New feature or request led buzzer labels Jul 12, 2025
Copy link
Contributor

@Copilot 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

A new feature to expand the LED driver API with dynamic frequency control, returning status and logging errors for PWM operations.

  • Changed set_duty and set_fade_with_time to return a boolean status and log failures.
  • Added get_frequency, set_frequency, and set_pwm methods.
  • Extended header docs and added fmt::formatter specializations for logging.

Reviewed Changes

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

File Description
components/led/src/led.cpp Updated set_duty to return bool, added error checks/logging, introduced get_frequency, set_frequency, set_pwm, and updated set_fade_with_time.
components/led/include/led.hpp Updated function signatures to return bool, added docs for new APIs, and added fmt::formatter specializations.
Comments suppressed due to low confidence (3)

components/led/include/led.hpp:149

  • [nitpick] The name set_pwm may be ambiguous. Consider renaming to something like set_frequency_and_duty to clearly convey that both parameters are configured.
  bool set_pwm(ledc_channel_t channel, size_t frequency_hz, float duty_percent);

components/led/src/led.cpp:147

  • There are no visible unit tests for get_frequency. Consider adding tests for both managed and unmanaged channels to verify correct optional behavior.
std::optional<size_t> Led::get_frequency(ledc_channel_t channel) const {

components/led/src/led.cpp:175

  • New set_pwm functionality should be covered by unit tests for both success and error paths when setting frequency and duty cycle.
bool Led::set_pwm(ledc_channel_t channel, size_t frequency_hz, float duty_percent) {


/**
* @brief Set the frequency of the LEDC channel.
* @note This function will block until until a current fade process
Copy link
Preview

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

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

Typo detected: the phrase 'until until' is duplicated. Consider revising to 'block until a current fade process completes'.

Suggested change
* @note This function will block until until a current fade process
* @note This function will block until a current fade process

Copilot uses AI. Check for mistakes.


/**
* @brief Set the PWM frequency and duty cycle for this channel.
* @note This function will block until until a current fade process
Copy link
Preview

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

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

Typo detected: the phrase 'until until' is duplicated. Consider revising to 'block until a current fade process completes'.

Suggested change
* @note This function will block until until a current fade process
* @note This function will block until a current fade process

Copilot uses AI. Check for mistakes.

@@ -118,36 +118,117 @@ std::optional<float> Led::get_duty(ledc_channel_t channel) const {
return (float)raw_duty / (float)max_raw_duty_ * 100.0f;
}

void Led::set_duty(ledc_channel_t channel, float duty_percent) {
bool Led::set_duty(ledc_channel_t channel, float duty_percent) {
Copy link
Preview

Copilot AI Jul 12, 2025

Choose a reason for hiding this comment

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

The semaphore take/give pattern is repeated across multiple methods. Consider extracting this into a RAII helper or utility function to reduce duplication and potential for mismatched calls.

Copilot uses AI. Check for mistakes.

Copy link

✅Static analysis result - no issues found! ✅

@finger563 finger563 merged commit d5000e7 into main Jul 12, 2025
85 checks passed
@finger563 finger563 deleted the feat/led-update branch July 12, 2025 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buzzer enhancement New feature or request led
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant