支持SPI=FLASH,DAP-LINK

This commit is contained in:
armfly 2020-11-29 21:36:51 +08:00
parent 3398d87db7
commit 0ab5e357af
72 changed files with 4661 additions and 1744 deletions

View File

@ -1,3 +1,21 @@
----------------------------------------------------------------------------
2020-11-29 V1.40 【重大更新】
新增功能:
1.增加SPI Flash脱机烧录功能需要升级PC软件更新EMMC磁盘文件
2.增加CMSIS-DAP仿真器功能。新增2个参数控制TVCC电压和蜂鸣器使能
3.增加DS18B20温度传感器驱动接口D0-D7可外接8个传感器.
- 新增lua接口函数 ok,temp = read("DS18B20", 2) --读D2口外接的传感器数据
- 数据监视器菜单下新增DS18B20温度表显示8路温度值
BUG:
1.解决串口监视器BUGASCII模式如果收到0x00, 则不显示后面的数据。需要将不可见字符转换空格
2.解决在非lua小程序界面执行luaPC机下载无法长按C退出的问题
其他优化:
1.按键驱动底层忽略从其他状态跳转过来时,第一个长按键和按键弹起事件
2.上电不显示logo界面以前有2秒延迟
3.lwip初始化代码拆分到 lwip_pro() 中执行,加快界面启动速度
----------------------------------------------------------------------------
2020-10-19 V1.35
1.解决CX32芯片机台信号异常1拖2模式解除SWD保护时机台GPIO输出解锁脉冲

View File

@ -10,3 +10,23 @@
普通触发模式还有遗留问题拖动触发位置滚动条时超出波形范围后H7-TOOL程序假死频繁进入看门狗中断暂未解决。H7-TOOL界面翻到电压档界面可恢复。
2020-10-26 SPI Flash烧录器接口方案
- 待定方案, 口线不够实现4路烧录
D0 PD14 PA15 PI0 - DIR PH8 CS2
D1 PD15 PA8 PH19 - DIR PG8 CS3
D2 PE6 PD0 PB7 - DIR PD9 MOSI (硬件SPI信号)
D3 PE5 PD1 PH11 - DIR PG10 MISO_1 (硬件SPI信号)
D4 PE4 PE7 PH12 - DIR PG12 CS1 (软件控制片选)
D5 PE2 PE8 PI5 - DIR PG7 SCK (硬件SPI信号)
D6 PE9 PD3 PA0 - DIR PD10 CS4
D7 PE10 PI6 - DIR PI1 MISO_2 (第2路MISO)
D8 PE11 PD4 PI3 - DIR PG9 MISO_3 (第3路MISO)
D9 PE12 PD5 - DIR PI12 MISO_4 (第4路MISO)
RS232_TX - RS232串口机台信号扩展 START BUSY OK NG
RS232_RX - RS232串口机台信号扩展

View File

@ -183,6 +183,8 @@ int32_t LAN8742_RegisterBusIO(lan8742_Object_t *pObj, lan8742_IOCtx_t *ioctx)
}
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD>2<EFBFBD><32> */
#if 0
if(status == LAN8742_STATUS_OK)
{
tickstart = pObj->IO.GetTick();
@ -193,6 +195,9 @@ int32_t LAN8742_RegisterBusIO(lan8742_Object_t *pObj, lan8742_IOCtx_t *ioctx)
}
pObj->Is_Initialized = 1;
}
#else
pObj->Is_Initialized = 1;
#endif
return status;
}

View File

@ -1,5 +1,12 @@
copy Objects\output.hex ..\h7_tool_app.hex
copy Objects\output.hex ..\app0.hex
hex2bin ..\app0.hex
LinkBin ..\h7_tool_app.bin =VAR @0x0 ..\app0.bin @0xE0000 ..\dap.bin
del ..\app0.bin
del ..\app0.hex
hex2bin ..\h7_tool_app.hex

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -384,9 +384,9 @@
<GroupName>App</GroupName>
<Files>
<File>
<FileName>main.h</FileName>
<FileName>includes.h</FileName>
<FileType>5</FileType>
<FilePath>..\..\User\app\inc\main.h</FilePath>
<FilePath>..\..\User\app\inc\includes.h</FilePath>
</File>
<File>
<FileName>main.c</FileName>
@ -493,6 +493,16 @@
<FileType>1</FileType>
<FilePath>..\..\User\app\src\status_uart_monitor.c</FilePath>
</File>
<File>
<FileName>status_ds18b20_meter.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\app\src\status_ds18b20_meter.c</FilePath>
</File>
<File>
<FileName>disp_lib.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\app\src\disp_lib.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -734,6 +744,11 @@
<FileType>1</FileType>
<FilePath>..\..\User\bsp\src\bsp_i2c_gpio_ext.c</FilePath>
</File>
<File>
<FileName>bsp_ds18b20.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\bsp\src\bsp_ds18b20.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -1574,21 +1589,26 @@
<FileType>1</FileType>
<FilePath>..\..\User\programmer\stm8_prog_file.c</FilePath>
</File>
<File>
<FileName>n76e_prog_file.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\programmer\n76e_prog_file.c</FilePath>
</File>
<File>
<FileName>n76e003_flash.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\programmer\n76e003_flash.c</FilePath>
</File>
<File>
<FileName>w25q_flash.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\programmer\w25q_flash.c</FilePath>
</File>
<File>
<FileName>cx32_isp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\programmer\cx32_isp.c</FilePath>
</File>
<File>
<FileName>pg_prog_file.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\programmer\pg_prog_file.c</FilePath>
</File>
</Files>
</Group>
<Group>

Binary file not shown.

View File

@ -68,7 +68,7 @@ __Vectors DCD __initial_sp ; Top of Stack
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0x00000135 ; Reserved H7-TOOL APP 固件版本
DCD 0x00000140 ; Reserved H7-TOOL APP 固件版本
DCD 0 ; Reserved 固件小版本
DCD 0 ; Reserved
DCD 0 ; Reserved

BIN
Project/dap.bin Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -28,10 +28,10 @@
4. USB-RS232 转换器
5. USB-TTL 串口转换器
6. USB-CAN 转换器 (未完成)
7. DAP-Link 仿真器 / 下载器 (未完成)
8. 脱机烧录器 (已完成STM32、MM32、GD32、新唐ARM、新唐8051、AT32、APM32、RT1052)
9. I2C 控制器 (未完成)
10. SPI 控制器 (未完成)
7. DAP-Link 仿真器 / 下载器
8. 脱机烧录器 (已完成STM32、MM32、GD32、新唐ARM、新唐8051、AT32、APM32、RT1052; SPI Flash)
9. I2C 控制器
10. SPI 控制器
11. GPIO 输入输出控制器
12. 模拟信号发生器
13. PWM 发生器 (未完成)
@ -41,32 +41,28 @@
17. 高侧电流表 & 电池放电容量测量
18. 双通道电压表
18. 电阻测量 通断蜂鸣
19. 温度测量
19. NTC温度测量
20. 二极管测量
21. 微型数控电源
22. 串口数据监视器
23. lua小程序
24. 8通道DS18B20温度表
### :construction: 任务列表 / TODO
<!-- 以下为示例 -->
- [ ] DAP-Link
- [x] DAP-Link 移植
- [ ] DAP-Link 测试
- [ ] `Wi-Fi` 无线调试
- [x] DAP-Link 实现RTT打印功能
- [ ] 联机下载
- [ ] 逻辑分析仪
- [ ] 底层驱动编码 (FMC、DMA、TIM)
- [ ] 兼容第三方上位机
- [ ] 脱机烧录器
- [x] 界面操作方式规划
- [x] 实现STM32系列
- [ ] 实现STM8系列
- [x] 根据客户需求补充其他厂家ARM芯片
- [ ] 实现STM32系列
- [ ] CAN功能
- [ ] 底层驱动验证
- [ ] 功能规划
- [ ] TIM 定时器相关
- [ ] 脉冲计数器 (脱机)
- [ ] 频率计 (脱机)
- [ ] PWM 发生器 (联机)
### :warning: 注意事项 / Attention

35
User/app/inc/disp_lib.h Normal file
View File

@ -0,0 +1,35 @@
/*
*********************************************************************************************************
*
* :
* : disp_lib.h
*
*********************************************************************************************************
*/
#ifndef _DISP_LIB_H_
#define _DISP_LIB_H_
void DispHeader(char *_str);
void DispHeaderSn(uint8_t _idx);
void DispMeasBar(uint8_t _ucLine, char *_pName, char *_pValue, char *_pUnit);
void DispMeasBarEx(uint8_t _ucLine, char *_pName, char *_pValue, char *_pUnit, uint16_t _usFillColor);
void DispParamBar(uint8_t _ucLine, char *_pName, char *_pValue, uint8_t _ucActive);
void DispHelpBar(char *_str1, char *_str2);
void DispHeader2(uint8_t _idx, char *_str);
void DispHeaderStr(char *_str);
void DispInfoBar16(uint8_t _ucLine, char *_pName, char *_pValue);
void DispInfoBar16Ex(uint8_t _ucLine, char *_pName, char *_pValue, uint16_t _ucColor);
void DispBox(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth, uint16_t _usColor);
void DispLabel(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
uint16_t _usColor, char *_pStr, FONT_T *_tFont);
void DispLabelRound(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
uint16_t _usColor, char *_pStr, FONT_T *_tFont);
void DispProgressBar(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
char *_str1, float _Percent, char *_str2, FONT_T *_tFont);
void ProgressBarSetColor(uint16_t _Color);
void DispMsgBox(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth, char *_str);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

58
User/app/inc/main.h → User/app/inc/includes.h Executable file → Normal file
View File

@ -1,18 +1,46 @@
/*
*********************************************************************************************************
*
* : main模块
* : main.h
* :
* : includes.h
* : V1.0
* : 使
*
* :
*
* V1.0 2020-06-12 Eric2013
*
* Copyright (C), 2020-2030, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef _MAIN_H_
#define _MAIN_H_
#ifndef _INCLUDES_H_
#define _INCLUDES_H_
/*
*********************************************************************************************************
* APP / BSP
*********************************************************************************************************
*/
#include "bsp.h"
/*
*********************************************************************************************************
*
*********************************************************************************************************
*/
#include "ui_def.h"
#include "param.h"
#include "modbus_register.h"
#include "disp_lib.h"
#include "lcd_menu.h"
#include "file_lib.h"
#include "lua_if.h"
#include "prog_if.h"
#include "modify_param.h"
#include "wifi_if.h"
#include "usb_if.h"
/* 主程序状态字定义, MS = Main Status */
enum
@ -51,29 +79,17 @@ enum
MS_MONITOR_CAN, /* CAN监视器 */
MS_MONITOR_GPIO, /* IO监视器 */
MS_MONITOR_ANALOG, /* 模拟量监视器 */
MS_DAPLINK, /* 仿真器状态 */
MS_JUMP_APP, /* 跳到APP状态 */
MS_DS18B20_METER, /* DS18B20温度表 */
};
void DispHeader(char *_str);
void DispHeaderSn(uint8_t _idx);
void DispMeasBar(uint8_t _ucLine, char *_pName, char *_pValue, char *_pUnit);
void DispMeasBarEx(uint8_t _ucLine, char *_pName, char *_pValue, char *_pUnit, uint16_t _usFillColor);
void DispParamBar(uint8_t _ucLine, char *_pName, char *_pValue, uint8_t _ucActive);
void DispHelpBar(char *_str1, char *_str2);
void DispHeader2(uint8_t _idx, char *_str);
void DispHeaderStr(char *_str);
void DispInfoBar16(uint8_t _ucLine, char *_pName, char *_pValue);
void DispInfoBar16Ex(uint8_t _ucLine, char *_pName, char *_pValue, uint16_t _ucColor);
void DispBox(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth, uint16_t _usColor);
void DispLabel(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
uint16_t _usColor, char *_pStr, FONT_T *_tFont);
void DispProgressBar(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
char *_str1, float _Percent, char *_str2, FONT_T *_tFont);
void ProgressBarSetColor(uint16_t _Color);
uint16_t NextStatus(uint16_t _NowStatus);
uint16_t LastStatus(uint16_t _NowStatus);
void DSO_StartMode2(void);
void PlayKeyTone(void);
void DispMsgBox(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth, char *_str);
extern uint16_t g_MainStatus;

View File

@ -14,6 +14,15 @@
#ifndef _MODIFY_PARAM_H
#define _MODIFY_PARAM_H
/* 修改参数的界面ID */
enum
{
MODIFY_PARAM_UART_MON = 0, /* 串口监视 */
MODIFY_PARAM_SYSTEM, /* 系统参数 */
MODIFY_PARAM_NET, /* 网络参数 */
MODIFY_PARAM_PROG, /* 脱机烧录器参数 */
};
/* 参数列表结构 */
typedef struct
{

View File

@ -118,6 +118,11 @@ typedef struct
uint8_t UartMonTimeStamp; /* 串口监视,加上时间戳 */
uint8_t UartMonProxy; /* 串口监视,协议 */
/* DAP-Link相关参数 */
uint8_t DAP_TVCCVolt; /* DAP=Link TVCC设置 0-关闭 0-50 表示 0-5.0V */
uint8_t DAP_BeepEn; /* DAP=Link 提示音使能 0:关闭 1:烧录完毕鸣叫 */
uint8_t DAP_Sn; /* DAP-Link 序号,用于驱动识别: */
} PARAM_T;
/* 模拟量校准参数 */

500
User/app/src/disp_lib.c Normal file
View File

