Software APIs
leds.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_BOARDS_TEACUP_V1_3_0_LEDS_H_
6 #define OPENTITAN_SW_DEVICE_LIB_BOARDS_TEACUP_V1_3_0_LEDS_H_
7 
8 #include "sw/device/lib/base/status.h"
10 
11 /**
12  * Defined Constants.
13  */
14 enum {
15  // Teacup LED Controller
16  kLedsDriverI2cAddr = 0x34,
17 
18  // Teacup LED Controller Registers
19  kLedsControlRegAddr = 0x00,
20  kLedUpdateRegAddr = 0x49,
21  kLedChannel0ScalingRegAddr = 0x4D,
22  kLedGlobalCurrentControlRegAddr = 0x6E,
23 
24  // LED DS5
25  kLedBlue0LowRegAddr = 0x07,
26  kLedRed0LowRegAddr = 0x09,
27  kLedGreen0LowRegAddr = 0x0B,
28 
29  // LED DS9
30  kLedBlue1LowRegAddr = 0x0D,
31  kLedRed1LowRegAddr = 0x0F,
32  kLedGreen1LowRegAddr = 0x11,
33 
34  // LED DS10
35  kLedBlue2LowRegAddr = 0x13,
36  kLedRed2LowRegAddr = 0x15,
37  kLedGreen2LowRegAddr = 0x17,
38 
39  // LED DS11
40  kLedBlue3LowRegAddr = 0x19,
41  kLedRed3LowRegAddr = 0x1B,
42  kLedGreen3LowRegAddr = 0x1D,
43 
44  // Other
45  kNumTeacupLeds = 4,
46 };
47 
48 /**
49  * Teacup RGB LEDs.
50  */
51 typedef enum teacup_led {
52  kTeacupLedDs5 = 0,
53  kTeacupLedDs9 = 1,
54  kTeacupLedDs10 = 2,
55  kTeacupLedDs11 = 3,
56 } teacup_led_t;
57 
58 /**
59  * LED RGB color value.
60  */
61 typedef struct led_rgb_color {
62  uint8_t r;
63  uint8_t g;
64  uint8_t b;
66 
67 /**
68  * Reads the teacup LED controller's control register.
69  *
70  * @param i2c I2C handle to communicate with the I2C LED controller.
71  * @param reg_addr Address of the I2C LED controller to read.
72  * @param[out] data_out Data read from the I2C LED controller.
73  */
75 status_t leds_read_ctrl_reg(const dif_i2c_t *i2c, uint8_t reg_addr,
76  uint8_t *data_out);
77 
78 /**
79  * Sets the color for a specific teacup LED.
80  *
81  * @param i2c I2C handle to communicate with the I2C LED controller.
82  * @param led The teacup LED to configure.
83  * @param color The color to set the LED to.
84  */
86 status_t leds_set_color(const dif_i2c_t *i2c, teacup_led_t led,
87  led_rgb_color_t color);
88 
89 /**
90  * Sets the brightness (global current control) of all LEDs on the teacup board.
91  *
92  * @param i2c I2C handle to communicate with the I2C LED controller.
93  * @param brightness The brightness value, in [0, 255], to set the LED to.
94  */
96 status_t leds_set_all_brightness(const dif_i2c_t *i2c, uint8_t brightness);
97 
98 /**
99  * Configures the I2C LED controller on the teacup board.
100  *
101  * @param i2c I2C handle to communicate with the I2C LED controller.
102  */
104 status_t leds_i2c_controller_configure(const dif_i2c_t *i2c);
105 
106 /**
107  * Turns all LEDs off, on the teacup board.
108  *
109  * @param i2c I2C handle to communicate with the I2C LED controller.
110  */
112 status_t leds_turn_all_off(const dif_i2c_t *i2c);
113 
114 /**
115  * Turns all LEDs on, on the teacup board.
116  *
117  * @param i2c I2C handle to communicate with the I2C LED controller.
118  */
120 status_t leds_turn_all_on(const dif_i2c_t *i2c);
121 
122 #endif // OPENTITAN_SW_DEVICE_LIB_BOARDS_TEACUP_V1_3_0_LEDS_H_