blob: a8e574ba182cb4ce4eb3ed83daf89634d3a4cf5b [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*******************************************************************************
2 * Copyright (C) 2016, ZIXC Corporation.
3 *
4 * File Name: hal_led.c
5 * File Mark:
6 * Description: This file contains the hal layer routines for i2c driver.
7 * Others:
8 * Version: V1.0
9 * Author: yx
10 * Date: 2014-07-03
11 * History 1:
12 * Date:
13 * Version:
14 * Author:
15 * Modification:
16 * History 2:
17 ******************************************************************************/
18
19/****************************************************************************
20* Include files
21****************************************************************************/
22#include <drvs_gpio.h>
23#include <led.h>
24
25/****************************************************************************
26* Local Types
27****************************************************************************/
28
29/****************************************************************************
30* Local Constants
31****************************************************************************/
32
33
34SINT32 led_SetStatus(led_channel channel, led_status status)
35{
36 SINT32 ret = 0;
37 if (status == LED_STATUS_ON)
38 {
39 switch (channel)
40 {
41 case LED_WIFI_BLUE:
42 zDrvGpio_SetOutputValue(LED_WIFI_BLUE_GPIO,GPIO_HIGH);
43 break;
44 case LED_SMS_BLUE:
45 zDrvGpio_SetOutputValue(LED_SMS_BLUE_GPIO,GPIO_HIGH);
46 break;
47 case LED_BAT_RED:
48 zDrvGpio_SetOutputValue(LED_BAT_RED_GPIO,GPIO_HIGH);
49 break;
50 case LED_BAT_GREEN:
51 zDrvGpio_SetOutputValue(LED_BAT_GREEN_GPIO,GPIO_HIGH);
52 break;
53 case LED_MODEM_BLUE:
54 zDrvGpio_SetOutputValue(LED_MODEM_BLUE_GPIO,GPIO_HIGH);
55 break;
56 case LED_MODEM_RED:
57 zDrvGpio_SetOutputValue(LED_MODEM_RED_GPIO,GPIO_HIGH);
58 break;
59 default:
60 break;
61
62
63 }
64 }
65 else if (status == LED_STATUS_OFF)
66 {
67 switch (channel)
68 {
69 case LED_WIFI_BLUE:
70 zDrvGpio_SetOutputValue(LED_WIFI_BLUE_GPIO,GPIO_LOW);
71 break;
72 case LED_SMS_BLUE:
73 zDrvGpio_SetOutputValue(LED_SMS_BLUE_GPIO,GPIO_LOW);
74 break;
75 case LED_BAT_RED:
76 zDrvGpio_SetOutputValue(LED_BAT_RED_GPIO,GPIO_LOW);
77 break;
78 case LED_BAT_GREEN:
79 zDrvGpio_SetOutputValue(LED_BAT_GREEN_GPIO,GPIO_LOW);
80 break;
81 case LED_MODEM_BLUE:
82 zDrvGpio_SetOutputValue(LED_MODEM_BLUE_GPIO,GPIO_LOW);
83 break;
84 case LED_MODEM_RED:
85 zDrvGpio_SetOutputValue(LED_MODEM_RED_GPIO,GPIO_LOW);
86 break;
87 default:
88 break;
89
90
91 }
92 }
93 else
94 {
95 return -1;
96 }
97
98 return ret;
99
100}
101
102#if 0
103
104/*******************************************************************************
105 * Function: led_SetLEDcurrent
106 * Description:
107 * Parameters:
108 * Input: led_color: LED_RED / LED_GREEN / LED_BLUE
109 * brightness: LED_BRIGHTNESS_1 ~ LED_BRIGHTNESS_16
110 * Output:
111 * Returns: success or fail
112 * Others: blue led can't set brightness, only can set on/off
113 ********************************************************************************/
114SINT32 led_SetLEDcurrent(UINT8 sink, led_current current)
115{
116 SINT32 ret = 0;
117 UINT8 slv_addr=0, reg_addr=0, reg_val=0, mask=0;
118
119 slv_addr = ZX234290_I2C_SLAVE_ADDR0;
120
121 reg_addr = ZX234290_REG_ADDR_SYS_CTRL;
122 if (current)
123 {
124 switch (sink)
125 {
126 case 1:
127 reg_val = LED_BITFVAL(1, 0); /* 0x07 寄存器 [1:0] */
128 break;
129 case 2:
130 reg_val = LED_BITFVAL(1, 1); /* 0x07 寄存器 [1:0] */
131 break;
132 default:
133 break;
134 }
135 }
136 else
137 {
138 switch (sink)
139 {
140 case 1:
141 reg_val = LED_BITFVAL(0, 0);
142 break;
143 case 2:
144 reg_val = LED_BITFVAL(0, 1); /* 0x07 寄存器 [1:0] */
145 break;
146 default:
147 break;
148 }
149 }
150
151 switch (sink)
152 {
153 case 1:
154 mask = LED_BITFMASK(1, 0);
155 break;
156 case 2:
157 mask = LED_BITFMASK(1, 1);; /* 0x07 寄存器 [1:0] */
158 break;
159 default:
160 break;
161 }
162
163
164 ret = zx297520_led_SetRegister(reg_addr, reg_val, mask);
165 //zOss_Sleep(500);
166
167 switch (sink)
168 {
169 case 1:
170 reg_addr = ZX234290_REG_ADDR_SINK1_CUR_SEL;
171 break;
172 case 2:
173 reg_addr = ZX234290_REG_ADDR_SINK2_CUR_SEL;
174 break;
175 default:
176 break;
177 }
178
179 reg_val = LED_BITFVAL(current, 0); /* 0x07 寄存器 [1:0] */
180 mask = LED_BITFMASK(4, 0);
181 ret = zx297520_led_SetRegister(reg_addr, reg_val, mask);
182
183 if (ret != 0)
184 {
185 return -1;
186 }
187
188 return 0;
189}
190#endif
191void zx29_led_init(void)
192{
193 zDrvGpio_SetFunc(LED_WIFI_BLUE_GPIO,LED_WIFI_BLUE_GPIO_FUN);
194 zDrvGpio_SetDirection(LED_WIFI_BLUE_GPIO,GPIO_OUT);
195 zDrvGpio_SetOutputValue(LED_WIFI_BLUE_GPIO,GPIO_LOW);
196
197 zDrvGpio_SetFunc(LED_SMS_BLUE_GPIO,LED_SMS_BLUE_GPIO_FUN);
198 zDrvGpio_SetDirection(LED_SMS_BLUE_GPIO,GPIO_OUT);
199 zDrvGpio_SetOutputValue(LED_SMS_BLUE_GPIO,GPIO_LOW);
200
201 zDrvGpio_SetFunc(LED_BAT_RED_GPIO,LED_BAT_RED_GPIO_FUN);
202 zDrvGpio_SetDirection(LED_BAT_RED_GPIO,GPIO_OUT);
203 zDrvGpio_SetOutputValue(LED_BAT_RED_GPIO,GPIO_LOW);
204
205 zDrvGpio_SetFunc(LED_BAT_GREEN_GPIO,LED_BAT_GREEN_GPIO_FUN);
206 zDrvGpio_SetDirection(LED_BAT_GREEN_GPIO,GPIO_OUT);
207 zDrvGpio_SetOutputValue(LED_BAT_GREEN_GPIO,GPIO_LOW);
208
209 zDrvGpio_SetFunc(LED_MODEM_RED_GPIO,LED_MODEM_RED_GPIO_FUN);
210 zDrvGpio_SetDirection(LED_MODEM_RED_GPIO,GPIO_OUT);
211 zDrvGpio_SetOutputValue(LED_MODEM_RED_GPIO,GPIO_LOW);
212
213 zDrvGpio_SetFunc(LED_MODEM_BLUE_GPIO,LED_MODEM_BLUE_GPIO_FUN);
214 zDrvGpio_SetDirection(LED_MODEM_BLUE_GPIO,GPIO_OUT);
215 zDrvGpio_SetOutputValue(LED_MODEM_BLUE_GPIO,GPIO_LOW);
216}
217
218void zx29_led_PowerOnLedOn(void)
219{
220 #if 1
221 led_SetStatus(LED_MODEM_RED,LED_STATUS_OFF);
222 led_SetStatus(LED_BAT_GREEN,LED_STATUS_OFF);
223
224 led_SetStatus(LED_WIFI_BLUE,LED_STATUS_ON);
225 led_SetStatus(LED_SMS_BLUE,LED_STATUS_ON);
226 led_SetStatus(LED_BAT_RED,LED_STATUS_ON);
227 led_SetStatus(LED_MODEM_BLUE,LED_STATUS_ON);
228 #endif
229
230}
231void zx29_led_PowerOnLedOff(void)
232{
233 udelay(19500); /*300ms*/
234 led_SetStatus(LED_WIFI_BLUE,LED_STATUS_OFF);
235 led_SetStatus(LED_SMS_BLUE,LED_STATUS_OFF);
236 led_SetStatus(LED_MODEM_BLUE,LED_STATUS_OFF);
237}
238