Skip to content

Commit efb0845

Browse files
Hust-ShuaiWangfanghuaqi
authored andcommitted
application:merge the branch of feature/ilight_mode and remove some warnings
1 parent 2bf8edb commit efb0845

File tree

6 files changed

+487
-58
lines changed

6 files changed

+487
-58
lines changed
Lines changed: 331 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
/* ------------------------------------------
2+
* Copyright (c) 2017, Synopsys, Inc. All rights reserved.
3+
4+
* Redistribution and use in source and binary forms, with or without modification,
5+
* are permitted provided that the following conditions are met:
6+
7+
* 1) Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
10+
* 2) Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation and/or
12+
* other materials provided with the distribution.
13+
14+
* 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
15+
* be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
* \version 2017.08
30+
* \date 2017-08-20
31+
* \author dbHu([email protected])
32+
--------------------------------------------- */
33+
/**
34+
* \file
35+
* \ingroup EMBARC_APP_FREERTOS_IOT_ILIGHT_SMARTDEVICE
36+
* \brief light control driver for ilight.
37+
*/
38+
39+
/**
40+
* \addtogroup EMBARC_APP_FREERTOS_IOT_ILIGHT_SMARTDEVICE
41+
* @{
42+
*/
43+
/* embARC HAL */
44+
#include "embARC.h"
45+
#include "embARC_debug.h"
46+
#include "dev_gpio.h"
47+
#include "dw_gpio.h"
48+
#include "arc_builtin.h"
49+
50+
/* custom HAL */
51+
#include "light_driver.h"
52+
#include "task.h"
53+
54+
uint8_t color_row;
55+
uint8_t light_num;
56+
57+
/**
58+
* Light control array definition.
59+
* Middle row of the lamp beads.
60+
*/
61+
static RGB_T ilight_middle[LIGHT_NUM_MIDDLE];
62+
63+
/**
64+
* Light control array definition.
65+
* Both sides of the lamp beads.
66+
*/
67+
static RGB_T ilight_side[LIGHT_NUM_SIDE];
68+
static RGB_T *piLight;
69+
70+
/**
71+
* Some variables definition related gpio initialization .
72+
* Middle row of lights.
73+
*/
74+
static DEV_GPIO_PTR port_gpio_middle;
75+
static DW_GPIO_PORT_PTR port_middle;
76+
static DEV_GPIO_INFO_PTR port_info_ptr_middle;
77+
78+
/**
79+
*Some variables definition related gpio initialization .
80+
*Middle row of lights.
81+
*/
82+
static DEV_GPIO_PTR port_gpio_side;
83+
static DW_GPIO_PORT_PTR port_side;
84+
static DEV_GPIO_INFO_PTR port_info_ptr_side;
85+
86+
87+
static uint32_t low_val_middle=0,low_val_side=0;
88+
static uint32_t temp_reg_middle,temp_reg_side;
89+
90+
/**
91+
* \brief Initialize light control gpio.2 pins will be initialized in this
92+
function,and output low after initialization.
93+
*/
94+
void light_ctr_gpio_init()
95+
{
96+
uint32_t val_middle,val_side;
97+
98+
port_gpio_middle = gpio_get_dev(GPIO_OUT_PORT_MIDDLE);
99+
port_gpio_middle->gpio_open(GPIO_OUT_MASK_MIDDLE);
100+
101+
port_gpio_side = gpio_get_dev(GPIO_OUT_PORT_SIDE);
102+
port_gpio_side->gpio_open(GPIO_OUT_MASK_SIDE);
103+
104+
port_gpio_middle->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)(GPIO_OUT_MASK_MIDDLE));
105+
port_gpio_middle->gpio_control(GPIO_CMD_DIS_BIT_INT, (void *)(GPIO_OUT_MASK_MIDDLE));
106+
107+
port_gpio_side->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)(GPIO_OUT_MASK_SIDE));
108+
port_gpio_side->gpio_control(GPIO_CMD_DIS_BIT_INT, (void *)(GPIO_OUT_MASK_SIDE));
109+
110+
port_info_ptr_middle =& (port_gpio_middle->gpio_info);
111+
port_middle = (DW_GPIO_PORT_PTR)(port_info_ptr_middle->gpio_ctrl);
112+
113+
port_info_ptr_side =& (port_gpio_side->gpio_info);
114+
port_side = (DW_GPIO_PORT_PTR)(port_info_ptr_side->gpio_ctrl);
115+
116+
low_val_middle &= GPIO_H_CFG_MIDDLE;
117+
low_val_middle |= low_val_middle;
118+
119+
low_val_side &= GPIO_H_CFG_SIDE;
120+
low_val_side |= low_val_side;
121+
122+
val_middle = GPIO_H_CFG_MIDDLE;
123+
temp_reg_middle = port_middle->regs->SWPORTS[port_middle->no].DR;
124+
temp_reg_middle &= ~GPIO_H_CFG_MIDDLE;
125+
val_middle &= GPIO_H_CFG_MIDDLE;
126+
temp_reg_middle |= val_middle;
127+
128+
val_side = GPIO_H_CFG_SIDE;
129+
temp_reg_side = port_side->regs->SWPORTS[port_side->no].DR;
130+
temp_reg_side &= ~ GPIO_H_CFG_SIDE;
131+
val_side &= GPIO_H_CFG_SIDE;
132+
temp_reg_side |= val_side;
133+
134+
port_middle->regs->SWPORTS[port_middle->no].DR = low_val_middle;
135+
port_side->regs->SWPORTS[port_side->no].DR = low_val_side;
136+
}
137+
138+
/**
139+
* \brief The light control function sends one bit data,0.The duration of the high level is 0.35us,
140+
the error is 150ns.The duration of the low level is 0.8us,the error is 150ns.
141+
* \param row Indicates which pin is going to send data.If it is not LIGHT_ROW_MIDDLE,it will be LIGHT_SIDE by default.
142+
*/
143+
void light_send_bit_0(uint16_t row)
144+
{
145+
uint8_t j;
146+
uint32_t value_high,value_low;
147+
DW_GPIO_PORT_PTR row_send;
148+
149+
if (row == LIGHT_ROW_MIDDLE) {
150+
row_send = port_middle;
151+
value_high = temp_reg_middle;
152+
value_low = low_val_middle;
153+
} else {
154+
row_send = port_side;
155+
value_high = temp_reg_side;
156+
value_low = low_val_side;
157+
}
158+
159+
/*!< 0.35us high level output */
160+
row_send->regs->SWPORTS[row_send->no].DR = value_high;
161+
for (j = 0;j < 6;j++) {
162+
asm("nop");
163+
}
164+
asm("nop");
165+
166+
/*!< Pull the pin low */
167+
row_send->regs->SWPORTS[row_send->no].DR = value_low;
168+
}
169+
170+
/**
171+
* \brief reset side row led
172+
*/
173+
void light_ctr_reset()
174+
{
175+
port_side->regs->SWPORTS[port_side->no].DR = low_val_side;
176+
delay_10us(50);
177+
}
178+
179+
/**
180+
* \brief The light control function sends one bit data,1.
181+
* \details The duration of the high level is 0.7us,the error is 150ns.The duration of the low level is 0.6us,the error is 150ns.
182+
* \param row Indicates which pin is going to send data.If it is not LIGHT_ROW_MIDDLE,it will be LIGHT_SIDE by default.
183+
*/
184+
void light_send_bit_1(uint16_t row)
185+
{
186+
uint8_t j;
187+
uint32_t value_high,value_low;
188+
DW_GPIO_PORT_PTR row_send;
189+
if (row == LIGHT_ROW_MIDDLE) {
190+
row_send = port_middle;
191+
value_high = temp_reg_middle;
192+
value_low = low_val_middle;
193+
} else {
194+
row_send = port_side;
195+
value_high = temp_reg_side;
196+
value_low = low_val_side;
197+
}
198+
199+
/* 0.7us high level output */
200+
row_send->regs->SWPORTS[row_send->no].DR = value_high;
201+
for (j = 0; j < 6; j++) {
202+
asm("nop");
203+
}
204+
for (j = 0; j < 6; j++) {
205+
asm("nop");
206+
}
207+
for (j = 0; j < 2; j++) {
208+
asm("nop");
209+
}
210+
asm("nop");
211+
212+
/*!< Pull the pin low */
213+
row_send->regs->SWPORTS[row_send->no].DR = value_low;
214+
}
215+
216+
/**
217+
* \brief Send 24 bits data to control one led.
218+
* \details According to parameter send 24 bits color data to light one beat.
219+
* \param color_data The low 24 bits of the parameter is effective.
220+
* \param row Indicates which pin is going to send data.If it is not LIGHT_ROW_MIDDLE,it will be LIGHT_SIDE by default.
221+
*/
222+
void light_send_colordata(uint32_t color_data,uint16_t row)
223+
{
224+
int8_t i;
225+
for (i = 23; i >= 0; i--) {
226+
if ((color_data >> i) & 0x01) {
227+
light_send_bit_1(row);
228+
} else {
229+
light_send_bit_0(row);
230+
}
231+
}
232+
}
233+
234+
/**
235+
* \brief Delay 10 us.
236+
* \details Implement the delay effect by executing empty statement.
237+
* parameter mul One unit represents 10 us.
238+
*/
239+
void delay_10us(uint32_t mul)
240+
{
241+
for (delay_num = 0; delay_num < 25 * mul; delay_num++) {
242+
243+
}
244+
}
245+
246+
/**
247+
* \brief Lighting control function.
248+
* \details Update specify arrays and send those arrays to control lamp beats.
249+
* \param mask Those bits which are setted one mark those lamp beats that are going to be changed.
250+
* \param row Indicates which pin is going to send data.If it is not LIGHT_ROW_MIDDLE,it will be LIGHT_SIDE by default.
251+
* \param rgb The data of clolor.
252+
*/
253+
void light_ctr_rgb(uint64_t mask,uint16_t row,uint8_t red,uint8_t green,uint8_t blue)
254+
{
255+
uint8_t i;
256+
uint32_t colordata = 0;
257+
color_row = row;
258+
RGB_T *ilight_color;
259+
260+
if (row == LIGHT_ROW_MIDDLE) {
261+
light_num = LIGHT_NUM_MIDDLE;
262+
ilight_color = &ilight_middle[0];
263+
piLight = ilight_middle;
264+
} else {
265+
light_num = LIGHT_NUM_SIDE;
266+
ilight_color = &ilight_side[0];
267+
piLight = ilight_side;
268+
}
269+
270+
/*!< Place the data of RGB colors into a 32-bit variable */
271+
colordata |= green;
272+
colordata = (colordata<<8) | red;
273+
colordata = (colordata<<8) | blue;
274+
275+
276+
/*!< Update the array element data */
277+
/*!< In order to avoid the shift operation is optimized,set the 64 bit one */
278+
for (i = 0; i < light_num; i++) {
279+
if ((mask >> i) & 0x01) {
280+
ilight_color[i].color = colordata;
281+
}
282+
}
283+
xQueueSendToFront(led_queue,(void *) & piLight,(TickType_t)0);
284+
delay_10us(5);
285+
}
286+
287+
/**
288+
* \brief Perform a left shift operation on the parameter.
289+
* \details Because the translater will set those bits which is higher than 32 high,so if you want to avoid this bug you have to set at least one bit high which is higher than 32.
290+
* \param aim_num The number which you want to perform.
291+
* \param shift num How many bits you want to shift.
292+
* \retval aim_num<<shift_num
293+
*/
294+
uint64_t light_ctr_mask_lshift(uint64_t aim_num,uint64_t shift_num)
295+
{
296+
aim_num |= 0x1000000000000000;
297+
return aim_num = aim_num << shift_num;
298+
}
299+
300+
/*
301+
* \brief Lighting control function.
302+
* \details Update specify arrays and send those arrays to control lamp beats.
303+
* \param mask Those bits which are setted one mark those lamp beats that are going to be changed.
304+
* \param row Indicates which pin is going to send data.If it is not LIGHT_ROW_MIDDLE,it will be LIGHT_SIDE by default.
305+
* \param rgb The data of clolor.
306+
*/
307+
void light_ctr_rgb_update(uint64_t mask,uint16_t row,uint8_t red,uint8_t green,uint8_t blue)
308+
{
309+
uint8_t i;
310+
uint32_t colordata = 0;
311+
RGB_T *ilight_color;
312+
if (row == LIGHT_ROW_MIDDLE) {
313+
light_num = LIGHT_NUM_MIDDLE;
314+
ilight_color = &ilight_middle[0];
315+
} else {
316+
light_num = LIGHT_NUM_SIDE;
317+
ilight_color = &ilight_side[0];
318+
}
319+
/*!< In order to avoid the shift operation is optimized,set the 64 bit one */
320+
colordata |= green;
321+
colordata = (colordata << 8) | red;
322+
colordata = (colordata << 8) | blue;
323+
/*!< Update the array element data */
324+
for (i = 0;i < light_num;i++) {
325+
if ((mask >> i) & 0x01) {
326+
ilight_color[i].color = colordata;
327+
}
328+
}
329+
}
330+
331+
/** @} */

0 commit comments

Comments
 (0)