添加 mmc5603驱动,可以正常读数
authorSnickerSun <snickersun@163.com>
Tue, 2 Jan 2024 02:26:44 +0000 (10:26 +0800)
committerSnickerSun <snickersun@163.com>
Tue, 2 Jan 2024 02:26:44 +0000 (10:26 +0800)
code/sdk/application/brandy/brandy_standard/service_init.c
code/sdk/build/config/target_config/brandy/config.py
code/sdk/drivers/peripheral/mag/CMakeLists.txt
code/sdk/drivers/peripheral/mag/mmc5603/Customer.c
code/sdk/drivers/peripheral/mag/mmc5603/Customer.h
code/sdk/drivers/peripheral/mag/mmc5603/MMC5603.c
code/sdk/drivers/peripheral/mag/mmc5603/MMC5603.h
code/sdk/drivers/peripheral/mag/mmc5603/main_sample.c
code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_at_cmd.c [new file with mode: 0644]
code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_at_cmd.h [new file with mode: 0644]

index 4dc7ca3..5bc5236 100755 (executable)
 #include "lis2doc_at_cmd.h"
 #endif
 
+#ifdef SUPPORT_AT_MMC5603
+#include "mmc5603_at_cmd.h"
+#endif
+
 #include "log_file.h"
 #ifdef CONFIG_OTA_UPDATE_SUPPORT
 #include "upg.h"
@@ -97,6 +101,11 @@ static void register_at_service(void)
     at_cmd_add_moudle(lis2doc_table, lis2doc_cmd_count);
 #endif
 
+#ifdef SUPPORT_AT_MMC5603
+    uint32_t mmc5603_cmd_count;
+    at_cmd_table_t *mmc5603_table = get_mmc5603_cmd_table(&mmc5603_cmd_count);
+    at_cmd_add_moudle(mmc5603_table, mmc5603_cmd_count);
+#endif
 
 }
 
index cb624c3..5400ddd 100755 (executable)
@@ -118,6 +118,7 @@ target = {
                     'FT_SINGLE_UART',
                     'PPG_HX3695',
                     'ACC_LIS2DOC',
+                    'MAG_MMC5603',
                     #'CONFIG_ADC_SUPPORT_AUTO_SCAN','CONFIG_ADC_SUPPORT_LONG_SAMPLE',
                     'MIPI_ULPS_SUPPORT', 'TPTYPE_FT6X46'],
         'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite",
@@ -129,6 +130,7 @@ target = {
                           "audio_proc", "audio_dump", "audio_probe", "power_manager", "gpu_proc",
                           "ppg_sensor",
                           "acc_sensor",
+                          "mag_sensor",
                           "batterry_service"],
         'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'alipay_set'],
         'dsp_version': 'max',
index ce78370..4681877 100644 (file)
@@ -4,32 +4,32 @@
 #===============================================================================
 set(COMPONENT_NAME "mag_sensor")
 
-set(SOURCES
-    ${CMAKE_CURRENT_SOURCE_DIR}/touch_screen_drv.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/touch_screen_queue1.c
-)
 
 if("MAG_MMC5603" IN_LIST DEFINES)
 set(SOURCES ${SOURCES}
     ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/Customer.c
     ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/main_sample.c
     ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/MMC5603.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/mmc5603_at_cmd.c
+)
+set(PUBLIC_HEADER
+    ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603
+)
+set(PUBLIC_DEFINES
+    SUPPORT_AT_MMC5603
 )
 else()
 set(SOURCES ${SOURCES}
     ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/Customer.c
     ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/main_sample.c
     ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/MMC5603.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603/mmc5603_at_cmd.c
 )
-endif()
-
-if("MAG_MMC5603" IN_LIST DEFINES)
 set(PUBLIC_HEADER
     ${CMAKE_CURRENT_SOURCE_DIR}/mmc5603
 )
