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 #include "ext_gpio.h"
19 
20 
21 /**
22  * @brief     This function set a pin's pull-up/down resistor.
23  * @param[in] gpio - the pin needs to set its pull-up/down resistor
24  * @param[in] up_down - the type of the pull-up/down resistor
25  * @return    none
26  */
gpio_setup_up_down_resistor(gpio_pin_e gpio,gpio_pull_type up_down)27 void gpio_setup_up_down_resistor(gpio_pin_e gpio, gpio_pull_type up_down)
28 {
29 	unsigned char r_val = up_down & 0x03;
30 
31 	unsigned char base_ana_reg = 0x0e + ((gpio >> 8) << 1) + ( (gpio & 0xf0) ? 1 : 0 );  //group = gpio>>8;
32 	unsigned char shift_num, mask_not;
33 
34 	if(gpio & 0x11){
35 		shift_num = 0;
36 		mask_not = 0xfc;
37 	}
38 	else if(gpio & 0x22){
39 		shift_num = 2;
40 		mask_not = 0xf3;
41 	}
42 	else if(gpio & 0x44){
43 		shift_num = 4;
44 		mask_not = 0xcf;
45 	}
46 	else if(gpio & 0x88){
47 		shift_num = 6;
48 		mask_not = 0x3f;
49 	}
50 	else{
51 		return;
52 	}
53 
54     if(GPIO_DP == gpio){
55         //usb_dp_pullup_en (0);
56     }
57 
58     analog_write_reg8(base_ana_reg, (analog_read_reg8(base_ana_reg) & mask_not) | (r_val << shift_num));
59 }
60 
61