85 lines
1.9 KiB
C
85 lines
1.9 KiB
C
|
||
#include "app.h"
|
||
#include "board.h"
|
||
#include "flow.h"
|
||
|
||
static struct flow business_fw; // 业务流程
|
||
static struct flow idle_fw; // 空闲任务
|
||
|
||
app_t app;
|
||
|
||
static uint8_t business_inspection(struct flow *fl)
|
||
{
|
||
FL_HEAD(fl);
|
||
for (;;)
|
||
{
|
||
tmc2240_config(TMC2240_1);
|
||
tmc2240_position_read(TMC2240_1);
|
||
FL_LOCK_DELAY(fl, FL_CLOCK_SEC);
|
||
}
|
||
FL_TAIL(fl);
|
||
}
|
||
/**
|
||
* @brief 对流量进行空闲检查
|
||
*
|
||
* 该函数会对传入的流量结构体进行空闲检查。
|
||
*
|
||
* @param fl 指向流量结构体的指针
|
||
*
|
||
* @return 返回值始终为0,该函数不返回实际值
|
||
*/
|
||
static uint8_t idle_inspection(struct flow *fl)
|
||
{
|
||
FL_HEAD(fl);
|
||
static uint32_t tick = 0;
|
||
for (;;)
|
||
{
|
||
GPIO_TOGGLE(LED_BLUE_GPIO_Port, LED_BLUE_Pin);
|
||
ssd1306_f6x8_string(0, 2, " tick:");
|
||
ssd1306_f6x8_number(40, 2, tick++, 0);
|
||
ssd1306_f6x8_string(0, 4, " cfg:");
|
||
ssd1306_f6x8_number(40, 4, tmc2240_get(TMC2240_1)->data.gconf, 0);
|
||
ssd1306_update_screen();
|
||
FL_LOCK_DELAY(fl, FL_CLOCK_SEC);
|
||
}
|
||
FL_TAIL(fl);
|
||
}
|
||
/**
|
||
* @brief 运行应用程序
|
||
*
|
||
* 该函数用于启动应用程序的运行。
|
||
*
|
||
* @details 此函数会调用 idle_inspection 函数,传入 idle_fw 作为参数。
|
||
* idle_inspection 函数的具体作用需参考其实现细节。
|
||
*/
|
||
void app_run(void)
|
||
{
|
||
business_inspection(&business_fw); // 业务流程检测
|
||
idle_inspection(&idle_fw);
|
||
}
|
||
|
||
/**
|
||
* @brief 初始化应用程序
|
||
*
|
||
* 初始化应用程序,包括启动空闲任务。
|
||
*/
|
||
void app_init(void)
|
||
{
|
||
ssd1306_draw_text_center(3, "LOADING...");
|
||
delay_ms(200);
|
||
// 显示加载进度条
|
||
ssd1306_clear_buffer();
|
||
for (uint8_t i = 0; i <= 100; i += 10)
|
||
{
|
||
ssd1306_draw_progress_bar(i);
|
||
}
|
||
|
||
FL_INIT(&business_fw); // 业务流程
|
||
FL_INIT(&idle_fw); // 空闲任务
|
||
|
||
ENABLE_TIM(TASK_TIM);
|
||
ENABLE_TIM(WORK_TIM);
|
||
|
||
ssd1306_clear();
|
||
}
|