• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
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 #pragma once
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include "hal_config.h"
22 #include "hal_port.h"
23 #include "gpio_ll.h"
24 #include "bk_icu.h"
25 
26 typedef struct {
27 	gpio_hw_t *hw;
28 	gpio_id_t gpio_id;
29 } gpio_hal_t;
30 
31 typedef struct {
32 	gpio_int_type_t gpio_int_type;
33 } gpio_hal_inttype_config_t;
34 
35 typedef struct {
36 	gpio_id_t id;
37 	gpio_dev_t dev[GPIO_PERI_FUNC_NUM];
38 } gpio_map_t;
39 
40 #if CONFIG_GPIO_WAKEUP_SUPPORT
41 typedef struct {
42 	gpio_id_t id;
43 	gpio_int_type_t int_type;
44 } gpio_wakeup_t;
45 #endif
46 
47 bk_err_t gpio_hal_init(gpio_hal_t *hal);
48 bk_err_t gpio_hal_disable_jtag_mode(gpio_hal_t *hal);
49 
50 bk_err_t gpio_hal_output_enable(gpio_hal_t *hal, gpio_id_t gpio_id, uint32 enable);
51 bk_err_t gpio_hal_input_enable(gpio_hal_t *hal, gpio_id_t gpio_id, uint32 enable);
52 bk_err_t gpio_hal_pull_up_enable(gpio_hal_t *hal, gpio_id_t gpio_id, uint32 enable);
53 bk_err_t gpio_hal_pull_enable(gpio_hal_t *hal, gpio_id_t gpio_id, uint32 enable);
54 bk_err_t gpio_hal_sencond_function_enable(gpio_hal_t *hal, gpio_id_t gpio_id, uint32 enable);
55 bk_err_t gpio_hal_monitor_input_enable(gpio_hal_t *hal, gpio_id_t gpio_id, uint32 enable);
56 
57 bk_err_t gpio_hal_set_capacity(gpio_hal_t *hal, gpio_id_t gpio_id, uint32 capacity);
58 bk_err_t gpio_hal_set_output_value(gpio_hal_t *hal, gpio_id_t gpio_id, uint32 output_value);
59 bk_err_t gpio_hal_get_input(gpio_hal_t *hal, gpio_id_t gpio_id);
60 
61 bk_err_t gpio_hal_set_int_type(gpio_hal_t *hal, gpio_id_t gpio_id, gpio_int_type_t type);
62 
63 bk_err_t gpio_hal_func_map(gpio_hal_t *hal, gpio_id_t id, gpio_dev_t dev);
64 bk_err_t gpio_hal_func_unmap(gpio_hal_t *hal, gpio_id_t gpio_id);
65 bk_err_t gpio_hal_set_config(gpio_hal_t *hal, gpio_id_t gpio_id, const gpio_config_t *config);
66 bk_err_t gpio_hal_devs_map(gpio_hal_t *hal, uint64 gpios, gpio_dev_t *devs, uint8 dev_num);
67 
68 bk_err_t gpio_hal_enable_interrupt(gpio_hal_t *hal, gpio_id_t gpio_id);
69 
70 #if CONFIG_GPIO_WAKEUP_SUPPORT
71 bk_err_t gpio_hal_bak_configs(uint16_t *gpio_cfg, uint32_t count);
72 bk_err_t gpio_hal_restore_configs(uint16_t *gpio_cfg, uint32_t count);
73 bk_err_t gpio_hal_bak_int_type_configs(uint32_t *gpio_int_type_cfg, uint32_t count);
74 bk_err_t gpio_hal_restore_int_type_configs(uint32_t *gpio_int_type_cfg, uint32_t count);
75 bk_err_t gpio_hal_bak_int_enable_configs(uint32_t *gpio_int_enable_cfg, uint32_t count);
76 bk_err_t gpio_hal_restore_int_enable_configs(uint32_t *gpio_int_enable_cfg, uint32_t count);
77 /* gpio switch to low power status:set all gpios to input mode */
78 bk_err_t gpio_hal_switch_to_low_power_status(void);
79 #else
80 bk_err_t gpio_hal_reg_save(uint32_t*  gpio_cfg);
81 bk_err_t gpio_hal_reg_restore(uint32_t*  gpio_cfg);
82 bk_err_t gpio_hal_wakeup_enable(int64_t index, uint64_t type_l, uint64_t type_h);
83 bk_err_t gpio_hal_wakeup_interrupt_clear();
84 #endif
85 
86 #define gpio_hal_disable_interrupt(hal, id)			gpio_ll_disable_interrupt((hal)->hw, id)
87 
88 #define gpio_hal_get_interrupt_status(hal, status)		gpio_ll_get_interrupt_status((hal)->hw, status)
89 #define gpio_hal_clear_interrupt_status(hal,status)		gpio_ll_clear_interrupt_status((hal)->hw, status)
90 #define gpio_hal_is_interrupt_triggered(hal, id,status)		gpio_ll_is_interrupt_triggered((hal)->hw, id, status)
91 #define gpio_hal_clear_chan_interrupt_status(hal, id)       gpio_ll_clear_chan_interrupt_status((hal)->hw, id)
92 
93 #if CFG_HAL_DEBUG_GPIO
94 void gpio_struct_dump(gpio_id_t gpio_index);
95 #else
96 #define gpio_struct_dump()
97 #endif
98 
99 #ifdef __cplusplus
100 }
101 #endif
102