-else()
-set(PUBLIC_HEADER
-    {CMAKE_CURRENT_SOURCE_DIR}/mmc5603
+set(PUBLIC_DEFINES
+    SUPPORT_AT_MMC5603
 )
 endif()
 
@@ -39,8 +39,7 @@ set(PRIVATE_HEADER
 set(PRIVATE_DEFINES
 )
 
-set(PUBLIC_DEFINES
-)
+
 
 # use this when you want to add ccflags like -include xxx
 set(COMPONENT_PUBLIC_CCFLAGS
index 0540dbd..3fb542e 100644 (file)
 #include "Customer.h"\r
-\r
-void Delay_Ms(int cnt)\r
+#include "osal_timer.h"\r
+#include "osal_mutex.h"\r
+#include "pinctrl.h"\r
+#include "chip_io.h"\r
+#include "time.h"\r
+#include "i2c.h"\r
+#include "gpio.h"\r
+#include "hal_gpio.h"\r
+#include "hal_i2c.h"\r
+#include "soc_osal.h"\r
+#include "tcxo.h"\r
+#define MMC5603_I2C_BUS  I2C_BUS_2\r
+#define MMC5603_I2C_TIME_MAX       3\r
+void mmc5603_Delay_Ms(int cnt)\r
 {\r
        /*  cnt is the time to wait */\r
        \r
-       /* \r
-       .\r
-       . Need to be implemented by user. \r
-       .\r
-       */\r
-       \r
+       uapi_tcxo_delay_ms(cnt);\r
        return;\r
 }\r
-void Delay_Us(int cnt)\r
+void mmc5603_Delay_Us(int cnt)\r
 {\r
        /*  cnt is the time to wait */\r
        \r
-       /* \r
-       .\r
-       . Need to be implemented by user. \r
-       .\r
-       */\r
+       uapi_tcxo_delay_us(cnt);\r
        \r
        return;\r
 }\r
+static uint8_t g_mmc_installed = 0;\r
+/*\r
+ * @brief  platform specific initialization (platform dependent)\r
+ */\r
+static void mmc5603_i2c_init(void)\r
+{\r
+    errcode_t result;\r
+    /* init i2c */\r
+    if ( g_mmc_installed == 1 )\r
+        return ;\r
+\r
+    result = uapi_i2c_master_init(MMC5603_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */\r
+    if (result != ERRCODE_SUCC) {\r
+        MMC_ERROR("mmc5603 i2c init fail! ret=0x%x", result);\r
+        return ;\r
+    }\r
+\r
+    MMC_WARNING("mmc5603:i2c_id = %d  i2c_speed = %d \r\n",\r
+        MMC5603_I2C_BUS, 400000);\r
+\r
+    g_mmc_installed = 1;\r
+\r
+    return ;\r
+}\r
+\r
+/*\r
+ * @brief  Write generic device register (platform dependent)\r
+ *\r
+ * @param  handle    customizable argument. In this examples is used in\r
+ *                   order to select the correct sensor bus handler.\r
+ * @param  reg       register to write\r
+ * @param  bufp      pointer to data to write in register reg\r
+ * @param  len       number of consecutive register to write\r
+ *\r
+ */\r
+static int32_t mmc5603_platform_write(unsigned char i2c_add, uint8_t reg, const uint8_t *bufp,\r
+                              uint16_t len)\r
+{\r
+\r
+    errcode_t ret;\r
+    uint32_t retry;\r
+    i2c_data_t data;\r
+    uint8_t *write_data = NULL;\r
+    uint16_t send_len;\r
+    uint8_t *data_buf=bufp;\r
+    uint16_t data_len=len;\r
+    \r
+    mmc5603_i2c_init();\r
+    send_len = data_len + sizeof(uint8_t);\r
+    write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL);\r
+    if (write_data == NULL) {\r
+        MMC_ERROR("mmc5603 send buff malloc fail!");\r
+        return ERRCODE_FAIL;\r
+    }\r
+    write_data[0] = reg;\r
+    ret = (uint32_t)memcpy_s(write_data + sizeof(uint8_t), send_len - sizeof(uint8_t), data_buf, data_len);\r
+    if (ret != EOK) {\r
+        MMC_ERROR("mmc5603 send_buf content copy fail! ret=0x%x", ret);\r
+        return ret;\r
+    }\r
+\r
+    data.send_buf = write_data;\r
+    data.send_len = send_len;\r
+    data.receive_buf = NULL;\r
+    data.receive_len = 0;\r
+\r
+    for (retry = 0; retry < MMC5603_I2C_TIME_MAX; retry++) {\r
+        ret = uapi_i2c_master_write(MMC5603_I2C_BUS, i2c_add, &data);\r
+        if (ret == ERRCODE_SUCC) {\r
+            break;\r
+        }\r
+    }\r
+    if (ret != ERRCODE_SUCC) {\r
+        MMC_ERROR("mmc5603 data write fail! ret=0x%x", ret);\r
+        return ret;\r
+    }\r
+\r
+    osal_kfree(write_data);\r
+  return 0;\r
+}\r
+\r
+/*\r
+ * @brief  Read generic device register (platform dependent)\r
+ *\r
+ * @param  handle    customizable argument. In this examples is used in\r
+ *                   order to select the correct sensor bus handler.\r
+ * @param  reg       register to read\r
+ * @param  bufp      pointer to buffer that store the data read\r
+ * @param  len       number of consecutive register to read\r
+ *\r
+ */\r
+static int32_t mmc5603_platform_read( unsigned char i2c_add,uint8_t reg, uint8_t *bufp,\r
+                             uint16_t len)\r
+{\r
+    errcode_t ret;\r
+    uint32_t retry;\r
+    i2c_data_t data;\r
+\r
+    mmc5603_i2c_init();\r
+    memset_s(bufp, len, 0, len);\r
+    data.send_buf = &reg;\r
+    data.send_len = 1;\r
+    data.receive_buf = bufp;\r
+    data.receive_len = len;\r
+\r
+    for (retry = 0; retry < MMC5603_I2C_TIME_MAX; retry++) {\r
+        ret = uapi_i2c_master_writeread(MMC5603_I2C_BUS, i2c_add, &data);\r
+        if (ret == ERRCODE_SUCC) {\r
+            break;\r
+        }\r
+    }\r
+    if (ret != ERRCODE_SUCC) {\r
+        MMC_ERROR("mmc5603 data read fail! ret=0x%x", ret);\r
+        return ret;\r
+    }\r
+\r
+    return ERRCODE_SUCC;\r
+}\r
 int I2C_Write_Reg(unsigned char i2c_add, unsigned char reg_add, unsigned char cmd)\r
 {\r
        /* i2c_add is the 7-bit i2c address of the sensor\r
@@ -32,13 +153,12 @@ int I2C_Write_Reg(unsigned char i2c_add, unsigned char reg_add, unsigned char cm
         * I2C operating successfully, return 1, otherwise return 0;\r
         */\r
        \r
-       /* \r
-       .\r
-       . Need to be implemented by user. \r
-       .\r
-       */       \r
-       \r
-       return 1;\r
+       if ( ERRCODE_SUCC == mmc5603_platform_write(i2c_add,reg_add,&cmd,1))\r
+       {\r
+               return 1;\r
+       }else{\r
+               return 0;\r
+       }\r
 }\r
 int I2C_Read_Reg(unsigned char i2c_add, unsigned char reg_add, unsigned char *data)\r
 {\r
@@ -48,13 +168,13 @@ int I2C_Read_Reg(unsigned char i2c_add, unsigned char reg_add, unsigned char *da
         * I2C operating successfully, return 1, otherwise return 0;    \r
         */\r
                \r
-       /* \r
-       .\r
-       . Need to be implemented by user. \r
-       .\r
-       */      \r
-        \r
-       return 1;\r
+       if ( ERRCODE_SUCC == mmc5603_platform_read(i2c_add,reg_add,data,1))\r
+       {\r
+               return 1;\r
+       }else{\r
+               return 0;\r
+       }\r
+\r
 }\r
 int I2C_MultiRead_Reg(unsigned char i2c_add, unsigned char reg_add, int num, unsigned char *data)\r
 {\r
@@ -65,12 +185,11 @@ int I2C_MultiRead_Reg(unsigned char i2c_add, unsigned char reg_add, int num, uns
         * I2C operating successfully, return 1, otherwise return 0;    \r
         */\r
        \r
-       /* \r
-       .\r
-       . Need to be implemented by user. \r
-       .\r
-       */\r
-       \r
-       return 1;\r
+       if ( ERRCODE_SUCC == mmc5603_platform_read(i2c_add,reg_add,data,num))\r
+       {\r
+               return 1;\r
+       }else{\r
+               return 0;\r
+       }\r
 }\r
 \r
index a61a346..535e41e 100644 (file)
@@ -1,13 +1,39 @@
+#ifndef __MMC5603_PORTING_H__\r
+#define __MMC5603_PORTING_H__\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include "debug_print.h"\r
+\r
+#define MMC_DEBUG\r
+\r
+#ifdef MMC_DEBUG\r
+#define MMC_LOG(fmt, ...)                    \\r
+    do {                                      \\r
+        PRINT(fmt"\r\n", ##__VA_ARGS__);     \\r
+    } while (0)\r
+#else\r
+#define MMC_LOG(ftm, ...)\r
+#endif\r
+\r
+#define MMC_ERROR(x, ...) \\r
+    do { \\r
+        PRINT("[ERROR]%s(%d): "x"\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \\r
+    } while (0)\r
+\r
+#define MMC_WARNING(x, ...) \\r
+    do { \\r
+        PRINT("[WARNING]%s(%d): "x"\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \\r
+    } while (0)\r
 \r
 /**\r
  * @brief Delay function.\r
  */\r
-void Delay_Ms(int cnt);\r
+void mmc5603_mmc5603_Delay_Ms(int cnt);\r
 \r
 /**\r
  * @brief Delay function.\r
  */\r
-void Delay_Us(int cnt);\r
+void mmc5603_Delay_Us(int cnt);\r
 \r
 /**\r
  * @brief I2C write register.\r
@@ -23,3 +49,5 @@ int I2C_Read_Reg(unsigned char i2c_add, unsigned char reg_add, unsigned char *da
  * @brief I2C multi read.\r
  */\r
 int I2C_MultiRead_Reg(unsigned char i2c_add, unsigned char reg_add, int num, unsigned char *data);\r
+\r
+#endif\r
index 0ab08c7..0454bfd 100644 (file)
@@ -76,7 +76,7 @@ int MMC5603_Factory_Test_Mode(void)
        /* Set Cmm_en bit '0', Disable continuous mode */       \r
        I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_CTRL2, 0x00);\r
        \r
-       Delay_Ms(20);\r
+       mmc5603_Delay_Ms(20);\r
        \r
        /* Write reg 0x1B */\r
        /* Set Auto_SR_en bit '0', Disable the function of automatic set/reset */\r
@@ -90,7 +90,7 @@ int MMC5603_Factory_Test_Mode(void)
        /* Write 0x01 to register 0x1B, set Take_meas_M bit '1' */\r
        I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_CTRL0, MMC5603_CMD_TMM);     \r
        /* Delay 10 ms to finish the TM operation */\r
-       Delay_Ms(10);           \r
+       mmc5603_Delay_Ms(10);           \r
        /* Read register data */\r
        I2C_MultiRead_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_DATA, 6, data_reg);\r
        /* Get high 16bits data */\r
@@ -103,7 +103,7 @@ int MMC5603_Factory_Test_Mode(void)
        /* Write 0x01 to register 0x1B, set Take_meas_M bit '1' */\r
        I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS,MMC5603_REG_CTRL0,MMC5603_CMD_TMM);       \r
        /* Delay 10 ms to finish the TM operation */\r
-       Delay_Ms(10);           \r
+       mmc5603_Delay_Ms(10);           \r
        /* Read register data */\r
        I2C_MultiRead_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_DATA, 6, data_reg);\r
        /* Get high 16bits data */\r
@@ -135,7 +135,7 @@ void MMC5603_SET(void)
        I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_CTRL0, MMC5603_CMD_SET);     \r
        \r
        /* Delay to finish the SET operation */\r
-       Delay_Ms(1);\r
+       mmc5603_Delay_Ms(1);\r
        \r
        return; \r
 }\r
@@ -149,7 +149,7 @@ void MMC5603_RESET(void)
        I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_CTRL0, MMC5603_CMD_RESET);\r
        \r
        /* Delay to finish the RESET operation */\r
