summaryrefslogtreecommitdiff
path: root/drivers/led/ckled2001.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/led/ckled2001.c')
-rw-r--r--drivers/led/ckled2001.c89
1 files changed, 44 insertions, 45 deletions
diff --git a/drivers/led/ckled2001.c b/drivers/led/ckled2001.c
index 6ababf55e9..8340aae823 100644
--- a/drivers/led/ckled2001.c
+++ b/drivers/led/ckled2001.c
@@ -16,18 +16,17 @@
#include "ckled2001.h"
#include "i2c_master.h"
-#include "wait.h"
-#ifndef CKLED2001_TIMEOUT
-# define CKLED2001_TIMEOUT 100
+#ifndef CKLED2001_I2C_TIMEOUT
+# define CKLED2001_I2C_TIMEOUT 100
#endif
-#ifndef CKLED2001_PERSISTENCE
-# define CKLED2001_PERSISTENCE 0
+#ifndef CKLED2001_I2C_PERSISTENCE
+# define CKLED2001_I2C_PERSISTENCE 0
#endif
-#ifndef PHASE_CHANNEL
-# define PHASE_CHANNEL MSKPHASE_12CHANNEL
+#ifndef CKLED2001_PHASE_CHANNEL
+# define CKLED2001_PHASE_CHANNEL CKLED2001_MSKPHASE_12CHANNEL
#endif
#ifndef CKLED2001_CURRENT_TUNE
@@ -44,25 +43,25 @@ uint8_t g_twi_transfer_buffer[65];
// We could optimize this and take out the unused registers from these
// buffers and the transfers in ckled2001_write_pwm_buffer() but it's
// probably not worth the extra complexity.
-uint8_t g_pwm_buffer[DRIVER_COUNT][192];
-bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
+uint8_t g_pwm_buffer[CKLED2001_DRIVER_COUNT][192];
+bool g_pwm_buffer_update_required[CKLED2001_DRIVER_COUNT] = {false};
-uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
-bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
+uint8_t g_led_control_registers[CKLED2001_DRIVER_COUNT][24] = {0};
+bool g_led_control_registers_update_required[CKLED2001_DRIVER_COUNT] = {false};
bool ckled2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
// If the transaction fails function returns false.
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
-#if CKLED2001_PERSISTENCE > 0
- for (uint8_t i = 0; i < CKLED2001_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_TIMEOUT) != 0) {
+#if CKLED2001_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < CKLED2001_I2C_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_TIMEOUT) != 0) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, CKLED2001_I2C_TIMEOUT) != 0) {
return false;
}
#endif
@@ -84,14 +83,14 @@ bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
}
-#if CKLED2001_PERSISTENCE > 0
- for (uint8_t i = 0; i < CKLED2001_PERSISTENCE; i++) {
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, CKLED2001_TIMEOUT) != 0) {
+#if CKLED2001_I2C_PERSISTENCE > 0
+ for (uint8_t i = 0; i < CKLED2001_I2C_PERSISTENCE; i++) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, CKLED2001_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
- if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, CKLED2001_TIMEOUT) != 0) {
+ if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, CKLED2001_I2C_TIMEOUT) != 0) {
return false;
}
#endif
@@ -101,48 +100,48 @@ bool ckled2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
void ckled2001_init(uint8_t addr) {
// Select to function page
- ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE);
// Setting LED driver to shutdown mode
- ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE);
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_SHUT_DOWN_MODE);
// Setting internal channel pulldown/pullup
- ckled2001_write_register(addr, PDU_REG, MSKSET_CA_CB_CHANNEL);
+ ckled2001_write_register(addr, CKLED2001_REG_PDU, CKLED2001_MSKSET_CA_CB_CHANNEL);
// Select number of scan phase
- ckled2001_write_register(addr, SCAN_PHASE_REG, PHASE_CHANNEL);
+ ckled2001_write_register(addr, CKLED2001_REG_SCAN_PHASE, CKLED2001_PHASE_CHANNEL);
// Setting PWM Delay Phase
- ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE1_REG, MSKPWM_DELAY_PHASE_ENABLE);
+ ckled2001_write_register(addr, CKLED2001_REG_SLEW_RATE_CONTROL_MODE1, CKLED2001_MSKPWM_DELAY_PHASE_ENABLE);
// Setting Driving/Sinking Channel Slew Rate
- ckled2001_write_register(addr, SLEW_RATE_CONTROL_MODE2_REG, MSKDRIVING_SINKING_CHHANNEL_SLEWRATE_ENABLE);
+ ckled2001_write_register(addr, CKLED2001_REG_SLEW_RATE_CONTROL_MODE2, CKLED2001_MSKDRIVING_SINKING_CHANNEL_SLEWRATE_ENABLE);
// Setting Iref
- ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_DISABLE);
+ ckled2001_write_register(addr, CKLED2001_REG_SOFTWARE_SLEEP, CKLED2001_MSKSLEEP_DISABLE);
// Set LED CONTROL PAGE (Page 0)
- ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE);
- for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) {
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_CONTROL_PAGE);
+ for (int i = 0; i < CKLED2001_LED_CONTROL_ON_OFF_LENGTH; i++) {
ckled2001_write_register(addr, i, 0x00);
}
// Set PWM PAGE (Page 1)
- ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE);
- for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) {
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_PWM_PAGE);
+ for (int i = 0; i < CKLED2001_LED_CURRENT_TUNE_LENGTH; i++) {
ckled2001_write_register(addr, i, 0x00);
}
// Set CURRENT PAGE (Page 4)
- uint8_t current_tuen_reg_list[LED_CURRENT_TUNE_LENGTH] = CKLED2001_CURRENT_TUNE;
- ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, CURRENT_TUNE_PAGE);
- for (int i = 0; i < LED_CURRENT_TUNE_LENGTH; i++) {
- ckled2001_write_register(addr, i, current_tuen_reg_list[i]);
+ uint8_t current_tune_reg_list[CKLED2001_LED_CURRENT_TUNE_LENGTH] = CKLED2001_CURRENT_TUNE;
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_CURRENT_TUNE_PAGE);
+ for (int i = 0; i < CKLED2001_LED_CURRENT_TUNE_LENGTH; i++) {
+ ckled2001_write_register(addr, i, current_tune_reg_list[i]);
}
// Enable LEDs ON/OFF
- ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE);
- for (int i = 0; i < LED_CONTROL_ON_OFF_LENGTH; i++) {
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_CONTROL_PAGE);
+ for (int i = 0; i < CKLED2001_LED_CONTROL_ON_OFF_LENGTH; i++) {
ckled2001_write_register(addr, i, 0xFF);
}
// Select to function page
- ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE);
// Setting LED driver to normal mode
- ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE);
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_NORMAL_MODE);
}
void ckled2001_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
@@ -198,7 +197,7 @@ void ckled2001_set_led_control_register(uint8_t index, bool red, bool green, boo
void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index) {
if (g_pwm_buffer_update_required[index]) {
- ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_PWM_PAGE);
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_PWM_PAGE);
// If any of the transactions fail we risk writing dirty PG0,
// refresh page 0 just in case.
@@ -211,7 +210,7 @@ void ckled2001_update_pwm_buffers(uint8_t addr, uint8_t index) {
void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index) {
if (g_led_control_registers_update_required[index]) {
- ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, LED_CONTROL_PAGE);
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_LED_CONTROL_PAGE);
for (int i = 0; i < 24; i++) {
ckled2001_write_register(addr, i, g_led_control_registers[index][i]);
}
@@ -221,16 +220,16 @@ void ckled2001_update_led_control_registers(uint8_t addr, uint8_t index) {
void ckled2001_sw_return_normal(uint8_t addr) {
// Select to function page
- ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE);
// Setting LED driver to normal mode
- ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_NORMAL_MODE);
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_NORMAL_MODE);
}
void ckled2001_sw_shutdown(uint8_t addr) {
// Select to function page
- ckled2001_write_register(addr, CONFIGURE_CMD_PAGE, FUNCTION_PAGE);
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURE_CMD_PAGE, CKLED2001_FUNCTION_PAGE);
// Setting LED driver to shutdown mode
- ckled2001_write_register(addr, CONFIGURATION_REG, MSKSW_SHUT_DOWN_MODE);
+ ckled2001_write_register(addr, CKLED2001_REG_CONFIGURATION, CKLED2001_MSKSW_SHUT_DOWN_MODE);
// Write SW Sleep Register
- ckled2001_write_register(addr, SOFTWARE_SLEEP_REG, MSKSLEEP_ENABLE);
+ ckled2001_write_register(addr, CKLED2001_REG_SOFTWARE_SLEEP, CKLED2001_MSKSLEEP_ENABLE);
}