You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
262 lines
7.5 KiB
262 lines
7.5 KiB
1 year ago
|
////////////////////////////////////////////////////////////////////////////
|
||
|
///@copyright Copyright (c) 2017, ���ؿƼ� All rights reserved.
|
||
|
///-------------------------------------------------------------------------
|
||
|
/// @file msa300.c
|
||
|
/// @brief msa300 driver app
|
||
|
///-------------------------------------------------------------------------
|
||
|
/// @version 1.0
|
||
|
/// @author CC
|
||
|
/// @date 20170122
|
||
|
/// @note cc_AS_stc01
|
||
|
//////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
/******************************************************************************/
|
||
|
/***************************** Include Files **********************************/
|
||
|
/******************************************************************************/
|
||
|
#include "bsp_msa300.h"
|
||
|
#include "../msp/uart0.h"
|
||
|
struct _s_gsens_ s_as;//[D_as_ch_mun];
|
||
|
|
||
|
|
||
|
// data*3.91mg/LSB 1g = 90 1/2g = 45 1/3g = 30 333mg/3.91mg = 85d=0x55
|
||
|
/// ��б30�Ⱦ�����
|
||
|
//#define D_actionTH_init 0x02
|
||
|
#define D_actionTH_init 0x0f
|
||
|
//#define D_actionTH_init 0x25 /// z������25�����ٽ�ֵ
|
||
|
////#define D_actionTH_init 0x0c
|
||
|
////#define D_actionTH_init 0x04
|
||
|
/// �жϳ�����ʱ��Ϊ4s 4s���жϽ��� �����½���
|
||
|
// #define D_latch_time_init D_latch_4s
|
||
|
#define D_latch_time_init D_latch_50ms
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#if 0
|
||
|
void L1_as_power_mode(unsigned char dev,unsigned char ps)
|
||
|
{
|
||
|
// s_as[0].reg_power
|
||
|
s_as[0].reg_power &= 0x3f;
|
||
|
s_as[0].reg_power |= ps;
|
||
|
L2_I2C_WriteCmd(dev,MSA_REG_POWERMODE_BW,s_as[0].reg_power); // ����normal ģʽ
|
||
|
}
|
||
|
|
||
|
|
||
|
/// D_sensor_active_close();DL_ms300_int_close();
|
||
|
|
||
|
/// L1_as_WorkStatus(D_wakeup);
|
||
|
|
||
|
///extern void L1_as_WorkStatus(unsigned char d);
|
||
|
void L1_as_WorkStatus(unsigned char d)
|
||
|
{
|
||
|
if(D_wakeup == d)
|
||
|
{
|
||
|
/// L1_ms300_reg_set(MSA_REG_INTERRUPT_MAPPING3,D_INT2_S_TAP|D_INT2_ACTIVE);
|
||
|
D_sensor_active_open();BITN_0(DR_who_wakeup, DRB_who_wakeup_action);
|
||
|
}else
|
||
|
{
|
||
|
/// L1_ms300_reg_set(MSA_REG_INTERRUPT_MAPPING3,0);
|
||
|
D_sensor_active_close();
|
||
|
}
|
||
|
}
|
||
|
void L1_as_action(void)
|
||
|
{
|
||
|
L2_I2C_ReadReg(D_i2c_addr_Gsensor,MSA_REG_Tape_Active_Status,&s_as[0].reg_temp,1); /// read only
|
||
|
///L0_uart0_uc('.');
|
||
|
s_as[0].reg_temp &= B0111_0111;/// ȥ������λ
|
||
|
if(s_as[0].reg_action == s_as[0].reg_temp)
|
||
|
{
|
||
|
}else
|
||
|
{
|
||
|
|
||
|
s_as[0].action_ok = 1;
|
||
|
s_as[0].reg_action = s_as[0].reg_temp;
|
||
|
}
|
||
|
/// L0_uart0_uchex(s_as[0].reg_temp)
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
/// msa300 ��ʼ�� ����ǰ����ʹ��iic�ij�ʼ��
|
||
|
/// ����ʹ���ж� ������EA ����
|
||
|
void L1_msa300_init(void)
|
||
|
{
|
||
|
///
|
||
|
///step 1: ��ȡpower reg
|
||
|
LD_gsensor_power(D_PowerMode_normal );
|
||
|
/// �ϵ�����standby ģʽ ��Ҫ���� 00:normal mode, 01:low power mode, 10/11 suspend mode
|
||
|
|
||
|
///step 2: ���÷ֱ��ʺͼ��ٶȷ�Χ
|
||
|
/// L1_ms300_reg_set(MSA_REG_G_RANGE,((D_MSA_14BIT)|(D_MSA_2G))); // 8b8t 2g
|
||
|
L1_ms300_reg_set(MSA_REG_G_RANGE,((D_MSA_8BIT)|(D_MSA_2G))); // 8b8t 2g
|
||
|
// L1_ms300_reg_set(NSA_REG_ODR_AXIS_DISABLE,
|
||
|
// D_ODR_31Hz25);
|
||
|
|
||
|
///step 3: ���� ����Ƶ�ʺʹ���bandwidth ������������Ƶ�ʵ�һ��
|
||
|
/// ODR BW
|
||
|
/// 15.63Hz (0100) 7.81Hz
|
||
|
/// CLOSE Y�ر� y�� ��Ϊģ�������ŵ�
|
||
|
L1_ms300_reg_set(MSA_REG_ODR_AXIS_DISABLE,D_AXIS_DIS_Y|D_ODR_15P63Hz);
|
||
|
// L1_ms300_reg_set(MSA_REG_ODR_AXIS_DISABLE,D_ODR_31Hz25);
|
||
|
////--------------------------------------------------------------------------
|
||
|
//CC-MD-VH06
|
||
|
/// for pcb (INT1 PIN5 ) --- SENSINT2---(P3.0 INT1)
|
||
|
/// (INT2 PIN6 ) --- SENSINT3---(P3.1/INT0)
|
||
|
|
||
|
///step 4: active �ж� ʹ��XZ��
|
||
|
L1_ms300_reg_set(MSA_REG_INTERRUPT_SETTINGS1,
|
||
|
ACTIVE_INT_EN_Y|ACTIVE_INT_EN_X); /// fixme:��Ҫ����ACTIVE_INT_EN_Y
|
||
|
L1_ms300_reg_set(D_Active_TH,D_actionTH_init);
|
||
|
|
||
|
///step 5:
|
||
|
/// ACTIVE �жϺ� single tap�ж�ӳ�䵽 int2�ϣ�Ҳ����int2��ƽ�仯��֪ͨmcu����
|
||
|
/// ps3.sch msa300.int1==sensint2 msa300.int2==sensint3 ---rxd
|
||
|
/// L1_ms300_reg_set(MSA_REG_INTERRUPT_MAPPING1,INT1_ACTIVE|INT1_S_TAP_INT);
|
||
|
// L1_ms300_reg_set(MSA_REG_INTERRUPT_MAPPING3,D_INT2_ACTIVE);
|
||
|
L1_ms300_reg_set(MSA_REG_INTERRUPT_MAPPING3,D_INT2_S_TAP|D_INT2_ACTIVE);
|
||
|
|
||
|
/// INT2_OD 0: push-pull
|
||
|
/// INT2_LVL 0: low, 1:high
|
||
|
/// L1_ms300_reg_set(MSA_REG_INT_PIN_CONFIG,D_INT2_OD|D_INT2_LVL_low);
|
||
|
L1_ms300_reg_set(MSA_REG_INT_PIN_CONFIG,D_INT2_pull|D_INT2_LVL_low);
|
||
|
///L1_ms300_reg_set(MSA_REG_INT_PIN_CONFIG,0|D_INT2_LVL_high);
|
||
|
|
||
|
////--------------------------------------------------------------------------
|
||
|
///step 6 : ����1s��ʱ�� ������\_____1s______/````
|
||
|
L1_ms300_reg_set(MSA_REG_INT_LATCH,D_latch_time_init);
|
||
|
///L1_i2c_Configure(0);DL_ms300_int_open
|
||
|
///();D_sensor_active_open();
|
||
|
/// L1_as_WorkStatus(D_wakeup);
|
||
|
|
||
|
// LD_gsensor_power(D_PowerMode_normal );
|
||
|
LD_gsensor_power(D_PowerMode_low );
|
||
|
}
|
||
|
#if 0///nouse
|
||
|
|
||
|
///0x02 ACC_X[5:0] 0x00
|
||
|
//0x03 ACC_X[13:6] 0x00
|
||
|
//0x04 ACC_Y[5:0] 0x00
|
||
|
//0x05 ACC_Y[13:6] 0x00
|
||
|
//0x06 ACC_Z[5:0] 0x00
|
||
|
//0x07 ACC_Z[13:6] 0x00
|
||
|
/// 0 1 2 3 4 5
|
||
|
// x5:0 x13:6 y5:0 y13:6 z5:0 z13:6
|
||
|
void L1_as_readXYZ(unsigned char CH)
|
||
|
{
|
||
|
|
||
|
/**********************************************
|
||
|
///read data
|
||
|
//S ADD W A REG A
|
||
|
//S ADD R A D1 A D2 A.....DX N P
|
||
|
L2_I2C_ReadReg(D_i2c_addr_AS1,0x02,(unsigned char *)s_as[CH].d,6);
|
||
|
|
||
|
////d 0 1 2 3 4 5
|
||
|
//// 02 03 04 05 06 07
|
||
|
//// XL XH YL YH ZL ZH
|
||
|
///
|
||
|
L0_uart0_uc(0x09);
|
||
|
// L0_uart0_uchex(s_as[0].d[0]); L0_uart0_uc(0x09);
|
||
|
L0_uart0_uchex(s_as[0].d[1]); L0_uart0_uc(0x09);
|
||
|
// L0_uart0_uchex(s_as[0].d[2]); L0_uart0_uc(0x09);
|
||
|
L0_uart0_uchex(s_as[0].d[3]); L0_uart0_uc(0x09);
|
||
|
// L0_uart0_uchex(s_as[0].d[4]); L0_uart0_uc(0x09);
|
||
|
L0_uart0_uchex(s_as[0].d[5]);
|
||
|
/// L0_uart0_sendArray((unsigned char *)&s_as[CH],6);
|
||
|
L0_uart0_uc(0x0d);
|
||
|
L0_uart0_uc(0x0a);
|
||
|
|
||
|
|
||
|
|
||
|
Lc_delay_ms(10);
|
||
|
*****************************************/
|
||
|
|
||
|
}
|
||
|
|
||
|
#endif //////nouse
|
||
|
/*****************
|
||
|
|
||
|
L2_I2C_ReadReg(D_i2c_addr_HP303B,0x0d,d,1);
|
||
|
L0_MUART_uc(d[0]);
|
||
|
L2_I2C_ReadReg(D_i2c_addr_AS1,0x05,d,1);// 11 =0f
|
||
|
L0_MUART_uc(d[0]);
|
||
|
L2_I2C_ReadReg(D_i2c_addr_AS2,0x05,d,1);//10 =0f
|
||
|
L0_MUART_uc(d[0]);
|
||
|
|
||
|
L1_as1_readXYZ();
|
||
|
s_p_rf.ucR1 = (U8)(s_as1.x>>8);
|
||
|
s_p_rf.ucR2 = (U8)(s_as1.y>>8);
|
||
|
s_p_rf.ucR3 = (U8)(s_as1.z>>8);
|
||
|
p = (U8*)&s_p_rf;
|
||
|
|
||
|
L0_MUART_uc(s_p_rf.ucR1);
|
||
|
L0_MUART_uc(s_p_rf.ucR2);
|
||
|
L0_MUART_uc(s_p_rf.ucR3);
|
||
|
L0_MUART_uc(0xc7);
|
||
|
*********************/
|
||
|
#if 0
|
||
|
|
||
|
void L3_msa300_fun(U8 *pPara)
|
||
|
{
|
||
|
U8 val = 0;
|
||
|
TS_P_debug *p = pPara;
|
||
|
/// Ac 01 02 03 ocr ---bsp_debug.c
|
||
|
/// p.cmd p.R2 p.R3 p.ocr
|
||
|
///Ac 00 03 01 00/// ACC_X[13:6]
|
||
|
switch(p->cmd)
|
||
|
{
|
||
|
case 0:
|
||
|
/// fc 00 02 01 xx ��ȡreg02 �е�һ������
|
||
|
///0x02 ACC_X[5:0] 0x00
|
||
|
//0x03 ACC_X[13:6] 0x00
|
||
|
//0x04 ACC_Y[5:0] 0x00
|
||
|
//0x05 ACC_Y[13:6] 0x00
|
||
|
//0x06 ACC_Z[5:0] 0x00
|
||
|
//0x07 ACC_Z[13:6] 0x00
|
||
|
//// Ac 00 03 01 00/// ACC_X[13:6]
|
||
|
//// Ac 00 05 01 00/// ACC_Y[13:6]
|
||
|
//// Ac 00 07 01 00/// ACC_Z[13:6]
|
||
|
L2_I2C_ReadReg(D_i2c_addr_AS1,p->R2 ,&val,p->R3);
|
||
|
///L0_uart0_uc(p->R2);
|
||
|
///L0_uart0_uc(p->R3);
|
||
|
L0_uart0_uc(val);
|
||
|
break;
|
||
|
case 2:
|
||
|
///Ac 02 22 01 00/// (05)=01
|
||
|
L0_uart0_uc('W');
|
||
|
///L2_I2C_WriteCmd(D_i2c_addr_AS1,p->R2,p->R3);
|
||
|
//L0_uart0_uc(pPara[2]);
|
||
|
// L0_uart0_uc(p->R2);
|
||
|
// L0_uart0_uc(p->R3);
|
||
|
break;
|
||
|
case 3:
|
||
|
///Ac 03 22 01 00/// (05)=01
|
||
|
L1_as_action();
|
||
|
if(1 == s_as[0].action_ok)
|
||
|
{
|
||
|
s_as[0].action_ok = 0;
|
||
|
L0_uart0_uc(s_as[0].reg_action);
|
||
|
}
|
||
|
/*********************
|
||
|
L2_I2C_ReadReg(D_i2c_addr_Gsensor,MSA_REG_Tape_Active_Status,&s_as[0].reg_temp,1); /// read only
|
||
|
///L0_uart0_uc('.');
|
||
|
s_as[0].reg_temp &= B0111_0111;
|
||
|
if(s_as[0].reg_power == s_as[0].reg_temp)
|
||
|
{
|
||
|
|
||
|
}else
|
||
|
{
|
||
|
L0_uart0_uc(s_as[0].reg_temp);
|
||
|
s_as[0].reg_power = s_as[0].reg_temp;
|
||
|
}*************************/
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
};
|
||
|
}
|
||
|
///#else
|
||
|
void L3_msa300_fun(U8 *pPara)
|
||
|
{
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
|