当前位置:网站首页>Simple operation and debugging of GPIO in Qualcomm platform
Simple operation and debugging of GPIO in Qualcomm platform
2022-06-10 08:36:00 【bobuddy】
One 、gpio Debugging method of
stay Linux Next , adopt sysfs, obtain gpio state , It can also be operated gpio.
1、 obtain gpio state
cd /sys/kernel/debug/
cat gpio
2、 operation gpio( With gpio99 For example )
cd /sys/class/gpio/
echo 99 > export
cd gpio99
echo in/out > direction // Set up gpio Input or output
cat direction // obtain gpio I / O status
echo 'value' > value // Set up gpio Register values
cat value // obtain gpio Register value
Two 、 stay kernel Code operation gpio
There is... In the code Two ways to operate gpio, One is to apply for one at a time gpio, Manipulate the after success gpio, The other is to use pinctrl, Set through the device tree , Operate more than one at a time gpio.
1、 Method 1
Add... In the device node of the device tree gpio // Optional
device_node {
...
gpio_name = <&tlmm 99 0>; //gpio_99
...
}
Driver code :
int gpio_99 = of_get_named_gpio_flags(dev->of_node, "gpio_name", 0, NULL); // Number of slave devices node , Optional
gpio_request(gpio_99, "gpio_name"); // adopt gpio Application No gpio
gpio_direction_output(gpio_99, 1); // Set up gpio_99 Output , The initial value is 1
gpio_set_value(gpio_99, 0); // Set up gpio_99 The value is 0
gpio_free(gpio_99); //gpio_99 It should be released after it is no longer used
notes :
gpio The application and setting of may fail , Exception handling should be done well
2、 Method 2
Device tree code :
platform pinctrl Add... Under the node Add sub nodes :
For details of relevant documents and equipment tree configuration, see kernel/Document/pinctrl.txt and Documentation/devicetree/bindings/pinctrl/ Next multiple files
gpio_group {
gpio_active: gpio_active {
mux {
pins = "gpio99", "gpio98"; // Multiplexing pins 99 and 98
functions = "gpio"; // The pin function is configured as normal gpio
};
config {
pins = "gpio99", "gpio98";
drive-strength = <8>; // The maximum current limit is 8mA
bias-pull-up; // Configure pull-up
output-high; // Output high level
};
};
gpio_sleep: gpio_sleep {
mux {
pins = "gpio99", "gpio98"; // Multiplexing pins 99 and 98
functions = "gpio"; // The pin function is configured as normal gpio
};
config {
pins = "gpio99", "gpio98";
drive-strength = <2>; // The maximum current limit is 2mA
bias-no-pull; // No pull-up or pull-down
output-low; // Output low level
};
};
Reference... In the device node pinctrl:
device_node {
...
pinctrl-names = "gpio_active", "gpio_sleep"; // Use separately pinctrl-0 and pinctrl-1
pinctrl-0 = <&gpio_active>; // quote
pinctrl-1 = <&gpio_sleep>; // quote
...
};
Kernel driver code :
struct pinctrl *pinctrl = devm_pinctrl_get(device); // obtain device Under the corresponding node pinctrl
struct pinctrl_state = pinctrl_lookup_state(pinctrl, "gpio_active"); // adopt pinctrl Name acquisition pinctrl Corresponding state
pinctrl_select_state(pinctrl, pinctrl_state); // Set up pinctrl The status of is 'gpio_active
devm_pinctrl_put(pinctrl); // Release resources after use
Method 1 and method 2 can also be used at the same time , Method 1 is easy to operate , But it can only be pulled up or down , Method 2 can be fully configured GPIO. Using both method 1 and method 2 in a device driver can ensure that resources are not operated by other modules .
边栏推荐
- Model deployment
- 【Lingo】运算符
- R语言使用dplyr包的select函数自定义改变dataframe数据中两个数据列的顺序
- [lingo] operator
- [adjustment] South China Normal University (211, double first-class) zhuangzhengfei research group of biophotonics Research Institute, master enrollment
- Preparation computer database mysql +php the next day
- R语言e1071包的naiveBayes函数构建朴素贝叶斯模型、使用caret包的confusionMatrix函数计算混淆矩阵(kappa、置信区间、每个类别的评估指标、特异度、敏感度等)
- [lingo] linear programming
- R语言使用neuralnet包构建神经网络回归模型(前馈神经网络回归模型),plot函数可视化训练完成的神经网络模型(包含输入输出、模型结构、权重等信息)
- Test: Cup
猜你喜欢

光流法浅学

Ayutthaya, Bangkok, Thailand, was rated as "the most worthwhile city to visit in the post epidemic era" by Forbes

Test preparation database computer level 2 day 6

SqlServer不同数据库名的还原

【Lingo】运算符

【密码学】AES加解密

MIT dropped out of school and started from scratch. At the age of 25, he became the youngest billionaire in the world

How to use module export import: uncaught syntaxerror: cannot use import statement outside a module

How to prevent virus in business system

怎么用思维导图设计测试用例
随机推荐
被微软遗弃的神作《扫雷》,竟然被中国玩家玩出花?
Research Report on market supply and demand and strategy of China's underwater inflatable bag industry
Web安全渗透测试基本流程
Introduction to temporal database incluxdb
JS common time operation moment JS reference document
Research Report on market supply and demand and strategy of China's water-cooled xenon test chamber industry
A wordle Pendant
测试:朋友圈点赞功能
What objects are suitable for automated testing?
接口测试怎么进行,如何做好接口测试
嵌入式还有人关注吗?嵌入式测试需要关注哪些问题?
"Minesweeping", a masterpiece abandoned by Microsoft, has been played out by Chinese players?
Oracle SQL command line (II. View)
Swin UNET strongest split network
Link Time Optimizations: New Way to Do Compiler Optimizations
How to use mind mapping to design test cases
A must visit museum in London recommended by: London Museum of natural history
[lingo] linear programming
R语言使用epiDisplay包的pyramid函数可视化金字塔图
完美人生PerfectLife——角色:Chenyuxin