@ -0,0 +1,500 @@
/*
*********************************************************************************************************
*
* :
* : disp_lib.c
* : V1.0
* : H7-TOOL APP
*
* :
*
* V1.0 2020-1106-20 armfly 1.APP部分整合而来
*
* Copyright (C), 2020-2030, www.armfly.com
*
*********************************************************************************************************
*/
#include "includes.h"
extern uint16_t g_MainStatus; /* 主状态字 */
/*
*********************************************************************************************************
* : DispHeader
* : 1
* : _str :
* :
*********************************************************************************************************
*/
extern uint16_t GetStatusIndex(uint16_t _NowStatus);
void DispHeader(char *_str)
{
uint8_t idx;
idx = GetStatusIndex(g_MainStatus);
DispHeader2(idx, _str);
}
/* 带序号参数 */
void DispHeader2(uint8_t _idx, char *_str)
{
FONT_T tFont;
char buf[48];
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = HEAD_TEXT_COLOR; /* 字体颜色 */
tFont.BackColor = HEAD_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
LCD_Fill_Rect(0, 0, HEAD_HEIGHT, HEAD_HEIGHT, HEAD_SN_COLOR); /* 清屏标题序号区 */
LCD_Fill_Rect(HEAD_HEIGHT, 0, HEAD_HEIGHT, 240 - HEAD_HEIGHT, HEAD_BACK_COLOR); /* 清屏标题栏文本区 */
sprintf(buf, "%02d", _idx);
tFont.BackColor = HEAD_SN_COLOR; /* 文字背景颜色 */
LCD_DispStr(4, 4, buf, &tFont);
/* 显示标题文字 */
tFont.BackColor = HEAD_BACK_COLOR; /* 文字背景颜色 */
LCD_DispStrEx(HEAD_HEIGHT, 4, _str, &tFont, 240 - HEAD_HEIGHT, ALIGN_CENTER);
LCD_DrawLine(0, HEAD_HEIGHT, 239, HEAD_HEIGHT, HEAD_BODER_COLOR);
/* 清屏正文区 00联机界面背景颜色不同于其他界面便于识别 */
LCD_Fill_Rect(0, HEAD_HEIGHT + 1, 240 - HEAD_HEIGHT - 1, 240, FORM_BACK_COLOR);
}
/* 只刷新标题文字部分,不清屏 */
void DispHeaderStr(char *_str)
{
FONT_T tFont;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = HEAD_TEXT_COLOR; /* 字体颜色 */
tFont.BackColor = HEAD_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
LCD_Fill_Rect(HEAD_HEIGHT, 0, HEAD_HEIGHT, 240 - HEAD_HEIGHT, HEAD_BACK_COLOR); /* 清屏标题栏文本区 */
/* 显示标题文字 */
tFont.BackColor = HEAD_BACK_COLOR; /* 文字背景颜色 */
LCD_DispStrEx(HEAD_HEIGHT, 4, _str, &tFont, 240 - HEAD_HEIGHT, ALIGN_CENTER);
}
/* 显示序号 */
void DispHeaderSn(uint8_t _idx)
{
FONT_T tFont;
char buf[48];
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = HEAD_TEXT_COLOR; /* 字体颜色 */
tFont.BackColor = HEAD_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
LCD_Fill_Rect(0, 0, HEAD_HEIGHT, HEAD_HEIGHT, HEAD_SN_COLOR); /* 清屏标题序号区 */
sprintf(buf, "%02d", _idx);
tFont.BackColor = HEAD_SN_COLOR; /* 文字背景颜色 */
LCD_DispStr(4, 4, buf, &tFont);
}
/*
*********************************************************************************************************
* : DispBox
* :
* : _usX : X
* _usY : Y
* _usHeight :
* _usWidth :
* _usColor :
* :
*********************************************************************************************************
*/
void DispBox(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth, uint16_t _usColor)
{
/* 绘制边框 */
LCD_DrawRoundRect(_usX, _usY, _usHeight, _usWidth, B0X_ARC, MEAS_BODER_COLOR);
/* 填充矩形 */
LCD_FillRoundRect(_usX + 1, _usY + 1, _usHeight - 2, _usWidth - 2, B0X_ARC, _usColor);
}
/*
*********************************************************************************************************
* : DispLabel
* :
* : _usX : X
* _usY : Y
* _usHeight :
* _usWidth :
* _usColor :
* _pStr :
* _pFont :
* :
*********************************************************************************************************
*/
void DispLabel(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
uint16_t _usColor, char *_pStr, FONT_T *_tFont)
{
/* 填充矩形 */
LCD_Fill_Rect(_usX, _usY, _usHeight, _usWidth, _usColor);
LCD_DispStr(_usX, _usY, _pStr, _tFont);
}
/*
*********************************************************************************************************
* : DispLabelRound
* : DAP-LINK
* : _usX : X
* _usY : Y
* _usHeight :
* _usWidth :
* _usColor :
* _pStr :
* _pFont :
* :
*********************************************************************************************************
*/
void DispLabelRound(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
uint16_t _usColor, char *_pStr, FONT_T *_tFont)
{
uint16_t fh;
uint16_t offset;
/* 绘制圆角矩形 */
DispBox(_usX, _usY, _usHeight, _usWidth, _usColor);
fh = LCD_GetFontHeight(_tFont);
if (_usHeight > fh)
{
offset = (_usHeight - fh) / 2;
}
else
{
offset = 0;
}
LCD_DispStrEx(_usX, _usY + offset, _pStr, _tFont, _usWidth, ALIGN_CENTER);
}
/*
*********************************************************************************************************
* : DispMeasBar
* :
* : _ucLine : 0 - 3 (4)
* _pName :
* _pValue :
* _pUnit :
* :
*********************************************************************************************************
*/
void DispMeasBar(uint8_t _ucLine, char *_pName, char *_pValue, char *_pUnit)
{
DispMeasBarEx(_ucLine, _pName, _pValue, _pUnit, MEAS_BACK_COLOR);
}
/*
*********************************************************************************************************
* : DispMeasBarEx
* :
* : _ucLine : 0 - 3 (4)
* _pName :
* _pValue :
* _pUnit :
* :
*********************************************************************************************************
*/
void DispMeasBarEx(uint8_t _ucLine, char *_pName, char *_pValue, char *_pUnit, uint16_t _usFillColor)
{
FONT_T tFont;
uint16_t x;
uint16_t y;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = MEAS_NAME_COLOR; /* 字体颜色 */
tFont.BackColor = CL_MASK; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = MEAS_WIN_LEFT;
y = HEAD_HEIGHT + 9 + _ucLine * (MEAS_WIN_HEIGHT + 9);
DispBox(x, y, MEAS_WIN_HEIGHT, MEAS_WIN_WIDTH, _usFillColor);
/* 参数名字 */
tFont.FrontColor = MEAS_NAME_COLOR;
LCD_DispStr(MEAS_WIN_LEFT + 5, y + 4, _pName, &tFont);
/* 测量值 */
tFont.FrontColor = MEAS_VALUE_COLOR;
LCD_DispStr(MEAS_WIN_LEFT + 80, y + 4, _pValue, &tFont);
/* 单位 */
tFont.FrontColor = MEAS_UNIT_COLOR;
LCD_DispStr(MEAS_WIN_LEFT + 188, y + 4, _pUnit, &tFont);
}
/*
*********************************************************************************************************
* : DispParamBar
* : - 使
* : _ucLine : 0 - 3 (4)
* _pName :
* _pValue :
* _ucActive :
* :
*********************************************************************************************************
*/
void DispParamBar(uint8_t _ucLine, char *_pName, char *_pValue, uint8_t _ucActive)
{
FONT_T tFont;
uint16_t x;
uint16_t y;
uint16_t NameWidth;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = MEAS_NAME_COLOR; /* 字体颜色 */
tFont.BackColor = CL_MASK; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = MEAS_WIN_LEFT;
y = HEAD_HEIGHT + 9 + _ucLine * (MEAS_WIN_HEIGHT + 3);
/* 绘制圆角矩形 */
if (_ucActive == 1) /* 选中是用黄色底 */
{
DispBox(x, y, MEAS_WIN_HEIGHT, MEAS_WIN_WIDTH, CL_YELLOW);
}
else
{
DispBox(x, y, MEAS_WIN_HEIGHT, MEAS_WIN_WIDTH, MEAS_BACK_COLOR);
}
/* 参数名字 */
tFont.FrontColor = MEAS_NAME_COLOR;
LCD_DispStr(MEAS_WIN_LEFT + 5, y + 4, _pName, &tFont);
NameWidth = LCD_GetStrWidth(_pName, &tFont);
/* 测量值 */
tFont.FrontColor = MEAS_VALUE_COLOR;
LCD_DispStr(MEAS_WIN_LEFT + 5 + NameWidth + 5, y + 4, _pValue, &tFont);
}
/*
*********************************************************************************************************
* : DispProgressBar
* :
* : _usX :
* _usX :
* _usHeight :
* _usWidth :
* _str :
* _Percent : ,
* tFont :
* :
*********************************************************************************************************
*/
extern uint8_t s_DispRefresh;
static uint16_t s_ProgressBarColor1 = PROGRESS_BACK_COLOR1;
void ProgressBarSetColor(uint16_t _Color)
{
s_ProgressBarColor1 = _Color;
}
void DispProgressBar(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
char *_str1, float _Percent, char *_str2, FONT_T *_tFont)
{
uint16_t width;
char buf[16];
uint16_t StrWidth;
uint16_t StrHeight;
uint16_t x, y;
if (_Percent > 100)
{
_Percent = 100;
}
width = ((_usWidth - 4) * _Percent) / 100;
/* 填充矩形 */
LCD_DrawRect(_usX, _usY, _usHeight, _usWidth, PROGRESS_BODER_COLOR);
LCD_Fill_Rect(_usX + 2, _usY + 2, _usHeight - 4, width, s_ProgressBarColor1);
if (_Percent < 100)
{
LCD_Fill_Rect(_usX + width + 2, _usY + 2, _usHeight - 4, _usWidth - width - 4, PROGRESS_BACK_COLOR2);
}
StrHeight = LCD_GetFontHeight(_tFont);
y = _usY + (_usHeight - StrHeight) / 2;
if (_str1[0] == 0) /* 只显示显示百分比文字 */
{
sprintf(buf, "%0.0f%%", _Percent);
StrWidth = LCD_GetStrWidth(buf, _tFont);
x = _usX + (_usWidth - StrWidth) / 2;
LCD_DispStr(x, y, buf, _tFont);
}
else
{
/* 显示左侧文本 */
x = _usX + 4;
LCD_DispStr(x, y, _str1, _tFont);
/* 显示百分比 */
sprintf(buf, "%0.0f%%", _Percent);
StrWidth = LCD_GetStrWidth(buf, _tFont);
x = _usX + (_usWidth - StrWidth) / 2;
LCD_DispStr(x, y, buf, _tFont);
/* 显示右侧文本 */
x = x + 36;
LCD_DispStr(x, y, _str2, _tFont);
}
}
/*
*********************************************************************************************************
* : DispHelpBar
* :
* :
* :
*********************************************************************************************************
*/
const unsigned char g_ImageHelp[512] = { /* 0X10,0X10,0X00,0X10,0X00,0X10,0X01,0X1B, */
0XF7,0X9E,0XF7,0X9E,0XF7,0X9E,0XFF,0XBE,0XFF,0XBE,0XEF,0X9E,0XD7,0X5E,0XCF,0X3F,
0XCF,0X1F,0XD7,0X5F,0XE7,0X9F,0XFF,0XDF,0XFF,0XDE,0XF7,0X9E,0XF7,0X9E,0XF7,0X9E,
0XF7,0X9E,0XF7,0X9E,0XF7,0XBE,0XEF,0X7E,0XC6,0XFE,0XAE,0XBE,0XA6,0X7E,0X9E,0X7E,
0X9E,0X7E,0X9E,0X7E,0XA6,0X7E,0XBE,0XDE,0XE7,0X7E,0XFF,0XBE,0XF7,0X9E,0XF7,0X9E,
0XF7,0X9E,0XF7,0XBE,0XE7,0X5E,0XB6,0XBE,0XA6,0X7E,0X9E,0X5E,0X96,0X5E,0X8E,0X1E,
0X8E,0X1E,0X96,0X3E,0X96,0X5E,0X9E,0X5E,0XAE,0X9E,0XDF,0X5E,0XFF,0XBE,0XF7,0X9E,
0XF7,0XBE,0XEF,0X7E,0XB6,0XBD,0X9E,0X7E,0X96,0X3E,0X96,0X3E,0X8E,0X1E,0XA6,0X7E,
0XA6,0X7E,0X8E,0X1D,0X8E,0X1E,0X8E,0X3D,0X96,0X3D,0XA6,0X7D,0XE7,0X7E,0XFF,0XDE,
0XFF,0XBE,0XBE,0XDD,0X9E,0X5D,0X96,0X3D,0X8E,0X1D,0X8E,0X1D,0X85,0XFD,0XDF,0X7E,
0XE7,0X9F,0X85,0XFD,0X86,0X1D,0X86,0X1D,0X8E,0X1D,0X8E,0X1D,0XB6,0XBD,0XFF,0XDF,
0XE7,0X7E,0X96,0X3D,0X8E,0X1D,0X86,0X1D,0X85,0XFD,0X86,0X1D,0X7D,0XFD,0X96,0X3D,
0X96,0X3D,0X85,0XFD,0X85,0XFD,0X85,0XFD,0X85,0XFD,0X85,0XFD,0X8E,0X1C,0XE7,0X7E,
0XCF,0X1E,0X7D,0XFC,0X85,0XFD,0X85,0XFD,0X7D,0XFD,0X7D,0XFD,0X8E,0X3D,0X96,0X3D,
0X8E,0X1D,0X7D,0XFD,0X7D,0XFD,0X7D,0XFD,0X7D,0XDC,0X7D,0XFC,0X75,0XDC,0XC6,0XFE,
0XB6,0XBD,0X75,0XBC,0X7D,0XDC,0X7D,0XDC,0X7D,0XFD,0X7D,0XDD,0X8E,0X3D,0XE7,0X7F,
0XD7,0X5E,0X75,0XDC,0X7D,0XDC,0X7D,0XDC,0X7D,0XDC,0X7D,0XDC,0X75,0X9C,0XAE,0X9D,
0XAE,0X9D,0X75,0X9C,0X7D,0XDC,0X7D,0XDC,0X7D,0XDC,0X7D,0XDC,0X6D,0X9C,0XBE,0XDE,
0XDF,0X5E,0X75,0XBC,0X7D,0XDC,0X7D,0XDC,0X75,0XBC,0X75,0XBC,0X6D,0X7B,0XA6,0X7D,
0XC6,0XFD,0X75,0X9C,0X7D,0XBC,0X75,0XBC,0X75,0XBC,0X75,0XBC,0X6D,0X9C,0XBE,0XDD,
0XD7,0X5E,0X6D,0X9C,0X75,0XBC,0X75,0XBC,0X75,0X9C,0X75,0X9C,0X65,0X7B,0XBE,0XDD,
0XE7,0X7E,0X85,0XDC,0X7D,0XBC,0X75,0X9C,0X75,0X9B,0X75,0X9C,0X65,0X7B,0XB6,0XBD,
0XD7,0X3E,0X65,0X7B,0X6D,0X9C,0X6D,0X7B,0X6D,0X7B,0X75,0X9B,0X75,0X9B,0XDF,0X5E,
0XFF,0XDE,0XAE,0X7C,0X85,0XDB,0X75,0X9B,0X6D,0X7B,0X6D,0X7B,0X5D,0X3B,0XB6,0XBD,
0XD7,0X5E,0X5D,0X3B,0X6D,0X7B,0X6D,0X7B,0X6D,0X7B,0X75,0X7B,0X9E,0X3C,0XFF,0XDF,
0XFF,0XBE,0XE7,0X5E,0X96,0X1C,0X7D,0XBB,0X75,0X7B,0X65,0X5B,0X75,0X9B,0XCF,0X1D,
0XDF,0X7E,0X85,0XDB,0X5D,0X3A,0X6D,0X5B,0X75,0X7B,0X85,0XDB,0XDF,0X5D,0XFF,0XDE,
0XF7,0X9E,0XFF,0XBE,0XD7,0X3D,0X95,0XFB,0X75,0X9B,0X6D,0X7B,0X6D,0X5B,0X6D,0X5A,
0X65,0X5A,0X6D,0X5A,0X65,0X5A,0X6D,0X5A,0X7D,0XBB,0XCE,0XFD,0XFF,0XDE,0XF7,0X9E,
0XF7,0X9E,0XF7,0X9E,0XFF,0XBE,0XDF,0X3D,0X9E,0X1B,0X6D,0X7A,0X5D,0X1A,0X4C,0XFA,
0X4C,0XDA,0X4C,0XFA,0X5D,0X3A,0X8D,0XFB,0XDF,0X3D,0XFF,0XBE,0XF7,0X9E,0XF7,0X9E,
0XF7,0X9E,0XF7,0X9E,0XF7,0X9E,0XF7,0X9E,0XEF,0X5D,0XCE,0XBB,0XA6,0X1A,0X85,0XBA,
0X85,0XBA,0X9E,0X1A,0XC6,0XBC,0XEF,0X7D,0XF7,0XBE,0XF7,0X9E,0XF7,0X9E,0XF7,0X9E,
};
void DispHelpBar(char *_str1, char *_str2)
{
FONT_T tFont; /* 定义字体结构体变量 */
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = HELP_TEXT_COLOR; /* 字体颜色 */
tFont.BackColor = HELP_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
ST7789_DrawBMP8(1, 240 - 36, 16, 16, (uint8_t *)g_ImageHelp);
LCD_DispStr(20, 240 - 36, _str1, &tFont);
LCD_DispStr(20, 240 - 18, _str2, &tFont);
}
/*
*********************************************************************************************************
* : DispInfoBar16
* : 16.
* : _line :
* _str1 :
* _str2 :
* :
*********************************************************************************************************
*/
void DispInfoBar16(uint8_t _ucLine, char *_pName, char *_pValue)
{
DispInfoBar16Ex(_ucLine, _pName, _pValue, INFO_VALUE_COLOR);
}
/* 带颜色参数 - 用于显示红色超标参数 */
void DispInfoBar16Ex(uint8_t _ucLine, char *_pName, char *_pValue, uint16_t _ucColor)
{
FONT_T tFont;
uint16_t x;
uint16_t y;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = INFO_NAME_COLOR; /* 字体颜色 */
tFont.BackColor = INFO_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = 5;
y = HEAD_HEIGHT + 5 + _ucLine * INFO_HEIGHT;
/* 参数名字 */
tFont.FrontColor = INFO_NAME_COLOR;
LCD_DispStr(x, y, _pName, &tFont);
x += LCD_GetStrWidth(_pName, &tFont) + 5;
/* 参数值 */
tFont.FrontColor = _ucColor;
LCD_DispStr(x, y, _pValue, &tFont);
}
/*
*********************************************************************************************************
* : DispMsgBox
* : . 16
* :
* :
*********************************************************************************************************
*/
void DispMsgBox(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth, char *_str)
{
FONT_T tFont;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = MEAS_NAME_COLOR; /* 字体颜色 */
tFont.BackColor = CL_MASK; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
DispBox(_usX, _usY, _usHeight, _usWidth, MEAS_BACK_COLOR);
/* 参数名字 */
tFont.FrontColor = MEAS_NAME_COLOR;
LCD_DispStr(_usX + 5, _usY + 4, _str, &tFont);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -14,11 +14,8 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "file_lib.h"
#include "lcd_menu.h"
#include "main.h"
#include "prog_if.h"
#include "includes.h"
#include "md5.h"
/*

View File

@ -14,10 +14,7 @@
*********************************************************************************************************
*/
#include "bsp.h"
#include "fonts.h"
#include "ui_def.h"
#include "lcd_menu.h"
#include "includes.h"
/*
*********************************************************************************************************

View File

@ -16,8 +16,7 @@
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "includes.h"
#include "status_link_mode.h"
#include "status_voltage_meter.h"
@ -51,7 +50,11 @@
#include "file_lib.h"
#include "elf_file.h"
static void DispLogo(void);
#include "w25q_flash.h"
extern void status_DS18B20Meter(void);
uint16_t GetStatusIndex(uint16_t _NowStatus);
uint16_t g_MainStatus; /* 主状态字 */
@ -66,38 +69,9 @@ static const uint16_t StatusOrder[] =
MS_TEMP_METER, /* 温度表 */
MS_TVCC_POWER, /* 微型数控电源 */
MS_PULSE_METER, /* 脉冲计 */
MS_MINI_DSO, /* 迷你示波器 */
//MS_MINI_DSO, /* 迷你示波器 */
};
uint32_t stm32crc(uint32_t *ptr, int len)
{
uint32_t xbit, data;
uint32_t crc = 0xFFFFFFFF; // init value
uint32_t polynom = 0x04c11db7;
while (len--) {
xbit = 1u << 31;
data = *ptr++;
for (int bits = 0; bits < 32; bits++)
{
if (crc & 0x80000000) {
crc <<= 1;
crc ^= polynom;
}
else
crc <<= 1;
if (data & xbit)
crc ^= polynom;
xbit >>= 1;
}
}
return crc;
}
/*
*********************************************************************************************************
* : main
@ -106,52 +80,15 @@ uint32_t stm32crc(uint32_t *ptr, int len)
* : ()
*********************************************************************************************************
*/
void JumpToDAPLink(void);
extern MENU_T g_tMenu1;
int main(void)
{
bsp_Init();
LoadParam(); /* 读取应用程序参数, 该函数在param.c */
PERIOD_Start(&g_tRunLed, 50, 50, 0); /* LED一直闪烁, 非阻塞 */
DispLogo();
bsp_InitESP32();
bsp_SetTVCC(3300);
DSO_InitHard();
DSO_SetDC(1, 1);
DSO_SetDC(2, 1);
DSO_SetGain(1, 3);
DSO_SetGain(2, 3);
/* 测试一拖四模式 */
{
g_gMulSwd.MultiMode = 0;
g_gMulSwd.Active[0] = 1;
g_gMulSwd.Active[1] = 1;
g_gMulSwd.Active[2] = 1;
g_gMulSwd.Active[3] = 1;
}
/* LwIP 初始化 */
{
/* 如果不插网线,此函数执行时间过长 */
/* 网络参数存在在全局变量 g_tParam.lwip_ip, g_tParam.lwip_net_mask, g_tParam.lwip_gateway */
lwip_start();
lwip_pro();
}
PERIOD_Start(&g_tRunLed, 1000, 1000, 0); /* LED一直闪烁, 每2秒闪1次 */
usbd_Init(); /* 初始化USB协议栈 */
FileSystemLoad(); /* 挂载文件系统 */
lua_Init(); /* 启动lua */
//wifi_state = WIFI_INIT;
ST7789_SetDirection(g_tParam.DispDir);
/* 主程序采用状态机实现程序功能切换 */
g_MainStatus = MS_LINK_MODE; /* 初始状态 = 联机界面 */
@ -165,6 +102,83 @@ int main(void)
g_gMulSwd.MultiMode = g_tParam.MultiProgMode;
g_MainStatus = MS_PROG_WORK; /* 多路烧录 */
}
else if (g_tParam.StartRun == 3)
{
uint32_t RegJump;
/*
32bit
RTC_BKP_DR0 RTC初始化标志
RTC_BKP_DR1
- boot = 1, app = 2, dap = 3
- 0x0102 : boot来app
- 0x0301 : dap来app
- 0x0103 : boot来dap
*/
RegJump = RTC_ReadBkup32(RTC_BKP_DR1);
if (RegJump == 0x0000)
{
JumpToDAPLink(); /* 进入DAP */
}
/* 从DAP返回直接到菜单选择状态 */
if (RegJump == 0x0301)
{
g_tMenu1.Cursor = 0;
g_MainStatus = MS_EXTEND_MENU1;
}
/* 进入00 待机界面 */
RTC_WriteBkup32(RTC_BKP_DR1, 0x0000);
}
else /* 0 - 缺省*/
{
uint32_t RegJump;
RegJump = RTC_ReadBkup32(RTC_BKP_DR1);
/* 从DAP返回直接到菜单选择状态 */
if (RegJump == 0x0301)
{
g_tMenu1.Cursor = 0;
g_MainStatus = MS_EXTEND_MENU1;
}
RTC_WriteBkup32(RTC_BKP_DR1, 0x0000);
}
/* 执行较快的初始化代码部分 */
{
//PERIOD_Start(&g_tRunLed, 50, 50, 0); /* LED一直闪烁, 非阻塞 */
PERIOD_Start(&g_tRunLed, 1000, 1000, 0); /* LED一直闪烁, 每2秒闪1次 */
bsp_InitESP32();
bsp_SetTVCC(3300);
DSO_InitHard();
DSO_SetDC(1, 1);
DSO_SetDC(2, 1);
DSO_SetGain(1, 3);
DSO_SetGain(2, 3);
/* 脱机烧录用的全局变量 */
{
g_gMulSwd.MultiMode = 0;
g_gMulSwd.Active[0] = 1;
g_gMulSwd.Active[1] = 1;
g_gMulSwd.Active[2] = 1;
g_gMulSwd.Active[3] = 1;
}
usbd_Init(); /* 初始化USB协议栈 */
FileSystemLoad(); /* 挂载文件系统 */
lua_Init(); /* 启动lua */
}
//wifi_state = WIFI_INIT;
while (1)
{
switch (g_MainStatus)
@ -182,7 +196,7 @@ int main(void)
break;
case MS_MODIFY_PARAM: /* 修改参数 */
status_ModifyParam();
//status_ModifyParam();
break;
case MS_ESP32_TEST: /* ESP32模块固件升级 */
@ -265,12 +279,12 @@ int main(void)
status_MonitorCan();
break;
case MS_MONITOR_GPIO: /* IO监视器 */
case MS_MONITOR_GPIO: /* 串口视器 */
status_MonitorUart();
break;
case MS_MONITOR_ANALOG: /* 模拟量监视器 */
status_MonitorUart();
case MS_DS18B20_METER: /* DS18B20温度表 */
status_DS18B20Meter();
break;
default:
@ -280,7 +294,6 @@ int main(void)
}
}
/*
*********************************************************************************************************
* : NextStatus
@ -380,472 +393,6 @@ uint16_t GetStatusIndex(uint16_t _NowStatus)
return idx;
}
/*
*********************************************************************************************************
* : DispLogo
* :
* :
* :
*********************************************************************************************************
*/
static void DispLogo(void)
{
FONT_T tFont; /* 定义字体结构体变量 */
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = RGB(200, 200, 200); /* 字体颜色 */
tFont.BackColor = FORM_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
ST7789_SetDirection(g_tParam.DispDir);
LCD_ClrScr(FORM_BACK_COLOR); /* 清屏,背景蓝色 */
/* 显示APP固件版本。版本号放在中断向量表 */
{
char buf[64];
uint16_t x = 5;
uint16_t y = 3;
uint16_t line_cap = 20;
//LCD_DispStr(x, y, "H7-TOOL多功能开发工具", &tFont);
LCD_DispStr(x, y, "H7-TOOL", &tFont);
y += line_cap;
sprintf(buf, "App Ver:%d.%02X",
APP_VERSION >> 8, APP_VERSION & 0xFF);
LCD_DispStr(x, y, buf, &tFont);
y += line_cap;
sprintf(buf, "Boot Ver:%d.%02X",
BOOT_VERSION >> 8, BOOT_VERSION & 0xFF);
LCD_DispStr(x, y, buf, &tFont);
y += line_cap;
LCD_DispStr(x, y, "正在配置网络...", &tFont);
}
ST7789_DrawScreen(); /* 立即刷屏一次 */
bsp_DelayMS(50); /* 刷屏后延迟50ms再开背光, 避免花屏闪一下问题 */
LCD_SetBackLight(BRIGHT_DEFAULT); /* 打开背光 */
}
/*
*********************************************************************************************************
* : DispHeader
* : 1
* : _str :
* :
*********************************************************************************************************
*/
void DispHeader(char *_str)
{
uint8_t idx;
idx = GetStatusIndex(g_MainStatus);
DispHeader2(idx, _str);
}
/* 带序号参数 */
void DispHeader2(uint8_t _idx, char *_str)
{
FONT_T tFont;
char buf[48];
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = HEAD_TEXT_COLOR; /* 字体颜色 */
tFont.BackColor = HEAD_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
LCD_Fill_Rect(0, 0, HEAD_HEIGHT, HEAD_HEIGHT, HEAD_SN_COLOR); /* 清屏标题序号区 */
LCD_Fill_Rect(HEAD_HEIGHT, 0, HEAD_HEIGHT, 240 - HEAD_HEIGHT, HEAD_BACK_COLOR); /* 清屏标题栏文本区 */
sprintf(buf, "%02d", _idx);
tFont.BackColor = HEAD_SN_COLOR; /* 文字背景颜色 */
LCD_DispStr(4, 4, buf, &tFont);
/* 显示标题文字 */
tFont.BackColor = HEAD_BACK_COLOR; /* 文字背景颜色 */
LCD_DispStrEx(HEAD_HEIGHT, 4, _str, &tFont, 240 - HEAD_HEIGHT, ALIGN_CENTER);
LCD_DrawLine(0, HEAD_HEIGHT, 239, HEAD_HEIGHT, HEAD_BODER_COLOR);
LCD_Fill_Rect(0, HEAD_HEIGHT + 1, 240 - HEAD_HEIGHT - 1, 240, FORM_BACK_COLOR); /* 清屏正文区 */
}
/* 只刷新标题文字部分,不清屏 */
void DispHeaderStr(char *_str)
{
FONT_T tFont;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = HEAD_TEXT_COLOR; /* 字体颜色 */
tFont.BackColor = HEAD_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
LCD_Fill_Rect(HEAD_HEIGHT, 0, HEAD_HEIGHT, 240 - HEAD_HEIGHT, HEAD_BACK_COLOR); /* 清屏标题栏文本区 */
/* 显示标题文字 */
tFont.BackColor = HEAD_BACK_COLOR; /* 文字背景颜色 */
LCD_DispStrEx(HEAD_HEIGHT, 4, _str, &tFont, 240 - HEAD_HEIGHT, ALIGN_CENTER);
}
/* 显示序号 */
void DispHeaderSn(uint8_t _idx)
{
FONT_T tFont;
char buf[48];
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = HEAD_TEXT_COLOR; /* 字体颜色 */
tFont.BackColor = HEAD_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
LCD_Fill_Rect(0, 0, HEAD_HEIGHT, HEAD_HEIGHT, HEAD_SN_COLOR); /* 清屏标题序号区 */
sprintf(buf, "%02d", _idx);
tFont.BackColor = HEAD_SN_COLOR; /* 文字背景颜色 */
LCD_DispStr(4, 4, buf, &tFont);
}
/*
*********************************************************************************************************
* : DispBox
* :
* : _usX : X
* _usY : Y
* _usHeight :
* _usWidth :
* _usColor :
* :
*********************************************************************************************************
*/
void DispBox(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth, uint16_t _usColor)
{
/* 绘制边框 */
LCD_DrawRoundRect(_usX, _usY, _usHeight, _usWidth, B0X_ARC, MEAS_BODER_COLOR);
/* 填充矩形 */
LCD_FillRoundRect(_usX + 1, _usY + 1, _usHeight - 2, _usWidth - 2, B0X_ARC, _usColor);
}
/*
*********************************************************************************************************
* : DispLabel
* :
* : _usX : X
* _usY : Y
* _usHeight :
* _usWidth :
* _usColor :
* _pStr :
* _pFont :
* :
*********************************************************************************************************
*/
void DispLabel(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
uint16_t _usColor, char *_pStr, FONT_T *_tFont)
{
/* 填充矩形 */
LCD_Fill_Rect(_usX, _usY, _usHeight, _usWidth, _usColor);
LCD_DispStr(_usX, _usY, _pStr, _tFont);
}
/*
*********************************************************************************************************
* : DispMeasBar
* :
* : _ucLine : 0 - 3 (4)
* _pName :
* _pValue :
* _pUnit :
* :
*********************************************************************************************************
*/
void DispMeasBar(uint8_t _ucLine, char *_pName, char *_pValue, char *_pUnit)
{
DispMeasBarEx(_ucLine, _pName, _pValue, _pUnit, MEAS_BACK_COLOR);
}
/*
*********************************************************************************************************
* : DispMeasBarEx
* :
* : _ucLine : 0 - 3 (4)
* _pName :
* _pValue :
* _pUnit :
* :
*********************************************************************************************************
*/
void DispMeasBarEx(uint8_t _ucLine, char *_pName, char *_pValue, char *_pUnit, uint16_t _usFillColor)
{
FONT_T tFont;
uint16_t x;
uint16_t y;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = MEAS_NAME_COLOR; /* 字体颜色 */
tFont.BackColor = CL_MASK; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = MEAS_WIN_LEFT;
y = HEAD_HEIGHT + 9 + _ucLine * (MEAS_WIN_HEIGHT + 9);
DispBox(x, y, MEAS_WIN_HEIGHT, MEAS_WIN_WIDTH, _usFillColor);
/* 参数名字 */
tFont.FrontColor = MEAS_NAME_COLOR;
LCD_DispStr(MEAS_WIN_LEFT + 5, y + 4, _pName, &tFont);
/* 测量值 */
tFont.FrontColor = MEAS_VALUE_COLOR;
LCD_DispStr(MEAS_WIN_LEFT + 80, y + 4, _pValue, &tFont);
/* 单位 */
tFont.FrontColor = MEAS_UNIT_COLOR;
LCD_DispStr(MEAS_WIN_LEFT + 188, y + 4, _pUnit, &tFont);
}
/*
*********************************************************************************************************
* : DispParamBar
* : - 使
* : _ucLine : 0 - 3 (4)
* _pName :
* _pValue :
* _ucActive :
* :
*********************************************************************************************************
*/
void DispParamBar(uint8_t _ucLine, char *_pName, char *_pValue, uint8_t _ucActive)
{
FONT_T tFont;
uint16_t x;
uint16_t y;
uint16_t NameWidth;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = MEAS_NAME_COLOR; /* 字体颜色 */
tFont.BackColor = CL_MASK; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = MEAS_WIN_LEFT;
y = HEAD_HEIGHT + 9 + _ucLine * (MEAS_WIN_HEIGHT + 3);
/* 绘制圆角矩形 */
if (_ucActive == 1) /* 选中是用黄色底 */
{
DispBox(x, y, MEAS_WIN_HEIGHT, MEAS_WIN_WIDTH, CL_YELLOW);
}
else
{
DispBox(x, y, MEAS_WIN_HEIGHT, MEAS_WIN_WIDTH, MEAS_BACK_COLOR);
}
/* 参数名字 */
tFont.FrontColor = MEAS_NAME_COLOR;
LCD_DispStr(MEAS_WIN_LEFT + 5, y + 4, _pName, &tFont);
NameWidth = LCD_GetStrWidth(_pName, &tFont);
/* 测量值 */
tFont.FrontColor = MEAS_VALUE_COLOR;
LCD_DispStr(MEAS_WIN_LEFT + 5 + NameWidth + 5, y + 4, _pValue, &tFont);
}
/*
*********************************************************************************************************
* : DispProgressBar
* :
* : _usX :
* _usX :
* _usHeight :
* _usWidth :
* _str :
* _Percent : ,
* tFont :
* :
*********************************************************************************************************
*/
extern uint8_t s_DispRefresh;
static uint16_t s_ProgressBarColor1 = PROGRESS_BACK_COLOR1;
void ProgressBarSetColor(uint16_t _Color)
{
s_ProgressBarColor1 = _Color;
}
void DispProgressBar(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
char *_str1, float _Percent, char *_str2, FONT_T *_tFont)
{
uint16_t width;
char buf[16];
uint16_t StrWidth;
uint16_t StrHeight;
uint16_t x, y;
if (_Percent > 100)
{
_Percent = 100;
}
width = ((_usWidth - 4) * _Percent) / 100;
/* 填充矩形 */
LCD_DrawRect(_usX, _usY, _usHeight, _usWidth, PROGRESS_BODER_COLOR);
LCD_Fill_Rect(_usX + 2, _usY + 2, _usHeight - 4, width, s_ProgressBarColor1);
if (_Percent < 100)
{
LCD_Fill_Rect(_usX + width + 2, _usY + 2, _usHeight - 4, _usWidth - width - 4, PROGRESS_BACK_COLOR2);
}
StrHeight = LCD_GetFontHeight(_tFont);
y = _usY + (_usHeight - StrHeight) / 2;
if (_str1[0] == 0) /* 只显示显示百分比文字 */
{
sprintf(buf, "%0.0f%%", _Percent);
StrWidth = LCD_GetStrWidth(buf, _tFont);
x = _usX + (_usWidth - StrWidth) / 2;
LCD_DispStr(x, y, buf, _tFont);
}
else
{
/* 显示左侧文本 */
x = _usX + 4;
LCD_DispStr(x, y, _str1, _tFont);
/* 显示百分比 */
sprintf(buf, "%0.0f%%", _Percent);
StrWidth = LCD_GetStrWidth(buf, _tFont);
x = _usX + (_usWidth - StrWidth) / 2;
LCD_DispStr(x, y, buf, _tFont);
/* 显示右侧文本 */
x = x + 36;
LCD_DispStr(x, y, _str2, _tFont);
}
}
/*
*********************************************************************************************************
* : DispHelpBar
* :
* :
* :
*********************************************************************************************************
*/
const unsigned char g_ImageHelp[512] = { /* 0X10,0X10,0X00,0X10,0X00,0X10,0X01,0X1B, */
0XF7,0X9E,0XF7,0X9E,0XF7,0X9E,0XFF,0XBE,0XFF,0XBE,0XEF,0X9E,0XD7,0X5E,0XCF,0X3F,
0XCF,0X1F,0XD7,0X5F,0XE7,0X9F,0XFF,0XDF,0XFF,0XDE,0XF7,0X9E,0XF7,0X9E,0XF7,0X9E,
0XF7,0X9E,0XF7,0X9E,0XF7,0XBE,0XEF,0X7E,0XC6,0XFE,0XAE,0XBE,0XA6,0X7E,0X9E,0X7E,
0X9E,0X7E,0X9E,0X7E,0XA6,0X7E,0XBE,0XDE,0XE7,0X7E,0XFF,0XBE,0XF7,0X9E,0XF7,0X9E,
0XF7,0X9E,0XF7,0XBE,0XE7,0X5E,0XB6,0XBE,0XA6,0X7E,0X9E,0X5E,0X96,0X5E,0X8E,0X1E,
0X8E,0X1E,0X96,0X3E,0X96,0X5E,0X9E,0X5E,0XAE,0X9E,0XDF,0X5E,0XFF,0XBE,0XF7,0X9E,
0XF7,0XBE,0XEF,0X7E,0XB6,0XBD,0X9E,0X7E,0X96,0X3E,0X96,0X3E,0X8E,0X1E,0XA6,0X7E,
0XA6,0X7E,0X8E,0X1D,0X8E,0X1E,0X8E,0X3D,0X96,0X3D,0XA6,0X7D,0XE7,0X7E,0XFF,0XDE,
0XFF,0XBE,0XBE,0XDD,0X9E,0X5D,0X96,0X3D,0X8E,0X1D,0X8E,0X1D,0X85,0XFD,0XDF,0X7E,
0XE7,0X9F,0X85,0XFD,0X86,0X1D,0X86,0X1D,0X8E,0X1D,0X8E,0X1D,0XB6,0XBD,0XFF,0XDF,
0XE7,0X7E,0X96,0X3D,0X8E,0X1D,0X86,0X1D,0X85,0XFD,0X86,0X1D,0X7D,0XFD,0X96,0X3D,
0X96,0X3D,0X85,0XFD,0X85,0XFD,0X85,0XFD,0X85,0XFD,0X85,0XFD,0X8E,0X1C,0XE7,0X7E,
0XCF,0X1E,0X7D,0XFC,0X85,0XFD,0X85,0XFD,0X7D,0XFD,0X7D,0XFD,0X8E,0X3D,0X96,0X3D,
0X8E,0X1D,0X7D,0XFD,0X7D,0XFD,0X7D,0XFD,0X7D,0XDC,0X7D,0XFC,0X75,0XDC,0XC6,0XFE,
0XB6,0XBD,0X75,0XBC,0X7D,0XDC,0X7D,0XDC,0X7D,0XFD,0X7D,0XDD,0X8E,0X3D,0XE7,0X7F,
0XD7,0X5E,0X75,0XDC,0X7D,0XDC,0X7D,0XDC,0X7D,0XDC,0X7D,0XDC,0X75,0X9C,0XAE,0X9D,
0XAE,0X9D,0X75,0X9C,0X7D,0XDC,0X7D,0XDC,0X7D,0XDC,0X7D,0XDC,0X6D,0X9C,0XBE,0XDE,
0XDF,0X5E,0X75,0XBC,0X7D,0XDC,0X7D,0XDC,0X75,0XBC,0X75,0XBC,0X6D,0X7B,0XA6,0X7D,
0XC6,0XFD,0X75,0X9C,0X7D,0XBC,0X75,0XBC,0X75,0XBC,0X75,0XBC,0X6D,0X9C,0XBE,0XDD,
0XD7,0X5E,0X6D,0X9C,0X75,0XBC,0X75,0XBC,0X75,0X9C,0X75,0X9C,0X65,0X7B,0XBE,0XDD,
0XE7,0X7E,0X85,0XDC,0X7D,0XBC,0X75,0X9C,0X75,0X9B,0X75,0X9C,0X65,0X7B,0XB6,0XBD,
0XD7,0X3E,0X65,0X7B,0X6D,0X9C,0X6D,0X7B,0X6D,0X7B,0X75,0X9B,0X75,0X9B,0XDF,0X5E,
0XFF,0XDE,0XAE,0X7C,0X85,0XDB,0X75,0X9B,0X6D,0X7B,0X6D,0X7B,0X5D,0X3B,0XB6,0XBD,
0XD7,0X5E,0X5D,0X3B,0X6D,0X7B,0X6D,0X7B,0X6D,0X7B,0X75,0X7B,0X9E,0X3C,0XFF,0XDF,
0XFF,0XBE,0XE7,0X5E,0X96,0X1C,0X7D,0XBB,0X75,0X7B,0X65,0X5B,0X75,0X9B,0XCF,0X1D,
0XDF,0X7E,0X85,0XDB,0X5D,0X3A,0X6D,0X5B,0X75,0X7B,0X85,0XDB,0XDF,0X5D,0XFF,0XDE,
0XF7,0X9E,0XFF,0XBE,0XD7,0X3D,0X95,0XFB,0X75,0X9B,0X6D,0X7B,0X6D,0X5B,0X6D,0X5A,
0X65,0X5A,0X6D,0X5A,0X65,0X5A,0X6D,0X5A,0X7D,0XBB,0XCE,0XFD,0XFF,0XDE,0XF7,0X9E,
0XF7,0X9E,0XF7,0X9E,0XFF,0XBE,0XDF,0X3D,0X9E,0X1B,0X6D,0X7A,0X5D,0X1A,0X4C,0XFA,
0X4C,0XDA,0X4C,0XFA,0X5D,0X3A,0X8D,0XFB,0XDF,0X3D,0XFF,0XBE,0XF7,0X9E,0XF7,0X9E,
0XF7,0X9E,0XF7,0X9E,0XF7,0X9E,0XF7,0X9E,0XEF,0X5D,0XCE,0XBB,0XA6,0X1A,0X85,0XBA,
0X85,0XBA,0X9E,0X1A,0XC6,0XBC,0XEF,0X7D,0XF7,0XBE,0XF7,0X9E,0XF7,0X9E,0XF7,0X9E,
};
void DispHelpBar(char *_str1, char *_str2)
{
FONT_T tFont; /* 定义字体结构体变量 */
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = HELP_TEXT_COLOR; /* 字体颜色 */
tFont.BackColor = HELP_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
ST7789_DrawBMP8(1, 240 - 36, 16, 16, (uint8_t *)g_ImageHelp);
LCD_DispStr(20, 240 - 36, _str1, &tFont);
LCD_DispStr(20, 240 - 18, _str2, &tFont);
}
/*
*********************************************************************************************************
* : DispInfoBar16
* : 16.
* : _line :
* _str1 :
* _str2 :
* :
*********************************************************************************************************
*/
void DispInfoBar16(uint8_t _ucLine, char *_pName, char *_pValue)
{
DispInfoBar16Ex(_ucLine, _pName, _pValue, INFO_VALUE_COLOR);
}
/* 带颜色参数 - 用于显示红色超标参数 */
void DispInfoBar16Ex(uint8_t _ucLine, char *_pName, char *_pValue, uint16_t _ucColor)
{
FONT_T tFont;
uint16_t x;
uint16_t y;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = INFO_NAME_COLOR; /* 字体颜色 */
tFont.BackColor = INFO_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = 5;
y = HEAD_HEIGHT + 5 + _ucLine * INFO_HEIGHT;
/* 参数名字 */
tFont.FrontColor = INFO_NAME_COLOR;
LCD_DispStr(x, y, _pName, &tFont);
x += LCD_GetStrWidth(_pName, &tFont) + 5;
/* 参数值 */
tFont.FrontColor = _ucColor;
LCD_DispStr(x, y, _pValue, &tFont);
}
/*
*********************************************************************************************************
* : DSO_StartMode2
@ -890,31 +437,4 @@ void PlayKeyTone(void)
}
}
/*
*********************************************************************************************************
* : DispMsgBox
* : . 16
* :
* :
*********************************************************************************************************
*/
void DispMsgBox(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth, char *_str)
{
FONT_T tFont;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = MEAS_NAME_COLOR; /* 字体颜色 */
tFont.BackColor = CL_MASK; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
DispBox(_usX, _usY, _usHeight, _usWidth, MEAS_BACK_COLOR);
/* 参数名字 */
tFont.FrontColor = MEAS_NAME_COLOR;
LCD_DispStr(_usX + 5, _usY + 4, _str, &tFont);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -14,12 +14,7 @@
*********************************************************************************************************
*/
#include "bsp.h"
#include "fonts.h"
#include "ui_def.h"
#include "main.h"
#include "lcd_menu.h"
#include "modify_param.h"
#include "includes.h"
/* 多行文本框 */
#define MEMO_X 5
@ -63,16 +58,27 @@ const PARAM_LIST_T UartMonParamList[UART_MON_PARAM_COUNT] =
};
/****** 系统设置-基本参数 ******************************************************************************/
#define SYS_BASE_PARAM_COUNT 16
#define SYS_BASE_PARAM_COUNT 4
const char *SysBaseParam0[] = {"关闭", "打开"};
const char *SysBaseParam1[] = {"1分钟", "5分钟", "15分钟", "1小时", "关闭"};
const char *SysBaseParam2[] = {"16点阵", "24点阵"};
const char *SysBaseParam3[] = {"缺省", "单路烧录", "多路烧录", "DAP-Link"};
const PARAM_LIST_T SysBaseParamList[SYS_BASE_PARAM_COUNT] =
{
/* 数据类型, 名称 可选列表, 最小值, 最大值, 缺省值 */
{ 0, "按键音: ", SysBaseParam0, 0, 1, 1},
{ 0, "屏保超时: ", SysBaseParam1, 0, 4, 0},
{ 0, "列表字体: ", SysBaseParam2, 0, 1, 0},
{ 0, "开机启动: ", SysBaseParam3, 0, 3, 0},
};
/****** 系统设置-IP参数 ******************************************************************************/
#define NET_PARAM_COUNT 13
const PARAM_LIST_T NetParamList[NET_PARAM_COUNT] =
{
/* 数据类型, 名称 可选列表, 最小值, 最大值, 缺省值 */
{ 0, "RJ45本机IP0: ", 0, 0, 255, 192},
{ 0, "RJ45本机IP1: ", 0, 0, 255, 168},
{ 0, "RJ45本机IP2: ", 0, 0, 255, 1},
@ -88,17 +94,18 @@ const PARAM_LIST_T SysBaseParamList[SYS_BASE_PARAM_COUNT] =
{ 0, "端口号: ", 0, 1024, 65535, 30010},
};
/****** 烧录参数 ******************************************************************************/
#define PROG_PARAM_COUNT 4
const char *ProgParam0[] = {"关闭", "1路", "1-2路", "1-3路", "1-4路"};
const char *ProgParam1[] = {"缺省", "单路烧录", "多路烧录"};
//const char *ProgParam1[] = {"缺省", "单路烧录", "多路烧录", "DAP-Link"};
const PARAM_LIST_T ProgParamList[PROG_PARAM_COUNT] =
{
/* 数据类型, 名称 可选列表, 最小值, 最大值, 缺省值 */
{ 0, "多路模式: ", ProgParam0, 0, 4, 4},
{ 0, "工厂代码: ", 0, 0, 999, 0},
{ 0, "烧录器编号: ", 0, 0, 999, 0},
{ 0, "开机启动: ", ProgParam1, 0, 2, 0},
{ 0, "开机启动: ", SysBaseParam3, 0, 3, 0},
};
/*
@ -307,21 +314,26 @@ void ModifyParam(uint16_t _MainStatus)
*/
void UartMonInitParam(uint16_t _MainStatus)
{
if (_MainStatus == MS_MONITOR_UART)
if (_MainStatus == MODIFY_PARAM_UART_MON)
{
s_pParamList = UartMonParamList;
s_ParamCount = UART_MON_PARAM_COUNT;
}
else if (_MainStatus == MS_SYSTEM_SET)
else if (_MainStatus == MODIFY_PARAM_SYSTEM)
{
s_pParamList = SysBaseParamList;
s_ParamCount = SYS_BASE_PARAM_COUNT;
}
else if (_MainStatus == MS_PROG_MODIFY_PARAM)
else if (_MainStatus == MODIFY_PARAM_PROG)
{
s_pParamList = ProgParamList;
s_ParamCount = PROG_PARAM_COUNT;
}
else if (_MainStatus == MODIFY_PARAM_NET)
{
s_pParamList = NetParamList;
s_ParamCount = NET_PARAM_COUNT;
}
}
/*
@ -351,19 +363,23 @@ static int32_t MonDispReadParam(uint8_t _index)
if (_index == 0) value = g_tParam.KeyToneEnable;
else if (_index == 1) value = g_tParam.LcdSleepTime;
else if (_index == 2) value = g_tParam.FileListFont24;
else if (_index == 3) value = g_tParam.LocalIPAddr[0];
else if (_index == 4) value = g_tParam.LocalIPAddr[1];
else if (_index == 5) value = g_tParam.LocalIPAddr[2];
else if (_index == 6) value = g_tParam.LocalIPAddr[3];
else if (_index == 7) value = g_tParam.Gateway[0];
else if (_index == 8) value = g_tParam.Gateway[1];
else if (_index == 9) value = g_tParam.Gateway[2];
else if (_index == 10) value = g_tParam.Gateway[3];
else if (_index == 11) value = g_tParam.NetMask[0];
else if (_index == 12) value = g_tParam.NetMask[1];
else if (_index == 13) value = g_tParam.NetMask[2];
else if (_index == 14) value = g_tParam.NetMask[3];
else if (_index == 15) value = g_tParam.LocalTCPPort;
else if (_index == 3) value = g_tParam.StartRun;
}
else if (s_pParamList == NetParamList)
{
if (_index == 0) value = g_tParam.LocalIPAddr[0];
else if (_index == 1) value = g_tParam.LocalIPAddr[1];
else if (_index == 2) value = g_tParam.LocalIPAddr[2];
else if (_index == 3) value = g_tParam.LocalIPAddr[3];
else if (_index == 4) value = g_tParam.Gateway[0];
else if (_index == 5) value = g_tParam.Gateway[1];
else if (_index == 6) value = g_tParam.Gateway[2];
else if (_index == 7) value = g_tParam.Gateway[3];
else if (_index == 8) value = g_tParam.NetMask[0];
else if (_index == 9) value = g_tParam.NetMask[1];
else if (_index == 10) value = g_tParam.NetMask[2];
else if (_index == 11) value = g_tParam.NetMask[3];
else if (_index == 12) value = g_tParam.LocalTCPPort;
}
else if (s_pParamList == ProgParamList)
{
@ -401,19 +417,23 @@ static void MonDispWriteParam(uint8_t _index, int32_t _value)
if (_index == 0) g_tParam.KeyToneEnable = _value;
else if (_index == 1) g_tParam.LcdSleepTime = _value;
else if (_index == 2) g_tParam.FileListFont24 = _value;
else if (_index == 3) g_tParam.LocalIPAddr[0] = _value;
else if (_index == 4) g_tParam.LocalIPAddr[1] = _value;
else if (_index == 5) g_tParam.LocalIPAddr[2] = _value;
else if (_index == 6) g_tParam.LocalIPAddr[3] = _value;
else if (_index == 7) g_tParam.Gateway[0] = _value;
else if (_index == 8) g_tParam.Gateway[1] = _value;
else if (_index == 9) g_tParam.Gateway[2] = _value;
else if (_index == 10) g_tParam.Gateway[3] = _value;
else if (_index == 11) g_tParam.NetMask[0] = _value;
else if (_index == 12) g_tParam.NetMask[1] = _value;
else if (_index == 13) g_tParam.NetMask[2] = _value;
else if (_index == 14) g_tParam.NetMask[3] = _value;
else if (_index == 15) g_tParam.LocalTCPPort = _value;
else if (_index == 3) g_tParam.StartRun = _value;
}
else if (s_pParamList == NetParamList)
{
if (_index == 0) g_tParam.LocalIPAddr[0] = _value;
else if (_index == 1) g_tParam.LocalIPAddr[1] = _value;
else if (_index == 2) g_tParam.LocalIPAddr[2] = _value;
else if (_index == 3) g_tParam.LocalIPAddr[3] = _value;
else if (_index == 4) g_tParam.Gateway[0] = _value;
else if (_index == 5) g_tParam.Gateway[1] = _value;
else if (_index == 6) g_tParam.Gateway[2] = _value;
else if (_index == 7) g_tParam.Gateway[3] = _value;
else if (_index == 8) g_tParam.NetMask[0] = _value;
else if (_index == 9) g_tParam.NetMask[1] = _value;
else if (_index == 10) g_tParam.NetMask[2] = _value;
else if (_index == 11) g_tParam.NetMask[3] = _value;
else if (_index == 12) g_tParam.LocalTCPPort = _value;
}
else if (s_pParamList == ProgParamList)
{

View File

@ -14,9 +14,7 @@
*********************************************************************************************************
*/
#include "bsp.h"
#include "param.h"
#include "modbus_reg_addr.h"
#include "includes.h"
PARAM_T g_tParam; /* 基本参数 */
CALIB_T g_tCalib; /* 校准参数 */
@ -59,6 +57,18 @@ void LoadParam(void)
g_tVar.MACaddr[5] = g_tVar.CPU_Sn[0] >> 0;
LoadCalibParam();
/* 固件升级新增参数的处理 */
{
if (g_tParam.DAP_TVCCVolt > 50)
{
g_tParam.DAP_TVCCVolt = 0;
g_tParam.DAP_BeepEn = 1;
bsp_GenRNG(&g_tParam.DAP_Sn, 1);
SaveParam();
}
}
}
/*
@ -155,6 +165,10 @@ void InitBaseParam(void)
g_tParam.StartRun = 0; /* 开机启动 */
g_tParam.DAP_TVCCVolt = 0;
g_tParam.DAP_BeepEn = 1;
bsp_GenRNG(&g_tParam.DAP_Sn, 1);
SaveParam();
}

