SL_Sc7a20_Driver.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #ifndef __SL_SC7A20_DRIVER_H__
  2. #define __SL_SC7A20_DRIVER_H__
  3. #include "PlatformTypes.h"
  4. #include "StandardTypes.h"
  5. #include "Spi.h"
  6. /***使用驱动前请根据实际接线情况配置******/
  7. /**SC7A20的SDO 脚接地: 0****************/
  8. /**SC7A20的SDO 脚接电源:1****************/
  9. #define SC7A20_SDO_VDD_GND 1
  10. /*****************************************/
  11. /***使用驱动前请根据实际IIC情况进行配置***/
  12. /**SC7A20的IIC 接口地址类型 7bits: 0****/
  13. /**SC7A20的IIC 接口地址类型 8bits: 1****/
  14. #define SC7A20_IIC_7BITS_8BITS 0
  15. /*****************************************/
  16. #define SL_SC7A20_16BIT_8BIT 1
  17. /**SC7A20的数据位数选择 16bits: 1****/
  18. /**SC7A20的数据位数选择 8bits: 0****/
  19. /*****************************************/
  20. #define SL_SC7A20_SPI_IIC_MODE 0
  21. /**SC7A20 SPI IIC 选择 SPI: 0****/
  22. /**SC7A20 SPI IIC 选择 IIC: 1****/
  23. /*****************************************/
  24. #define SL_6D4D2D1D_SEL 6
  25. #if SL_SC7A20_SPI_IIC_MODE==1
  26. #if SC7A20_SDO_VDD_GND==0
  27. #define SC7A20_IIC_7BITS_ADDR 0x18
  28. #define SC7A20_IIC_8BITS_ADDR 0x30
  29. #else
  30. #define SC7A20_IIC_7BITS_ADDR 0x19
  31. #define SC7A20_IIC_8BITS_ADDR 0x32
  32. #endif
  33. #if SC7A20_IIC_7BITS_8BITS==0
  34. #define SC7A20_IIC_ADDRESS SC7A20_IIC_7BITS_ADDR
  35. #else
  36. #define SC7A20_IIC_ADDRESS SC7A20_IIC_8BITS_ADDR
  37. #endif
  38. #endif
  39. #define SC7A20_CHIP_ID_ADDRESS (uint8)0x0F
  40. #define SC7A20_CHIP_ID_VALUE (uint8)0x11
  41. #define SL_SC7A20_CTRL_REG1 (uint8)0x20
  42. #define SL_SC7A20_CTRL_REG2 (uint8)0x21
  43. #define SL_SC7A20_CTRL_REG3 (uint8)0x22
  44. #define SL_SC7A20_CTRL_REG4 (uint8)0x23
  45. #define SL_SC7A20_CTRL_REG5 (uint8)0x24
  46. #define SL_SC7A20_CTRL_REG6 (uint8)0x25
  47. #define SL_SC7A20_STATUS_REG (uint8)0x27
  48. #define SL_SC7A20_OUT_X_L (uint8)0x28
  49. #define SL_SC7A20_OUT_X_H (uint8)0x29
  50. #define SL_SC7A20_OUT_Y_L (uint8)0x2A
  51. #define SL_SC7A20_OUT_Y_H (uint8)0x2B
  52. #define SL_SC7A20_OUT_Z_L (uint8)0x2C
  53. #define SL_SC7A20_OUT_Z_H (uint8)0x2D
  54. #define SL_SC7A20_FIFO_CTRL_REG (uint8)0x2E
  55. #define SL_SC7A20_FIFO_SRC_REG (uint8)0x2F
  56. #define SL_SC7A20_INT1_CFG (uint8)0x30
  57. #define SL_SC7A20_INT1_SRC (uint8)0x31
  58. #define SL_SC7A20_INT1_THS (uint8)0x32
  59. #define SL_SC7A20_INT1_DURATION (uint8)0x33
  60. #define SL_SC7A20_INT2_CFG (uint8)0x34
  61. #define SL_SC7A20_INT2_SRC (uint8)0x35
  62. #define SL_SC7A20_INT2_THS (uint8)0x36
  63. #define SL_SC7A20_INT2_DURATION (uint8)0x37
  64. #define SL_SC7A20_CLICK_CFG (uint8)0x38
  65. #define SL_SC7A20_CLICK_SRC (uint8)0x39
  66. #define SL_SC7A20_CLICK_THS (uint8)0x3A
  67. #define SL_SC7A20_TIME_LIMIT (uint8)0x3B
  68. #define SL_SC7A20_TIME_LATENCY (uint8)0x3C
  69. #define SL_SC7A20_TIME_WINDOW (uint8)0x3D
  70. #define SL_SC7A20_ACT_THS (uint8)0x3E
  71. #define SL_SC7A20_ACT_DURATION (uint8)0x3F
  72. /*连续读取数据时的数据寄存器地址*/
  73. #define SL_SC7A20_DATA_OUT (uint8)(SL_SC7A20_OUT_X_L)
  74. /**********特殊功能寄存器**********/
  75. /*非原厂技术人员请勿修改*/
  76. #define SL_SC7A20_MTP_ENABLE 0x00
  77. #define SL_SC7A20_MTP_CFG (uint8)0x1E
  78. #define SL_SC7A20_MTP_VALUE (uint8)0x05
  79. #define SL_SC7A20_SDOI2C_PU_CFG (uint8)0x57
  80. #define SL_SC7A20_SDO_PU_MSK (uint8)0x08
  81. #define SL_SC7A20_I2C_PU_MSK (uint8)0x04
  82. #define SL_SC7A20_HR_ENABLE (uint8)0X08
  83. #define SL_SC7A20_BOOT_ENABLE (uint8)0X80
  84. /*非原厂技术人员请勿修改*/
  85. /***************数据更新速率**加速度计使能**********/
  86. #define SL_SC7A20_ODR_POWER_DOWN (uint8)0x00
  87. #define SL_SC7A20_ODR_1HZ (uint8)0x17
  88. #define SL_SC7A20_ODR_10HZ (uint8)0x27
  89. #define SL_SC7A20_ODR_25HZ (uint8)0x37
  90. #define SL_SC7A20_ODR_50HZ (uint8)0x47
  91. #define SL_SC7A20_ODR_100HZ (uint8)0x57
  92. #define SL_SC7A20_ODR_200HZ (uint8)0x67
  93. #define SL_SC7A20_ODR_400HZ (uint8)0x77
  94. #define SL_SC7A20_ODR_1600HZ (uint8)0x87
  95. #define SL_SC7A20_ODR_1250HZ (uint8)0x97
  96. #define SL_SC7A20_ODR_5000HZ (uint8)0x9F
  97. #define SL_SC7A20_LOWER_POWER_ODR_1HZ (uint8)0x1F
  98. #define SL_SC7A20_LOWER_POWER_ODR_10HZ (uint8)0x2F
  99. #define SL_SC7A20_LOWER_POWER_ODR_25HZ (uint8)0x3F
  100. #define SL_SC7A20_LOWER_POWER_ODR_50HZ (uint8)0x4F
  101. #define SL_SC7A20_LOWER_POWER_ODR_100HZ (uint8)0x5F
  102. #define SL_SC7A20_LOWER_POWER_ODR_200HZ (uint8)0x6F
  103. #define SL_SC7A20_LOWER_POWER_ODR_400HZ (uint8)0x7F
  104. /***************数据更新速率**加速度计使能**********/
  105. /***************传感器量程设置**********************/
  106. #define SL_SC7A20_FS_2G (uint8)0x00
  107. #define SL_SC7A20_FS_4G (uint8)0x10
  108. #define SL_SC7A20_FS_8G (uint8)0x20
  109. #define SL_SC7A20_FS_16G (uint8)0x30
  110. /***************传感器量程设置**********************/
  111. /***取值在0-127之间,此处仅举例****/
  112. #define SL_SC7A20_INT_THS_5PERCENT (uint8)0x06
  113. #define SL_SC7A20_INT_THS_10PERCENT (uint8)0x0C
  114. #define SL_SC7A20_INT_THS_20PERCENT (uint8)0x18
  115. #define SL_SC7A20_INT_THS_40PERCENT (uint8)0x30
  116. #define SL_SC7A20_INT_THS_80PERCENT (uint8)0x60
  117. /***取值在0-127之间,此处仅举例 乘以ODR单位时间****/
  118. #define SL_SC7A20_INT_DURATION_2CLK (uint8)0x02
  119. #define SL_SC7A20_INT_DURATION_5CLK (uint8)0x05
  120. #define SL_SC7A20_INT_DURATION_10CLK (uint8)0x0A
  121. #define SL_SC7A20_INT_DURATION_30CLK (uint8)0x2E
  122. /***中断有效时的电平设置,高电平相当于上升沿,低电平相当于下降沿****/
  123. #define SL_SC7A20_INT_ACTIVE_LOWER_LEVEL 0x02 //0x02:中断时INT1脚输出 低电平
  124. #define SL_SC7A20_INT_ACTIVE_HIGH_LEVEL 0x00 //0x00:中断时INT1脚输出 高电平
  125. /***中断有效时的电平设置,高电平相当于上升沿,低电平相当于下降沿****/
  126. #define SL_SC7A20_INT_AOI1_INT1 0x40 //AOI1 TO INT1
  127. #define SL_SC7A20_INT_AOI2_INT1 0x20 //AOI2 TO INT1
  128. /********客户需要进行的IIC接口封包函数****************/
  129. Std_ReturnType Gsensor_SPI_Write(uint8 Addr,uint8 *DataBufferPtr,uint16 Length);
  130. Std_ReturnType Gsensor_SPI_Read(uint8 Addr,uint8 *DataBufferPtr,uint16 Length);
  131. /**Gsensor_SPI_Write 函数中, sl_spi_iic:0=spi 1=i2c Reg:寄存器地址 data:寄存器的配置值******************/
  132. /**Gsensor_SPI_Write 函数 是一个单次写的函数*******************************************************************/
  133. /***Gsensor_SPI_Read 函数中, sl_spi_iic:0=spi 1=i2c Reg 同上,len:读取数据长度,buf:存储数据首地址(指针)***/
  134. /***Gsensor_SPI_Read 函数 是可以进行单次读或多次连续读取的函数*************************************************/
  135. /*** 客户IIC函数封装举例
  136. uint8 SL_MEMS_i2c_spi_Write(uint8 reg, uint8 data)
  137. {
  138. i2cWrite(SC7A20_IIC_ADDRESS, reg, data); //由客户的II函数接口决定
  139. return 1;
  140. }
  141. uint8 SL_MEMS_i2c_spi_Read(uint8 reg, uint8 len, uint8 *buf)
  142. {
  143. i2cRead( SC7A20_IIC_ADDRESS, reg, len, buf);//由客户的II函数接口决定
  144. return 1;
  145. }
  146. ***/
  147. Std_ReturnType SL_SC7A20_Online_Test(void);
  148. Std_ReturnType SL_SC7A20_BOOT(void);
  149. Std_ReturnType SL_SC7A20_INT_Config(void);
  150. Std_ReturnType SL_SC7A20_INT_RESET(void);
  151. Std_ReturnType SL_SC7A20_FS_Config(uint8 Sc7a20_FS_Reg);
  152. Std_ReturnType SL_SC7A20_Power_Config(uint8 Power_Config_Reg);
  153. Std_ReturnType SL_SC7A20_Read_XYZ_Data(sint16 *SL_SC7A20_Data_XYZ_Buf);
  154. void SL_SC7A20_AOI1_event(void);
  155. void SL_SC7A20_AOI2_event(void);
  156. void SL_SC7A20_Reg_read_all(void);
  157. Std_ReturnType GsensorInit(void);
  158. //步骤如下:
  159. //0.signed char SL_SC7A20_BOOT(void);
  160. //1.signed char SL_SC7A20_Online_Test(void);
  161. //2.signed char SL_SC7A20_FS_Config(uint8 Sc7a20_FS_Reg);
  162. //3.signed char SL_SC7A20_Power_Config(uint8 Power_Config_Reg);
  163. //6.signed char SL_SC7A20_Read_XYZ_Data(signed char *SL_SC7A20_Data_XYZ_Buf);
  164. //6.signed char SL_SC7A20_Read_XYZ_Data(signed short *SL_SC7A20_Data_XYZ_Buf);
  165. #endif /* __SL_SC7A20_DRIVER_H */