1 /*
2 * Copyright (c) 2021-2022 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3 *
4 * This file 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 #include <stdlib.h>
10 #include "gpio_core.h"
11 #include "hal_gpio.h"
12 #include "hal_iomux.h"
13 #include "hdf_log.h"
14 #include "osal_irq.h"
15 #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
16 #include "hcs_macro.h"
17 #include "hdf_config_macro.h"
18 #else
19 #include "device_resource_if.h"
20 #endif
21
22 #define HDF_LOG_TAG GPIO_BES
23
24 /*
25 * Pin configuration
26 */
27 enum GPIO_CONFIG {
28 ANALOG_MODE, /* Used as a function pin, input and output analog */
29 IRQ_MODE, /* Used to trigger interrupt */
30 INPUT_PULL_UP, /* Input with an internal pull-up resistor - use with devices
31 that actively drive the signal low - e.g. button connected to ground */
32 INPUT_PULL_DOWN, /* Input with an internal pull-down resistor - use with devices
33 that actively drive the signal high - e.g. button connected to a power rail */
34 INPUT_HIGH_IMPEDANCE, /* Input - must always be driven, either actively or by an external pullup resistor */
35 OUTPUT_PUSH_PULL, /* Output actively driven high and actively driven low -
36 must not be connected to other active outputs - e.g. LED output */
37 OUTPUT_OPEN_DRAIN_NO_PULL, /* Output actively driven low but is high-impedance when set high -
38 can be connected to other open-drain/open-collector outputs.
39 Needs an external pull-up resistor */
40 OUTPUT_OPEN_DRAIN_PULL_UP, /* Output actively driven low and is pulled high
41 with an internal resistor when set high -
42 can be connected to other open-drain/open-collector outputs. */
43 };
44
45 struct GpioResource {
46 uint32_t pin;
47 uint32_t realPin;
48 uint32_t config;
49 uint32_t pinNum;
50 uint32_t type; /**< Type of the input event EV_KEY */
51 uint32_t code; /**< Specific code item of the input event KEY_POWER*/
52 unsigned long physBase;
53 };
54
55 enum GpioDeviceState {
56 GPIO_DEVICE_UNINITIALIZED = 0x0u,
57 GPIO_DEVICE_INITIALIZED = 0x1u,
58 };
59
60 struct GpioDevice {
61 uint8_t port; /* gpio port */
62 struct GpioResource resource;
63 enum GPIO_CONFIG config; /* gpio config */
64 };
65
66 typedef int32_t (*oem_gpio_irq_handler_t)(uint16_t gpio, void *data);
67
68 #define DECIMALNUM 10
69 #define OCTALNUM 8
70
71 static struct GpioCntlr g_gpioCntlr;
72
73 enum HAL_GPIO_PIN_T g_gpioPinReflectionMap[HAL_GPIO_PIN_LED_NUM] = {0};
74
75 static struct HAL_GPIO_IRQ_CFG_T g_gpioIrqCfg[HAL_GPIO_PIN_LED_NUM] = {0};
76
OemGpioIrqHdl(enum HAL_GPIO_PIN_T pin)77 static void OemGpioIrqHdl(enum HAL_GPIO_PIN_T pin)
78 {
79 if (pin >= HAL_GPIO_PIN_LED_NUM) {
80 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, pin);
81 return;
82 }
83 for (size_t i = 0; i < HAL_GPIO_PIN_LED_NUM; i++) {
84 if (pin == (enum HAL_GPIO_PIN_T)g_gpioPinReflectionMap[i]) {
85 GpioCntlrIrqCallback(&g_gpioCntlr, i);
86 return;
87 }
88 }
89 }
90
91 /* dispatch */
GpioDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)92 int32_t GpioDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
93 {
94 if (client == NULL || client->device == NULL || data == NULL || reply == NULL) {
95 HDF_LOGE("%s: client or client->device is NULL", __func__);
96 return HDF_ERR_INVALID_PARAM;
97 }
98 return HDF_SUCCESS;
99 }
100
101 /* HdfDriverEntry method definitions */
102 static int32_t GpioDriverInit(struct HdfDeviceObject *device);
103 static void GpioDriverRelease(struct HdfDeviceObject *device);
104
105 /* HdfDriverEntry definitions */
106 struct HdfDriverEntry g_GpioDriverEntry = {
107 .moduleVersion = 1,
108 .moduleName = "BES_GPIO_MODULE_HDF",
109 .Init = GpioDriverInit,
110 .Release = GpioDriverRelease,
111 };
112 HDF_INIT(g_GpioDriverEntry);
113
114 /* GpioMethod method definitions */
115 static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val);
116 static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val);
117 static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir);
118 static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir);
119 static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode);
120 static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio);
121 static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio);
122 static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio);
123 /* GpioMethod definitions */
124 struct GpioMethod g_GpioCntlrMethod = {
125 .request = NULL,
126 .release = NULL,
127 .write = GpioDevWrite,
128 .read = GpioDevRead,
129 .setDir = GpioDevSetDir,
130 .getDir = GpioDevGetDir,
131 .toIrq = NULL,
132 .setIrq = GpioDevSetIrq,
133 .unsetIrq = GpioDevUnSetIrq,
134 .enableIrq = GpioDevEnableIrq,
135 .disableIrq = GpioDevDisableIrq,
136 };
137
InitGpioDevice(struct GpioDevice * device)138 static int InitGpioDevice(struct GpioDevice *device)
139 {
140 struct HAL_IOMUX_PIN_FUNCTION_MAP gpioCfg;
141 if (device == NULL) {
142 HDF_LOGE("%s: device is NULL", __func__);
143 return HDF_ERR_INVALID_PARAM;
144 }
145 gpioCfg.pin = device->port;
146 gpioCfg.function = HAL_IOMUX_FUNC_AS_GPIO;
147 gpioCfg.volt = HAL_IOMUX_PIN_VOLTAGE_VIO;
148
149 if ((device->config == OUTPUT_PUSH_PULL) || (device->config == OUTPUT_OPEN_DRAIN_PULL_UP)
150 || (device->config == INPUT_PULL_UP) || (device->config == IRQ_MODE)) {
151 gpioCfg.pull_sel = HAL_IOMUX_PIN_PULLUP_ENABLE;
152 } else if ((device->config == INPUT_PULL_DOWN)) {
153 gpioCfg.pull_sel = HAL_IOMUX_PIN_PULLDOWN_ENABLE;
154 } else {
155 gpioCfg.pull_sel = HAL_IOMUX_PIN_NOPULL;
156 }
157
158 hal_iomux_init(&gpioCfg, 1);
159
160 return HDF_SUCCESS;
161 }
162 #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
163 #define PLATFORM_GPIO_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), gpio_config)
GetGpioDeviceResource(struct GpioDevice * device)164 static uint32_t GetGpioDeviceResource(struct GpioDevice *device)
165 {
166 uint32_t relPin;
167 int32_t ret;
168 struct GpioResource *resource = NULL;
169 if (device == NULL) {
170 HDF_LOGE("%s: device is NULL", __func__);
171 return HDF_ERR_INVALID_PARAM;
172 }
173 resource = &device->resource;
174 if (resource == NULL) {
175 HDF_LOGE("%s: resource is NULL", __func__);
176 return HDF_ERR_INVALID_OBJECT;
177 }
178 resource->pinNum = HCS_PROP(PLATFORM_GPIO_CONFIG, pinNum);
179 uint32_t pins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pin));
180 uint32_t realPins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, realPin));
181 uint32_t configs[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, config));
182 for (size_t i = 0; i < resource->pinNum; i++) {
183 resource->pin = pins[i];
184 resource->realPin = realPins[i];
185 resource->config = configs[i];
186
187 relPin = resource->realPin / DECIMALNUM * OCTALNUM + resource->realPin % DECIMALNUM;
188 g_gpioPinReflectionMap[resource->pin] = relPin;
189 device->config = resource->config;
190 resource->pin = relPin;
191 device->port = relPin;
192
193 ret = InitGpioDevice(device);
194 if (ret != HDF_SUCCESS) {
195 HDF_LOGE("InitGpioDevice FAIL\r\n");
196 return HDF_FAILURE;
197 }
198 }
199
200 return HDF_SUCCESS;
201 }
202 #else
GetGpioDeviceResource(struct GpioDevice * device,const struct DeviceResourceNode * resourceNode)203 static uint32_t GetGpioDeviceResource(struct GpioDevice *device, const struct DeviceResourceNode *resourceNode)
204 {
205 uint32_t relPin;
206 int32_t ret;
207 struct GpioResource *resource = NULL;
208 struct DeviceResourceIface *dri = NULL;
209 if (device == NULL || resourceNode == NULL) {
210 HDF_LOGE("%s: device is NULL", __func__);
211 return HDF_ERR_INVALID_PARAM;
212 }
213 resource = &device->resource;
214 if (resource == NULL) {
215 HDF_LOGE("%s: resource is NULL", __func__);
216 return HDF_ERR_INVALID_OBJECT;
217 }
218 dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
219 if (dri == NULL || dri->GetUint32 == NULL) {
220 HDF_LOGE("DeviceResourceIface is invalid");
221 return HDF_ERR_INVALID_OBJECT;
222 }
223
224 if (dri->GetUint32(resourceNode, "pinNum", &resource->pinNum, 0) != HDF_SUCCESS) {
225 HDF_LOGE("gpio config read pinNum fail");
226 return HDF_FAILURE;
227 }
228
229 for (size_t i = 0; i < resource->pinNum; i++) {
230 if (dri->GetUint32ArrayElem(resourceNode, "pin", i, &resource->pin, 0) != HDF_SUCCESS) {
231 HDF_LOGE("gpio config read pin fail");
232 return HDF_FAILURE;
233 }
234
235 if (dri->GetUint32ArrayElem(resourceNode, "realPin", i, &resource->realPin, 0) != HDF_SUCCESS) {
236 HDF_LOGE("gpio config read realPin fail");
237 return HDF_FAILURE;
238 }
239
240 if (dri->GetUint32ArrayElem(resourceNode, "config", i, &resource->config, 0) != HDF_SUCCESS) {
241 HDF_LOGE("gpio config read config fail");
242 return HDF_FAILURE;
243 }
244
245 relPin = resource->realPin / DECIMALNUM * OCTALNUM + resource->realPin % DECIMALNUM;
246 g_gpioPinReflectionMap[resource->pin] = relPin;
247 device->config = resource->config;
248 resource->pin = relPin;
249 device->port = relPin;
250
251 ret = InitGpioDevice(device);
252 if (ret != HDF_SUCCESS) {
253 HDF_LOGE("InitGpioDevice FAIL\r\n");
254 return HDF_FAILURE;
255 }
256 }
257 return HDF_SUCCESS;
258 }
259 #endif
260
AttachGpioDevice(struct GpioCntlr * gpioCntlr,struct HdfDeviceObject * device)261 static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, struct HdfDeviceObject *device)
262 {
263 int32_t ret;
264
265 struct GpioDevice *gpioDevice = NULL;
266 #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
267 if (device == NULL) {
268 #else
269 if (device == NULL || device->property == NULL) {
270 #endif
271 HDF_LOGE("%s: param is NULL", __func__);
272 return HDF_ERR_INVALID_PARAM;
273 }
274
275 gpioDevice = (struct GpioDevice *)OsalMemAlloc(sizeof(struct GpioDevice));
276 if (gpioDevice == NULL) {
277 HDF_LOGE("%s: OsalMemAlloc gpioDevice error", __func__);
278 return HDF_ERR_MALLOC_FAIL;
279 }
280 #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
281 ret = GetGpioDeviceResource(gpioDevice);
282 #else
283 ret = GetGpioDeviceResource(gpioDevice, device->property);
284 #endif
285 if (ret != HDF_SUCCESS) {
286 OsalMemFree(gpioDevice);
287 return HDF_FAILURE;
288 }
289
290 gpioCntlr->count = gpioDevice->resource.pinNum;
291 gpioCntlr->priv = (void *)gpioDevice;
292 return HDF_SUCCESS;
293 }
294
295 static int32_t GpioDriverInit(struct HdfDeviceObject *device)
296 {
297 int32_t ret;
298 struct GpioCntlr *gpioCntlr = NULL;
299
300 if (device == NULL) {
301 HDF_LOGE("%s: device is NULL", __func__);
302 return HDF_ERR_INVALID_PARAM;
303 }
304
305 ret = PlatformDeviceBind(&g_gpioCntlr.device, device);
306 if (ret != HDF_SUCCESS) {
307 HDF_LOGE("%s: bind hdf device failed:%d", __func__, ret);
308 return ret;
309 }
310
311 gpioCntlr = GpioCntlrFromHdfDev(device);
312 if (gpioCntlr == NULL) {
313 HDF_LOGE("GpioCntlrFromHdfDev fail\r\n");
314 return HDF_DEV_ERR_NO_DEVICE_SERVICE;
315 }
316
317 ret = AttachGpioDevice(gpioCntlr, device); // GpioCntlr add GpioDevice to priv
318 if (ret != HDF_SUCCESS) {
319 HDF_LOGE("AttachGpioDevice fail\r\n");
320 return HDF_DEV_ERR_ATTACHDEV_FAIL;
321 }
322
323 gpioCntlr->ops = &g_GpioCntlrMethod; // register callback
324 ret = GpioCntlrAdd(gpioCntlr);
325 if (ret != HDF_SUCCESS) {
326 HDF_LOGE("GpioCntlrAdd fail %d\r\n", gpioCntlr->start);
327 return HDF_FAILURE;
328 }
329 return HDF_SUCCESS;
330 }
331
332 static void GpioDriverRelease(struct HdfDeviceObject *device)
333 {
334 struct GpioCntlr *gpioCntlr = NULL;
335
336 if (device == NULL) {
337 HDF_LOGE("%s: device is NULL", __func__);
338 return;
339 }
340
341 gpioCntlr = GpioCntlrFromHdfDev(device);
342 if (gpioCntlr == NULL) {
343 HDF_LOGE("GpioCntlrFromHdfDev fail\r\n");
344 return HDF_DEV_ERR_NO_DEVICE_SERVICE;
345 }
346
347 gpioCntlr->ops = NULL;
348 OsalMemFree(gpioCntlr->priv);
349 gpioCntlr->count = 0;
350 }
351
352 /* dev api */
353 static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val)
354 {
355 (void)cntlr;
356 if (gpio >= HAL_GPIO_PIN_LED_NUM) {
357 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio);
358 return HDF_ERR_NOT_SUPPORT;
359 }
360 uint16_t halGpio = g_gpioPinReflectionMap[gpio];
361 if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) {
362 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio);
363 return HDF_ERR_NOT_SUPPORT;
364 }
365
366 hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)halGpio, HAL_GPIO_DIR_OUT, val);
367
368 return HDF_SUCCESS;
369 }
370
371 static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val)
372 {
373 (void)cntlr;
374 uint16_t value;
375 if (gpio >= HAL_GPIO_PIN_LED_NUM) {
376 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio);
377 return HDF_ERR_NOT_SUPPORT;
378 }
379 uint16_t halGpio = g_gpioPinReflectionMap[gpio];
380 if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) {
381 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio);
382 return HDF_ERR_NOT_SUPPORT;
383 }
384
385 value = (uint16_t)hal_gpio_pin_get_val((enum HAL_GPIO_PIN_T)halGpio);
386 *val = value;
387
388 return HDF_SUCCESS;
389 }
390
391 static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir)
392 {
393 (void)cntlr;
394 if (gpio >= HAL_GPIO_PIN_LED_NUM) {
395 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio);
396 return HDF_ERR_NOT_SUPPORT;
397 }
398 uint16_t halGpio = g_gpioPinReflectionMap[gpio];
399 if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) {
400 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio);
401 return HDF_ERR_NOT_SUPPORT;
402 }
403
404 hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)halGpio, (enum HAL_GPIO_DIR_T)dir, 0);
405
406 return HDF_SUCCESS;
407 }
408
409 static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir)
410 {
411 (void)cntlr;
412 uint16_t value;
413 if (gpio >= HAL_GPIO_PIN_LED_NUM) {
414 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio);
415 return HDF_ERR_NOT_SUPPORT;
416 }
417 uint16_t halGpio = g_gpioPinReflectionMap[gpio];
418 if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) {
419 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio);
420 return HDF_ERR_NOT_SUPPORT;
421 }
422
423 value = (uint16_t)hal_gpio_pin_get_dir((enum HAL_GPIO_PIN_T)halGpio);
424 *dir = value;
425
426 return HDF_SUCCESS;
427 }
428
429 static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode)
430 {
431 (void)cntlr;
432 if (gpio >= HAL_GPIO_PIN_LED_NUM) {
433 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio);
434 return HDF_ERR_NOT_SUPPORT;
435 }
436 enum HAL_GPIO_PIN_T pin = (enum HAL_GPIO_PIN_T)g_gpioPinReflectionMap[gpio];
437 if (pin >= HAL_GPIO_PIN_LED_NUM) {
438 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, pin);
439 return HDF_ERR_NOT_SUPPORT;
440 }
441
442 if ((mode == OSAL_IRQF_TRIGGER_RISING) || (mode == OSAL_IRQF_TRIGGER_FALLING)) {
443 g_gpioIrqCfg[pin].irq_type = HAL_GPIO_IRQ_TYPE_EDGE_SENSITIVE;
444 } else if ((mode == OSAL_IRQF_TRIGGER_HIGH) || (mode == OSAL_IRQF_TRIGGER_LOW)) {
445 g_gpioIrqCfg[pin].irq_type = HAL_GPIO_IRQ_TYPE_LEVEL_SENSITIVE;
446 } else {
447 HDF_LOGE("%s %d, error mode:%hu", __func__, __LINE__, mode);
448 return HDF_ERR_NOT_SUPPORT;
449 }
450
451 if (mode == OSAL_IRQF_TRIGGER_HIGH || mode == OSAL_IRQF_TRIGGER_RISING) {
452 mode = HAL_GPIO_IRQ_POLARITY_HIGH_RISING;
453 } else {
454 mode = HAL_GPIO_IRQ_POLARITY_LOW_FALLING;
455 }
456
457 g_gpioIrqCfg[pin].irq_polarity = mode;
458
459 return HDF_SUCCESS;
460 }
461
462 static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio)
463 {
464 (void)cntlr;
465 if (gpio >= HAL_GPIO_PIN_LED_NUM) {
466 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio);
467 return HDF_ERR_NOT_SUPPORT;
468 }
469 enum HAL_GPIO_PIN_T pin = (enum HAL_GPIO_PIN_T)g_gpioPinReflectionMap[gpio];
470 if (pin >= HAL_GPIO_PIN_LED_NUM) {
471 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, pin);
472 return HDF_ERR_NOT_SUPPORT;
473 }
474
475 return HDF_SUCCESS;
476 }
477
478 static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
479 {
480 (void)cntlr;
481 struct HAL_GPIO_IRQ_CFG_T gpioCfg;
482 if (gpio >= HAL_GPIO_PIN_LED_NUM) {
483 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio);
484 return HDF_ERR_NOT_SUPPORT;
485 }
486 uint16_t halGpio = (enum HAL_GPIO_PIN_T)g_gpioPinReflectionMap[gpio];
487 if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) {
488 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, (enum HAL_GPIO_PIN_T)halGpio);
489 return HDF_ERR_NOT_SUPPORT;
490 }
491
492 hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)halGpio, HAL_GPIO_DIR_IN, 0);
493
494 gpioCfg.irq_enable = true;
495 gpioCfg.irq_debounce = true;
496 gpioCfg.irq_polarity = g_gpioIrqCfg[(enum HAL_GPIO_PIN_T)halGpio].irq_polarity;
497 gpioCfg.irq_handler = OemGpioIrqHdl;
498 gpioCfg.irq_type = g_gpioIrqCfg[(enum HAL_GPIO_PIN_T)halGpio].irq_type;
499 g_gpioIrqCfg[halGpio] = gpioCfg;
500
501 hal_gpio_setup_irq((enum HAL_GPIO_PIN_T)halGpio, &gpioCfg);
502
503 return HDF_SUCCESS;
504 }
505
506 static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
507 {
508 (void)cntlr;
509 if (gpio >= HAL_GPIO_PIN_LED_NUM) {
510 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, gpio);
511 return HDF_ERR_NOT_SUPPORT;
512 }
513 uint16_t halGpio = (enum HAL_GPIO_PIN_T)g_gpioPinReflectionMap[gpio];
514 if ((enum HAL_GPIO_PIN_T)halGpio >= HAL_GPIO_PIN_LED_NUM) {
515 HDF_LOGE("%s %d, error pin:%hu", __func__, __LINE__, halGpio);
516 return HDF_ERR_NOT_SUPPORT;
517 }
518
519 const struct HAL_GPIO_IRQ_CFG_T gpioCfg = {
520 .irq_enable = false,
521 .irq_debounce = false,
522 .irq_polarity = HAL_GPIO_IRQ_POLARITY_LOW_FALLING,
523 .irq_handler = NULL,
524 .irq_type = HAL_GPIO_IRQ_TYPE_EDGE_SENSITIVE,
525 };
526
527 hal_gpio_setup_irq((enum HAL_GPIO_PIN_T)halGpio, &gpioCfg);
528
529 return HDF_SUCCESS;
530 }
531