View File

@ -14,13 +14,7 @@
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "lcd_menu.h"
#include "file_lib.h"
#include "lua_if.h"
#include "prog_if.h"
#include "modify_param.h"
#include "includes.h"
/* 多行文本框 */
#define MEMO_X 0
@ -213,7 +207,7 @@ void status_MonitorCan(void)
case KEY_LONG_DOWN_S: /* S键 长按 */
LCD_SetEncode(ENCODE_UTF8);
ModifyParam(MS_MONITOR_UART); /* 参数修改界面,阻塞 */
ModifyParam(MODIFY_PARAM_UART_MON); /* 参数修改界面,阻塞 */
LCD_SetEncode(ENCODE_GBK);
fRefresh = 1;
fInit = 1;

View File

@ -14,8 +14,7 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "includes.h"
static void DispCurrentVolt(void);
static void AutoCurrentRange(void);

View File

@ -0,0 +1,210 @@
/*
*********************************************************************************************************
*
* : DS18B20温度传感器监视
* : status_ds18b20_meter.c
* : V1.0
* : 8DS18B20温度值
* :
*
* V1.0 2020-11-29 armfly
*
* Copyright (C), 2019-2030, www.armfly.com
*
*********************************************************************************************************
*/
#include "includes.h"
static void DispDS18B20(void);
static float TemperatureMin[8];
static float TemperatureMax[8];
/*
*********************************************************************************************************
* : status_DS18B20Meter
* : DS18B20温度表状态.
* :
* :
*********************************************************************************************************
*/
void status_DS18B20Meter(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t fRefresh;
DispHeader("DS18B20温度表");
// DispHelpBar("D0-D7可接8个DS18B20",
// "");
fRefresh = 1;
{
uint8_t i;
for (i = 0; i < 8; i++)
{
TemperatureMin[i] = 125;
TemperatureMax[i] = -60;
}
}
bsp_StartAutoTimer(0, 300);
while (g_MainStatus == MS_DS18B20_METER)
{
if (fRefresh) /* 刷新整个界面 */
{
fRefresh = 0;
DispDS18B20();
}
bsp_Idle();
if (bsp_CheckTimer(0))
{
fRefresh = 1;
}
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_S: /* S键按下 */
break;
case KEY_UP_S: /* S键释放 */
;
break;
case KEY_LONG_DOWN_S: /* S键长按 */
break;
case KEY_DOWN_C: /* C键按下 */
break;
case KEY_UP_C: /* C键释放 */
;
break;
case KEY_LONG_DOWN_C: /* C键长按 */
PlayKeyTone();
g_MainStatus = MS_EXTEND_MENU_REC;
break;
default:
break;
}
}
}
bsp_StopTimer(0);
}
/*
*********************************************************************************************************
* : DispDS18B20
* : 8DS18B20数据
* :
* :
*********************************************************************************************************
*/
#define LABLE_X 5
static void DispDS18B20(void)
{
/*
BackColor = RGB(255, 236, 245);
BackColor = RGB(150, 240, 40);
BackColor = RGB(255, 255, 136);
BackColor = RGB(239, 223, 255);
BackColor = RGB(119, 253, 213);
*/
FONT_T tFont16, tFont24;
char buf[32];
uint16_t x, y, h, w;
uint8_t i;
uint8_t SensorOk[8];
float Temperature[8];
for (i = 0; i < 8; i++)
{
if (DS18B20_ReadTemp(i, &Temperature[i]) == 1)
{
SensorOk[i] = 1;
/* DS18B20第1次读出数据可能是 85.0 */
if ((uint16_t)(Temperature[i] * 10) != 850)
{
if (Temperature[i] < TemperatureMin[i])
{
TemperatureMin[i] = Temperature[i];
}
if (Temperature[i] > TemperatureMax[i])
{
TemperatureMax[i] = Temperature[i];
}
}
}
else
{
SensorOk[i] = 0;
}
}
/* 设置字体参数 */
{
tFont16.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont16.FrontColor = RGB(120,120,120); /* 字体颜色 */
tFont16.BackColor = CL_MASK; /* 文字背景 - 透明 */
tFont16.Space = 0; /* 文字间距,单位 = 像素 */
tFont24.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont24.FrontColor = RGB(50,50,50); /* 字体颜色 */
tFont24.BackColor = CL_MASK; /* 文字背景 - 透明 */
tFont24.Space = 0; /* 文字间距,单位 = 像素 */
}
x = LABLE_X;
y = 36;
h = 24 + 1;
w = 200;
for (i = 0; i < 8; i++)
{
/* 显示数字编号 */
sprintf(buf, "%d", i);
w = 24;
DispLabelRound(x, y, h, w, RGB(150, 240, 40), buf, &tFont24);
/* 显示实时温度值 */
if (SensorOk[i] == 0)
{
sprintf(buf, "----");
}
else
{
/* -40.0℃ */
sprintf(buf, "%0.1f℃", Temperature[i]);
}
w = 100;
DispLabelRound(x + 24 + 5, y, h, w, RGB(255, 236, 245), buf, &tFont24);
/* 显示温度最大最小值 */
if (SensorOk[i] == 0)
{
sprintf(buf, "----");
}
else
{
/* -40.0℃ */
sprintf(buf, "%0.1f, %0.1f", TemperatureMin[i],TemperatureMax[i]);
}
w = 100;
DispLabelRound(x + 24 + 8 + 100, y, h, w, RGB(255, 255, 136), buf, &tFont16);
y += h;
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -13,19 +13,20 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "includes.h"
#include "lcd_menu.h"
#include "SW_DP_Multi.h"
#include "modify_param.h"
#include "usb_if.h"
const uint8_t *g_Menu1_Text[] =
{
" 1 脱机烧录器(单路)",
" 2 脱机烧录器(多路)",
" 3 LUA小程序",
" 4 数据监视器",
" 5 系统设置",
" 1 CMSIS-DAP仿真器",
" 2 脱机烧录器(单路)",
" 3 脱机烧录器(多路)",
" 4 LUA小程序",
" 5 数据监视器",
" 6 系统设置",
/* 结束符号, 用于菜单函数自动识别菜单项个数 */
"&"
@ -36,7 +37,7 @@ MENU_T g_tMenu1;
const uint8_t *g_MenuRec_Text[] =
{
"1 串口(TTL 485 232)",
"2 CAN总线(预留)",
"2 DS18B20温度表",
/* 结束符号, 用于菜单函数自动识别菜单项个数 */
"&"
@ -44,6 +45,8 @@ const uint8_t *g_MenuRec_Text[] =
MENU_T g_tMenuRec;
void JumpToDAPLink(void);
/*
*********************************************************************************************************
* : status_ExtendMenu1
@ -110,23 +113,28 @@ void status_ExtendMenu1(void)
case KEY_LONG_DOWN_S: /* S键 上 */
if (g_tMenu1.Cursor == 0)
{
g_gMulSwd.MultiMode = 0;
g_MainStatus = MS_PROG_WORK;
/* 跳转到DAP固件 */
JumpToDAPLink();
}
else if (g_tMenu1.Cursor == 1)
{
g_gMulSwd.MultiMode = g_tParam.MultiProgMode;
g_gMulSwd.MultiMode = 0;
g_MainStatus = MS_PROG_WORK;
}
else if (g_tMenu1.Cursor == 2)
{
g_MainStatus = MS_LUA_SELECT_FILE;
g_gMulSwd.MultiMode = g_tParam.MultiProgMode;
g_MainStatus = MS_PROG_WORK;
}
else if (g_tMenu1.Cursor == 3)
{
g_MainStatus = MS_EXTEND_MENU_REC;
g_MainStatus = MS_LUA_SELECT_FILE;
}
else if (g_tMenu1.Cursor == 4)
{
g_MainStatus = MS_EXTEND_MENU_REC;
}
else if (g_tMenu1.Cursor == 5)
{
g_MainStatus = MS_SYSTEM_SET;
}
@ -222,7 +230,7 @@ void status_ExtendMenuRec(void)
}
else if (g_tMenuRec.Cursor == 1)
{
g_MainStatus = MS_MONITOR_CAN;
g_MainStatus = MS_DS18B20_METER;
}
else if (g_tMenuRec.Cursor == 2)
{
@ -251,4 +259,75 @@ void status_ExtendMenuRec(void)
}
}
/*
*********************************************************************************************************
* : JumpToDAPLink
* : daplink固件
* :
* :
*********************************************************************************************************
*/
void JumpToDAPLink(void)
{
uint8_t i;
__IO uint32_t AppAddr = 0x08100000; /* APP 地址 */
void (*AppJump)(void); /* 声明一个函数指针 */
usbd_UnInit();
/* 关闭全局中断 */
DISABLE_INT();
/* 关闭所有的外设 */
bsp_DeInit();
/* 设置所有时钟到默认状态使用HSI时钟 */
HAL_RCC_DeInit();
/* 关闭UART外设 */
{
USART1->CR1 &= ~USART_CR1_UE;
USART2->CR1 &= ~USART_CR1_UE;
USART3->CR1 &= ~USART_CR1_UE;
UART4->CR1 &= ~USART_CR1_UE;
UART5->CR1 &= ~USART_CR1_UE;
USART6->CR1 &= ~USART_CR1_UE;
UART7->CR1 &= ~USART_CR1_UE;
UART8->CR1 &= ~USART_CR1_UE;
}
/* 关闭滴答定时器,复位到默认值 */
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/* 关闭所有中断,清除所有中断挂起标志 */
for (i = 0; i < 8; i++)
{
NVIC->ICER[i]=0xFFFFFFFF;
NVIC->ICPR[i]=0xFFFFFFFF;
}
/* 使能全局中断 */
ENABLE_INT();
/* 跳转到应用程序首地址是MSP地址+4是复位中断服务程序地址 */
AppJump = (void (*)(void)) (*((uint32_t *) (AppAddr + 4)));
/* 设置主堆栈指针 */
__set_MSP(*(uint32_t *)AppAddr);
/* 在RTOS工程这条语句很重要设置为特权级模式使用MSP指针 */
__set_CONTROL(0);
/* 跳转到系统BootLoader */
AppJump();
/* 跳转成功的话,不会执行到这里,用户可以在这里添加代码 */
while (1)
{
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -13,8 +13,7 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "includes.h"
#include "usbd_user.h"
#define DATE_X 5

View File

@ -13,8 +13,7 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "includes.h"
#include "lcd_menu.h"
#include "file_lib.h"
#include "lua_if.h"

View File

@ -13,9 +13,7 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "lcd_menu.h"
#include "includes.h"
/*
*********************************************************************************************************

View File

@ -13,8 +13,7 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "includes.h"
static void DispPulse(void);

View File

@ -13,14 +13,9 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "file_lib.h"
#include "lua_if.h"
#include "prog_if.h"
#include "lcd_menu.h"
#include "includes.h"
#include "SW_DP_Multi.h"
#include "modify_param.h"
/* 三个按钮 */
#define BTN1_X (240 - BTN1_W - 5)
@ -98,6 +93,7 @@ static void DispProgCounter(void);
extern void sysTickInit(void);
extern uint8_t swd_init_debug(void);
extern uint8_t swd_read_idcode(uint32_t *id);
extern uint8_t swd_init(void);
/*
*********************************************************************************************************
@ -282,6 +278,18 @@ void status_ProgWork(void)
// }
// }
/* V1.36 解决第一次上电第1次烧录失败问题 */
{
if (g_gMulSwd.MultiMode == 0)
{
MUL_PORT_SWD_SETUP();
}
else
{
swd_init();
}
}
g_tProg.AutoStart = 0;
fRefresh = 1;
while (g_MainStatus == MS_PROG_WORK)
@ -931,7 +939,7 @@ void status_ProgSetting(void)
{
//g_MainStatus = MS_PROG_MODIFY_PARAM);;
ModifyParam(MS_PROG_MODIFY_PARAM);
ModifyParam(MODIFY_PARAM_PROG);
LCD_DispMenu(&g_tMenuProg1);
/* 通知lua程序多路编程参数变化 */
lua_do("MULTI_MODE = pg_read_c_var(\"MultiProgMode\")");

View File

@ -13,8 +13,7 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "includes.h"
static void DispResistor(void);

View File

@ -13,24 +13,17 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "status_system_set.h"
#include "lcd_menu.h"
#include "wifi_if.h"
#include "usb_if.h"
#include "file_lib.h"
#include "modify_param.h"
#include "includes.h"
const uint8_t *g_MenuSys_Text[] =
{
" 1 硬件信息",
" 2 参数设置",
" 1 基本参数",
" 2 网络参数",
" 3 ESP32固件升级",
" 4 USB eMMC磁盘",
" 5 数据维护",
" 6 重启",
" 6 硬件信息",
" 7 重启",
/* 结束符号, 用于菜单函数自动识别菜单项个数 */
"&"
};
@ -112,12 +105,13 @@ void status_SystemSetMain(void)
if (g_tMenuSys.Cursor == 0)
{
g_MainStatus = MS_HARD_INFO;
ModifyParam(MODIFY_PARAM_SYSTEM);
DispHeader2(90, "系统设置"); /* 需要清屏 */
LCD_DispMenu(&g_tMenuSys);
}
else if (g_tMenuSys.Cursor == 1)
{
//g_MainStatus = MS_MODIFY_PARAM;
ModifyParam(MS_SYSTEM_SET);
ModifyParam(MODIFY_PARAM_NET);
DispHeader2(90, "系统设置"); /* 需要清屏 */
LCD_DispMenu(&g_tMenuSys);
}
@ -133,7 +127,11 @@ void status_SystemSetMain(void)
{
g_MainStatus = MS_FILE_MANAGE;
}
else if (g_tMenuSys.Cursor == 5) /* 重启 */
else if (g_tMenuSys.Cursor == 5)
{
g_MainStatus = MS_HARD_INFO;
}
else if (g_tMenuSys.Cursor == 6) /* 重启 */
{
ResetReq = 1;
}
@ -379,250 +377,6 @@ void status_HardInfo(void)
}
}
/*
*********************************************************************************************************
* : status_ModifyParam
* :
* :
* :
*********************************************************************************************************
*/
#define PARAM_NUM 4
void status_ModifyParam(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t fRefresh = 1;
uint8_t fSaveParam = 0;
uint8_t cursor = 0;
char buf[48];
uint8_t ucIgnoreKey = 1;
uint8_t active;
DispHeader2(92, "参数设置");
DispHelpBar("长按S键选择参数",
"短按S、C键修改参数值");
while (g_MainStatus == MS_MODIFY_PARAM)
{
bsp_Idle();
if (fRefresh == 1)
{
fRefresh = 0;
/* 第1个参数 */
{
if (cursor == 0)
{
active = 1;
}
else
{
active = 0;
}
if (g_tParam.KeyToneEnable == 0)
{
sprintf(buf, "关闭");
DispParamBar(0, "1 按键音:", buf, active);
}
else
{
sprintf(buf, "打开");
DispParamBar(0, "1 按键音:", buf, active);
}
}
/* 第2个参数 - 界面风格 */
{
if (cursor == 1)
{
active = 1;
}
else
{
active = 0;
}
sprintf(buf, "%3d", g_tParam.UIStyle);
DispParamBar(1, "2 主 题:", buf, active);
}
/* 第3个参数 - 屏保 */
{
uint16_t min;
if (cursor == 2)
{
active = 1;
}
else
{
active = 0;
}
min = GetSleepTimeMinute();
if (min == 0)
{
sprintf(buf, "关闭");
}
else
{
sprintf(buf, "%3d 分钟", min);
}
DispParamBar(2, "3 屏 保:", buf, active);
}
/* 第3个参数 - 文件列表字体 */
{
if (cursor == 3)
{
active = 1;
}
else
{
active = 0;
}
if (g_tParam.FileListFont24 == 1)
{
sprintf(buf, "24点阵");
}
else
{
sprintf(buf, "16点阵");
}
DispParamBar(3, "4 列表字体:", buf, active);
}
}
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 弹起 */
if (ucIgnoreKey == 1)
{
ucIgnoreKey = 0;
break;
}
if (cursor == 0)
{
if (g_tParam.KeyToneEnable == 0)
{
g_tParam.KeyToneEnable = 1;
}
else
{
g_tParam.KeyToneEnable = 0;
}
}
else if (cursor == 1)
{
g_tParam.UIStyle++;
if (g_tParam.UIStyle >= UI_STYLE_NUM)
{
g_tParam.UIStyle = 0;
}
}
else if (cursor == 2)
{
if (g_tParam.LcdSleepTime > 0)
{
g_tParam.LcdSleepTime--;
}
else
{
g_tParam.LcdSleepTime = 4;
}
}
else if (cursor == 3)
{
if (g_tParam.FileListFont24 == 0)
{
g_tParam.FileListFont24 = 1;
}
else
{
g_tParam.FileListFont24 = 0;
}
}
fRefresh = 1;
fSaveParam = 1;
break;
case KEY_UP_C: /* C键 下 */
if (cursor == 0)
{
if (g_tParam.KeyToneEnable == 0)
{
g_tParam.KeyToneEnable = 1;
}
else
{
g_tParam.KeyToneEnable = 0;
}
}
else if (cursor == 1)
{
if (g_tParam.UIStyle > 0)
{
g_tParam.UIStyle--;
}
else
{
g_tParam.UIStyle = UI_STYLE_NUM;
}
}
else if (cursor == 2)
{
if (++g_tParam.LcdSleepTime > 4)
{
g_tParam.LcdSleepTime = 0;
}
}
else if (cursor == 3)
{
if (g_tParam.FileListFont24 == 0)
{
g_tParam.FileListFont24 = 1;
}
else
{
g_tParam.FileListFont24 = 0;
}
}
fRefresh = 1;
fSaveParam = 1;
break;
case KEY_LONG_DOWN_S: /* S键长按 - 选择参数 */
if (++cursor >= PARAM_NUM)
{
cursor = 0;
}
ucIgnoreKey = 1;
fRefresh = 1;
break;
case KEY_LONG_DOWN_C: /* C键长按 - 返回 */
PlayKeyTone();
g_MainStatus = MS_SYSTEM_SET;
break;
default:
break;
}
}
}
if (fSaveParam == 1)
{
SaveParam(); /* 保存参数 */
}
}
/*
*********************************************************************************************************
* : status_ESP32Test

View File

@ -13,8 +13,7 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "includes.h"
static void DispTemp(void);

View File

@ -13,8 +13,7 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "includes.h"
static void DispTVccVoltCurr(void);
static void DispTVccSetting(uint16_t _volt, uint8_t _mode);

View File

@ -13,13 +13,8 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "lcd_menu.h"
#include "file_lib.h"
#include "lua_if.h"
#include "prog_if.h"
#include "modify_param.h"
#include "includes.h"
/* 多行文本框 */
#define TITLE_X 0
@ -183,6 +178,10 @@ void UartReciveNew2(uint8_t _byte)
if (g_tParam.UartMonHex == 0) /* ASCII格式显示 */
{
if (_byte < ' ')
{
_byte = ' '; /* 不可见字符转换为空格 */
}
LCD_MemoAddChar(&g_RecMemo, _byte);
}
else /* HEX格式显示 */
@ -396,7 +395,7 @@ void status_MonitorUart(void)
else if (g_tMenuUart.Cursor == 3) /* 设置串口参数 */
{
LCD_SetEncode(ENCODE_UTF8);
ModifyParam(MS_MONITOR_UART); /* 参数修改界面,阻塞 */
ModifyParam(MODIFY_PARAM_UART_MON); /* 参数修改界面,阻塞 */
LCD_SetEncode(ENCODE_GBK);
fInit = 1;
}

View File

@ -13,8 +13,7 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "includes.h"
static void DispCH1CH2(void);
static void AutoVoltRange(void);

View File

@ -14,10 +14,7 @@
*********************************************************************************************************
*/
#include "bsp.h"
#include "wifi_if.h"
#include "param.h"
#include "main.h"
#include "includes.h"
uint8_t link_id = 0xFF; /* 当前的TCP连接id, 0-4有效。 FF表示无TCP连接 */
uint8_t wifi_state = WIFI_STOP;

View File

@ -100,6 +100,20 @@ void bsp_Init(void)
bsp_InitRNG(); /* 配置启用随机数模块 */
}
/*
*********************************************************************************************************
* : bsp_DeInit
* :
* :
* :
*********************************************************************************************************
*/
void bsp_DeInit(void)
{
bsp_DeInitUart();
}
/*
*********************************************************************************************************
* : SystemClock_Config

View File

@ -99,6 +99,7 @@
#include "bsp_ext_io.h"
#include "bsp_rng.h"
#include "bsp_ds18b20.h"
@ -108,6 +109,7 @@
/* 提供给其他C文件调用的函数 */
void bsp_Init(void);
void bsp_DeInit(void);
void bsp_Idle(void);
void bsp_GetCpuID(uint32_t *_id);

