CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
123
返回列表 发新帖
楼主: tll

无需驱动,不用编程,无视代码半分钟搞定GPIO

[复制链接]
发表于 2013-8-21 22:01:03 | 显示全部楼层
板子友善之臂的,
回复 支持 反对

使用道具 举报

发表于 2013-8-22 09:31:58 | 显示全部楼层
学习一下,虽然还不知其所以然
回复 支持 反对

使用道具 举报

发表于 2014-1-13 14:22:21 | 显示全部楼层
对新手来说,有很直观到操作感。。。
回复 支持 反对

使用道具 举报

发表于 2014-1-13 19:00:37 | 显示全部楼层
yuzj 发表于 2014-1-13 14:22
对新手来说,有很直观到操作感。。。

参考 最新的 http://docs.cubieboard.org/tutorials/common/gpio_on_lubuntu
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-1-16 13:23:50 | 显示全部楼层
@allen 发表于 2014-1-13 19:00
参考 最新的 http://docs.cubieboard.org/tutorials/common/gpio_on_lubuntu

我这个给新手用的,很方便,其他的都有各自缺点
回复 支持 反对

使用道具 举报

发表于 2014-3-6 15:15:29 | 显示全部楼层
确实很方便,我弄那个sunxi-gpio驱动,很久都没弄好
回复 支持 反对

使用道具 举报

发表于 2014-3-8 12:11:50 | 显示全部楼层
wget http://www.tonylianlong.com/file/gpio.deb这条命令都执行不了,找不到
回复 支持 反对

使用道具 举报

发表于 2014-3-8 13:28:22 | 显示全部楼层
wget http://www.tonylianlong.com/file/gpio.deb
--2014-03-08 05:27:06--  http://www.tonylianlong.com/file/gpio.deb
Resolving www.tonylianlong.com (www.tonylianlong.com)... 192.227.235.226
Connecting to www.tonylianlong.com (www.tonylianlong.com)|192.227.235.226|:80...
HTTP request sent, awaiting response... 404 Not Found
2014-03-08 05:27:06 ERROR 404: Not Found.
这是怎么回事???
回复 支持 反对

使用道具 举报

发表于 2014-7-17 16:38:55 | 显示全部楼层
本帖最后由 darson 于 2014-7-17 17:22 编辑
tll 发表于 2013-7-22 13:50
抱歉我把源代码弄丢了……

tll 的 gpio.deb 源码应该是这样的,排版有点乱,凑合用吧,我用的是PH 引脚 ,可以根据需要修改
  1.   
  2.     #include <ctype.h>
  3.     #include <string.h>
  4.     #include <stdlib.h>
  5.     #include <stdio.h>
  6.     #include <math.h>
  7.     #include <time.h>
  8.     #include <signal.h>
  9.     #include <sys/types.h>
  10.     #include <sys/stat.h>
  11.     #include <fcntl.h>
  12.     #include <sys/mman.h>
  13.     #include <sys/select.h>
  14.     #include <pthread.h>
  15.     #include <unistd.h>
  16.     #include <sched.h>
  17.     #include <errno.h>


  18.     #define SW_PORTC_IO_BASE  0x01c20800

  19.     int main(int argc,char *argv[]) {
  20.                
  21.         unsigned int * pc;
  22.        int fd, i;
  23.        char * ptr;
  24.        unsigned int addr_start, addr_offset, PageSize, PageMask, data;
  25.                 int a;
  26.                 char s[10] ;
  27.                 char s1[]="open";
  28.                 char s2[]="close";
  29.                 printf("Which pin do you want to use (PH?) :");
  30.                 scanf("%d",&a);
  31.                 if(0<= a && a <=27){
  32.                 printf("OK,please enter 'open' or 'close' to open or close this pin:");
  33.                
  34.                 scanf("%s",s);
  35.        PageSize = sysconf(_SC_PAGESIZE);
  36.        PageMask = (~(PageSize-1));
  37.        addr_start = SW_PORTC_IO_BASE & PageMask;
  38.        addr_offset = SW_PORTC_IO_BASE & ~PageMask;

  39.        fd = open("/dev/mem", O_RDWR);
  40.        if(fd < 0) {
  41.           perror("Unable to open /dev/mem");
  42.           return(-1);
  43.        }

  44.        pc = mmap(0, PageSize*2, PROT_READ|PROT_WRITE, MAP_SHARED, fd, addr_start);

  45.        if(pc == MAP_FAILED) {
  46.           perror("Unable to mmap file");
  47.           printf("pc:%lx\n", (unsigned long)pc);
  48.           return(-1);
  49.        }
  50.        ptr = (char *)pc + addr_offset;
  51.        data = *(unsigned int *)(ptr+0x10c);

  52.                 if(strcmp(s,s1)==0){
  53.                
  54.                 data |= 1<<a;                          
  55.                 *(unsigned int *)(ptr+0x10c) = data;
  56.                  printf("Open successed!")    ;
  57.                  return 0;
  58.                 }
  59.                
  60.                 else if(strcmp(s,s2)==0){
  61.                 data &= ~(1<<a);
  62.                  *(unsigned int *)(ptr+0x10c) = data;
  63.                 printf("Close successed!")    ;
  64.                 return 0;
  65.                
  66.                 }
  67. else {
  68. printf("Please enter 'open' or 'close',not '%s',okay?\n",s);

  69. }
  70.                 }
  71.                 else {
  72.                 printf("Hey!Please enter a number from 0 to 27!\n");
  73.                 return -1;        
  74.                 }

  75.         }
复制代码

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-4-30 07:31 , Processed in 0.024288 second(s), 12 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部