• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef _GPIO_API_H_
16 #define _GPIO_API_H_
17 
18 #include <stdint.h>
19 #include "plf.h"
20 
21 #define GPIOA_IDX_MAX   (16)
22 #define GPIOB_IDX_MAX   (16)
23 
24 #define GPIOIRQ_CB_PARAM(idx,evt)   (((idx) << 16) | evt)
25 #define GPIOIRQ_CB_EVENT(param)     ((param) & 0xFFFF)
26 #define GPIOIRQ_CB_INDEX(param)     ((param) >> 16)
27 
28 enum {
29     GPIODIR_INPUT = 0,
30     GPIODIR_OUTPUT
31 };
32 
33 enum {
34     GPIOVAL_LOW = 0,
35     GPIOVAL_HIGH
36 };
37 
38 enum {
39     GPIOIRQ_TYPE_EDGE_RISE = 0,
40     GPIOIRQ_TYPE_EDGE_FALL,
41     GPIOIRQ_TYPE_EDGE_BOTH
42 };
43 
44 enum {
45     GPIOIRQ_EVENT_EDGE_RISE = 0,
46     GPIOIRQ_EVENT_EDGE_FALL,
47     GPIOIRQ_EVENT_EDGE_BOTH
48 };
49 
50 typedef void (*gpio_irq_handler_t)(int event);
51 
52 // Simple APIs
53 void gpio_init  (int gpidx);
54 void gpio_deinit(int gpidx);
55 void gpio_dir_in(int gpidx);
56 void gpio_dir_out(int gpidx);
57 void gpio_set   (int gpidx);
58 void gpio_clr   (int gpidx);
59 int  gpio_get   (int gpidx);
60 void gpio_force_pull_up_enable(int gpidx);
61 void gpio_force_pull_dn_enable(int gpidx);
62 void gpio_force_pull_none_enable(int gpidx);
63 void gpio_force_pull_up_dn_disable(int gpidx);
64 void gpio_irq_en_set(int gpidx, int enable);
65 void gpio_irq_init(int gpidx, int type, gpio_irq_handler_t handler);
66 
67 #if PLF_PMIC
68 void gpiob_init  (int gpidx);
69 void gpiob_deinit(int gpidx);
70 void gpiob_dir_in(int gpidx);
71 void gpiob_dir_out(int gpidx);
72 void gpiob_set   (int gpidx);
73 void gpiob_clr   (int gpidx);
74 int  gpiob_get   (int gpidx);
75 void gpiob_force_pull_up_enable(int gpidx);
76 void gpiob_force_pull_dn_enable(int gpidx);
77 void gpiob_force_pull_none_enable(int gpidx);
78 void gpiob_force_pull_up_dn_disable(int gpidx);
79 void pmic_clock_set_for_gpiob(void);
80 void GPIOB_IRQHandler(void);
81 void gpiob_irq_history_set(uint32_t gpidx_bit);
82 void gpiob_irq_history_clear(uint32_t gpidx_bit);
83 uint32_t gpiob_irq_history_get(void);
84 void gpiob_irq_init(int gpidx, int type, gpio_irq_handler_t handler, int filter);
85 #endif
86 
87 #endif /* _GPIO_API_H_ */
88