View File

@ -33,6 +33,8 @@ void bsp_InitRTC(void);
uint8_t RTC_WriteClock(uint16_t _year, uint8_t _mon, uint8_t _day, uint8_t _hour, uint8_t _min, uint8_t _sec);
void RTC_ReadClock(void);
uint8_t RTC_CalcWeek(uint16_t _year, uint8_t _mon, uint8_t _day);
uint32_t RTC_ReadBkup32(uint32_t _addr);
void RTC_WriteBkup32(uint32_t _addr, uint32_t _value);
extern RTC_T g_tRTC;

View File

@ -0,0 +1,19 @@
/*
*********************************************************************************************************
*
* : DS18B20 (1-wire
* : bsp_ds18b20.h
*
* Copyright (C), 2020, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef _BSP_DS18B20_H
#define _BSP_DS18B20_H
uint8_t DS18B20_ReadTemp(uint8_t _ch, float *_result);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -55,7 +55,8 @@ typedef enum
ES_GPIO_SWD_OUT = 8, /* 1拖4 SWD接口用 */
ES_GPIO_SPI = 9, /* SPI功能 */
ES_GPIO_SPI = 9, /* 硬件SPI功能 */
ES_PROG_SPI_FLASH = 10, /* 脱机烧录SPI FLASH */
} EIO_SELECT_E;
void bsp_InitExtIO(void);

