Lab Session 4
在Lab 3的基础上增加低功耗 (Auto Judgement) 功能
5.4
增加低功耗 (Auto Judgement) 功能应用程序
5.4.1 将培训配套资料Checkpoints文件夹中的工程 "Lab session 4" 中的qe_gen文件的 "qe_touch_sample.c" 拷贝
并覆盖 "Project Explorer" 的Lab_session_1工程中qe_gen文件的 "qe_touch_sample.c".
5.4.2 应用程序代码说明
使用init_peripheral_function初始化需要使用的外设
使用R_CTSU_Open() 初始化config01 (MEC电极)
使用RM_TOUCH_Open() 初始化config02 (12个自容式按键)
/* Initialize peripheral functions */ init_peripheral_function(); /* Open Touch middleware */ err = R_CTSU_Open (g_qe_ctsu_instance_config01.p_ctrl, g_qe_ctsu_instance_config01.p_cfg); ctsu_ctrl = (ctsu_instance_ctrl_t *)g_qe_ctsu_instance_config01.p_ctrl; err = RM_TOUCH_Open (g_qe_touch_instance_config02.p_ctrl, g_qe_touch_instance_config02.p_cfg);
5.4.3 应用程序代码说明
以下代码完成config01 (MEC电极) 和 config02 (12个自容式按键电极) 的初始化偏置电流调整。
/* Initial Offset Tuning */ { (void)R_LPT_SetCMT(LPT_CH1, (uint32_t)WAKEUP_LPT_PERIOD_NORMAL); /* Method1 offset tuning */ do { err = R_CTSU_ScanStart (g_qe_ctsu_instance_config01.p_ctrl); if (FSP_SUCCESS != err) { while (true) {} } (void)R_LPT_Control(LPT_CMD_START); while (0 == g_qe_touch_flag) {} g_qe_touch_flag = 0; err = R_CTSU_OffsetTuning (g_qe_ctsu_instance_config01.p_ctrl); } while(err != FSP_SUCCESS); /* Method2 offset tuning */ do { err = RM_TOUCH_ScanStart (g_qe_touch_instance_config02.p_ctrl); if (FSP_SUCCESS != err) { while (true) {} } (void)R_LPT_Control(LPT_CMD_START); while (0 == g_qe_touch_flag) {} g_qe_touch_flag = 0; err = RM_TOUCH_DataGet(g_qe_touch_instance_config02.p_ctrl, &button_status02, NULL, NULL); } while(err != FSP_SUCCESS); }
5.4.4 应用程序代码说明
以下代码完成config01 (MEC电极) 在Normal模式下的baseline调整。
/* base line setting @method1 */ for (uint32_t i = 0U; i < WAKEUP_TIME_BASELINE; i++) { err = R_CTSU_ScanStart (g_qe_ctsu_instance_config01.p_ctrl); if (FSP_SUCCESS != err) { while (true) {} } (void)R_LPT_Control(LPT_CMD_START); R_BSP_SoftwareDelay(WAKEUP_WAIT_MEASUREEND, BSP_DELAY_MILLISECS); (void)R_LPT_Control(LPT_CMD_STOP); (void)R_LPT_Control(LPT_CMD_COUNT_RESET); ctsu_ctrl->state = CTSU_STATE_SCANNED; err = R_CTSU_AutoJudgementDataGet (g_qe_ctsu_instance_config01.p_ctrl, &button_status01); if (FSP_SUCCESS == err) { RM_TOUCH_MonitorAddressGet (g_qe_touch_instance_config02.p_ctrl, &monitor_buf_address, &monitor_id_address, &monitor_size_address); qe_monitor_autojudge (g_qe_ctsu_instance_config01.p_ctrl); } }
5.4.5 应用程序代码说明
以下代码完成进入低功耗模式的操作,在低功耗模式里完成config01 (MEC电极) 的测量和自动判断,当config01 (MEC电极) 有按键On判断是时,退出低功耗,并通过R_CTSU_AutoJudgementDataGet() 取得结果。
/* Standby mode */ { /* for [CONFIG01] configuration */ (void)R_LPT_SetCMT(LPT_CH1, (uint32_t)WAKEUP_LPT_PERIOD_STANDBY); err = R_CTSU_ScanStart (g_qe_ctsu_instance_config01.p_ctrl); /* Enter software standby mode */ lpc_err = R_LPC_LowPowerModeActivate(&activate_standby_callback); if (LPC_SUCCESS != lpc_err) { while (true) {} } while (0 == g_qe_touch_flag) {} g_qe_touch_flag = 0; err = R_CTSU_AutoJudgementDataGet (g_qe_ctsu_instance_config01.p_ctrl, &button_status01); if (FSP_SUCCESS == err) { RM_TOUCH_MonitorAddressGet (g_qe_touch_instance_config02.p_ctrl, &monitor_buf_address, &monitor_id_address, &monitor_size_address); qe_monitor_autojudge (g_qe_ctsu_instance_config01.p_ctrl); } }
5.4.6 应用程序代码说明
以下代码为进入Software Standby Mode时的Callback程序,用于启动Low-power Timer定时器。
/* activate_standby_callback */ static void activate_standby_callback(void *p_data) { lpt_err_t lpt_err; /* Start LPT count */ lpt_err = R_LPT_Control(LPT_CMD_START); if (LPT_SUCCESS != lpt_err) while(1); }
5.4.7 应用程序代码说明
以下代码为退出Snooze Mode时的Callback程序,用于停止和复位Low-power Timer定时器,以及disable snooze release interrupt。
/*snooze_callback*/ static void snooze_callback(void *p_data) { lpt_err_t lpt_err; lpc_err_t lpc_err; /* Stop LPT count */ lpt_err = R_LPT_Control(LPT_CMD_STOP); if (LPT_SUCCESS != lpt_err) while(1); /* Reset LPT count */ lpt_err = R_LPT_Control(LPT_CMD_COUNT_RESET); if (LPT_SUCCESS != lpt_err) while(1); /* Disable snooze release interrupt */ lpc_err = R_LPC_SnoozeModeConfigure(&gs_snooze_mode); if (LPC_SUCCESS != lpc_err) while(1); }
5.4.8 点击图标,编译程序。
5.4.9 以上应用程序代码的详细解释
您可参考瑞萨官网的应用笔记RX140 Group Smart Wakeup Solution Rev.1.00以及配套的样例程序。
审核编辑:刘清
全部0条评论
快来发表一下你的评论吧 !