• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "nds_intrinsic.h"
24 
25 #include "../analog.h"
26 #include "../clock.h"
27 #include "../compatibility_pack/cmpt.h"
28 #include "../dma.h"
29 #include "../flash.h"
30 #include "../gpio.h"
31 #include "../mdec.h"
32 #include "../plic.h"
33 #include "../pm.h"
34 #include "../stimer.h"
35 #include "../sys.h"
36 #include "../timer.h"
37 #include "../trng.h"
38 
39 /**
40  * @brief     This function read a pin's cache from the buffer.
41  * @param[in] pin - the pin needs to read.
42  * @param[in] p - the buffer from which to read the pin's level.
43  * @return    the state of the pin.
44  */
gpio_read_cache(gpio_pin_e pin,unsigned char * p)45 static inline unsigned int gpio_read_cache(gpio_pin_e pin, unsigned char *p)
46 {
47     return p[pin >> 8] & (pin & 0xff);
48 }
49 
50 /**
51  * @brief      This function read all the pins' input level.
52  * @param[out] p - the buffer used to store all the pins' input level
53  * @return     none
54  */
gpio_read_all(unsigned char * p)55 static inline void gpio_read_all(unsigned char *p)
56 {
57     p[0] = REG_ADDR8(0x140300);
58     p[1] = REG_ADDR8(0x140308);
59     p[2] = REG_ADDR8(0x140310);
60     p[3] = REG_ADDR8(0x140318);
61     p[4] = REG_ADDR8(0x140320);
62 }
63 
64 /**
65  *  @brief  Define pull up or down types
66  */
67 typedef enum {
68     PM_PIN_UP_DOWN_FLOAT = 0,
69     PM_PIN_PULLUP_1M = 1,
70     PM_PIN_PULLDOWN_100K = 2,
71     PM_PIN_PULLUP_10K = 3,
72 } gpio_pull_type;
73 
74 /**
75  * @brief     This function set a pin's pull-up/down resistor.
76  * @param[in] gpio - the pin needs to set its pull-up/down resistor
77  * @param[in] up_down - the type of the pull-up/down resistor
78  * @return    none
79  */
80 void gpio_setup_up_down_resistor(gpio_pin_e gpio, gpio_pull_type up_down);
81 
82 #endif /* DRIVERS_B91_EXT_GPIO_H_ */
83