|
21 | 21 | #define TANMATSU_COPROCESSOR_I2C_REG_DISPLAY_BACKLIGHT 11 |
22 | 22 | #define TANMATSU_COPROCESSOR_I2C_REG_KEYBOARD_BACKLIGHT 12 |
23 | 23 | #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 |
25 | 25 | #define TANMATSU_COPROCESSOR_I2C_REG_INPUT 15 |
26 | 26 | #define TANMATSU_COPROCESSOR_I2C_REG_OUTPUT 16 |
27 | 27 | #define TANMATSU_COPROCESSOR_I2C_REG_RADIO_CONTROL 17 |
|
69 | 69 | #define TANMATSU_COPROCESSOR_I2C_REG_LED5_G 142 |
70 | 70 | #define TANMATSU_COPROCESSOR_I2C_REG_LED5_R 143 |
71 | 71 | #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 |
72 | 74 |
|
73 | 75 | typedef struct tanmatsu_coprocessor { |
74 | 76 | 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 |
321 | 323 | return ESP_OK; |
322 | 324 | } |
323 | 325 |
|
| 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 | + |
324 | 345 | esp_err_t tanmatsu_coprocessor_get_inputs(tanmatsu_coprocessor_handle_t handle, |
325 | 346 | tanmatsu_coprocessor_inputs_t* out_inputs) { |
326 | 347 | ESP_RETURN_ON_ERROR( |
@@ -753,3 +774,76 @@ esp_err_t tanmatsu_coprocessor_set_led_data(tanmatsu_coprocessor_handle_t handle |
753 | 774 | "Communication fault"); |
754 | 775 | return ESP_OK; |
755 | 776 | } |
| 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 | +} |
0 commit comments