主题 : mini2440 24C08 驱动代码 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 7351
精华: 1
发帖: 58
金钱: 455 两
威望: 324 点
综合积分: 136 分
注册时间: 2009-07-11
最后登录: 2014-10-17
楼主  发表于: 2014-10-17 01:54

 mini2440 24C08 驱动代码

我在 kernel 找不到 24C08 相关驱动代码 ,

.config  文件里面 CONFIG_AT24  is not set 也是没打开

为什么 下面 测试程序 24C08 又成正常 write / read ,
复制代码
  1. /***************************************************************************
  2.     copyright            : (C) by 2009 Guangzhou FriendlyaRM, in China
  3.     email                : capbily@163.com
  4.     website         : http://www.arm9.net
  5. ***************************************************************************/
  6. /*  串口终端中执行命令i2c –w 可以向板子的24C08 器件中写入数据(0x00-0xff)
  7. *  
  8. * i2c –r 可以从板子的24C08 器件中读出输出
  9. *
  10. */
  11. #include <stdio.h>
  12. #include <fcntl.h>
  13. #include <getopt.h>
  14. #include <unistd.h>
  15. #include <stdlib.h>
  16. #include <errno.h>
  17. #include <string.h>
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20. #include "24cXX.h"
  21. #define usage_if(a) do { do_usage_if( a , __LINE__); } while(0);
  22. void do_usage_if(int b, int line)
  23. {
  24.     const static char *eeprog_usage =
  25.         "I2C-24C08(256 bytes) Read/Write Program, ONLY FOR TEST!\n"
  26.         "FriendlyARM Computer Tech. 2009\n";
  27.     if(!b)
  28.         return;
  29.     fprintf(stderr, "%s\n[line %d]\n", eeprog_usage, line);
  30.     exit(1);
  31. }
  32. #define die_if(a, msg) do { do_die_if( a , msg, __LINE__); } while(0);
  33. void do_die_if(int b, char* msg, int line)
  34. {
  35.     if(!b)
  36.         return;
  37.     fprintf(stderr, "Error at line %d: %s\n", line, msg);
  38.     fprintf(stderr, "    sysmsg: %s\n", strerror(errno));
  39.     exit(1);
  40. }
  41. static int read_from_eeprom(struct eeprom *e, int addr, int size)
  42. {
  43.     int ch, i;
  44.     for(i = 0; i < size; ++i, ++addr)
  45.     {
  46.         die_if((ch = eeprom_read_byte(e, addr)) < 0, "read error");
  47.         if( (i % 16) == 0 )
  48.             printf("\n %.4x|  ", addr);
  49.         else if( (i % 8) == 0 )
  50.             printf("  ");
  51.         printf("%.2x ", ch);
  52.         fflush(stdout);
  53.     }
  54.     fprintf(stderr, "\n\n");
  55.     return 0;
  56. }
  57. static int write_to_eeprom(struct eeprom *e, int addr)
  58. {
  59.     int i;
  60.     for(i=0, addr=0; i<256; i++, addr++)
  61.     {
  62.         if( (i % 16) == 0 )
  63.             printf("\n %.4x|  ", addr);
  64.         else if( (i % 8) == 0 )
  65.             printf("  ");
  66.         printf("%.2x ", i);
  67.         fflush(stdout);
  68.         die_if(eeprom_write_byte(e, addr, i), "write error");
  69.     }
  70.     fprintf(stderr, "\n\n");
  71.     return 0;
  72. }
  73. int main(int argc, char** argv)
  74. {
  75.     struct eeprom e;
  76.     int op;
  77.     op = 0;
  78.     usage_if(argc != 2 || argv[1][0] != '-' || argv[1][2] != '\0');
  79.     op = argv[1][1];
  80.     fprintf(stderr, "Open /dev/i2c-0 with 8bit mode\n");
  81.     die_if(eeprom_open("/dev/i2c-0", 0x50, EEPROM_TYPE_8BIT_ADDR, &e) < 0,
  82.             "unable to open eeprom device file "
  83.             "(check that the file exists and that it's readable)");
  84.     switch(op)
  85.     {
  86.     case 'r':
  87.         fprintf(stderr, "  Reading 256 bytes from 0x0\n");
  88.         read_from_eeprom(&e, 0, 256);
  89.         break;
  90.     case 'w':
  91.         fprintf(stderr, "  Writing 0x00-0xff into 24C08 \n");
  92.         write_to_eeprom(&e, 0);
  93.         break;
  94.     default:
  95.         usage_if(1);
  96.         exit(1);
  97.     }
  98.     eeprom_close(&e);
  99.     return 0;
  100. }
[ 此帖被shihyu在2014-10-17 02:11重新编辑 ]
级别: 论坛版主
UID: 103400
精华: 0
发帖: 434
金钱: 2235 两
威望: 447 点
综合积分: 868 分
注册时间: 2014-04-24
最后登录: 2016-10-10
1楼  发表于: 2014-10-17 18:09
驱动没开源吧,友善在编译的时候,只给了我们一个.ko文件