You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
2.6 KiB
108 lines
2.6 KiB
2 years ago
|
#include "menu_port.h"
|
||
|
#include "elog.h"
|
||
|
|
||
|
// #define Max_MenuBuf_Size 256
|
||
|
|
||
|
extern UART_HandleTypeDef huart3;
|
||
|
extern const struct menu_tree_node menu_tree[];
|
||
|
// extern osMessageQueueId_t menuMsgQueueHandle;
|
||
|
// extern osSemaphoreId_t elog_menuHandle;
|
||
|
|
||
|
uint8_t Menu_Buf[Max_MenuBuf_Size];
|
||
|
|
||
|
UART_HandleTypeDef *Menuhuart = &huart3;
|
||
|
MenuPort_t *menuport;
|
||
|
|
||
|
MenuPort_t * MenuPort_Init( )
|
||
|
{
|
||
|
|
||
|
MenuPort_t *Handle = (MenuPort_t *)malloc(sizeof(MenuPort_t));
|
||
|
if (Handle == NULL)
|
||
|
{
|
||
|
Menuport_Error("fail to create MenuPort");
|
||
|
return NULL;
|
||
|
}
|
||
|
Handle->menu = (struct menu *)malloc(sizeof(struct menu));
|
||
|
return Handle;
|
||
|
|
||
|
}
|
||
|
|
||
|
void MenuPort_Setup( MenuPort_t *menuport, UART_HandleTypeDef *huart, GPIO_TypeDef *gpio, uint16_t pin, uint8_t mode ,uint8_t trans_mode)
|
||
|
{
|
||
|
menuport->huart = huart;
|
||
|
menuport->gpio = gpio;
|
||
|
menuport->pin = pin;
|
||
|
menuport->mode = mode;
|
||
|
menuport->trans_mode = trans_mode;
|
||
|
|
||
|
}
|
||
|
|
||
|
/* 待传入的函数 实际函数*/
|
||
|
int MenuPort_Send(MenuPort_t *menuport, uint8_t * buf, uint32_t size){
|
||
|
if( menuport->mode ==1 ) {
|
||
|
HAL_GPIO_WritePin(menuport->gpio,menuport->pin , SET);
|
||
|
}
|
||
|
|
||
|
switch (menuport->trans_mode)
|
||
|
{
|
||
|
case 1:
|
||
|
HAL_UART_Transmit_IT(menuport->huart, buf, size);
|
||
|
break;
|
||
|
case 2:
|
||
|
HAL_UART_Transmit_DMA(menuport->huart, buf, size);
|
||
|
break;
|
||
|
default:
|
||
|
HAL_UART_Transmit(menuport->huart, buf, size,0xFFFF);
|
||
|
}
|
||
|
|
||
|
if( menuport->mode ==1 ) {
|
||
|
HAL_GPIO_WritePin( menuport->gpio, menuport->pin , RESET );
|
||
|
}
|
||
|
return 0;
|
||
|
|
||
|
}
|
||
|
|
||
|
void Menuport_receive_callback(MenuPort_t *menuport, uint8_t *buf,uint32_t size)
|
||
|
{
|
||
|
/* 接收回调 中断直接调用menu, 不经过menuport回调*/
|
||
|
menu_parse_callback( menuport->menu, (char *)buf, size );
|
||
|
|
||
|
}
|
||
|
|
||
|
void menuport_exit( MenuPort_t *menuport)
|
||
|
{
|
||
|
if ( menu_get_state(menuport->menu) != 0 )
|
||
|
{
|
||
|
// osSemaphoreRelease(elog_menuHandle); /* 一直持有到菜单结束才释放*/
|
||
|
menu_exit(menuport->menu );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Menuport_Error(char *error)
|
||
|
{
|
||
|
/* 定制输出 error内容*/
|
||
|
// printf (error);
|
||
|
while (1);
|
||
|
}
|
||
|
|
||
|
|
||
|
void menu_entry( void *argument)
|
||
|
{
|
||
|
// osStatus_t status;
|
||
|
// uint8_t recv_buff[Max_MenuBuf_Size] ={0};
|
||
|
menuport = MenuPort_Init();
|
||
|
MenuPort_Setup( menuport, Menuhuart, NULL, 0, 0, 0 ); /* poll 模式发送,DMA IT 模式会出问题*/
|
||
|
menu_init( menuport->menu, menu_tree, (void*)menuport, ( menu_send_function_type ) MenuPort_Send );
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
void Menu_Task( MenuPort_t *menuport){
|
||
|
menu_print_callback(menuport->menu);
|
||
|
// for ( ; ; )
|
||
|
// {
|
||
|
// osDelay(10);
|
||
|
// menu_print_callback(((MenuPort_t *)argument)->menu);
|
||
|
// }
|
||
|
}
|