-       Delay_Ms(1);\r
+       mmc5603_Delay_Ms(1);\r
        \r
        return; \r
 }\r
@@ -216,7 +216,7 @@ int MMC5603_Auto_SelfTest(void)
        I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_CTRL0, MMC5603_CMD_AUTO_ST_EN);\r
        \r
        /* Delay 15ms to finish the selftest process */\r
-       Delay_Ms(15);\r
+       mmc5603_Delay_Ms(15);\r
        \r
        /* Read register 0x18, check Sat_sensor bit */\r
        I2C_Read_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_STATUS1, &reg_status);        \r
@@ -274,7 +274,7 @@ int MMC5603_Saturation_Checking(void)
                \r
                /* Do TM_M after selftest operation */\r
                I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS,MMC5603_REG_CTRL0,MMC5603_CMD_TMM);       \r
-               Delay_Ms(8);\r
+               mmc5603_Delay_Ms(8);\r
        }\r
 \r
        return ret;\r
@@ -300,15 +300,15 @@ void MMC5603_Auto_Switch(uint16_t *mag)
                        \r
                        /* Disable continuous mode */   \r
                        I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_CTRL2, 0x00);\r
-                       Delay_Ms(15);//Delay 15ms to finish the last sampling\r
+                       mmc5603_Delay_Ms(15);//Delay 15ms to finish the last sampling\r
                        \r
                        /* Do SET operation */\r
                        I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_CTRL0, MMC5603_CMD_SET);     \r
