From dd0a34422656395a7aed3d06e2ef8088b4f9c560 Mon Sep 17 00:00:00 2001 From: SamAtBackbone Date: Tue, 26 Sep 2023 09:17:32 -0700 Subject: [PATCH 1/3] Update aw9523.hpp -Separate constructor from initialization. This way the object can be used before the hardware can be initialized. The object can also be reinitialized later if necessary. -Add 'get_output' methods. Allows a read of the set output value. --- components/aw9523/include/aw9523.hpp | 34 ++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/components/aw9523/include/aw9523.hpp b/components/aw9523/include/aw9523.hpp index ee7eaa93a..b6b26ef1b 100644 --- a/components/aw9523/include/aw9523.hpp +++ b/components/aw9523/include/aw9523.hpp @@ -84,9 +84,15 @@ class Aw9523 { * @param config Config structure for configuring the AW9523 */ Aw9523(const Config &config) - : address_(config.device_address), write_(config.write), read_(config.read), + : config_(config), address_(config.device_address), write_(config.write), read_(config.read), logger_({.tag = "Aw9523", .level = config.log_level}) { - init(config); + } + + /** + * @brief Initialize the component class. + */ + void initialize(void) { + init(config_); } /** @@ -213,6 +219,27 @@ class Aw9523 { set_pins(Port::PORT1, mask >> 8); } + /** + * @brief Read the output pin values on the provided port. + * @param port The Port for which to read the pins + * @return The pin values as an 8 bit mask. + */ + uint8_t get_output(Port port) { + auto addr = port == Port::PORT0 ? Registers::OUTPORT0 : Registers::OUTPORT1; + return read_one_((uint8_t)addr); + } + + /** + * @brief Read the output pin values on both Port 0 and Port 1. + * @return The pin values as a 16 bit mask (P0_0 lsb, P1_7 msb). + */ + uint16_t get_output() { + return (read_one_((uint8_t)Registers::OUTPORT1) << 8) | read_one_((uint8_t)Registers::OUTPORT0); + // TODO: this should work as well, but doesn't seem to (only the first + // byte read seems to be correct...) + // return read_two_((uint8_t)Registers::OUTPORT0); + } + /** * @brief Configure the provided pins to interrupt on change. * @param port The port associated with the provided pin mask. @@ -420,6 +447,8 @@ class Aw9523 { ///< b00=imax, default=b00) }; + + void init(const Config &config) { configure_global_control(config.output_drive_mode_p0, config.max_led_current); set_direction(Port::PORT0, config.port_0_direction_mask); @@ -450,6 +479,7 @@ class Aw9523 { write_(address_, data, total_len); } + Config config_; uint8_t address_; write_fn write_; read_fn read_; From dd2e8daed76144f1faca3aa560c0374476a35119 Mon Sep 17 00:00:00 2001 From: SamAtBackbone Date: Tue, 26 Sep 2023 09:20:29 -0700 Subject: [PATCH 2/3] Update aw9523_example.cpp Update the example with the new initialization method --- components/aw9523/example/main/aw9523_example.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/aw9523/example/main/aw9523_example.cpp b/components/aw9523/example/main/aw9523_example.cpp index 317b06ec7..9fb11e8ca 100644 --- a/components/aw9523/example/main/aw9523_example.cpp +++ b/components/aw9523/example/main/aw9523_example.cpp @@ -15,7 +15,7 @@ static constexpr auto I2C_FREQ_HZ = (400 * 1000); static constexpr auto I2C_TIMEOUT_MS = 10; extern "C" void app_main(void) { - { + fmt::print("Starting aw9523 example, controls:\n" "\tP0_0 -> increase P1_5 brightness\n" "\tP0_1 -> increase P1_6 brightness\n" @@ -68,6 +68,7 @@ extern "C" void app_main(void) { .write = aw9523_write, .read = aw9523_read, .log_level = espp::Logger::Verbosity::WARN}); + aw9523.initialize(); //Initialized separately from the constructor. // set P1_5, P1_6, and P1_7 to be leds int r_led = (1 << 13); int g_led = (1 << 14); @@ -140,7 +141,7 @@ extern "C" void app_main(void) { } // now clean up the i2c driver i2c_driver_delete(I2C_NUM); - } + fmt::print("Aw9523 example complete!\n"); From 65a66d3bdeeb97e576ea3cb0febed9ca5f6fdacb Mon Sep 17 00:00:00 2001 From: SamAtBackbone Date: Tue, 26 Sep 2023 09:22:06 -0700 Subject: [PATCH 3/3] Update aw9523.hpp Update comments --- components/aw9523/include/aw9523.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/aw9523/include/aw9523.hpp b/components/aw9523/include/aw9523.hpp index b6b26ef1b..dadd1164f 100644 --- a/components/aw9523/include/aw9523.hpp +++ b/components/aw9523/include/aw9523.hpp @@ -80,7 +80,7 @@ class Aw9523 { }; /** - * @brief Construct the Aw9523 and configure it. + * @brief Construct the Aw9523. Initialization called separately. * @param config Config structure for configuring the AW9523 */ Aw9523(const Config &config)