MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / gpio_set

Function gpio_set

bsp/loongson/ls1cdev/libraries/ls1c_gpio.c:130–170  ·  view source on GitHub ↗

* 在指定gpio输出高电平或低电平 * @gpio gpio引脚,取值范围[0, 127] * @level 电平值 * * 例: 在gpio50上输出低电平 * gpio_set(50, gpio_level_low); */

Source from the content-addressed store, hash-verified

128 * gpio_set(50, gpio_level_low);
129 */
130void gpio_set(unsigned int gpio, gpio_level_t level)
131{
132 volatile unsigned int *gpio_outx = NULL; // GPIO_OUTx寄存器
133 unsigned int port = GPIO_GET_PORT(gpio);
134 unsigned int pin = GPIO_GET_PIN(gpio);
135
136 // 获取寄存器地址
137 switch (port)
138 {
139 case 0:
140 gpio_outx = (volatile unsigned int *)LS1C_GPIO_OUT0;
141 break;
142
143 case 1:
144 gpio_outx = (volatile unsigned int *)LS1C_GPIO_OUT1;
145 break;
146
147 case 2:
148 gpio_outx = (volatile unsigned int *)LS1C_GPIO_OUT2;
149 break;
150
151 case 3:
152 gpio_outx = (volatile unsigned int *)LS1C_GPIO_OUT3;
153 break;
154
155 default: // 正确的程序不应该走到这里,直接返回
156 return ;
157 }
158
159 // 输出
160 if (gpio_level_low == level)
161 {
162 reg_clr_one_bit(gpio_outx, pin);
163 }
164 else
165 {
166 reg_set_one_bit(gpio_outx, pin);
167 }
168
169 return ;
170}
171
172
173/*

Callers 8

ls1c_pin_writeFunction · 0.50
ls1c_touch_irqhandlerFunction · 0.50
touch_initFunction · 0.50
ls1c_i2c_gpio_initFunction · 0.50
ls1c_set_sdaFunction · 0.50
ls1c_set_sclFunction · 0.50
gpio_direction_outputFunction · 0.50
gpio_set_valueFunction · 0.50

Calls 2

reg_clr_one_bitFunction · 0.70
reg_set_one_bitFunction · 0.70

Tested by

no test coverage detected