-                       Delay_Ms(1);//Delay 1ms to finish the SET operation\r
+                       mmc5603_Delay_Ms(1);//Delay 1ms to finish the SET operation\r
                        \r
                        /* Do TM_M before next data reading */\r
                        I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS,MMC5603_REG_CTRL0,MMC5603_CMD_TMM);       \r
-                       Delay_Ms(8);//Delay 8ms to finish the TM_M operation                    \r
+                       mmc5603_Delay_Ms(8);//Delay 8ms to finish the TM_M operation                    \r
                }       \r
        }\r
        else if(sensor_state == 2)\r
@@ -345,7 +345,7 @@ void MMC5603_Disable(void)
        /* Set Cmm_en bit '0', Disable continuous mode */       \r
        I2C_Write_Reg(MMC5603_7BITI2C_ADDRESS, MMC5603_REG_CTRL2, 0x00);\r
        \r
-       Delay_Ms(20);\r
+       mmc5603_Delay_Ms(20);\r
        \r
        return;\r
 }\r
@@ -374,7 +374,7 @@ void MMC5603_Enable(void)
        /* Work mode setting */\r
        MMC5603_Continuous_Mode_With_Auto_SR(MMC5603_CMD_BW00, 50);\r
        \r
-       Delay_Ms(20);\r
+       mmc5603_Delay_Ms(20);\r
        \r
        return;\r
 }\r
