1 /******************************************************************************
2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3 * All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************/
18
19 #ifndef DRIVERS_B91_EXT_GPIO_H_
20 #define DRIVERS_B91_EXT_GPIO_H_
21
22 #include "compiler.h"
23
24 #include "../analog.h"
25 #include "../dma.h"
26 #include "../gpio.h"
27 #include "../pm.h"
28 #include "../timer.h"
29 #include "../flash.h"
30 #include "../mdec.h"
31 #include "../trng.h"
32 #include "../sys.h"
33 #include "../plic.h"
34 #include "../stimer.h"
35 #include "../clock.h"
36 #include "../compatibility_pack/cmpt.h"
37
38 /**
39 * @brief This function read a pin's cache from the buffer.
40 * @param[in] pin - the pin needs to read.
41 * @param[in] p - the buffer from which to read the pin's level.
42 * @return the state of the pin.
43 */
gpio_read_cache(gpio_pin_e pin,unsigned char * p)44 static inline unsigned int gpio_read_cache(gpio_pin_e pin, unsigned char *p)
45 {
46 return p[pin>>8] & (pin & 0xff);
47 }
48
49 /**
50 * @brief This function read all the pins' input level.
51 * @param[out] p - the buffer used to store all the pins' input level
52 * @return none
53 */
gpio_read_all(unsigned char * p)54 static inline void gpio_read_all(unsigned char *p)
55 {
56 p[0] = REG_ADDR8(0x140300);
57 p[1] = REG_ADDR8(0x140308);
58 p[2] = REG_ADDR8(0x140310);
59 p[3] = REG_ADDR8(0x140318);
60 p[4] = REG_ADDR8(0x140320);
61 }
62
63 /**
64 * @brief Define pull up or down types
65 */
66 typedef enum {
67 PM_PIN_UP_DOWN_FLOAT = 0,
68 PM_PIN_PULLUP_1M = 1,
69 PM_PIN_PULLDOWN_100K = 2,
70 PM_PIN_PULLUP_10K = 3,
71 }gpio_pull_type;
72
73 /**
74 * @brief This function set a pin's pull-up/down resistor.
75 * @param[in] gpio - the pin needs to set its pull-up/down resistor
76 * @param[in] up_down - the type of the pull-up/down resistor
77 * @return none
78 */
79 void gpio_setup_up_down_resistor(gpio_pin_e gpio, gpio_pull_type up_down);
80
81
82
83 #endif /* DRIVERS_B91_EXT_GPIO_H_ */
84