i2c-tomega8.h
上传用户:wealth48
上传日期:2022-06-24
资源大小:1701k
文件大小:4k
源码类别:

uCOS

开发平台:

C/C++

  1. #ifndef __I2C_TOMEGA8_H_
  2. #define __I2C_TOMEGA8_H_
  3. #define I2COWNER_ADDRESS (0x10>>1)
  4. #define MEGA8_I2CADDRESS (0x60)
  5. typedef __packed struct{
  6. unsigned char cmd; //(command|(dev_type<<4))
  7. unsigned char ctrl;
  8. }I2C_control;
  9. #define ICCARD_COUNT_TYPESEL_OFFSET 2
  10. typedef __packed struct{
  11. unsigned char cmd; //(command|(dev_type<<4))
  12. unsigned char key;
  13. }I2C_kbd;
  14. typedef __packed struct{
  15. unsigned char cmd; //(command|(dev_type<<4))
  16. unsigned char ps2data;
  17. }I2C_PS2;
  18. #define ICCARD_COUNT_FAILED_OFFSET 2
  19. typedef unsigned char ICCardErrorCode;
  20. #define ICCARD_COUNT_OFFSET 4 //ic card frame count offset
  21. #define MAX_ICCARD_RWBUFFER 128
  22. typedef __packed struct tagICCardRWBuffer{
  23. unsigned short address;
  24. unsigned char cnt;
  25. unsigned char buffer[MAX_ICCARD_RWBUFFER];
  26. }ICCARD_data;
  27. #define ICCARD_COUNT_PWD_OFFSET 2
  28. #define MAX_ICCARD_PWDBUFFER 128
  29. typedef __packed struct tagICCardPwdBuffer{
  30. unsigned char cnt;
  31. unsigned char buffer[MAX_ICCARD_PWDBUFFER];
  32. }ICCARD_PWDDATA;
  33. __packed union tagI2C_ICCard_unionBUF{
  34. ICCARD_data _ICCardRWBuffer;
  35. ICCARD_PWDDATA _ICCardPwdBuffer;
  36. ICCardErrorCode _errorcode;
  37. };
  38. typedef __packed struct{
  39. unsigned char cmd; //(command|(dev_type<<4))
  40. union tagI2C_ICCard_unionBUF _I2C_ICCard_unionBUF;
  41. }I2C_ICCard;
  42. #define iccard_addr _I2C_ICCard_unionBUF._ICCardRWBuffer.address
  43. #define iccard_cnt _I2C_ICCard_unionBUF._ICCardRWBuffer.cnt
  44. #define iccard_buf _I2C_ICCard_unionBUF._ICCardRWBuffer.buffer
  45. #define iccard_pwdcnt _I2C_ICCard_unionBUF._ICCardPwdBuffer.cnt
  46. #define iccard_pwdbuf _I2C_ICCard_unionBUF._ICCardPwdBuffer.buffer
  47. #define iccard_errcode _I2C_ICCard_unionBUF._errorcode
  48. typedef union {
  49. unsigned char m_cmd;
  50. I2C_ICCard m_iccard;
  51. I2C_kbd m_kbd;
  52. I2C_PS2 m_ps2;
  53. unsigned char m_buffer[1];
  54. }I2C_MEGA8_BUFFER;
  55. #define BUFFER_TYPE_LEN (sizeof(unsigned char))
  56. #define GetI2CCmd(cmd) (cmd&0xf)
  57. #define GetI2C_Devtype(cmd) (cmd>>4)
  58. #define MakeCmd(type, cmd) (cmd|(type<<4))
  59. // Device type 
  60. #define DTYPE_ALL 0 //芯片控制命令
  61. #define DTYPE_SECURITY 1 //加密命令
  62. #define DTYPE_ICCARD 2 //IC卡读写命令
  63. #define DTYPE_MKEYB 3 //矩阵键盘扫描命令
  64. #define DTYPE_PS2_0 4 //PS2接口0命令
  65. #define DTYPE_PS2_1 5 //PS2接口2命令
  66. // Commands
  67. #define CMD_CTRL_BASE 0x0
  68. #define CMD_CTRL (CMD_CTRL_BASE+0) //控制字
  69. #define CMD_MST_ADDR (CMD_CTRL_BASE+1) //主控端地址
  70. #define CMD_GET_MKEY (CMD_CTRL_BASE+2) //读取扫描键盘码
  71. #define CMD_GET_TEST1 (CMD_CTRL_BASE+0xa) //读取测试寄存器
  72. #define CMD_SEC_BASE 0x10
  73. #define CMD_SEC_PASS (CMD_SEC_BASE+0)
  74. #define CMD_SEC_PASSACK (CMD_SEC_BASE+1)
  75. #define CMD_ICC_BASE 0x20
  76. #define CMD_ICC_TYPESEL (CMD_ICC_BASE+0)
  77. #define CMD_ICC_READ (CMD_ICC_BASE+1)
  78. #define CMD_ICC_WRITE (CMD_ICC_BASE+2)
  79. #define CMD_ICC_VERIFY (CMD_ICC_BASE+3)
  80. #define CMD_ICC_FAILED (CMD_ICC_BASE+4)
  81. #define CMD_MKEYB 0x30
  82. #define CMD_PS2_0 0x40
  83. #define CMD_PS2_1 0x50
  84. #define ICC_FAILED_NULL 0 //没有错误
  85. #define ICC_FAILED_NOCARD 1 //IC 卡没有插入
  86. #define ICC_FAILED_ERRTYPE 2 //错误的IC 卡类型
  87. #define ICC_FAILED_BUSY 3 //IC 卡忙
  88. #define ICC_FAILED_NOSEL 4 //未选择IC卡类型
  89. #define ICC_FAILED_READERR 5 //IC 卡读取错误
  90. #define ICC_FAILED_WRITEERR 6 //IC 卡写入错误
  91. #define ICC_FAILED_VERIFYERR 7 //IC 卡校验错误
  92. #define ICC_FAILED_WAITING 0xff //IC 卡通讯状态等待
  93. //ic card type define
  94. #define ICCARD_COMPTYPE_ATMEL (1<<4)
  95. #define ICCARD_COMPTYPE_SIEMENS (2<<4)
  96. //atmel 24cxx ic card
  97. #define ICCARD_TYPE_AT24C02 (ICCARD_COMPTYPE_ATMEL|1)
  98. #define ICCARD_TYPE_AT24C04 (ICCARD_COMPTYPE_ATMEL|2)
  99. #define ICCARD_TYPE_AT24C08 (ICCARD_COMPTYPE_ATMEL|3)
  100. #define ICCARD_TYPE_AT24C16 (ICCARD_COMPTYPE_ATMEL|4)
  101. #define ICCARD_TYPE_AT24C32 (ICCARD_COMPTYPE_ATMEL|5)
  102. #define ICCARD_TYPE_AT24C64 (ICCARD_COMPTYPE_ATMEL|6)
  103. #define ICCARD_TYPE_SLE4442 (ICCARD_COMPTYPE_SIEMENS|1)
  104. #define ICCARD_IOCTL_LASTERR 1
  105. #define ICCARD_IOCTL_SELCARD 2
  106. #define ICCARD_IOCTL_4442VERIFY 3
  107. #define CTRL_MKEn (1<<3) //扫描键盘开启
  108. #define CTRL_ICEn (1<<2) //ic card控制开启
  109. #define CTRL_PS1En (1<<1) //ps2 1接口开启
  110. #define CTRL_PS0En (1) //ps2 0接口开启
  111. #endif /*#ifndef __I2C_TOMEGA8_H_*/