index e5a1691..a7461d4 100644 (file)
 #ifndef _MMC5603_H\r
 #define _MMC5603_H \r
 \r
-typedef   signed char  int8_t;                 // signed 8-bit number    (-128 to +127)\r
-typedef unsigned char  uint8_t;        // unsigned 8-bit number  (+0 to +255)\r
-typedef   signed short int16_t;        // signed 16-bt number    (-32768 to +32767)\r
-typedef unsigned short uint16_t;       // unsigned 16-bit number (+0 to +65535)\r
-typedef   signed int   int32_t;        // signed 32-bt number    (-2,147,483,648 to +2,147,483,647)\r
-typedef unsigned int   uint32_t;       // unsigned 32-bit number (+0 to +4,294,967,295)\r
+#include <stdint.h>\r
+#include <stddef.h>\r
+#include <math.h>\r
+#include <sys/cdefs.h>\r
+// typedef   signed char  int8_t;              // signed 8-bit number    (-128 to +127)\r
+// typedef unsigned char  uint8_t;     // unsigned 8-bit number  (+0 to +255)\r
+// typedef   signed short int16_t;     // signed 16-bt number    (-32768 to +32767)\r
+// typedef unsigned short uint16_t;    // unsigned 16-bit number (+0 to +65535)\r
+// typedef   signed int   int32_t;     // signed 32-bt number    (-2,147,483,648 to +2,147,483,647)\r
+// typedef unsigned int   uint32_t;    // unsigned 32-bit number (+0 to +4,294,967,295)\r
 \r
 #define MMC5603_7BITI2C_ADDRESS                0x30\r
 \r
