@@ -20,7 +20,8 @@ namespace espp {
2020 */
2121class Lp5817 : public BasePeripheral <> {
2222public:
23- static constexpr uint8_t DEFAULT_ADDRESS = 0x2D ; // 7-bit address
23+ static constexpr uint8_t DEFAULT_ADDRESS = 0x2D ; // 7-bit address
24+ static constexpr uint8_t BROADCAST_ADDRESS = 0x34 ; // 7-bit address
2425
2526 // / LED channels
2627 enum class Channel : uint8_t { OUT0 = 0 , OUT1 = 1 , OUT2 = 2 };
@@ -94,16 +95,10 @@ class Lp5817 : public BasePeripheral<> {
9495 */
9596 bool enable (bool on, std::error_code &ec) {
9697 std::lock_guard<std::recursive_mutex> lock (base_mutex_);
97- logger_.info (" Turning device {}" , on ? " ON " : " OFF " );
98+ logger_.info (" Setting enable to {}" , on);
9899 // set the chip_en bit
99100 set_bits_in_register_by_mask ((uint8_t )Registers::CHIP_EN, CHIP_EN_MASK,
100101 on ? CHIP_EN_MASK : 0x00 , ec);
101- // then clear the POR flag if enabling
102- if (on && !ec) {
103- if (!clear_por_flag (ec)) {
104- logger_.error (" Failed to clear POR flag: {}" , ec.message ());
105- }
106- }
107102 return !ec;
108103 }
109104
@@ -356,6 +351,79 @@ class Lp5817 : public BasePeripheral<> {
356351 return !ec;
357352 }
358353
354+ /* *
355+ * @brief Check if device is enabled.
356+ * @param ec Error code set on failure.
357+ * @return true if device is enabled, false otherwise.
358+ */
359+ bool is_enabled (std::error_code &ec) {
360+ auto reg = read_u8_from_register ((uint8_t )Registers::CHIP_EN, ec);
361+ if (ec)
362+ return false ;
363+ return (reg & CHIP_EN_MASK) != 0 ;
364+ }
365+
366+ /* *
367+ * @brief Check if output stage is enabled for a channel.
368+ * @param ch Channel to check.
369+ * @param ec Error code set on failure.
370+ * @return true if output stage is enabled, false otherwise.
371+ */
372+ bool is_channel_enabled (Channel ch, std::error_code &ec) {
373+ auto reg = read_u8_from_register ((uint8_t )Registers::DEV_CONFIG1, ec);
374+ if (ec)
375+ return false ;
376+ uint8_t bit = 1 << (uint8_t )ch; // bits 0..2
377+ return (reg & bit) != 0 ;
378+ }
379+
380+ /* *
381+ * @brief Get the current global max current setting.
382+ * @param ec Error code set on failure.
383+ * @return Current global max current setting.
384+ */
385+ GlobalMaxCurrent get_max_current (std::error_code &ec) {
386+ auto reg = read_u8_from_register ((uint8_t )Registers::DEV_CONFIG0, ec);
387+ if (ec)
388+ return GlobalMaxCurrent::MA_25_5; // default
389+ return (reg & MAX_CURRENT_MASK) ? GlobalMaxCurrent::MA_51 : GlobalMaxCurrent::MA_25_5;
390+ }
391+
392+ /* *
393+ * @brief Get the current brightness of a channel.
394+ * @param ch Channel to read.
395+ * @param ec Error code set on failure.
396+ * @return Brightness [0,255].
397+ */
398+ uint8_t get_brightness (Channel ch, std::error_code &ec) {
399+ auto reg = dc_register_for (ch);
400+ return read_u8_from_register (reg, ec);
401+ }
402+
403+ /* *
404+ * @brief Get the current manual PWM value of a channel (manual mode).
405+ * @param ch Channel to read.
406+ * @param ec Error code set on failure.
407+ * @return Manual PWM value [0,255].
408+ */
409+ uint8_t get_manual_pwm (Channel ch, std::error_code &ec) {
410+ auto reg = manual_pwm_register_for (ch);
411+ return read_u8_from_register (reg, ec);
412+ }
413+
414+ /* *
415+ * @brief Get the current global fade time setting.
416+ * @param ec Error code set on failure.
417+ * @return Current fade time setting.
418+ */
419+ bool is_fade_enabled (Channel ch, std::error_code &ec) {
420+ auto reg = read_u8_from_register ((uint8_t )Registers::DEV_CONFIG2, ec);
421+ if (ec)
422+ return false ;
423+ uint8_t bit = 1 << (uint8_t )ch; // bits 0..2
424+ return (reg & bit) != 0 ;
425+ }
426+
359427 /* *
360428 * @brief Read flag register (POR/TSD).
361429 * @param ec Error code set on failure.
@@ -390,6 +458,16 @@ class Lp5817 : public BasePeripheral<> {
390458 return (flags & FLAG_CLR_TSD_MASK) != 0 ;
391459 }
392460
461+ /* *
462+ * @brief Clear both POR (Power-On Reset) and TSD (Thermal Shutdown) flags.
463+ * @param ec Error code set on failure.
464+ * @return true on success, false on failure.
465+ */
466+ bool clear_flags (std::error_code &ec) {
467+ write_u8_to_register ((uint8_t )Registers::FLAG_CLR, FLAG_CLR_POR_MASK | FLAG_CLR_TSD_MASK, ec);
468+ return !ec;
469+ }
470+
393471 /* *
394472 * @brief Clear POR (Power-On Reset) flag.
395473 * @param ec Error code set on failure.
0 commit comments