• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef LIGHT_DRIVER_H
10 #define LIGHT_DRIVER_H
11 
12 #include "device_resource_if.h"
13 #include "gpio_if.h"
14 #include "hdf_base.h"
15 #include "hdf_device_desc.h"
16 #include "hdf_log.h"
17 #include "hdf_workqueue.h"
18 #include "osal_mutex.h"
19 #include "osal_timer.h"
20 
21 #define LIGHT_MAKE_R_BIT    0X80000000
22 #define LIGHT_MAKE_G_BIT    0X00008000
23 #define LIGHT_MAKE_B_BIT    0X00000080
24 #define LIGHT_WAIT_TIME     50
25 
26 #define LIGHT_ID_NUM      4
27 
28 #define CHECK_LIGHT_NULL_PTR_RETURN_VALUE(ptr, ret) do { \
29     if ((ptr) == NULL) { \
30         HDF_LOGE("%s:line %d pointer is null and return ret", __func__, __LINE__); \
31         return (ret); \
32     } \
33 } while (0)
34 
35 #define CHECK_LIGHT_NULL_PTR_RETURN(ptr) do { \
36     if ((ptr) == NULL) { \
37         HDF_LOGE("%s:line %d pointer is null and return", __func__, __LINE__); \
38         return; \
39     } \
40 } while (0)
41 
42 #define CHECK_LIGHT_PARSER_RESULT_RETURN_VALUE(ret, str) do { \
43     if ((ret) != HDF_SUCCESS) { \
44         HDF_LOGE("%s:line %d %s fail, ret = %d!", __func__, __LINE__, str, ret); \
45         return HDF_FAILURE; \
46     } \
47 } while (0)
48 
49 enum LightIoCmd {
50     LIGHT_IO_CMD_GET_INFO_LIST     = 0,
51     LIGHT_IO_CMD_OPS               = 1,
52     LIGHT_IO_CMD_END,
53 };
54 
55 enum LightOpsCmd {
56     LIGHT_OPS_IO_CMD_ENABLE        = 0,
57     LIGHT_OPS_IO_CMD_DISABLE       = 1,
58     LIGHT_OPS_IO_CMD_END,
59 };
60 
61 enum LightState {
62     LIGHT_STATE_START   = 0,
63     LIGHT_STATE_STOP    = 1,
64     LIGHT_STATE_BUTT,
65 };
66 
67 enum LightId {
68     LIGHT_ID_NONE                = 0,
69     LIGHT_ID_BATTERY             = 1,
70     LIGHT_ID_NOTIFICATIONS       = 2,
71     LIGHT_ID_ATTENTION           = 3,
72     LIGHT_ID_BUTT,
73 };
74 
75 enum LightFlashMode {
76     LIGHT_FLASH_NONE = 0,
77     LIGHT_FLASH_TIMED = 1,
78     LIGHT_FLASH_BUTT = 2,
79 };
80 
81 struct LightFlashEffect {
82     int32_t flashMode;
83     uint32_t onTime;
84     uint32_t offTime;
85 };
86 
87 struct LightEffect {
88     uint32_t lightBrightness;
89     struct LightFlashEffect flashEffect;
90 };
91 
92 struct LightInfo {
93     uint32_t lightId;
94     int32_t reserved;
95 };
96 
97 struct LightDeviceInfo {
98     enum LightState lightState;
99     uint32_t busNum;
100     uint32_t busRNum;
101     uint32_t busGNum;
102     uint32_t busBNum;
103     uint32_t lightBrightness;
104     uint32_t onTime;
105     uint32_t offTime;
106 };
107 
108 struct LightDriverData {
109     struct IDeviceIoService ioService;
110     struct HdfDeviceObject *device;
111     HdfWorkQueue workQueue;
112     HdfWork work;
113     OsalTimer timer;
114     struct OsalMutex mutex;
115     uint32_t lightId;
116     uint32_t lightNum;
117     struct LightDeviceInfo *info[LIGHT_ID_BUTT];
118 };
119 
120 typedef int32_t (*LightCmdHandle)(uint32_t lightId, struct HdfSBuf *data, struct HdfSBuf *reply);
121 
122 struct LightCmdHandleList {
123     enum LightOpsCmd cmd;
124     LightCmdHandle func;
125 };
126 
127 #endif /* LIGHT_DRIVER_H */
128