index 2680f68..9560c34 100644 (file)
@@ -5,15 +5,15 @@ float magnetic_field_x;
 float magnetic_field_y;\r
 float magnetic_field_z;\r
 \r
-int main(void)\r
+int test_mmc5603(void)\r
 {\r
        /* Magnetic field vector, unit is gauss */\r
        float mag_raw_data[3] = {0.0};  \r
        \r
        /* Enable the sensor. */\r
        MMC5603_Enable();       \r
-       \r
-       while(1)\r
+       int count = 10;\r
+       while(count)\r
        {               \r
                /* Get the MMC5603 data, unit is gauss */\r
                MMC5603_GetData(mag_raw_data);  \r
@@ -21,8 +21,12 @@ int main(void)
                magnetic_field_x = mag_raw_data[0];     //unit is gauss\r
                magnetic_field_y = mag_raw_data[1];     //unit is gauss\r
                magnetic_field_z = mag_raw_data[2];     //unit is gauss\r
-               \r
+               count-- ;\r
                /* Sampling interval is 20ms, and the sampling rate is 50Hz. */\r
-               Delay_Ms(20);\r
+\r
+               MMC_LOG("mag 5603 x %.03f, y %.03f , z %.03f \r\n",magnetic_field_x,magnetic_field_y,magnetic_field_z);\r
+               mmc5603_Delay_Ms(20);\r
        }\r
+       MMC5603_Disable();\r
+       return 0;\r
 }\r
diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_at_cmd.c b/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_at_cmd.c
new file mode 100644 (file)
index 0000000..5ad8475
--- /dev/null
@@ -0,0 +1,62 @@
+
+// #include "mmc5603.h"
+
+
+#include "at_cmd_api.h"
+#include "pm_control.h"
+#include "MMC5603.h"
+#include "Customer.h"
+
+#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
+#define MMC5603_MAX_ARGC            8
+#define MMC5603_MAX_ARGV_LEN        64
+
+#define MMC5603_SUCCESS             0
+#define MMC5603_FAILED              (-1)
+
+static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen,
+        uint8_t argv[MMC5603_MAX_ARGC][MMC5603_MAX_ARGV_LEN], uint32_t* argc)
+{
+    uint32_t pos = 0;
+    *argc = 0;
+
+    for (uint32_t i = 0; i < paraLen; i++) {
+        if ((para[i] == ' ' || para[i] == '\n') && pos != 0) {
+            argv[*argc][pos] = '\0';
+            *argc += 1;
+            pos = 0;
+            if (*argc >= MMC5603_MAX_ARGC) {
+                return MMC5603_FAILED;
+            }
+        } else {
+            argv[*argc][pos] = para[i];
+            pos++;
+            if (pos >= MMC5603_MAX_ARGV_LEN) {
+                return MMC5603_FAILED;
+            }
+        }
+    }
+    if (pos != 0) {
+        *argc += 1;
+    }
+
+    return MMC5603_SUCCESS;
+}
+
+extern int test_mmc5603(void);
+static uint32_t mmc5603_do_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    test_mmc5603();
+    return ERRCODE_SUCC;
+}
+
+static const at_cmd_table_t g_mmc5603_cmd[] = {
+    { (char *)"AT^MMC5603TEST",      mmc5603_do_test, (char *)"aac enable" },
+};
+
+at_cmd_table_t *get_mmc5603_cmd_table(uint32_t *cmd_count)
+{
+    *cmd_count = ARRAY_COUNT(g_mmc5603_cmd);
+    return (at_cmd_table_t *)g_mmc5603_cmd;
+}
diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_at_cmd.h b/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_at_cmd.h
new file mode 100644 (file)
index 0000000..1f2dd30
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n
+ *
+ * Description: Provides at cmd register func \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2022-07-20, Create file. \n
+ */
+#ifndef MMC5603_AT_PROCESS_H
+#define MMC5603_AT_PROCESS_H
+
+#include <stdint.h>
+#include <stdio.h>
+#include "errcode.h"
+#include "soc_osal.h"
+#include "at_cmd_api.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+at_cmd_table_t *get_mmc5603_cmd_table(uint32_t *cmd_count);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif