123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- #ifndef __SL_SC7A20_DRIVER_H__
- #define __SL_SC7A20_DRIVER_H__
- #include "PlatformTypes.h"
- #include "StandardTypes.h"
- #include "Spi.h"
- /***使用驱动前请根据实际接线情况配置******/
- /**SC7A20的SDO 脚接地: 0****************/
- /**SC7A20的SDO 脚接电源:1****************/
- #define SC7A20_SDO_VDD_GND 1
- /*****************************************/
- /***使用驱动前请根据实际IIC情况进行配置***/
- /**SC7A20的IIC 接口地址类型 7bits: 0****/
- /**SC7A20的IIC 接口地址类型 8bits: 1****/
- #define SC7A20_IIC_7BITS_8BITS 0
- /*****************************************/
- #define SL_SC7A20_16BIT_8BIT 1
- /**SC7A20的数据位数选择 16bits: 1****/
- /**SC7A20的数据位数选择 8bits: 0****/
- /*****************************************/
- #define SL_SC7A20_SPI_IIC_MODE 0
- /**SC7A20 SPI IIC 选择 SPI: 0****/
- /**SC7A20 SPI IIC 选择 IIC: 1****/
- /*****************************************/
- #define SL_6D4D2D1D_SEL 6
- #if SL_SC7A20_SPI_IIC_MODE==1
- #if SC7A20_SDO_VDD_GND==0
- #define SC7A20_IIC_7BITS_ADDR 0x18
- #define SC7A20_IIC_8BITS_ADDR 0x30
- #else
- #define SC7A20_IIC_7BITS_ADDR 0x19
- #define SC7A20_IIC_8BITS_ADDR 0x32
- #endif
- #if SC7A20_IIC_7BITS_8BITS==0
- #define SC7A20_IIC_ADDRESS SC7A20_IIC_7BITS_ADDR
- #else
- #define SC7A20_IIC_ADDRESS SC7A20_IIC_8BITS_ADDR
- #endif
- #endif
- #define SC7A20_CHIP_ID_ADDRESS (uint8)0x0F
- #define SC7A20_CHIP_ID_VALUE (uint8)0x11
- #define SL_SC7A20_CTRL_REG1 (uint8)0x20
- #define SL_SC7A20_CTRL_REG2 (uint8)0x21
- #define SL_SC7A20_CTRL_REG3 (uint8)0x22
- #define SL_SC7A20_CTRL_REG4 (uint8)0x23
- #define SL_SC7A20_CTRL_REG5 (uint8)0x24
- #define SL_SC7A20_CTRL_REG6 (uint8)0x25
- #define SL_SC7A20_STATUS_REG (uint8)0x27
- #define SL_SC7A20_OUT_X_L (uint8)0x28
- #define SL_SC7A20_OUT_X_H (uint8)0x29
- #define SL_SC7A20_OUT_Y_L (uint8)0x2A
- #define SL_SC7A20_OUT_Y_H (uint8)0x2B
- #define SL_SC7A20_OUT_Z_L (uint8)0x2C
- #define SL_SC7A20_OUT_Z_H (uint8)0x2D
- #define SL_SC7A20_FIFO_CTRL_REG (uint8)0x2E
- #define SL_SC7A20_FIFO_SRC_REG (uint8)0x2F
- #define SL_SC7A20_INT1_CFG (uint8)0x30
- #define SL_SC7A20_INT1_SRC (uint8)0x31
- #define SL_SC7A20_INT1_THS (uint8)0x32
- #define SL_SC7A20_INT1_DURATION (uint8)0x33
- #define SL_SC7A20_INT2_CFG (uint8)0x34
- #define SL_SC7A20_INT2_SRC (uint8)0x35
- #define SL_SC7A20_INT2_THS (uint8)0x36
- #define SL_SC7A20_INT2_DURATION (uint8)0x37
- #define SL_SC7A20_CLICK_CFG (uint8)0x38
- #define SL_SC7A20_CLICK_SRC (uint8)0x39
- #define SL_SC7A20_CLICK_THS (uint8)0x3A
- #define SL_SC7A20_TIME_LIMIT (uint8)0x3B
- #define SL_SC7A20_TIME_LATENCY (uint8)0x3C
- #define SL_SC7A20_TIME_WINDOW (uint8)0x3D
- #define SL_SC7A20_ACT_THS (uint8)0x3E
- #define SL_SC7A20_ACT_DURATION (uint8)0x3F
-
- /*连续读取数据时的数据寄存器地址*/
- #define SL_SC7A20_DATA_OUT (uint8)(SL_SC7A20_OUT_X_L)
- /**********特殊功能寄存器**********/
- /*非原厂技术人员请勿修改*/
- #define SL_SC7A20_MTP_ENABLE 0x00
- #define SL_SC7A20_MTP_CFG (uint8)0x1E
- #define SL_SC7A20_MTP_VALUE (uint8)0x05
- #define SL_SC7A20_SDOI2C_PU_CFG (uint8)0x57
- #define SL_SC7A20_SDO_PU_MSK (uint8)0x08
- #define SL_SC7A20_I2C_PU_MSK (uint8)0x04
- #define SL_SC7A20_HR_ENABLE (uint8)0X08
- #define SL_SC7A20_BOOT_ENABLE (uint8)0X80
- /*非原厂技术人员请勿修改*/
- /***************数据更新速率**加速度计使能**********/
- #define SL_SC7A20_ODR_POWER_DOWN (uint8)0x00
- #define SL_SC7A20_ODR_1HZ (uint8)0x17
- #define SL_SC7A20_ODR_10HZ (uint8)0x27
- #define SL_SC7A20_ODR_25HZ (uint8)0x37
- #define SL_SC7A20_ODR_50HZ (uint8)0x47
- #define SL_SC7A20_ODR_100HZ (uint8)0x57
- #define SL_SC7A20_ODR_200HZ (uint8)0x67
- #define SL_SC7A20_ODR_400HZ (uint8)0x77
- #define SL_SC7A20_ODR_1600HZ (uint8)0x87
- #define SL_SC7A20_ODR_1250HZ (uint8)0x97
- #define SL_SC7A20_ODR_5000HZ (uint8)0x9F
-
- #define SL_SC7A20_LOWER_POWER_ODR_1HZ (uint8)0x1F
- #define SL_SC7A20_LOWER_POWER_ODR_10HZ (uint8)0x2F
- #define SL_SC7A20_LOWER_POWER_ODR_25HZ (uint8)0x3F
- #define SL_SC7A20_LOWER_POWER_ODR_50HZ (uint8)0x4F
- #define SL_SC7A20_LOWER_POWER_ODR_100HZ (uint8)0x5F
- #define SL_SC7A20_LOWER_POWER_ODR_200HZ (uint8)0x6F
- #define SL_SC7A20_LOWER_POWER_ODR_400HZ (uint8)0x7F
- /***************数据更新速率**加速度计使能**********/
- /***************传感器量程设置**********************/
- #define SL_SC7A20_FS_2G (uint8)0x00
- #define SL_SC7A20_FS_4G (uint8)0x10
- #define SL_SC7A20_FS_8G (uint8)0x20
- #define SL_SC7A20_FS_16G (uint8)0x30
- /***************传感器量程设置**********************/
- /***取值在0-127之间,此处仅举例****/
- #define SL_SC7A20_INT_THS_5PERCENT (uint8)0x06
- #define SL_SC7A20_INT_THS_10PERCENT (uint8)0x0C
- #define SL_SC7A20_INT_THS_20PERCENT (uint8)0x18
- #define SL_SC7A20_INT_THS_40PERCENT (uint8)0x30
- #define SL_SC7A20_INT_THS_80PERCENT (uint8)0x60
- /***取值在0-127之间,此处仅举例 乘以ODR单位时间****/
- #define SL_SC7A20_INT_DURATION_2CLK (uint8)0x02
- #define SL_SC7A20_INT_DURATION_5CLK (uint8)0x05
- #define SL_SC7A20_INT_DURATION_10CLK (uint8)0x0A
- #define SL_SC7A20_INT_DURATION_30CLK (uint8)0x2E
- /***中断有效时的电平设置,高电平相当于上升沿,低电平相当于下降沿****/
- #define SL_SC7A20_INT_ACTIVE_LOWER_LEVEL 0x02 //0x02:中断时INT1脚输出 低电平
- #define SL_SC7A20_INT_ACTIVE_HIGH_LEVEL 0x00 //0x00:中断时INT1脚输出 高电平
- /***中断有效时的电平设置,高电平相当于上升沿,低电平相当于下降沿****/
- #define SL_SC7A20_INT_AOI1_INT1 0x40 //AOI1 TO INT1
- #define SL_SC7A20_INT_AOI2_INT1 0x20 //AOI2 TO INT1
- /********客户需要进行的IIC接口封包函数****************/
- Std_ReturnType Gsensor_SPI_Write(uint8 Addr,uint8 *DataBufferPtr,uint16 Length);
- Std_ReturnType Gsensor_SPI_Read(uint8 Addr,uint8 *DataBufferPtr,uint16 Length);
- /**Gsensor_SPI_Write 函数中, sl_spi_iic:0=spi 1=i2c Reg:寄存器地址 data:寄存器的配置值******************/
- /**Gsensor_SPI_Write 函数 是一个单次写的函数*******************************************************************/
- /***Gsensor_SPI_Read 函数中, sl_spi_iic:0=spi 1=i2c Reg 同上,len:读取数据长度,buf:存储数据首地址(指针)***/
- /***Gsensor_SPI_Read 函数 是可以进行单次读或多次连续读取的函数*************************************************/
- /*** 客户IIC函数封装举例
- uint8 SL_MEMS_i2c_spi_Write(uint8 reg, uint8 data)
- {
- i2cWrite(SC7A20_IIC_ADDRESS, reg, data); //由客户的II函数接口决定
- return 1;
- }
- uint8 SL_MEMS_i2c_spi_Read(uint8 reg, uint8 len, uint8 *buf)
- {
- i2cRead( SC7A20_IIC_ADDRESS, reg, len, buf);//由客户的II函数接口决定
- return 1;
- }
- ***/
- Std_ReturnType SL_SC7A20_Online_Test(void);
- Std_ReturnType SL_SC7A20_BOOT(void);
- Std_ReturnType SL_SC7A20_INT_Config(void);
- Std_ReturnType SL_SC7A20_INT_RESET(void);
- Std_ReturnType SL_SC7A20_FS_Config(uint8 Sc7a20_FS_Reg);
- Std_ReturnType SL_SC7A20_Power_Config(uint8 Power_Config_Reg);
- Std_ReturnType SL_SC7A20_Read_XYZ_Data(sint16 *SL_SC7A20_Data_XYZ_Buf);
- void SL_SC7A20_AOI1_event(void);
- void SL_SC7A20_AOI2_event(void);
- void SL_SC7A20_Reg_read_all(void);
- Std_ReturnType GsensorInit(void);
- //步骤如下:
- //0.signed char SL_SC7A20_BOOT(void);
- //1.signed char SL_SC7A20_Online_Test(void);
- //2.signed char SL_SC7A20_FS_Config(uint8 Sc7a20_FS_Reg);
- //3.signed char SL_SC7A20_Power_Config(uint8 Power_Config_Reg);
- //6.signed char SL_SC7A20_Read_XYZ_Data(signed char *SL_SC7A20_Data_XYZ_Buf);
- //6.signed char SL_SC7A20_Read_XYZ_Data(signed short *SL_SC7A20_Data_XYZ_Buf);
- #endif /* __SL_SC7A20_DRIVER_H */
|