View File

@ -187,6 +187,7 @@ typedef struct
}UART_T;
void bsp_InitUart(void);
void bsp_DeInitUart(void);
void comSendBuf(COM_PORT_E _ucPort, uint8_t *_ucaBuf, uint16_t _usLen);
void comSendChar(COM_PORT_E _ucPort, uint8_t _ucByte);
uint8_t comGetChar(COM_PORT_E _ucPort, uint8_t *_pByte);

View File

@ -296,4 +296,31 @@ uint8_t RTC_CalcWeek(uint16_t _year, uint8_t _mon, uint8_t _day)
return w;
}
/*
*********************************************************************************************************
* : RTC_ReadBkup32
* :
* : _addr 0-31
* :
*********************************************************************************************************
*/
uint32_t RTC_ReadBkup32(uint32_t _addr)
{
return HAL_RTCEx_BKUPRead(&RtcHandle, _addr);
}
/*
*********************************************************************************************************
* : RTC_WriteBkup32
* :
* : _addr 0-31
* :
*********************************************************************************************************
*/
void RTC_WriteBkup32(uint32_t _addr, uint32_t _value)
{
HAL_RTCEx_BKUPWrite(&RtcHandle, _addr, _value);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

491
User/bsp/src/bsp_ds18b20.c Normal file
View File

@ -0,0 +1,491 @@
/*
*********************************************************************************************************
*
* : DS18B20 (1-wire
* : bsp_ds18b20.c
* : V1.0
* : H7-TOOL 10us定时中断模式驱动. 8.
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "param.h"
#define DS18B20_IRQ_HANDLE TIM16_IRQHandler
#define TIM_HARD TIM16
#define TIM_HARD_IRQn TIM16_IRQn
#define DQ_DIR_OUTPUT(ch) EIO_ConfigPort(ch, ES_GPIO_OUT)
#define DQ_DIR_INPUT(ch) EIO_ConfigPort(ch, ES_GPIO_IN)
#define DQ_0(ch) EIO_SetOutLevel(ch, 0)
#define DQ_1(ch) EIO_SetOutLevel(ch, 1)
/* 判断DQ输入是否为低 */
#define DQ_IS_LOW(ch) (EIO_GetInputLevel(ch) == 0)
/*
D0 PD14 PA15 PI0 - DIR PH8 CS2
D1 PD15 PA8 PH19 - DIR PG8 CS3
D2 PE6 PD0 PB7 - DIR PD9 MOSI_1 (SPI信号)
D3 PE5 PD1 PH11 - DIR PG10 MISO_1 (SPI信号)
D4 PE4 PE7 PH12 - DIR PG12 CS1 ()
D5 PE2 PE8 PI5 - DIR PG7 SCK (SPI信号)
D6 PE9 PD3 PA0 - DIR PD10 MOSI_2
D7 PE10 PI6 - DIR PI1 MISO_2 (2MISO)
D8 PE11 PD4 PI3 - DIR PG9 MISO_3 (3MISO)
D9 PE12 PD5 - DIR PI12 MISO_4 (4MISO)
*/
static float s_DS18B20_TempReg[8];
static uint16_t s_err[8] = {0};
static void DS18B20_StartTimerIRQ(void);
static void DS18B20_StopTimerIRQ(void);
static uint8_t s_ch = 0;
static uint16_t s_status = 0;
/*
*********************************************************************************************************
* : DS18B20_ReadTempReg
* : . .
* :
* : 01OK
*********************************************************************************************************
*/
uint8_t DS18B20_ReadTemp(uint8_t _ch, float *_result)
{
uint8_t re = 0;
if (_ch > 7)
{
return re;
}
EIO_ConfigPort(_ch, ES_GPIO_OUT); /* DQ方向输出 */
s_err[_ch] = 1;
s_ch = _ch;
s_status = 0;
/* 定时周期10us频率100KHz */
DS18B20_StartTimerIRQ();
while (s_status != 10)
{
//bsp_Idle();
}
DS18B20_StopTimerIRQ();
if (s_err[s_ch] == 1)
{
re = 0; /* 返回异常温度值 */
}
else
{
*_result = (float)s_DS18B20_TempReg[s_ch] / 16;
re = 1;
}
return re;
}
/*
*********************************************************************************************************
* : DS18B20_CaculCRC
* : CRC校验
* : _buf:
* _len :
* :
*********************************************************************************************************
*/
uint8_t DS18B20_CaculCRC(uint8_t *_buf, uint8_t _len)
{
uint8_t crc = 0, i, j;
for (i = 0; i < _len; i++)
{
crc = crc ^ _buf[i];
for (j = 0; j < 8; j++)
{
if (crc & 0x01)
{
crc = (crc >> 1) ^ 0x8C;
}
else
{
crc >>= 1;
}
}
}
return crc;
}
/*
*********************************************************************************************************
* : DS18B20_IRQ_HANDLE
* : 10us定时中断服务程序DS18B20温度值
* :
* :
*********************************************************************************************************
*/
void DS18B20_IRQ_HANDLE(void)
{
static uint16_t s_time = 0;
static uint16_t s_call_ret = 0;
static uint16_t s_write_value = 0;
static uint8_t s_i;
static uint8_t s_read;
static uint8_t s_rx_buf[9];
static uint8_t s_rx_len = 0;
if (TIM_HARD->SR & TIM_IT_UPDATE)
{
TIM_HARD->SR = (uint16_t)~TIM_IT_UPDATE;
}
/*
, DS18B20 page 15
DQ 480us
DQDQ被上拉电阻拉高 15-60us
DS18B20 DQ为低 60-240us presence pulse (,DS18B20准备就绪 )
DS18B20复位成功
*/
s_time++;
switch (s_status)
{
// DS18B20_Reset(_ch);
// DS18B20_WriteByte(_ch, 0xcc); /* 发命令 - 跳过ROM */
// DS18B20_WriteByte(_ch,0x44); /* 发转换命令 */
// DS18B20_Reset(_ch); /* 总线复位 */
// DS18B20_WriteByte(_ch, 0xcc); /* 发命令 */
// DS18B20_WriteByte(_ch,0xbe); /* 读温度 */
// temp1 = DS18B20_ReadByte(_ch); /* 读温度值低字节 */
// temp2 = DS18B20_ReadByte(_ch); /* 读温度值高字节 */
// return ((temp2 << 8) | temp1); /* 返回16位寄存器值 */
case 0:
s_status++;
break;
case 1:
s_call_ret = s_status + 1; /* 执行完毕返回状态 */
s_status = 100; /* 去执行DS18B20_Reset */
break;
case 2:
s_call_ret = s_status + 1;
s_write_value = 0xcc;
s_status = 110; /* DS18B20_WriteByte(_ch, 0xcc); */
break;
case 3:
s_call_ret = s_status + 1;
s_write_value = 0x44;
s_status = 110; /* DS18B20_WriteByte(_ch,0x44); */
break;
case 4:
s_call_ret = s_status + 1;
s_status = 100; /* DS18B20_Reset */
break;
case 5:
s_call_ret = s_status + 1;
s_write_value = 0xcc;
s_status = 110; /* DS18B20_WriteByte(_ch, 0xcc); */
break;
case 6:
s_call_ret = s_status + 1;
s_write_value = 0xBE;
s_status = 110; /* DS18B20_WriteByte(_ch,0xbe); */
break;
case 7:
s_call_ret = s_status + 1;
s_status = 120; /* DS18B20_ReadByte(_ch); 读温度值 */
break;
case 8:
if (DS18B20_CaculCRC(s_rx_buf, 8) == s_rx_buf[8] && s_rx_buf[4] == 0x7F)
{
int16_t reg16;
reg16 = (s_rx_buf[1] << 8) + s_rx_buf[0];
s_DS18B20_TempReg[s_ch] = reg16;
s_err[s_ch] = 0; /* 读取成功清0 */
}
else
{
s_err[s_ch] = 1;
}
s_status++;
break;
case 9:
/* 任务结束,关闭定时中断 */
DS18B20_StopTimerIRQ();
s_status++;
break;
case 10: /* 执行一次结束,再此处等待 */
;
break;
case 99: /* 异常处理 */
s_err[s_ch] = 1; /* 错误 */
s_status = 9; /* 结束任务 */
break;
/************ DS18B20_Reset 总线复位子程序 ************/
case 100:
DQ_DIR_OUTPUT(s_ch); /* DQ方向输出 */
DQ_0(s_ch); /* 拉低DQ */
s_time = 0;
s_status++;
break;
case 101: /* 延迟 520uS 要求这个延迟大于 480us */
if (s_time >= 52)
{
DQ_DIR_INPUT(s_ch); /* DQ方向输入, 外部上拉会拉到高 */
//DQ_1(s_ch); /* 释放DQ */
s_time = 0;
s_status++;
}
break;
case 102: /* 延时60us等待总线电平归位 */
if (s_time >= 6)
{
s_time = 0;
s_status++;
}
if (!DQ_IS_LOW(s_ch)) /* 总线已经拉高 */
{
s_time = 0;
s_status++;
}
break;
case 103: /* 等待DS18B20拉低总线 */
if (DQ_IS_LOW(s_ch))
{
s_time = 0;
s_status++;
}
if (s_time > 8) /* 80us 没检测到应答则认为DS18B20异常 */
{
s_status = 99; /* 错误处理 */
}
break;
case 104: /* 等待DS18B20释放总线 */
if (!DQ_IS_LOW(s_ch))
{
s_time = 0;
s_status++;
}
if (s_time > 30) /* 300us 没释放则认为DS18B20异常 */
{
s_status = 99; /* 错误处理 */
}
break;
case 105: /* 复位成功,下面可以开始读数据了 */
s_status = s_call_ret;
break;
/************ DS18B20_WriteByte ************/
// for (i = 0; i < 8; i++)
// {
// DQ_0(_ch);
// bsp_DelayUS(2);
// if (_val & 0x01)
// {
// DQ_1(_ch);
// }
// else
// {
// DQ_0(_ch);
// }
// bsp_DelayUS(60);
// DQ_1(_ch);
// bsp_DelayUS(2);
// _val >>= 1;
// }
case 110:
s_i = 0;
s_status++;
break;
case 110 + 1:
DQ_DIR_OUTPUT(s_ch); /* DQ方向输出 */
DQ_0(s_ch); /* 拉低DQ */
bsp_DelayUS(2);
if (s_write_value & 0x01)
{
DQ_1(s_ch);
}
else
{
DQ_0(s_ch);
}
s_time = 0;
s_status++;
break;
case 110 + 2:
if (s_time >= 6)
{
DQ_1(s_ch);
s_write_value >>= 1;
if (++s_i >= 8)
{
s_status++;
}
else
{
s_status--;
}
}
break;
case 110 + 3:
s_status = s_call_ret;
break;
/************ DS18B20_ReadByte ************/
// uint8_t i;
// uint8_t read = 0;
// for (i = 0; i < 8; i++)
// {
// read >>= 1;
// DQ_0(_ch);
// bsp_DelayUS(3);
// DQ_1(_ch);
// bsp_DelayUS(3);
// if (DQ_IS_LOW(_ch))
// {
// ;
// }
// else
// {
// read |= 0x80;
// }
// bsp_DelayUS(60);
// }
// return read;
case 120:
s_rx_len = 0;
s_status++;
break;
case 120 + 1:
s_i = 0;
s_read = 0;
s_status++;
break;
case 120 + 2:
s_read >>= 1;
DQ_DIR_OUTPUT(s_ch); /* DQ方向输出 */
DQ_0(s_ch);
bsp_DelayUS(3);
//DQ_1(s_ch);
DQ_DIR_INPUT(s_ch); /* DQ方向输入 */
bsp_DelayUS(3);
if (DQ_IS_LOW(s_ch))
{
;
}
else
{
s_read |= 0x80;
}
s_time = 0;
s_status++;
break;
case 120 + 3:
if (s_time >= 6) /* 延迟60us */
{
if (++s_i >= 8)
{
s_status++;
}
else
{
s_status--;
}
}
break;
case 120 + 4:
s_rx_buf[s_rx_len] = s_read;
if (++s_rx_len >= 9)
{
s_status++;
}
else
{
s_status = 120 + 1;
}
break;
case 120 + 5:
//s_err[s_ch] = 0; /* 读取成功清0 */
s_status = s_call_ret;
break;
}
}
/*
*********************************************************************************************************
* : DS18B20_StartTimerIRQ
* : TIM定时中断
* :
* :
*********************************************************************************************************
*/
static void DS18B20_StartTimerIRQ(void)
{
bsp_SetTIMforInt(TIM_HARD, 100*1000, 0, 0);
}
/*
*********************************************************************************************************
* : DS18B20_StopTimerIRQ
* : TIM定时中断
* :
* :
*********************************************************************************************************
*/
static void DS18B20_StopTimerIRQ(void)
{
bsp_SetTIMforInt(TIM_HARD, 0, 0, 0);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -351,6 +351,12 @@ void EIO_D0_Config(EIO_SELECT_E _mode)
GPIO_INIT_UART7(GPIOA, GPIO_PIN_15); /* 配置GPIO为UART7功能 */
GPIO_INIT_INPUT(GPIOI, GPIO_PIN_0); /* 配置为GPIO 输入功能 */
}
else if (_mode == ES_PROG_SPI_FLASH)
{
GPIO_DIR_SET_OUT(GPIO_D0_DIR, PIN_D0_DIR); /* 设置为输出方向 - 先执行 */
GPIO_INIT_INPUT(GPIOA, GPIO_PIN_15); /* 配置为GPIO 输入功能 */
GPIO_INIT_OUT_PP(GPIOI, GPIO_PIN_0); /* 配置为GPIO 输出功能 */
}
else
{
g_tVar.GpioMode[0] = 0;
@ -405,6 +411,13 @@ void EIO_D1_Config(EIO_SELECT_E _mode)
GPIO_INIT_INPUT(GPIOI, GPIO_PIN_0); /* 配置为GPIO 输入功能 */
GPIO_DIR_SET_IN(GPIO_D1_DIR, PIN_D1_DIR); /* 设置为输入方向 - 后执行 */
}
else if (_mode == ES_PROG_SPI_FLASH) /* PD15 输出 */
{
GPIO_DIR_SET_OUT(GPIO_D1_DIR, PIN_D1_DIR); /* 设置为输出方向 - 先执行 */
GPIO_INIT_INPUT(GPIOA, GPIO_PIN_8); /* 配置为GPIO输入功能 */
GPIO_INIT_INPUT(GPIOH, GPIO_PIN_10); /* 配置为GPIO输入功能 */
GPIO_INIT_OUT_PP(GPIOD, GPIO_PIN_15); /* 配置为GPIO输出功能 */
}
else
{
g_tVar.GpioMode[1] = 0;
@ -459,6 +472,13 @@ void EIO_D2_Config(EIO_SELECT_E _mode)
GPIO_INIT_INPUT(GPIOB, GPIO_PIN_7); /* 配置为GPIO 输入功能 */
GPIO_INIT_AF_PP(GPIOE, GPIO_PIN_6); /* 配置为GPIO AF功能 */
}
else if (_mode == ES_PROG_SPI_FLASH) /* MOSI_1 = PD0(写时) PE6(读时) */
{
GPIO_DIR_SET_OUT(GPIO_D2_DIR, PIN_D2_DIR); /* 设置为输出方向 - 先执行 */
GPIO_INIT_INPUT(GPIOB, GPIO_PIN_7); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOE, GPIO_PIN_6); /* 配置为GPIO 输入功能 */
GPIO_INIT_OUT_PP(GPIOD, GPIO_PIN_0); /* 配置为GPIO 输出功能 */
}
else
{
g_tVar.GpioMode[2] = 0;
@ -513,6 +533,13 @@ void EIO_D3_Config(EIO_SELECT_E _mode)
GPIO_INIT_AF_PP(GPIOE, GPIO_PIN_5); /* 配置为GPIO AF */
GPIO_DIR_SET_IN(GPIO_D3_DIR, PIN_D3_DIR); /* 设置为输入方向 - 后执行 */
}
else if (_mode == ES_PROG_SPI_FLASH) /* MOSI_2 = PD1(写时) PE5(读时) */
{
GPIO_DIR_SET_OUT(GPIO_D3_DIR, PIN_D3_DIR); /* 设置为输出方向 - 先执行 */
GPIO_INIT_INPUT(GPIOH, GPIO_PIN_11); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOE, GPIO_PIN_5); /* 配置为GPIO 输入功能 */
GPIO_INIT_OUT_PP(GPIOD, GPIO_PIN_1); /* 配置为GPIO 输出功能 */
}
else
{
g_tVar.GpioMode[3] = 0;
@ -561,6 +588,12 @@ void EIO_D4_Config(EIO_SELECT_E _mode)
GPIO_INIT_INPUT(GPIOH, GPIO_PIN_12); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOE, GPIO_PIN_4); /* 配置为GPIO 输入功能 */
}
else if (_mode == ES_PROG_SPI_FLASH) /* MISO_1 = PE4 */
{
GPIO_INIT_INPUT(GPIOH, GPIO_PIN_12); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOE, GPIO_PIN_4); /* 配置为GPIO 输入功能 */
GPIO_DIR_SET_IN(GPIO_D4_DIR, PIN_D4_DIR); /* 设置为输入方向 - 后执行 */
}
else
{
g_tVar.GpioMode[4] = 0;
@ -615,6 +648,12 @@ void EIO_D5_Config(EIO_SELECT_E _mode)
GPIO_INIT_INPUT(GPIOI, GPIO_PIN_5); /* 配置为GPIO 输入功能 */
GPIO_INIT_AF_PP(GPIOE, GPIO_PIN_2); /* 配置为GPIO 为AF给 */
}
else if (_mode == ES_PROG_SPI_FLASH) /* MISO_2 = PE2 */
{
GPIO_INIT_INPUT(GPIOI, GPIO_PIN_5); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOE, GPIO_PIN_2); /* 配置为GPIO 输入功能 */
GPIO_DIR_SET_IN(GPIO_D5_DIR, PIN_D5_DIR); /* 设置为输入方向 - 后执行 */
}
else
{
g_tVar.GpioMode[5] = 0;
@ -670,6 +709,13 @@ void EIO_D6_Config(EIO_SELECT_E _mode)
GPIO_INIT_INPUT(GPIOA, GPIO_PIN_0); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOD, GPIO_PIN_3); /* 配置为GPIO 输入功能 */
}
else if (_mode == ES_PROG_SPI_FLASH) /* MOSI_3 = PD3(写时) PE9(读时) */
{
GPIO_DIR_SET_OUT(GPIO_D6_DIR, PIN_D6_DIR); /* 设置为输出方向 - 先执行 */
GPIO_INIT_INPUT(GPIOA, GPIO_PIN_0); /* 配置为GPIO 输入功能 */
GPIO_INIT_OUT_PP(GPIOD, GPIO_PIN_3); /* 配置为GPIO 输出功能 */
GPIO_INIT_INPUT(GPIOE, GPIO_PIN_9);
}
else
{
g_tVar.GpioMode[6] = 0;
@ -732,6 +778,13 @@ void EIO_D7_Config(EIO_SELECT_E _mode)
GPIO_INIT_INPUT(GPIOI, GPIO_PIN_6); /* 配置为GPIO 输入功能 */
GPIO_DIR_SET_IN(GPIO_D7_DIR, PIN_D7_DIR); /* 设置为输入方向 - 后执行 */
}
else if (_mode == ES_PROG_SPI_FLASH) /* MISO_3 = PE10 */
{
GPIO_INIT_INPUT(GPIOF, GPIO_PIN_0); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOI, GPIO_PIN_6); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOE, GPIO_PIN_10); /* 配置为GPIO 输入功能 */
GPIO_DIR_SET_IN(GPIO_D7_DIR, PIN_D7_DIR); /* 设置为输入方向 - 后执行 */
}
else
{
g_tVar.GpioMode[7] = 0;
@ -806,6 +859,14 @@ void EIO_D8_Config(EIO_SELECT_E _mode)
GPIO_INIT_INPUT(GPIOE, GPIO_PIN_11); /* 配置为GPIO 输入功能 */
GPIO_INIT_FMC(GPIOD, GPIO_PIN_4); /* 配置为FMC功能 NOE */
}
else if (_mode == ES_PROG_SPI_FLASH) /* MOSI_4 = PD4(写时) PE11(读时) */
{
GPIO_DIR_SET_OUT(GPIO_D8_DIR, PIN_D8_DIR); /* 设置为输出方向 - 先执行 */
GPIO_INIT_OUT_PP(GPIOD, GPIO_PIN_4); /* 配置为GPIO 输出功能 */
GPIO_INIT_INPUT(GPIOI, GPIO_PIN_3); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOE, GPIO_PIN_3); /* 配置为GPIO 输入功能 */
}
else
{
g_tVar.GpioMode[8] = 0;
@ -883,6 +944,14 @@ void EIO_D9_Config(EIO_SELECT_E _mode)
GPIO_INIT_INPUT(GPIOD, GPIO_PIN_5); /* 配置为GPIO 输入功能 */
GPIO_DIR_SET_IN(GPIO_D9_DIR, PIN_D9_DIR); /* 设置为输入方向 - 后执行 */
}
else if (_mode == ES_PROG_SPI_FLASH) /* MISO_4 = PE12(读时) */
{
GPIO_INIT_INPUT(GPIOE, GPIO_PIN_12); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOF, GPIO_PIN_1); /* 配置为GPIO 输入功能 */
GPIO_INIT_INPUT(GPIOD, GPIO_PIN_5); /* 配置为GPIO 输入功能 */
GPIO_DIR_SET_IN(GPIO_D9_DIR, PIN_D9_DIR); /* 设置为输入方向 - 后执行 */
}
else
{
g_tVar.GpioMode[9] = 0;

View File

@ -252,6 +252,33 @@ void bsp_PutKey(uint8_t _KeyCode)
return;
}
/* 启动后 100ms内检测到按键按下全部忽略 - 例如从 DAP返回C键一直按着. 需要忽略这个按键事件 */
{
static uint8_t s_JumpFlag = 0;
if (s_JumpFlag == 0)
{
if (bsp_CheckRunTime(0) < 100)
{
s_JumpFlag = 1;
return;
}
else
{
s_JumpFlag = 2;
}
}
else if (s_JumpFlag == 1)
{
if (_KeyCode == KEY_1_UP || _KeyCode == KEY_1_LONG_UP
|| _KeyCode == KEY_2_UP || _KeyCode == KEY_2_LONG_UP)
{
s_JumpFlag = 2;
return;
}
}
}
s_tKey.Buf[s_tKey.Write] = _KeyCode;
if (++s_tKey.Write >= KEY_FIFO_SIZE)

