三种方式控制GPIO
BBB为REV C,emmc4G版本,系统为Debian 7.9 wheezy (2015.11.12),内核为Linux 3.8.13.使用命令cat /etc/dogtag查看
查看系统信息的四种方式
uname -a
lsb_release -a
cat /proc/version
sudo cat /etc/dogtag
cd /opt/scripts/tools
./version.sh
这次先从GPIO控制开始,目标是user led。板子上四个led的定义为:
- USR0 is configured at boot to blink in a heartbeat pattern-------------------------running
- USR1 is configured at boot to light during microSD card accesses-------------micro SD
- USR2 is configured at boot to light during CPU activity----------------------------CPU
- USR3 is configured at boot to light during eMMC accesses----------------------emmc
1. 命令行控制
以GPIO user led 3为例
这样就可以控制usr LED3的亮灭了。
quectel模块net status led灯控制举例:
root@mdm9607-perf:/sys/class/leds# ls
net_status
root@mdm9607-perf:/sys/class/leds# cd net_status/
root@mdm9607-perf:/sys/devices/soc:leds_gpio/leds/net_status# ls
brightness delay_on max_brightness subsystem uevent
delay_off device power trigger
root@mdm9607-perf:/sys/devices/soc:leds_gpio/leds/net_status# ls -AlF
total
-rw-r--r-- root root Jan brightness
-rw-r--r-- root root Jan : delay_off
-rw-r--r-- root root Jan : delay_on
lrwxrwxrwx root root Jan device -> ../../../soc:leds_gpio/
-rw-r--r-- root root Jan max_brightness
drwxr-xr-x root root Jan power/
lrwxrwxrwx root root Jan subsystem -> ../../../../class/leds/
-rw-r--r-- root root Jan trigger
-rw-r--r-- root root Jan uevent
root@mdm9607-perf:/sys/devices/soc:leds_gpio/leds/net_status# cat trigger
none usb-online rfkill0 [timer]
root@mdm9607-perf:/sys/devices/soc:leds_gpio/leds/net_status# echo none>trigger
root@mdm9607-perf:/sys/devices/soc:leds_gpio/leds/net_status# echo > brightnes
s
root@mdm9607-perf:/sys/devices/soc:leds_gpio/leds/net_status# echo > brightnes
这样就可以控制net status led的亮灭了。
它的System Reference Manual (SRM)文档在Hardware 部分下载p66页中
1.1 查看占用的引脚
我们查看目前已经使用的引脚及其寄存器地址:
root:/sys/kernel/debug/pinctrl/44e10800.pinmux# cat pingroups
registered pin groups:
group: pinmux_userled_pins
pin 21 (44e10854)
pin 22 (44e10858)
pin 23 (44e1085c)
pin 24 (44e10860)
group: pinmux_rstctl_pins
pin 20 (44e10850)
group: pinmux_i2c0_pins
pin 98 (44e10988)
pin 99 (44e1098c)
group: pinmux_i2c2_pins
pin 94 (44e10978)
pin 95 (44e1097c)
group: pinmux_mmc1_pins
pin 88 (44e10960)!!!!!!!!!not have this one
group: pinmux_emmc2_pins
pin 32 (44e10880)
pin 33 (44e10884)
pin 0 (44e10800)
pin 1 (44e10804)
pin 2 (44e10808)
pin 3 (44e1080c)
pin 4 (44e10810)
pin 5 (44e10814)
pin 6 (44e10818)
pin 7 (44e1081c)
group: pinmux_userled_pins
pin 21 (44e10854)
pin 22 (44e10858)
pin 23 (44e1085c)
pin 24 (44e10860)
group: mcasp0_pins
pin 107 (44e109ac)
pin 103 (44e1099c)
pin 101 (44e10994)
pin 100 (44e10990)
pin 27 (44e1086c)!!!!!!!!!pin 106 (44e109a8)
group: nxp_hdmi_bonelt_pins
pin 108 (44e109b0)
pin 40 (44e108a0)
pin 41 (44e108a4)
pin 42 (44e108a8)
pin 43 (44e108ac)
pin 44 (44e108b0)
pin 45 (44e108b4)
pin 46 (44e108b8)
pin 47 (44e108bc)
pin 48 (44e108c0)
pin 49 (44e108c4)
pin 50 (44e108c8)
pin 51 (44e108cc)
pin 52 (44e108d0)
pin 53 (44e108d4)
pin 54 (44e108d8)
pin 55 (44e108dc)
pin 56 (44e108e0)
pin 57 (44e108e4)
pin 58 (44e108e8)
pin 59 (44e108ec)
group: nxp_hdmi_bonelt_off_pins
pin 108 (44e109b0)
1.2 查看所有引脚
所有引脚的功能
root:/sys/kernel/debug/pinctrl/44e10800.pinmux# cat pinmux-pins
Pinmux settings per pin
Format: pin (name): mux_owner gpio_owner hog?
pin 0 (44e10800): mmc.11 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 1 (44e10804): mmc.11 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 2 (44e10808): mmc.11 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 3 (44e1080c): mmc.11 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 4 (44e10810): mmc.11 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 5 (44e10814): mmc.11 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 6 (44e10818): mmc.11 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 7 (44e1081c): mmc.11 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 8 (44e10820): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 9 (44e10824): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 10 (44e10828): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 11 (44e1082c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 12 (44e10830): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 13 (44e10834): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 14 (44e10838): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 15 (44e1083c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 16 (44e10840): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 17 (44e10844): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 18 (44e10848): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 19 (44e1084c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 20 (44e10850): rstctl.4 (GPIO UNCLAIMED) function pinmux_rstctl_pins group pinmux_rstctl_pins
pin 21 (44e10854): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 22 (44e10858): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 23 (44e1085c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 24 (44e10860): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 25 (44e10864): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 26 (44e10868): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 27 (44e1086c): 48038000.mcasp (GPIO UNCLAIMED) function mcasp0_pins group mcasp0_pins
pin 28 (44e10870): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 29 (44e10874): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 30 (44e10878): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 31 (44e1087c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 32 (44e10880): mmc.11 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 33 (44e10884): mmc.11 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 34 (44e10888): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 35 (44e1088c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 36 (44e10890): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 37 (44e10894): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 38 (44e10898): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 39 (44e1089c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 40 (44e108a0): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 41 (44e108a4): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 42 (44e108a8): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 43 (44e108ac): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 44 (44e108b0): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 45 (44e108b4): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 46 (44e108b8): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 47 (44e108bc): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 48 (44e108c0): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 49 (44e108c4): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 50 (44e108c8): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 51 (44e108cc): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 52 (44e108d0): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 53 (44e108d4): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 54 (44e108d8): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 55 (44e108dc): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 56 (44e108e0): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 57 (44e108e4): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 58 (44e108e8): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 59 (44e108ec): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 60 (44e108f0): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 61 (44e108f4): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 62 (44e108f8): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 63 (44e108fc): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 64 (44e10900): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 65 (44e10904): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 66 (44e10908): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 67 (44e1090c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 68 (44e10910): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 69 (44e10914): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 70 (44e10918): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 71 (44e1091c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 72 (44e10920): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 73 (44e10924): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 74 (44e10928): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 75 (44e1092c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 76 (44e10930): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 77 (44e10934): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 78 (44e10938): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 79 (44e1093c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 80 (44e10940): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 81 (44e10944): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 82 (44e10948): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 83 (44e1094c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 84 (44e10950): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 85 (44e10954): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 86 (44e10958): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 87 (44e1095c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 88 (44e10960): mmc.5 (GPIO UNCLAIMED) function pinmux_mmc1_pins group pinmux_mmc1_pins
pin 89 (44e10964): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 90 (44e10968): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 91 (44e1096c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 92 (44e10970): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 93 (44e10974): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 94 (44e10978): 4819c000.i2c (GPIO UNCLAIMED) function pinmux_i2c2_pins group pinmux_i2c2_pins
pin 95 (44e1097c): 4819c000.i2c (GPIO UNCLAIMED) function pinmux_i2c2_pins group pinmux_i2c2_pins
pin 96 (44e10980): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 97 (44e10984): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 98 (44e10988): 44e0b000.i2c (GPIO UNCLAIMED) function pinmux_i2c0_pins group pinmux_i2c0_pins
pin 99 (44e1098c): 44e0b000.i2c (GPIO UNCLAIMED) function pinmux_i2c0_pins group pinmux_i2c0_pins
pin 100 (44e10990): 48038000.mcasp (GPIO UNCLAIMED) function mcasp0_pins group mcasp0_pins
pin 101 (44e10994): 48038000.mcasp (GPIO UNCLAIMED) function mcasp0_pins group mcasp0_pins
pin 102 (44e10998): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 103 (44e1099c): 48038000.mcasp (GPIO UNCLAIMED) function mcasp0_pins group mcasp0_pins
pin 104 (44e109a0): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 105 (44e109a4): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 106 (44e109a8): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 107 (44e109ac): 48038000.mcasp (GPIO UNCLAIMED) function mcasp0_pins group mcasp0_pins
pin 108 (44e109b0): hdmi.13 (GPIO UNCLAIMED) function nxp_hdmi_bonelt_pins group nxp_hdmi_bonelt_pins
pin 109 (44e109b4): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 110 (44e109b8): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 111 (44e109bc): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 112 (44e109c0): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 113 (44e109c4): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 114 (44e109c8): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 115 (44e109cc): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 116 (44e109d0): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 117 (44e109d4): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 118 (44e109d8): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 119 (44e109dc): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 120 (44e109e0): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 121 (44e109e4): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 122 (44e109e8): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 123 (44e109ec): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 124 (44e109f0): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 125 (44e109f4): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 126 (44e109f8): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 127 (44e109fc): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 128 (44e10a00): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 129 (44e10a04): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 130 (44e10a08): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 131 (44e10a0c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 132 (44e10a10): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 133 (44e10a14): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 134 (44e10a18): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 135 (44e10a1c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 136 (44e10a20): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 137 (44e10a24): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 138 (44e10a28): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 139 (44e10a2c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 140 (44e10a30): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 141 (44e10a34): (MUX UNCLAIMED) (GPIO UNCLAIMED)
因为系统已经占用了很多引脚,为了方便,我们选择下图中带有GPIO的引脚来操作
P9-15 GPIO1_16 = 1 x 32 + 16 = GPIO 48
如果在P9-15接个led就会点亮它。使用完毕以后记得unexported。
https://elinux.org/EBC_Exercise_07_Updating_an_Old_U-Boot
cd /opt/scripts/tools
config-pin -q P9_15
1.3 引脚模式详解
(查表知道P9-15 GPIO1_16 GPIO48 Offset 0x040)
注意:GPIO 48 is not PIN 48!!!
GPIO地址为44e10840 #pinmux_pins中的16号
事实上我们看到GPIO 48它对应于pin 16,所以不要想当然。
这里发现引脚模式0x27为0010 0111,它是什么意思呢?
我们看AM3358的技术手册,AM335x Sitara Processors Technical Reference Manual (Rev. M).pdf点击打开链接 搜索关键字“conf_<module>”Page 1426
010 0111, Fast, Receiver enable, pull down selected, pull up/pull down enable, mux select mode7, 所以整个含义就是INPUT GPIO(mode7) pulldown, 下拉输入。
BBB_SRM Page 86页
0x07 means 000 0111 = Fast, Disable Receiver, Pulldown type, enabled, mux mode 7.下拉输出
0x17 means 001 0111 = Fast, Disable Receiver, Pullup type, enabled, mux mode 7.上拉输出
0x27 means 010 0111 = Fast, Enable Receiver, Pulldown type, enabled, mux mode 7.下拉输入
0x37 means 011 0111 = Fast, Enable Receiver, Pullup type, enabled, mux mode 7. 上拉输入
注意这也不是绝对的,例如pins GPIO2_6 到 GPIO2_14 都有 42.2k 下拉电阻 到 GND 并且 100k 上拉电阻。SRM Page 74
2. C++程序控制
这里仍旧控制Usr Led3,程序如下:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
#define LED3_PATH "/sys/class/leds/beaglebone:green:usr3"
void writeLED(string filename, string value){
fstream fs;
string path(LED3_PATH);
fs.open((path + filename).c_str(), fstream::out);
fs << value;
fs.close();
}
void removeTrigger(){
writeLED("/trigger", "none");
}
int main(int argc, char* argv[]){
if(argc!=2){
cout << "Usage is makeLED and one of: " << endl;
cout << " on, off, flash or status" << endl;
cout << " e.g. makeLED flash" << endl;
return 2;
}
string cmd(argv[1]);
cout << "Starting the makeLED program" << endl;
cout << "The current LED Path is: " << LED3_PATH << endl;
// select whether command is on, off, flash or status
if(cmd=="on"){
cout << "Turning the LED on" << endl;
removeTrigger();
writeLED("/brightness", "1");
}
else if (cmd=="off"){
cout << "Turning the LED off" << endl;
removeTrigger();
writeLED("/brightness", "0");
}
else if (cmd=="flash"){
cout << "Flashing the LED" << endl;
writeLED("/trigger", "timer");
writeLED("/delay_on", "50");
writeLED("/delay_off", "50");
}
else if (cmd=="status"){
// display the current trigger details
std::fstream fs;
fs.open( LED3_PATH "/trigger", std::fstream::in);
string line;
while(getline(fs,line)) cout << line << endl;
fs.close();
}
else{
cout << "Invalid command!" << endl;
}
cout << "Finished the makeLED Program" << endl;
return 0;
}
2.1 利用软链接,根据指令来执行程序
主程序makeLEDmulti.cpp
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
#define LED3_PATH "/sys/class/leds/beaglebone:green:usr3"
void writeLED(string filename, string value){
fstream fs;
string path(LED3_PATH);
fs.open((path + filename).c_str(), fstream::out);
fs << value;
fs.close();
}
void removeTrigger(){
writeLED("/trigger", "none");
}
bool endsWith(string const &in, string const &comp){
//int compare(int pos, int n,const string &s)const;//比较当前字符串从pos开始的n个字符组成的字符串与s的大小
return (0 == in.compare(in.length()-comp.length(), comp.length(), comp));//比较in字符串从相减结果个字符开始的comp.length组成的字符串与comp的大小
// onled onled; 5-5, 5, onled
// offled onled; 6-5, 5, onled
}
int main(int argc, char* argv[]){
if(argc!=2){
cout << "Usage is makeLEDmulti is by calling one of: " << endl;
cout << " flashled, onled, offled, ledstatus" << endl;
cout << " e.g. sudo ./flashled" << endl;
}
string cmd(argv[0]);
cout << "Starting the makeLEDmulti program" << endl;
cout << "The current LED Path is: " << LED3_PATH << endl;
// select whether command is on, off, flash or status
if(endsWith(cmd,"onled")){
cout << "Turning the LED on" << endl;
removeTrigger();
writeLED("/brightness", "1");
}
else if (endsWith(cmd,"offled")){
cout << "Turning the LED off" << endl;
removeTrigger();
writeLED("/brightness", "0");
}
else if (endsWith(cmd,"flashled")){
cout << "Flashing the LED" << endl;
writeLED("/trigger", "timer");
writeLED("/delay_on", "50");
writeLED("/delay_off", "50");
}
else if (endsWith(cmd,"ledstatus")){
// display the current trigger details
std::fstream fs;
fs.open( LED3_PATH "/trigger", std::fstream::in);
string line;
while(getline(fs,line)) cout << line << endl;
fs.close();
}
else{
cout << "Invalid command!" << endl;
}
cout << "Finished the makeLEDmulti Program" << endl;
return 0;
}
build文件
#!/bin/bash
echo "Building the makeLED application"
g++ makeLEDmulti.cpp -o makeLEDmulti
if ! [ -e "onled" ]; then
ln -s makeLEDmulti onled
echo "Created onled symbolic link"
fi
if ! [ -e "offled" ]; then
ln -s makeLEDmulti offled
echo "Created offled symbolic link"
fi
if ! [ -e "ledstatus" ]; then
ln -s makeLEDmulti ledstatus
echo "Created ledstatus symbolic link"
fi
if ! [ -e "flashled" ]; then
ln -s makeLEDmulti flashled
echo "Created flashled symbolic link"
fi
echo "Finished"
3. 使用Device Tree来设置引脚初始状态
这里设置 P9_11 PINS$28 GPIO0_30 = 30 Output Mode7 pulldown
P9_13 PINS$29 GPIO0_31 = 31 Input Mode7 pullup
YW-GPIO-Example.dts内容如下
/dts-v1/;
/plugin/;
/{
compatible = "ti,beaglebone", "ti,beaglebone-black";
part-number = "YW-GPIO-Example";
version = "00A0";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
yw_example: YW_GPIO_Example {
pinctrl-single,pins = <
0x070 0x07 // P9_11 PINS$28 GPIO0_30 = 30 Output Mode7 pulldown
0x074 0x37 // P9_13 PINS$29 GPIO0_31 = 31 Input Mode7 pullup
/* OUTPUT GPIO(mode7) 0x07 pulldown, 0x17 pullup, 0x?f no pullup/down */
/* INPUT GPIO(mode7) 0x27 pulldown, 0x37 pullup, 0x?f no pullup/down */
>;
};
};
};
fragment@1 {
target = <&ocp>;
__overlay__ {
gpio_helper {
compatible = "gpio-of-helper";
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&yw_example>;
};
};
};
};
3.1 编译dts
这个是device tree source文件,系统并不能直接用,使用如下命令编译
dtc -O dtb -o YW-GPIO-Example-00A0.dtbo -b 0 -@ YW-GPIO-Example.dts
要真正起作用还需要拷贝到指定目录,使用命令
sudo cp YW-GPIO-Example-00A0.dtbo /lib/firmware
3.2 查看已加载的Slot
加载Device Tree Overlay之前,我们查看一下系统中已经存在哪些SLOTS
对于SLOTS4 P-O-L 这里的L就是Load(加载)。
3.3 加载Slot
加载我们之前编译的dtbo文件(可以不需要版本号那些哦),即part-number
查看引脚状态
3.4 卸载Slot
卸载SLOT
有时候为了避免引脚冲突,我们需要移除HDMI或EMMC SLOT,它们的移除步骤复杂一点还需要改动/boot/uEnv.txt文件
/media$ sudo mkdir /mnt/vfat
/media$ sudo mount /dev/mmcblk0p1 /mnt/vfat
/media$ cd /mnt/vfat
/mnt/vfat$ sudo vim uEnv.txt
将这句取消注释
##Disable HDMI
optargs=capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN
然后
/mnt/vfat$ cd ..
/mnt$ sudo umount /mnt/vfat
/mnt$ sudo reboot
重启后查看一下slots,cat /sys/devices/bone_capemgr.9/slots
3.5 自启动Slot
还是需要修改uEnv.txt,先去看看/lib/firmware下的dtbo文件
仿照上面的写
optargs=capemgr.enable_partno=ADAFRUIT-SPI0
也可以vim /etc/default/capemgr来添加自启动的slot。
参考资料:
- 《Exploring BeagleBone: Tools and Techniques for Building with Embedded Linux》by Derek Molloyhttp://exploringbeaglebone.com/chapter6/
- https://github.com/jadonk/validation-scripts/tree/master/test-capemgr
- https://github.com/jadonk/cape-firmware/tree/master/arch/arm/boot/dts cape参考
- http://blog.csdn.net/wyt2013/article/details/14175275 export 任意引脚
=================================2016.11=============================================
http://www.righto.com/2016/08/the-beaglebones-io-pins-inside-software.html
三种方式控制GPIO的更多相关文章
- CSS控制样式的三种方式优先级对比验证
入职已经一个月了,自此后,就好久没有写过博客了,在此先跟关注我的博友们说声抱歉.今天,在公司的一个培训作业的驱动以及伟哥那句“再不写博客就开除你”的监督下,我终于重拾旧爱,再次登录博客园,继续与大家分 ...
- 格式化输出的三种方式,运算符及流程控制之if判断
''' 格式化输出的三种方式,运算符及流程控制之if判断 ''' # 格式化输出的三种方式 # 一.占位符 程序中经常会有这样场景:要求用户输入信息,然后打印成固定的格式 比如要求用户输入用户名和年龄 ...
- java:struts框架2(方法的动态和静态调用,获取Servlet API三种方式(推荐IOC(控制反转)),拦截器,静态代理和动态代理(Spring AOP))
1.方法的静态和动态调用: struts.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCT ...
- 监视EntityFramework中的sql流转你需要知道的三种方式Log,SqlServerProfile, EFProfile
大家在学习entityframework的时候,都知道那linq写的叫一个爽,再也不用区分不同RDMS的sql版本差异了,但是呢,高效率带来了差灵活性,我们 无法控制sql的生成策略,所以必须不要让自 ...
- iOS字体加载三种方式
静态加载 动态加载 动态下载苹果提供的多种字体 其他 打印出当前所有可用的字体 检查某字体是否已经下载 这是一篇很简短的文章,介绍了 iOS 自定义字体加载的三种方式. 静态加载 这个可以说是最简单最 ...
- 【Java EE 学习 52】【Spring学习第四天】【Spring与JDBC】【JdbcTemplate创建的三种方式】【Spring事务管理】【事务中使用dbutils则回滚失败!!!??】
一.JDBC编程特点 静态代码+动态变量=JDBC编程. 静态代码:比如所有的数据库连接池 都实现了DataSource接口,都实现了Connection接口. 动态变量:用户名.密码.连接的数据库. ...
- 加载gif动画的三种方式
GifView.h/** * 调用结束就开始播放动画,如果需要用户指定何时播放的话,只需要把timer的开始放到合适的位置.通过对CFDictonaryRaf 也就是gifProperties的改变, ...
- Spring依赖注入三种方式详解
在讲解Spring依赖注入之前的准备工作: 下载包含Spring的工具jar包的压缩包 解压缩下载下来的Spring压缩包文件 解压缩之后我们会看到libs文件夹下有许多jar包,而我们只需要其中的c ...
- Linux就这个范儿 第15章 七种武器 linux 同步IO: sync、fsync与fdatasync Linux中的内存大页面huge page/large page David Cutler Linux读写内存数据的三种方式
Linux就这个范儿 第15章 七种武器 linux 同步IO: sync.fsync与fdatasync Linux中的内存大页面huge page/large page David Cut ...
随机推荐
- Android USB Host框架
Android 下的usb框架及功能点:https://blog.csdn.net/tianruxishui/article/details/379029591.Android framework中* ...
- Learning C# by Developing Games with Unity 5.x(2nd) 学习
项目:https://pan.baidu.com/s/1o7IMcZo using UnityEngine; using System.Collections; namespace VoidGame ...
- wampserver变橙色,apache 服务无法启动!问题解决小记(安装失败亦可参考)
http://blog.csdn.net/haoaiqian/article/details/58147079 80端口被占用的可能性非常大,关掉IIS即可
- 关于 php json float 出现很多位的问题
关于 php json float 出现很多位的问题 serialize_precision http://php.net/manual/en/ini.list.php https://wiki.ph ...
- C++ vs Objective C
oc Short list of some of the major differences: C++ allows multiple inheritance, Objective-C doesn't ...
- git刚初始化项目的操作
# Command line instructions ## Git global setup git config --global user.name "iback" git ...
- php 过滤器filter_var验证邮箱/url/ip等
验证邮箱.url或者ip,除了使用正则外,也可以使用内置的函数库过滤器filter来完成这些功能. filter_var (PHP 5 >= 5.2.0, PHP 7)filter_var — ...
- 服务网关Zuul
路由+过滤器 = Zuul 核心是一系列的过滤器 Zuul的四种过滤器API 前置(PRE) 后置(POST) 路由(Route) 错误(Error) Zuul组织架构图 二.Zuul的使用 1 创建 ...
- NET设计模式 第二部分 创建型模式(6):创建型模式专题总结(Creational Pattern)
创建型模式专题总结(Creational Pattern) ——.NET设计模式系列之七 Terrylee,2006年1月 概述 创建型模式,就是用来创建对象的模式,抽象了实例化的过程.它帮助一个系统 ...
- Qt中多线程问题
1. 出现的问题 编写视频解码器程序时,把解码那部分单独置于一个线程中进行处理,后来实际应用到项目中发现内存泄漏很严重 问题就出现在多线程中,每次视频解码器程序关闭时首先必须释放其所涉及的堆空间, 由 ...