From 4817f6f1bad75afad0c47674109910fa6ea85555 Mon Sep 17 00:00:00 2001 From: ainyan03 Date: Mon, 17 Aug 2026 13:14:32 +0000 Subject: [PATCH] Report M5IOE1 PWM frequency write results Return the underlying I2C write status from setPwmFrequency and document that the configured frequency is shared by every PWM channel. BREAKING: the setPwmFrequency return type changes from void to bool. Ordinary calls that discard the result remain source-compatible, but code that depends on the exact member-function type must update from void (M5IOE1_Class::*)(uint16_t) to bool (M5IOE1_Class::*)(uint16_t). --- src/utility/M5IOE1_Class.cpp | 4 ++-- src/utility/M5IOE1_Class.hpp | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utility/M5IOE1_Class.cpp b/src/utility/M5IOE1_Class.cpp index 591c261..5fb8d9c 100644 --- a/src/utility/M5IOE1_Class.cpp +++ b/src/utility/M5IOE1_Class.cpp @@ -109,10 +109,10 @@ namespace m5 return true; } - void M5IOE1_Class::setPwmFrequency(std::uint16_t frequency) + bool M5IOE1_Class::setPwmFrequency(std::uint16_t frequency) { std::uint8_t data[2] = { static_cast(frequency & 0xFF), static_cast(frequency >> 8) }; - writeRegister(M5IOE1_REG_PWM_FREQ_L, data, sizeof(data)); + return writeRegister(M5IOE1_REG_PWM_FREQ_L, data, sizeof(data)); } bool M5IOE1_Class::setPwmDutyPercent(pwm_channel_t channel, std::uint32_t duty, diff --git a/src/utility/M5IOE1_Class.hpp b/src/utility/M5IOE1_Class.hpp index d073aac..be1568b 100644 --- a/src/utility/M5IOE1_Class.hpp +++ b/src/utility/M5IOE1_Class.hpp @@ -58,7 +58,10 @@ namespace m5 bool digitalRead(uint8_t pin) override; bool getInputLevel(uint8_t pin, bool* level) override; - void setPwmFrequency(std::uint16_t frequency); + /// set the PWM frequency in Hz. + /// @note The frequency is shared by all PWM channels, so changing it also + /// changes a channel that is already running. + bool setPwmFrequency(std::uint16_t frequency); /// set PWM duty in percent. /// @param channel PWM channel (pwm_ch1 - pwm_ch4).