View File

@ -333,6 +333,7 @@ void ST7789_DrawScreen(void)
}
#else
static int32_t s_time1 = 0;
static uint8_t s_first_run = 0; /* 上电第1次运行准备好数据后开背光避免短暂花屏 */
if (s_DispRefresh == 0)
{
@ -360,6 +361,13 @@ void ST7789_DrawScreen(void)
while (wTransferState == 0){}
s_time1 = bsp_GetRunTime();
if (s_first_run == 0)
{
s_first_run = 1;
LCD_SetBackLight(BRIGHT_DEFAULT); /* 打开背光 255 */
}
#endif
}

View File

@ -413,6 +413,40 @@ void bsp_SetTIMforInt(TIM_TypeDef* TIMx, uint32_t _ulFreq, uint8_t _PreemptionPr
uint16_t usPrescaler;
uint32_t uiTIMxCLK;
if (_ulFreq == 0)
{
bsp_RCC_TIM_Disable(TIMx);
__HAL_TIM_ENABLE_IT(&TimHandle, TIM_IT_UPDATE);
/* 配置TIM定时更新中断 (Update) */
{
uint8_t irq = 0; /* 中断号, 定义在 stm32h7xx.h */
if (TIMx == TIM1) irq = TIM1_UP_IRQn;
else if (TIMx == TIM2) irq = TIM2_IRQn;
else if (TIMx == TIM3) irq = TIM3_IRQn;
else if (TIMx == TIM4) irq = TIM4_IRQn;
else if (TIMx == TIM5) irq = TIM5_IRQn;
else if (TIMx == TIM6) irq = TIM6_DAC_IRQn;
else if (TIMx == TIM7) irq = TIM7_IRQn;
else if (TIMx == TIM8) irq = TIM8_UP_TIM13_IRQn;
else if (TIMx == TIM12) irq = TIM8_BRK_TIM12_IRQn;
else if (TIMx == TIM13) irq = TIM8_UP_TIM13_IRQn;
else if (TIMx == TIM14) irq = TIM8_TRG_COM_TIM14_IRQn;
else if (TIMx == TIM15) irq = TIM15_IRQn;
else if (TIMx == TIM16) irq = TIM16_IRQn;
else if (TIMx == TIM17) irq = TIM17_IRQn;
else
{
Error_Handler(__FILE__, __LINE__);
}
HAL_NVIC_DisableIRQ((IRQn_Type)irq);
}
return;
}
/* 使能TIM时钟 */
bsp_RCC_TIM_Enable(TIMx);

View File

@ -330,7 +330,7 @@ void bsp_StartTimer(uint8_t _id, uint32_t _period)
* : bsp_StartAutoTimer
* :
* : _id : ID0,TMR_COUNT-1IDID冲突
* _period : 10ms
* _period : 1ms
* :
*********************************************************************************************************
*/

View File

@ -238,6 +238,14 @@ void bsp_InitUart(void)
RS485_InitTXE(); /* 配置RS485芯片的发送使能硬件配置为推挽输出 */
}
void bsp_DeInitUart(void)
{
HAL_UART_DeInit(&(g_tUart1.huart));
HAL_UART_DeInit(&(g_tUart4.huart));
HAL_UART_DeInit(&(g_tUart7.huart));
}
/*
*********************************************************************************************************
* : ComToUart

View File

@ -51,21 +51,21 @@
*/
/*
H7-TOOL程序
...(FLM_CRC32)
19968ms, 0.00%
20894ms, 100.00%
0: 16.7M, 9M
-- PIN_DELAY_SLOW(0)
...(FLM_CRC32)
20708ms, 0.00%
21648ms, 100.00%
1: 6.2M 5.4M
2: 5.7M 5.0M
3: 5.3M 4.6M
4: 4.2M 4.3M
10: 2.94M 3.1M
20: 2.1M 2.0M
40: 1.29M 1.29M
100: 594K 594K
-- PIN_DELAY_SLOW(1)
...(FLM_CRC32)
21417ms, 0.00%
22376ms, 100.00%
200: 313K 313K
1000: 65K 65K
2000: 33.1K 33.1K
5000: 13.2K 13.2K
*/
//#define PIN_SWCLK_SET() PIN_SWCLK_TCK_SET();PIN_SWCLK_TCK_SET()
@ -130,13 +130,13 @@
if (val & 1) \
{ \
GPIOD->BSRR = GPIO_PIN_4 + (GPIO_PIN_3 << 16U); \
val >>= 1; \
val >>= 1; PIN_DELAY_S(); \
PIN_SWCLK_SET(); PIN_DELAY_S(); \
} \
else \
{ \
GPIOD->BSRR = (GPIO_PIN_4 + GPIO_PIN_3) << 16U; \
val >>= 1; \
val >>= 1; PIN_DELAY_S(); \
PIN_SWCLK_SET(); PIN_DELAY_S(); \
}
@ -212,13 +212,66 @@ uint8_t SWD_TransferFast(uint32_t request, uint32_t *data)
/* Read data */
/* armfly 优化奇偶校验算法 */
val = 0U;
#if 0
{
uint32_t buf[32];
// PD3 = CLK PD4 = DIO
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[0] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[1] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[2] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[3] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[4] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[5] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[6] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[7] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[8] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[9] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[10] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[11] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[12] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[13] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[14] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[15] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[16] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[17] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[18] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[19] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[20] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[21] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[22] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[23] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[24] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[25] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[26] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[27] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[28] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[29] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[30] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
GPIOD->BSRR = (GPIO_PIN_3 << 16U); buf[31] = GPIOD->IDR; GPIOD->BSRR = GPIO_PIN_3;
parity = 0;
for (n = 0; n < 32; n++)
{
val >>= 1;
if (buf[n] & GPIO_PIN_4)
{
val |= 0x80000000;
parity++;
}
}
//parity = GetParity(val);
}
#else
for (n = 32U; n; n--) {
SW_READ_BIT_FAST(bit); /* Read RDATA[0:31] */
val >>= 1;
val |= bit << 31;
}
parity = GetParity(val);
#endif
SW_READ_BIT_FAST(bit); /* Read Parity */

