1. 修改battery service,添加charger插入检测 广播消息支持,有bug暂未联动。
authorSnickerSun <snickersun@163.com>
Thu, 1 Feb 2024 09:10:23 +0000 (17:10 +0800)
committerSnickerSun <snickersun@163.com>
Thu, 1 Feb 2024 09:10:23 +0000 (17:10 +0800)
2. 默认添加alipay service 服务 I2C3 默认100kHz 影响smartpa 8166
3. 添加马达服务,暂未测试

23 files changed:
code/sdk/application/audio/vendor/common/vendor_common.h
code/sdk/application/battery/CMakeLists.txt
code/sdk/application/battery/hal/battery_hal.cpp [moved from code/sdk/application/battery/hal/battery_hal.c with 100% similarity]
code/sdk/application/battery/hal/battery_hal.h
code/sdk/application/battery/service/battery_driver.cpp [moved from code/sdk/application/battery/service/battery_service.c with 55% similarity]
code/sdk/application/battery/service/battery_service.cpp [new file with mode: 0644]
code/sdk/application/battery/test/battery_at_cmd.cpp [moved from code/sdk/application/battery/test/battery_at_cmd.c with 91% similarity]
code/sdk/application/brandy/brandy_standard/thread_pri_init.c
code/sdk/application/wearable/alipay/driver_adapt/soc_adapt.c
code/sdk/build/config/target_config/brandy/config.py
code/sdk/drivers/chips/brandy/porting/button/button_porting.c
code/sdk/drivers/chips/brandy/porting/include/button_porting.h
code/sdk/drivers/peripheral/CMakeLists.txt
code/sdk/drivers/peripheral/vibrator/CMakeLists.txt
code/sdk/drivers/peripheral/vibrator/service/CMakeLists.txt [new file with mode: 0644]
code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/vibrator/service/vibrator_service.h [new file with mode: 0644]
code/sdk/drivers/peripheral/vibrator/vibrator.c
code/sdk/drivers/peripheral/vibrator/vibrator.h
code/sdk/drivers/peripheral/vibrator/vibrator_at_cmd.c
code/sdk/drivers/peripheral/vibrator/vibrator_hal.c [new file with mode: 0644]
code/sdk/drivers/peripheral/vibrator/vibrator_hal.h [new file with mode: 0644]
code/sdk/middleware/services/gui/uikit/ui/frameworks/dock/vibrator_manager.cpp

index 4e849ba..571aec7 100755 (executable)
@@ -13,8 +13,8 @@
 
 #define VENDOR_LOG_TRACE 0 /* 0: trace log off; 1: trace log on */
 
-#define I2C_BAUDRATE 400000 /* 标准模式上限:100KHz,快速模式上限:400KHz,高速模式上限:3.4MKHz */
-#define I2C_HIGH_SPEED_CODE 1 /* 高速模式主机码,每个主机唯一,范围0~7,仅高速模式生效 */
+#define I2C_BAUDRATE 100000 /* 标准模式上限:100KHz,快速模式上限:400KHz,高速模式上限:3.4MKHz */ /* 与安全芯片同一个i2c,采用安全芯片的配置100k**/
+#define I2C_HIGH_SPEED_CODE 0 /* 高速模式主机码,每个主机唯一,范围0~7,仅高速模式生效 */
 
 #define SAP_CORE "A"
 
