Skip to content

Commit 1382853

Browse files
authored
Merge pull request #1 from Nicolai-Electronics/add-led-features
Add new LED features (brightness, mode selection, message LED)
2 parents 172398b + 23f6b58 commit 1382853

2 files changed

Lines changed: 107 additions & 1 deletion

File tree

tanmatsu_coprocessor.c

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define TANMATSU_COPROCESSOR_I2C_REG_DISPLAY_BACKLIGHT 11
2222
#define TANMATSU_COPROCESSOR_I2C_REG_KEYBOARD_BACKLIGHT 12
2323
#define TANMATSU_COPROCESSOR_I2C_REG_INTERRUPT 13
24-
#define TANMATSU_COPROCESSOR_I2C_REG_RESERVED_0 14
24+
#define TANMATSU_COPROCESSOR_I2C_REG_LED_BRIGHTNESS 14
2525
#define TANMATSU_COPROCESSOR_I2C_REG_INPUT 15
2626
#define TANMATSU_COPROCESSOR_I2C_REG_OUTPUT 16
2727
#define TANMATSU_COPROCESSOR_I2C_REG_RADIO_CONTROL 17
@@ -69,6 +69,8 @@
6969
#define TANMATSU_COPROCESSOR_I2C_REG_LED5_G 142
7070
#define TANMATSU_COPROCESSOR_I2C_REG_LED5_R 143
7171
#define TANMATSU_COPROCESSOR_I2C_REG_LED5_B 144
72+
#define TANMATSU_COPROCESSOR_I2C_REG_LED_MODE 145
73+
#define TANMATSU_COPROCESSOR_I2C_REG_MESSAGE 146
7274

7375
typedef struct tanmatsu_coprocessor {
7476
i2c_master_dev_handle_t dev_handle; /// I2C device handle
@@ -321,6 +323,25 @@ esp_err_t tanmatsu_coprocessor_get_interrupt(tanmatsu_coprocessor_handle_t handl
321323
return ESP_OK;
322324
}
323325

326+
esp_err_t tanmatsu_coprocessor_get_led_brightness(tanmatsu_coprocessor_handle_t handle, uint8_t* out_brightness) {
327+
ESP_RETURN_ON_ERROR(ts_i2c_master_transmit_receive(handle, handle->dev_handle,
328+
(uint8_t[]){TANMATSU_COPROCESSOR_I2C_REG_LED_BRIGHTNESS}, 1,
329+
out_brightness, 1, TANMATSU_COPROCESSOR_TIMEOUT_MS),
330+
TAG, "Communication fault");
331+
return ESP_OK;
332+
}
333+
334+
esp_err_t tanmatsu_coprocessor_set_led_brightness(tanmatsu_coprocessor_handle_t handle, uint8_t brightness) {
335+
ESP_RETURN_ON_ERROR(ts_i2c_master_transmit(handle, handle->dev_handle,
336+
(uint8_t[]){
337+
TANMATSU_COPROCESSOR_I2C_REG_LED_BRIGHTNESS,
338+
brightness,
339+
},
340+
2, TANMATSU_COPROCESSOR_TIMEOUT_MS),
341+
TAG, "Communication fault");
342+
return ESP_OK;
343+
}
344+
324345
esp_err_t tanmatsu_coprocessor_get_inputs(tanmatsu_coprocessor_handle_t handle,
325346
tanmatsu_coprocessor_inputs_t* out_inputs) {
326347
ESP_RETURN_ON_ERROR(
@@ -753,3 +774,76 @@ esp_err_t tanmatsu_coprocessor_set_led_data(tanmatsu_coprocessor_handle_t handle
753774
"Communication fault");
754775
return ESP_OK;
755776
}
777+
778+
esp_err_t tanmatsu_coprocessor_get_led_mode(tanmatsu_coprocessor_handle_t handle, bool* out_automatic) {
779+
uint8_t mode;
780+
ESP_RETURN_ON_ERROR(
781+
ts_i2c_master_transmit_receive(handle, handle->dev_handle, (uint8_t[]){TANMATSU_COPROCESSOR_I2C_REG_LED_MODE},
782+
1, &mode, 1, TANMATSU_COPROCESSOR_TIMEOUT_MS),
783+
TAG, "Communication fault");
784+
if (out_automatic) {
785+
*out_automatic = (mode & 0x01) >> 0;
786+
}
787+
return ESP_OK;
788+
}
789+
790+
esp_err_t tanmatsu_coprocessor_set_led_mode(tanmatsu_coprocessor_handle_t handle, bool automatic) {
791+
uint8_t mode = (automatic & 0x01) << 0;
792+
ESP_RETURN_ON_ERROR(ts_i2c_master_transmit(handle, handle->dev_handle,
793+
(uint8_t[]){
794+
TANMATSU_COPROCESSOR_I2C_REG_LED_MODE,
795+
mode,
796+
},
797+
2, TANMATSU_COPROCESSOR_TIMEOUT_MS),
798+
TAG, "Communication fault");
799+
return ESP_OK;
800+
}
801+
802+
esp_err_t tanmatsu_coprocessor_get_message(tanmatsu_coprocessor_handle_t handle, bool* out_red, bool* out_green,
803+
bool* out_blue, bool* out_red_b, bool* out_green_b, bool* out_blue_b,
804+
bool* out_fade, bool* out_fade_hold) {
805+
uint8_t message = 0;
806+
ESP_RETURN_ON_ERROR(
807+
ts_i2c_master_transmit_receive(handle, handle->dev_handle, (uint8_t[]){TANMATSU_COPROCESSOR_I2C_REG_MESSAGE}, 1,
808+
&message, 1, TANMATSU_COPROCESSOR_TIMEOUT_MS),
809+
TAG, "Communication fault");
810+
if (out_red) {
811+
*out_red = (message >> 0) & 1;
812+
}
813+
if (out_green) {
814+
*out_green = (message >> 1) & 1;
815+
}
816+
if (out_blue) {
817+
*out_blue = (message >> 2) & 1;
818+
}
819+
if (out_fade) {
820+
*out_fade = (message >> 3) & 1;
821+
}
822+
if (out_red_b) {
823+
*out_red_b = (message >> 4) & 1;
824+
}
825+
if (out_green_b) {
826+
*out_green_b = (message >> 5) & 1;
827+
}
828+
if (out_blue_b) {
829+
*out_blue_b = (message >> 6) & 1;
830+
}
831+
if (out_fade_hold) {
832+
*out_fade_hold = (message >> 7) & 1;
833+
}
834+
return ESP_OK;
835+
}
836+
837+
esp_err_t tanmatsu_coprocessor_set_message(tanmatsu_coprocessor_handle_t handle, bool red, bool green, bool blue,
838+
bool red_b, bool green_b, bool blue_b, bool fade, bool fade_hold) {
839+
uint8_t message = (red << 0) | (green << 1) | (blue << 2) | (fade << 3) | (red_b << 4) | (green_b << 5) |
840+
(blue_b << 6) | (fade_hold << 7);
841+
ESP_RETURN_ON_ERROR(ts_i2c_master_transmit(handle, handle->dev_handle,
842+
(uint8_t[]){
843+
TANMATSU_COPROCESSOR_I2C_REG_MESSAGE,
844+
message,
845+
},
846+
2, TANMATSU_COPROCESSOR_TIMEOUT_MS),
847+
TAG, "Communication fault");
848+
return ESP_OK;
849+
}

tanmatsu_coprocessor.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ esp_err_t tanmatsu_coprocessor_set_keyboard_backlight(tanmatsu_coprocessor_handl
193193
esp_err_t tanmatsu_coprocessor_get_interrupt(tanmatsu_coprocessor_handle_t handle, bool* out_keyboard, bool* out_input,
194194
bool* out_pmic);
195195

196+
esp_err_t tanmatsu_coprocessor_get_led_brightness(tanmatsu_coprocessor_handle_t handle, uint8_t* out_brightness);
197+
esp_err_t tanmatsu_coprocessor_set_led_brightness(tanmatsu_coprocessor_handle_t handle, uint8_t brightness);
198+
196199
esp_err_t tanmatsu_coprocessor_get_inputs(tanmatsu_coprocessor_handle_t handle,
197200
tanmatsu_coprocessor_inputs_t* out_inputs);
198201

@@ -250,3 +253,12 @@ esp_err_t tanmatsu_coprocessor_get_pmic_charging_status(tanmatsu_coprocessor_han
250253
esp_err_t tanmatsu_coprocessor_get_pmic_otg_control(tanmatsu_coprocessor_handle_t handle, bool* out_enable);
251254
esp_err_t tanmatsu_coprocessor_set_pmic_otg_control(tanmatsu_coprocessor_handle_t handle, bool enable);
252255
esp_err_t tanmatsu_coprocessor_set_led_data(tanmatsu_coprocessor_handle_t handle, uint8_t* data, uint8_t length);
256+
257+
esp_err_t tanmatsu_coprocessor_get_led_mode(tanmatsu_coprocessor_handle_t handle, bool* out_automatic);
258+
esp_err_t tanmatsu_coprocessor_set_led_mode(tanmatsu_coprocessor_handle_t handle, bool automatic);
259+
260+
esp_err_t tanmatsu_coprocessor_get_message(tanmatsu_coprocessor_handle_t handle, bool* out_red, bool* out_green,
261+
bool* out_blue, bool* out_red_b, bool* out_green_b, bool* out_blue_b,
262+
bool* out_fade, bool* out_fade_hold);
263+
esp_err_t tanmatsu_coprocessor_set_message(tanmatsu_coprocessor_handle_t handle, bool red, bool green, bool blue,
264+
bool red_b, bool green_b, bool blue_b, bool fade, bool fade_hold);

0 commit comments

Comments
 (0)