Skip to content
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

Feature/aw9523 update #111

Merged
merged 5 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/aw9523/example/main/aw9523_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");

Expand Down
36 changes: 33 additions & 3 deletions components/aw9523/include/aw9523.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,19 @@ 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)
: 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_);
}

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -450,6 +479,7 @@ class Aw9523 {
write_(address_, data, total_len);
}

Config config_;
uint8_t address_;
write_fn write_;
read_fn read_;
Expand Down
Loading