1 /*
2 * Copyright (c) 2022 Talkweb 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 #include <stdlib.h>
10 #include "hal_gpio.h"
11 #include "hal_exti.h"
12 #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
13 #include "hcs_macro.h"
14 #include "hdf_config_macro.h"
15 #else
16 #include "device_resource_if.h"
17 #endif
18 #include "gpio_core.h"
19 #include "hdf_log.h"
20 #include "osal_irq.h"
21
22 #define HDF_LOG_TAG gpio_stm_c
23
24 static const uint16_t g_stmRealPinMaps[STM32_GPIO_PIN_MAX] = {
25 LL_GPIO_PIN_0,
26 LL_GPIO_PIN_1,
27 LL_GPIO_PIN_2,
28 LL_GPIO_PIN_3,
29 LL_GPIO_PIN_4,
30 LL_GPIO_PIN_5,
31 LL_GPIO_PIN_6,
32 LL_GPIO_PIN_7,
33 LL_GPIO_PIN_8,
34 LL_GPIO_PIN_9,
35 LL_GPIO_PIN_10,
36 LL_GPIO_PIN_11,
37 LL_GPIO_PIN_12,
38 LL_GPIO_PIN_13,
39 LL_GPIO_PIN_14,
40 LL_GPIO_PIN_15,
41 };
42
43 typedef struct {
44 uint32_t group;
45 uint32_t realPin;
46 uint32_t pin;
47 } GpioInflectInfo;
48
49 GpioInflectInfo g_gpioPinsMap[STM32_GPIO_PIN_MAX * STM32_GPIO_GROUP_MAX] = {0};
50
51 static const GPIO_TypeDef* g_gpioxMaps[STM32_GPIO_GROUP_MAX] = {
52 GPIOA,
53 GPIOB,
54 GPIOC,
55 GPIOD,
56 GPIOE,
57 GPIOF,
58 GPIOG,
59 GPIOH,
60 GPIOI,
61 };
62
63 static const uint32_t g_gpioExitLineMap[STM32_GPIO_PIN_MAX] = {
64 LL_EXTI_LINE_0,
65 LL_EXTI_LINE_1,
66 LL_EXTI_LINE_2,
67 LL_EXTI_LINE_3,
68 LL_EXTI_LINE_4,
69 LL_EXTI_LINE_5,
70 LL_EXTI_LINE_6,
71 LL_EXTI_LINE_7,
72 LL_EXTI_LINE_8,
73 LL_EXTI_LINE_9,
74 LL_EXTI_LINE_10,
75 LL_EXTI_LINE_11,
76 LL_EXTI_LINE_12,
77 LL_EXTI_LINE_13,
78 LL_EXTI_LINE_14,
79 LL_EXTI_LINE_15,
80 };
81
82 typedef struct {
83 uint32_t pin;
84 uint32_t realPin;
85 uint32_t mode;
86 uint32_t group;
87 uint32_t pull;
88 uint32_t speed;
89 uint32_t outputType;
90 uint32_t alternate;
91 } GpioResource;
92
93 enum GpioDeviceState {
94 GPIO_DEVICE_UNINITIALIZED = 0x0u,
95 GPIO_DEVICE_INITIALIZED = 0x1u,
96 };
97
98 typedef struct {
99 uint32_t pinNums;
100 GpioResource resource;
101 STM32_GPIO_GROUP group; /* gpio config */
102 } GpioDevice;
103
104 static struct GpioCntlr g_stmGpioCntlr;
105
106 static HAL_GPIO_EXIT_CFG_T g_gpioExitCfg[STM32_GPIO_PIN_MAX * STM32_GPIO_GROUP_MAX] = {0};
107
OemGpioIrqHdl(uint32_t pin)108 static void OemGpioIrqHdl(uint32_t pin)
109 {
110 GpioCntlrIrqCallback(&g_stmGpioCntlr, pin);
111 return;
112 }
113
114 /* HdfDriverEntry method definitions */
115 static int32_t GpioDriverInit(struct HdfDeviceObject *device);
116 static void GpioDriverRelease(struct HdfDeviceObject *device);
117
118 /* HdfDriverEntry definitions */
119 struct HdfDriverEntry g_GpioDriverEntry = {
120 .moduleVersion = 1,
121 .moduleName = "ST_GPIO_MODULE_HDF",
122 .Init = GpioDriverInit,
123 .Release = GpioDriverRelease,
124 };
125 HDF_INIT(g_GpioDriverEntry);
126
127 /* GpioMethod method definitions */
128 static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val);
129 static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val);
130 static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir);
131 static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir);
132 static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode);
133 static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio);
134 static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio);
135 static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio);
136
137 /* GpioMethod definitions */
138 struct GpioMethod g_GpioCntlrMethod = {
139 .request = NULL,
140 .release = NULL,
141 .write = GpioDevWrite,
142 .read = GpioDevRead,
143 .setDir = GpioDevSetDir,
144 .getDir = GpioDevGetDir,
145 .toIrq = NULL,
146 .setIrq = GpioDevSetIrq,
147 .unsetIrq = GpioDevUnSetIrq,
148 .enableIrq = GpioDevEnableIrq,
149 .disableIrq = GpioDevDisableIrq,
150 };
151
InitGpioClock(STM32_GPIO_GROUP group)152 static void InitGpioClock(STM32_GPIO_GROUP group)
153 {
154 switch (group) {
155 case STM32_GPIO_GROUP_A:
156 LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
157 break;
158 case STM32_GPIO_GROUP_B:
159 LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
160 break;
161 case STM32_GPIO_GROUP_C:
162 LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOC);
163 break;
164 case STM32_GPIO_GROUP_D:
165 LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOD);
166 break;
167 case STM32_GPIO_GROUP_E:
168 LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOE);
169 break;
170 case STM32_GPIO_GROUP_F:
171 LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOF);
172 break;
173 case STM32_GPIO_GROUP_G:
174 LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOG);
175 break;
176 case STM32_GPIO_GROUP_H:
177 LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOH);
178 break;
179 case STM32_GPIO_GROUP_I:
180 LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOI);
181 break;
182 default:
183 break;
184 }
185 }
186
InitGpioDevice(const GpioDevice * device)187 static int32_t InitGpioDevice(const GpioDevice* device)
188 {
189 LL_GPIO_InitTypeDef gpioInitStruct = {0};
190 if (device == NULL) {
191 HDF_LOGE("%s: device is NULL", __func__);
192 return HDF_ERR_INVALID_PARAM;
193 }
194 uint32_t halGpio = g_stmRealPinMaps[device->resource.realPin];
195 if (halGpio > LL_GPIO_PIN_15 || halGpio < LL_GPIO_PIN_0) {
196 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, halGpio);
197 return HDF_ERR_NOT_SUPPORT;
198 }
199
200 /* init clock */
201 InitGpioClock(device->resource.group);
202
203 GPIO_TypeDef* goiox = g_gpioxMaps[device->resource.group];
204 if (device->resource.mode & LL_GPIO_MODE_OUTPUT) {
205 LL_GPIO_ResetOutputPin(goiox, halGpio);
206 }
207
208 gpioInitStruct.Pin = halGpio;
209 gpioInitStruct.Mode = device->resource.mode;
210 gpioInitStruct.Pull = device->resource.pull;
211 gpioInitStruct.Speed = device->resource.speed;
212 gpioInitStruct.OutputType = device->resource.outputType;
213 gpioInitStruct.Alternate = device->resource.alternate;
214 LL_GPIO_Init(goiox, &gpioInitStruct);
215
216 return HDF_SUCCESS;
217 }
218
219 #ifndef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
GpioParseHcs(const struct DeviceResourceIface * dri,GpioDevice * device,const struct DeviceResourceNode * resourceNode)220 static int32_t GpioParseHcs(const struct DeviceResourceIface *dri,
221 GpioDevice *device, const struct DeviceResourceNode *resourceNode)
222 {
223 GpioResource *resource = NULL;
224 resource = &device->resource;
225 if (resource == NULL) {
226 HDF_LOGE("%s: resource is NULL", __func__);
227 return HDF_ERR_INVALID_OBJECT;
228 }
229
230 if (dri->GetUint32(resourceNode, "pinNum", &device->pinNums, 0) != HDF_SUCCESS) {
231 HDF_LOGE("gpio config read pinNum fail");
232 return HDF_FAILURE;
233 }
234
235 for (size_t i = 0; i < device->pinNums; i++) {
236 if (dri->GetUint32ArrayElem(resourceNode, "pin", i, &resource->pin, 0) != HDF_SUCCESS) {
237 return HDF_FAILURE;
238 }
239
240 if (dri->GetUint32ArrayElem(resourceNode, "realPin", i, &resource->realPin, 0) != HDF_SUCCESS) {
241 return HDF_FAILURE;
242 }
243
244 if (dri->GetUint32ArrayElem(resourceNode, "mode", i, &resource->mode, 0) != HDF_SUCCESS) {
245 return HDF_FAILURE;
246 }
247
248 if (dri->GetUint32ArrayElem(resourceNode, "speed", i, &resource->speed, 0) != HDF_SUCCESS) {
249 return HDF_FAILURE;
250 }
251
252 if (dri->GetUint32ArrayElem(resourceNode, "pull", i, &resource->pull, 0) != HDF_SUCCESS) {
253 return HDF_FAILURE;
254 }
255
256 if (dri->GetUint32ArrayElem(resourceNode, "output", i, &resource->outputType, 0) != HDF_SUCCESS) {
257 return HDF_FAILURE;
258 }
259
260 if (dri->GetUint32ArrayElem(resourceNode, "group", i, &resource->group, 0) != HDF_SUCCESS) {
261 return HDF_FAILURE;
262 }
263
264 if (dri->GetUint32ArrayElem(resourceNode, "alternate", i, &resource->alternate, 0) != HDF_SUCCESS) {
265 return HDF_FAILURE;
266 }
267
268 g_gpioPinsMap[resource->pin].group = resource->group;
269 g_gpioPinsMap[resource->pin].realPin = resource->realPin;
270 g_gpioPinsMap[resource->pin].pin = resource->pin;
271
272 if (InitGpioDevice(device) != HDF_SUCCESS) {
273 HDF_LOGE("InitGpioDevice FAIL\r\n");
274 return HDF_FAILURE;
275 }
276 }
277
278 return HDF_SUCCESS;
279 }
280 #endif
281
282 #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
283 #define PLATFORM_GPIO_CONFIG HCS_NODE(HCS_NODE(HCS_ROOT, platform), gpio_config)
GetGpioDeviceResource(GpioDevice * device)284 static uint32_t GetGpioDeviceResource(GpioDevice *device)
285 {
286 GpioResource *resource = NULL;
287 if (device == NULL) {
288 HDF_LOGE("%s: device is NULL", __func__);
289 return HDF_ERR_INVALID_PARAM;
290 }
291 resource = &device->resource;
292 if (resource == NULL) {
293 HDF_LOGE("%s: resource is NULL", __func__);
294 return HDF_ERR_INVALID_OBJECT;
295 }
296 device->pinNums = HCS_PROP(PLATFORM_GPIO_CONFIG, pinNum);
297 uint32_t pins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pin));
298 uint32_t realPins[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, realPin));
299 uint32_t groups[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, group));
300 uint32_t modes[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, mode));
301 uint32_t speeds[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, speed));
302 uint32_t pulls[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, pull));
303 uint32_t outputs[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, output));
304 uint32_t alternates[] = HCS_ARRAYS(HCS_NODE(PLATFORM_GPIO_CONFIG, alternate));
305 for (size_t i = 0; i < device->pinNums; i++) {
306 resource->pin = pins[i];
307 resource->realPin = realPins[i];
308 resource->group = groups[i];
309 resource->mode = modes[i];
310 resource->speed = speeds[i];
311 resource->pull = pulls[i];
312 resource->outputType = outputs[i];
313 resource->alternate = alternates[i];
314 g_gpioPinsMap[resource->pin].group = resource->group;
315 g_gpioPinsMap[resource->pin].realPin = resource->realPin;
316 g_gpioPinsMap[resource->pin].pin = resource->pin;
317
318 if (InitGpioDevice(device) != HDF_SUCCESS) {
319 HDF_LOGE("InitGpioDevice FAIL\r\n");
320 return HDF_FAILURE;
321 }
322 }
323
324 return HDF_SUCCESS;
325 }
326 #else
GetGpioDeviceResource(GpioDevice * device,const struct DeviceResourceNode * resourceNode)327 static int32_t GetGpioDeviceResource(GpioDevice *device, const struct DeviceResourceNode *resourceNode)
328 {
329 struct DeviceResourceIface *dri = NULL;
330 if (device == NULL || resourceNode == NULL) {
331 HDF_LOGE("%s: device is NULL", __func__);
332 return HDF_ERR_INVALID_PARAM;
333 }
334
335 dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
336 if (dri == NULL || dri->GetUint32 == NULL) {
337 HDF_LOGE("DeviceResourceIface is invalid");
338 return HDF_ERR_INVALID_OBJECT;
339 }
340
341 if (GpioParseHcs(dri, device, resourceNode) != HDF_SUCCESS) {
342 HDF_LOGE("gpio config parse hcs fail");
343 return HDF_FAILURE;
344 }
345
346 return HDF_SUCCESS;
347 }
348 #endif
349
AttachGpioDevice(struct GpioCntlr * gpioCntlr,const struct HdfDeviceObject * device)350 static int32_t AttachGpioDevice(struct GpioCntlr *gpioCntlr, const struct HdfDeviceObject *device)
351 {
352 int32_t ret;
353
354 GpioDevice *gpioDevice = NULL;
355 #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
356 if (device == NULL) {
357 #else
358 if (device == NULL || device->property == NULL) {
359 #endif
360 HDF_LOGE("%s: property is NULL", __func__);
361 return HDF_ERR_INVALID_PARAM;
362 }
363
364 gpioDevice = (GpioDevice *)OsalMemAlloc(sizeof(GpioDevice));
365 if (gpioDevice == NULL) {
366 HDF_LOGE("%s: OsalMemAlloc gpioDevice error", __func__);
367 return HDF_ERR_MALLOC_FAIL;
368 }
369
370 #ifdef LOSCFG_DRIVERS_HDF_CONFIG_MACRO
371 ret = GetGpioDeviceResource(gpioDevice);
372 #else
373 ret = GetGpioDeviceResource(gpioDevice, device->property);
374 #endif
375 if (ret != HDF_SUCCESS) {
376 (void)OsalMemFree(gpioDevice);
377 return HDF_FAILURE;
378 }
379 gpioCntlr->priv = gpioDevice;
380 gpioCntlr->count = gpioDevice->pinNums;
381
382 return HDF_SUCCESS;
383 }
384
385 static int32_t GpioDriverInit(struct HdfDeviceObject *device)
386 {
387 int32_t ret;
388 struct GpioCntlr *gpioCntlr = NULL;
389
390 if (device == NULL) {
391 HDF_LOGE("%s: device is NULL", __func__);
392 return HDF_ERR_INVALID_PARAM;
393 }
394
395 ret = PlatformDeviceBind(&g_stmGpioCntlr.device, device);
396 if (ret != HDF_SUCCESS) {
397 HDF_LOGE("%s: bind hdf device failed:%d", __func__, ret);
398 return ret;
399 }
400
401 gpioCntlr = GpioCntlrFromHdfDev(device);
402 if (gpioCntlr == NULL) {
403 HDF_LOGE("GpioCntlrFromHdfDev fail\r\n");
404 return HDF_DEV_ERR_NO_DEVICE_SERVICE;
405 }
406
407 ret = AttachGpioDevice(gpioCntlr, device); /* GpioCntlr add GpioDevice to priv */
408 if (ret != HDF_SUCCESS) {
409 HDF_LOGE("AttachGpioDevice fail\r\n");
410 return HDF_DEV_ERR_ATTACHDEV_FAIL;
411 }
412
413 gpioCntlr->ops = &g_GpioCntlrMethod; /* register callback */
414 ret = GpioCntlrAdd(gpioCntlr);
415 if (ret != HDF_SUCCESS) {
416 HDF_LOGE("GpioCntlrAdd fail %d\r\n", gpioCntlr->start);
417 return HDF_FAILURE;
418 }
419
420 return HDF_SUCCESS;
421 }
422
423 static int32_t GpioDriverBind(struct HdfDeviceObject *device)
424 {
425 if (device == NULL) {
426 HDF_LOGE("device object is NULL\n");
427 return HDF_FAILURE;
428 }
429
430 return HDF_SUCCESS;
431 }
432
433 static void GpioDriverRelease(struct HdfDeviceObject *device)
434 {
435 struct GpioCntlr *gpioCntlr = NULL;
436
437 if (device == NULL) {
438 HDF_LOGE("%s: device is NULL", __func__);
439 return;
440 }
441
442 gpioCntlr = GpioCntlrFromHdfDev(device);
443 if (gpioCntlr == NULL) {
444 HDF_LOGE("%s: host is NULL", __func__);
445 return;
446 }
447
448 gpioCntlr->count = 0;
449 }
450
451 /* dev api */
452 static int32_t GpioDevWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val)
453 {
454 (void)cntlr;
455 uint16_t realPin = g_gpioPinsMap[gpio].realPin;
456 uint32_t pinReg = g_stmRealPinMaps[realPin];
457 if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
458 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
459 return HDF_ERR_NOT_SUPPORT;
460 }
461 HDF_LOGE("%s %d ,write pin num %d", __func__, __LINE__, realPin);
462 GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
463 if (val) {
464 LL_GPIO_SetOutputPin(gpiox, pinReg);
465 } else {
466 LL_GPIO_ResetOutputPin(gpiox, pinReg);
467 }
468
469 return HDF_SUCCESS;
470 }
471
472 static int32_t GpioDevRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val)
473 {
474 (void)cntlr;
475 uint16_t realPin = g_gpioPinsMap[gpio].realPin;
476 uint32_t pinReg = g_stmRealPinMaps[realPin];
477 uint16_t value = 0;
478 if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
479 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
480 return HDF_ERR_NOT_SUPPORT;
481 }
482
483 GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
484 value = LL_GPIO_ReadInputPin(gpiox, pinReg);
485 *val = value;
486
487 return HDF_SUCCESS;
488 }
489
490 static int32_t GpioDevSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir)
491 {
492 (void)cntlr;
493 uint16_t realPin = g_gpioPinsMap[gpio].realPin;
494 uint32_t pinReg = g_stmRealPinMaps[realPin];
495 if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
496 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
497 return HDF_ERR_NOT_SUPPORT;
498 }
499 GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
500 LL_GPIO_SetPinMode(gpiox, pinReg, dir);
501
502 return HDF_SUCCESS;
503 }
504
505 static int32_t GpioDevGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir)
506 {
507 (void)cntlr;
508 uint16_t realPin = g_gpioPinsMap[gpio].realPin;
509 uint32_t pinReg = g_stmRealPinMaps[realPin];
510 uint16_t value = 0;
511 if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
512 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
513 return HDF_ERR_NOT_SUPPORT;
514 }
515 GPIO_TypeDef* gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
516 value = LL_GPIO_GetPinMode(gpiox, pinReg);
517 *dir = value;
518
519 return HDF_SUCCESS;
520 }
521
522 static int32_t GpioDevSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode)
523 {
524 (void)cntlr;
525 uint16_t realPin = g_gpioPinsMap[gpio].realPin;
526 uint32_t pinReg = g_stmRealPinMaps[realPin];
527 if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
528 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
529 return HDF_ERR_NOT_SUPPORT;
530 }
531
532 if (mode == OSAL_IRQF_TRIGGER_RISING) {
533 g_gpioExitCfg[gpio].trigger = LL_EXTI_TRIGGER_RISING;
534 } else if (mode == OSAL_IRQF_TRIGGER_FALLING) {
535 g_gpioExitCfg[gpio].trigger = LL_EXTI_TRIGGER_FALLING;
536 } else {
537 HDF_LOGE("%s %d, error mode:%d", __func__, __LINE__, mode);
538 return HDF_ERR_NOT_SUPPORT;
539 }
540
541 return HDF_SUCCESS;
542 }
543
544 static int32_t GpioDevUnSetIrq(struct GpioCntlr *cntlr, uint16_t gpio)
545 {
546 (void)cntlr;
547 uint16_t realPin = g_gpioPinsMap[gpio].realPin;
548 uint32_t pinReg = g_stmRealPinMaps[realPin];
549 if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
550 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
551 return HDF_ERR_NOT_SUPPORT;
552 }
553
554 return HDF_SUCCESS;
555 }
556
557 static int32_t GpioDevEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
558 {
559 (void)cntlr;
560 LL_EXTI_InitConfig exitInitConfig = {0};
561 uint16_t realPin = g_gpioPinsMap[gpio].realPin;
562 uint32_t pinReg = g_stmRealPinMaps[realPin];
563 if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
564 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
565 return HDF_ERR_NOT_SUPPORT;
566 }
567
568 exitInitConfig.Exithandler = OemGpioIrqHdl;
569 exitInitConfig.Gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
570 exitInitConfig.initType.Line_0_31 = g_gpioExitLineMap[g_gpioPinsMap[gpio].realPin];
571 exitInitConfig.initType.LineCommand = ENABLE;
572 exitInitConfig.initType.Mode = LL_EXTI_MODE_IT;
573 exitInitConfig.PinReg = pinReg;
574 exitInitConfig.initType.Trigger = g_gpioExitCfg[gpio].trigger;
575
576 LL_SETUP_EXTI(&exitInitConfig, g_gpioPinsMap[gpio].realPin, gpio, g_gpioPinsMap[gpio].group);
577
578 return HDF_SUCCESS;
579 }
580
581 static int32_t GpioDevDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
582 {
583 (void)cntlr;
584 LL_EXTI_InitConfig exitInitConfig = {0};
585 uint16_t realPin = g_gpioPinsMap[gpio].realPin;
586 uint32_t pinReg = g_stmRealPinMaps[realPin];
587 if (pinReg > LL_GPIO_PIN_15 || pinReg < LL_GPIO_PIN_0) {
588 HDF_LOGE("%s %d, error pin:%d", __func__, __LINE__, realPin);
589 return HDF_ERR_NOT_SUPPORT;
590 }
591
592 exitInitConfig.Exithandler = NULL;
593 exitInitConfig.Gpiox = g_gpioxMaps[g_gpioPinsMap[gpio].group];
594 exitInitConfig.initType.Line_0_31 = g_gpioExitLineMap[g_gpioPinsMap[gpio].realPin];
595 exitInitConfig.initType.LineCommand = DISABLE;
596 exitInitConfig.initType.Mode = LL_EXTI_MODE_IT;
597 exitInitConfig.PinReg = pinReg;
598 exitInitConfig.initType.Trigger = g_gpioExitCfg[gpio].trigger;
599 LL_SETUP_EXTI(&exitInitConfig, g_gpioPinsMap[gpio].realPin, gpio, g_gpioPinsMap[gpio].group);
600
601 return HDF_SUCCESS;
602 }
603