index 931dd00..c93422e 100644 (file)
@@ -11,32 +11,35 @@ ${CMAKE_CURRENT_SOURCE_DIR}/test
 ${CMAKE_CURRENT_SOURCE_DIR}/service
 )
 set(PRIVATE_HEADER
+    ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits
+    ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits
 )
 
 set(SOURCES
-${CMAKE_CURRENT_SOURCE_DIR}/service/battery_service.c
-${CMAKE_CURRENT_SOURCE_DIR}/test/battery_at_cmd.c
-${CMAKE_CURRENT_SOURCE_DIR}/hal/battery_hal.c
+${CMAKE_CURRENT_SOURCE_DIR}/service/battery_driver.cpp
+${CMAKE_CURRENT_SOURCE_DIR}/service/battery_service.cpp
+${CMAKE_CURRENT_SOURCE_DIR}/test/battery_at_cmd.cpp
+${CMAKE_CURRENT_SOURCE_DIR}/hal/battery_hal.cpp
 )
 
 set(COMPONENT_PUBLIC_CCFLAGS
 )
 
 set(COMPONENT_CCFLAGS
-    # -std=c++11
-    # -Wno-error
-    # -Wno-unused-parameter
-    # -fno-exceptions
-    # -fno-unwind-tables
-    # -fno-asynchronous-unwind-tables
-    # -Wno-undef
-    # -Wno-bitwise-op-parentheses
-    # -Wno-shift-op-parentheses
-    # -nostdlibinc
-    # -nostdinc
-    # -nostdlib
-    # -Wno-c++11-narrowing
-    # -Wno-error=unused-function
+    -std=c++11
+    -Wno-error
+    -Wno-unused-parameter
+    -fno-exceptions
+    -fno-unwind-tables
+    -fno-asynchronous-unwind-tables
+    -Wno-undef
+    -Wno-bitwise-op-parentheses
+    -Wno-shift-op-parentheses
+    -nostdlibinc
+    -nostdinc
+    -nostdlib
+    -Wno-c++11-narrowing
+    -Wno-error=unused-function
 )
 
 set(WHOLE_LINK
index bb53cda..a0e88b0 100644 (file)
@@ -16,6 +16,20 @@ extern "C" {
 #endif /* __cplusplus */
 #endif /* __cplusplus */
 
+#include "adc_porting.h"
+
+typedef struct {
+    float battery_voltage;
+    float battery_ntc_temp;
+    float pcb_ntc_temp;
+    bool usb_plugged;
+} battery_info_t;
+
+#define ADC_CHANNEL_BAT_VOLTAGE ADC_CHANNEL_2
+#define ADC_CHANNEL_BAT_TEMP ADC_CHANNEL_0
+#define ADC_CHANNEL_PCB_TEMP ADC_CHANNEL_5
+
+
 uint8_t battery_get_battery_temp(float *temp);
 uint8_t battery_get_pcb_temp(float *temp);
 /**
@@ -6,6 +6,11 @@
  * History: \n
  * 2022-08-16, Create file. \n
  */
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
 
 #include "adc.h"
 #define TEST_PARAM_ARGC_1 1
@@ -43,7 +48,7 @@ typedef enum {
 
 #include "adc_porting.h"
 #include "pinctrl.h"
-#include "debug_print.h"
+
 #include "soc_osal.h"
 #include "tcxo.h"
 #include "irmalloc.h"
@@ -61,6 +66,9 @@ typedef enum {
 
 #include "battery_hal.h"
 
+
+#include "debug_print.h"
+
 #define HAL_ADC_SAMPLE_NUMBER_CONFIG_0 10  /* Channel with buffer manual sample average number. */
 #define HAL_ADC_SAMPLE_NUMBER_CONFIG_1 10  /* Channel without buffer manual sample average number. */
 #define HAL_ADC_DISCARD_NUMBER_CONFIG_0 8  /* Channel with buffer manual sample discard number. */
@@ -75,9 +83,7 @@ typedef enum {
 #define batteryservice_VOLTAGE_MAX (4.2f)
 #define batteryservice_VOLTAGE_MIN (3.2f)
 
-#define ADC_CHANNEL_BAT_VOLTAGE ADC_CHANNEL_2
-#define ADC_CHANNEL_BAT_TEMP ADC_CHANNEL_0
-#define ADC_CHANNEL_PCB_TEMP ADC_CHANNEL_5
+
 
 static uint32_t g_adc_sample_times = 0;
 static uint32_t g_adc_sample_discard = 0;
@@ -88,15 +94,16 @@ static uint32_t g_adc_sample_stick = 0;
 #define MAXIMUM_VOLTAGE_RANGE         17
 
 
-typedef struct {
-    float battery_voltage;
-    float battery_ntc_temp;
-    float pcb_ntc_temp;
-    bool usb_plugged;
-} battery_info_t;
+
 
 
 static battery_info_t current_battery_info={0};
+
+battery_info_t *get_current_battery_info(void)
+{
+    return &current_battery_info;
+}
+
 static uint32_t adc_get_sample_times(void)
 {
     return g_adc_sample_times;
@@ -294,225 +301,8 @@ void disable_02c(void)
 }
 
 
-static bool g_batter_service_initialled = false;
-errcode_t uapi_battery_init(void);
-#include "tcxo.h"
-uint8_t batteryservice_get_voltage(float *voltage)
-{
-    uint8_t percent = 0;
-    *voltage = current_battery_info.battery_voltage;
-    if (*voltage <= batteryservice_VOLTAGE_MIN)
-        return 0;
-    if (*voltage >= batteryservice_VOLTAGE_MAX)
-        return 100;
-    percent = (*voltage - batteryservice_VOLTAGE_MIN)*100/(batteryservice_VOLTAGE_MAX - batteryservice_VOLTAGE_MIN) ;
-    return percent;
-}
-uint8_t batteryservice_get_battery_temp(float *temp)
-{
-
-    *temp = current_battery_info.battery_ntc_temp;
-   
-    return 0;
-}
-uint8_t batteryservice_get_pcb_temp(float *temp)
-{
-    *temp = current_battery_info.pcb_ntc_temp;
-    return 0;
-}
-/**************************Battery Check Timer***********************/
-/**
- * 电池电压读取逻辑:
- *      充电10秒,停止充电1秒,并读取电压。之后再开始充电10秒,再停止充电一秒,读取电压,然后再开始充电。。。。依此类推。
- * **/
-
-#include "cmsis_os2.h"
-#include "input_app.h"
-/**充电器检测相关*/
-#include "button_porting.h"
-
-osTimerId_t g_battery_timer = NULL;
-
-// static bool g_bat_timer_is_running = false;
-#define CHARGE_CHECK_TIMER_CYCLE_MS 1000 
-#define DISABLE_CHARGE_CHECK_MS 1000
-#define ENABLE_CHARGE_TIMEOUT_MS 10000
-bool last_battery_charge_enable_status=true; // true上次刚设置在充电状态,false 上次设置不在充电状态。注意这个是充电IC的充电开关设置,并非真正处于充电状态的标识。
-static unsigned long g_app_queue;
-#define BATTERY_CMD_CHECK_VOLTAGE 0x11
-#define BATTERY_CMD_DISABLE_CHARGE 0x12
-
-static uint8_t g_check_count = 0;
-
-static void battery_check_timer_callback(void* data);
-
-static void battery_timer_start_check_released(uint32_t rtc_ms)
-{
-    if (osTimerIsRunning(g_battery_timer))  osTimerStop(g_battery_timer);
-    osTimerStart(g_battery_timer, rtc_ms);
-}
-void do_battery_check_msg(int cmd);
-static void battery_check_and_enable_charge(void);
-
-
-static void battery_check_timer_callback(void * data)
-{
-    unused(data);
-    do_battery_check_msg(BATTERY_CMD_CHECK_VOLTAGE);
-   
-}
-void uapi_battery_deinit(void)
-{
-    /* Stop the time and clear the pin map */
-    osTimerStop(g_battery_timer);
-    osTimerDelete(g_battery_timer);
-    g_battery_timer = NULL;
-}
-
-
-
-void do_battery_check_msg(int cmd)
-{
-    int ret;
-
-    common_notify_mail_t mail = {0};
-    mail.comm.app = (app_type)cmd;
-    ret = osal_msg_queue_write_copy(g_app_queue, (void *)&mail,
-                                    sizeof(common_notify_mail_t), 0);
-    if (ret != OSAL_SUCCESS) {
-        PRINT("Error battery Check MSG 0x%02X send failed! err=0x%x! \r\n",cmd, ret);
-    }
-    
+#ifdef __cplusplus
+#if __cplusplus
 }
-/**
- * return 0 not charged, 1 charging
-*/
-uint8_t get_charge_stat(void)
-{
-    if(uapi_get_charger_plug_status())
-        return 1;
-    else
-        return 0;
-}
-static void battery_check_and_enable_charge(void)
-{
-    batteryservice_get_voltage_by_channel(&current_battery_info.battery_voltage,ADC_CHANNEL_BAT_VOLTAGE);
-    uapi_tcxo_delay_ms(20);
-    batteryservice_get_voltage_by_channel(&current_battery_info.battery_ntc_temp,ADC_CHANNEL_BAT_TEMP);
-    uapi_tcxo_delay_ms(20);
-    batteryservice_get_voltage_by_channel(&current_battery_info.pcb_ntc_temp,ADC_CHANNEL_PCB_TEMP);
-    uapi_tcxo_delay_ms(20);
-    enable_charge();
-}
-static void battery_check_task(void const *arg)
-{
-    unused(arg);
-    int32_t ret;
-    common_notify_mail_t mail;
-    uint32_t msgsize = (uint32_t)sizeof(common_notify_mail_t);
-    
-    if(uapi_get_charger_plug_status())
-    {   //如果充电线插入状态,为了获取准确电池数据,需要先停止充电一秒,再继续获取电量。
-        disable_charge();
-        uapi_tcxo_delay_ms(1000);
-        battery_check_and_enable_charge();
-    }else{
-        battery_check_and_enable_charge();
-    }
-
-    while (1) {
-        ret = osal_msg_queue_read_copy(g_app_queue, (void *)&mail, &msgsize,
-                                       OSAL_MSGQ_WAIT_FOREVER);
-        if (ret != OSAL_SUCCESS) {
-            continue;
-        }
-
-        #ifdef XTS_SUPPORT
-        extern uint8_t is_xts_test_done(void);
-            if (is_xts_test_done() == 0)
-                continue;
-        #endif
-        // get_charge_stat();
-
-        if (mail.comm.app == BATTERY_CMD_CHECK_VOLTAGE) {
-
-            g_check_count++;
-            // PRINT("BATTERY_CMD_CHECK_VOLTAGE g_check_count %d\r\n",g_check_count);
-            
-            if(last_battery_charge_enable_status == true){
-            
-                if (g_check_count*CHARGE_CHECK_TIMER_CYCLE_MS  >= ENABLE_CHARGE_TIMEOUT_MS)
-                {
-                    // PRINT("BATTERY_CMD_CHECK_VOLTAGE disable_charge \r\n");
-
-                    g_check_count = 0 ;
-                    //超时交换状态
-                    disable_charge();
-                    last_battery_charge_enable_status = false;
-                }
-
-            }else if (last_battery_charge_enable_status == false) {
-                if (g_check_count*CHARGE_CHECK_TIMER_CYCLE_MS  >= DISABLE_CHARGE_CHECK_MS)
-                {
-                    // PRINT("BATTERY_CMD_CHECK_VOLTAGE battery_check_and_enable_charge \r\n");
-
-                    g_check_count = 0 ;
-                    //超时交换状态
-                    battery_check_and_enable_charge();
-                    last_battery_charge_enable_status = true;
-                }
-                
-            }
-        }
-    }
-}
-
-
-
-errcode_t battery_charger_plug_event_callback(bool plugged)
-{
-    PRINT("[battery][service] battery_charger_plug event %d \n",plugged);
-    return ERRCODE_SUCC;
-}
-
-
-errcode_t uapi_battery_init(void)
-{
-    if (osal_msg_queue_create("battery_queue", APP_BOARD_MSG_COUNT, &g_app_queue,
-                              0, sizeof(common_notify_mail_t)) != ERRCODE_SUCC) {
-        PRINT("[battery][service] app create mail fail\n");
-        return ERRCODE_FAIL;
-    }
-
-
-    osal_task *task_handle = osal_kthread_create((osal_kthread_handler)battery_check_task, NULL,
-                                                 "battery_service", APP_BOARD_TASK_SIZE);
-    if (task_handle == NULL) {
-        osal_msg_queue_is_full(g_app_queue);
-        PRINT("create battery service thread fail!\r\n");
-        return ERRCODE_FAIL;
-    }
-
-    osal_kthread_set_priority(task_handle, APP_BOARD_TASK_PRIO);
-    // osal_kthread_set_priority(task_handle, 10);
-    g_battery_timer = osTimerNew((osTimerFunc_t)battery_check_timer_callback, osTimerOnce, NULL, NULL);
-
-    /**下面初始化电池基本数据,充电线基本状态*/
-    uapi_register_charger_event_callback(battery_charger_plug_event_callback);
-   
-    //开始timer
-    battery_timer_start_check_released(CHARGE_CHECK_TIMER_CYCLE_MS);
-
-
-    return ERRCODE_SUCC;
-}
-
-void battery_service_resume(void)
-{
-    PRINT("battery_service resume!\r\n");
-    // battery_check_timer_callback(0);
-}
-void battery_service_suspend(void)
-{
-    PRINT("battery_service suspend!\r\n");
-}
\ No newline at end of file
+#endif /* __cplusplus */
+#endif /* __cplusplus */
\ No newline at end of file
diff --git a/code/sdk/application/battery/service/battery_service.cpp b/code/sdk/application/battery/service/battery_service.cpp
new file mode 100644 (file)
index 0000000..7e9eb07
--- /dev/null
@@ -0,0 +1,360 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n
+ *
+ * Description: Test adc source \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2022-08-16, Create file. \n
+ */
+
+
+#include <time.h>
+#include <sys/time.h>
+#include <stdio.h>
+
+#include "wearable_log.h"
+#include "securec.h"
+#include "broadcast_service.h"
+#include "broadcast_feature.h"
+#include "service_id_define.h"
+#include "samgr_lite.h"
+#include "thread_adapter.h"
+#include "graphic_service.h"
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+// #include "soc_osal.h"
+#include "tcxo.h"
+#include "irmalloc.h"
+#include "errcode.h"
+#include "common_def.h"
+
+#include "rtc.h"
+#include "timer.h"
+#include "systick.h"
+
+#include "battery_hal.h"
+
+
+#include "debug_print.h"
+#define batteryservice_VOLTAGE_MAX (4.2f)
+#define batteryservice_VOLTAGE_MIN (3.2f)
+
+bool batteryservice_get_voltage_by_channel(float *voltage, uint8_t channel);
+battery_info_t *get_current_battery_info(void);
+static bool g_batter_service_initialled = false;
+errcode_t uapi_battery_init(void);
+#include "tcxo.h"
+uint8_t batteryservice_get_voltage(float *voltage)
+{
+    uint8_t percent = 0;
+    battery_info_t *current_battery_info = get_current_battery_info();
+    *voltage = current_battery_info->battery_voltage;
+    if (*voltage <= batteryservice_VOLTAGE_MIN)
+        return 0;
+    if (*voltage >= batteryservice_VOLTAGE_MAX)
+        return 100;
+    percent = (*voltage - batteryservice_VOLTAGE_MIN)*100/(batteryservice_VOLTAGE_MAX - batteryservice_VOLTAGE_MIN) ;
+    return percent;
+}
+uint8_t batteryservice_get_battery_temp(float *temp)
+{
+    battery_info_t *current_battery_info = get_current_battery_info();
+    *temp = current_battery_info->battery_ntc_temp;
+   
+    return 0;
+}
+uint8_t batteryservice_get_pcb_temp(float *temp)
+{
+    battery_info_t *current_battery_info = get_current_battery_info();
+    *temp = current_battery_info->pcb_ntc_temp;
+    return 0;
+}
+/**************************Battery Check Timer***********************/
+/**
+ * 电池电压读取逻辑:
+ *      充电10秒,停止充电1秒,并读取电压。之后再开始充电10秒,再停止充电一秒,读取电压,然后再开始充电。。。。依此类推。
+ * **/
+
+#include "cmsis_os2.h"
+#include "input_app.h"
+/**充电器检测相关*/
+#include "button_porting.h"
+#include "battery_service.h"
+
+osTimerId_t g_battery_timer = NULL;
+
+// static bool g_bat_timer_is_running = false;
+#define CHARGE_CHECK_TIMER_CYCLE_MS 1000 
+#define DISABLE_CHARGE_CHECK_MS 1000
+#define ENABLE_CHARGE_TIMEOUT_MS 10000
+bool last_battery_charge_enable_status=true; // true上次刚设置在充电状态,false 上次设置不在充电状态。注意这个是充电IC的充电开关设置,并非真正处于充电状态的标识。
+static unsigned long g_app_queue;
+#define BATTERY_CMD_CHECK_VOLTAGE 0x11
+#define BATTERY_CMD_DISABLE_CHARGE 0x12
+#define BATTERY_CMD_CHARGE_PLUG 0x13
+#define BATTERY_CMD_CHARGE_UNPLUG 0x14
+static uint8_t g_check_count = 0;
+
+static void battery_check_timer_callback(void* data);
+errcode_t charger_plug_event_ui_callback(bool plugged);
+
+static void battery_timer_start_check_released(uint32_t rtc_ms)
+{
+    if (osTimerIsRunning(g_battery_timer))  osTimerStop(g_battery_timer);
+    osTimerStart(g_battery_timer, rtc_ms);
+}
+void do_battery_check_msg(uint8_t cmd);
+static void battery_check_and_enable_charge(void);
+
+
+static void battery_check_timer_callback(void * data)
+{
+    unused(data);
+    do_battery_check_msg(BATTERY_CMD_CHECK_VOLTAGE);
+   
+}
+void uapi_battery_deinit(void)
+{
+    /* Stop the time and clear the pin map */
+    osTimerStop(g_battery_timer);
+    osTimerDelete(g_battery_timer);
+    g_battery_timer = NULL;
+}
+
+
+
+void do_battery_check_msg(uint8_t cmd)
+{
+    int ret;
+
+    common_notify_mail_t mail = {0};
+    mail.comm.app = APP_BUTTON;
+    mail.comm.event = cmd;
+    ret = osal_msg_queue_write_copy(g_app_queue, (void *)&mail,
+                                    sizeof(common_notify_mail_t), 0);
+    if (ret != OSAL_SUCCESS) {
+        PRINT("Error battery Check MSG 0x%02X send failed! err=0x%x! \r\n",cmd, ret);
+    }
+    
+}
+/**
+ * return 0 not charged, 1 charging
+*/
+uint8_t get_charge_stat(void)
+{
+    if(uapi_get_charger_plug_status())
+        return 1;
+    else
+        return 0;
+}
+static void battery_check_and_enable_charge(void)
+{
+    battery_info_t *current_battery_info = get_current_battery_info();
+    batteryservice_get_voltage_by_channel(&current_battery_info->battery_voltage,ADC_CHANNEL_BAT_VOLTAGE);
+    uapi_tcxo_delay_ms(20);
+    batteryservice_get_voltage_by_channel(&current_battery_info->battery_ntc_temp,ADC_CHANNEL_BAT_TEMP);
+    uapi_tcxo_delay_ms(20);
+    batteryservice_get_voltage_by_channel(&current_battery_info->pcb_ntc_temp,ADC_CHANNEL_PCB_TEMP);
+    uapi_tcxo_delay_ms(20);
+    enable_charge();
+}
+static void battery_check_task(void const *arg)
+{
+    unused(arg);
+    int32_t ret;
+    common_notify_mail_t mail;
+    uint32_t msgsize = (uint32_t)sizeof(common_notify_mail_t);
+    
+    if(uapi_get_charger_plug_status())
+    {   //如果充电线插入状态,为了获取准确电池数据,需要先停止充电一秒,再继续获取电量。
+        disable_charge();
+        uapi_tcxo_delay_ms(1000);
+        battery_check_and_enable_charge();
+    }else{
+        battery_check_and_enable_charge();
+    }
+
+    while (1) {
+        ret = osal_msg_queue_read_copy(g_app_queue, (void *)&mail, &msgsize,
+                                       OSAL_MSGQ_WAIT_FOREVER);
+        if (ret != OSAL_SUCCESS) {
+            continue;
+        }
+
+        #ifdef XTS_SUPPORT
+        extern uint8_t is_xts_test_done(void);
+            if (is_xts_test_done() == 0)
+                continue;
+        #endif
+        // get_charge_stat();
+
+        if (mail.comm.event == BATTERY_CMD_CHECK_VOLTAGE) {
+
+            g_check_count++;
+            // PRINT("BATTERY_CMD_CHECK_VOLTAGE g_check_count %d\r\n",g_check_count);
+            
+            if(last_battery_charge_enable_status == true){
+            
+                if (g_check_count*CHARGE_CHECK_TIMER_CYCLE_MS  >= ENABLE_CHARGE_TIMEOUT_MS)
+                {
+                    // PRINT("BATTERY_CMD_CHECK_VOLTAGE disable_charge \r\n");
+
+                    g_check_count = 0 ;
+                    //超时交换状态
+                    disable_charge();
+                    last_battery_charge_enable_status = false;
+                    // GraphicService::GetInstance()->PostGraphicEvent(std::bind(charger_plug_event_ui_callback, true));
+
+                }
+
+            }else if (last_battery_charge_enable_status == false) {
+                if (g_check_count*CHARGE_CHECK_TIMER_CYCLE_MS  >= DISABLE_CHARGE_CHECK_MS)
+                {
+                    // PRINT("BATTERY_CMD_CHECK_VOLTAGE battery_check_and_enable_charge \r\n");
+
+                    g_check_count = 0 ;
+                    //超时交换状态
+                    battery_check_and_enable_charge();
+                    last_battery_charge_enable_status = true;
+
+                    // GraphicService::GetInstance()->PostGraphicEvent(std::bind(charger_plug_event_ui_callback, false));
+
+                }
+                
+            }
+        }else if (mail.comm.event == BATTERY_CMD_CHARGE_PLUG) {
+            PRINT("[battery][service] charger_plug_event_ui_callback plugged \n");
+            // GraphicService::GetInstance()->PostGraphicEvent(std::bind(charger_plug_event_ui_callback, true));
+        }else if (mail.comm.event == BATTERY_CMD_CHARGE_UNPLUG) {
+            PRINT("[battery][service] charger_plug_event_ui_callback unplugged \n");
+            // GraphicService::GetInstance()->PostGraphicEvent(std::bind(charger_plug_event_ui_callback, false));
+        }
+    }
+}
+
+
+
+void ChargerEventPublish(uint16_t topic, uint16_t data)
+{
+    int32 ret;
+    uint32 size = sizeof(uint16_t);
+    Request *request = NULL;
+    BroadcastApi *broadcastApi = NULL;
+    IUnknown *api = NULL;
+
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish topic=%u!!", topic);
+
+    /* alloc request */
+    request = SAMGR_AllocRequestMsg(0, PLATFORM_CORE, BROADCAST_SVR_ID, size);
+    if (request == NULL) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SAMGR_AllocRequestMsg failed");
+        return;
+    }
+    request->msgId = topic;
+    ret = memcpy_s(request->data, size, (const void *)&data, size);
+    if (ret != EOK) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish memcpy_s rateDataTmp fail! ret = %d", ret);
+        return;
+    }
+    request->len = size;
+    request->msgValue = 0;
+
+    /* public request */
+    api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME);
+    if (api == NULL) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetFeatureApi failed");
+        SAMGR_FreeRequestMsg(request);
+        return;
+    }
+    ret = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi);
+    if (ret != 0 || broadcastApi == NULL) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "QueryInterface failed");
+        SAMGR_FreeRequestMsg(request);
+        return;
+    }
+    broadcastApi->PublishTopic((IUnknown *)broadcastApi, request);
+    broadcastApi->Release((IUnknown *)broadcastApi);
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish end!!");
+
+    return;
+}
+errcode_t charger_plug_event_ui_callback(bool plugged)
+{
+    if(plugged){
+        ChargerEventPublish( TOPIC_EVENT_CHARGE_PLUG,0);
+    }else{
+        ChargerEventPublish(TOPIC_EVENT_CHARGE_UNPLUG,1);
+    } 
+}
+
+
+errcode_t battery_charger_plug_event_callback(uint8_t plugged)
+{
+        
+    PRINT("[battery][service] battery_charger_plug plugged %u \n",plugged);
+
+    if(plugged == 1){
+        // PRINT("[battery][service] battery_charger_plug plugged \n");
+        do_battery_check_msg(BATTERY_CMD_CHARGE_PLUG);
+    }else{
+        // PRINT("[battery][service] battery_charger_plug unplugged \n");
+        do_battery_check_msg(BATTERY_CMD_CHARGE_UNPLUG);
+    }   
+    return ERRCODE_SUCC;
+}
+
+
+errcode_t uapi_battery_init(void)
+{
+    if (osal_msg_queue_create("battery_queue", APP_BOARD_MSG_COUNT, &g_app_queue,
+                              0, sizeof(common_notify_mail_t)) != ERRCODE_SUCC) {
+        PRINT("[battery][service] app create mail fail\n");
+        return ERRCODE_FAIL;
+    }
+
+
+    osal_task *task_handle = osal_kthread_create((osal_kthread_handler)battery_check_task, NULL,
+                                                 "battery_service", APP_BOARD_TASK_SIZE);
+    if (task_handle == NULL) {
+        osal_msg_queue_is_full(g_app_queue);
+        PRINT("create battery service thread fail!\r\n");
+        return ERRCODE_FAIL;
+    }
+
+    osal_kthread_set_priority(task_handle, APP_BOARD_TASK_PRIO);
+    // osal_kthread_set_priority(task_handle, 10);
+    g_battery_timer = osTimerNew((osTimerFunc_t)battery_check_timer_callback, osTimerOnce, NULL, NULL);
+
+    /**下面初始化电池基本数据,充电线基本状态*/
+    uapi_register_charger_event_callback(battery_charger_plug_event_callback);
+   
+    //开始timer
+    battery_timer_start_check_released(CHARGE_CHECK_TIMER_CYCLE_MS);
+
+
+    return ERRCODE_SUCC;
+}
+
+void battery_service_resume(void)
+{
+    PRINT("battery_service resume!\r\n");
+    // battery_check_timer_callback(0);
+}
+void battery_service_suspend(void)
+{
+    PRINT("battery_service suspend!\r\n");
+}
+
+
+
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
\ No newline at end of file
@@ -1,9 +1,16 @@
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
 #include "at_cmd_api.h"
 #include "pm_control.h"
 #include "debug_print.h"
 #include "battery_hal.h"
 #include "battery_service.h"
 #include "string.h"
