23 #include <i2c/smbus.h>
24 #include <linux/i2c-dev.h>
25 #include <sys/ioctl.h>
35 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_RESET, 0xFF) < 0) {
return false; }
54 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_ENABLE, 0x00) < 0) {
return false; }
58 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_ENABLE, 0xFF) < 0) {
return false; }
60 uint8_t ledcontrol1 = 0;
61 uint8_t ledcontrol2 = 0;
62 uint8_t ledcontrol3 = 0;
64 for (
int i = 0; i < 6; ++i) {
65 if (state->
led[0 + i] > 0) { ledcontrol1 |= 1 << i; }
68 for (
int i = 0; i < 6; ++i) {
69 if (state->
led[6 + i] > 0) { ledcontrol2 |= 1 << i; }
72 for (
int i = 0; i < 6; ++i) {
73 if (state->
led[12 + i] > 0) { ledcontrol3 |= 1 << i; }
76 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_LED_01, ledcontrol1) < 0) {
return false; }
78 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_LED_02, ledcontrol2) < 0) {
return false; }
80 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_LED_03, ledcontrol3) < 0) {
return false; }
82 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_01, state->
led[0]) < 0) {
return false; }
84 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_02, state->
led[1]) < 0) {
return false; }
86 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_03, state->
led[2]) < 0) {
return false; }
88 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_04, state->
led[3]) < 0) {
return false; }
90 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_05, state->
led[4]) < 0) {
return false; }
92 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_06, state->
led[5]) < 0) {
return false; }
94 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_07, state->
led[6]) < 0) {
return false; }
96 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_08, state->
led[7]) < 0) {
return false; }
98 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_09, state->
led[8]) < 0) {
return false; }
100 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_10, state->
led[9]) < 0) {
return false; }
102 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_11, state->
led[10]) < 0) {
return false; }
104 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_12, state->
led[11]) < 0) {
return false; }
106 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_13, state->
led[12]) < 0) {
return false; }
108 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_14, state->
led[13]) < 0) {
return false; }
110 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_15, state->
led[14]) < 0) {
return false; }
112 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_16, state->
led[15]) < 0) {
return false; }
114 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_17, state->
led[16]) < 0) {
return false; }
116 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_PWM_18, state->
led[17]) < 0) {
return false; }
118 if (i2c_smbus_write_byte_data(busHandle,
SN3218_REG_UPDATE, 0xFF) < 0) {
return false; }
#define SN3218_ADDR_DEFAULT
SN3218 I2C Address.
bool i2c_sn3218_reset(const int busHandle)
Reset device to defaults.
bool i2c_sn3218_update(const int busHandle, const i2c_sn3218_state *state)
Configure SN3218 chip to match state object.
#define SN3218_REG_LED_03
LEDs 13-18 control register.
#define SN3218_REG_LED_01
LEDs 1 - 6 control register.
#define SN3218_REG_LED_02
LEDs 7-12 control register.
#define SN3218_REG_PWM_16
LED 16 PWM Intensity (0-255)
#define SN3218_REG_PWM_15
LED 15 PWM Intensity (0-255)
#define SN3218_REG_PWM_06
LED 6 PWM Intensity (0-255)
#define SN3218_REG_PWM_10
LED 10 PWM Intensity (0-255)
#define SN3218_REG_PWM_13
LED 13 PWM Intensity (0-255)
#define SN3218_REG_PWM_07
LED 7 PWM Intensity (0-255)
#define SN3218_REG_PWM_05
LED 5 PWM Intensity (0-255)
#define SN3218_REG_PWM_09
LED 9 PWM Intensity (0-255)
#define SN3218_REG_PWM_17
LED 17 PWM Intensity (0-255)
#define SN3218_REG_PWM_12
LED 12 PWM Intensity (0-255)
#define SN3218_REG_PWM_18
LED 18 PWM Intensity (0-255)
#define SN3218_REG_PWM_11
LED 11 PWM Intensity (0-255)
#define SN3218_REG_PWM_01
LED 1 PWM Intensity (0-255)
#define SN3218_REG_PWM_02
LED 2 PWM Intensity (0-255)
#define SN3218_REG_PWM_14
LED 14 PWM Intensity (0-255)
#define SN3218_REG_PWM_04
LED 4 PWM Intensity (0-255)
#define SN3218_REG_PWM_08
LED 8 PWM Intensity (0-255)
#define SN3218_REG_PWM_03
LED 3 PWM Intensity (0-255)
#define SN3218_REG_RESET
SN3218 Reset register - set high to reset all control registers.
#define SN3218_REG_UPDATE
SN3218 Update register - set high to apply changes.
#define SN3218_REG_ENABLE
Global device enable register.
SN3218 State representation.
uint8_t led[18]
Individual LED brightnesses.
bool global_enable
Global on/off switch.