View File

@ -611,7 +611,7 @@ Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled an
- LED output pins are enabled and LEDs are turned off.
*/
extern void bsp_InitSPI2_Fast(void);
static __inline void DAP_SETUP(void)
__inline void DAP_SETUP(void)
{
// /* Enable port clock */
// __HAL_RCC_GPIOA_CLK_ENABLE();
@ -637,7 +637,9 @@ static __inline void DAP_SETUP(void)
EIO_D6_Config(ES_GPIO_OUT); /* SWCLK - <20><><EFBFBD><EFBFBD> */
EIO_D8_Config(ES_GPIO_OUT); /* SWDIO - <20><><EFBFBD><EFBFBD> */
EIO_D2_Config(ES_GPIO_OUT); /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD> */
//EIO_D2_Config(ES_GPIO_OUT); /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD> */
//DAP_SETUP
#if SPI_MODE_ENABLE == 1
bsp_InitSPI2_Fast();

View File

@ -1,3 +1,21 @@
/*
*********************************************************************************************************
*
* : lua接口API
* : lua_if.c
* : V1.0
* :
* :
*
* V1.0 2019-10-06 armfly
*
* Copyright (C), 2019-2030, www.armfly.com
*
*********************************************************************************************************
*/
#include "includes.h"
#include "lua_if.h"
#include "bsp.h"
#include "param.h"
@ -164,8 +182,8 @@ void LuaYeildHook(lua_State *_L, lua_Debug *ar)
}
}
}
if (g_MainStatus == MS_PROG_WORK)
else
//if (g_MainStatus == MS_PROG_WORK) 在其他状态按C键退出
{
uint8_t ucKeyCode;
@ -1008,6 +1026,78 @@ uint32_t lua_GetVarUint32(const char *_VarName, uint32_t _Default)
return data;
}
/*
*********************************************************************************************************
* : lua_ReadDev
* : ok, temp = read("DS18B20", 1)
* :
* :
*********************************************************************************************************
*/
static int lua_ReadDev(lua_State* L)
{
const char *device;
size_t len;
if (lua_type(L, 1) == LUA_TSTRING) /* 判断第1个参数 */
{
device = luaL_checklstring(L, 1, &len); /* 1是参数的位置 len是string的长度 */
}
if (strcmp(device, "DS18B20") == 0) /* re,temp = read("DS18B20", 0) */
{
float ftemp;
uint8_t ch;
if (lua_type(L, 2) == LUA_TNUMBER) /* 判断第2个参数, 通道 */
{
ch = luaL_checknumber(L, 2);
}
else
{
ch = 0;
}
if (DS18B20_ReadTemp(ch, &ftemp) == 1) /* 正常返回温度值 */
{
lua_pushnumber(L, 1);
lua_pushnumber(L, ftemp);
return 2;
}
else
{
lua_pushnumber(L, 0);
return 1;
}
}
return 0;
}
/*
*********************************************************************************************************
* : lua_WriteDev
* :
* :
* :
*********************************************************************************************************
*/
static int lua_WriteDev(lua_State* L)
{
const char *device;
size_t len;
if (lua_type(L, 1) == LUA_TSTRING) /* 判断第1个参数 */
{
device = luaL_checklstring(L, 1, &len); /* 1是参数的位置 len是string的长度 */
}
if (strcmp(device, "DS18B20") == 0) /* re,temp = read("DS18B20", 0) */
{
;
}
return 0;
}
/*
*********************************************************************************************************
* : lua_RegisterFunc
@ -1040,6 +1130,9 @@ static void lua_RegisterFunc(void)
lua_register(g_Lua, "get_rng", get_rng);
lua_register(g_Lua, "crc32_stm32", crc32_stm32);
/* 读写2个通用函数 */
lua_register(g_Lua, "read", lua_ReadDev);
lua_register(g_Lua, "write", lua_WriteDev);
/* 注册接口函数 */
lua_gpio_RegisterFun();

View File

@ -50,7 +50,7 @@ static int lua_PowerOnDac(lua_State* L)
{
WriteRegValue_06H(REG03_DAC_WAVE_TYPE, 0); /* 直流 */
WriteRegValue_06H(REG03_DAC_WAVE_START, 1);
return 1;
return 0;
}
/*
@ -65,7 +65,7 @@ static int lua_PowerOffDac(lua_State* L)
{
WriteRegValue_06H(REG03_DAC_WAVE_TYPE, 0); /* 直流 */
WriteRegValue_06H(REG03_DAC_WAVE_START, 0);
return 1;
return 0;
}
/*
@ -87,7 +87,7 @@ static int lua_WriteDac(lua_State* L)
WriteRegValue_06H(REG03_OUT_VOLT_DAC, value);
return 1;
return 0;
}
/*
@ -109,7 +109,7 @@ static int lua_WriteVolt(lua_State* L)
WriteRegValue_06H(REG03_OUT_VOLT_MV, value);
return 1;
return 0;
}
/*
@ -132,7 +132,7 @@ static int lua_WriteCurr(lua_State* L)
WriteRegValue_06H(REG03_OUT_CURR_UA, value);
return 1;
return 0;
}
/*
@ -154,7 +154,7 @@ static int lua_WriteTvccDac(lua_State* L)
WriteRegValue_06H(REG03_OUT_TVCC_DAC, value);
return 1;
return 0;
}
/*
@ -176,7 +176,7 @@ static int lua_WriteTvccVolt(lua_State* L)
WriteRegValue_06H(REG03_OUT_TVCC_MV, value);
return 1;
return 0;
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,11 +1,24 @@
/*
*********************************************************************************************************
*
* : lua接口SWD烧录器器
* : lua_if_swd.c
* : V1.0
* :
* :
*
* V1.0 2019-10-06 armfly
*
* Copyright (C), 2019-2030, www.armfly.com
*
*********************************************************************************************************
*/
#include "includes.h"
#include "lauxlib.h"
#include "lualib.h"
#include "time.h"
#include "lua_if.h"
#include "bsp.h"
#include "elf_file.h"
#include "file_lib.h"
#include "prog_if.h"
#include "target_reset.h"
#include "target_config.h"
#include "swd_host.h"
@ -20,7 +33,7 @@
#include "debug_cm.h"
#include "n76e003_flash.h"
#include "cx32_isp.h"
#include "w25q_flash.h"
/* 为了避免和DAP驱动中的函数混淆本模块函数名前缀用 h7swd */
@ -240,9 +253,9 @@ static int h7swd_Init(lua_State* L)
N76E_EnterIAP(); /* 进入IAP状态 */
}
else
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
;
W25Q_InitHard();
}
return 0;
@ -258,44 +271,70 @@ static int h7swd_Init(lua_State* L)
*/
static int h7swd_ReadID(lua_State* L)
{
uint32_t id;
uint32_t id_buf[4];
// uint32_t id;
// uint32_t id_buf[4];
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
{
if (MUL_swd_read_idcode(id_buf) == 0)
{
lua_pushnumber(L, 0); /* 出错 */
}
else
{
lua_pushnumber(L, id); /* 成功,返回ID */
}
}
else
{
if (swd_read_idcode(&id) == 0)
{
lua_pushnumber(L, 0); /* 出错 */
}
else
{
lua_pushnumber(L, id); /* 成功,返回ID */
}
}
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
id = 0x00000800; /* STM8没有ID, 填一个固定值 */
lua_pushnumber(L, id); /* 成功,返回ID */
}
else
{
id = 0;
lua_pushnumber(L, 0); /* 出错 */
}
// if (g_tProg.ChipType == CHIP_SWD_ARM)
// {
// if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
// {
// if (MUL_swd_read_idcode(id_buf) == 0)
// {
// lua_pushnumber(L, 0); /* 出错 */
// }
// else
// {
// lua_pushnumber(L, id); /* 成功,返回ID */
// }
// }
// else
// {
// if (swd_read_idcode(&id) == 0)
// {
// lua_pushnumber(L, 0); /* 出错 */
// }
// else
// {
// lua_pushnumber(L, id); /* 成功,返回ID */
// }
// }
// }
// else if (g_tProg.ChipType == CHIP_SWIM_STM8)
// {
// id = 0x00000800; /* STM8没有ID, 填一个固定值 */
// lua_pushnumber(L, id); /* 成功,返回ID */
// }
// else if (g_tProg.ChipType == CHIP_SPI_FLASH)
// {
// W25Q_DetectIC(id_buf);
// if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
// {
// if (MUL_swd_read_idcode(id_buf) == 0)
// {
// lua_pushnumber(L, 0); /* 出错 */
// }
// else
// {
// lua_pushnumber(L, id); /* 成功,返回ID */
// }
// }
// else
// {
// if (swd_read_idcode(&id) == 0)
// {
// lua_pushnumber(L, 0); /* 出错 */
// }
// else
// {
// lua_pushnumber(L, id); /* 成功,返回ID */
// }
// }
// }
// else
// {
// id = 0;
// lua_pushnumber(L, 0); /* 出错 */
// }
return 1;
}
@ -480,6 +519,41 @@ static int h7swd_ReadMemory(lua_State* L)
lua_pushlstring(L, (char *)s_lua_read_buf, num);
return 2;
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
{
if (W25Q_ReadBuf(addr, s_lua_read_buf, num) == 0)
{
lua_pushnumber(L, 0); /* 出错 */
}
else
{
lua_pushnumber(L, 1); /* 成功 */
}
lua_pushlstring(L, (char *)s_lua_read_buf, num);
lua_pushlstring(L, (char *)(s_lua_read_buf + num), num);
lua_pushlstring(L, (char *)(s_lua_read_buf + 2 * num), num);
lua_pushlstring(L, (char *)(s_lua_read_buf + 3 * num), num);
return 5;
}
else
{
if (W25Q_ReadBuf(addr, s_lua_read_buf, num) == 0)
{
lua_pushnumber(L, 0); /* 出错 */
}
else
{
lua_pushnumber(L, 1); /* 成功 */
}
lua_pushlstring(L, (char *)s_lua_read_buf, num);
return 2;
}
}
else
{
lua_pushnumber(L, 0); /* 出错 */
@ -1116,7 +1190,7 @@ static int h7_LoadAlgoFile(lua_State* L)
* : 0 1
*********************************************************************************************************
*/
uint16_t PG_N76E_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndAddr, uint32_t _CtrlByte,
extern uint16_t PG_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndAddr, uint32_t _CtrlByte,
uint32_t _FileIndex, const char *_AlgoName);
static int h7_ProgFile(lua_State* L)
{
@ -1217,7 +1291,18 @@ static int h7_ProgFile(lua_State* L)
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
if (PG_N76E_ProgFile(file_name, FlashAddr, EndAddr, CtrlByte, FileIndex, AlgoName) == 0)
if (PG_ProgFile(file_name, FlashAddr, EndAddr, CtrlByte, FileIndex, AlgoName) == 0)
{
lua_pushnumber(L, 1); /*OK */
}
else
{
lua_pushnumber(L, 0); /* 出错 */
}
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
if (PG_ProgFile(file_name, FlashAddr, EndAddr, CtrlByte, FileIndex, AlgoName) == 0)
{
lua_pushnumber(L, 1); /*OK */
}
@ -1470,6 +1555,27 @@ static int h7_DetectIC(lua_State* L)
lua_pushnumber(L, id); /* 成功,返回ID */
return 1;
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
uint32_t id[4];
W25Q_InitHard();
W25Q_DetectIC(id);
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
{
lua_pushnumber(L, id[0]); /* 成功,返回ID */
lua_pushnumber(L, id[1]); /* 成功,返回ID */
lua_pushnumber(L, id[2]); /* 成功,返回ID */
lua_pushnumber(L, id[3]); /* 成功,返回ID */
return 4;
}
else
{
lua_pushnumber(L, id[0]); /* 成功,返回ID */
return 1;
}
}
lua_pushnumber(L, -1); /* 失败 */
return 1;
}
@ -2021,6 +2127,17 @@ static int h7_EraseSector(lua_State* L)
lua_pushnumber(L, 1); /* 成功 */
}
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
if (W25Q_EraseSector(FlashAddr) == 0)
{
lua_pushnumber(L, 0); /* 出错 */
}
else
{
lua_pushnumber(L, 1); /* 成功 */
}
}
else
{
lua_pushnumber(L, 0); /* 出错 */

View File

@ -38,7 +38,7 @@
#include "lwip_user.h"
#include "net_udp.h"
static uint8_t s_init_lwip_ok = 0;
static uint8_t s_lwip_status = 0;
struct netif gnetif;
@ -72,34 +72,6 @@ static void Netif_Config(void)
#endif
}
/*
*********************************************************************************************************
* : lwip_start
* : lwip_start, g_tParam.lwip_ip, g_tParam.lwip_net_mask,
* g_tParam.lwip_gateway
* :
* :
*********************************************************************************************************
*/
void lwip_start(void)
{
/* Initialize the LwIP stack */
lwip_init();
/* Configure the Network interface */
Netif_Config();
/* Http webserver Init */
http_server_init();
/* tcp server init */
tcp_echoserver_init();
udp_server_init(); /* 开启UDP监听 */
s_init_lwip_ok = 1;
}
/*
*********************************************************************************************************
* : lwip_pro
@ -110,11 +82,32 @@ void lwip_start(void)
*/
void lwip_pro(void)
{
if (s_init_lwip_ok == 0)
switch (s_lwip_status)
{
return;
}
case 0:
lwip_init(); /* Initialize the LwIP stack */
s_lwip_status++;
break;
case 1:
/* Configure the Network interface */
Netif_Config();
s_lwip_status++;
break;
case 2:
/* Http webserver Init */
http_server_init();
/* tcp server init */
tcp_echoserver_init();
udp_server_init(); /* 开启UDP监听 */
s_lwip_status = 10;
break;
case 10:
/* Read a received packet from the Ethernet buffers and send it
to the lwIP for handling */
ethernetif_input(&gnetif);
@ -129,6 +122,8 @@ void lwip_pro(void)
#if LWIP_DHCP
DHCP_Periodic_Handle(&gnetif);
#endif
break;
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -169,8 +169,8 @@ AI : 示波器 CH1 均值, mV单位
#define REG03_DSO_MEASURE_MODE 0x01FF /* 1表示电流检测模式 */
#define REG03_CH1_DC 0x0200 /* CH1通道AC/DC耦合切换 1表示DC */
#define REG03_CH2_DC 0x0201 /* CH2通道AC/DC耦合切换 */
#define REG03_CH1_GAIN 0x0202 /* CH1通道增益切换0-3 */
#define REG03_CH2_GAIN 0x0203 /* CH2通道增益切换0-3 */
#define REG03_CH1_GAIN 0x0202 /* CH1通道增益切换0-7 */
#define REG03_CH2_GAIN 0x0203 /* CH2通道增益切换0-7 */
#define REG03_CH1_OFFSET 0x0204 /* CH1通道直流偏值0-2500mV 保留,不支持) */
#define REG03_CH2_OFFSET 0x0205 /* CH2通道直流偏值0-2500mV 保留,不支持) */
#define REG03_DSO_FREQ_ID 0x0206 /* 示波器采样频率档位 */

View File

@ -42,40 +42,48 @@ uint8_t ReadRegValue_03H(uint16_t reg_addr, uint16_t *reg_value)
{
case REG03_NET_CPU_ID0: /* MCU序号只读 */
case REG03_DEV_ID0:
case REG03_BOOT_CPU_ID0:
value = g_tVar.CPU_Sn[0];
break;
case REG03_NET_CPU_ID1:
case REG03_DEV_ID1:
case REG03_BOOT_CPU_ID1:
value = g_tVar.CPU_Sn[0] >> 16;
break;
case REG03_NET_CPU_ID2:
case REG03_DEV_ID2:
case REG03_BOOT_CPU_ID2:
value = g_tVar.CPU_Sn[1];
break;
case REG03_NET_CPU_ID3:
case REG03_DEV_ID3:
case REG03_BOOT_CPU_ID3:
value = g_tVar.CPU_Sn[1] >> 16;
break;
case REG03_NET_CPU_ID4:
case REG03_DEV_ID4:
case REG03_BOOT_CPU_ID4:
value = g_tVar.CPU_Sn[2];
break;
case REG03_NET_CPU_ID5:
case REG03_DEV_ID5:
case REG03_BOOT_CPU_ID5:
value = g_tVar.CPU_Sn[2] >> 16;
break;
case REG03_NET_HARD_VER:
case REG03_HARD_MODEL:
case REG03_BOOT_HARD_VER:
value = HARD_MODEL;
break;
case REG03_BOOT_VER:
case REG03_BOOT_SOFT_VER:
value = BOOT_VERSION;
break;

View File

@ -28,6 +28,7 @@
#include "stm8_flash.h"
#include "stm8_swim.h"
#include "n76e003_flash.h"
#include "w25q_flash.h"
/* 64H帧子功能码定义 */
enum
@ -42,8 +43,8 @@ static void MODS66_WriteMem(void);
/*
*********************************************************************************************************
* : MODS_64H
* :
* : MODS_66H
* : SWD内存读写操作通信接
* :
* :
*********************************************************************************************************
@ -239,9 +240,23 @@ static void MODS66_ReadMem(void)
memcpy(&g_tModS.TxBuf[g_tModS.TxCount], s_lua_read_buf, package_len);
g_tModS.TxCount += package_len;
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
if (W25Q_ReadBuf(offset_addr, s_lua_read_buf, package_len) == 0)
{
g_tModS.TxBuf[g_tModS.TxCount++] = 0x01; /* 出错 */
}
else
{
;
g_tModS.TxBuf[g_tModS.TxCount++] = 0x00; /* 执行结果 00 */
}
memcpy(&g_tModS.TxBuf[g_tModS.TxCount], s_lua_read_buf, package_len);
g_tModS.TxCount += package_len;
}
else
{
g_tModS.TxBuf[g_tModS.TxCount++] = 0x01; /* 出错 */
}
}

