From 2ebb8217f43b69f491620423ea4d5d5944d1f91d Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期六, 05 七月 2025 22:43:58 +0800
Subject: [PATCH] 格式化部分代码

---
 keil/include/drivers/lis3dh_driver.c |  145 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 112 insertions(+), 33 deletions(-)

diff --git a/keil/include/drivers/lis3dh_driver.c b/keil/include/drivers/lis3dh_driver.c
index b22121f..089330b 100644
--- a/keil/include/drivers/lis3dh_driver.c
+++ b/keil/include/drivers/lis3dh_driver.c
@@ -165,19 +165,75 @@
 }
 
 
-//void delay_us(uint32_t nTimer)
-//{
-//    uint32_t i=0;
-//    for(i=0;i<nTimer;i++){
-//        __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
-//		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
-//		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
-//        __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
-//		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
-//		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
-//        __NOP();__NOP();__NOP();__NOP();
-//    }
-//}
+static void delay_us(uint32_t nTimer)
+{
+    uint32_t i=0;
+    for(i=0; i<nTimer; i++) {
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+        __NOP();
+
+
+    }
+}
 AxesRaw_t lis2dhdata;
 
 //OLED初始化IIC
@@ -198,7 +254,7 @@
     io_pin_mux_set(SCL_PIN, IO_FUNC0);
 
     gpio_pin_set_dir(SDA_PIN , GPIO_DIR_OUT, 1);
-		//io_open_drain_set(SDA_PIN, 1);
+    //io_open_drain_set(SDA_PIN, 1);
     io_pull_set(SDA_PIN , IO_PULL_UP, IO_PULL_UP_LEVEL2);//输出高阻态
 
     gpio_pin_set_dir(SCL_PIN , GPIO_DIR_OUT, 1);
@@ -212,18 +268,37 @@
 void Accelerometer_Init()
 {
 
-    LIS3DH_GetWHO_AM_I(&lisidtemp);
-    lisid=(uint16_t)lisidtemp;
+//    LIS3DH_GetWHO_AM_I(&lisidtemp);
+//    lisid=(uint16_t)lisidtemp;
 
-    if(lisid == 0x33)
+//    if(lisid == 0x33)
+//    {
+//        LIS3DH_Data_Init();
+//    }
+//    else
+//    {
+//        g_com_map[IMU_ENABLE]=0;
+//    }
+    lisid = mir3da_ReadOneByte(REG_CHIP_ID);
+
+    if(lisid == 0x13)
     {
-        LIS3DH_Data_Init();
+        mir3da_init();
     }
     else
     {
-        g_com_map[IMU_ENABLE]=0;
-    }
+        LIS3DH_GetWHO_AM_I(&lisidtemp);
+        lisid=(uint16_t)lisidtemp;
 
+        if(lisid == 0x33)
+        {
+            LIS3DH_Data_Init();
+        }
+        else
+        {
+            g_com_map[IMU_ENABLE]=0;
+        }
+    }
 }
 
 void mir3da_init()
@@ -484,11 +559,18 @@
     return acc_g;
 }
 
-
+void  IIC2_SDA_OUT()
+{
+    gpio_pin_set_dir(SDA_PIN , GPIO_DIR_OUT, 1);
+}
+void  IIC2_SDA_IN()
+{
+    gpio_pin_set_dir(SDA_PIN,GPIO_DIR_IN,1); //SDA设置为输入等待接收端的应答信号
+}
 //产生IIC起始信号
 void IIC2_Start(void)
 {
-//		IIC2_SDA_OUT();     //sda线输出
+    IIC2_SDA_OUT();     //sda线输出
     SDA_1;
 //		delay_us(10);
     SCL_1;
@@ -500,7 +582,7 @@
 //产生IIC停止信号
 void IIC2_Stop(void)
 {
-//		IIC2_SDA_OUT();//sda线输出
+    IIC2_SDA_OUT();//sda线输出
     SCL_0;
 //		delay_us(10);
     SDA_0;//STOP:when CLK is high DATA change form low to high
@@ -515,16 +597,14 @@
 //等待应答信号到来
 //返回值:1,接收应答失败
 //        0,接收应答成功
-
 uint8_t IIC2_Wait_Ack(void)
 {
     uint8_t ucErrTime=0;
-//  IIC2_SDA_IN();      //SDA设置为输入
-    gpio_pin_set_dir(SDA_PIN , GPIO_DIR_IN, 1);
+    IIC2_SDA_IN();
     SDA_1;
-    delay_us(6);
+    delay_us(15);
     SCL_1;
-    delay_us(6);
+    delay_us(15);
 
     while(IIC2_READ_SDA)
     {
@@ -535,7 +615,6 @@
             return 1;
         }
     }
-    gpio_pin_set_dir(SDA_PIN , GPIO_DIR_OUT, 1);
     SCL_0;//时钟输出0
     return 0;
 }
@@ -543,7 +622,7 @@
 void IIC2_Ack(void)
 {
     SCL_0;
-//	IIC2_SDA_OUT();
+    IIC2_SDA_OUT();
     SDA_0;
     delay_us(10);
     SCL_1;
@@ -554,7 +633,7 @@
 void IIC2_NAck(void)
 {
     SCL_0;
-//	IIC2_SDA_OUT();
+    IIC2_SDA_OUT();
     SDA_1;
     delay_us(10);
     SCL_1;
@@ -570,7 +649,7 @@
 void IIC2_Send_Byte(uint8_t txd)
 {
     uint8_t t;
-//		IIC2_SDA_OUT();
+    IIC2_SDA_OUT();
     SCL_0;//拉低时钟开始数据传输
     for(t=0; t<8; t++)
     {
@@ -595,7 +674,7 @@
 uint8_t IIC2_Read_Byte(unsigned char ack)
 {
     unsigned char i,receive=0;
-//	IIC2_SDA_IN();//SDA设置为输入
+    IIC2_SDA_IN();//SDA设置为输入
     for(i=0; i<8; i++ )
     {
         SCL_0;

--
Gitblit v1.9.3