+#include "battery_at_cmd.h"
 
 #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
 #define BATTERY_MAX_ARGC            8
@@ -78,3 +85,10 @@ at_cmd_table_t *get_battery_cmd_table(uint32_t *cmd_count)
     *cmd_count = ARRAY_COUNT(g_battery_cmd);
     return (at_cmd_table_t *)g_battery_cmd;
 }
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
\ No newline at end of file
index fb5f82b..2958163 100755 (executable)
@@ -56,6 +56,9 @@
 #ifdef SUPPORT_AT_OHOSFWK\r
 #include "ohosfwk_startup.h"\r
 #endif\r
+#ifdef SUPPORT_AT_VIBRATOR\r
+#include "vibrator_service.h"\r
+#endif\r
 #ifdef SUPPORT_BATTERY_SERVICE\r
 #include "battery_service.h"\r
 #endif\r
 #ifdef ACC_LIS2DOC\r
 #include "acc_service.h"\r
 #endif\r
+\r
+#ifdef SUPPORT_ALIPAY_SEC\r
+#include "alipay_feature.h"\r
+#endif\r
 #include "clocks_config.h"\r
 \r
 #define EMMC_BASE_ADDR              0x52062000\r
@@ -306,15 +313,21 @@ static void thread_main(const void *unused)
 #endif\r
     uapi_pm_remove_sleep_veto(PM_ID_DEBUG);\r
 \r
