我发现内核中的GPIO驱动程序留下/sys/class/gpio来控制gpio,但我发现GPIO也可以被控制/dev/mem,我发现这个映射可能在spi-bcm2708(它调用__ioremap作为平台驱动程序)中完成,但我不这样做了解spi和GPIO之间的关系,它们在linux中如何协同工作?
pi@raspberrypi:~/Desktop/go $ go run shell1.go
Run Code Online (Sandbox Code Playgroud)
结果我得到:
pi@raspberrypi:~/Desktop/go $ go run shell1.go
# command-line-arguments
./shell1.go:29: undefined: n
./shell1.go:29: cannot use b (type []byte) as type string in argument to strconv.ParseFloat
./shell1.go:32: undefined: n
Run Code Online (Sandbox Code Playgroud)
Go文件( shell1.go)代码为:
package main
import (
// "net/http"
// "github.com/julienschmidt/httprouter"
"fmt"
"log"
"os/exec"
"strconv"
"time"
//"bytes"
//"encoding/binary"
)
import _ "github.com/go-sql-driver/mysql"
import _ "database/sql"
func main() {
for {
time.Sleep(10 * time.Millisecond)
cmd := exec.Command("gpio.bash")
b, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
n, …Run Code Online (Sandbox Code Playgroud) 有人对 libgpiod API 有经验吗?我已经在我的linux平台上安装了它,但无法调用它的库函数。
我安装的是:
git clone git://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
cd libgpiod
./autogen.sh
make
make install
Run Code Online (Sandbox Code Playgroud)
之后,我在/usr/local/lib/中看到libgpiod.so库,在/usr/local/include/中看到gpiod.h(出于良好的考虑,我也运行了)。但是,当我尝试编译以下内容时:ldconfig
测试.c
#include <gpiod.h>
struct gpio_chip *chip;
int main(void)
{
chip = gpio_chip_open("/dev/gpiochip4");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:undefined reference to 'gpiod_chip_open'
谁能帮我看看我哪里出了问题?
提前谢谢了!
我有一个Raspberry Pi.我通过命令行在板上安装了WiringPi for pilot GPIO.
我做了一个名为aggiornaora.sh的脚本
gpio -g write 18 1 #it set the GPIO port to 1
#log with reverse append
(echo 'accensione';date;echo ' ') | cat - logstufa.txt > temp && mv temp logstufa.txt
Run Code Online (Sandbox Code Playgroud)
如果我试图直接执行它,这个脚本工作正常sh aggiornaora.sh.但是当cron运行脚本时,它只执行第二个操作.全部具有root权限.我通过"gpio readall"检查了这个问题.
在您看来可能是什么问题?
好吧我很难过,我可能没有足够的android经验,所以我不知道使用哪些权限.
我已经重新编译了android内核以暴露我需要的gpio引脚,也许我需要在内核中做一些事来解决我的问题...基本上在这一点上我不知道
我可以打开adb shell并/sys/class/gpio/export 141获取gpio文件夹及其文件(值,方向等).
当我在adb shell我的时候,我可以设置方向和值使用echo out>direction;echo 1>value;echo 0>value;,一切都很好,引脚驱动低或高.
我把它export 141放入init.rc,现在在启动时导出.如果我尝试从我的kivy应用程序中访问值文件,它会崩溃,并说权限被拒绝(预期)
如果我chmod 0666同时direction和value它成功更新文件sys中的权限.
-rw-rw-rw- root root 4096 2013-10-01 06:59 value
-rw-rw-rw- root root 4096 2013-10-01 06:59 direction
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试从kivy(python)写入文件时,[Errno 1] Operation not permitted 如果我尝试chown将文件发送给我的应用程序用户或系统,我会得到相同的结果.我觉得我几乎尝试了所有东西,似乎无法写入/sys/class/gpio/gpio141/value或指示
在我的initramfs.cpio中,我只有这些目录:
root@localhost extract]# ls
dev init tmp sys
Run Code Online (Sandbox Code Playgroud)
dev有控制台,sys是空的.
init是一个二进制文件,对应于我在内核启动后访问GPIO时讨论过的程序.
现在在同一个GPIO程序中,我想编写代码来挂载/ sys.我知道它可以使用mount挂载:
mount -t sysfs none /sys
Run Code Online (Sandbox Code Playgroud)
如何编写将实现上述代码的C程序.请注意,我没有文件系统; initramfs.cpio有空文件夹:/ sys,/ tmp.如果需要,我可以放更多的空文件夹.但我不能把完整的文件系统.
我的主要目的是 使用此程序或其他方式访问GPIO ,但不使用完整的文件系统.我不需要运行任何其他东西,但只想要GPIO访问(和LED闪烁)
我正在尝试使用wiringPi的简单代码:
#include<wiringPi.h>
#include<stdio.h>
int main(void){
int i;
wirintPiSetup();
pinMode(0,OUTPUT); //a single LED
pinMode(8,INPUT); //tactile switch
for(;;){
delay(500);
//push tactile switch and LED is turning on
if(digitalRead(8)) digitalWrite(0,0);
else digitalWrite(0,1);
printf("%d",digitalRead(8));
}
}
Run Code Online (Sandbox Code Playgroud)
我期望printf()的结果输出到控制台,但它不起作用.printf()无法与wiringPi API同时运行?
编译时没有警告.并且CPU消耗总是低于4%.在Raspbian上运行.
谢谢你的时间!
我正在开发嵌入式系统上的恢复机制.如果用户按下GPIO按钮,我想启动进入恢复模式.恢复模式意味着选择不同的内核和根分区.我坚持在条件命令中使用gpio值.如果我写的if gpio input 20; then cmd; fi cmd将始终运行,因为gpio返回错误状态而不是GPIO的值.我怎样才能获得价值?
使用U-Boot命令实现引导选择是否可行(我需要将LED闪烁15秒,如果用户按下按钮至少5秒,则切换到恢复).在C代码中实现这个逻辑会更容易吗?如果是这样在哪里看,有没有例子?
通常,提供恢复系统似乎是嵌入式工程师的常见任务.这种情况下的最佳做法是什么?实现这个的最常见方式是什么?我在网上找不到任何帮助或指导.
使用Linux内核,因为它是描述编译这里,我试图让一个LED闪烁下面这个wiki:Linux的GPIO驱动程序.我正在使用Xilinx的Zybo板.
我启用了内核选项:
CONFIG_GPIO_SYSFS=y
CONFIG_SYSFS=y
CONFIG_GPIO_XILINX=y
Run Code Online (Sandbox Code Playgroud)
我检查了我已经在/ sys中安装了SysFs
我想配置MIO端口的引脚7,因为它连接到电路板中的LED LD4.所以我使用了这个表达式:
echo 7 > /sys/class/gpio/export
Run Code Online (Sandbox Code Playgroud)
我总是得到这个错误:
export_store: invalid GPIO 7
ash: write error: Invalid argument
Run Code Online (Sandbox Code Playgroud)
我也尝试导出值,145 (138+7)因为我在这里找到了解释:forum_link和86因为这个人得到的东西是basic_example.但我总是得到同样的错误.
你能给我一些帮助吗?也许我必须使用其他偏移?或者它与权限配置更相关?
我是内核编程的新手,现在尝试将一些值写入设备驱动程序中的32位GPIO寄存器。I / O被ioremap()设置为内存地址。问题是,我不知道如何writel()/ writeb()/ writew()该地址写入位。
供应商文件说该寄存器已打开0xE5200000。我要写入的[0:3]位是这些位,其余的28位(这些[4:31]位)保留为零。
这是到目前为止我编写的设备驱动程序代码的一部分:
#define TCON_ADDR 0xE250000 // The address as provided by the vendor
static void *TIMER_CON_ADDR;
// I have to map and write to the address when the device is opened
static int on_dev_open(struct inode *inode, struct file *file) {
unsigned int data;
TIMER_CON_ADDR = ioremap(TCON_ADDR, 4); // Map the [0:4] bits to TIMER_CON_ADDR
data = 4; // 0100 in binary
writel(data, TIMER_CON_ADDR); …Run Code Online (Sandbox Code Playgroud)