View File

@ -1,10 +1,10 @@
/*
*********************************************************************************************************
*
* : N76E003芯片编程模块
* : n76e_prog_file.c
* :
* : pg_prog_file.c
* : V1.0
* : N76E003芯
* :
*
* :
*
@ -31,7 +31,7 @@ extern const program_target_t flash_algo;
/*
*********************************************************************************************************
* : PG_N76E_ProgFile
* : PG_ProgFile
* : flash lua程序调用
* : _Path :
* _FlashAddr : flash起始地址
@ -42,7 +42,7 @@ extern const program_target_t flash_algo;
* : 0 = ok,
*********************************************************************************************************
*/
uint16_t PG_N76E_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndAddr, uint32_t _CtrlByte,
uint16_t PG_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndAddr, uint32_t _CtrlByte,
uint32_t _FileIndex, const char *_AlgoName)
{
char path[256];
@ -55,6 +55,7 @@ uint16_t PG_N76E_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndA
// uint8_t fBlankChip = 0;
// uint32_t BlockSize;
uint32_t CheckLen; /* 实际扫描的空间大小 */
uint8_t EmptyValue; /* 空片的值 */
/* 传入的文件名是相对路径 */
if (strlen(_Path) + strlen(PROG_USER_DIR) > sizeof(path))
@ -125,6 +126,19 @@ uint16_t PG_N76E_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndA
}
}
if (g_tProg.ChipType == CHIP_SWIM_STM8 || g_tProg.ChipType == CHIP_NUVOTON_8051)
{
EmptyValue = 0x00;
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
EmptyValue = 0xFF;
}
else
{
EmptyValue = 0x00;
}
/*
4bit表示擦除模式 0 1 2
4bit表示查空 0 1
@ -169,6 +183,9 @@ uint16_t PG_N76E_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndA
{
uint32_t addr;
uint32_t endAddr;
uint32_t SectorSize;
SectorSize = PG_GetSectorSize(_AlgoName, addr);
endAddr = _FlashAddr + FileLen;
if (endAddr > _EndAddr)
@ -196,12 +213,13 @@ uint16_t PG_N76E_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndA
float percent;
percent = addr - _FlashAddr; /* 已擦除大小 */
percent = percent / (endAddr - _FlashAddr);
percent = 100 * percent / (endAddr - _FlashAddr);
PG_PrintPercent(percent, addr); /* 显示100% */
}
addr += PG_GetSectorSize(_AlgoName, addr);
addr += SectorSize;
}
PG_PrintPercent(100.0, addr); /* 显示100% */
}
else if (EraseMode == 1) /* 1:整片擦除 */
{
@ -284,7 +302,7 @@ uint16_t PG_N76E_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndA
/* V1.11 修正bug : 烧写非整数倍PageSize的文件失败 */
if (bytes % PageSize)
{
memset(&FsReadBuf[bytes], 0x00 ,PageSize - (bytes % PageSize)); /* 填充空值 00 */
memset(&FsReadBuf[bytes], EmptyValue ,PageSize - (bytes % PageSize)); /* 填充空值 00 or FF */
bytes = ((bytes + PageSize - 1) / PageSize) * PageSize;
}
@ -306,8 +324,8 @@ uint16_t PG_N76E_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndA
FileOffset += PageSize;
/* 进度指示 - 每2KB刷新一次 */
if ((FileOffset % 2048) == 0 || (bytes < 2048 && (FileOffset % 512) == 0))
/* 进度指示 - 每4KB刷新一次 */
if ((FileOffset % 8192) == 0 || (bytes < 8192 && (FileOffset % 512) == 0))
{
float percent;
@ -394,6 +412,11 @@ uint16_t PG_N76E_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndA
PageSize = sizeof(FsReadBuf);
}
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
{
PageSize = PageSize / 4;
}
if (PageSize >= DeviceSize)
{
PageSize = DeviceSize;
@ -437,6 +460,7 @@ uint16_t PG_N76E_ProgFile(const char *_Path, uint32_t _FlashAddr, uint32_t _EndA
}
/* 进度指示 */
if ((FileOffset % 8192) == 0 || (bytes < 8192 && (FileOffset % 512) == 0))
{
float percent = -1;

View File

@ -14,19 +14,17 @@
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "param.h"
#include "file_lib.h"
#include "lua_if.h"
#include "prog_if.h"
#include "includes.h"
#include "swd_host.h"
#include "swd_flash.h"
#include "elf_file.h"
#include "main.h"
#include "stm8_flash.h"
#include "n76e003_flash.h"
#include "SW_DP_Multi.h"
#include "swd_host_multi.h"
#include "w25q_flash.h"
extern const program_target_t flash_algo;
@ -216,6 +214,29 @@ void PG_ReloadLuaVar(void)
{
h7swim_ReadLuaVar(); /* 读取LUA中的全局变量 */
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
// uint32_t Capacity; /* 芯片容量 */
// uint32_t SectorSize; /* 扇区大小 */
// uint32_t EraseSectorCmd; /* 扇区擦除指令 */
// uint32_t EraseSectorTimeout; /* 擦除扇区超时 ms */
// uint32_t EraseChipTimeout; /* 擦除整片超时 ms */
// uint32_t ProgPageTimeout; /* 编程page超时 */
// uint8_t AutoAddrInc; /* AAI模式写 */
g_tW25Q.Capacity = lua_GetVarUint32("FLASH_SIZE", 0);
g_tW25Q.SectorSize = lua_GetVarUint32("SECTOR_SIZE", 4096);
g_tW25Q.EraseSectorCmd = lua_GetVarUint32("ERASE_SECTOR_CMD", 0x20);
g_tW25Q.EraseSectorTimeout = lua_GetVarUint32("ERASE_SECTOR_TIMEOUT", 2 * 1000);
g_tW25Q.EraseChipTimeout = lua_GetVarUint32("ERASE_CHIP_TIMEOUT", 400 * 1000);
g_tW25Q.ProgPageTimeout = 100; /* 100ms */
g_tW25Q.AutoAddrInc = lua_GetVarUint32("PROG_AAI", 0);
g_tW25Q.ReadMode = lua_GetVarUint32("READ_MODE", 0);
g_tW25Q.ReadIDCmd = lua_GetVarUint32("READ_ID_CMD", 0x9F);
g_tW25Q.EraseChipCmd = lua_GetVarUint32("ERASE_CHIP_CMD", 0xC7);
g_tW25Q.UnlockCmd = lua_GetVarUint32("UNLOCK_CMD", 0x00);
}
}
/*
@ -522,6 +543,11 @@ uint8_t PG_FixDataIsDiff(void)
return 0;
}
/*
*********************************************************************************************************
* . pg_prog_file.c
*********************************************************************************************************
*/
/*
*********************************************************************************************************
@ -547,6 +573,10 @@ uint32_t PG_GetSectorSize(const char *_Algo, uint32_t _Addr)
{
sz = 128;
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
sz = lua_GetVarUint32("SECTOR_SIZE", 4*1024);
}
return sz;
}
@ -560,6 +590,23 @@ uint32_t PG_GetSectorSize(const char *_Algo, uint32_t _Addr)
*/
uint8_t PG_EraseSector(const char *_Algo, uint32_t _Addr)
{
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
/* ARM不用这个文件 */;
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
/* STM8都是整片擦除 */;
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
/* 选择整片擦除 */
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
W25Q_EraseSector(_Addr);
}
return 1;
}
@ -587,6 +634,10 @@ uint32_t PG_GetPageSize(const char *_Algo)
{
sz = 32;
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
sz = lua_GetVarUint32("FLASH_PAGE_SIZE", 1024);;
}
return sz;
}
@ -640,7 +691,10 @@ uint32_t PG_GetDeviceAddr(const char *_Algo)
addr = 0;
}
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
addr = lua_GetVarUint32("FLASH_ADDRESS", 0);
}
return addr;
}
@ -694,7 +748,10 @@ uint32_t PG_GetDeviceSize(const char *_Algo)
sz = 1024;
}
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
sz = lua_GetVarUint32("FLASH_SIZE", 0);
}
return sz;
}
@ -720,7 +777,10 @@ uint8_t PG_EraseChip(void)
{
N76E_EraseChip();
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
W25Q_EraseChip();
}
return 1;
}
@ -746,7 +806,10 @@ uint8_t PG_CheckBlank(const char *_Algo, uint32_t _Addr, uint32_t _Size)
{
;
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
;
}
return 0;
}
@ -776,7 +839,10 @@ uint8_t PG_ProgramBuf(const char *_Algo, uint32_t _FlashAddr, uint8_t *_Buff, ui
{
re = N76E_FLASH_ProgramBuf(_FlashAddr, _Buff, _Size);
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
re = W25Q_FLASH_ProgramBuf(_FlashAddr, _Buff, _Size);
}
return re;
}
@ -806,6 +872,10 @@ uint8_t PG_ReadBuf(const char *_Algo, uint32_t _FlashAddr, uint8_t *_Buff, uint3
{
re = N76E_ReadBuf(_FlashAddr, _Buff, _Size);
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
re = W25Q_ReadBuf(_FlashAddr, _Buff, _Size);
}
return re;
}

View File

@ -67,6 +67,8 @@ typedef struct
uint8_t AbortOnError; /* 多路模式0表示出错时继续烧录OK的芯片 1表示出错后立刻同时终止 */
uint8_t ChNum; /* 通道个数 */
}OFFLINE_PROG_T;
/* lua脚本fix_data_begin()返回一个table用于通知C程序哪些内存地址需要填充数据 */

1493
User/programmer/w25q_flash.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
/*
*********************************************************************************************************
*
* : SPI Flash编程驱动
* : w25q_flash.h
*
*********************************************************************************************************
*/
#ifndef _W25Q_FLASH_H
#define _W25Q_FLASH_H
typedef struct
{
uint32_t Capacity; /* 芯片容量 */
uint32_t SectorSize; /* 扇区大小 */
uint32_t EraseSectorCmd; /* 扇区擦除指令 */
uint32_t EraseSectorTimeout; /* 擦除扇区超时 ms */
uint32_t EraseChipCmd; /* 全片擦除指令 */
uint32_t EraseChipTimeout; /* 擦除整片超时 ms */
uint32_t ProgPageTimeout; /* 编程page超时 */
uint8_t AutoAddrInc; /* AAI模式写 */
uint8_t ReadMode; /* 0表示单线1表示单线MOSI,双线MISO2表示双线MOSI,双线MISO */
uint8_t ReadIDCmd; /* 大多数是0x9F SST是0x90 */
uint8_t UnlockCmd; /* 解锁指令 */
}W25Q_T;
void W25Q_InitHard(void);
uint8_t W25Q_DetectIC(uint32_t *_id);
uint8_t W25Q_EraseSector(uint32_t _addr);
uint8_t W25Q_EraseChip(void);
uint8_t W25Q_FLASH_ProgramBuf(uint32_t _FlashAddr, uint8_t *_Buff, uint32_t _Size);
uint8_t W25Q_ReadBuf(uint32_t _Addr, uint8_t *_Buf, uint16_t _Len);
extern W25Q_T g_tW25Q;
#endif

View File

@ -38,6 +38,24 @@ void usbd_Init(void)
//tusb_init();
}
/*
*********************************************************************************************************
* : usbd_UnInit
* : 退USB协议栈
* :
* :
*********************************************************************************************************
*/
void usbd_UnInit(void)
{
if (USBD_Device.dev_config > 0)
{
USBD_Stop(&USBD_Device);
USBD_DeInit(&USBD_Device);
}
}
/*
*********************************************************************************************************
* : usbd_OpenCDC

View File

@ -18,6 +18,7 @@
#include "usbd_cdc_interface.h"
void usbd_Init(void);
void usbd_UnInit(void);
void usbd_OpenCDC(uint8_t _com);
void usbd_OpenCDC2(uint8_t _com);
void usbd_CloseCDC(void);

View File

@ -475,12 +475,6 @@ static void TIM_Config(void)
/* ## Enable TIM peripherals Clock ####################################### */
TIMx_CLK_ENABLE();
/* ## Configure the NVIC for TIMx ######################################## */
/* Set Interrupt Group Priority */
HAL_NVIC_SetPriority(TIMx_IRQn, 6, 0);
/* Enable the TIMx global Interrupt */
HAL_NVIC_EnableIRQ(TIMx_IRQn);
/* Set TIMx instance */
TimHandle.Instance = TIMx;
@ -507,6 +501,14 @@ static void TIM_Config(void)
/* Starting Error */
ERROR_HANDLER();
}
/* 2020-11-27 V1.36 移动到后面在前面从DAP跳转时会死机 */
/* ## Configure the NVIC for TIMx ######################################## */
/* Set Interrupt Group Priority */
HAL_NVIC_SetPriority(TIMx_IRQn, 6, 0);
/* Enable the TIMx global Interrupt */
HAL_NVIC_EnableIRQ(TIMx_IRQn);
}
/*