From d587e8940968012df129506cd676192523ae2b37 Mon Sep 17 00:00:00 2001 From: Wyatt_Zhang <46043032+Huckies@users.noreply.github.com> Date: Tue, 14 Feb 2023 17:18:51 +0800 Subject: [PATCH 1/2] added soft reset and auto lowpower for AW20216 --- drivers/led/aw20216.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/led/aw20216.c b/drivers/led/aw20216.c index cbb0b60774c8..c4b591a24dbe 100644 --- a/drivers/led/aw20216.c +++ b/drivers/led/aw20216.c @@ -15,6 +15,7 @@ */ #include "aw20216.h" +#include "wait.h" #include "spi_master.h" /* The AW20216 appears to be somewhat similar to the IS31FL743, although quite @@ -34,6 +35,8 @@ #define AW_REG_CONFIGURATION 0x00 // PG0 #define AW_REG_GLOBALCURRENT 0x01 // PG0 +#define AW_REG_RESET 0x2F // PG0 +#define AW_REG_MIXFUNCTION 0x46 // PG0 // Default value of AW_REG_CONFIGURATION // D7:D4 = 1011, SWSEL (SW1~SW12 active) @@ -41,7 +44,10 @@ // D2:D1 = 00, OSDE (open/short detection enable) // D0 = 0, CHIPEN (write 1 to enable LEDs when hardware enable pulled high) #define AW_CONFIG_DEFAULT 0b10110000 +#define AW_MIXCR_DEFAULT 0b00000000 +#define AW_RESET_CMD 0xAE #define AW_CHIPEN 1 +#define AW_LPEN (0x01 << 1) #define AW_PWM_REGISTER_COUNT 216 @@ -94,6 +100,10 @@ static inline bool AW20216_write_register(pin_t cs_pin, uint8_t page, uint8_t re return AW20216_write(cs_pin, page, reg, &value, 1); } +void AW20216_soft_reset(pin_t cs_pin) { + AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_RESET, AW_RESET_CMD); +} + static void AW20216_init_scaling(pin_t cs_pin) { // Set constant current to the max, control brightness with PWM for (uint8_t i = 0; i < AW_PWM_REGISTER_COUNT; i++) { @@ -111,15 +121,23 @@ static inline void AW20216_soft_enable(pin_t cs_pin) { AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN); } +static inline void AW20216_auto_lowpower(pin_t cs_pin) { + AW20216_write_register(cs_pin, AW_PAGE_FUNCTION, AW_REG_MIXFUNCTION, AW_MIXCR_DEFAULT | AW_LPEN); +} + void AW20216_init(pin_t cs_pin, pin_t en_pin) { setPinOutput(en_pin); writePinHigh(en_pin); + AW20216_soft_reset(cs_pin); + wait_ms(2); + // Drivers should start with all scaling and PWM registers as off AW20216_init_current_limit(cs_pin); AW20216_init_scaling(cs_pin); AW20216_soft_enable(cs_pin); + AW20216_auto_lowpower(cs_pin); } void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { From 4caeb69869a9a7ff252402a3a60f648b31120061 Mon Sep 17 00:00:00 2001 From: Huckies <46043032+Huckies@users.noreply.github.com> Date: Tue, 14 Feb 2023 23:56:54 +0800 Subject: [PATCH 2/2] Update aw20216.c --- drivers/led/aw20216.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/led/aw20216.c b/drivers/led/aw20216.c index c4b591a24dbe..7895f1497b0f 100644 --- a/drivers/led/aw20216.c +++ b/drivers/led/aw20216.c @@ -1,4 +1,5 @@ /* Copyright 2021 Jasper Chan + * 2023 Huckies * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by