-\r
+#ifdef SUPPORT_AT_VIBRATOR\r
+    uapi_vibrator_service_init();\r
+#endif\r
 #ifdef SUPPORT_BATTERY_SERVICE\r
     uapi_battery_init();\r
 #endif\r
+\r
 #ifdef MAG_MMC5603\r
     uapi_mag_service_init();\r
 #endif\r
 #ifdef ACC_LIS2DOC\r
     uapi_acc_service_init();\r
+#endif\r
+#ifdef SUPPORT_ALIPAY_SEC\r
+    uapi_alipay_svr_init();\r
 #endif\r
     set_startup_finish_flag();\r
 }\r
index 19d4b36..15f15c4 100755 (executable)
@@ -21,6 +21,11 @@ uint8_t g_alipay_i2c_mempool[ALIPAY_SEC_I2C_MEMPOOL_SIZE] = {0};
 unsigned char *IIC_Master_Init(void)\r
 {\r
     errcode_t result;\r
+    result = i2c_master_init_check(ALIPAY_SEC_I2C_INDEX, 100000, I2C_SPEED_MODE_SS);\r
+    if (result == ERRCODE_I2C_ALREADY_INIT) {\r
+        return g_alipay_i2c_mempool;\r
+    }\r
+\r
     result = uapi_i2c_master_init(ALIPAY_SEC_I2C_INDEX, 100000, I2C_SPEED_MODE_SS); /* 100000: 100KHz */\r
     if (result != ERRCODE_SUCC) {\r
         MyPrintf("se i2c init fail! ret=0x%x", result);\r
index e3ba629..0f8413f 100755 (executable)
@@ -146,19 +146,20 @@ target = {
                           "acc_sensor",
                           "mag_sensor",
                           "vibrator",
+                          "vibrator_service",
                           "lwIP",
                           "audio_manager",
                           "custom_utils",
                           "rotary_encoder",
-                        #   "nativelauncher",
-                          "fd230launcher",
+                          "nativelauncher",
+                        #   "fd230launcher",
                           "batterry_service"
                                                  ],
         'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'alipay_set'],
         'dsp_version': 'max',
         'packet': True,
-        # 'fs_image_path':'evb4',
-        'fs_image_path':'fd230',
+        'fs_image_path':'evb4',
+        # 'fs_image_path':'fd230',
         'fs_image': True
     },
     #native-xts: liteos + uikit + nandflash + mipi + psram + audio  典型合封UIKIT版本
@@ -191,6 +192,7 @@ target = {
                           "acc_sensor",
                           "mag_sensor",
                           "vibrator",
+                          "vibrator_service",
                           "audio_manager",
                           "custom_utils",
                           "rotary_encoder",
index 875660b..76a4e66 100755 (executable)
@@ -218,15 +218,22 @@ static void deal_with_vbus_event(void)
 {
     if (reg32_getbit(ULP_WKUP_INT_STS, VBUS_INSERT_INTERRUPT_POS) == 1) {
         charger_plugged = true;
-
-       
-    }else if (reg32_getbit(ULP_WKUP_INT_STS, VBUS_UNPLUG_INNTERRUPT_POS) == 1) {
-        charger_plugged = false;
+        if (g_charger_callbackevent != NULL)
+        {
+            g_charger_callbackevent(1);
+        }
+        return ;
     }
-    if (g_charger_callbackevent != NULL)
-    {
-        g_charger_callbackevent(charger_plugged);
+    
+    if (reg32_getbit(ULP_WKUP_INT_STS, VBUS_UNPLUG_INNTERRUPT_POS) == 1) {
+        charger_plugged = false;
+        if (g_charger_callbackevent != NULL)
+        {
+            g_charger_callbackevent(0);
+        }
+        return ;
     }
+    
     return;
 }
 
index 6a315c1..d5ab5f1 100755 (executable)
@@ -80,7 +80,7 @@ typedef enum {
     STARTUP_OTHER
 } startup_reason_t;
 
-typedef errcode_t (*charger_plug_event_callback_func_t)(bool plug_event);
+typedef errcode_t (*charger_plug_event_callback_func_t)(uint8_t plug_event);
 
 
 button_peripheral_api *button_port_get_api(void);
index 52ee4c8..13c1597 100644 (file)
@@ -13,3 +13,4 @@ add_subdirectory_if_exist(vibrator)
 add_subdirectory_if_exist(slip)
 add_subdirectory_if_exist(utils)
 add_subdirectory_if_exist(rotary_encoder)
+add_subdirectory_if_exist(vibrator/service)
index 93b247f..69af41f 100644 (file)
@@ -7,10 +7,12 @@ set(COMPONENT_NAME "vibrator")
 set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/vibrator.c
     ${CMAKE_CURRENT_SOURCE_DIR}/vibrator_at_cmd.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/vibrator_hal.c
 )
 
 set(PUBLIC_HEADER
     ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}/service
 )
 
 set(PRIVATE_HEADER
diff --git a/code/sdk/drivers/peripheral/vibrator/service/CMakeLists.txt b/code/sdk/drivers/peripheral/vibrator/service/CMakeLists.txt
new file mode 100644 (file)
index 0000000..11cd7ca
--- /dev/null
@@ -0,0 +1,56 @@
+#===============================================================================
+# @brief    cmake file
+# Copyright (c) @CompanyNameMagicTag 2022-2023. All rights reserved.
+#===============================================================================
+set(COMPONENT_NAME "vibrator_service")
+
+set(SOURCES
+    ${CMAKE_CURRENT_SOURCE_DIR}/vibrator_service.cpp
+)
+
+set(PUBLIC_HEADER
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+set(PRIVATE_HEADER
+    ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits
+    ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits
+    ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits
+)
+
+set(PRIVATE_DEFINES
+)
+
+set(PUBLIC_DEFINES
+)
+
+# use this when you want to add ccflags like -include xxx
+set(COMPONENT_PUBLIC_CCFLAGS
+)
+
+set(COMPONENT_CCFLAGS
+    -std=c++11
+    -Wno-error
+    -Wno-unused-parameter
+    -fno-exceptions
+    -fno-unwind-tables
+    -fno-asynchronous-unwind-tables
+    -Wno-undef
+    -Wno-bitwise-op-parentheses
+    -Wno-shift-op-parentheses
+    -nostdlibinc
+    -nostdinc
+    -nostdlib
+    -Wno-c++11-narrowing
+    -Wno-error=unused-function
+)
+
+set(WHOLE_LINK
+    true
+)
+
+set(MAIN_COMPONENT
+    false
+)
+
+build_component()
diff --git a/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp b/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp
new file mode 100644 (file)
index 0000000..88967fe
--- /dev/null
@@ -0,0 +1,157 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n
+ *
+ * Description: Test adc source \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2022-08-16, Create file. \n
+ */
+
+#include "dock/vibrator_manager.h"
+
+// using namespace OHOS::VibratorType;
+// using namespace OHOS::VibratorManager;
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+
+#include "pinctrl.h"
+#include "debug_print.h"
+#include "soc_osal.h"
+#include "tcxo.h"
+#include "irmalloc.h"
+#include "errcode.h"
+#include "common_def.h"
+
+#include "chip_core_irq.h"
+#include "chip_io.h"
+#include "gpio.h"
+#include "pm_veto.h"
+
+#include "rtc.h"
+#include "timer.h"
+#include "systick.h"
+
+
+static bool g_batter_service_initialled = false;
+
+#include "tcxo.h"
+
+#include "cmsis_os2.h"
+#include "input_app.h"
+
+#include "vibrator_service.h"
+#include "vibrator_hal.h"
+#include "vibrator.h"
+
+void custom_VibratorFunc(OHOS::VibratorType vibratorType)
+{
+    switch (vibratorType)
+    {
+        case OHOS::VibratorType::VIBRATOR_TYPE_ONE:
+            do_vibrator_cmd(VIB_CMD_MSG_ONE);
+        break;
+        case OHOS::VibratorType::VIBRATOR_TYPE_TWO:
+            do_vibrator_cmd(VIB_CMD_MSG_TWO);
+        break;
+        case OHOS::VibratorType::VIBRATOR_TYPE_THREE:
+            do_vibrator_cmd(VIB_CMD_MSG_THREE);
+        break;
+    } 
+
+}
+
+#define MAG_CHECK_MS 20
+static unsigned long g_app_queue;
+
+static bool vibrator_service_running_stat = false;
+
+
+void uapi_vibrator_service_deinit(void)
+{
+
+}
+
+
+
+void do_vibrator_cmd(int cmd)
+{
+    int ret;
+
+    common_notify_mail_t mail = {0};
+    mail.comm.app = (app_type)cmd;
+    ret = osal_msg_queue_write_copy(g_app_queue, (void *)&mail,
+                                    sizeof(common_notify_mail_t), 0);
+    if (ret != OSAL_SUCCESS) {
+        PRINT("Error mag Check MSG 0x%02X send failed! err=0x%x! \r\n",cmd, ret);
+    }
+    
+}
+
+static void vibrator_service_check_task(void const *arg)
+{
+    unused(arg);
+    int32_t ret;
+    common_notify_mail_t mail;
+    uint32_t msgsize = (uint32_t)sizeof(common_notify_mail_t);
+
+    while (1) {
+        ret = osal_msg_queue_read_copy(g_app_queue, (void *)&mail, &msgsize,
+                                       OSAL_MSGQ_WAIT_FOREVER);
+        if (ret != OSAL_SUCCESS) {
+            continue;
+        }
+
+
+        if (mail.comm.app == VIB_CMD_MSG_ONE)
+        {
+            g_VibratorFunc( 1 ,  500, 50);
+        }
+         else if (mail.comm.app == VIB_CMD_MSG_TWO)
+        {
+             g_VibratorFunc( 2 ,  500, 50);
+        }
+         else if (mail.comm.app == VIB_CMD_MSG_THREE)
+        {
+             g_VibratorFunc( 3 ,  500, 50);
+        }
+
+    }
+}
+
+errcode_t uapi_vibrator_service_init(void)
+{
+    if (osal_msg_queue_create("vibrator_service_queue", APP_BOARD_MSG_COUNT, &g_app_queue,
+                              0, sizeof(common_notify_mail_t)) != ERRCODE_SUCC) {
+        PRINT("[mag][service] app create mail fail\n");
+        return ERRCODE_FAIL;
+    }
+
+
+    osal_task *task_handle = osal_kthread_create((osal_kthread_handler)vibrator_service_check_task, NULL,
+                                                 "vibrator_service_service", APP_BOARD_TASK_SIZE);
+    if (task_handle == NULL) {
+        osal_msg_queue_is_full(g_app_queue);
+        PRINT("create mag service thread fail!\r\n");
+        return ERRCODE_FAIL;
+    }
+
+    osal_kthread_set_priority(task_handle, APP_BOARD_TASK_PRIO);
+    // osal_kthread_set_priority(task_handle, 10);
+
+
+    OHOS::VibratorManager::GetInstance()->RegisterVibratorFunc(custom_VibratorFunc);
+    
+    return ERRCODE_SUCC;
+}
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.h b/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.h
new file mode 100644 (file)
index 0000000..d1d1d58
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n
+ *
+ * Description: Test adc header \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2022-08-16, Create file. \n
+ */
+
+#ifndef VIB_SERVICE_H__
+#define VIB_SERVICE_H__
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#include "stdint.h"
+#include "errcode.h"
+
+
+#define VIB_CMD_MSG_ONE 0x21
+#define VIB_CMD_MSG_TWO 0x22
+#define VIB_CMD_MSG_THREE 0x23
+
+/**
+ * 测试指令 参数cmd 选项: VIB_CMD_MSG_ONE VIB_CMD_MSG_TWO VIB_CMD_MSG_THREE
+*/
+extern void do_vibrator_cmd(int cmd);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
\ No newline at end of file
index c8acb13..d928dc9 100644 (file)
 #include "pwm.h"
 #include "pwm_porting.h"
 #include "pinctrl.h"
+#include "vibrator.h"
+
+
+
+#ifdef  VIB_USE_PWM
 #define VIBRATOR_GPIOPPIN S_AGPIO_R2
 // #define VIBRATORPIN_MODE HAL_PIO_FUNC_PWMP1_M2 
 #define VIBRATORPIN_MODE HAL_PIO_FUNC_PWMN1_M3 
@@ -101,15 +106,59 @@ static int test_pwm_repeat(int vibratorType)
 
     return 0;
 }
-void g_VibratorFunc(uint8_t vibratorType , uint16_t delaytime)
+void g_VibratorFunc(uint8_t vibratorType , uint16_t vibtime_ms,uint16_t delaytime_ms)
 {
 
     if(vibratorType <1 || vibratorType > 3)
     {
         PRINT("g_VibratorFunc vib times should in 1~3 \r\n",vibratorType);
     }else{
-        PRINT("g_VibratorFunc vib  %d times , delaytime %d\r\n",vibratorType ,  delaytime);
-        delay_ms = delaytime;
+        PRINT("g_VibratorFunc vib  %d times , delaytime_ms %d\r\n",vibratorType ,  delaytime_ms);
+        delay_ms = delaytime_ms;
         test_pwm_repeat(vibratorType);
     }
 }
+
+#else
+#define VIBRATOR_GPIOPPIN S_AGPIO_R2
+#define VIBRATORPIN_MODE HAL_PIO_FUNC_GPIO 
+static  pin_t pin = VIBRATOR_GPIOPPIN;
+static  pin_mode_t mode = VIBRATORPIN_MODE;
+#define VIBRATOR_VIB_HZ 200
+
+static void vib_once(uint32_t duration_time)
+{
+      uint32_t delaytime_ms = 1000/VIBRATOR_VIB_HZ;
+      uapi_pin_set_mode(VIBRATOR_GPIOPPIN, (pin_mode_t)HAL_PIO_FUNC_GPIO);
+      uapi_gpio_set_dir(VIBRATOR_GPIOPPIN,GPIO_DIRECTION_OUTPUT);
+
+      while(duration_time)
+      {
+        duration_time-=delaytime_ms;
+        uapi_gpio_toggle(VIBRATOR_GPIOPPIN);
+        uapi_tcxo_delay_ms(delaytime_ms); 
+      }
+      uapi_gpio_set_val(VIBRATOR_GPIOPPIN,GPIO_LEVEL_LOW);
+}
+
+void g_VibratorFunc(uint8_t vibratorType , uint16_t vibtime_ms,uint16_t delaytime_ms)
+{
+
+    if(vibratorType >0)
+    {
+        PRINT("g_VibratorFunc vib  %d times , vibtime_ms %d , delaytime_ms %d\r\n",vibratorType ,vibtime_ms,  delaytime_ms);
+        uint8_t count = vibratorType;
+        while(count--)
+        {
+            // PRINT("g_VibratorFunc vib  %d times \r\n",count );
+            vib_once(vibtime_ms);
+            // PRINT("g_VibratorFunc vib  %d times \r\n",count );
+            uapi_tcxo_delay_ms(delaytime_ms);
+        }
+    }else{
+        PRINT("Not Supported Vibtype %d !\r\n",vibratorType );
+
+    }
+}
+
+#endif
index b0983db..c23f1f9 100644 (file)
@@ -21,7 +21,7 @@ extern "C" {
 /**
  * vibtype 1 vib1 , 2 vib2, 3 vib3 
 */
-void g_VibratorFunc(uint8_t vibratorType , uint16_t delaytime);
+void g_VibratorFunc(uint8_t vibratorType , uint16_t vibtime_ms,uint16_t delaytime_ms);
 
 /**
  * @}
index 6f54417..0b6cf4e 100644 (file)
@@ -6,6 +6,7 @@
 #include "pm_control.h"
 #include "vibrator.h"
 #include "debug_print.h"
+#include "vibrator_hal.h"
 
 #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
 #define VIBRATOR_MAX_ARGC            8
@@ -56,13 +57,13 @@ static uint32_t vibrator_do_test(uint8_t *para, uint32_t paraLen, char *strCommo
         return ERRCODE_FAIL;
     }
 
-    if (argc != 2) {
+    if (argc != 1) {
         PRINT("VIBRATORTEST ATCMD Set Parameter Failed argc %d\n",argc);
         return ERRCODE_FAIL;
     }
-    uint8_t channel = (uint8_t)atoi((char*)argv[0]);
-    uint16_t delaytime = (uint16_t)atoi((char*)argv[1]);
-    g_VibratorFunc(channel,delaytime);
+    uint8_t vibtype = (uint8_t)atoi((char*)argv[0]);
+    PRINT("VIBRATORTEST ATCMD custom_VibratorFunc VibType %d\n",vibtype);
+    hal_custom_VibratorFunc(vibtype);
     return ERRCODE_SUCC;
 }
 
diff --git a/code/sdk/drivers/peripheral/vibrator/vibrator_hal.c b/code/sdk/drivers/peripheral/vibrator/vibrator_hal.c
new file mode 100644 (file)
index 0000000..ebe90dc
--- /dev/null
@@ -0,0 +1,23 @@
+
+#include "vibrator_hal.h"
+#include "vibrator_service.h"
+#include "debug_print.h"
+void hal_custom_VibratorFunc(uint8_t vibratorType)
+{
+    switch (vibratorType)
+    {
+        case ENUM_VIBRATOR_TYPE_ONE:
+            PRINT("ENUM_VIBRATOR_TYPE_ONE\r\n");
+            do_vibrator_cmd(VIB_CMD_MSG_ONE);
+        break;
+        case ENUM_VIBRATOR_TYPE_TWO:
+            PRINT("ENUM_VIBRATOR_TYPE_TWO\r\n");
+            do_vibrator_cmd(VIB_CMD_MSG_TWO);
+        break;
+        case ENUM_VIBRATOR_TYPE_THREE:
+            PRINT("ENUM_VIBRATOR_TYPE_THREE\r\n");
+            do_vibrator_cmd(VIB_CMD_MSG_THREE);
+        break;
+    } 
+
+}
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/vibrator/vibrator_hal.h b/code/sdk/drivers/peripheral/vibrator/vibrator_hal.h
new file mode 100644 (file)
index 0000000..9b21864
--- /dev/null
@@ -0,0 +1,38 @@
+
+/**
+ * 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 HX3507_HAL_H
+#define HX3507_HAL_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 */
+typedef enum {
+    ENUM_VIBRATOR_TYPE_ONE=1,
+    ENUM_VIBRATOR_TYPE_TWO=2,
+    ENUM_VIBRATOR_TYPE_THREE=3,
+} VIB_TYPE_ENUM_T;
+
+void hal_custom_VibratorFunc(uint8_t vibratorType);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
index 21f37da..a4ca91b 100755 (executable)
 #include "dock/vibrator_manager.h"
 
 #if ENABLE_VIBRATOR
+
+
 namespace OHOS {
 VibratorManager* VibratorManager::GetInstance()
 {
     static VibratorManager instance;
     return &instance;
 }
+
 } // namespace OHOS
 #endif