Merge pull request #11 from armfly/armfly

+1.增加微型数控电源。
This commit is contained in:
armfly 2019-11-04 01:13:36 +08:00 committed by GitHub
commit 8ef69693ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
75 changed files with 1046 additions and 17815 deletions

View File

@ -3,6 +3,11 @@
2. usbd_cdc_interface.h 文件中的宏定义移到c文件中编译过但是运行异常奇怪。
3. qspi_read(), lua连续读取存在问题. 2019-07-07
----------------------------------------------------------------------------
2019-11-04 V1.03b
1.增加微型数控电源。
2.整理bsp_timer.c, bso_tim_pwm.c文件
----------------------------------------------------------------------------
2019-11-03 V1.03a
1.GBK->UTF-8

File diff suppressed because it is too large Load Diff

View File

@ -452,6 +452,11 @@
<FileType>5</FileType>
<FilePath>..\..\User\app\inc\main.h</FilePath>
</File>
<File>
<FileName>status_tvcc_power.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\app\src\status_tvcc_power.c</FilePath>
</File>
</Files>
</Group>
<Group>

BIN
Project/h7_tool_app.bin Normal file

Binary file not shown.

View File

@ -14,23 +14,24 @@
#include "param.h"
#include "modbus_register.h"
#define SWITCH_BEEP_ENABLE 1 /* 1表示切换主状态时蜂鸣器鸣叫 */
#define SWITCH_BEEP_ENABLE 1 /* 1表示切换主状态时蜂鸣器鸣叫 */
/* 主程序状态字定义, MS = Main Status */
enum
{
MS_LINK_MODE = 0, /* 联机状态 */
MS_LINK_MODE = 0, /* 联机状态 */
MS_SYSTEM_SET, /* 系统设置 */
MS_HARD_INFO, /* 关于-硬件信息 */
MS_ESP32_TEST, /* ESP32模块升级状态 */
MS_USB_UART1, /* 虚拟串口状态。RS232 RS485 TTL-UART */
MS_SYSTEM_SET, /* 系统设置 */
MS_HARD_INFO, /* 关于-硬件信息 */
MS_ESP32_TEST, /* ESP32模块升级状态 */
MS_USB_UART1, /* 虚拟串口状态。RS232 RS485 TTL-UART */
MS_PROGRAMMER, /* 脱机下载器 */
MS_VOLTAGE_METER, /* 电压表 */
MS_CURRENT_METER, /* 高侧电流表 */
MS_TEMP_METER, /* 温度表 */
MS_RESISTOR_METER, /* 电阻表 */
MS_PROGRAMMER, /* 脱机下载器 */
MS_VOLTAGE_METER, /* 电压表 */
MS_CURRENT_METER, /* 高侧电流表 */
MS_TEMP_METER, /* 温度表 */
MS_RESISTOR_METER, /* 电阻表 */
MS_TVCC_POWER, /* 微型数控电源 */
};
void DispHeader(char *_str);

View File

@ -1,23 +0,0 @@
/*
*********************************************************************************************************
*
* : BMP文件处理模块
* : bmp_file.h
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __BMP_FILE_H
#define __BMP_FILE_H
#include "bsp.h"
void SaveScreenToBmp(uint16_t _index);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,31 +0,0 @@
/*
*********************************************************************************************************
*
* : CAN网络演示程序
* : can_network.h
* : V1.0
* :
* :
*
* v1.0 2011-09-01 armfly ST固件库V3.5.0
*
* Copyright (C), 2010-2011, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef _CAN_NETWORK_H
#define _CAN_NETWORK_H
void can_Init(void);
void can_DeInit(void);
/* 应用层协议 */
void can_LedOn(uint8_t _addr, uint8_t _led_no);
void can_LedOff(uint8_t _addr, uint8_t _led_no);
void can_BeepCtrl(uint8_t _addr, uint8_t _cmd);
void can1_Analyze(void);
void can2_Analyze(void);
#endif

View File

@ -1,21 +0,0 @@
/*
*********************************************************************************************************
*
* : AD7606数据采集模块测试程序
* : ad7606_test.h
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __AD7606_TEST_H
#define __AD7606_TEST_H
void TestAD7606(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,21 +0,0 @@
/*
*********************************************************************************************************
*
* : AD7705
* : ad7705_test.h
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __AD7705_TEST_H
#define __AD7705_TEST_H
void TestAD7705(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : AD9833测试界面
* : form_ad9833.h
* : V1.0
* :
*
* Copyright (C), 2015-2016, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __FORM_AD9833_H
#define __FORM_AD9833_H
void FormMain9833(void);
#endif

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : ADS1256数据采集模块测试程序
* : ads1256_test.h
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __ADS1256_TEST_H
#define __ADS1256_TEST_H
void TestADS1256(void);
#endif

View File

@ -1,46 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : audio_rec.h
* : V1.0
* :
* :
*
* v1.0 2011-09-08 armfly ST固件库V3.5.0
*
* Copyright (C), 2010-2011, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __audio_rec_H
#define __audio_rec_H
#include <inttypes.h>
/* 录音机状态 */
enum
{
STA_IDLE = 0, /* 待机状态 */
STA_RECORDING, /* 录音状态 */
STA_PLAYING, /* 放音状态 */
STA_STOP_I2S, /* 临时状态主程序通知I2S中断服务程序准备停止 */
};
typedef struct
{
uint8_t ucFmtIdx; /* 音频格式:标准、位长、采样频率 */
uint8_t ucVolume; /* 当前放音音量 */
uint8_t ucMicGain; /* 当前MIC增益 */
int16_t *pAudio; /* 定义一个指针用于访问外部SRAM */
uint32_t uiCursor; /* 播放位置 */
uint8_t ucSpkOutEn; /* 放音时,是否打开扬声器 */
uint8_t ucStatus; /* 录音机状态0表示待机1表示录音中2表示播放中 */
} REC_T;
void RecorderDemo(void);
#endif

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : camera_test.c
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __CAMERA_TEST_H
#define __CAMERA_TEST_H
void TestCamera(void);
#endif

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : CAN网络测试界面
* : form_can.h
* : V1.0
* :
*
* Copyright (C), 2015-2016, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __FORM_CAN_H
#define __FORM_CAN_H
void FormMainCAN(void);
#endif

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : DAC8501测试界面
* : form_dac8501.h
* : V1.0
* :
*
* Copyright (C), 2014-2015, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __FORM_DAC8501_H
#define __FORM_DAC8501_H
void FormMainDAC8501(void);
#endif

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : DAC8562测试界面
* : form_dac8562.h
* : V1.0
* :
*
* Copyright (C), 2014-2015, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __FORM_DAC8562_H
#define __FORM_DAC8562_H
void FormMainDAC8562(void);
#endif

View File

@ -1,85 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : form_dso.c
*
* Copyright (C), 2015-2016, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __FORM_DSO_H
#define __FORM_DSO_H
#define SAMPLE_COUNT (1 * 1024) /* 采样深度,即最大样本个数 */
/*
*/
typedef struct
{
// uint16_t Ch1Buf[SAMPLE_COUNT]; /* 通道1数据缓冲区 */
// uint16_t Ch2Buf[SAMPLE_COUNT]; /* 通道2数据缓冲区 */
uint16_t *Ch1Buf; /* 通道1数据缓冲区 */
uint16_t *Ch2Buf; /* 通道2数据缓冲区 */
uint32_t TimeBaseIdHold; /* 暂停时的时基 */
uint32_t TimeBaseId; /* 时基索引, 查表可得到 us单位的时基 */
uint32_t SampleFreq; /* 采样频率单位Hz */
uint32_t TimeBase; /* 时基 查表可得到 us单位的时基 */
uint8_t Ch1AttId; /* CH1 衰减倍数索引 */
uint8_t Ch2AttId; /* CH2 衰减倍数索引 */
int32_t Ch1Attenuation; /* 波形1幅度衰减系数(原始数据x10后再除以这个数) */
int32_t Ch2Attenuation; /* 波形2幅度衰减系数(原始数据x10后再除以这个数) */
uint16_t Ch1VScale; /* 通道1垂直分度值mV单位 */
uint16_t Ch2VScale; /* 通道2垂直分度值mV单位 */
uint32_t TriggerLevel; /* 触发电平(ADC采样结果比较值) */
uint32_t TriggerUpEdge; /* 1表示触发模式上跳沿0表示下跳沿 */
int16_t Ch1VOffset; /* 通道1 GND线位置, 可以为负数 */
int16_t Ch2VOffset; /* 通道1 GND线位置, 可以为负数 */
uint8_t ActiveCH; /* 当前焦点通道 1表示CH1, 2表示CH2 */
uint8_t AdjustMode; /* 当前调节模式0表示调节幅度1表示调节偏移 */
/* 使用2个缓冲区完成波形的擦除和重现 */
uint16_t xCh1Buf1[310]; /* 波形数据,坐标数组 */
uint16_t yCh1Buf1[310]; /* 波形数据,坐标数组 */
uint16_t xCh1Buf2[310]; /* 波形数据,坐标数组 */
uint16_t yCh1Buf2[310]; /* 波形数据,坐标数组 */
uint16_t xCh2Buf1[310]; /* 波形数据,坐标数组 */
uint16_t yCh2Buf1[310]; /* 波形数据,坐标数组 */
uint16_t xCh2Buf2[310]; /* 波形数据,坐标数组 */
uint16_t yCh2Buf2[310]; /* 波形数据,坐标数组 */
uint8_t BufUsed; /* 0表示当前用Buf1 1表示用Buf2 */
uint8_t HoldEn; /* 波形采集暂停标志 1表示暂停0表示运行 */
uint8_t CH1_DC; /* 通道1 AC/DC的设置 */
uint8_t CH2_DC; /* 通道1 AC/DC的设置 */
uint8_t CH1_Gain; /* 通道1 增益的设置 */
uint8_t CH2_Gain; /* 通道1 增益的设置 */
} DSO_T;
/*
*/
typedef enum
{
SR_1K = 0, /* */
} SAMPLE_RATE_E;
void InitDSO(void);
void SetSampRate(uint32_t freq);
void DsoMain(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,55 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : fm_radio.c
* : V1.0
*
* Copyright (C), 2012-2013, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef _FM_RADIO_H_
#define _FM_RADIO_H_
#define FM_RX 0
#define AM_RX 1
#define SI4704 4
#define SI4730 30
/*
Worldwide FM band support (64108 MHz)
Worldwide AM band support (5201710 kHz)
88-1080.1
*/
typedef struct
{
uint8_t ChipType; /* 芯片型号代码 */
uint8_t ucMode; /* AM 或 FM */
uint8_t ucListType; /* 电台列表类型。武汉地区或全国 */
uint8_t ucFMCount; /* FM 电台个数 */
uint16_t usFMList[255]; /* FM 电台列表 */
uint8_t ucIndexFM; /* 当前电台索引 */
uint8_t ucAMCount; /* FM 电台个数 */
uint16_t usAMList[128]; /* FM 电台列表 */
uint8_t ucIndexAM; /* 当前电台索引 */
uint32_t usFreq; /* 当前电台频率 */
uint8_t ucVolume; /* 音量 */
uint8_t ucSpkOutEn; /* 扬声器输出使能 */
uint8_t ucRssiEn; /* 信号质量定时刷新 使能 */
} RADIO_T;
void RadioMain(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : MG323 GPRS模块
* : gprs_test.h
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __GPRS_TEST_H
#define __GPRS_TEST_H
void TestGPRS(void);
#endif

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : GPS定位模块测试程序
* : gps_test.h
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __GPS_TEST_H
#define __GPS_TEST_H
void TestGPS(void);
#endif

View File

@ -1,21 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : hard_test.h
* : V1.0
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef _HARD_TEST_H_
#define _HARD_TEST_H_
extern void HardInfo(void);
extern void PrintfHardInfo(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,20 +0,0 @@
/*
*********************************************************************************************************
*
* : WEB服务器程序
* : http_server.h
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HTTP_SERVER_H
#define __HTTP_SERVER_H
void WebServer(void);
#endif

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : MEMS I2C ,
* : mems_test.h
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __MEMS_TEST_H
#define __MEMS_TEST_H
void TestMems(void);
#endif

View File

@ -1,41 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : reserve.h
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __MP3_PLAYER_H
#define __MP3_PLAYER_H
/* 定义一个用于MP3播放器的结构体
便
*/
typedef struct
{
uint8_t ucMuteOn; /* 0 : 静音, 1: 放音 */
uint8_t ucVolume; /* 当前音量 */
uint32_t uiProgress; /* 当前进度(已读取的字节数) */
uint8_t ucPauseEn; /* 暂停使能 */
uint8_t ListCount; /* 播放列表的歌曲个数 */
uint8_t ListIndex; /* 当前歌曲索引 */
} MP3_T;
/* 歌曲列表 */
typedef struct
{
char FileName[13]; /* 8+3结构文件名 */
uint32_t FileSize; /* 文件长度 */
char LenFileName[256]; /* 长文件名, 可以用于显示 */
} PLAY_LIST_T;
void MP3Player(void);
#endif

View File

@ -1,21 +0,0 @@
/*
*********************************************************************************************************
*
* : OLED显示器
* : oled_test.c
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __OLED_TEST_H
#define __OLED_TEST_H
void TestOLED(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : reserve.h
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __RESERVE_H
#define __RESERVE_H
void ReserveFunc(void);
#endif

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : RS485测试界面
* : form_rs485.h
* : V1.0
* :
*
* Copyright (C), 2014-2015, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __FORM_RS485_H
#define __FORM_RS485_H
void FormMainRS485(void);
#endif

View File

@ -1,20 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : touch_test.h
* : V1.0
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef _TOUCH_TEST_H_
#define _TOUCH_TEST_H_
extern void TestTouch(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : SD卡和NAND Flash模拟U盘测试程序
* : usbd_msc_test.c
* : V1.0
* :
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __USBD_MSC_TEST_H
#define __USBD_MSC_TEST_H
void TestUsbdMsc(void);
#endif

View File

@ -1,19 +0,0 @@
/*
*********************************************************************************************************
*
* : ESP8266 WIFI模块
* : wifi_test.h
* : V1.0
* :
*
* Copyright (C), 2015-2016, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __WIFI_TEST_H
#define __WIFI_TEST_H
void TestWIFI(void);
#endif

View File

@ -1,20 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : status_menu.h
* : V1.0
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef _STATUS_MENU_H_
#define _STATUS_MENU_H_
void status_MenuMain(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,20 +1,17 @@
/*
*********************************************************************************************************
*
* :
* : main_menu.h
* : V1.0
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef _MAIN_MENU_H_
#define _MAIN_MENU_H
extern uint8_t MainMenu(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
/*
*********************************************************************************************************
*
* :
* : status_tvcc_power.h
*
*********************************************************************************************************
*/
#ifndef _STATUS_TVCC_POWER_H_
#define _STATUS_TVCC_POWER_H_
void status_TVCCPower(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -26,6 +26,7 @@
#include "status_temp_meter.h"
#include "status_programmer.h"
#include "status_system_set.h"
#include "status_tvcc_power.h"
#include "wifi_if.h"
#include "ff.h"
@ -52,6 +53,7 @@ static const uint16_t StatusOrder[] =
MS_RESISTOR_METER, /* 电阻表 */
MS_CURRENT_METER, /* 高侧电流表 */
MS_TEMP_METER, /* 温度表 */
MS_TVCC_POWER, /* 微型数控电源 */
MS_PROGRAMMER, /* 脱机下载器 */
};
@ -142,6 +144,10 @@ int main(void)
status_ResistorMeter();
break;
case MS_TVCC_POWER: /* 微型电源 */
status_TVCCPower();
break;
default:
g_MainStatus = MS_LINK_MODE;
break;

View File

@ -1,226 +0,0 @@
/*
*********************************************************************************************************
*
* : BMP文件处理模块
* : bmp_file.c
* : V1.0
* : BMP文件
*
* :
*
* V1.0 2013-03-01 armfly
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#include "ff.h"
#include "bmp_file.h"
#include "ff_gen_drv.h"
#include "sd_diskio_dma.h"
/*
BMP文件的组成结构 :
bitmap-file header
bitmap-information header
/color table
bitmap-data
16256
162432
16使2
5 5绿 5 555555使15 0
5 6绿 5 565
24使3绿
32使4绿Alpha通道
*/
/* BMP文件头结构 必须添加__packed关键字表示结构体成员间紧密排列 */
__packed typedef struct
{
/* 14字节 位图文件头 */
uint16_t bfType; /* 2字节 位图类别, 在Windows中此字段的值总为'BM'*/
uint32_t bfSize; /* bmp文件大小 4字节 */
uint16_t bfReserved1; /* 保留,每字节以"00"填写 2字节 */
uint16_t bfReserved2; /* 同上 2字节 */
uint32_t bfOffBits; /* 记录图像数据区的起始位置(图象数据相对于文件头字节的偏移量)。 4字节 */
/* 40字节 位图信息头 */
uint32_t biSize; /* 4字节 本结构的大小在Windows中总为28h40字节 */
int32_t biWidth; /* 4字节 BMP图像的宽度单位像素 */
int32_t biHeight; /* 4字节 BMP图像的高度单位像素 */
uint16_t biPlanes; /* 2字节 目标设备的级别(色彩平面数)固定为1 */
uint16_t biBitCount; /* 2字节 BMP图像的色深即一个像素用多少位表示。常见的有 1 4 8 16 24 32 */
uint32_t biCompression; /* 4字节 压缩类型0(不压缩), 1(BI_RLE8), 2(BI_RLE4) */
uint32_t biSizeImage; /* 4字节 表示位图数据区域的大小以字节为单位 */
int32_t biXPelsPerMeter; /* 4字节 用象素/米表示的水平分辨率 */
int32_t biYPelsPerMeter; /* 4字节 用象素/米表示的垂直分辨率 */
uint32_t biClrUsed; /* 4字节 实际使用色彩数目,则由位数定 */
uint32_t biClrImportant; /* 4字节 图像中重要的色彩数目。0表示调色板内所有的颜色都是重要的 */
} BMP_T;
/*
*********************************************************************************************************
* : MakeBmpHeader
* : BMP文件头结构 24 RGB = 888 B前G中R后
* : _pBmp : BMP文件头结构体指针
* _Height :
* _Width :
* :
*********************************************************************************************************
*/
static void MakeBmpHeader(BMP_T *_pBmp, uint16_t _Width, uint16_t _Height)
{
/* 14字节 位图文件头 */
_pBmp->bfType = 0x4D42; /* 2字节 位图类别, 在Windows中此字段的值总为'BM'*/
_pBmp->bfSize = (_Height * _Width * 3) + 54; /* bmp文件大小 4字节 */
_pBmp->bfReserved1 = 0; /* 保留,每字节以"00"填写 2字节 */
_pBmp->bfReserved2 = 0; /* 同上 2字节 */
_pBmp->bfOffBits = 54; /* 记录图像数据区的起始位置(图象数据相对于文件头字节的偏移量)。 4字节 */
/* 40字节 位图信息头 */
_pBmp->biSize = 40; /* 4字节 本结构的大小在Windows中总为28h40字节 */
_pBmp->biWidth = _Width; /* 4字节 BMP图像的宽度单位像素 */
_pBmp->biHeight = _Height; /* 4字节 BMP图像的高度单位像素 */
_pBmp->biPlanes = 1; /* 2字节 目标设备的级别(色彩平面数)固定为1 */
_pBmp->biBitCount = 24; /* 2字节 BMP图像的色深即一个像素用多少位表示。常见的有 1 4 8 16 24 32 */
_pBmp->biCompression = 0; /* 4字节 压缩类型0(不压缩), 1(BI_RLE8), 2(BI_RLE4) */
_pBmp->biSizeImage = (_Height * _Width * 3); /* 4字节 表示位图数据区域的大小以字节为单位 */
_pBmp->biXPelsPerMeter = 0; /* 4字节 用象素/米表示的水平分辨率 */
_pBmp->biYPelsPerMeter = 0; /* 4字节 用象素/米表示的垂直分辨率 */
_pBmp->biClrUsed = 0; /* 4字节 实际使用色彩数目0则由位数定 */
_pBmp->biClrImportant = 0; /* 4字节 图像中重要的色彩数目。0表示调色板内所有的颜色都是重要的 */
}
/*
*********************************************************************************************************
* : SaveScreenToBmp
* : BMP文件头FatFS文件系统使用
* : _index :
* :
*********************************************************************************************************
*/
void SaveScreenToBmp(uint16_t _index)
{
__packed BMP_T tBmpHead;
uint8_t LineData[800 * 3]; /* 按最大 800像素宽度分配缓冲区 */
uint16_t i, j;
uint16_t pixel;
/* 本函数使用的局部变量占用较多,请修改启动文件,保证堆栈空间够用 */
FRESULT result;
FATFS fs;
FIL file;
uint32_t bw;
char path[32];
char DiskPath[4]; /* SD card logical drive path */
FATFS_LinkDriver(&SD_Driver, DiskPath);
bsp_LedOn(1); /* 点亮LED1, 表示开始截屏 */
MakeBmpHeader(&tBmpHead, LCD_GetWidth(), LCD_GetHeight()); /* 构建BMP文件头 */
/* 文件系统操作 */
{
/* 挂载文件系统 */
result = f_mount(&fs, DiskPath, 0); /* Mount a logical drive 1表示立即执行 */
if (result != FR_OK)
{
goto quit1;
}
/* 打开文件 */
sprintf(path, "%s/%dx%d_%02d.bmp", DiskPath, tBmpHead.biWidth, tBmpHead.biHeight, _index);
//result = f_opendir(&DirInf, path);
result = f_open(&file, path, FA_CREATE_ALWAYS | FA_WRITE);
if (result != FR_OK)
{
printf("创建SD卡文件%s失败 (%d)\r\n", path, result);
goto quit1;
}
}
/* 写bmp文件头 */
result = f_write(&file, (char *)&tBmpHead, 54, &bw);
if (result != FR_OK)
{
printf("%s 文件写入失败\r\n", path);
goto quit1;
}
/* 开始读取屏幕数据,并写入文件 */
for (i = 0; i < tBmpHead.biHeight; i++)
{
/* 读取1行数据到缓冲区 (注意BMP文件扫描次序从左到右从下到上。和LCD逻辑坐标是垂直翻转的) */
for (j = 0; j < tBmpHead.biWidth; j++)
{
pixel = LCD_GetPixel(j, tBmpHead.biHeight - i - 1); /* 读取屏幕1个像素 RGB = 565结构*/
#if 1
LineData[3 * j + 2] = ((pixel & 0xF800) >> 8); /* R */
LineData[3 * j + 1] = ((pixel & 0x07E0) >> 3); /* G */
LineData[3 * j + 0] = ((pixel & 0x001F) << 3); /* B */
#else
if (_index == 0)
{
LineData[3 * j + 2] = 255;
LineData[3 * j + 1] = 0;
LineData[3 * j + 0] = 0;
}
else if (_index == 1)
{
LineData[3 * j + 2] = 0;
LineData[3 * j + 1] = 255;
LineData[3 * j + 0] = 0;
}
else
{
LineData[3 * j + 2] = 0;
LineData[3 * j + 1] = 0;
LineData[3 * j + 0] = 255;
}
#endif
}
#if 0
/* 写1行数据 */
result = f_write(&file, LineData, tBmpHead.biWidth * 3, &bw);
if (result != FR_OK)
{
printf("%s 文件写入失败\r\n", path);
goto quit1;
}
#else
for (j = 0; j < tBmpHead.biWidth * 3 / 480; j++)
{
/* 写1行数据 */
result = f_write(&file, &LineData[480 * j], 480, &bw);
if (result != FR_OK)
{
printf("%s 文件写入失败\r\n", path);
goto quit1;
}
}
#endif
}
quit1:
/* 关闭文件*/
f_close(&file);
/* 卸载文件系统 */
//f_mount(ucVolume, NULL);
f_mount(NULL, DiskPath, 0);
FATFS_UnLinkDriver(DiskPath); /* 卸载驱动 */
bsp_LedOff(1); /* 关闭LED1, 表示开始截屏结束 */
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,165 +0,0 @@
/*
*********************************************************************************************************
*
* : CAN网络通信程序
* : can_network.c
* : V1.0
* : CAN节点
* :
*
* v1.0 2015-08-09 armfly ST固件库V3.5.0
*
* Copyright (C), 2015-2016, www.armfly.com
*
*********************************************************************************************************
*/
/*
:
01 01 01 --- LED指示灯点亮 120001
3(1-4)
02 00 --- 12 00 01 021
*/
#include "bsp.h"
#include "can_network.h"
uint8_t g_ucLedNo = 0; /* 点亮的LED灯序号0-3 */
/*
*********************************************************************************************************
* : can_LedOn
* : CAN1发送指令LED点亮
* : _addr 0 广
* _led_no LED指示灯序号
* :
*********************************************************************************************************
*/
void can_LedOn(uint8_t _addr, uint8_t _led_no)
{
uint8_t tx_buf[8];
tx_buf[0] = 0x01;
tx_buf[1] = 0x01; /* 点亮 */
tx_buf[2] = _led_no;
can1_SendPacket(tx_buf, 3);
}
/*
*********************************************************************************************************
* : can_LedOff
* : CAN1发送指令CAN2执行命令LED关闭
* : _addr 0 广
* _led_no LED指示灯序号
* :
*********************************************************************************************************
*/
void can_LedOff(uint8_t _addr, uint8_t _led_no)
{
uint8_t tx_buf[8];
tx_buf[0] = 0x01;
tx_buf[1] = 0x00; /* 关闭 */
tx_buf[2] = _led_no;
can1_SendPacket(tx_buf, 3);
}
/*
*********************************************************************************************************
* : can_BeepCtrl
* : CAN2发送指令CAN1执行命令
* : _addr 0 广
* _cmd LED指示灯序号
* :
*********************************************************************************************************
*/
void can_BeepCtrl(uint8_t _addr, uint8_t _cmd)
{
uint8_t tx_buf[8];
tx_buf[0] = 0x01;
tx_buf[1] = _cmd; /* 第2个字节 00 表示关闭01表示持续鸣叫 02表示鸣叫1次 */
can1_SendPacket(tx_buf, 2);
}
/*
*********************************************************************************************************
* : can_Init
* : CAN硬件
* :
* :
*********************************************************************************************************
*/
void can_Init(void)
{
bsp_InitCan1();
bsp_InitCan2();
}
/*
*********************************************************************************************************
* : can_DeInit
* : 退CAN硬件硬质CPU相关的GPIO为缺省CAN中断
* :
* :
*********************************************************************************************************
*/
void can_DeInit(void)
{
bsp_DeInitCan1();
bsp_DeInitCan2();
}
/*
*********************************************************************************************************
* : can1_Analyze
* : CAN1收到的数据.
* :
* :
*********************************************************************************************************
*/
void can1_Analyze(void)
{
if (g_Can1RxHeader.DataLength == 3)
{
if (g_Can1RxData[0] == 0x02)
{
if (g_Can1RxData[1] == 0)
{
BEEP_Stop(); /* 关闭蜂鸣器 */
}
else
{
BEEP_Start(8, 8, g_Can1RxData[1]); /* 鸣叫80ms停80ms n次 */
}
}
}
}
/*
*********************************************************************************************************
* : can2_Analyze
* : CAN2收到的数据LED动作
* :
* :
*********************************************************************************************************
*/
void can2_Analyze(void)
{
if (g_Can2RxHeader.DataLength == 2)
{
if (g_Can1RxData[0] == 0x01)
{
if (g_Can1RxData[1] == 0)
{
bsp_LedOff(g_Can1RxData[2]); /* 关闭LED */
}
else
{
bsp_LedOn(g_Can1RxData[2]); /* 打开LED */
}
}
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,354 +0,0 @@
/*
*********************************************************************************************************
*
* : AD7606数据采集模块测试程序
* : ad7606_test.c
* : V1.0
* : MPU-6050, HCM5833L, BMP085, BH1750
* :
*
* v1.0 2013-02-01 armfly
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T LabelN[8 + 2];
LABEL_T LabelV[8 + 2];
LABEL_T LabelS1;
BUTTON_T BtnRet;
} FormAD_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "AD7606数据采集模块测试程序"
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define LabelN1_X (BOX1_X + 6)
#define LabelN1_Y (BOX1_Y + 20)
#define LabelN1_TEXT "通道1 : "
#define LabelV1_X (LabelN1_X + 64)
#define LabelV1_Y LabelN1_Y
#define LabelV1_TEXT "-"
#define LabelS1_X (BOX1_X + 6)
#define LabelS1_Y (BOX1_Y + BOX1_H - 20)
#define LabelS1_TEXT "K1键切换量程, 摇杆上下键选择过采样倍率"
static void InitFormAD(void);
static void DispADInitFace(void);
static void DispADStatus(void);
FormAD_T *FormAD;
/*
*********************************************************************************************************
* : TestAD7606
* : AD7606模块
*
* :
*********************************************************************************************************
*/
void TestAD7606(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
int16_t tpX, tpY;
FormAD_T form;
uint8_t fRefresh;
FormAD = &form;
InitFormAD();
DispADInitFace();
/* 进入主程序循环体 */
bsp_StartAutoTimer(0, 500); /* 每0.5秒定时显示状态 */
bsp_InitAD7606(); /* 配置AD7606相关GPIO */
AD7606_StartRecord(1000); /* 进入自动采集模式采样频率1KHz数据存放在全局FIFO */
fRefresh = 1;
while (g_MainStatus == MS_AD7606)
{
bsp_Idle();
if (bsp_CheckTimer(0) || (fRefresh == 1))
{
fRefresh = 0;
DispADStatus();
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormAD->BtnRet.Focus = 1;
LCD_DrawButton(&FormAD->BtnRet);
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormAD->BtnRet.Focus = 0;
LCD_DrawButton(&FormAD->BtnRet);
g_MainStatus = MS_MAIN_MENU;
}
else /* 按钮失去焦点 */
{
FormAD->BtnRet.Focus = 0;
LCD_DrawButton(&FormAD->BtnRet);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键按下 切换量程 */
if (g_tAD7606.ucRange == 0)
{
AD7606_SetInputRange(1);
}
else
{
AD7606_SetInputRange(0);
}
fRefresh = 1;
break;
case KEY_DOWN_K2: /* K2键按下 */
break;
case KEY_DOWN_K3: /* K3键按下 */
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
if (g_tAD7606.ucOS < 6)
{
g_tAD7606.ucOS++;
}
AD7606_SetOS(g_tAD7606.ucOS);
fRefresh = 1;
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
if (g_tAD7606.ucOS > 0)
{
g_tAD7606.ucOS--;
}
AD7606_SetOS(g_tAD7606.ucOS);
fRefresh = 1;
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
bsp_StopTimer(0); /* 停止软件定时器 */
AD7606_StopRecord(); /* 停止自动采集 */
}
/*
*********************************************************************************************************
* : DispADStatus
* : AD7606状态
*
* :
*********************************************************************************************************
*/
static void DispADStatus(void)
{
char buf[128];
uint8_t i;
int32_t volt;
uint8_t m;
if (g_tAD7606.ucRange == 1)
{
FormAD->LabelV[8].pCaption = "±10V";
m = 2;
}
else
{
FormAD->LabelV[8].pCaption = "±5V ";
m = 1;
}
LCD_DrawLabel(&FormAD->LabelV[8]);
for (i = 0; i < 8; i++)
{
/* 实测 21508 = 3.300V; 个体有差异 */
volt = m * g_tAD7606.sNowAdc[i] * 3300 / 21508;
sprintf(buf, "%6d %6dmV ", g_tAD7606.sNowAdc[i], volt);
FormAD->LabelV[i].pCaption = buf;
LCD_DrawLabel(&FormAD->LabelV[i]);
}
sprintf(buf, "%d", g_tAD7606.ucOS);
FormAD->LabelV[9].pCaption = buf;
LCD_DrawLabel(&FormAD->LabelV[9]);
}
/*
*********************************************************************************************************
* : InitFormAD
* : GPS初始界面控件
*
* :
*********************************************************************************************************
*/
static void InitFormAD(void)
{
/* 分组框标题字体 */
FormAD->FontBox.FontCode = FC_ST_16;
FormAD->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormAD->FontBox.FrontColor = CL_BLACK;
FormAD->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormAD->FontBlack.FontCode = FC_ST_16;
FormAD->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormAD->FontBlack.FrontColor = CL_BLACK;
FormAD->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormAD->FontBlue.FontCode = FC_ST_16;
FormAD->FontBlue.BackColor = CL_BTN_FACE;
FormAD->FontBlue.FrontColor = CL_BLUE;
FormAD->FontBlue.Space = 0;
/* 按钮字体 */
FormAD->FontBtn.FontCode = FC_ST_16;
FormAD->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormAD->FontBtn.FrontColor = CL_BLACK;
FormAD->FontBtn.Space = 0;
/* 分组框 */
FormAD->Box1.Left = BOX1_X;
FormAD->Box1.Top = BOX1_Y;
FormAD->Box1.Height = BOX1_H;
FormAD->Box1.Width = BOX1_W;
FormAD->Box1.pCaption = BOX1_TEXT;
FormAD->Box1.Font = &FormAD->FontBox;
/* 标签 */
{
uint8_t i;
const char *strName[10] = {"通道1", "通道2", "通道3", "通道4", "通道5", "通道6", "通道7", "通道8", "量程", "过采样"};
for (i = 0; i < 10; i++)
{
FormAD->LabelN[i].Left = LabelN1_X;
FormAD->LabelN[i].Top = LabelN1_Y + i * 20;
FormAD->LabelN[i].MaxLen = 0;
FormAD->LabelN[i].pCaption = (char *)strName[i];
FormAD->LabelN[i].Font = &FormAD->FontBlack; /* 黑色 */
FormAD->LabelV[i].Left = LabelN1_X + 60;
FormAD->LabelV[i].Top = LabelN1_Y + i * 20; /* 蓝色 */
FormAD->LabelV[i].MaxLen = 0;
FormAD->LabelV[i].pCaption = "-";
FormAD->LabelV[i].Font = &FormAD->FontBlue;
}
FormAD->LabelS1.Left = LabelS1_X;
FormAD->LabelS1.Top = LabelS1_Y;
FormAD->LabelS1.MaxLen = 0;
FormAD->LabelS1.pCaption = LabelS1_TEXT;
FormAD->LabelS1.Font = &FormAD->FontBlack; /* 黑色 */
}
/* 按钮 */
FormAD->BtnRet.Left = BTN_RET_X;
FormAD->BtnRet.Top = BTN_RET_Y;
FormAD->BtnRet.Height = BTN_RET_H;
FormAD->BtnRet.Width = BTN_RET_W;
FormAD->BtnRet.pCaption = BTN_RET_TEXT;
FormAD->BtnRet.Font = &FormAD->FontBtn;
FormAD->BtnRet.Focus = 0;
}
/*
*********************************************************************************************************
* : DispADInitFace
* :
* :
* :
*********************************************************************************************************
*/
static void DispADInitFace(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormAD->Box1);
/* 标签 */
{
uint8_t i;
for (i = 0; i < 10; i++)
{
LCD_DrawLabel(&FormAD->LabelN[i]);
}
LCD_DrawLabel(&FormAD->LabelS1);
}
/* 按钮 */
LCD_DrawButton(&FormAD->BtnRet);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,333 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : reserve.c
* : V1.0
* : MPU-6050, HCM5833L, BMP085, BH1750
* :
*
* v1.0 2013-02-01 armfly
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_ad7705.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
BUTTON_T BtnRet;
} FormAD7705_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "AD7705模块测试程序..."
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define LABEL1_X (BOX1_X + 6)
#define LABEL1_Y (BOX1_Y + 20)
#define LABEL1_TEXT "通道1 : "
#define LABEL2_X (LABEL1_X + 64)
#define LABEL2_Y LABEL1_Y
#define LABEL2_TEXT "0000.0000"
#define LABEL3_X (LABEL1_X)
#define LABEL3_Y (LABEL1_Y + 20)
#define LABEL3_TEXT "通道2 : "
#define LABEL4_X (LABEL3_X + 64)
#define LABEL4_Y (LABEL3_Y)
#define LABEL4_TEXT "00000.0000"
#define LABEL5_X (LABEL1_X)
#define LABEL5_Y (LABEL1_Y + 20 * 3)
#define LABEL5_TEXT "----"
static void InitFormAD7705(void);
static void DispFormAD7705(void);
FormAD7705_T *FormAD7705;
/*
*********************************************************************************************************
* : TestAD7705
* : AD7705模块
*
* :
*********************************************************************************************************
*/
void TestAD7705(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
FormAD7705_T form;
uint16_t adc1, adc2;
FormAD7705 = &form;
InitFormAD7705();
DispFormAD7705();
bsp_InitTM7705(); /* 初始化配置TM7705 */
if (g_TM7705_OK == 0)
{
FormAD7705->Label5.pCaption = "未检测到 AD7705";
LCD_DrawLabel(&FormAD7705->Label5);
}
else
{
FormAD7705->Label5.pCaption = "已检测到 AD7705";
LCD_DrawLabel(&FormAD7705->Label5);
TM7705_CalibSelf(1); /* 自校准。执行时间较长约180ms */
adc1 = TM7705_ReadAdc(1);
TM7705_CalibSelf(2); /* 自校准。执行时间较长约180ms */
adc2 = TM7705_ReadAdc(2);
}
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
//TM7705_Scan1(); /* 扫描ADC通道1 */
TM7705_Scan2(); /* 扫描两个个ADC通道, 无等待的 */
{
/* 读取扫描结果 (结果定时读取即可) */
adc1 = TM7705_GetAdc1();
adc2 = TM7705_GetAdc2();
/* 打印采集数据 */
{
int volt1, volt2;
char buf[64];
/* 计算实际电压值(近似估算的),如需准确,请进行校准 */
volt1 = (adc1 * 5000) / 65535;
volt2 = (adc2 * 5000) / 65535;
/* 显示ADC采样结果 */
sprintf(buf, "%5d (%5dmV)", adc1, volt1);
FormAD7705->Label2.pCaption = buf;
LCD_DrawLabel(&FormAD7705->Label2);
sprintf(buf, "%5d (%5dmV)", adc2, volt2);
FormAD7705->Label4.pCaption = buf;
LCD_DrawLabel(&FormAD7705->Label4);
}
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormAD7705->BtnRet.Focus = 1;
LCD_DrawButton(&FormAD7705->BtnRet);
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormAD7705->BtnRet.Focus = 0;
LCD_DrawButton(&FormAD7705->BtnRet);
fQuit = 1; /* 返回 */
}
else /* 按钮失去焦点 */
{
FormAD7705->BtnRet.Focus = 0;
LCD_DrawButton(&FormAD7705->BtnRet);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键 */
break;
case KEY_DOWN_K2: /* K2键按下 */
break;
case KEY_DOWN_K3: /* K3键按下 */
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
}
/*
*********************************************************************************************************
* : InitFormAD7705
* :
*
* :
*********************************************************************************************************
*/
static void InitFormAD7705(void)
{
/* 分组框标题字体 */
FormAD7705->FontBox.FontCode = FC_ST_16;
FormAD7705->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormAD7705->FontBox.FrontColor = CL_BLACK;
FormAD7705->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormAD7705->FontBlack.FontCode = FC_ST_16;
FormAD7705->FontBlack.BackColor = CL_BTN_FACE; /* 透明色 */
FormAD7705->FontBlack.FrontColor = CL_BLACK;
FormAD7705->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormAD7705->FontBlue.FontCode = FC_ST_16;
FormAD7705->FontBlue.BackColor = CL_BTN_FACE;
FormAD7705->FontBlue.FrontColor = CL_BLUE;
FormAD7705->FontBlue.Space = 0;
/* 按钮字体 */
FormAD7705->FontBtn.FontCode = FC_ST_16;
FormAD7705->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormAD7705->FontBtn.FrontColor = CL_BLACK;
FormAD7705->FontBtn.Space = 0;
/* 分组框 */
FormAD7705->Box1.Left = BOX1_X;
FormAD7705->Box1.Top = BOX1_Y;
FormAD7705->Box1.Height = BOX1_H;
FormAD7705->Box1.Width = BOX1_W;
FormAD7705->Box1.pCaption = BOX1_TEXT;
FormAD7705->Box1.Font = &FormAD7705->FontBox;
/* 静态标签 */
FormAD7705->Label1.Left = LABEL1_X;
FormAD7705->Label1.Top = LABEL1_Y;
FormAD7705->Label1.MaxLen = 0;
FormAD7705->Label1.pCaption = LABEL1_TEXT;
FormAD7705->Label1.Font = &FormAD7705->FontBlack;
FormAD7705->Label3.Left = LABEL3_X;
FormAD7705->Label3.Top = LABEL3_Y;
FormAD7705->Label3.MaxLen = 0;
FormAD7705->Label3.pCaption = LABEL3_TEXT;
FormAD7705->Label3.Font = &FormAD7705->FontBlack;
FormAD7705->Label5.Left = LABEL5_X;
FormAD7705->Label5.Top = LABEL5_Y;
FormAD7705->Label5.MaxLen = 0;
FormAD7705->Label5.pCaption = LABEL5_TEXT;
FormAD7705->Label5.Font = &FormAD7705->FontBlack;
/* 动态标签 */
FormAD7705->Label2.Left = LABEL2_X;
FormAD7705->Label2.Top = LABEL2_Y;
FormAD7705->Label2.MaxLen = 0;
FormAD7705->Label2.pCaption = LABEL2_TEXT;
FormAD7705->Label2.Font = &FormAD7705->FontBlue;
FormAD7705->Label4.Left = LABEL4_X;
FormAD7705->Label4.Top = LABEL4_Y;
FormAD7705->Label4.MaxLen = 0;
FormAD7705->Label4.pCaption = LABEL4_TEXT;
FormAD7705->Label4.Font = &FormAD7705->FontBlue;
/* 按钮 */
FormAD7705->BtnRet.Left = BTN_RET_X;
FormAD7705->BtnRet.Top = BTN_RET_Y;
FormAD7705->BtnRet.Height = BTN_RET_H;
FormAD7705->BtnRet.Width = BTN_RET_W;
FormAD7705->BtnRet.pCaption = BTN_RET_TEXT;
FormAD7705->BtnRet.Font = &FormAD7705->FontBtn;
FormAD7705->BtnRet.Focus = 0;
}
/*
*********************************************************************************************************
* : DispFormAD7705
* :
* :
* :
*********************************************************************************************************
*/
static void DispFormAD7705(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormAD7705->Box1);
/* 静态标签 */
LCD_DrawLabel(&FormAD7705->Label1);
LCD_DrawLabel(&FormAD7705->Label3);
LCD_DrawLabel(&FormAD7705->Label5);
/* 动态标签 */
LCD_DrawLabel(&FormAD7705->Label2);
LCD_DrawLabel(&FormAD7705->Label4);
/* 按钮 */
LCD_DrawButton(&FormAD7705->BtnRet);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,828 +0,0 @@
/*
*********************************************************************************************************
*
* : AD9833波形发生器测试界面
* : form_ad9833.c
* : V1.0
* : AD9833模块的功能
* :
*
* v1.0 2015-07-19 armfly
*
* Copyright (C), 2015-2016, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_ad9833.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 黑色 */
FONT_T FontBlue; /* 蓝色 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
BUTTON_T BtnRet;
BUTTON_T Btn1;
BUTTON_T Btn2;
BUTTON_T Btn3;
BUTTON_T Btn4;
BUTTON_T Btn5;
BUTTON_T Btn6;
BUTTON_T Btn7;
BUTTON_T Btn8;
BUTTON_T Btn9;
BUTTON_T Btn10;
BUTTON_T Btn11;
BUTTON_T Btn12;
BUTTON_T Btn13;
BUTTON_T Btn14;
BUTTON_T Btn15;
BUTTON_T Btn16;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
LABEL_T Label6;
uint32_t Freq; /* 波形频率。单位 0.1Hz */
AD9833_WAVE_E WaveType; /* 波形类型 */
uint8_t ScanBand; /* 扫频波段 */
uint32_t FreqBegin; /* 开始频率 */
uint32_t FreqEnd; /* 截止频率 */
} Form9833_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - 53)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_T "AD9833波形发生器"
#define BTN1_H 32
#define BTN1_W 105
/* 第1行按钮坐标 */
#define BTN1_X (BOX1_X + 10)
#define BTN1_Y (BOX1_Y + 20)
#define BTN1_T "正弦波"
#define BTN2_H BTN1_H
#define BTN2_W BTN1_W
#define BTN2_X (BTN1_X + BTN1_W + 10)
#define BTN2_Y BTN1_Y
#define BTN2_T "三角波"
#define BTN3_H BTN1_H
#define BTN3_W BTN1_W
#define BTN3_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN3_Y BTN1_Y
#define BTN3_T "方波"
#define BTN16_H BTN1_H
#define BTN16_W BTN1_W
#define BTN16_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN16_Y BTN1_Y
#define BTN16_T "停止"
/* 第2行按钮坐标 */
#define BTN4_H BTN1_H
#define BTN4_W BTN1_W
#define BTN4_X BTN1_X
#define BTN4_Y (BTN1_Y + BTN1_H + 10)
#define BTN4_T "频率+0.1Hz"
#define BTN5_H BTN1_H
#define BTN5_W BTN1_W
#define BTN5_X (BTN1_X + 1 * (BTN1_W + 10))
#define BTN5_Y BTN4_Y
#define BTN5_T "频率-0.1Hz"
#define BTN6_H BTN1_H
#define BTN6_W BTN1_W
#define BTN6_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN6_Y BTN4_Y
#define BTN6_T "频率+1Hz"
#define BTN7_H BTN1_H
#define BTN7_W BTN1_W
#define BTN7_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN7_Y BTN4_Y
#define BTN7_T "频率-1Hz"
/* 第3行按钮坐标 */
#define BTN8_H BTN1_H
#define BTN8_W BTN1_W
#define BTN8_X BTN1_X
#define BTN8_Y (BTN1_Y + 2 * (BTN1_H + 10))
#define BTN8_T "频率+1kHz"
#define BTN9_H BTN1_H
#define BTN9_W BTN1_W
#define BTN9_X (BTN1_X + 1 * (BTN1_W + 10))
#define BTN9_Y BTN8_Y
#define BTN9_T "频率-1kHz"
#define BTN10_H BTN1_H
#define BTN10_W BTN1_W
#define BTN10_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN10_Y BTN8_Y
#define BTN10_T "频率+100kHz"
#define BTN11_H BTN1_H
#define BTN11_W BTN1_W
#define BTN11_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN11_Y BTN8_Y
#define BTN11_T "频率-100kHz"
/* 第4行按钮坐标 */
#define BTN12_H BTN1_H
#define BTN12_W BTN1_W
#define BTN12_X BTN1_X
#define BTN12_Y (BTN1_Y + 3 * (BTN1_H + 10))
#define BTN12_T "频率=10Hz"
#define BTN13_H BTN1_H
#define BTN13_W BTN1_W
#define BTN13_X (BTN1_X + 1 * (BTN1_W + 10))
#define BTN13_Y BTN12_Y
#define BTN13_T "频率=10KHz"
#define BTN14_H BTN1_H
#define BTN14_W BTN1_W
#define BTN14_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN14_Y BTN12_Y
#define BTN14_T "扫频频段"
#define BTN15_H BTN1_H
#define BTN15_W BTN1_W
#define BTN15_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN15_Y BTN12_Y
#define BTN15_T "开始扫频"
#define LBL1_X BOX1_X + 5
#define LBL1_Y 190
#define LBL1_T "输出波形:"
#define LBL2_X LBL1_X + 85
#define LBL2_Y LBL1_Y
#define LBL2_T " "
#define LBL3_X LBL1_X
#define LBL3_Y LBL1_Y + 20
#define LBL3_T "波形频率:"
#define LBL4_X LBL3_X + 85
#define LBL4_Y LBL3_Y
#define LBL4_T " "
#define LBL5_X LBL1_X
#define LBL5_Y LBL3_Y + 25
#define LBL5_T "扫频频段:"
#define LBL6_X LBL5_X + 85
#define LBL6_Y LBL5_Y
#define LBL6_T " "
/* 按钮 */
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 80
#define BTN_RET_X (g_LcdWidth - BTN_RET_W - 8)
#define BTN_RET_Y (g_LcdHeight - BTN_RET_H - 4)
#define BTN_RET_T "返回"
#define BAND_NUM 6
static const uint32_t s_FreqBand[BAND_NUM][3] =
{
/* 开始频率 结束频率 步进频率 (单位 0.1Hz) */
{0, 1000, 10},
{0, 10000, 10},
{0, 100000, 100},
{0, 100000, 1000},
{0, 1000000, 1000},
{0, 100000000, 100000}};
Form9833_T *Form9833;
static void InitForm9833(void);
static void DispForm9833(void);
static void Disp9833Info(void);
static void FreqToStr(uint32_t _freq, char *_dispbuf);
/*
*********************************************************************************************************
* : FormMain9833
* :
* :
* :
*********************************************************************************************************
*/
void FormMain9833(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
Form9833_T form;
uint8_t fDispInfo = 1;
Form9833 = &form;
InitForm9833();
DispForm9833();
bsp_InitAD9833();
Form9833->Freq = 100000; /* 波形频率。单位 0.1Hz */
Form9833->WaveType = NONE_WAVE; /* 波形类型 */
Form9833->ScanBand = 0;
fDispInfo = 1;
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
if (fDispInfo)
{
fDispInfo = 0;
AD9833_SetWaveFreq(Form9833->Freq); /*设置频率值 */
AD9833_SelectWave(Form9833->WaveType);
Disp9833Info(); /* 显示频率 */
}
/* 扫频 */
if (bsp_CheckTimer(0))
{
Form9833->Freq += s_FreqBand[Form9833->ScanBand][2]; /* 步进频率 */
fDispInfo = 1;
if (Form9833->Freq >= s_FreqBand[Form9833->ScanBand][1])
{
bsp_StopTimer(0); /* 停止定时器 */
}
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (LCD_ButtonTouchDown(&Form9833->BtnRet, tpX, tpY))
{
//fQuit = 1; 释放时再退出
}
else if (LCD_ButtonTouchDown(&Form9833->Btn1, tpX, tpY))
{
Form9833->WaveType = SINE_WAVE; /* 正弦波 */
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn2, tpX, tpY))
{
Form9833->WaveType = TRI_WAVE; /* 三角波 */
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn3, tpX, tpY))
{
Form9833->WaveType = SQU_WAVE; /* 方波 */
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn4, tpX, tpY)) /* 频率 +0.1Hz */
{
if (Form9833->Freq < AD9833_MAX_FREQ)
{
Form9833->Freq++;
}
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn5, tpX, tpY)) /* 频率 -0.1Hz */
{
if (Form9833->Freq > 0)
{
Form9833->Freq--;
}
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn6, tpX, tpY)) /* 频率 +1Hz */
{
if (Form9833->Freq < AD9833_MAX_FREQ)
{
Form9833->Freq += 10;
}
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn7, tpX, tpY)) /* 频率 -1Hz */
{
if (Form9833->Freq > 10)
{
Form9833->Freq -= 10;
}
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn8, tpX, tpY)) /* 频率 +1kHz */
{
if (Form9833->Freq < AD9833_MAX_FREQ)
{
Form9833->Freq += 10000;
}
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn9, tpX, tpY)) /* 频率 -1kHz */
{
if (Form9833->Freq > 10000)
{
Form9833->Freq -= 10000;
}
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn10, tpX, tpY)) /* 频率 +100kHz */
{
if (Form9833->Freq < AD9833_MAX_FREQ)
{
Form9833->Freq += 1000000;
}
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn11, tpX, tpY)) /* 频率 -100kHz */
{
if (Form9833->Freq > 1000000)
{
Form9833->Freq -= 1000000;
}
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn12, tpX, tpY)) /* 频率 = 10Hz */
{
Form9833->Freq = 100;
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn13, tpX, tpY)) /* 频率 = 10KHz */
{
Form9833->Freq = 100000;
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn14, tpX, tpY)) /* 扫频频段 */
{
/* 切换扫频频段 */
if (++Form9833->ScanBand >= BAND_NUM)
{
Form9833->ScanBand = 0;
}
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn15, tpX, tpY)) /* 开始扫频 */
{
Form9833->Freq = s_FreqBand[Form9833->ScanBand][0];
bsp_StartAutoTimer(0, 100); /* 100ms 更新一次频率 */
fDispInfo = 1;
}
else if (LCD_ButtonTouchDown(&Form9833->Btn16, tpX, tpY))
{
Form9833->WaveType = NONE_WAVE; /* 输出停止 */
fDispInfo = 1;
bsp_StopTimer(0); /* 停止定时器 */
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (LCD_ButtonTouchRelease(&Form9833->BtnRet, tpX, tpY))
{
fQuit = 1; /* 返回 */
}
else
{
LCD_ButtonTouchRelease(&Form9833->BtnRet, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn1, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn2, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn3, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn4, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn5, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn6, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn7, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn8, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn9, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn10, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn11, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn12, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn13, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn14, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn15, tpX, tpY);
LCD_ButtonTouchRelease(&Form9833->Btn16, tpX, tpY);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键 + 1*/
break;
case KEY_DOWN_K2: /* K2键 - 1 */
break;
case KEY_DOWN_K3: /* K3键 - 清0 */
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
}
/*
*********************************************************************************************************
* : InitForm9833
* :
*
* :
*********************************************************************************************************
*/
static void InitForm9833(void)
{
/* 分组框标题字体 */
Form9833->FontBox.FontCode = FC_ST_16;
Form9833->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
Form9833->FontBox.FrontColor = CL_BLACK;
Form9833->FontBox.Space = 0;
/* 字体1 用于静止标签 */
Form9833->FontBlack.FontCode = FC_ST_16;
Form9833->FontBlack.BackColor = CL_MASK; /* 透明色 */
Form9833->FontBlack.FrontColor = CL_BLACK;
Form9833->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
Form9833->FontBlue.FontCode = FC_ST_16;
Form9833->FontBlue.BackColor = CL_BTN_FACE;
Form9833->FontBlue.FrontColor = CL_BLUE;
Form9833->FontBlue.Space = 0;
/* 按钮字体 */
Form9833->FontBtn.FontCode = FC_ST_16;
Form9833->FontBtn.BackColor = CL_MASK; /* 透明背景 */
Form9833->FontBtn.FrontColor = CL_BLACK;
Form9833->FontBtn.Space = 0;
/* 分组框 */
Form9833->Box1.Left = BOX1_X;
Form9833->Box1.Top = BOX1_Y;
Form9833->Box1.Height = BOX1_H;
Form9833->Box1.Width = BOX1_W;
Form9833->Box1.pCaption = BOX1_T;
Form9833->Box1.Font = &Form9833->FontBox;
/* 标签 */
Form9833->Label1.Left = LBL1_X;
Form9833->Label1.Top = LBL1_Y;
Form9833->Label1.MaxLen = 0;
Form9833->Label1.pCaption = LBL1_T;
Form9833->Label1.Font = &Form9833->FontBlack;
Form9833->Label2.Left = LBL2_X;
Form9833->Label2.Top = LBL2_Y;
Form9833->Label2.MaxLen = 0;
Form9833->Label2.pCaption = LBL2_T;
Form9833->Label2.Font = &Form9833->FontBlue;
Form9833->Label3.Left = LBL3_X;
Form9833->Label3.Top = LBL3_Y;
Form9833->Label3.MaxLen = 0;
Form9833->Label3.pCaption = LBL3_T;
Form9833->Label3.Font = &Form9833->FontBlack;
Form9833->Label4.Left = LBL4_X;
Form9833->Label4.Top = LBL4_Y;
Form9833->Label4.MaxLen = 0;
Form9833->Label4.pCaption = LBL4_T;
Form9833->Label4.Font = &Form9833->FontBlue;
Form9833->Label5.Left = LBL5_X;
Form9833->Label5.Top = LBL5_Y;
Form9833->Label5.MaxLen = 0;
Form9833->Label5.pCaption = LBL5_T;
Form9833->Label5.Font = &Form9833->FontBlack;
Form9833->Label6.Left = LBL6_X;
Form9833->Label6.Top = LBL6_Y;
Form9833->Label6.MaxLen = 0;
Form9833->Label6.pCaption = LBL6_T;
Form9833->Label6.Font = &Form9833->FontBlue;
/* 按钮 */
Form9833->BtnRet.Left = BTN_RET_X;
Form9833->BtnRet.Top = BTN_RET_Y;
Form9833->BtnRet.Height = BTN_RET_H;
Form9833->BtnRet.Width = BTN_RET_W;
Form9833->BtnRet.pCaption = BTN_RET_T;
Form9833->BtnRet.Font = &Form9833->FontBtn;
Form9833->BtnRet.Focus = 0;
Form9833->Btn1.Left = BTN1_X;
Form9833->Btn1.Top = BTN1_Y;
Form9833->Btn1.Height = BTN1_H;
Form9833->Btn1.Width = BTN1_W;
Form9833->Btn1.pCaption = BTN1_T;
Form9833->Btn1.Font = &Form9833->FontBtn;
Form9833->Btn1.Focus = 0;
Form9833->Btn2.Left = BTN2_X;
Form9833->Btn2.Top = BTN2_Y;
Form9833->Btn2.Height = BTN2_H;
Form9833->Btn2.Width = BTN2_W;
Form9833->Btn2.pCaption = BTN2_T;
Form9833->Btn2.Font = &Form9833->FontBtn;
Form9833->Btn2.Focus = 0;
Form9833->Btn3.Left = BTN3_X;
Form9833->Btn3.Top = BTN3_Y;
Form9833->Btn3.Height = BTN3_H;
Form9833->Btn3.Width = BTN3_W;
Form9833->Btn3.pCaption = BTN3_T;
Form9833->Btn3.Font = &Form9833->FontBtn;
Form9833->Btn3.Focus = 0;
Form9833->Btn4.Left = BTN4_X;
Form9833->Btn4.Top = BTN4_Y;
Form9833->Btn4.Height = BTN4_H;
Form9833->Btn4.Width = BTN4_W;
Form9833->Btn4.pCaption = BTN4_T;
Form9833->Btn4.Font = &Form9833->FontBtn;
Form9833->Btn4.Focus = 0;
Form9833->Btn5.Left = BTN5_X;
Form9833->Btn5.Top = BTN5_Y;
Form9833->Btn5.Height = BTN5_H;
Form9833->Btn5.Width = BTN5_W;
Form9833->Btn5.pCaption = BTN5_T;
Form9833->Btn5.Font = &Form9833->FontBtn;
Form9833->Btn5.Focus = 0;
Form9833->Btn6.Left = BTN6_X;
Form9833->Btn6.Top = BTN6_Y;
Form9833->Btn6.Height = BTN6_H;
Form9833->Btn6.Width = BTN6_W;
Form9833->Btn6.pCaption = BTN6_T;
Form9833->Btn6.Font = &Form9833->FontBtn;
Form9833->Btn6.Focus = 0;
Form9833->Btn7.Left = BTN7_X;
Form9833->Btn7.Top = BTN7_Y;
Form9833->Btn7.Height = BTN7_H;
Form9833->Btn7.Width = BTN7_W;
Form9833->Btn7.pCaption = BTN7_T;
Form9833->Btn7.Font = &Form9833->FontBtn;
Form9833->Btn7.Focus = 0;
Form9833->Btn8.Left = BTN8_X;
Form9833->Btn8.Top = BTN8_Y;
Form9833->Btn8.Height = BTN8_H;
Form9833->Btn8.Width = BTN8_W;
Form9833->Btn8.pCaption = BTN8_T;
Form9833->Btn8.Font = &Form9833->FontBtn;
Form9833->Btn8.Focus = 0;
Form9833->Btn9.Left = BTN9_X;
Form9833->Btn9.Top = BTN9_Y;
Form9833->Btn9.Height = BTN9_H;
Form9833->Btn9.Width = BTN9_W;
Form9833->Btn9.pCaption = BTN9_T;
Form9833->Btn9.Font = &Form9833->FontBtn;
Form9833->Btn9.Focus = 0;
Form9833->Btn10.Left = BTN10_X;
Form9833->Btn10.Top = BTN10_Y;
Form9833->Btn10.Height = BTN10_H;
Form9833->Btn10.Width = BTN10_W;
Form9833->Btn10.pCaption = BTN10_T;
Form9833->Btn10.Font = &Form9833->FontBtn;
Form9833->Btn10.Focus = 0;
Form9833->Btn11.Left = BTN11_X;
Form9833->Btn11.Top = BTN11_Y;
Form9833->Btn11.Height = BTN11_H;
Form9833->Btn11.Width = BTN11_W;
Form9833->Btn11.pCaption = BTN11_T;
Form9833->Btn11.Font = &Form9833->FontBtn;
Form9833->Btn11.Focus = 0;
Form9833->Btn12.Left = BTN12_X;
Form9833->Btn12.Top = BTN12_Y;
Form9833->Btn12.Height = BTN12_H;
Form9833->Btn12.Width = BTN12_W;
Form9833->Btn12.pCaption = BTN12_T;
Form9833->Btn12.Font = &Form9833->FontBtn;
Form9833->Btn12.Focus = 0;
Form9833->Btn13.Left = BTN13_X;
Form9833->Btn13.Top = BTN13_Y;
Form9833->Btn13.Height = BTN13_H;
Form9833->Btn13.Width = BTN13_W;
Form9833->Btn13.pCaption = BTN13_T;
Form9833->Btn13.Font = &Form9833->FontBtn;
Form9833->Btn13.Focus = 0;
Form9833->Btn14.Left = BTN14_X;
Form9833->Btn14.Top = BTN14_Y;
Form9833->Btn14.Height = BTN14_H;
Form9833->Btn14.Width = BTN14_W;
Form9833->Btn14.pCaption = BTN14_T;
Form9833->Btn14.Font = &Form9833->FontBtn;
Form9833->Btn14.Focus = 0;
Form9833->Btn15.Left = BTN15_X;
Form9833->Btn15.Top = BTN15_Y;
Form9833->Btn15.Height = BTN15_H;
Form9833->Btn15.Width = BTN15_W;
Form9833->Btn15.pCaption = BTN15_T;
Form9833->Btn15.Font = &Form9833->FontBtn;
Form9833->Btn15.Focus = 0;
Form9833->Btn16.Left = BTN16_X;
Form9833->Btn16.Top = BTN16_Y;
Form9833->Btn16.Height = BTN16_H;
Form9833->Btn16.Width = BTN16_W;
Form9833->Btn16.pCaption = BTN16_T;
Form9833->Btn16.Font = &Form9833->FontBtn;
Form9833->Btn16.Focus = 0;
}
/*
*********************************************************************************************************
* : DispForm9833
* :
* :
* :
*********************************************************************************************************
*/
static void DispForm9833(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&Form9833->Box1);
LCD_DrawLabel(&Form9833->Label1);
LCD_DrawLabel(&Form9833->Label2);
LCD_DrawLabel(&Form9833->Label3);
LCD_DrawLabel(&Form9833->Label4);
LCD_DrawLabel(&Form9833->Label5);
LCD_DrawLabel(&Form9833->Label6);
/* 按钮 */
LCD_DrawButton(&Form9833->Btn1);
LCD_DrawButton(&Form9833->Btn2);
LCD_DrawButton(&Form9833->Btn3);
LCD_DrawButton(&Form9833->Btn4);
LCD_DrawButton(&Form9833->Btn5);
LCD_DrawButton(&Form9833->Btn6);
LCD_DrawButton(&Form9833->Btn5);
LCD_DrawButton(&Form9833->Btn6);
LCD_DrawButton(&Form9833->Btn7);
LCD_DrawButton(&Form9833->Btn8);
LCD_DrawButton(&Form9833->Btn9);
LCD_DrawButton(&Form9833->Btn10);
LCD_DrawButton(&Form9833->Btn11);
LCD_DrawButton(&Form9833->Btn12);
LCD_DrawButton(&Form9833->Btn13);
LCD_DrawButton(&Form9833->Btn14);
LCD_DrawButton(&Form9833->Btn15);
LCD_DrawButton(&Form9833->Btn16);
LCD_DrawButton(&Form9833->BtnRet);
}
/*
*********************************************************************************************************
* : FreqToStr
* :
* : _freq 0.1Hz
* _dispbuf
* :
*********************************************************************************************************
*/
static void FreqToStr(uint32_t _freq, char *_dispbuf)
{
if (_freq < 10000)
{
sprintf(_dispbuf, "%d.%dHz", _freq / 10, _freq % 10);
}
else if (_freq >= 10000 && _freq < 10000000)
{
sprintf(_dispbuf, "%d.%04dKHz", _freq / 10000, _freq % 10000);
}
else if (_freq >= 10000000)
{
sprintf(_dispbuf, "%d.%07d%MHz", _freq / 10000000, (_freq % 10000000));
}
}
/*
*********************************************************************************************************
* : DispDacVoltage
* :
* :
* _
* :
*********************************************************************************************************
*/
static void Disp9833Info(void)
{
char buf[128];
{
/* 打印当前的波形类型 */
if (Form9833->WaveType == NONE_WAVE)
{
strcpy(buf, "关闭");
}
else if (Form9833->WaveType == TRI_WAVE)
{
strcpy(buf, "三角波");
}
else if (Form9833->WaveType == SINE_WAVE)
{
strcpy(buf, "正弦波");
}
else if (Form9833->WaveType == SQU_WAVE)
{
strcpy(buf, "方波");
}
else
{
strcpy(buf, "xxxxx");
}
Form9833->Label2.pCaption = buf;
LCD_DrawLabel(&Form9833->Label2);
}
{
/* 打印当前的扫频频段 */
uint32_t freq1, freq2, step;
char buf1[32];
char buf2[32];
char buf3[32];
freq1 = s_FreqBand[Form9833->ScanBand][0];
freq2 = s_FreqBand[Form9833->ScanBand][1];
step = s_FreqBand[Form9833->ScanBand][2];
FreqToStr(freq1, buf1);
FreqToStr(freq2, buf2);
FreqToStr(step, buf3);
sprintf(buf, "%s-%s, 步进 %s", buf1, buf2, buf3);
Form9833->Label6.pCaption = buf;
LCD_DrawLabel(&Form9833->Label6);
}
{
/* 打印当前的频率值 */
FreqToStr(Form9833->Freq, buf); /* 将整数格式的频率值转换为可显示的ASCII字符串 */
Form9833->Label4.pCaption = buf;
LCD_DrawLabel(&Form9833->Label4);
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,404 +0,0 @@
/*
*********************************************************************************************************
*
* : AD7606数据采集模块测试程序
* : ad7606_test.c
* : V1.0
* : MPU-6050, HCM5833L, BMP085, BH1750
* :
*
* v1.0 2013-02-01 armfly
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T LabelN[8 + 2];
LABEL_T LabelV[8 + 2];
LABEL_T LabelS1;
BUTTON_T BtnRet;
}FormADS1256_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "ADS1256数据采集模块测试程序"
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define LabelN1_X (BOX1_X + 6)
#define LabelN1_Y (BOX1_Y + 20)
#define LabelN1_TEXT "通道1 : "
#define LabelV1_X (LabelN1_X + 64)
#define LabelV1_Y LabelN1_Y
#define LabelV1_TEXT "-"
#define LabelS1_X (BOX1_X + 6)
#define LabelS1_Y (BOX1_Y + BOX1_H - 20)
#define LabelS1_TEXT "摇杆上下键选择增益, 左右键选择滤波参数"
static void InitFormADS1256(void);
static void DispADInitFace(void);
static void DispADStatus(void);
FormADS1256_T *FormADS1256;
/*
*********************************************************************************************************
* : TestADS1256
* : ADS1256模块
*
* :
*********************************************************************************************************
*/
void TestADS1256(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
int16_t tpX, tpY;
FormADS1256_T form;
uint8_t fRefresh;
FormADS1256 = &form;
InitFormADS1256();
DispADInitFace();
bsp_InitADS1256();
ADS1256_CfgADC(ADS1256_GAIN_1, ADS1256_30SPS); /* 配置ADC参数 增益1:1, 数据输出速率 30Hz */
/* 打印芯片ID (通过读ID可以判断硬件接口是否正常) , 正常时状态寄存器的高4bit = 3 */
#if 0
{
uint8_t id;
id = ADS1256_ReadChipID();
if (id != 3)
{
printf("Error, ASD1256 Chip ID = 0x%X\r\n", id);
}
else
{
printf("Ok, ASD1256 Chip ID = 0x%X\r\n", id);
}
}
#endif
/* 进入主程序循环体 */
bsp_StartAutoTimer(0, 500);
ADS1256_StartScan(); /* 启动8通道ADC扫描 */
fRefresh = 1;
while (g_MainStatus == MS_ADS1256)
{
bsp_Idle();
if (bsp_CheckTimer(0) || (fRefresh == 1))
{
fRefresh = 0;
DispADStatus();
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormADS1256->BtnRet.Focus = 1;
LCD_DrawButton(&FormADS1256->BtnRet);
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormADS1256->BtnRet.Focus = 0;
LCD_DrawButton(&FormADS1256->BtnRet);
g_MainStatus = MS_MAIN_MENU; /* 返回 */
}
else /* 按钮失去焦点 */
{
FormADS1256->BtnRet.Focus = 0;
LCD_DrawButton(&FormADS1256->BtnRet);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键按下 切换量程 */
case KEY_DOWN_K2: /* K2键按下 */
case KEY_DOWN_K3: /* K3键按下 */
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
if (g_tADS1256.Gain < 6)
{
g_tADS1256.Gain++;
}
ADS1256_CfgADC(g_tADS1256.Gain, g_tADS1256.DataRate); /* 配置ADC参数 增益和数据输出速率 */
ADS1256_StartScan();
fRefresh = 1;
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
if (g_tADS1256.Gain > 0)
{
g_tADS1256.Gain--;
}
ADS1256_CfgADC(g_tADS1256.Gain, g_tADS1256.DataRate); /* 配置ADC参数 增益和数据输出速率 */
ADS1256_StartScan();
fRefresh = 1;
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
if (g_tADS1256.DataRate < ADS1256_2d5SPS)
{
g_tADS1256.DataRate++;
}
ADS1256_CfgADC(g_tADS1256.Gain, g_tADS1256.DataRate); /* 配置ADC参数 增益和数据输出速率 */
ADS1256_StartScan();
fRefresh = 1;
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
if (g_tADS1256.DataRate > ADS1256_1000SPS)
{
g_tADS1256.DataRate--;
}
ADS1256_CfgADC(g_tADS1256.Gain, g_tADS1256.DataRate); /* 配置ADC参数 增益和数据输出速率 */
ADS1256_StartScan();
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
ADS1256_StopScan(); /* 停止ADS1256的中断响应 */
}
/*
*********************************************************************************************************
* : DispADStatus
* : ADC状态
*
* :
*********************************************************************************************************
*/
static void DispADStatus(void)
{
char buf[128];
uint8_t i;
const char *strGain[7] = { "X1 (±5V)", "X2 (±2.5V)", "X4 (±1.25V)", "X8 (±0.625V)", "X16 (±312.5mV)",
"X32 (±156.25mV)", "X64 (±78.125mV)"};
const char *strRate[ADS1256_DRATE_MAX] =
{
"1, 30000SPS",
"2, 15000SPS",
"4, 7500SPS",
"8, 3750SPS",
"15, 2000SPS",
"30, 1000SPS",
"60, 500SPS",
"300, 100SPS",
"500, 60SPS",
"600, 50SPS",
"1000, 30SPS",
"1200, 25SPS",
"2000, 15SPS",
"3000, 10SPS",
"6000, 5SPS",
"12000, 2d5SPS"
};
/* 显示 ADC结果 */
for (i = 0; i < 8; i++)
{
int32_t iTemp;
/* 计算实际电压值(近似估算的),如需准确,请进行校准 */
iTemp = ((int64_t)g_tADS1256.AdcNow[i] * 2500000) / 4194303;
if (iTemp < 0)
{
iTemp = -iTemp;
sprintf(buf, "%6d,(-%d.%03d %03d V) ", g_tADS1256.AdcNow[i] , iTemp /1000000, (iTemp%1000000)/1000, iTemp%1000);
}
else
{
sprintf(buf, "%6d,( %d.%03d %03d V) ", g_tADS1256.AdcNow[i] , iTemp/1000000, (iTemp%1000000)/1000, iTemp%1000);
}
FormADS1256->LabelV[i].pCaption = buf;
LCD_DrawLabel(&FormADS1256->LabelV[i]);
}
/* 显示 增益 */
FormADS1256->LabelV[8].pCaption = (char *)strGain[g_tADS1256.Gain];
LCD_DrawLabel(&FormADS1256->LabelV[8]);
/* 显示 数据速率 */
FormADS1256->LabelV[9].pCaption = (char *)strRate[g_tADS1256.DataRate];
LCD_DrawLabel(&FormADS1256->LabelV[9]);
}
/*
*********************************************************************************************************
* : InitFormADS1256
* : GPS初始界面控件
*
* :
*********************************************************************************************************
*/
static void InitFormADS1256(void)
{
/* 分组框标题字体 */
FormADS1256->FontBox.FontCode = FC_ST_16;
FormADS1256->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormADS1256->FontBox.FrontColor = CL_BLACK;
FormADS1256->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormADS1256->FontBlack.FontCode = FC_ST_16;
FormADS1256->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormADS1256->FontBlack.FrontColor = CL_BLACK;
FormADS1256->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormADS1256->FontBlue.FontCode = FC_ST_16;
FormADS1256->FontBlue.BackColor = CL_BTN_FACE;
FormADS1256->FontBlue.FrontColor = CL_BLUE;
FormADS1256->FontBlue.Space = 0;
/* 按钮字体 */
FormADS1256->FontBtn.FontCode = FC_ST_16;
FormADS1256->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormADS1256->FontBtn.FrontColor = CL_BLACK;
FormADS1256->FontBtn.Space = 0;
/* 分组框 */
FormADS1256->Box1.Left = BOX1_X;
FormADS1256->Box1.Top = BOX1_Y;
FormADS1256->Box1.Height = BOX1_H;
FormADS1256->Box1.Width = BOX1_W;
FormADS1256->Box1.pCaption = BOX1_TEXT;
FormADS1256->Box1.Font = &FormADS1256->FontBox;
/* 标签 */
{
uint8_t i;
const char *strName[10] = {"通道1","通道2","通道3","通道4","通道5","通道6","通道7","通道8",
"增益(量程)", "滤波(速率)"};
for (i = 0; i < 10; i++)
{
FormADS1256->LabelN[i].Left = LabelN1_X;
FormADS1256->LabelN[i].Top = LabelN1_Y + i * 20;
FormADS1256->LabelN[i].MaxLen = 0;
FormADS1256->LabelN[i].pCaption = (char *)strName[i];
FormADS1256->LabelN[i].Font = &FormADS1256->FontBlack; /* 黑色 */
FormADS1256->LabelV[i].Left = LabelN1_X + 60;
FormADS1256->LabelV[i].Top = LabelN1_Y + i * 20; /* 蓝色 */
FormADS1256->LabelV[i].MaxLen = 0;
FormADS1256->LabelV[i].pCaption = "-";
FormADS1256->LabelV[i].Font = &FormADS1256->FontBlue;
}
FormADS1256->LabelV[8].Left = LabelN1_X + 120;
FormADS1256->LabelV[9].Left = LabelN1_X + 120;
FormADS1256->LabelS1.Left = LabelS1_X;
FormADS1256->LabelS1.Top = LabelS1_Y;
FormADS1256->LabelS1.MaxLen = 0;
FormADS1256->LabelS1.pCaption = LabelS1_TEXT;
FormADS1256->LabelS1.Font = &FormADS1256->FontBlack; /* 黑色 */
}
/* 按钮 */
FormADS1256->BtnRet.Left = BTN_RET_X;
FormADS1256->BtnRet.Top = BTN_RET_Y;
FormADS1256->BtnRet.Height = BTN_RET_H;
FormADS1256->BtnRet.Width = BTN_RET_W;
FormADS1256->BtnRet.pCaption = BTN_RET_TEXT;
FormADS1256->BtnRet.Font = &FormADS1256->FontBtn;
FormADS1256->BtnRet.Focus = 0;
}
/*
*********************************************************************************************************
* : DispADInitFace
* :
* :
* :
*********************************************************************************************************
*/
static void DispADInitFace(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormADS1256->Box1);
/* 标签 */
{
uint8_t i;
for (i = 0; i < 10; i++)
{
LCD_DrawLabel(&FormADS1256->LabelN[i]);
}
LCD_DrawLabel(&FormADS1256->LabelS1);
}
/* 按钮 */
LCD_DrawButton(&FormADS1256->BtnRet);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,719 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : audio_rec.c
* : V1.2
* : I2S录音和回放功能
* :
*
* v1.0 2013-02-01 armfly
* V1.1 2014-11-04 armfly LED1指示灯的控制GPIO将用于3.5
* V1.2 2015-01-08 armfly StartPlay(void)
*
* Copyright (C), 2015-2020, www.armfly.com
*
*********************************************************************************************************
*/
/*
I2S音频CODEC芯片为WM8978
[TAMPER] =
[WAKEUP] =
[USER] =
/ =
/ = MIC增益
OK键 =
STM32开发板外扩的2MB SRAM中使8K采样率16bit格式1MB可以保存64秒录音
SRAM中读取数据
WM8978支持的采样率 :
Support for 8, 11.025, 12, 16, 22.05, 24, 32, 44.1 and 48kHz sample rates
*/
#include "bsp.h"
#include "form_audio_rec.h"
#define STR_Help1 "摇杆上/下键 = 调节耳机音量"
#define STR_Help2 "摇杆左/右键 = 调节麦克风增益"
#define STR_Help3 "K1键 = 选择音频格式"
/* 返回按钮的坐标(屏幕右下角) */
#define BUTTON_RET_H 32
#define BUTTON_RET_W 60
#define BUTTON_RET_X (g_LcdWidth - BUTTON_RET_W - 4)
#define BUTTON_RET_Y (g_LcdHeight - BUTTON_RET_H - 4)
#define BUTTON_RET_TEXT "返回"
#define BUTTON_REC_H 32
#define BUTTON_REC_W 74
#define BUTTON_REC_X 5
#define BUTTON_REC_Y 180
#define BUTTON_REC_TEXT "开始录音"
#define BUTTON_PLAY_H 32
#define BUTTON_PLAY_W 74
#define BUTTON_PLAY_X (BUTTON_REC_X + BUTTON_REC_W + 10)
#define BUTTON_PLAY_Y BUTTON_REC_Y
#define BUTTON_PLAY_TEXT "开始放音"
#define BUTTON_STOP_H 32
#define BUTTON_STOP_W 74
#define BUTTON_STOP_X (BUTTON_PLAY_X + BUTTON_PLAY_W + 10)
#define BUTTON_STOP_Y BUTTON_REC_Y
#define BUTTON_STOP_TEXT "停止"
/* 以下是检查框 */
#define CHECK_SPK_X BUTTON_REC_X
#define CHECK_SPK_Y (BUTTON_REC_Y + BUTTON_REC_H + 5)
#define CHECK_SPK_H CHECK_BOX_H
#define CHECK_SPK_W (CHECK_BOX_W + 5 * 16) /* 决定触摸有效区域 */
#define CHECK_SPK_TEXT "打开扬声器"
REC_T g_tRec;
/* 音频格式切换列表(可以自定义) */
#define FMT_COUNT 9 /* 音频格式数组元素个数 */
uint32_t g_FmtList[FMT_COUNT][3] =
{
{I2S_STANDARD_PHILIPS, SAI_DATASIZE_16, I2S_AUDIOFREQ_8K},
{I2S_STANDARD_PHILIPS, SAI_DATASIZE_16, I2S_AUDIOFREQ_11K},
{I2S_STANDARD_PHILIPS, SAI_DATASIZE_16, I2S_AUDIOFREQ_16K},
{I2S_STANDARD_PHILIPS, SAI_DATASIZE_16, I2S_AUDIOFREQ_22K},
{I2S_STANDARD_PHILIPS, SAI_DATASIZE_16, I2S_AUDIOFREQ_32K},
{I2S_STANDARD_PHILIPS, SAI_DATASIZE_16, I2S_AUDIOFREQ_44K},
{I2S_STANDARD_PHILIPS, SAI_DATASIZE_16, I2S_AUDIOFREQ_48K},
{I2S_STANDARD_PHILIPS, SAI_DATASIZE_16, I2S_AUDIOFREQ_96K},
{I2S_STANDARD_PHILIPS, SAI_DATASIZE_16, I2S_AUDIOFREQ_192K},
};
/* 定义录音放音缓冲区 */
#define REC_MEM_ADDR SDRAM_APP_BUF
#define REC_MEM_SIZE (2 * 1024 * 1024)
/* 仅允许本文件内调用的函数声明 */
static void DispStatus(void);
static void StartPlay(void);
static void StartRecord(void);
static void StopRec(void);
/*
*********************************************************************************************************
* : RecorderDemo
* :
* :
* :
*********************************************************************************************************
*/
void RecorderDemo(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fRefresh; /* 刷屏请求标志,1表示需要刷新 */
uint8_t fQuit = 0;
FONT_T tFont, tFontBtn, tFontChk; /* 定义一个字体结构体变量,用于设置字体参数 */
char buf[128];
uint16_t x, y;
uint16_t usLineCap = 18;
int16_t tpX, tpY;
BUTTON_T tBtn;
CHECK_T tCheck;
LCD_ClrScr(CL_BLUE); /* 清屏,背景蓝色 */
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_WHITE; /* 字体颜色 */
tFont.BackColor = CL_BLUE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
/* 按钮字体 */
tFontBtn.FontCode = FC_ST_16;
tFontBtn.BackColor = CL_MASK; /* 透明色 */
tFontBtn.FrontColor = CL_BLACK;
tFontBtn.Space = 0;
/* CheckBox 字体 */
tFontChk.FontCode = FC_ST_16;
tFontChk.BackColor = CL_MASK; /* 透明色 */
tFontChk.FrontColor = CL_YELLOW;
tFontChk.Space = 0;
}
x = 5;
y = 3;
LCD_DispStr(x, y, "WM8978录音机", &tFont); /* 在(8,3)坐标处显示一串汉字 */
y += usLineCap;
/* 测试I2C设备 */
{
if (i2c_CheckDevice(WM8978_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "WM8978 Ok (0x%02X)", WM8978_SLAVE_ADDRESS);
LCD_DispStr(x, y, buf, &tFont);
}
else
{
sprintf(buf, "WM8978 Err (0x%02X)", WM8978_SLAVE_ADDRESS);
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
y += usLineCap;
tFont.FrontColor = CL_YELLOW;
LCD_DispStr(x, y, STR_Help1, &tFont);
y += usLineCap;
LCD_DispStr(x, y, STR_Help2, &tFont);
y += usLineCap;
LCD_DispStr(x, y, STR_Help3, &tFont);
y += usLineCap;
tFont.FrontColor = CL_WHITE;
}
/* 配置外部SRAM接口已经在 bsp.c 中的 bsp_Init() 函数执行过 */
/* 检测WM8978芯片此函数会自动配置CPU的GPIO */
if (!wm8978_Init())
{
bsp_DelayMS(500);
return;
}
/* 显示按钮 */
{
tBtn.Font = &tFontBtn;
tBtn.Left = BUTTON_RET_X;
tBtn.Top = BUTTON_RET_Y;
tBtn.Height = BUTTON_RET_H;
tBtn.Width = BUTTON_RET_W;
tBtn.Focus = 0; /* 未选中 */
tBtn.pCaption = BUTTON_RET_TEXT;
LCD_DrawButton(&tBtn);
tBtn.Left = BUTTON_REC_X;
tBtn.Top = BUTTON_REC_Y;
tBtn.Height = BUTTON_REC_H;
tBtn.Width = BUTTON_REC_W;
tBtn.Focus = 0; /* 失去焦点 */
tBtn.pCaption = BUTTON_REC_TEXT;
LCD_DrawButton(&tBtn);
tBtn.Left = BUTTON_PLAY_X;
tBtn.Top = BUTTON_PLAY_Y;
tBtn.Height = BUTTON_PLAY_H;
tBtn.Width = BUTTON_PLAY_W;
tBtn.Focus = 0; /* 失去焦点 */
tBtn.pCaption = BUTTON_PLAY_TEXT;
LCD_DrawButton(&tBtn);
tBtn.Left = BUTTON_STOP_X;
tBtn.Top = BUTTON_STOP_Y;
tBtn.Height = BUTTON_STOP_H;
tBtn.Width = BUTTON_STOP_W;
tBtn.Focus = 0; /* 失去焦点 */
tBtn.pCaption = BUTTON_STOP_TEXT;
LCD_DrawButton(&tBtn);
/* 显示检查框 */
tCheck.Font = &tFontChk;
tCheck.Left = CHECK_SPK_X;
tCheck.Top = CHECK_SPK_Y;
tCheck.Height = CHECK_SPK_H;
tCheck.Width = CHECK_SPK_W;
if (g_tRec.ucSpkOutEn == 1)
{
tCheck.Checked = 1;
}
else
{
tCheck.Checked = 0;
}
tCheck.pCaption = CHECK_SPK_TEXT;
LCD_DrawCheckBox(&tCheck);
}
/* 初始化全局变量 */
g_tRec.ucVolume = 52; /* 缺省音量 */
g_tRec.ucMicGain = 34; /* 缺省PGA增益 */
fRefresh = 1;
g_tRec.ucFmtIdx = 1; /* 缺省音频格式(16Bit, 16KHz) */
g_tRec.pAudio = (int16_t *)SDRAM_APP_BUF; /* 通过 init16_t * 型指针访问外部SRAM */
/* 清零录音缓冲区. SRAM容量2M字节 */
// {
// int i;
// for (i = 0 ; i < 1 * 1024 * 1024; i++)
// {
// g_tRec.pAudio[i] = 0;
// }
// }
/* 生成正弦波数组 */
AUDIO_MakeSine16bit((int16_t *)REC_MEM_ADDR, 1000, 16000, 16000 * 5);
g_tRec.ucStatus = STA_IDLE; /* 首先进入空闲状态 */
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
AUDIO_Poll();
/* 集中处理显示界面刷新 */
if (fRefresh == 1)
{
fRefresh = 0;
DispStatus(); /* 显示当前状态,频率,音量等 */
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BUTTON_RET_X, BUTTON_RET_Y, BUTTON_RET_H, BUTTON_RET_W))
{
tBtn.Left = BUTTON_RET_X;
tBtn.Top = BUTTON_RET_Y;
tBtn.Height = BUTTON_RET_H;
tBtn.Width = BUTTON_RET_W;
tBtn.Focus = 1; /* 焦点 */
tBtn.pCaption = BUTTON_RET_TEXT;
LCD_DrawButton(&tBtn);
}
else if (TOUCH_InRect(tpX, tpY, BUTTON_REC_X, BUTTON_REC_Y, BUTTON_REC_H, BUTTON_REC_W))
{
tBtn.Left = BUTTON_REC_X;
tBtn.Top = BUTTON_REC_Y;
tBtn.Height = BUTTON_REC_H;
tBtn.Width = BUTTON_REC_W;
tBtn.Focus = 1; /* 焦点 */
tBtn.pCaption = BUTTON_REC_TEXT;
LCD_DrawButton(&tBtn);
}
else if (TOUCH_InRect(tpX, tpY, BUTTON_PLAY_X, BUTTON_PLAY_Y, BUTTON_PLAY_H, BUTTON_PLAY_W))
{
tBtn.Left = BUTTON_PLAY_X;
tBtn.Top = BUTTON_PLAY_Y;
tBtn.Height = BUTTON_PLAY_H;
tBtn.Width = BUTTON_PLAY_W;
tBtn.Focus = 1; /* 焦点 */
tBtn.pCaption = BUTTON_PLAY_TEXT;
LCD_DrawButton(&tBtn);
}
else if (TOUCH_InRect(tpX, tpY, BUTTON_STOP_X, BUTTON_STOP_Y, BUTTON_STOP_H, BUTTON_STOP_W))
{
tBtn.Left = BUTTON_STOP_X;
tBtn.Top = BUTTON_STOP_Y;
tBtn.Height = BUTTON_STOP_H;
tBtn.Width = BUTTON_STOP_W;
tBtn.Focus = 1; /* 焦点 */
tBtn.pCaption = BUTTON_STOP_TEXT;
LCD_DrawButton(&tBtn);
}
else if (TOUCH_InRect(tpX, tpY, CHECK_SPK_X, CHECK_SPK_Y, CHECK_SPK_H, CHECK_SPK_W))
{
if (g_tRec.ucSpkOutEn)
{
g_tRec.ucSpkOutEn = 0;
tCheck.Checked = 0;
/* 配置WM8978芯片输入为AUX接口(收音机),输出为耳机 */
/* 在 StartPlay() 函数内部配置 */
}
else
{
g_tRec.ucSpkOutEn = 1;
tCheck.Checked = 1;
/* 配置WM8978芯片输入为AUX接口(收音机),输出为耳机 和 扬声器 */
/* 在 StartPlay() 函数内部配置 */
}
tCheck.Left = CHECK_SPK_X;
tCheck.Top = CHECK_SPK_Y;
tCheck.Height = CHECK_SPK_H;
tCheck.Width = CHECK_SPK_W;
tCheck.pCaption = CHECK_SPK_TEXT;
LCD_DrawCheckBox(&tCheck);
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BUTTON_RET_X, BUTTON_RET_Y, BUTTON_RET_H, BUTTON_RET_W))
{
tBtn.Font = &tFontBtn;
tBtn.Left = BUTTON_RET_X;
tBtn.Top = BUTTON_RET_Y;
tBtn.Height = BUTTON_RET_H;
tBtn.Width = BUTTON_RET_W;
tBtn.Focus = 1; /* 焦点 */
tBtn.pCaption = BUTTON_RET_TEXT;
LCD_DrawButton(&tBtn);
fQuit = 1; /* 返回 */
}
else if (TOUCH_InRect(tpX, tpY, BUTTON_REC_X, BUTTON_REC_Y, BUTTON_REC_H, BUTTON_REC_W))
{
tBtn.Font = &tFontBtn;
tBtn.Left = BUTTON_REC_X;
tBtn.Top = BUTTON_REC_Y;
tBtn.Height = BUTTON_REC_H;
tBtn.Width = BUTTON_REC_W;
tBtn.Focus = 0; /* 失去焦点 */
tBtn.pCaption = BUTTON_REC_TEXT;
LCD_DrawButton(&tBtn);
StartRecord(); /* 开始录音 */
fRefresh = 1;
}
else if (TOUCH_InRect(tpX, tpY, BUTTON_PLAY_X, BUTTON_PLAY_Y, BUTTON_PLAY_H, BUTTON_PLAY_W))
{
tBtn.Font = &tFontBtn;
tBtn.Left = BUTTON_PLAY_X;
tBtn.Top = BUTTON_PLAY_Y;
tBtn.Height = BUTTON_PLAY_H;
tBtn.Width = BUTTON_PLAY_W;
tBtn.Focus = 0; /* 失去焦点 */
tBtn.pCaption = BUTTON_PLAY_TEXT;
LCD_DrawButton(&tBtn);
StartPlay(); /* 开始放音 */
fRefresh = 1;
}
else if (TOUCH_InRect(tpX, tpY, BUTTON_STOP_X, BUTTON_STOP_Y, BUTTON_STOP_H, BUTTON_STOP_W))
{
tBtn.Left = BUTTON_STOP_X;
tBtn.Top = BUTTON_STOP_Y;
tBtn.Height = BUTTON_STOP_H;
tBtn.Width = BUTTON_STOP_W;
tBtn.Focus = 0; /* 失去焦点 */
tBtn.pCaption = BUTTON_STOP_TEXT;
LCD_DrawButton(&tBtn);
StopRec(); /* 停止录音和放音 */
fRefresh = 1;
}
else /* 按钮失去焦点 */
{
tBtn.Font = &tFontBtn;
tBtn.Focus = 0; /* 未选中 */
tBtn.Left = BUTTON_RET_X;
tBtn.Top = BUTTON_RET_Y;
tBtn.Height = BUTTON_RET_H;
tBtn.Width = BUTTON_RET_W;
tBtn.pCaption = BUTTON_RET_TEXT;
LCD_DrawButton(&tBtn);
tBtn.Left = BUTTON_REC_X;
tBtn.Top = BUTTON_REC_Y;
tBtn.Height = BUTTON_REC_H;
tBtn.Width = BUTTON_REC_W;
tBtn.pCaption = BUTTON_REC_TEXT;
LCD_DrawButton(&tBtn);
tBtn.Left = BUTTON_PLAY_X;
tBtn.Top = BUTTON_PLAY_Y;
tBtn.Height = BUTTON_PLAY_H;
tBtn.Width = BUTTON_PLAY_W;
tBtn.pCaption = BUTTON_PLAY_TEXT;
LCD_DrawButton(&tBtn);
tBtn.Left = BUTTON_STOP_X;
tBtn.Top = BUTTON_STOP_Y;
tBtn.Height = BUTTON_STOP_H;
tBtn.Width = BUTTON_STOP_W;
tBtn.pCaption = BUTTON_STOP_TEXT;
LCD_DrawButton(&tBtn);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键切换音频格式在下次开始录音和放音时有效 */
if (++g_tRec.ucFmtIdx >= FMT_COUNT)
{
g_tRec.ucFmtIdx = 0;
}
fRefresh = 1;
break;
case KEY_DOWN_K2: /* K2键按下录音 */
StartRecord();
fRefresh = 1;
break;
case KEY_DOWN_K3: /* K3键按下放音 */
StartPlay();
fRefresh = 1;
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
if (g_tRec.ucVolume <= VOLUME_MAX - VOLUME_STEP)
{
g_tRec.ucVolume += VOLUME_STEP;
wm8978_SetEarVolume(g_tRec.ucVolume);
wm8978_SetSpkVolume(g_tRec.ucVolume);
fRefresh = 1;
}
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
if (g_tRec.ucVolume >= VOLUME_STEP)
{
g_tRec.ucVolume -= VOLUME_STEP;
wm8978_SetEarVolume(g_tRec.ucVolume);
wm8978_SetSpkVolume(g_tRec.ucVolume);
fRefresh = 1;
}
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
if (g_tRec.ucMicGain >= GAIN_STEP)
{
g_tRec.ucMicGain -= GAIN_STEP;
wm8978_SetMicGain(g_tRec.ucMicGain);
fRefresh = 1;
}
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
if (g_tRec.ucMicGain <= GAIN_MAX - GAIN_STEP)
{
g_tRec.ucMicGain += GAIN_STEP;
wm8978_SetMicGain(g_tRec.ucMicGain);
fRefresh = 1;
}
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
StopRec(); /* 停止录音和放音 */
fRefresh = 1;
break;
default:
break;
}
}
/* 处理消息 */
{
MSG_T msg;
if (bsp_GetMsg(&msg))
{
switch (msg.MsgCode)
{
case MSG_WM8978_DMA_END:
StopRec(); /* 停止录音和放音 */
fRefresh = 1;
break;
default:
break;
}
}
}
}
StopRec(); /* 停止录音和放音 */
}
/*
*********************************************************************************************************
* : StartPlay
* : WM8978和STM32的I2S开始放音
* :
* :
*********************************************************************************************************
*/
static void StartPlay(void)
{
/* 如果已经再录音和放音状态,则需要先停止再开启 */
AUDIO_Stop(); /* 停止I2S录音和放音 */
wm8978_Init(); /* 复位WM8978到复位状态 */
bsp_DelayMS(20); /* 延迟一段时间等待I2S中断结束 */
g_tRec.ucStatus = STA_PLAYING; /* 放音状态 */
g_tRec.uiCursor = 0; /* 数据指针复位为0从头开始放音 */
/* 配置WM8978芯片输入为DAC输出为耳机 */
if (g_tRec.ucSpkOutEn == 1)
{
wm8978_CfgAudioPath(DAC_ON, EAR_LEFT_ON | EAR_RIGHT_ON | SPK_ON); /* 打开扬声器 */
}
else
{
wm8978_CfgAudioPath(DAC_ON, EAR_LEFT_ON | EAR_RIGHT_ON); /* 关闭扬声器 */
}
/* 调节音量,左右相同音量 */
wm8978_SetEarVolume(g_tRec.ucVolume);
wm8978_SetSpkVolume(g_tRec.ucVolume);
/* 配置WM8978音频接口为飞利浦标准I2S接口16bit */
wm8978_CfgAudioIF(I2S_STANDARD_PHILIPS, 16);
/* 配置STM32的I2S音频接口(比如飞利浦标准I2S接口16bit 8K采样率), 开始放音 */
AUDIO_Init(1, I2S_STANDARD_PHILIPS, g_FmtList[g_tRec.ucFmtIdx][1], g_FmtList[g_tRec.ucFmtIdx][2]);
{
int16_t *pWave = (int16_t *)REC_MEM_ADDR;
AUDIO_Play(pWave, AUDIO_GetRecordSampleCount());
}
}
/*
*********************************************************************************************************
* : StartRecord
* : WM8978和STM32的I2S开始录音
* :
* :
*********************************************************************************************************
*/
static void StartRecord(void)
{
/* 如果已经再录音和放音状态,则需要先停止再开启 */
AUDIO_Stop(); /* 停止I2S录音和放音 */
wm8978_Init(); /* 复位WM8978到复位状态 */
bsp_DelayMS(20); /* 延迟一段时间等待I2S中断结束 */
g_tRec.ucStatus = STA_RECORDING; /* 录音状态 */
g_tRec.uiCursor = 0; /* 数据指针复位为0从头开始录音 */
/* 配置WM8978芯片输入为Mic输出为耳机 */
//wm8978_CfgAudioPath(MIC_LEFT_ON | ADC_ON, EAR_LEFT_ON | EAR_RIGHT_ON);
//wm8978_CfgAudioPath(MIC_RIGHT_ON | ADC_ON, EAR_LEFT_ON | EAR_RIGHT_ON);
wm8978_CfgAudioPath(MIC_LEFT_ON | MIC_RIGHT_ON | ADC_ON, EAR_LEFT_ON | EAR_RIGHT_ON);
/* 调节放音音量,左右相同音量 */
wm8978_SetEarVolume(g_tRec.ucVolume);
/* 设置MIC通道增益 */
wm8978_SetMicGain(g_tRec.ucMicGain);
/* 配置WM8978音频接口为飞利浦标准I2S接口16bit */
wm8978_CfgAudioIF(I2S_STANDARD_PHILIPS, 16);
/* 配置STM32的I2S音频接口(比如飞利浦标准I2S接口16bit 8K采样率), 开始放音 */
AUDIO_Init(3, I2S_STANDARD_PHILIPS, g_FmtList[g_tRec.ucFmtIdx][1], g_FmtList[g_tRec.ucFmtIdx][2]);
{
int16_t *pWave1 = (int16_t *)REC_MEM_ADDR;
int16_t *pWave2 = (int16_t *)(REC_MEM_ADDR + 1 * 1024 * 1024);
AUDIO_Play(pWave2, 1 * 1024 * 1024);
AUDIO_Record(pWave1, 1 * 1024 * 1024);
}
}
/*
*********************************************************************************************************
* : StopRec
* :
* :
* :
*********************************************************************************************************
*/
static void StopRec(void)
{
g_tRec.ucStatus = STA_IDLE; /* 待机状态 */
AUDIO_Stop(); /* 停止I2S录音和放音 */
wm8978_Init(); /* 复位WM8978到复位状态 */
}
/*
*********************************************************************************************************
* : DispStatus
* :
* :
* :
*********************************************************************************************************
*/
static void DispStatus(void)
{
FONT_T tFont;
char buf[128];
uint16_t x, y;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_WHITE; /* 字体颜色 */
tFont.BackColor = CL_BLUE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = 5;
y = 100;
/* 显示当前音频格式 */
sprintf(buf, "音频格式: Philips,16Bit,%d.%dkHz ",
g_FmtList[g_tRec.ucFmtIdx][2] / 1000,
(g_FmtList[g_tRec.ucFmtIdx][2] % 1000) / 100);
sprintf(&buf[strlen(buf)], "录音时长: %d.%03d秒 ",
(REC_MEM_SIZE / 2) / g_FmtList[g_tRec.ucFmtIdx][2],
(((REC_MEM_SIZE / 2) * 1000) / g_FmtList[g_tRec.ucFmtIdx][2]) % 1000);
LCD_DispStr(x, y, buf, &tFont);
y += 18;
sprintf(buf, "麦克风增益 = %d ", g_tRec.ucMicGain);
sprintf(&buf[strlen(buf)], "耳机音量 = %d ", g_tRec.ucVolume);
LCD_DispStr(x, y, buf, &tFont);
y += 18;
if (g_tRec.ucStatus == STA_IDLE)
{
sprintf(buf, "状态 = 空闲 ");
}
else if (g_tRec.ucStatus == STA_RECORDING)
{
sprintf(buf, "状态 = 正在录音");
}
else if (g_tRec.ucStatus == STA_PLAYING)
{
sprintf(buf, "状态 = 正在回放");
}
LCD_DispStr(x, y, buf, &tFont);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,478 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : camera_test.c
* : V1.1
* : 使STM32F429的DCMI摄像头接口
* :
*
* v1.0 2013-02-01 armfly STM32F407
* v1.1 2015-10-17 armfly STM32F429
*
* Copyright (C), 2015-2020, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_camera.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 蓝色 */
FONT_T FontRed; /* 变化的文字字体 红色 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T Label1;
LABEL_T Label2; /* 状态 */
LABEL_T Label3;
LABEL_T Label4; /* 状态 */
LABEL_T Label5;
LABEL_T Label6; /* 状态 */
BUTTON_T Btn1; /* 打开摄像头 */
BUTTON_T Btn2; /* 暂停 */
BUTTON_T BtnRet;
} FormCAM_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 4个框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 5
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "摄像头0V7670测试程序"
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define BTN1_H 32
#define BTN1_W 100
#define BTN1_X (BOX1_X + 330)
#define BTN1_Y (BOX1_Y + 100)
#define BTN1_TEXT "打开摄像头"
#define BTN2_H 32
#define BTN2_W 100
#define BTN2_X BTN1_X
#define BTN2_Y (BTN1_Y + BTN1_H + 10)
#define BTN2_TEXT "关闭摄像头"
/* 标签 */
#define LABEL1_X (BOX1_X + 330)
#define LABEL1_Y (BOX1_Y + 20)
#define LABEL1_TEXT "Chip ID : "
#define LABEL2_X (LABEL1_X + 80)
#define LABEL2_Y LABEL1_Y
#define LABEL2_TEXT "--"
#define LABEL3_X (LABEL1_X)
#define LABEL3_Y (LABEL1_Y + 20)
#define LABEL3_TEXT "状态1 : "
#define LABEL4_X (LABEL3_X + 80)
#define LABEL4_Y (LABEL3_Y)
#define LABEL4_TEXT "--"
#define LABEL5_X (LABEL1_X)
#define LABEL5_Y (LABEL1_Y + 20 * 2)
#define LABEL5_TEXT "状态2 : "
#define LABEL6_X (LABEL5_X + 80)
#define LABEL6_Y (LABEL5_Y)
#define LABEL6_TEXT "--"
/* 摄像显示窗口位置和大小 */
#define PHOTO_X 10
#define PHOTO_Y 22
#define PHOTO_H 240
#define PHOTO_W 320
static void InitFormCam(void);
static void DispCamInitFace(void);
FormCAM_T *FormCam;
/* Buffer location should aligned to cache line size (32 bytes) */
#define CAN_BUF_SIZE (320 * 265 * 2)
ALIGN_32BYTES(uint16_t s_CamCache[CAN_BUF_SIZE]);
/*
*********************************************************************************************************
* : TestCamera
* :
*
* :
*********************************************************************************************************
*/
void TestCamera(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
uint16_t usChipID;
char buf[128];
uint8_t fStop = 0;
FormCAM_T form;
uint8_t fRefresh;
FormCam = &form;
InitFormCam();
bsp_InitCamera();
DispCamInitFace();
if (i2c_CheckDevice(OV7670_SLAVE_ADDRESS) == 0)
{
usChipID = OV_ReadID();
sprintf(buf, "0x%04X", usChipID);
FormCam->Label2.Font = &FormCam->FontBlue;
FormCam->Label2.pCaption = buf;
}
else
{
sprintf(buf, "None ");
FormCam->Label2.Font = &FormCam->FontRed;
FormCam->Label2.pCaption = buf;
}
LCD_DrawLabel(&FormCam->Label2);
LCD_DrawRect(PHOTO_X - 1, PHOTO_Y - 1, PHOTO_H + 2, PHOTO_W + 2, CL_RED);
fRefresh = 1;
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
if (fRefresh)
{
fRefresh = 0;
//LCD_DrawLabel(&FormCam->Label6);
}
if (g_tCam.CaptureOk == 1)
{
g_tCam.CaptureOk = 0;
/* 开始绘图 ,图片在 s_CamCache */
SCB_CleanInvalidateDCache();
LCD429_DrawBMP(PHOTO_X, PHOTO_Y, PHOTO_H, PHOTO_W, (uint16_t *)s_CamCache);
if (fStop == 0)
{
bsp_StartTimer(0, 50); /* 启动定时器 */
}
}
if (bsp_CheckTimer(0))
{
{
//g_tTP.Enable = 0;
//RA8875_StartDirectDraw(PHOTO_X, PHOTO_Y, PHOTO_H, PHOTO_W);
CAM_Start((uint32_t)s_CamCache);
}
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormCam->BtnRet.Focus = 1;
LCD_DrawButton(&FormCam->BtnRet);
}
else if (TOUCH_InRect(tpX, tpY, BTN1_X, BTN1_Y, BTN1_H, BTN1_W))
{
FormCam->Btn1.Focus = 1;
LCD_DrawButton(&FormCam->Btn1);
}
else if (TOUCH_InRect(tpX, tpY, BTN2_X, BTN2_Y, BTN2_H, BTN2_W))
{
FormCam->Btn2.Focus = 1;
LCD_DrawButton(&FormCam->Btn2);
}
break;
case TOUCH_MOVE: /* 触笔移动事件 */
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormCam->BtnRet.Focus = 0;
LCD_DrawButton(&FormCam->BtnRet);
fQuit = 1; /* 返回 */
}
else if (TOUCH_InRect(tpX, tpY, BTN1_X, BTN1_Y, BTN1_H, BTN1_W)) /* 打开摄像头 */
{
FormCam->Btn1.Focus = 0;
LCD_DrawButton(&FormCam->Btn1);
{
if (i2c_CheckDevice(OV7670_SLAVE_ADDRESS) == 0)
{
usChipID = OV_ReadID();
sprintf(buf, "0x%04X", usChipID);
FormCam->Label2.Font = &FormCam->FontBlue;
FormCam->Label2.pCaption = buf;
}
else
{
sprintf(buf, "None ");
FormCam->Label2.Font = &FormCam->FontRed;
FormCam->Label2.pCaption = buf;
}
LCD_DrawLabel(&FormCam->Label2);
}
{
//g_tTP.Enable = 0;
//RA8875_StartDirectDraw(PHOTO_X, PHOTO_Y, PHOTO_H, PHOTO_W);
CAM_Start((uint32_t)s_CamCache); /* 摄像头DMA的目标地址设置为显存 */
}
fStop = 0;
fRefresh = 1;
}
else if (TOUCH_InRect(tpX, tpY, BTN2_X, BTN2_Y, BTN2_H, BTN2_W))
{
FormCam->Btn2.Focus = 0;
LCD_DrawButton(&FormCam->Btn2);
bsp_StopTimer(0); /* 停止自动定时器 */
fStop = 1;
fRefresh = 1;
}
else /* 按钮失去焦点 */
{
FormCam->BtnRet.Focus = 0;
LCD_DrawButton(&FormCam->BtnRet);
FormCam->Btn1.Focus = 0;
LCD_DrawButton(&FormCam->Btn1);
FormCam->Btn2.Focus = 0;
LCD_DrawButton(&FormCam->Btn2);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键 */
break;
case KEY_DOWN_K2: /* K2键按下 */
break;
case KEY_DOWN_K3: /* K3键按下 */
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
CAM_Stop(); /* 停止摄像头DMA */
g_tTP.Enable = 1;
break;
default:
break;
}
}
}
bsp_StopTimer(0); /* 停止自动定时器 */
CAM_Stop();
// RA8875_QuitDirectDraw();
g_tTP.Enable = 1;
}
/*
*********************************************************************************************************
* : InitFormCam
* : GPS初始界面控件
*
* :
*********************************************************************************************************
*/
static void InitFormCam(void)
{
/* 分组框标题字体 */
FormCam->FontBox.FontCode = FC_ST_16;
FormCam->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormCam->FontBox.FrontColor = CL_BLACK;
FormCam->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormCam->FontBlack.FontCode = FC_ST_16;
FormCam->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormCam->FontBlack.FrontColor = CL_BLACK;
FormCam->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormCam->FontBlue.FontCode = FC_ST_16;
FormCam->FontBlue.BackColor = CL_BTN_FACE;
FormCam->FontBlue.FrontColor = CL_BLUE;
FormCam->FontBlue.Space = 0;
/* 字体3 用于变化的文字 */
FormCam->FontRed.FontCode = FC_ST_16;
FormCam->FontRed.BackColor = CL_BTN_FACE;
FormCam->FontRed.FrontColor = CL_RED;
FormCam->FontRed.Space = 0;
/* 按钮字体 */
FormCam->FontBtn.FontCode = FC_ST_16;
FormCam->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormCam->FontBtn.FrontColor = CL_BLACK;
FormCam->FontBtn.Space = 0;
/* 分组框 */
FormCam->Box1.Left = BOX1_X;
FormCam->Box1.Top = BOX1_Y;
FormCam->Box1.Height = BOX1_H;
FormCam->Box1.Width = BOX1_W;
FormCam->Box1.pCaption = BOX1_TEXT;
FormCam->Box1.Font = &FormCam->FontBox;
/* 静态标签 */
FormCam->Label1.Left = LABEL1_X;
FormCam->Label1.Top = LABEL1_Y;
FormCam->Label1.MaxLen = 0;
FormCam->Label1.pCaption = LABEL1_TEXT;
FormCam->Label1.Font = &FormCam->FontBlack;
FormCam->Label3.Left = LABEL3_X;
FormCam->Label3.Top = LABEL3_Y;
FormCam->Label3.MaxLen = 0;
FormCam->Label3.pCaption = LABEL3_TEXT;
FormCam->Label3.Font = &FormCam->FontBlack;
FormCam->Label5.Left = LABEL5_X;
FormCam->Label5.Top = LABEL5_Y;
FormCam->Label5.MaxLen = 0;
FormCam->Label5.pCaption = LABEL5_TEXT;
FormCam->Label5.Font = &FormCam->FontBlack;
/* 动态标签 */
FormCam->Label2.Left = LABEL2_X;
FormCam->Label2.Top = LABEL2_Y;
FormCam->Label2.MaxLen = 0;
FormCam->Label2.pCaption = LABEL2_TEXT;
FormCam->Label2.Font = &FormCam->FontBlue;
FormCam->Label4.Left = LABEL4_X;
FormCam->Label4.Top = LABEL4_Y;
FormCam->Label4.MaxLen = 0;
FormCam->Label4.pCaption = LABEL4_TEXT;
FormCam->Label4.Font = &FormCam->FontBlue;
FormCam->Label6.Left = LABEL6_X;
FormCam->Label6.Top = LABEL6_Y;
FormCam->Label6.MaxLen = 0;
FormCam->Label6.pCaption = LABEL6_TEXT;
FormCam->Label6.Font = &FormCam->FontBlue;
/* 按钮 */
FormCam->BtnRet.Left = BTN_RET_X;
FormCam->BtnRet.Top = BTN_RET_Y;
FormCam->BtnRet.Height = BTN_RET_H;
FormCam->BtnRet.Width = BTN_RET_W;
FormCam->BtnRet.pCaption = BTN_RET_TEXT;
FormCam->BtnRet.Font = &FormCam->FontBtn;
FormCam->BtnRet.Focus = 0;
FormCam->Btn1.Left = BTN1_X;
FormCam->Btn1.Top = BTN1_Y;
FormCam->Btn1.Height = BTN1_H;
FormCam->Btn1.Width = BTN1_W;
FormCam->Btn1.pCaption = BTN1_TEXT;
FormCam->Btn1.Font = &FormCam->FontBtn;
FormCam->Btn1.Focus = 0;
FormCam->Btn2.Left = BTN2_X;
FormCam->Btn2.Top = BTN2_Y;
FormCam->Btn2.Height = BTN2_H;
FormCam->Btn2.Width = BTN2_W;
FormCam->Btn2.pCaption = BTN2_TEXT;
FormCam->Btn2.Font = &FormCam->FontBtn;
FormCam->Btn2.Focus = 0;
}
/*
*********************************************************************************************************
* : DispUSBInitFace
* :
* :
* :
*********************************************************************************************************
*/
static void DispCamInitFace(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormCam->Box1);
/* 标签 */
LCD_DrawLabel(&FormCam->Label1);
LCD_DrawLabel(&FormCam->Label2);
LCD_DrawLabel(&FormCam->Label3);
LCD_DrawLabel(&FormCam->Label4);
LCD_DrawLabel(&FormCam->Label5);
LCD_DrawLabel(&FormCam->Label6);
/* 按钮 */
LCD_DrawButton(&FormCam->BtnRet);
LCD_DrawButton(&FormCam->Btn1);
LCD_DrawButton(&FormCam->Btn2);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,501 +0,0 @@
/*
*********************************************************************************************************
*
* : CAN网络测试界面
* : form_can.c
* : V1.0
* : CAN网络互通测试
* :
*
* v1.0 2015-08-09 armfly
*
* Copyright (C), 2015-2016, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_can.h"
#include "can_network.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
LABEL_T Label6;
BUTTON_T BtnRet;
BUTTON_T Btn1;
BUTTON_T Btn2;
BUTTON_T Btn3;
BUTTON_T Btn4;
BUTTON_T Btn5;
BUTTON_T Btn6;
LABEL_T LblInfo1;
LABEL_T LblInfo2;
} FormCAN_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H 100
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "CAN网络测试"
/* 第1个框内的按钮 */
#define BTN1_H 32
#define BTN1_W 100
#define BTN1_X (BOX1_X + 10)
#define BTN1_Y (BOX1_Y + 20)
#define BTN1_TEXT "点亮LED2"
#define BTN2_H BTN1_H
#define BTN2_W BTN1_W
#define BTN2_X (BTN1_X + BTN1_W + 10)
#define BTN2_Y BTN1_Y
#define BTN2_TEXT "关闭LED2"
#define BTN3_H BTN1_H
#define BTN3_W BTN1_W
#define BTN3_X BTN1_X
#define BTN3_Y (BTN1_Y + BTN1_H + 10)
#define BTN3_TEXT "蜂鸣2声"
#define BTN4_H BTN1_H
#define BTN4_W BTN1_W
#define BTN4_X (BTN1_X + BTN1_W + 10)
#define BTN4_Y (BTN1_Y + BTN1_H + 10)
#define BTN4_TEXT "蜂鸣3声"
#define BTN5_H BTN1_H
#define BTN5_W BTN1_W
#define BTN5_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN5_Y (BTN1_Y + BTN1_H + 10)
#define BTN5_TEXT "蜂鸣20声"
#define BTN6_H BTN1_H
#define BTN6_W BTN1_W
#define BTN6_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN6_Y (BTN1_Y + BTN1_H + 10)
#define BTN6_TEXT "停止蜂鸣"
#define LABEL1_X (BTN5_X + 10)
#define LABEL1_Y BTN2_Y
#define LABEL1_TEXT "地址: "
#define LABEL2_X (LABEL1_X + 48)
#define LABEL2_Y LABEL1_Y
#define LABEL2_TEXT "0"
#define LABEL3_X (LABEL2_X + 32)
#define LABEL3_Y LABEL1_Y
#define LABEL3_TEXT "波特率: "
#define LABEL4_X (LABEL3_X + 64)
#define LABEL4_Y (LABEL3_Y)
#define LABEL4_TEXT "0"
#define LABEL5_X (LABEL1_X)
#define LABEL5_Y (LABEL1_Y + 20)
#define LABEL5_TEXT "接收:"
#define LABEL6_X (LABEL5_X + 48)
#define LABEL6_Y LABEL5_Y
#define LABEL6_TEXT " "
#define LBL_INFO1_X (BOX1_X)
#define LBL_INFO1_Y (BOX1_Y + BOX1_H + 10)
#define LBL_INFO1_TEXT "请将两个开发板的CAN接口互联"
#define LBL_INFO2_X LBL_INFO1_X
#define LBL_INFO2_Y (LBL_INFO1_Y + 20)
#define LBL_INFO2_TEXT "可以互相控制对方的LED2和蜂鸣器"
/* 按钮 */
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 80
#define BTN_RET_X (g_LcdWidth - BTN_RET_W - 8)
#define BTN_RET_Y (g_LcdHeight - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
static void InitFormCAN(void);
static void DispFormCAN(void);
static void DispLabelBaud(uint32_t _Baud);
static void DispLabelRx(uint8_t *_buf, uint8_t _len);
FormCAN_T *FormCAN;
/*
*********************************************************************************************************
* : FormMainCAN
* : CAN测试主程序
* :
* :
*********************************************************************************************************
*/
void FormMainCAN(void)
{
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
FormCAN_T form;
uint32_t baud;
FormCAN = &form;
InitFormCAN();
DispFormCAN();
baud = 500000;
DispLabelBaud(baud);
can_Init(); /* 初始化STM32 CAN硬件 */
/* 进入主程序循环体 */
bsp_StartAutoTimer(2, 10);
while (fQuit == 0)
{
bsp_Idle();
// MODBUS_Poll();
if (bsp_CheckTimer(2))
{
can_LedOn(1, 1);
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (LCD_ButtonTouchDown(&FormCAN->BtnRet, tpX, tpY))
{
//fQuit = 1;
}
else if (LCD_ButtonTouchDown(&FormCAN->Btn1, tpX, tpY))
{
can_LedOn(1, 2);
}
else if (LCD_ButtonTouchDown(&FormCAN->Btn2, tpX, tpY))
{
can_LedOff(1, 2);
}
else if (LCD_ButtonTouchDown(&FormCAN->Btn3, tpX, tpY))
{
can_BeepCtrl(1, 2); /* 控制蜂鸣器鸣叫2声 */
}
else if (LCD_ButtonTouchDown(&FormCAN->Btn4, tpX, tpY))
{
can_BeepCtrl(1, 3); /* 控制蜂鸣器鸣叫3声 */
}
else if (LCD_ButtonTouchDown(&FormCAN->Btn5, tpX, tpY))
{
can_BeepCtrl(1, 20); /* 控制蜂鸣器鸣叫20声 */
}
else if (LCD_ButtonTouchDown(&FormCAN->Btn6, tpX, tpY))
{
can_BeepCtrl(1, 0); /* 控制蜂鸣器停止鸣叫 */
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (LCD_ButtonTouchRelease(&FormCAN->BtnRet, tpX, tpY))
{
fQuit = 1; /* 返回 */
}
else
{
LCD_ButtonTouchRelease(&FormCAN->BtnRet, tpX, tpY);
LCD_ButtonTouchRelease(&FormCAN->Btn1, tpX, tpY);
LCD_ButtonTouchRelease(&FormCAN->Btn2, tpX, tpY);
LCD_ButtonTouchRelease(&FormCAN->Btn3, tpX, tpY);
LCD_ButtonTouchRelease(&FormCAN->Btn4, tpX, tpY);
LCD_ButtonTouchRelease(&FormCAN->Btn5, tpX, tpY);
LCD_ButtonTouchRelease(&FormCAN->Btn6, tpX, tpY);
}
break;
}
}
/* 处理应用层消息 */
{
MSG_T msg;
if (bsp_GetMsg(&msg))
{
switch (msg.MsgCode)
{
case MSG_CAN1_RX: /* 接收到CAN设备的应答 */
DispLabelRx(g_Can1RxData, g_Can1RxHeader.DataLength);
can1_Analyze();
break;
case MSG_CAN2_RX: /* 接收到CAN设备的应答 */
DispLabelRx(g_Can2RxData, g_Can2RxHeader.DataLength);
can1_Analyze();
break;
}
}
}
}
can_DeInit(); /* 关闭CAN时钟 */
}
/*
*********************************************************************************************************
* : InitFormCAN
* :
*
* :
*********************************************************************************************************
*/
static void InitFormCAN(void)
{
/* 分组框标题字体 */
FormCAN->FontBox.FontCode = FC_ST_16;
FormCAN->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormCAN->FontBox.FrontColor = CL_BLACK;
FormCAN->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormCAN->FontBlack.FontCode = FC_ST_16;
FormCAN->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormCAN->FontBlack.FrontColor = CL_BLACK;
FormCAN->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormCAN->FontBlue.FontCode = FC_ST_16;
FormCAN->FontBlue.BackColor = CL_BTN_FACE;
FormCAN->FontBlue.FrontColor = CL_BLUE;
FormCAN->FontBlue.Space = 0;
/* 按钮字体 */
FormCAN->FontBtn.FontCode = FC_ST_16;
FormCAN->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormCAN->FontBtn.FrontColor = CL_BLACK;
FormCAN->FontBtn.Space = 0;
/* 分组框 */
FormCAN->Box1.Left = BOX1_X;
FormCAN->Box1.Top = BOX1_Y;
FormCAN->Box1.Height = BOX1_H;
FormCAN->Box1.Width = BOX1_W;
FormCAN->Box1.pCaption = BOX1_TEXT;
FormCAN->Box1.Font = &FormCAN->FontBox;
/* 静态标签 */
FormCAN->Label1.Left = LABEL1_X;
FormCAN->Label1.Top = LABEL1_Y;
FormCAN->Label1.MaxLen = 0;
FormCAN->Label1.pCaption = LABEL1_TEXT;
FormCAN->Label1.Font = &FormCAN->FontBlack;
FormCAN->Label3.Left = LABEL3_X;
FormCAN->Label3.Top = LABEL3_Y;
FormCAN->Label3.MaxLen = 0;
FormCAN->Label3.pCaption = LABEL3_TEXT;
FormCAN->Label3.Font = &FormCAN->FontBlack;
FormCAN->Label5.Left = LABEL5_X;
FormCAN->Label5.Top = LABEL5_Y;
FormCAN->Label5.MaxLen = 0;
FormCAN->Label5.pCaption = LABEL5_TEXT;
FormCAN->Label5.Font = &FormCAN->FontBlack;
/* 动态标签 */
FormCAN->Label2.Left = LABEL2_X;
FormCAN->Label2.Top = LABEL2_Y;
FormCAN->Label2.MaxLen = 0;
FormCAN->Label2.pCaption = LABEL2_TEXT;
FormCAN->Label2.Font = &FormCAN->FontBlue;
FormCAN->Label4.Left = LABEL4_X;
FormCAN->Label4.Top = LABEL4_Y;
FormCAN->Label4.MaxLen = 0;
FormCAN->Label4.pCaption = LABEL4_TEXT;
FormCAN->Label4.Font = &FormCAN->FontBlue;
FormCAN->Label6.Left = LABEL6_X;
FormCAN->Label6.Top = LABEL6_Y;
FormCAN->Label6.MaxLen = 0;
FormCAN->Label6.pCaption = LABEL6_TEXT;
FormCAN->Label6.Font = &FormCAN->FontBlue;
/* 按钮 */
FormCAN->BtnRet.Left = BTN_RET_X;
FormCAN->BtnRet.Top = BTN_RET_Y;
FormCAN->BtnRet.Height = BTN_RET_H;
FormCAN->BtnRet.Width = BTN_RET_W;
FormCAN->BtnRet.pCaption = BTN_RET_TEXT;
FormCAN->BtnRet.Font = &FormCAN->FontBtn;
FormCAN->BtnRet.Focus = 0;
FormCAN->Btn1.Left = BTN1_X;
FormCAN->Btn1.Top = BTN1_Y;
FormCAN->Btn1.Height = BTN1_H;
FormCAN->Btn1.Width = BTN1_W;
FormCAN->Btn1.pCaption = BTN1_TEXT;
FormCAN->Btn1.Font = &FormCAN->FontBtn;
FormCAN->Btn1.Focus = 0;
FormCAN->Btn2.Left = BTN2_X;
FormCAN->Btn2.Top = BTN2_Y;
FormCAN->Btn2.Height = BTN2_H;
FormCAN->Btn2.Width = BTN2_W;
FormCAN->Btn2.pCaption = BTN2_TEXT;
FormCAN->Btn2.Font = &FormCAN->FontBtn;
FormCAN->Btn2.Focus = 0;
FormCAN->Btn3.Left = BTN3_X;
FormCAN->Btn3.Top = BTN3_Y;
FormCAN->Btn3.Height = BTN3_H;
FormCAN->Btn3.Width = BTN3_W;
FormCAN->Btn3.pCaption = BTN3_TEXT;
FormCAN->Btn3.Font = &FormCAN->FontBtn;
FormCAN->Btn3.Focus = 0;
FormCAN->Btn4.Left = BTN4_X;
FormCAN->Btn4.Top = BTN4_Y;
FormCAN->Btn4.Height = BTN4_H;
FormCAN->Btn4.Width = BTN4_W;
FormCAN->Btn4.pCaption = BTN4_TEXT;
FormCAN->Btn4.Font = &FormCAN->FontBtn;
FormCAN->Btn4.Focus = 0;
FormCAN->Btn5.Left = BTN5_X;
FormCAN->Btn5.Top = BTN5_Y;
FormCAN->Btn5.Height = BTN5_H;
FormCAN->Btn5.Width = BTN5_W;
FormCAN->Btn5.pCaption = BTN5_TEXT;
FormCAN->Btn5.Font = &FormCAN->FontBtn;
FormCAN->Btn5.Focus = 0;
FormCAN->Btn6.Left = BTN6_X;
FormCAN->Btn6.Top = BTN6_Y;
FormCAN->Btn6.Height = BTN6_H;
FormCAN->Btn6.Width = BTN6_W;
FormCAN->Btn6.pCaption = BTN6_TEXT;
FormCAN->Btn6.Font = &FormCAN->FontBtn;
FormCAN->Btn6.Focus = 0;
{
FormCAN->LblInfo1.Left = LBL_INFO1_X;
FormCAN->LblInfo1.Top = LBL_INFO1_Y;
FormCAN->LblInfo1.MaxLen = 0;
FormCAN->LblInfo1.pCaption = LBL_INFO1_TEXT;
FormCAN->LblInfo1.Font = &FormCAN->FontBlack;
FormCAN->LblInfo2.Left = LBL_INFO2_X;
FormCAN->LblInfo2.Top = LBL_INFO2_Y;
FormCAN->LblInfo2.MaxLen = 0;
FormCAN->LblInfo2.pCaption = LBL_INFO2_TEXT;
FormCAN->LblInfo2.Font = &FormCAN->FontBlack;
}
}
/*
*********************************************************************************************************
* : DispFormCAN
* :
* :
* :
*********************************************************************************************************
*/
static void DispFormCAN(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormCAN->Box1);
LCD_DrawLabel(&FormCAN->Label1);
LCD_DrawLabel(&FormCAN->Label3);
LCD_DrawLabel(&FormCAN->Label5);
LCD_DrawLabel(&FormCAN->Label2);
LCD_DrawLabel(&FormCAN->Label4);
LCD_DrawLabel(&FormCAN->Label6);
/* 按钮 */
LCD_DrawButton(&FormCAN->Btn1);
LCD_DrawButton(&FormCAN->Btn2);
LCD_DrawButton(&FormCAN->Btn3);
LCD_DrawButton(&FormCAN->Btn4);
LCD_DrawButton(&FormCAN->Btn5);
LCD_DrawButton(&FormCAN->Btn6);
LCD_DrawLabel(&FormCAN->LblInfo1);
LCD_DrawLabel(&FormCAN->LblInfo2);
LCD_DrawButton(&FormCAN->BtnRet);
}
/*
*********************************************************************************************************
* : DispLabelTx
* :
* : _Baud
* _
* :
*********************************************************************************************************
*/
static void DispLabelBaud(uint32_t _Baud)
{
char buf[10];
sprintf(buf, "%d", _Baud);
/* 动态标签 */
FormCAN->Label4.pCaption = buf;
LCD_DrawLabel(&FormCAN->Label4);
}
/*
*********************************************************************************************************
* : DispLabelTx
* :
* : _buf
* _
* :
*********************************************************************************************************
*/
static void DispLabelRx(uint8_t *_buf, uint8_t _len)
{
char disp_buf[32];
uint8_t len;
len = _len;
if (len > sizeof(disp_buf) / 3)
{
len = sizeof(disp_buf) / 3;
}
HexToAscll(_buf, disp_buf, len);
/* 动态标签 */
FormCAN->Label6.pCaption = disp_buf;
LCD_DrawLabel(&FormCAN->Label6);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,763 +0,0 @@
/*
*********************************************************************************************************
*
* : DAC8501 DAC8562模块测试界面
* : form_dac8501.c
* : V1.0
* : DAC8501模块和DAC8562模块
* :
*
* v1.0 2014-10-15 armfly
*
* Copyright (C), 2014-2015, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_dac8501.h"
#include "math.h"
#define TIMx TIM5
#define TIMx_IRQHandler TIM5_IRQHandler
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 黑色 */
FONT_T FontBlue; /* 蓝色 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
BUTTON_T BtnRet;
BUTTON_T Btn1;
BUTTON_T Btn2;
BUTTON_T Btn3;
BUTTON_T Btn4;
BUTTON_T Btn5;
BUTTON_T Btn6;
BUTTON_T Btn7;
BUTTON_T Btn8;
BUTTON_T Btn9;
BUTTON_T Btn10;
BUTTON_T Btn11;
BUTTON_T Btn12;
BUTTON_T Btn13;
BUTTON_T Btn14;
BUTTON_T Btn15;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
LABEL_T Label6;
uint16_t DacValue; /* DAC数据 */
int32_t Voltage; /* 输出电压 */
} Form8501_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - 53)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_T "DAC8501 双路DAC模块(16bit, 0 -> 5V)"
#define BTN1_H 32
#define BTN1_W 105
/* 第1行按钮坐标 */
#define BTN1_X (BOX1_X + 10)
#define BTN1_Y (BOX1_Y + 20)
#define BTN1_T "0V"
#define BTN2_H BTN1_H
#define BTN2_W BTN1_W
#define BTN2_X (BTN1_X + BTN1_W + 10)
#define BTN2_Y BTN1_Y
#define BTN2_T "2.5V"
#define BTN3_H BTN1_H
#define BTN3_W BTN1_W
#define BTN3_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN3_Y BTN1_Y
#define BTN3_T "5.0V"
/* 第2行按钮坐标 */
#define BTN4_H BTN1_H
#define BTN4_W BTN1_W
#define BTN4_X BTN1_X
#define BTN4_Y (BTN1_Y + BTN1_H + 10)
#define BTN4_T "DAC值+1"
#define BTN5_H BTN1_H
#define BTN5_W BTN1_W
#define BTN5_X (BTN1_X + 1 * (BTN1_W + 10))
#define BTN5_Y BTN4_Y
#define BTN5_T "DAC值-1"
#define BTN6_H BTN1_H
#define BTN6_W BTN1_W
#define BTN6_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN6_Y BTN4_Y
#define BTN6_T "DAC值+100"
#define BTN7_H BTN1_H
#define BTN7_W BTN1_W
#define BTN7_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN7_Y BTN4_Y
#define BTN7_T "DAC值-100"
/* 第3行按钮坐标 */
#define BTN8_H BTN1_H
#define BTN8_W BTN1_W
#define BTN8_X BTN1_X
#define BTN8_Y (BTN1_Y + 2 * (BTN1_H + 10))
#define BTN8_T "电压+1mV"
#define BTN9_H BTN1_H
#define BTN9_W BTN1_W
#define BTN9_X (BTN1_X + 1 * (BTN1_W + 10))
#define BTN9_Y BTN8_Y
#define BTN9_T "电压-1mV"
#define BTN10_H BTN1_H
#define BTN10_W BTN1_W
#define BTN10_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN10_Y BTN8_Y
#define BTN10_T "电压+100mV"
#define BTN11_H BTN1_H
#define BTN11_W BTN1_W
#define BTN11_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN11_Y BTN8_Y
#define BTN11_T "电压-100mV"
/* 第4行按钮坐标 */
#define BTN12_H BTN1_H
#define BTN12_W BTN1_W
#define BTN12_X BTN1_X
#define BTN12_Y (BTN1_Y + 3 * (BTN1_H + 10))
#define BTN12_T "同步正弦波"
#define BTN13_H BTN1_H
#define BTN13_W BTN1_W
#define BTN13_X (BTN1_X + 1 * (BTN1_W + 10))
#define BTN13_Y BTN12_Y
#define BTN13_T "相差90度正弦"
#define BTN14_H BTN1_H
#define BTN14_W BTN1_W
#define BTN14_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN14_Y BTN12_Y
#define BTN14_T "相差180度正弦"
#define BTN15_H BTN1_H
#define BTN15_W BTN1_W
#define BTN15_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN15_Y BTN12_Y
#define BTN15_T "停止正弦输出"
#define LBL1_X BOX1_X + 5
#define LBL1_Y 190
#define LBL1_T "当前DAC值:"
#define LBL2_X LBL1_X + 85
#define LBL2_Y LBL1_Y
#define LBL2_T ""
#define LBL3_X LBL1_X
#define LBL3_Y LBL1_Y + 20
#define LBL3_T " 输出电压:"
#define LBL4_X LBL3_X + 85
#define LBL4_Y LBL3_Y
#define LBL4_T " "
/* 按钮 */
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 80
#define BTN_RET_X (g_LcdWidth - BTN_RET_W - 8)
#define BTN_RET_Y (g_LcdHeight - BTN_RET_H - 4)
#define BTN_RET_T "返回"
static void InitForm8501(void);
static void DispForm8501(void);
static void DispDacValue(void);
static void DispDacVoltage(void);
static void MakeSinTable(uint16_t *_pBuf, uint16_t _usSamples, uint16_t _usBottom, uint16_t _usTop);
Form8501_T *Form8501;
#define DAC_OUT_FREQ 10000 /* DAC 输出样本频率 10KHz */
#define WAVE_SAMPLES 200 /* 每周期样本数, 越大波形幅度越细腻,但是输出最大频率会降低 */
static uint16_t s_WaveBuf[WAVE_SAMPLES];
static uint16_t s_WavePos1, s_WavePos2;
/*
*********************************************************************************************************
* : InitForm8501
* :
*
* :
*********************************************************************************************************
*/
static void InitForm8501(void)
{
/* 分组框标题字体 */
Form8501->FontBox.FontCode = FC_ST_16;
Form8501->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
Form8501->FontBox.FrontColor = CL_BLACK;
Form8501->FontBox.Space = 0;
/* 字体1 用于静止标签 */
Form8501->FontBlack.FontCode = FC_ST_16;
Form8501->FontBlack.BackColor = CL_MASK; /* 透明色 */
Form8501->FontBlack.FrontColor = CL_BLACK;
Form8501->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
Form8501->FontBlue.FontCode = FC_ST_16;
Form8501->FontBlue.BackColor = CL_BTN_FACE;
Form8501->FontBlue.FrontColor = CL_BLUE;
Form8501->FontBlue.Space = 0;
/* 按钮字体 */
Form8501->FontBtn.FontCode = FC_ST_16;
Form8501->FontBtn.BackColor = CL_MASK; /* 透明背景 */
Form8501->FontBtn.FrontColor = CL_BLACK;
Form8501->FontBtn.Space = 0;
/* 分组框 */
Form8501->Box1.Left = BOX1_X;
Form8501->Box1.Top = BOX1_Y;
Form8501->Box1.Height = BOX1_H;
Form8501->Box1.Width = BOX1_W;
Form8501->Box1.pCaption = BOX1_T;
Form8501->Box1.Font = &Form8501->FontBox;
/* 标签 */
Form8501->Label1.Left = LBL1_X;
Form8501->Label1.Top = LBL1_Y;
Form8501->Label1.MaxLen = 0;
Form8501->Label1.pCaption = LBL1_T;
Form8501->Label1.Font = &Form8501->FontBlack;
Form8501->Label2.Left = LBL2_X;
Form8501->Label2.Top = LBL2_Y;
Form8501->Label2.MaxLen = 0;
Form8501->Label2.pCaption = LBL2_T;
Form8501->Label2.Font = &Form8501->FontBlue;
Form8501->Label3.Left = LBL3_X;
Form8501->Label3.Top = LBL3_Y;
Form8501->Label3.MaxLen = 0;
Form8501->Label3.pCaption = LBL3_T;
Form8501->Label3.Font = &Form8501->FontBlack;
Form8501->Label4.Left = LBL4_X;
Form8501->Label4.Top = LBL4_Y;
Form8501->Label4.MaxLen = 0;
Form8501->Label4.pCaption = LBL4_T;
Form8501->Label4.Font = &Form8501->FontBlue;
/* 按钮 */
Form8501->BtnRet.Left = BTN_RET_X;
Form8501->BtnRet.Top = BTN_RET_Y;
Form8501->BtnRet.Height = BTN_RET_H;
Form8501->BtnRet.Width = BTN_RET_W;
Form8501->BtnRet.pCaption = BTN_RET_T;
Form8501->BtnRet.Font = &Form8501->FontBtn;
Form8501->BtnRet.Focus = 0;
Form8501->Btn1.Left = BTN1_X;
Form8501->Btn1.Top = BTN1_Y;
Form8501->Btn1.Height = BTN1_H;
Form8501->Btn1.Width = BTN1_W;
Form8501->Btn1.pCaption = BTN1_T;
Form8501->Btn1.Font = &Form8501->FontBtn;
Form8501->Btn1.Focus = 0;
Form8501->Btn2.Left = BTN2_X;
Form8501->Btn2.Top = BTN2_Y;
Form8501->Btn2.Height = BTN2_H;
Form8501->Btn2.Width = BTN2_W;
Form8501->Btn2.pCaption = BTN2_T;
Form8501->Btn2.Font = &Form8501->FontBtn;
Form8501->Btn2.Focus = 0;
Form8501->Btn3.Left = BTN3_X;
Form8501->Btn3.Top = BTN3_Y;
Form8501->Btn3.Height = BTN3_H;
Form8501->Btn3.Width = BTN3_W;
Form8501->Btn3.pCaption = BTN3_T;
Form8501->Btn3.Font = &Form8501->FontBtn;
Form8501->Btn3.Focus = 0;
Form8501->Btn4.Left = BTN4_X;
Form8501->Btn4.Top = BTN4_Y;
Form8501->Btn4.Height = BTN4_H;
Form8501->Btn4.Width = BTN4_W;
Form8501->Btn4.pCaption = BTN4_T;
Form8501->Btn4.Font = &Form8501->FontBtn;
Form8501->Btn4.Focus = 0;
Form8501->Btn5.Left = BTN5_X;
Form8501->Btn5.Top = BTN5_Y;
Form8501->Btn5.Height = BTN5_H;
Form8501->Btn5.Width = BTN5_W;
Form8501->Btn5.pCaption = BTN5_T;
Form8501->Btn5.Font = &Form8501->FontBtn;
Form8501->Btn5.Focus = 0;
Form8501->Btn6.Left = BTN6_X;
Form8501->Btn6.Top = BTN6_Y;
Form8501->Btn6.Height = BTN6_H;
Form8501->Btn6.Width = BTN6_W;
Form8501->Btn6.pCaption = BTN6_T;
Form8501->Btn6.Font = &Form8501->FontBtn;
Form8501->Btn6.Focus = 0;
Form8501->Btn7.Left = BTN7_X;
Form8501->Btn7.Top = BTN7_Y;
Form8501->Btn7.Height = BTN7_H;
Form8501->Btn7.Width = BTN7_W;
Form8501->Btn7.pCaption = BTN7_T;
Form8501->Btn7.Font = &Form8501->FontBtn;
Form8501->Btn7.Focus = 0;
Form8501->Btn8.Left = BTN8_X;
Form8501->Btn8.Top = BTN8_Y;
Form8501->Btn8.Height = BTN8_H;
Form8501->Btn8.Width = BTN8_W;
Form8501->Btn8.pCaption = BTN8_T;
Form8501->Btn8.Font = &Form8501->FontBtn;
Form8501->Btn8.Focus = 0;
Form8501->Btn9.Left = BTN9_X;
Form8501->Btn9.Top = BTN9_Y;
Form8501->Btn9.Height = BTN9_H;
Form8501->Btn9.Width = BTN9_W;
Form8501->Btn9.pCaption = BTN9_T;
Form8501->Btn9.Font = &Form8501->FontBtn;
Form8501->Btn9.Focus = 0;
Form8501->Btn10.Left = BTN10_X;
Form8501->Btn10.Top = BTN10_Y;
Form8501->Btn10.Height = BTN10_H;
Form8501->Btn10.Width = BTN10_W;
Form8501->Btn10.pCaption = BTN10_T;
Form8501->Btn10.Font = &Form8501->FontBtn;
Form8501->Btn10.Focus = 0;
Form8501->Btn11.Left = BTN11_X;
Form8501->Btn11.Top = BTN11_Y;
Form8501->Btn11.Height = BTN11_H;
Form8501->Btn11.Width = BTN11_W;
Form8501->Btn11.pCaption = BTN11_T;
Form8501->Btn11.Font = &Form8501->FontBtn;
Form8501->Btn11.Focus = 0;
Form8501->Btn12.Left = BTN12_X;
Form8501->Btn12.Top = BTN12_Y;
Form8501->Btn12.Height = BTN12_H;
Form8501->Btn12.Width = BTN12_W;
Form8501->Btn12.pCaption = BTN12_T;
Form8501->Btn12.Font = &Form8501->FontBtn;
Form8501->Btn12.Focus = 0;
Form8501->Btn13.Left = BTN13_X;
Form8501->Btn13.Top = BTN13_Y;
Form8501->Btn13.Height = BTN13_H;
Form8501->Btn13.Width = BTN13_W;
Form8501->Btn13.pCaption = BTN13_T;
Form8501->Btn13.Font = &Form8501->FontBtn;
Form8501->Btn13.Focus = 0;
Form8501->Btn14.Left = BTN14_X;
Form8501->Btn14.Top = BTN14_Y;
Form8501->Btn14.Height = BTN14_H;
Form8501->Btn14.Width = BTN14_W;
Form8501->Btn14.pCaption = BTN14_T;
Form8501->Btn14.Font = &Form8501->FontBtn;
Form8501->Btn14.Focus = 0;
Form8501->Btn15.Left = BTN15_X;
Form8501->Btn15.Top = BTN15_Y;
Form8501->Btn15.Height = BTN15_H;
Form8501->Btn15.Width = BTN15_W;
Form8501->Btn15.pCaption = BTN15_T;
Form8501->Btn15.Font = &Form8501->FontBtn;
Form8501->Btn15.Focus = 0;
}
/*
*********************************************************************************************************
* : FormMainDAC8501
* : DAC8501 DAC8562测试主程序
* :
* :
*********************************************************************************************************
*/
void FormMainDAC8501(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
Form8501_T form;
uint8_t fDispVolt = 1;
Form8501 = &form;
InitForm8501();
DispForm8501();
bsp_InitDAC8501();
MakeSinTable(s_WaveBuf, WAVE_SAMPLES, 0, 65535);
Form8501->DacValue = 0;
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
if (fDispVolt)
{
fDispVolt = 0;
DAC8501_SetDacData(0, Form8501->DacValue);
DAC8501_SetDacData(1, Form8501->DacValue);
DispDacValue();
DispDacVoltage();
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (LCD_ButtonTouchDown(&Form8501->BtnRet, tpX, tpY))
{
//fQuit = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn1, tpX, tpY))
{
Form8501->DacValue = 0;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn2, tpX, tpY))
{
Form8501->DacValue = 32767;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn3, tpX, tpY))
{
Form8501->DacValue = 65535;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn4, tpX, tpY))
{
Form8501->DacValue++;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn5, tpX, tpY))
{
Form8501->DacValue--;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn6, tpX, tpY))
{
Form8501->DacValue += 100;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn7, tpX, tpY))
{
Form8501->DacValue -= 100;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn8, tpX, tpY))
{
/* +1mV */
Form8501->Voltage = DAC8501_DacToVoltage(Form8501->DacValue);
Form8501->Voltage += 10;
Form8501->DacValue = DAC8501_VoltageToDac(Form8501->Voltage);
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn9, tpX, tpY))
{
/* -1mV */
Form8501->Voltage = DAC8501_DacToVoltage(Form8501->DacValue);
Form8501->Voltage -= 10;
Form8501->DacValue = DAC8501_VoltageToDac(Form8501->Voltage);
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn10, tpX, tpY))
{
/* +100mV */
Form8501->Voltage = DAC8501_DacToVoltage(Form8501->DacValue);
Form8501->Voltage += 1000;
Form8501->DacValue = DAC8501_VoltageToDac(Form8501->Voltage);
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn11, tpX, tpY))
{
/* -100mV */
Form8501->Voltage = DAC8501_DacToVoltage(Form8501->DacValue);
Form8501->Voltage -= 1000;
Form8501->DacValue = DAC8501_VoltageToDac(Form8501->Voltage);
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn12, tpX, tpY))
{
bsp_SetTIMforInt(TIMx, DAC_OUT_FREQ, 0, 0);
s_WavePos1 = 0; /* 波形1超前 0度 */
s_WavePos2 = 0;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn13, tpX, tpY))
{
bsp_SetTIMforInt(TIM4, DAC_OUT_FREQ, 0, 0);
s_WavePos1 = WAVE_SAMPLES / 4; /* 波形1超前 90度 */
s_WavePos2 = 0;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn14, tpX, tpY))
{
bsp_SetTIMforInt(TIM4, DAC_OUT_FREQ, 0, 0);
s_WavePos1 = WAVE_SAMPLES / 2; /* 波形1超前 180度 */
s_WavePos2 = 0;
}
else if (LCD_ButtonTouchDown(&Form8501->Btn15, tpX, tpY))
{
bsp_SetTIMforInt(TIM4, 0, 0, 0); /* 关闭用于波形发生的定时器 */
fDispVolt = 1;
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (LCD_ButtonTouchRelease(&Form8501->BtnRet, tpX, tpY))
{
fQuit = 1; /* 返回 */
}
else
{
LCD_ButtonTouchRelease(&Form8501->BtnRet, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn1, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn2, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn3, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn4, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn5, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn6, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn7, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn8, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn9, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn10, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn11, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn12, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn13, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn14, tpX, tpY);
LCD_ButtonTouchRelease(&Form8501->Btn15, tpX, tpY);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键 + 1*/
break;
case KEY_DOWN_K2: /* K2键 - 1 */
break;
case KEY_DOWN_K3: /* K3键 - 清0 */
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
bsp_SetTIMforInt(TIM4, 0, 0, 0); /* 关闭用于波形发生的定时器 */
}
/*
*********************************************************************************************************
* : DispForm8501
* :
* :
* :
*********************************************************************************************************
*/
static void DispForm8501(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&Form8501->Box1);
LCD_DrawLabel(&Form8501->Label1);
LCD_DrawLabel(&Form8501->Label2);
LCD_DrawLabel(&Form8501->Label3);
LCD_DrawLabel(&Form8501->Label4);
/* 按钮 */
LCD_DrawButton(&Form8501->Btn1);
LCD_DrawButton(&Form8501->Btn2);
LCD_DrawButton(&Form8501->Btn3);
LCD_DrawButton(&Form8501->Btn4);
LCD_DrawButton(&Form8501->Btn5);
LCD_DrawButton(&Form8501->Btn6);
LCD_DrawButton(&Form8501->Btn5);
LCD_DrawButton(&Form8501->Btn6);
LCD_DrawButton(&Form8501->Btn7);
LCD_DrawButton(&Form8501->Btn8);
LCD_DrawButton(&Form8501->Btn9);
LCD_DrawButton(&Form8501->Btn10);
LCD_DrawButton(&Form8501->Btn11);
LCD_DrawButton(&Form8501->Btn12);
LCD_DrawButton(&Form8501->Btn13);
LCD_DrawButton(&Form8501->Btn14);
LCD_DrawButton(&Form8501->Btn15);
LCD_DrawButton(&Form8501->BtnRet);
}
/*
*********************************************************************************************************
* : DispDacValue
* : DAC数值
* :
* :
*********************************************************************************************************
*/
static void DispDacValue(void)
{
char buf[10];
sprintf(buf, "%d", Form8501->DacValue);
Form8501->Label2.pCaption = buf;
LCD_DrawLabel(&Form8501->Label2);
}
/*
*********************************************************************************************************
* : DispDacVoltage
* :
* :
* _
* :
*********************************************************************************************************
*/
static void DispDacVoltage(void)
{
char buf[10];
Form8501->Voltage = DAC8501_DacToVoltage(Form8501->DacValue);
sprintf(buf, "%d.%04dV", Form8501->Voltage / 10000, Form8501->Voltage % 10000);
Form8501->Label4.pCaption = buf;
LCD_DrawLabel(&Form8501->Label4);
}
/*
*********************************************************************************************************
* : MakeSinTable
* :
* : _pBuf :
* _usSamples : 32
* _usBottom :
* _usTop :
* :
*********************************************************************************************************
*/
static void MakeSinTable(uint16_t *_pBuf, uint16_t _usSamples, uint16_t _usBottom, uint16_t _usTop)
{
uint16_t i;
uint16_t mid; /* 中值 */
uint16_t att; /* 幅度 */
mid = (_usBottom + _usTop) / 2; /* 0位的值 */
att = (_usTop - _usBottom) / 2; /* 正弦波幅度峰峰值除以2 */
for (i = 0; i < _usSamples; i++)
{
_pBuf[i] = mid + (int32_t)(att * sin((i * 2 * 3.14159) / _usSamples));
}
}
/*
*********************************************************************************************************
* : TIM4_IRQHandler
* : TIM4
* :
* :
*********************************************************************************************************
*/
void TIMx_IRQHandler(void)
{
uint16_t dac;
if (READ_BIT(TIMx->SR, TIM_IT_UPDATE) != 0)
{
CLEAR_BIT(TIMx->SR, TIM_IT_UPDATE);
/* 3.5寸屏如果触摸程序正在访问SPI触摸芯片TSC2046则丢弃本次 */
if (bsp_SpiBusBusy())
{
return;
}
/* 波形1 */
dac = s_WaveBuf[s_WavePos1++];
if (s_WavePos1 >= WAVE_SAMPLES)
{
s_WavePos1 = 0;
}
DAC8501_SetDacData(0, dac); /* 改变第1通道 DAC输出电压 */
/* 波形1 */
dac = s_WaveBuf[s_WavePos2++];
if (s_WavePos2 >= WAVE_SAMPLES)
{
s_WavePos2 = 0;
}
DAC8501_SetDacData(1, dac); /* 改变第2通道 DAC输出电压 */
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,762 +0,0 @@
/*
*********************************************************************************************************
*
* : DAC8562模块测试界面
* : form_dac8562.c
* : V1.0
* : DAC8562模块
* :
*
* v1.0 2014-10-15 armfly
*
* Copyright (C), 2014-2015, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_dac8562.h"
#include "math.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 黑色 */
FONT_T FontBlue; /* 蓝色 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
BUTTON_T BtnRet;
BUTTON_T Btn1;
BUTTON_T Btn2;
BUTTON_T Btn3;
BUTTON_T Btn4;
BUTTON_T Btn5;
BUTTON_T Btn6;
BUTTON_T Btn7;
BUTTON_T Btn8;
BUTTON_T Btn9;
BUTTON_T Btn10;
BUTTON_T Btn11;
BUTTON_T Btn12;
BUTTON_T Btn13;
BUTTON_T Btn14;
BUTTON_T Btn15;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
LABEL_T Label6;
uint16_t DacValue; /* DAC数据 */
int32_t Voltage; /* 输出电压 */
} Form8562_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - 53)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_T "DAC8562 双路DAC模块(16bit, -10V -> +10V)"
#define BTN1_H 32
#define BTN1_W 105
/* 第1行按钮坐标 */
#define BTN1_X (BOX1_X + 10)
#define BTN1_Y (BOX1_Y + 20)
#define BTN1_T "-10V"
#define BTN2_H BTN1_H
#define BTN2_W BTN1_W
#define BTN2_X (BTN1_X + BTN1_W + 10)
#define BTN2_Y BTN1_Y
#define BTN2_T "0V"
#define BTN3_H BTN1_H
#define BTN3_W BTN1_W
#define BTN3_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN3_Y BTN1_Y
#define BTN3_T "+10V"
/* 第2行按钮坐标 */
#define BTN4_H BTN1_H
#define BTN4_W BTN1_W
#define BTN4_X BTN1_X
#define BTN4_Y (BTN1_Y + BTN1_H + 10)
#define BTN4_T "DAC值+1"
#define BTN5_H BTN1_H
#define BTN5_W BTN1_W
#define BTN5_X (BTN1_X + 1 * (BTN1_W + 10))
#define BTN5_Y BTN4_Y
#define BTN5_T "DAC值-1"
#define BTN6_H BTN1_H
#define BTN6_W BTN1_W
#define BTN6_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN6_Y BTN4_Y
#define BTN6_T "DAC值+100"
#define BTN7_H BTN1_H
#define BTN7_W BTN1_W
#define BTN7_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN7_Y BTN4_Y
#define BTN7_T "DAC值-100"
/* 第3行按钮坐标 */
#define BTN8_H BTN1_H
#define BTN8_W BTN1_W
#define BTN8_X BTN1_X
#define BTN8_Y (BTN1_Y + 2 * (BTN1_H + 10))
#define BTN8_T "电压+1mV"
#define BTN9_H BTN1_H
#define BTN9_W BTN1_W
#define BTN9_X (BTN1_X + 1 * (BTN1_W + 10))
#define BTN9_Y BTN8_Y
#define BTN9_T "电压-1mV"
#define BTN10_H BTN1_H
#define BTN10_W BTN1_W
#define BTN10_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN10_Y BTN8_Y
#define BTN10_T "电压+100mV"
#define BTN11_H BTN1_H
#define BTN11_W BTN1_W
#define BTN11_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN11_Y BTN8_Y
#define BTN11_T "电压-100mV"
/* 第4行按钮坐标 */
#define BTN12_H BTN1_H
#define BTN12_W BTN1_W
#define BTN12_X BTN1_X
#define BTN12_Y (BTN1_Y + 3 * (BTN1_H + 10))
#define BTN12_T "同步正弦波"
#define BTN13_H BTN1_H
#define BTN13_W BTN1_W
#define BTN13_X (BTN1_X + 1 * (BTN1_W + 10))
#define BTN13_Y BTN12_Y
#define BTN13_T "2路90度正弦"
#define BTN14_H BTN1_H
#define BTN14_W BTN1_W
#define BTN14_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN14_Y BTN12_Y
#define BTN14_T "2路180度正弦"
#define BTN15_H BTN1_H
#define BTN15_W BTN1_W
#define BTN15_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN15_Y BTN12_Y
#define BTN15_T "停止正弦输出"
#define LBL1_X BOX1_X + 5
#define LBL1_Y 190
#define LBL1_T "当前DAC值:"
#define LBL2_X LBL1_X + 85
#define LBL2_Y LBL1_Y
#define LBL2_T ""
#define LBL3_X LBL1_X
#define LBL3_Y LBL1_Y + 20
#define LBL3_T " 输出电压:"
#define LBL4_X LBL3_X + 85
#define LBL4_Y LBL3_Y
#define LBL4_T " "
/* 按钮 */
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 80
#define BTN_RET_X (g_LcdWidth - BTN_RET_W - 8)
#define BTN_RET_Y (g_LcdHeight - BTN_RET_H - 4)
#define BTN_RET_T "返回"
static void InitForm8562(void);
static void DispForm8562(void);
static void DispDacValue(void);
static void DispDacVoltage(void);
static void MakeSinTable(uint16_t *_pBuf, uint16_t _usSamples, uint16_t _usBottom, uint16_t _usTop);
Form8562_T *Form8562;
#define DAC_OUT_FREQ 10000 /* DAC 输出样本频率 10KHz */
#define WAVE_SAMPLES 200 /* 每周期样本数, 越大波形幅度越细腻,但是输出最大频率会降低 */
static uint16_t s_WaveBuf[WAVE_SAMPLES];
static uint16_t s_WavePos1, s_WavePos2;
/*
*********************************************************************************************************
* : InitForm8562
* :
*
* :
*********************************************************************************************************
*/
static void InitForm8562(void)
{
/* 分组框标题字体 */
Form8562->FontBox.FontCode = FC_ST_16;
Form8562->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
Form8562->FontBox.FrontColor = CL_BLACK;
Form8562->FontBox.Space = 0;
/* 字体1 用于静止标签 */
Form8562->FontBlack.FontCode = FC_ST_16;
Form8562->FontBlack.BackColor = CL_MASK; /* 透明色 */
Form8562->FontBlack.FrontColor = CL_BLACK;
Form8562->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
Form8562->FontBlue.FontCode = FC_ST_16;
Form8562->FontBlue.BackColor = CL_BTN_FACE;
Form8562->FontBlue.FrontColor = CL_BLUE;
Form8562->FontBlue.Space = 0;
/* 按钮字体 */
Form8562->FontBtn.FontCode = FC_ST_16;
Form8562->FontBtn.BackColor = CL_MASK; /* 透明背景 */
Form8562->FontBtn.FrontColor = CL_BLACK;
Form8562->FontBtn.Space = 0;
/* 分组框 */
Form8562->Box1.Left = BOX1_X;
Form8562->Box1.Top = BOX1_Y;
Form8562->Box1.Height = BOX1_H;
Form8562->Box1.Width = BOX1_W;
Form8562->Box1.pCaption = BOX1_T;
Form8562->Box1.Font = &Form8562->FontBox;
/* 标签 */
Form8562->Label1.Left = LBL1_X;
Form8562->Label1.Top = LBL1_Y;
Form8562->Label1.MaxLen = 0;
Form8562->Label1.pCaption = LBL1_T;
Form8562->Label1.Font = &Form8562->FontBlack;
Form8562->Label2.Left = LBL2_X;
Form8562->Label2.Top = LBL2_Y;
Form8562->Label2.MaxLen = 0;
Form8562->Label2.pCaption = LBL2_T;
Form8562->Label2.Font = &Form8562->FontBlue;
Form8562->Label3.Left = LBL3_X;
Form8562->Label3.Top = LBL3_Y;
Form8562->Label3.MaxLen = 0;
Form8562->Label3.pCaption = LBL3_T;
Form8562->Label3.Font = &Form8562->FontBlack;
Form8562->Label4.Left = LBL4_X;
Form8562->Label4.Top = LBL4_Y;
Form8562->Label4.MaxLen = 0;
Form8562->Label4.pCaption = LBL4_T;
Form8562->Label4.Font = &Form8562->FontBlue;
/* 按钮 */
Form8562->BtnRet.Left = BTN_RET_X;
Form8562->BtnRet.Top = BTN_RET_Y;
Form8562->BtnRet.Height = BTN_RET_H;
Form8562->BtnRet.Width = BTN_RET_W;
Form8562->BtnRet.pCaption = BTN_RET_T;
Form8562->BtnRet.Font = &Form8562->FontBtn;
Form8562->BtnRet.Focus = 0;
Form8562->Btn1.Left = BTN1_X;
Form8562->Btn1.Top = BTN1_Y;
Form8562->Btn1.Height = BTN1_H;
Form8562->Btn1.Width = BTN1_W;
Form8562->Btn1.pCaption = BTN1_T;
Form8562->Btn1.Font = &Form8562->FontBtn;
Form8562->Btn1.Focus = 0;
Form8562->Btn2.Left = BTN2_X;
Form8562->Btn2.Top = BTN2_Y;
Form8562->Btn2.Height = BTN2_H;
Form8562->Btn2.Width = BTN2_W;
Form8562->Btn2.pCaption = BTN2_T;
Form8562->Btn2.Font = &Form8562->FontBtn;
Form8562->Btn2.Focus = 0;
Form8562->Btn3.Left = BTN3_X;
Form8562->Btn3.Top = BTN3_Y;
Form8562->Btn3.Height = BTN3_H;
Form8562->Btn3.Width = BTN3_W;
Form8562->Btn3.pCaption = BTN3_T;
Form8562->Btn3.Font = &Form8562->FontBtn;
Form8562->Btn3.Focus = 0;
Form8562->Btn4.Left = BTN4_X;
Form8562->Btn4.Top = BTN4_Y;
Form8562->Btn4.Height = BTN4_H;
Form8562->Btn4.Width = BTN4_W;
Form8562->Btn4.pCaption = BTN4_T;
Form8562->Btn4.Font = &Form8562->FontBtn;
Form8562->Btn4.Focus = 0;
Form8562->Btn5.Left = BTN5_X;
Form8562->Btn5.Top = BTN5_Y;
Form8562->Btn5.Height = BTN5_H;
Form8562->Btn5.Width = BTN5_W;
Form8562->Btn5.pCaption = BTN5_T;
Form8562->Btn5.Font = &Form8562->FontBtn;
Form8562->Btn5.Focus = 0;
Form8562->Btn6.Left = BTN6_X;
Form8562->Btn6.Top = BTN6_Y;
Form8562->Btn6.Height = BTN6_H;
Form8562->Btn6.Width = BTN6_W;
Form8562->Btn6.pCaption = BTN6_T;
Form8562->Btn6.Font = &Form8562->FontBtn;
Form8562->Btn6.Focus = 0;
Form8562->Btn7.Left = BTN7_X;
Form8562->Btn7.Top = BTN7_Y;
Form8562->Btn7.Height = BTN7_H;
Form8562->Btn7.Width = BTN7_W;
Form8562->Btn7.pCaption = BTN7_T;
Form8562->Btn7.Font = &Form8562->FontBtn;
Form8562->Btn7.Focus = 0;
Form8562->Btn8.Left = BTN8_X;
Form8562->Btn8.Top = BTN8_Y;
Form8562->Btn8.Height = BTN8_H;
Form8562->Btn8.Width = BTN8_W;
Form8562->Btn8.pCaption = BTN8_T;
Form8562->Btn8.Font = &Form8562->FontBtn;
Form8562->Btn8.Focus = 0;
Form8562->Btn9.Left = BTN9_X;
Form8562->Btn9.Top = BTN9_Y;
Form8562->Btn9.Height = BTN9_H;
Form8562->Btn9.Width = BTN9_W;
Form8562->Btn9.pCaption = BTN9_T;
Form8562->Btn9.Font = &Form8562->FontBtn;
Form8562->Btn9.Focus = 0;
Form8562->Btn10.Left = BTN10_X;
Form8562->Btn10.Top = BTN10_Y;
Form8562->Btn10.Height = BTN10_H;
Form8562->Btn10.Width = BTN10_W;
Form8562->Btn10.pCaption = BTN10_T;
Form8562->Btn10.Font = &Form8562->FontBtn;
Form8562->Btn10.Focus = 0;
Form8562->Btn11.Left = BTN11_X;
Form8562->Btn11.Top = BTN11_Y;
Form8562->Btn11.Height = BTN11_H;
Form8562->Btn11.Width = BTN11_W;
Form8562->Btn11.pCaption = BTN11_T;
Form8562->Btn11.Font = &Form8562->FontBtn;
Form8562->Btn11.Focus = 0;
Form8562->Btn12.Left = BTN12_X;
Form8562->Btn12.Top = BTN12_Y;
Form8562->Btn12.Height = BTN12_H;
Form8562->Btn12.Width = BTN12_W;
Form8562->Btn12.pCaption = BTN12_T;
Form8562->Btn12.Font = &Form8562->FontBtn;
Form8562->Btn12.Focus = 0;
Form8562->Btn13.Left = BTN13_X;
Form8562->Btn13.Top = BTN13_Y;
Form8562->Btn13.Height = BTN13_H;
Form8562->Btn13.Width = BTN13_W;
Form8562->Btn13.pCaption = BTN13_T;
Form8562->Btn13.Font = &Form8562->FontBtn;
Form8562->Btn13.Focus = 0;
Form8562->Btn14.Left = BTN14_X;
Form8562->Btn14.Top = BTN14_Y;
Form8562->Btn14.Height = BTN14_H;
Form8562->Btn14.Width = BTN14_W;
Form8562->Btn14.pCaption = BTN14_T;
Form8562->Btn14.Font = &Form8562->FontBtn;
Form8562->Btn14.Focus = 0;
Form8562->Btn15.Left = BTN15_X;
Form8562->Btn15.Top = BTN15_Y;
Form8562->Btn15.Height = BTN15_H;
Form8562->Btn15.Width = BTN15_W;
Form8562->Btn15.pCaption = BTN15_T;
Form8562->Btn15.Font = &Form8562->FontBtn;
Form8562->Btn15.Focus = 0;
}
/*
*********************************************************************************************************
* : FormMainDAC8562
* : DAC8562测试主程序
* :
* :
*********************************************************************************************************
*/
void FormMainDAC8562(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
Form8562_T form;
uint8_t fDispVolt = 1;
Form8562 = &form;
InitForm8562();
DispForm8562();
bsp_InitDAC8562();
MakeSinTable(s_WaveBuf, WAVE_SAMPLES, 0, 65535);
Form8562->DacValue = 0;
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
if (fDispVolt)
{
fDispVolt = 0;
bsp_SetTIMforInt(TIM7, 0, 0, 0); /* 关闭用于波形发生的定时器 */
DAC8562_SetDacData(0, Form8562->DacValue);
DAC8562_SetDacData(1, Form8562->DacValue);
DispDacValue();
DispDacVoltage();
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (LCD_ButtonTouchDown(&Form8562->BtnRet, tpX, tpY))
{
//fQuit = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn1, tpX, tpY))
{
Form8562->DacValue = 0;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn2, tpX, tpY))
{
Form8562->DacValue = 32767;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn3, tpX, tpY))
{
Form8562->DacValue = 65535;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn4, tpX, tpY))
{
Form8562->DacValue++;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn5, tpX, tpY))
{
Form8562->DacValue--;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn6, tpX, tpY))
{
Form8562->DacValue += 100;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn7, tpX, tpY))
{
Form8562->DacValue -= 100;
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn8, tpX, tpY))
{
/* +1mV */
Form8562->Voltage = DAC8562_DacToVoltage(Form8562->DacValue);
Form8562->Voltage += 10;
Form8562->DacValue = DAC8562_VoltageToDac(Form8562->Voltage);
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn9, tpX, tpY))
{
/* -1mV */
Form8562->Voltage = DAC8562_DacToVoltage(Form8562->DacValue);
Form8562->Voltage -= 10;
Form8562->DacValue = DAC8562_VoltageToDac(Form8562->Voltage);
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn10, tpX, tpY))
{
/* +100mV */
Form8562->Voltage = DAC8562_DacToVoltage(Form8562->DacValue);
Form8562->Voltage += 1000;
Form8562->DacValue = DAC8562_VoltageToDac(Form8562->Voltage);
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn11, tpX, tpY))
{
/* -100mV */
Form8562->Voltage = DAC8562_DacToVoltage(Form8562->DacValue);
Form8562->Voltage -= 1000;
Form8562->DacValue = DAC8562_VoltageToDac(Form8562->Voltage);
fDispVolt = 1;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn12, tpX, tpY))
{
bsp_SetTIMforInt(TIM7, DAC_OUT_FREQ, 0, 0);
s_WavePos1 = 0; /* 波形1超前 0度 */
s_WavePos2 = 0;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn13, tpX, tpY))
{
bsp_SetTIMforInt(TIM7, DAC_OUT_FREQ, 0, 0);
s_WavePos1 = WAVE_SAMPLES / 4; /* 波形1超前 90度 */
s_WavePos2 = 0;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn14, tpX, tpY))
{
bsp_SetTIMforInt(TIM7, DAC_OUT_FREQ, 0, 0);
s_WavePos1 = WAVE_SAMPLES / 2; /* 波形1超前 180度 */
s_WavePos2 = 0;
}
else if (LCD_ButtonTouchDown(&Form8562->Btn15, tpX, tpY))
{
bsp_SetTIMforInt(TIM7, 0, 0, 0); /* 关闭用于波形发生的定时器 */
fDispVolt = 1;
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (LCD_ButtonTouchRelease(&Form8562->BtnRet, tpX, tpY))
{
fQuit = 1; /* 返回 */
}
else
{
LCD_ButtonTouchRelease(&Form8562->BtnRet, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn1, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn2, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn3, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn4, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn5, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn6, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn7, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn8, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn9, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn10, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn11, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn12, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn13, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn14, tpX, tpY);
LCD_ButtonTouchRelease(&Form8562->Btn15, tpX, tpY);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键 + 1*/
break;
case KEY_DOWN_K2: /* K2键 - 1 */
break;
case KEY_DOWN_K3: /* K3键 - 清0 */
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
bsp_SetTIMforInt(TIM7, 0, 0, 0); /* 关闭用于波形发生的定时器 */
}
/*
*********************************************************************************************************
* : DispForm8562
* :
* :
* :
*********************************************************************************************************
*/
static void DispForm8562(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&Form8562->Box1);
LCD_DrawLabel(&Form8562->Label1);
LCD_DrawLabel(&Form8562->Label2);
LCD_DrawLabel(&Form8562->Label3);
LCD_DrawLabel(&Form8562->Label4);
/* 按钮 */
LCD_DrawButton(&Form8562->Btn1);
LCD_DrawButton(&Form8562->Btn2);
LCD_DrawButton(&Form8562->Btn3);
LCD_DrawButton(&Form8562->Btn4);
LCD_DrawButton(&Form8562->Btn5);
LCD_DrawButton(&Form8562->Btn6);
LCD_DrawButton(&Form8562->Btn5);
LCD_DrawButton(&Form8562->Btn6);
LCD_DrawButton(&Form8562->Btn7);
LCD_DrawButton(&Form8562->Btn8);
LCD_DrawButton(&Form8562->Btn9);
LCD_DrawButton(&Form8562->Btn10);
LCD_DrawButton(&Form8562->Btn11);
LCD_DrawButton(&Form8562->Btn12);
LCD_DrawButton(&Form8562->Btn13);
LCD_DrawButton(&Form8562->Btn14);
LCD_DrawButton(&Form8562->Btn15);
LCD_DrawButton(&Form8562->BtnRet);
}
/*
*********************************************************************************************************
* : DispDacValue
* : DAC数值
* :
* :
*********************************************************************************************************
*/
static void DispDacValue(void)
{
char buf[10];
sprintf(buf, "%d", Form8562->DacValue);
Form8562->Label2.pCaption = buf;
LCD_DrawLabel(&Form8562->Label2);
}
/*
*********************************************************************************************************
* : DispDacVoltage
* :
* :
* _
* :
*********************************************************************************************************
*/
static void DispDacVoltage(void)
{
char buf[10];
Form8562->Voltage = DAC8562_DacToVoltage(Form8562->DacValue);
sprintf(buf, "%d.%04dV", Form8562->Voltage / 10000, (abs(Form8562->Voltage) % 10000));
Form8562->Label4.pCaption = buf;
LCD_DrawLabel(&Form8562->Label4);
}
/*
*********************************************************************************************************
* : MakeSinTable
* :
* : _pBuf :
* _usSamples : 32
* _usBottom :
* _usTop :
* :
*********************************************************************************************************
*/
static void MakeSinTable(uint16_t *_pBuf, uint16_t _usSamples, uint16_t _usBottom, uint16_t _usTop)
{
uint16_t i;
uint16_t mid; /* 中值 */
uint16_t att; /* 幅度 */
mid = (_usBottom + _usTop) / 2; /* 0位的值 */
att = (_usTop - _usBottom) / 2; /* 正弦波幅度峰峰值除以2 */
for (i = 0; i < _usSamples; i++)
{
_pBuf[i] = mid + (int32_t)(att * sin((i * 2 * 3.14159) / _usSamples));
}
}
/*
*********************************************************************************************************
* : TIM7_IRQHandler
* : TIM7
* :
* :
*********************************************************************************************************
*/
void TIM7_IRQHandler(void)
{
uint16_t dac;
if (READ_BIT(TIM7->SR, TIM_IT_UPDATE) != 0)
{
CLEAR_BIT(TIM7->SR, TIM_IT_UPDATE);
/* 3.5寸屏如果触摸程序正在访问SPI触摸芯片TSC2046则丢弃本次 */
if (bsp_SpiBusBusy())
{
return;
}
/* 波形1 */
dac = s_WaveBuf[s_WavePos1++];
if (s_WavePos1 >= WAVE_SAMPLES)
{
s_WavePos1 = 0;
}
DAC8562_SetDacData(0, dac); /* 改变第1通道 DAC输出电压 */
/* 波形1 */
dac = s_WaveBuf[s_WavePos2++];
if (s_WavePos2 >= WAVE_SAMPLES)
{
s_WavePos2 = 0;
}
DAC8562_SetDacData(1, dac); /* 改变第2通道 DAC输出电压 */
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,660 +0,0 @@
/*
*********************************************************************************************************
*
* : SIM800 GPRS模块
* : gprs_test.c
* : V1.0
* : GPRS模块 SIM800
* :
*
* v1.0 2015-08-01 armfly
*
* Copyright (C), 2015-2016, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_gprs.h"
#include "num_pad.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontRed;
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
LABEL_T Label6;
LABEL_T Label7;
LABEL_T Label8;
LABEL_T Label9;
EDIT_T Edit1; /* 电话号码 */
BUTTON_T Btn1; /* 拨号 */
BUTTON_T Btn2; /* 挂机 */
BUTTON_T Btn3; /* 接听来话 */
BUTTON_T Btn4; /* 拨打10086 */
BUTTON_T Btn5; /* 拨打10010 */
BUTTON_T BtnRet; /* 返回 */
char strHardInfo[32]; /* 模块硬件信息 */
uint8_t ucNetStatus; /* 网络状态 */
uint8_t ucAudioCh; /* 当前音频通道 0 1 */
uint8_t ucEarVolume; /* 耳机音量 0 - 5 */
int16_t ucMicGain; /* MIC音量 -12最小增益 12最大增益 13静音*/
} FormGPRS_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "GPRS模块测试程序."
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define LABEL1_X (BOX1_X + 6)
#define LABEL1_Y (BOX1_Y + 20)
#define LABEL1_TEXT "模块版本 : "
#define LABEL2_X (LABEL1_X + 100)
#define LABEL2_Y LABEL1_Y
#define LABEL2_TEXT "---"
#define LABEL3_X (LABEL1_X)
#define LABEL3_Y (LABEL1_Y + 20)
#define LABEL3_TEXT "网络状态 : "
#define LABEL4_X (LABEL3_X + 100)
#define LABEL4_Y (LABEL3_Y)
#define LABEL4_TEXT "---"
#define LABEL5_X (LABEL1_X)
#define LABEL5_Y (LABEL1_Y + 20 * 2)
#define LABEL5_TEXT "音频通道 : "
#define LABEL6_X (LABEL5_X + 100)
#define LABEL6_Y LABEL5_Y
#define LABEL6_TEXT "1"
#define LABEL7_X (LABEL1_X)
#define LABEL7_Y (LABEL1_Y + 20 * 3)
#define LABEL7_TEXT "耳机音量和MIC增益 : "
#define LABEL8_X (LABEL7_X + 160)
#define LABEL8_Y LABEL7_Y
#define LABEL8_TEXT "---"
#define LABEL9_X (LABEL1_X)
#define LABEL9_Y (LABEL1_Y + 20 * 5)
#define LABEL9_TEXT "电话号码 : "
/* Edit */
#define EDIT1_X (LABEL9_X + 90)
#define EDIT1_Y (LABEL9_Y - 4)
#define EDIT1_H 26
#define EDIT1_W 132
/* 按钮 */
#define BTN1_H 32
#define BTN1_W 60
#define BTN1_X LABEL1_X
#define BTN1_Y (EDIT1_Y + EDIT1_H + 10)
#define BTN1_TEXT "拨号"
#define BTN2_H 32
#define BTN2_W 60
#define BTN2_X (BTN1_X + BTN1_W + 10)
#define BTN2_Y BTN1_Y
#define BTN2_TEXT "挂机"
#define BTN3_H 32
#define BTN3_W 90
#define BTN3_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN3_Y BTN1_Y
#define BTN3_TEXT "接听来话"
#define BTN4_H 32
#define BTN4_W 124
#define BTN4_X BTN1_X
#define BTN4_Y (BTN1_Y + BTN1_H + 10)
#define BTN4_TEXT "拨打10086"
#define BTN5_H 32
#define BTN5_W 124
#define BTN5_X BTN4_X + BTN4_W + 10
#define BTN5_Y (BTN1_Y + BTN1_H + 10)
#define BTN5_TEXT "拨打10010"
static void InitFormGPRS(void);
static void DispFormGPRS(void);
FormGPRS_T *FormGPRS;
void TestGPRS_SIM800(void);
void TestGPRS_MG323(void);
/*
*********************************************************************************************************
* : TestGPRS
* : GPRS模块
*
* :
*********************************************************************************************************
*/
void TestGPRS(void)
{
TestGPRS_SIM800();
}
/*
*********************************************************************************************************
* : TestGPRS_SIM800
* : SIM800 GPRS模块
*
* :
*********************************************************************************************************
*/
void TestGPRS_SIM800(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
uint8_t ucValue;
uint8_t fRefresh = 1;
FormGPRS_T form;
FormGPRS = &form;
LCD_ClrScr(CL_BTN_FACE);
InitFormGPRS();
DispFormGPRS();
bsp_InitSIM800();
printf("正在给GPRS模块上电...\r\n");
/* 给GSM模块上电 */
if (SIM800_PowerOn())
{
printf("\r\n上电完成\r\n");
}
else
{
printf("\r\n模块无应答\r\n");
}
{
SIM800_INFO_T tInfo;
if (SIM800_GetHardInfo(&tInfo))
{
FormGPRS->Label2.Font = &FormGPRS->FontBlue;
sprintf(FormGPRS->strHardInfo, "%s %s %s", tInfo.Manfacture, tInfo.Model, tInfo.Revision);
}
else
{
FormGPRS->Label2.Font = &FormGPRS->FontRed;
sprintf(FormGPRS->strHardInfo, "未检测到模块");
}
FormGPRS->Label2.pCaption = FormGPRS->strHardInfo;
LCD_DrawLabel(&FormGPRS->Label2);
}
//SIM800_SetAutoReport(); /* 设置事件自动上报 */
SIM800_SetMicGain(0, FormGPRS->ucMicGain); /* 设置MIC增益 */
SIM800_SetEarVolume(FormGPRS->ucEarVolume); /* 设置耳机音量 */
bsp_DelayMS(100);
SIM800_SendAT("AT+CMICBIAS=0"); /* 打开MIC偏置电路 */
bsp_StartAutoTimer(0, 500);
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
/* 从MG323收到的数据发送到串口1 */
if (comGetChar(COM_SIM800, &ucValue))
{
comSendChar(COM1, ucValue);
continue;
}
/* 将串口1的数据发送到MG323模块 */
if (comGetChar(COM1, &ucValue))
{
comSendChar(COM_SIM800, ucValue);
continue;
}
/* 每隔0.5秒查询一下网络注册状态 */
if (bsp_CheckTimer(0))
{
FormGPRS->ucNetStatus = SIM800_GetNetStatus();
if ((FormGPRS->ucNetStatus == CREG_LOCAL_OK) || (FormGPRS->ucNetStatus == CREG_REMOTE_OK))
{
bsp_StopTimer(0); /* 停止自动刷新 */
/* 配置WM8978芯片输入为LINE接口输出为耳机 和 扬声器 */
wm8978_CfgAudioPath(LINE_ON, EAR_LEFT_ON | EAR_RIGHT_ON | SPK_ON);
}
else if (FormGPRS->ucNetStatus == CREG_NO_REG)
{
bsp_StopTimer(0); /* 停止自动刷新 */
}
fRefresh = 1;
}
if (fRefresh)
{
fRefresh = 0;
DispFormGPRS(); /* 刷新所有控件 */
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
LCD_ButtonTouchDown(&FormGPRS->BtnRet, tpX, tpY);
LCD_ButtonTouchDown(&FormGPRS->Btn1, tpX, tpY);
LCD_ButtonTouchDown(&FormGPRS->Btn2, tpX, tpY);
LCD_ButtonTouchDown(&FormGPRS->Btn3, tpX, tpY);
LCD_ButtonTouchDown(&FormGPRS->Btn4, tpX, tpY);
LCD_ButtonTouchDown(&FormGPRS->Btn5, tpX, tpY);
/* 编辑框 */
if (TOUCH_InRect(tpX, tpY, EDIT1_X, EDIT1_Y, EDIT1_H, EDIT1_W))
{
{
if (InputNumber(NUMPAD_TEL, "设置电话号码", 0, (void *)FormGPRS->Edit1.Text))
{
;
}
ClearWinNumPad(FORM_BACK_COLOR); /* 清除数字键盘窗口 */
fRefresh = 1;
}
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (LCD_ButtonTouchRelease(&FormGPRS->BtnRet, tpX, tpY))
{
fQuit = 1; /* 返回 */
}
else if (LCD_ButtonTouchRelease(&FormGPRS->Btn1, tpX, tpY)) /* 拨号 */
{
/* 拨打电话 */
SIM800_DialTel(FormGPRS->Edit1.Text);
}
else if (LCD_ButtonTouchRelease(&FormGPRS->Btn2, tpX, tpY))
{
/* 挂机 */
SIM800_Hangup();
}
else if (LCD_ButtonTouchRelease(&FormGPRS->Btn3, tpX, tpY)) /* 接听来话 */
{
SIM800_SendAT("ATA");
}
else if (LCD_ButtonTouchRelease(&FormGPRS->Btn4, tpX, tpY)) /* 拨打10086 */
{
SIM800_DialTel("10086");
}
else if (LCD_ButtonTouchRelease(&FormGPRS->Btn5, tpX, tpY)) /* 拨打10010 */
{
SIM800_DialTel("10010");
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键 */
SIM800_SendAT("ATD10086;"); /* 拨打10086 */
break;
case KEY_DOWN_K2: /* K2键按下 */
SIM800_SendAT("ATH"); /* 挂断电话 */
break;
case KEY_DOWN_K3: /* K3键按下 */
fRefresh = 1;
break;
case JOY_DOWN_U: /* 摇杆UP键按下 调节耳机音量 */
if (FormGPRS->ucEarVolume < EAR_VOL_MAX)
{
FormGPRS->ucEarVolume++;
SIM800_SetEarVolume(FormGPRS->ucEarVolume);
}
fRefresh = 1;
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 调节耳机音量 */
if (FormGPRS->ucEarVolume > EAR_VOL_MIN)
{
FormGPRS->ucEarVolume--;
SIM800_SetEarVolume(FormGPRS->ucEarVolume);
}
fRefresh = 1;
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 调节MIC增益 */
if (FormGPRS->ucMicGain > MIC_GAIN_MIN)
{
FormGPRS->ucMicGain--;
SIM800_SetMicGain(0, FormGPRS->ucMicGain);
}
fRefresh = 1;
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 调节MIC增益 */
if (FormGPRS->ucMicGain < MIC_GAIN_MAX)
{
FormGPRS->ucMicGain++;
SIM800_SetMicGain(0, FormGPRS->ucMicGain);
}
fRefresh = 1;
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
/* 关闭WM8978芯片 */
wm8978_PowerDown();
SIM800_PowerOff(); /* 下电 */
printf("GPRS模块已下电.\r\n");
}
/*
*********************************************************************************************************
* : InitFormGPRS
* :
*
* :
*********************************************************************************************************
*/
static void InitFormGPRS(void)
{
/* 分组框标题字体 */
FormGPRS->FontBox.FontCode = FC_ST_16;
FormGPRS->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormGPRS->FontBox.FrontColor = CL_BLACK;
FormGPRS->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormGPRS->FontBlack.FontCode = FC_ST_16;
FormGPRS->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormGPRS->FontBlack.FrontColor = CL_BLACK;
FormGPRS->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormGPRS->FontBlue.FontCode = FC_ST_16;
FormGPRS->FontBlue.BackColor = CL_BTN_FACE;
FormGPRS->FontBlue.FrontColor = CL_BLUE;
FormGPRS->FontBlue.Space = 0;
FormGPRS->FontRed.FontCode = FC_ST_16;
FormGPRS->FontRed.BackColor = CL_BTN_FACE;
FormGPRS->FontRed.FrontColor = CL_RED;
FormGPRS->FontRed.Space = 0;
/* 按钮字体 */
FormGPRS->FontBtn.FontCode = FC_ST_16;
FormGPRS->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormGPRS->FontBtn.FrontColor = CL_BLACK;
FormGPRS->FontBtn.Space = 0;
/* 分组框 */
FormGPRS->Box1.Left = BOX1_X;
FormGPRS->Box1.Top = BOX1_Y;
FormGPRS->Box1.Height = BOX1_H;
FormGPRS->Box1.Width = BOX1_W;
FormGPRS->Box1.pCaption = BOX1_TEXT;
FormGPRS->Box1.Font = &FormGPRS->FontBox;
/* 静态标签 */
FormGPRS->Label1.Left = LABEL1_X;
FormGPRS->Label1.Top = LABEL1_Y;
FormGPRS->Label1.MaxLen = 0;
FormGPRS->Label1.pCaption = LABEL1_TEXT;
FormGPRS->Label1.Font = &FormGPRS->FontBlack;
FormGPRS->Label3.Left = LABEL3_X;
FormGPRS->Label3.Top = LABEL3_Y;
FormGPRS->Label3.MaxLen = 0;
FormGPRS->Label3.pCaption = LABEL3_TEXT;
FormGPRS->Label3.Font = &FormGPRS->FontBlack;
FormGPRS->Label5.Left = LABEL5_X;
FormGPRS->Label5.Top = LABEL5_Y;
FormGPRS->Label5.MaxLen = 0;
FormGPRS->Label5.pCaption = LABEL5_TEXT;
FormGPRS->Label5.Font = &FormGPRS->FontBlack;
FormGPRS->Label7.Left = LABEL7_X;
FormGPRS->Label7.Top = LABEL7_Y;
FormGPRS->Label7.MaxLen = 0;
FormGPRS->Label7.pCaption = LABEL7_TEXT;
FormGPRS->Label7.Font = &FormGPRS->FontBlack;
FormGPRS->Label9.Left = LABEL9_X;
FormGPRS->Label9.Top = LABEL9_Y;
FormGPRS->Label9.MaxLen = 0;
FormGPRS->Label9.pCaption = LABEL9_TEXT;
FormGPRS->Label9.Font = &FormGPRS->FontBlack;
/* 动态标签 */
FormGPRS->Label2.Left = LABEL2_X;
FormGPRS->Label2.Top = LABEL2_Y;
FormGPRS->Label2.MaxLen = 0;
FormGPRS->Label2.pCaption = LABEL2_TEXT;
FormGPRS->Label2.Font = &FormGPRS->FontBlue;
FormGPRS->Label4.Left = LABEL4_X;
FormGPRS->Label4.Top = LABEL4_Y;
FormGPRS->Label4.MaxLen = 0;
FormGPRS->Label4.pCaption = LABEL4_TEXT;
FormGPRS->Label4.Font = &FormGPRS->FontBlue;
FormGPRS->Label6.Left = LABEL6_X;
FormGPRS->Label6.Top = LABEL6_Y;
FormGPRS->Label6.MaxLen = 0;
FormGPRS->Label6.pCaption = LABEL6_TEXT;
FormGPRS->Label6.Font = &FormGPRS->FontBlue;
FormGPRS->Label8.Left = LABEL8_X;
FormGPRS->Label8.Top = LABEL8_Y;
FormGPRS->Label8.MaxLen = 0;
FormGPRS->Label8.pCaption = LABEL8_TEXT;
FormGPRS->Label8.Font = &FormGPRS->FontBlue;
/* 按钮 */
FormGPRS->BtnRet.Left = BTN_RET_X;
FormGPRS->BtnRet.Top = BTN_RET_Y;
FormGPRS->BtnRet.Height = BTN_RET_H;
FormGPRS->BtnRet.Width = BTN_RET_W;
FormGPRS->BtnRet.pCaption = BTN_RET_TEXT;
FormGPRS->BtnRet.Font = &FormGPRS->FontBtn;
FormGPRS->BtnRet.Focus = 0;
FormGPRS->Btn1.Left = BTN1_X;
FormGPRS->Btn1.Top = BTN1_Y;
FormGPRS->Btn1.Height = BTN1_H;
FormGPRS->Btn1.Width = BTN1_W;
FormGPRS->Btn1.pCaption = BTN1_TEXT;
FormGPRS->Btn1.Font = &FormGPRS->FontBtn;
FormGPRS->Btn1.Focus = 0;
FormGPRS->Btn2.Left = BTN2_X;
FormGPRS->Btn2.Top = BTN2_Y;
FormGPRS->Btn2.Height = BTN2_H;
FormGPRS->Btn2.Width = BTN2_W;
FormGPRS->Btn2.pCaption = BTN2_TEXT;
FormGPRS->Btn2.Font = &FormGPRS->FontBtn;
FormGPRS->Btn2.Focus = 0;
FormGPRS->Btn3.Left = BTN3_X;
FormGPRS->Btn3.Top = BTN3_Y;
FormGPRS->Btn3.Height = BTN3_H;
FormGPRS->Btn3.Width = BTN3_W;
FormGPRS->Btn3.pCaption = BTN3_TEXT;
FormGPRS->Btn3.Font = &FormGPRS->FontBtn;
FormGPRS->Btn3.Focus = 0;
FormGPRS->Btn4.Left = BTN4_X;
FormGPRS->Btn4.Top = BTN4_Y;
FormGPRS->Btn4.Height = BTN4_H;
FormGPRS->Btn4.Width = BTN4_W;
FormGPRS->Btn4.pCaption = BTN4_TEXT;
FormGPRS->Btn4.Font = &FormGPRS->FontBtn;
FormGPRS->Btn4.Focus = 0;
FormGPRS->Btn5.Left = BTN5_X;
FormGPRS->Btn5.Top = BTN5_Y;
FormGPRS->Btn5.Height = BTN5_H;
FormGPRS->Btn5.Width = BTN5_W;
FormGPRS->Btn5.pCaption = BTN5_TEXT;
FormGPRS->Btn5.Font = &FormGPRS->FontBtn;
FormGPRS->Btn5.Focus = 0;
/* 编辑框 */
FormGPRS->Edit1.Left = EDIT1_X;
FormGPRS->Edit1.Top = EDIT1_Y;
FormGPRS->Edit1.Height = EDIT1_H;
FormGPRS->Edit1.Width = EDIT1_W;
sprintf(FormGPRS->Edit1.Text, "10086");
FormGPRS->Edit1.pCaption = FormGPRS->Edit1.Text;
FormGPRS->Edit1.Font = &FormGPRS->FontBtn;
FormGPRS->ucMicGain = MIC_GAIN_DEFAULT; /* 缺省MIC增益 */
FormGPRS->ucEarVolume = EAR_VOL_DEFAULT; /* 缺省耳机音量 */
}
/*
*********************************************************************************************************
* : DispFormGPRS
* :
* :
* :
*********************************************************************************************************
*/
static void DispFormGPRS(void)
{
//LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormGPRS->Box1);
/* 静态标签 */
LCD_DrawLabel(&FormGPRS->Label1);
LCD_DrawLabel(&FormGPRS->Label3);
LCD_DrawLabel(&FormGPRS->Label5);
LCD_DrawLabel(&FormGPRS->Label7);
LCD_DrawLabel(&FormGPRS->Label9);
/* 按钮 */
LCD_DrawButton(&FormGPRS->BtnRet);
LCD_DrawButton(&FormGPRS->Btn1);
LCD_DrawButton(&FormGPRS->Btn2);
LCD_DrawButton(&FormGPRS->Btn3);
LCD_DrawButton(&FormGPRS->Btn4);
LCD_DrawButton(&FormGPRS->Btn5);
/* 编辑框 */
LCD_DrawEdit(&FormGPRS->Edit1);
/* 动态标签 */
LCD_DrawLabel(&FormGPRS->Label2);
/* 网络注册状态 */
if (FormGPRS->ucNetStatus == CREG_NO_REG)
{
FormGPRS->Label4.pCaption = "没有注册, 已停止搜寻";
}
else if (FormGPRS->ucNetStatus == CREG_LOCAL_OK)
{
FormGPRS->Label4.pCaption = "已注册到本地网络 ";
}
else if (FormGPRS->ucNetStatus == CREG_SEARCH)
{
FormGPRS->Label4.pCaption = "正在搜寻网络运营商 ";
}
else if (FormGPRS->ucNetStatus == CREG_REJECT)
{
FormGPRS->Label4.pCaption = "注册被拒绝 ";
}
else if (FormGPRS->ucNetStatus == CREG_REMOTE_OK)
{
FormGPRS->Label4.pCaption = "已注册到漫游网络 ";
}
else
{
FormGPRS->Label4.pCaption = "xxx ";
}
LCD_DrawLabel(&FormGPRS->Label4);
if (FormGPRS->ucAudioCh == 0)
{
FormGPRS->Label6.pCaption = "第1通道 INTMIC, INTEAR";
}
else
{
FormGPRS->Label6.pCaption = "第2通道 EXTMIC, EXTEAR";
}
LCD_DrawLabel(&FormGPRS->Label6);
/* 耳机音量 */
{
char buf[64];
sprintf(buf, "Ear = %d, Mic = %d", FormGPRS->ucEarVolume, FormGPRS->ucMicGain);
FormGPRS->Label8.pCaption = buf;
LCD_DrawLabel(&FormGPRS->Label8);
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,457 +0,0 @@
/*
*********************************************************************************************************
*
* : GPS定位模块测试程序
* : gps_test.c
* : V1.0
* : MPU-6050, HCM5833L, BMP085, BH1750
* :
*
* v1.0 2013-02-01 armfly
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_gps.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontRed; /* 红色字体 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T Label1;
LABEL_T Label2; /* 纬度 */
LABEL_T Label3;
LABEL_T Label4; /* 经度 */
LABEL_T Label5;
LABEL_T Label6; /* 速度 */
LABEL_T Label7;
LABEL_T Label8; /* 海拔 */
LABEL_T Label9;
LABEL_T Label10; /* 状态 */
BUTTON_T BtnRet;
} FormGPS_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "GPS定位模块测试程序"
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define LABEL1_X (BOX1_X + 6)
#define LABEL1_Y (BOX1_Y + 20)
#define LABEL1_TEXT "纬度 : "
#define LABEL2_X (LABEL1_X + 64)
#define LABEL2_Y LABEL1_Y
#define LABEL2_TEXT "0000.0000"
#define LABEL3_X (LABEL1_X)
#define LABEL3_Y (LABEL1_Y + 20)
#define LABEL3_TEXT "经度 : "
#define LABEL4_X (LABEL3_X + 64)
#define LABEL4_Y (LABEL3_Y)
#define LABEL4_TEXT "00000.0000"
#define LABEL5_X (LABEL1_X)
#define LABEL5_Y (LABEL1_Y + 20 * 2)
#define LABEL5_TEXT "速度 : "
#define LABEL6_X (LABEL5_X + 64)
#define LABEL6_Y LABEL5_Y
#define LABEL6_TEXT "0.0KM"
#define LABEL7_X (LABEL1_X)
#define LABEL7_Y (LABEL1_Y + 20 * 3)
#define LABEL7_TEXT "海拔 : "
#define LABEL8_X (LABEL7_X + 64)
#define LABEL8_Y LABEL7_Y
#define LABEL8_TEXT "0.0M"
#define LABEL9_X (LABEL1_X)
#define LABEL9_Y (LABEL1_Y + 20 * 5)
#define LABEL9_TEXT "硬件 : "
#define LABEL10_X (LABEL9_X + 64)
#define LABEL10_Y LABEL9_Y
#define LABEL10_TEXT ""
static void InitFormGPS(void);
static void DispGPSInitFace(void);
static void DispGPSStatus(void);
FormGPS_T *FormGPS;
/*
*********************************************************************************************************
* : TestGPS
* : GPS模块
*
* :
*********************************************************************************************************
*/
void TestGPS(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
FormGPS_T form;
FormGPS = &form;
bsp_InitGPS();
InitFormGPS();
DispGPSInitFace();
bsp_StartAutoTimer(0, 1000); /* 每秒定时显示GPS状态 */
bsp_StartTimer(1, 3000); /* 3秒超时没有收到GPS数据则认为串口连接失败 */
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
gps_pro();
if (bsp_CheckTimer(0))
{
DispGPSStatus();
}
/* 这段代码用于判断CPU是否能够收到GPS模块返回的数据 */
{
if (bsp_CheckTimer(1))
{
FormGPS->Label10.Font = &FormGPS->FontRed;
FormGPS->Label10.pCaption = "未检测到GPS模块";
LCD_DrawLabel(&FormGPS->Label10);
}
if (g_tGPS.UartOk == 1) /* 串口通信正常的标志, 如果以后收到了校验合格的命令串则设置为1 */
{
bsp_StartTimer(1, 3000); /* 3秒超时没有收到GPS数据则认为串口连接失败 */
FormGPS->Label10.Font = &FormGPS->FontBlue;
FormGPS->Label10.pCaption = "检测到GPS模块. 串口数据收发OK";
LCD_DrawLabel(&FormGPS->Label10);
g_tGPS.UartOk = 0;
}
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormGPS->BtnRet.Focus = 1;
LCD_DrawButton(&FormGPS->BtnRet);
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormGPS->BtnRet.Focus = 0;
LCD_DrawButton(&FormGPS->BtnRet);
fQuit = 1; /* 返回 */
}
else /* 按钮失去焦点 */
{
FormGPS->BtnRet.Focus = 0;
LCD_DrawButton(&FormGPS->BtnRet);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键 */
break;
case KEY_DOWN_K2: /* K2键按下 */
break;
case KEY_DOWN_K3: /* K3键按下 */
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
bsp_StopTimer(0);
}
/*
*********************************************************************************************************
* : DispGPSStatus
* : GPS状态
*
* :
*********************************************************************************************************
*/
static void DispGPSStatus(void)
{
char buf[128];
/* 纬度 */
if (g_tGPS.NS == 'S')
{
sprintf(buf, "南纬 %02d°%02d.%04d'=%02d.%06d°", g_tGPS.WeiDu_Du,
g_tGPS.WeiDu_Fen / 10000, g_tGPS.WeiDu_Fen % 10000,
g_tGPS.WeiDu_Du, gps_FenToDu(g_tGPS.WeiDu_Fen));
sprintf(&buf[strlen(buf)], "=%02d°%02d'%02d\"", g_tGPS.WeiDu_Du,
g_tGPS.WeiDu_Fen / 10000, gps_FenToMiao(g_tGPS.WeiDu_Fen));
}
else
{
sprintf(buf, "北纬 %02d°%02d.%04d'=%02d.%06d°", g_tGPS.WeiDu_Du,
g_tGPS.WeiDu_Fen / 10000, g_tGPS.WeiDu_Fen % 10000,
g_tGPS.WeiDu_Du, gps_FenToDu(g_tGPS.WeiDu_Fen));
sprintf(&buf[strlen(buf)], "=%02d°%02d'%02d\"", g_tGPS.WeiDu_Du,
g_tGPS.WeiDu_Fen / 10000, gps_FenToMiao(g_tGPS.WeiDu_Fen));
}
FormGPS->Label2.pCaption = buf;
LCD_DrawLabel(&FormGPS->Label2);
/* 经度 */
if (g_tGPS.EW == 'E')
{
sprintf(buf, "东经 %03d°%02d.%04d'=%03d.%06d°", g_tGPS.JingDu_Du,
g_tGPS.JingDu_Fen / 10000, g_tGPS.JingDu_Fen % 10000,
g_tGPS.JingDu_Du, gps_FenToDu(g_tGPS.JingDu_Fen));
sprintf(&buf[strlen(buf)], "=%03d°%02d'%02d\"", g_tGPS.JingDu_Du,
g_tGPS.WeiDu_Fen / 10000, gps_FenToMiao(g_tGPS.JingDu_Fen));
}
else
{
sprintf(buf, "西经 %03d°%02d.%04d'=%03d.%06d°", g_tGPS.JingDu_Du,
g_tGPS.JingDu_Fen / 10000, g_tGPS.JingDu_Fen % 10000,
g_tGPS.JingDu_Du, gps_FenToDu(g_tGPS.JingDu_Fen));
sprintf(&buf[strlen(buf)], "=%03d°%02d'%02d\"", g_tGPS.JingDu_Du,
g_tGPS.JingDu_Fen / 10000, gps_FenToMiao(g_tGPS.JingDu_Fen));
}
FormGPS->Label4.pCaption = buf;
LCD_DrawLabel(&FormGPS->Label4);
/* 速度 */
sprintf(buf, "%5d.%d KM/h", g_tGPS.SpeedKM / 10, g_tGPS.SpeedKM % 10);
FormGPS->Label6.pCaption = buf;
LCD_DrawLabel(&FormGPS->Label6);
/* 海拔 */
sprintf(buf, "%5d.%d M", g_tGPS.Altitude / 10, g_tGPS.Altitude % 10);
FormGPS->Label8.pCaption = buf;
LCD_DrawLabel(&FormGPS->Label8);
}
/*
*********************************************************************************************************
* : InitFormGPS
* : GPS初始界面控件
*
* :
*********************************************************************************************************
*/
static void InitFormGPS(void)
{
/* 分组框标题字体 */
FormGPS->FontBox.FontCode = FC_ST_16;
FormGPS->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormGPS->FontBox.FrontColor = CL_BLACK;
FormGPS->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormGPS->FontBlack.FontCode = FC_ST_16;
FormGPS->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormGPS->FontBlack.FrontColor = CL_BLACK;
FormGPS->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormGPS->FontBlue.FontCode = FC_ST_16;
FormGPS->FontBlue.BackColor = CL_BTN_FACE;
FormGPS->FontBlue.FrontColor = CL_BLUE;
FormGPS->FontBlue.Space = 0;
FormGPS->FontRed.FontCode = FC_ST_16;
FormGPS->FontRed.BackColor = CL_BTN_FACE;
FormGPS->FontRed.FrontColor = CL_RED;
FormGPS->FontRed.Space = 0;
/* 按钮字体 */
FormGPS->FontBtn.FontCode = FC_ST_16;
FormGPS->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormGPS->FontBtn.FrontColor = CL_BLACK;
FormGPS->FontBtn.Space = 0;
/* 分组框 */
FormGPS->Box1.Left = BOX1_X;
FormGPS->Box1.Top = BOX1_Y;
FormGPS->Box1.Height = BOX1_H;
FormGPS->Box1.Width = BOX1_W;
FormGPS->Box1.pCaption = BOX1_TEXT;
FormGPS->Box1.Font = &FormGPS->FontBox;
/* 静态标签 */
FormGPS->Label1.Left = LABEL1_X;
FormGPS->Label1.Top = LABEL1_Y;
FormGPS->Label1.MaxLen = 0;
FormGPS->Label1.pCaption = LABEL1_TEXT;
FormGPS->Label1.Font = &FormGPS->FontBlack;
FormGPS->Label3.Left = LABEL3_X;
FormGPS->Label3.Top = LABEL3_Y;
FormGPS->Label3.MaxLen = 0;
FormGPS->Label3.pCaption = LABEL3_TEXT;
FormGPS->Label3.Font = &FormGPS->FontBlack;
FormGPS->Label5.Left = LABEL5_X;
FormGPS->Label5.Top = LABEL5_Y;
FormGPS->Label5.MaxLen = 0;
FormGPS->Label5.pCaption = LABEL5_TEXT;
FormGPS->Label5.Font = &FormGPS->FontBlack;
FormGPS->Label7.Left = LABEL7_X;
FormGPS->Label7.Top = LABEL7_Y;
FormGPS->Label7.MaxLen = 0;
FormGPS->Label7.pCaption = LABEL7_TEXT;
FormGPS->Label7.Font = &FormGPS->FontBlack;
FormGPS->Label9.Left = LABEL9_X;
FormGPS->Label9.Top = LABEL9_Y;
FormGPS->Label9.MaxLen = 0;
FormGPS->Label9.pCaption = LABEL9_TEXT;
FormGPS->Label9.Font = &FormGPS->FontBlack;
/* 动态标签 */
FormGPS->Label2.Left = LABEL2_X;
FormGPS->Label2.Top = LABEL2_Y;
FormGPS->Label2.MaxLen = 0;
FormGPS->Label2.pCaption = LABEL2_TEXT;
FormGPS->Label2.Font = &FormGPS->FontBlue;
FormGPS->Label4.Left = LABEL4_X;
FormGPS->Label4.Top = LABEL4_Y;
FormGPS->Label4.MaxLen = 0;
FormGPS->Label4.pCaption = LABEL4_TEXT;
FormGPS->Label4.Font = &FormGPS->FontBlue;
FormGPS->Label6.Left = LABEL6_X;
FormGPS->Label6.Top = LABEL6_Y;
FormGPS->Label6.MaxLen = 0;
FormGPS->Label6.pCaption = LABEL6_TEXT;
FormGPS->Label6.Font = &FormGPS->FontBlue;
FormGPS->Label8.Left = LABEL8_X;
FormGPS->Label8.Top = LABEL8_Y;
FormGPS->Label8.MaxLen = 0;
FormGPS->Label8.pCaption = LABEL8_TEXT;
FormGPS->Label8.Font = &FormGPS->FontBlue;
FormGPS->Label10.Left = LABEL10_X;
FormGPS->Label10.Top = LABEL10_Y;
FormGPS->Label10.MaxLen = 0;
FormGPS->Label10.pCaption = LABEL10_TEXT;
FormGPS->Label10.Font = &FormGPS->FontBlue;
/* 按钮 */
FormGPS->BtnRet.Left = BTN_RET_X;
FormGPS->BtnRet.Top = BTN_RET_Y;
FormGPS->BtnRet.Height = BTN_RET_H;
FormGPS->BtnRet.Width = BTN_RET_W;
FormGPS->BtnRet.pCaption = BTN_RET_TEXT;
FormGPS->BtnRet.Font = &FormGPS->FontBtn;
FormGPS->BtnRet.Focus = 0;
}
/*
*********************************************************************************************************
* : DispGPSInitFace
* :
* :
* :
*********************************************************************************************************
*/
static void DispGPSInitFace(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormGPS->Box1);
/* 静态标签 */
LCD_DrawLabel(&FormGPS->Label1);
LCD_DrawLabel(&FormGPS->Label3);
LCD_DrawLabel(&FormGPS->Label5);
LCD_DrawLabel(&FormGPS->Label7);
LCD_DrawLabel(&FormGPS->Label9);
/* 动态标签 */
LCD_DrawLabel(&FormGPS->Label2);
LCD_DrawLabel(&FormGPS->Label4);
LCD_DrawLabel(&FormGPS->Label6);
LCD_DrawLabel(&FormGPS->Label8);
LCD_DrawLabel(&FormGPS->Label10);
/* 按钮 */
LCD_DrawButton(&FormGPS->BtnRet);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,601 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : hard_test.c
* : V1.0
* :
* :
*
* V1.0 2013-01-01 armfly
*
* Copyright (C), 2012-2013, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h" /* printf函数定向输出到串口所以必须包含这个文件 */
#include "form_hard_test.h"
/* 返回按钮的坐标(屏幕右下角) */
#define BUTTON_RET_H 32
#define BUTTON_RET_W 60
#define BUTTON_RET_X (g_LcdWidth - BUTTON_RET_W - 4)
#define BUTTON_RET_Y (g_LcdHeight - BUTTON_RET_H - 4)
/*
*********************************************************************************************************
* : HardInfo
* :
* :
* :
*********************************************************************************************************
*/
void HardInfo(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fRefresh; /* 刷屏请求标志,1表示需要刷新 */
FONT_T tFont, tFontBtn; /* 定义一个字体结构体变量,用于设置字体参数 */
char buf[128];
uint16_t x, y;
uint16_t usLineCap = 18;
int16_t tpX, tpY;
BUTTON_T tBtn;
LCD_ClrScr(CL_BLUE); /* 清屏,背景蓝色 */
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_WHITE; /* 字体颜色 */
tFont.BackColor = CL_BLUE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
/* 按钮字体 */
tFontBtn.FontCode = FC_ST_16;
tFontBtn.BackColor = CL_MASK; /* 透明色 */
tFontBtn.FrontColor = CL_BLACK;
tFontBtn.Space = 0;
}
x = 5;
y = 3;
LCD_DispStr(x, y, "安富莱STM32-V6开发板硬件信息", &tFont); /* 在(8,3)坐标处显示一串汉字 */
y += usLineCap;
/* 检测CPU ID */
{
uint32_t id[3];
bsp_GetCpuID(id);
printf("\r\nCPU : STM32H743, 主频: %dMHz\r\n", SystemCoreClock / 1000000);
LCD_DispStr(x, y, "CPU : STM32H743", &tFont);
y += usLineCap;
sprintf(buf, " UID = %08X %08X %08X", id[0], id[1], id[2]);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
y += usLineCap;
}
/* 显示TFT控制器型号和屏幕分辨率 */
{
strcpy(buf, "TFT Driver : ");
LCD_GetChipDescribe(&buf[strlen(buf)]); /* 读取TFT驱动芯片型号 */
sprintf(&buf[strlen(buf)], " %d x %d", LCD_GetWidth(), LCD_GetHeight());
LCD_DispStr(x, y, buf, &tFont);
y += usLineCap;
}
/* 测试SRAM */
{
sprintf(buf, "SDRAM Model ... ");
LCD_DispStr(x, y, buf, &tFont);
if (bsp_TestExtSDRAM2() == 0)
{
sprintf(buf, "SDRAM, 32Bit, Test OK");
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else
{
sprintf(buf, " SDRAM, Test Err");
printf("%s\r\n", buf);
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
y += usLineCap;
}
/* 测试NADN Flash */
#if 1
{
uint32_t id;
NAND_Init(); /* 初始化NAND */
id = NAND_ReadID();
sprintf(buf, "NAND Flash ID = 0x%04X, Type = ", id);
if (id == HY27UF081G2A)
{
sprintf(buf, "NAND Flash ID = 0x%04X, Model = HY27UF081G2A, OK", id);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else if (id == H27U1G8F2BTR)
{
sprintf(buf, "NAND Flash ID = 0x%04X, Model = H27U1G8F2BTR, OK", id);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else if (id == H27U4G8F2DTR)
{
sprintf(buf, "NAND Flash ID = 0x%04X, Model = H27U4G8F2DTR, OK", id);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else
{
sprintf(buf, "NAND Flash ID = 0x%04X, Model = Unknow, Err", id);
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
y += usLineCap;
//NAND_DispBadBlockInfo(); /* 向串口1打印NAND Flash坏块信息 (此函数开头初始FSMC) */
}
#endif
/* 测试I2C设备 */
{
if (i2c_CheckDevice(EE_DEV_ADDR) == 0)
{
sprintf(buf, "AT24C128 Ok (0x%02X)", EE_DEV_ADDR);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else
{
sprintf(buf, "AT24C128 Err (0x%02X)", EE_DEV_ADDR);
printf("%s\r\n", buf);
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
y += usLineCap;
if (i2c_CheckDevice(I2C_ADDR_SI4730_W) == 0)
{
sprintf(buf, "Si4730/4704 Ok (0x%02X)", I2C_ADDR_SI4730_W);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else
{
sprintf(buf, "Si4730/4704 Err (0x%02X)", I2C_ADDR_SI4730_W);
printf("%s\r\n", buf);
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
y += usLineCap;
#if 0
if (i2c_CheckDevice(HMC5883L_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "HMC5883L Ok (0x%02X)", HMC5883L_SLAVE_ADDRESS);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else
{
sprintf(buf, "HMC5883L / MAG3110 Err");
printf("%s\r\n", buf);
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
y += usLineCap;
#endif
if (i2c_CheckDevice(MPU6050_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "MPU6050 Ok (0x%02X)", MPU6050_SLAVE_ADDRESS);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else
{
sprintf(buf, "MPU6050 Err (0x%02X)", MPU6050_SLAVE_ADDRESS);
printf("%s\r\n", buf);
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
y += usLineCap;
if (i2c_CheckDevice(BMP085_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "BMP180 Ok (0x%02X)", BMP085_SLAVE_ADDRESS);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else
{
sprintf(buf, "BMP180 Err (0x%02X)", BMP085_SLAVE_ADDRESS);
printf("%s\r\n", buf);
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
y += usLineCap;
if (i2c_CheckDevice(WM8978_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "WM8978 Ok (0x%02X)", WM8978_SLAVE_ADDRESS);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else
{
sprintf(buf, "WM8978 Err (0x%02X)", WM8978_SLAVE_ADDRESS);
printf("%s\r\n", buf);
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
y += usLineCap;
if (i2c_CheckDevice(BH1750_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "BH1750 Ok (0x%02X)", BH1750_SLAVE_ADDRESS);
printf("%s\r\n", buf);
LCD_DispStr(x, y, buf, &tFont);
}
else
{
sprintf(buf, "BH1750 Err (0x%02X)", BH1750_SLAVE_ADDRESS);
printf("%s\r\n", buf);
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
y += usLineCap;
}
/* 测试SPI Flash */
{
bsp_InitSFlash(); /* 初始化SPI硬件 */
sf_ReadInfo();
/* 检测串行Flash OK */
sprintf(buf, "SPI Flash ID = %08X, Model = %s", g_tSF.ChipID, g_tSF.ChipName);
printf("%s\r\n", buf);
if (g_tSF.ChipID == W25Q64BV_ID)
{
LCD_DispStr(x, y, buf, &tFont);
}
else
{
tFont.FrontColor = CL_RED;
LCD_DispStr(x, y, buf, &tFont);
tFont.FrontColor = CL_WHITE;
}
}
fRefresh = 1; /* 1表示需要刷新LCD */
bsp_StartAutoTimer(0, 1000);
while (1)
{
bsp_Idle();
/* 显示时钟 */
if (bsp_CheckTimer(0))
{
uint16_t x, y;
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_WHITE; /* 字体颜色 */
tFont.BackColor = CL_BLUE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
RTC_ReadClock(); /* 读时钟,结果在 g_tRTC */
x = 5;
y = LCD_GetHeight() - 20;
sprintf(buf, "%4d-%02d-%02d %02d:%02d:%02d",
g_tRTC.Year, g_tRTC.Mon, g_tRTC.Day, g_tRTC.Hour, g_tRTC.Min, g_tRTC.Sec);
LCD_DispStr(x, y, buf, &tFont);
}
if (fRefresh)
{
fRefresh = 0;
/* 显示按钮 */
{
tBtn.Font = &tFontBtn;
tBtn.Left = BUTTON_RET_X;
tBtn.Top = BUTTON_RET_Y;
tBtn.Height = BUTTON_RET_H;
tBtn.Width = BUTTON_RET_W;
tBtn.Focus = 0; /* 失去焦点 */
tBtn.pCaption = "返回";
LCD_DrawButton(&tBtn);
}
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BUTTON_RET_X, BUTTON_RET_Y, BUTTON_RET_H, BUTTON_RET_W))
{
tBtn.Font = &tFontBtn;
tBtn.Left = BUTTON_RET_X;
tBtn.Top = BUTTON_RET_Y;
tBtn.Height = BUTTON_RET_H;
tBtn.Width = BUTTON_RET_W;
tBtn.Focus = 1; /* 焦点 */
tBtn.pCaption = "返回";
LCD_DrawButton(&tBtn);
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BUTTON_RET_X, BUTTON_RET_Y, BUTTON_RET_H, BUTTON_RET_W))
{
tBtn.Font = &tFontBtn;
tBtn.Left = BUTTON_RET_X;
tBtn.Top = BUTTON_RET_Y;
tBtn.Height = BUTTON_RET_H;
tBtn.Width = BUTTON_RET_W;
tBtn.Focus = 1; /* 焦点 */
tBtn.pCaption = "返回";
LCD_DrawButton(&tBtn);
return; /* 返回 */
}
else /* 按钮失去焦点 */
{
tBtn.Font = &tFontBtn;
tBtn.Left = BUTTON_RET_X;
tBtn.Top = BUTTON_RET_Y;
tBtn.Height = BUTTON_RET_H;
tBtn.Width = BUTTON_RET_W;
tBtn.Focus = 0; /* 焦点 */
tBtn.pCaption = "返回";
LCD_DrawButton(&tBtn);
}
}
}
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case JOY_DOWN_OK: /* 摇杆OK键 */
break;
default:
break;
}
}
}
}
/*
*********************************************************************************************************
* : PrintfHardInfo
* : . printf到串口
* :
* :
*********************************************************************************************************
*/
extern uint32_t dm9k_ReadID(void);
void PrintfHardInfo(void)
{
char buf[128];
/* 检测CPU ID */
{
uint32_t id[3];
bsp_GetCpuID(id);
printf("\r\nCPU : STM32H743, 主频: %dMHz\r\n", SystemCoreClock / 1000000);
sprintf(buf, " UID = %08X %08X %08X", id[0], id[1], id[2]);
printf("%s\r\n", buf);
}
/* 显示TFT控制器型号和屏幕分辨率 */
{
strcpy(buf, "TFT Driver : ");
LCD_GetChipDescribe(&buf[strlen(buf)]); /* 读取TFT驱动芯片型号 */
sprintf(&buf[strlen(buf)], " %d x %d", LCD_GetWidth(), LCD_GetHeight());
printf("%s\r\n", buf);
}
/* 测试SRAM */
#if 0
{
if (bsp_TestExtSDRAM2() == 0)
{
sprintf(buf, "SDRAM Test OK");
printf("%s\r\n", buf);
}
else
{
sprintf(buf, "SDRAM Test Err");
printf("%s\r\n", buf);
}
}
#endif
/* 测试NADN Flash */
#if 1
{
uint32_t id;
NAND_Init(); /* 初始化NAND */
id = NAND_ReadID();
sprintf(buf, "NAND Flash ID = 0x%04X, Type = ", id);
if (id == HY27UF081G2A)
{
sprintf(buf, "NAND Flash ID = 0x%04X, Model = HY27UF081G2A, OK", id);
printf("%s\r\n", buf);
}
else if (id == H27U1G8F2BTR)
{
sprintf(buf, "NAND Flash ID = 0x%04X, Model = H27U1G8F2BTR, OK", id);
printf("%s\r\n", buf);
}
else if (id == H27U4G8F2DTR)
{
sprintf(buf, "NAND Flash ID = 0x%04X, Model = H27U4G8F2DTR, OK", id);
printf("%s\r\n", buf);
}
else
{
sprintf(buf, "NAND Flash ID = 0x%04X, Model = Unknow, Err", id);
printf("%s\r\n", buf);
}
}
#endif
/* 测试I2C设备 */
{
if (i2c_CheckDevice(EE_DEV_ADDR) == 0)
{
sprintf(buf, "AT24C128 Ok (0x%02X)", EE_DEV_ADDR);
printf("%s\r\n", buf);
}
else
{
sprintf(buf, "AT24C128 Err (0x%02X)", EE_DEV_ADDR);
printf("%s\r\n", buf);
}
if (i2c_CheckDevice(I2C_ADDR_SI4730_W) == 0)
{
sprintf(buf, "Si4730 Ok (0x%02X)", I2C_ADDR_SI4730_W);
printf("%s\r\n", buf);
}
else
{
sprintf(buf, "Si4730 Err (0x%02X)", I2C_ADDR_SI4730_W);
printf("%s\r\n", buf);
}
#if 0
if (i2c_CheckDevice(HMC5883L_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "HMC5883L Ok (0x%02X)", HMC5883L_SLAVE_ADDRESS);
printf("%s\r\n", buf);
}
else
{
sprintf(buf, "HMC5883L Err (0x%02X)", HMC5883L_SLAVE_ADDRESS);
printf("%s\r\n", buf);
}
#endif
if (i2c_CheckDevice(MPU6050_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "MPU6050 Ok (0x%02X)", MPU6050_SLAVE_ADDRESS);
printf("%s\r\n", buf);
}
else
{
sprintf(buf, "MPU6050 Err (0x%02X)", MPU6050_SLAVE_ADDRESS);
printf("%s\r\n", buf);
}
if (i2c_CheckDevice(BMP085_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "BMP180 Ok (0x%02X)", BMP085_SLAVE_ADDRESS);
printf("%s\r\n", buf);
}
else
{
sprintf(buf, "BMP180 Err (0x%02X)", BMP085_SLAVE_ADDRESS);
printf("%s\r\n", buf);
}
if (i2c_CheckDevice(WM8978_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "WM8978 Ok (0x%02X)", WM8978_SLAVE_ADDRESS);
printf("%s\r\n", buf);
}
else
{
sprintf(buf, "WM8978 Err (0x%02X)", WM8978_SLAVE_ADDRESS);
printf("%s\r\n", buf);
}
if (i2c_CheckDevice(BH1750_SLAVE_ADDRESS) == 0)
{
sprintf(buf, "BH1750 Ok (0x%02X)", BH1750_SLAVE_ADDRESS);
printf("%s\r\n", buf);
}
else
{
sprintf(buf, "BH1750 Err (0x%02X)", BH1750_SLAVE_ADDRESS);
printf("%s\r\n", buf);
}
}
/* 测试SPI Flash */
{
//bsp_InitSFlash(); /* 初始化SPI硬件, bsp.c 中已经初始化 */
/* 检测串行Flash OK */
sprintf(buf, "SPI Flash ID= = %08X, Model = %s", g_tSF.ChipID, g_tSF.ChipName);
printf("%s\r\n", buf);
}
/* 检测DM9000 */
#if 0
{
uint32_t id;
id = dm9k_ReadID();
if (id == 0x0A469000)
{
printf("DM9000AEP OK, ID = %8X\r\n", id);
}
else
{
printf("DM9000AEP Error, ID = %8X\r\n", id);
}
}
#endif
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,250 +0,0 @@
/*
*********************************************************************************************************
*
* : web server
* : http_server.c
* : V1.0
* : WEB服务器功能DM9000AEP网卡电路和DM9161 PHY电路
* :
*
* V1.0 2013-01-01 armfly
*
* Copyright (C), 2012-2013, www.armfly.com
*
*********************************************************************************************************
*/
#include "stdio.h"
#include "bsp.h"
#include "num_pad.h"
#include "param.h"
/* for LwIP */
//#include "netconf.h"
//#include "main_lwip.h"
//#include "httpd_w.h"
#include "lwip/opt.h"
#include "lwip/init.h"
#include "netif/etharp.h"
#include "lwip/netif.h"
#include "lwip/timeouts.h"
#include "lwip/dhcp.h"
#include "ethernetif.h"
#include "app_ethernet.h"
#include "http_cgi_ssi.h"
void lwip_start(void);
void lwip_pro(void);
/*
*********************************************************************************************************
* : WebServer
* : web服务器程序
* :
* :
*********************************************************************************************************
*/
void WebServer(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
int16_t tpX, tpY;
uint16_t x, y;
uint16_t usLineCap = 18;
char buf[128];
uint8_t fRefresh;
FONT_T tFont; /* 定义字体结构体变量 */
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_BLACK; /* 字体颜色 */
tFont.BackColor = FORM_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
LCD_ClrScr(FORM_BACK_COLOR); /* 清屏,背景蓝色 */
LCD_DispStr(5, 3, "逻辑分析仪示波器", &tFont);
}
/* LwIP 初始化 */
{
/* 如果不插网线,此函数执行时间过长 */
/* 网络参数存在在全局变量 g_tParam.lwip_ip, g_tParam.lwip_net_mask, g_tParam.lwip_gateway */
lwip_start();
}
LCD_ClrScr(FORM_BACK_COLOR); /* 清屏,背景蓝色 */
fRefresh = 1;
while (1)
{
bsp_Idle();
uip_pro();
lwip_pro();
if (fRefresh) /* 刷新整个界面 */
{
fRefresh = 0;
}
if (PHYLinkChanged == 1) /* DM9162联网状态变化 */
{
PHYLinkChanged = 0;
fRefresh = 1;
}
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_S: /* S键 */
break;
case KEY_DOWN_C: /* C键 */
break;
default:
break;
}
}
}
}
/*
*********************************************************************************************************
* LwIP
*********************************************************************************************************
*/
struct netif gnetif;
/*
*********************************************************************************************************
* : uip_ChangeNetParam
* : g_tParam.uip_ip, g_tParam.uip_net_mask,
* g_tParam.uip_gateway
* :
* :
*********************************************************************************************************
*/
void lwip_ChangeNetParam(void)
{
// //uip_ipaddr(ipaddr, 192,168,1,10); /* 缺省IP */
// uip_sethostaddr((uint16_t *)g_tParam.uip_ip);
// //uip_ipaddr(ipaddr, 255,255,255,0); /* 地址掩码 */
// uip_setnetmask((uint16_t *)g_tParam.uip_net_mask);
// //uip_ipaddr(ipaddr, 192,168,1,1); /* 默认网关 */
// uip_setdraddr((uint16_t *)g_tParam.uip_gateway);
}
/**
* @brief Setup the network interface
* @param None
* @retval None
*/
/*Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 */
#define IP_ADDR0 ((uint8_t)192U)
#define IP_ADDR1 ((uint8_t)168U)
#define IP_ADDR2 ((uint8_t)1U)
#define IP_ADDR3 ((uint8_t)86U)
/*NETMASK*/
#define NETMASK_ADDR0 ((uint8_t)255U)
#define NETMASK_ADDR1 ((uint8_t)255U)
#define NETMASK_ADDR2 ((uint8_t)255U)
#define NETMASK_ADDR3 ((uint8_t)0U)
/*Gateway Address*/
#define GW_ADDR0 ((uint8_t)192U)
#define GW_ADDR1 ((uint8_t)168U)
#define GW_ADDR2 ((uint8_t)1U)
#define GW_ADDR3 ((uint8_t)1U)
static void Netif_Config(void)
{
ip_addr_t ipaddr;
ip_addr_t netmask;
ip_addr_t gw;
#if LWIP_DHCP
ip_addr_set_zero_ip4(&ipaddr);
ip_addr_set_zero_ip4(&netmask);
ip_addr_set_zero_ip4(&gw);
#else
/* IP address default setting */
IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
#endif
/* add the network interface */
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);
/* Registers the default network interface */
netif_set_default(&gnetif);
ethernet_link_status_updated(&gnetif);
#if LWIP_NETIF_LINK_CALLBACK
netif_set_link_callback(&gnetif, ethernet_link_status_updated);
#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();
}
/*
*********************************************************************************************************
* : lwip_pro
* : lwip
* :
* :
*********************************************************************************************************
*/
void lwip_pro(void)
{
/* Read a received packet from the Ethernet buffers and send it
to the lwIP for handling */
ethernetif_input(&gnetif);
/* Handle timeouts */
sys_check_timeouts();
#if LWIP_NETIF_LINK_CALLBACK
Ethernet_Link_Periodic_Handle(&gnetif);
#endif
#if LWIP_DHCP
DHCP_Periodic_Handle(&gnetif);
#endif
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,571 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : main_menu.c
* : V1.0
* :
* :
*
* v1.0 2012-08-08 armfly ST固件库V3.5.0
*
* Copyright (C), 2012-2013, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h" /* printf函数定向输出到串口所以必须包含这个文件 */
#include "images.h" /* 图标文件 */
#include "form_main_menu.h"
#include "main.h"
#define KEY_INFO "K3:校准 K1:背景 OK:显示方向"
#define ICON_LEFT 16
#define ICON_TOP 25
#define TOP_BAR_H 20 /* 顶部栏高度 */
#define BOTTOM_BAR_H 20 /* 底部栏高度 */
#define CL_BAR RGB(0, 73, 108) /* 顶部栏和底部栏背景颜色 */
extern const unsigned char acRecorder[48 * 48 * 4];
extern const unsigned char acTape[48 * 48 * 4];
extern const unsigned char acCamera[48 * 48 * 4];
extern const unsigned char acChiLun[48 * 48 * 4];
extern const unsigned char acchujiao[48 * 48 * 4];
#define ICONS_COUNT 28
static ICON_T s_tMainIcons[ICONS_COUNT] =
{
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)achwinfo, "硬件信息"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acLCD, "触摸屏和按键"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acRadio, "收音机"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acRecorder, "录音机"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acchujiao, "MEMS传感器"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acweb, "WEB服务器"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acGPS, "GPS定位模块"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acPhone, "GPRS模块"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acMP3, "MP3模块"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acUSBDisk, "模拟U盘"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acCamera, "摄像头"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "OLED显示器"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acADC, "AD7606模块"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acADC, "AD7705模块"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acADC, "ADS1256模块"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "RS485数码管"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "DAC8501"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "DAC8562"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "预留"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "示波器"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "串口WiFi"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "CAN网络"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "AD9833模块"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "预留4"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "预留5"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "预留6"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "预留7"},
{ID_ICON, 0, 0, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acChiLun, "预留8"},
};
/* 图标点击后,切换程序状态 */
static const uint8_t s_RetStatus[ICONS_COUNT] =
{
MS_HARDWARE_INFO, /* 硬件信息 */
MS_TEST_TOUCH, /* 测试触摸屏 */
MS_RADIO, /* 收音机 */
MS_WM8978_REC, /* 录音机 */
MS_MEMS, /* MEMS 传感器测试I2C 三轴陀螺仪,磁力计,气压计 */
MS_ETH_WEB, /* 以太网DM9000和DM9161 WEB服务器 */
MS_GPS, /* GPS测试 */
MS_GPRS, /* GPRS模块测试 */
MS_MP3, /* 校准触摸状态 */
MS_MASS_STORAGE, /* SD卡NAND模拟U盘 */
MS_CAMERA, /* 摄像头 */
MS_OLED, /* OLED显示器 */
MS_AD7606, /* 测试 AD7606 */
MS_AD7705, /* AD7705模块 */
MS_ADS1256, /* ADS1256模块 */
MS_RS485, /* RS485通信 */
MS_DAC8501, /* DAC8501 模块 */
MS_DAC8562, /* DAC8562 模块 */
MS_RA8875, /* RA8875字库 */
MS_DSO, /* 示波器 */
MS_WIFI, /* 串口WIFI */
MS_CAN, /* CAN网络测试 */
MS_AD9833, /* AD9833模块 */
MS_RESERVED,
MS_RESERVED,
MS_RESERVED,
MS_RESERVED,
MS_RESERVED};
static uint8_t s_IconsPageNo = 0; /* 图标页面, 一屏显示不下时自动排列到第2屏 */
static uint8_t s_IconsPageMax; /* 图标页面个数 */
static uint8_t s_IconNumPerPage; /* 每页面最多包含几个图片 */
static int16_t s_IconsCursor = 0; /* 选中的图标, -1表示无选中 */
static uint16_t s_down_x; /* 触笔按下时的x坐标 ; 用于识别滑动方向 */
static uint16_t s_down_y; /* 触笔按下时的y坐标 ; 用于识别滑动方向 */
#define STYLE_COUNT 7 /* 颜色方案个数 */
/* 主界面风格 */
typedef struct
{
uint16_t *pBmp; /* 背景图片指针如果是0, 则取单色背景参数 BackColor */
uint16_t BackColor; /* 背景颜色 */
uint16_t TextColor; /* 图标文本的颜色 */
} STYLE_T;
/*
RGB565格式NOR Flash
NOR Flash 0x6400 0000
0x0020 0000 255K字节 480x272_海滩.bin + 0x3FC00
0x0023 FC00 255K字节 480x272_树叶.bin
0x0027 F800 255K字节 480x272_水珠.bin
0x002B F400 755K字节 800x480_海滩.bin + 0xBB800
0x0037 AC00 755K字节 800x480_树叶.bin
0x0043 6400 755K字节 800x480_水珠.bin
*/
static const STYLE_T s_UI480[STYLE_COUNT] =
{
/* 背景图片, 背景颜色, 图标文字颜色 */
{0, CL_WHITE, CL_BLACK}, /* 白色背景 */
{0, RGB(0, 78, 152), CL_WHITE}, /* XP桌面蓝背景 */
{0, RGB(185, 193, 204), CL_BLACK}, /* 灰色背景 */
{0, RGB(38, 38, 38), CL_WHITE}, /* 深黑色背景 */
{(uint16_t *)(0x64000000 + 0x00200000), 0, CL_BLACK}, /* 480x272 沙滩背景 */
{(uint16_t *)(0x64000000 + 0x0023FC00), 0, CL_WHITE}, /* 480x272 树叶背景 */
{(uint16_t *)(0x64000000 + 0x0027F800), 0, CL_BLACK}, /* 480x272 水珠背景 */
};
static const STYLE_T s_UI800[STYLE_COUNT] =
{
/* 背景图片, 背景颜色, 图标文字颜色 */
{0, CL_WHITE, CL_BLACK}, /* 白色背景 */
{0, RGB(0, 78, 152), CL_WHITE}, /* XP桌面蓝背景 */
{0, RGB(185, 193, 204), CL_BLACK}, /* 灰色背景 */
{0, RGB(38, 38, 38), CL_WHITE}, /* 深黑色背景 */
{(uint16_t *)(0x64000000 + 0x002BF400), 0, CL_BLACK}, /* 800x480 沙滩背景 */
{(uint16_t *)(0x64000000 + 0x0037AC00), 0, CL_WHITE}, /* 800x480 树叶背景 */
{(uint16_t *)(0x64000000 + 0x00436400), 0, CL_BLACK}, /* 800x480 水珠背景 */
};
static uint16_t s_ColorIndex = 0; /* 当前选中的颜色方案序号 */
/* 图标文字颜色 */
#define MAIN_TEXT_COLOR ((g_LcdWidth == 480) ? s_UI480[s_ColorIndex].TextColor : s_UI800[s_ColorIndex].TextColor)
static void DispBackground(void);
static void ArrayIcon(void);
static void DispTopBar(void);
static void DispBottomBar(void);
/*
*********************************************************************************************************
* : MainMenu
* :
*
* :
*********************************************************************************************************
*/
uint8_t MainMenu(void)
{
#if 0
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fRefresh; /* 刷屏请求标志,1表示需要刷新 */
FONT_T tIconFont; /* 定义一个字体结构体变量,用于图标文本 */
int16_t tpX, tpY;
uint16_t i;
DispTopBar(); /* 显示顶部栏 */
DispBottomBar(); /* 显示底部栏 */
DispBackground(); /* 显示图标背景 */
/* 设置字体参数 */
{
tIconFont.FontCode = FC_ST_12; /* 字体代码 16点阵 */
tIconFont.FrontColor = MAIN_TEXT_COLOR; /* 字体颜色 */
tIconFont.BackColor = CL_MASK; /* 文字背景颜色 */
tIconFont.Space = 1; /* 文字间距,单位 = 像素 */
}
//s_IconsPageNo = 0; /* 图标页面号,不要清零。 */
fRefresh = 1; /* 1表示需要刷新LCD */
while (g_MainStatus == MS_MAIN_MENU)
{
bsp_Idle();
if (fRefresh)
{
fRefresh = 0;
/* 显示图标阵列 */
ArrayIcon(); /* 排列图标 */
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
/* 绘制图标阵列 */
{
s_IconsCursor = -1; /* -1 表示当前没有图标被激活点亮 */
for (i = s_IconNumPerPage * s_IconsPageNo;
i < s_IconNumPerPage * s_IconsPageNo + s_IconNumPerPage && i < ICONS_COUNT;
i++)
{
if (TOUCH_InRect(tpX, tpY, s_tMainIcons[i].Left, s_tMainIcons[i].Top,
s_tMainIcons[i].Height, s_tMainIcons[i].Width))
{
s_IconsCursor = i;
LCD_DrawIcon32(&s_tMainIcons[i], &tIconFont, 1); /* 0 表示正常显示, 1表示选中 */
}
}
s_down_x = tpX;
s_down_y = tpY;
}
break;
case TOUCH_MOVE: /* 触笔移动事件 */
if (s_IconsCursor >= 0)
{
if (TOUCH_InRect(tpX, tpY, s_tMainIcons[s_IconsCursor].Left, s_tMainIcons[s_IconsCursor].Top,
s_tMainIcons[s_IconsCursor].Height, s_tMainIcons[s_IconsCursor].Width))
{
;
}
else
{
LCD_DrawIcon32(&s_tMainIcons[s_IconsCursor], &tIconFont, 0); /* 0 表示正常显示, 1表示选中 */
s_IconsCursor = -1;
}
}
if (s_down_x > 0)
{
if (tpX - s_down_x > 50)
{
/* 向右滑动 */
if (s_IconsPageNo > 0)
{
s_IconsPageNo--;
DispBackground();
ArrayIcon(); /* 排列图标 */
}
s_down_x = 0;
}
else if (tpX - s_down_x < -50)
{
/* 向左滑动 */
if (s_IconsPageNo < s_IconsPageMax - 1)
{
s_IconsPageNo++;
DispBackground();
ArrayIcon(); /* 排列图标 */
}
s_down_x = 0;
}
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (s_IconsCursor >= 0)
{
/* 按下时的坐标和弹起时坐标都在图标内才算有效点击 */
if (TOUCH_InRect(tpX, tpY, s_tMainIcons[s_IconsCursor].Left, s_tMainIcons[s_IconsCursor].Top,
s_tMainIcons[s_IconsCursor].Height, s_tMainIcons[s_IconsCursor].Width)
&& TOUCH_InRect(s_down_x, s_down_y, s_tMainIcons[s_IconsCursor].Left, s_tMainIcons[s_IconsCursor].Top,
s_tMainIcons[s_IconsCursor].Height, s_tMainIcons[s_IconsCursor].Width))
{
g_MainStatus = s_RetStatus[s_IconsCursor]; /* 返回程序状态 */
}
else
{
LCD_DrawIcon32(&s_tMainIcons[s_IconsCursor], &tIconFont, 0); /* 0 表示正常显示, 1表示选中 */
s_IconsCursor = -1;
}
}
break;
default:
break;
}
}
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case JOY_DOWN_L: /* 遥杆右键 2014-08-22 */
return MS_RA8875; /* 进入RA8875界面 */
case JOY_DOWN_U: /* 遥杆上键 2014-08-22 */
return MS_TEST_TOUCH; /* 进入触摸界面 */
case JOY_DOWN_OK: /* 遥感OK键 */
if (++g_LcdDirection > 3)
{
g_LcdDirection = 0;
}
/* 显示方向代码 0 横屏正常, 1=横屏180度翻转, 2=竖屏, 3=竖屏180度翻转 */
LCD_SetDirection(g_LcdDirection);
DispTopBar(); /* 显示顶部栏 */
DispBottomBar(); /* 显示底部栏 */
DispBackground(); /* 显示背景 */
fRefresh = 1;
break;
case KEY_DOWN_K3: /* K3键 */
return MS_CALIBRATION; /* 进入触摸界面 */
//break;
case KEY_DOWN_K1: /* K1键 */
if (++s_ColorIndex >= STYLE_COUNT)
{
s_ColorIndex = 0;
}
/* 重新绘制背景 */
{
DispBackground(); /* 显示背景 */
/* 设置字体参数 */
{
tIconFont.FontCode = FC_ST_12; /* 字体代码 16点阵 */
tIconFont.FrontColor = MAIN_TEXT_COLOR; /* 字体颜色 */
tIconFont.BackColor = CL_MASK; /* 文字背景颜色 */
tIconFont.Space = 1; /* 文字间距,单位 = 像素 */
}
}
fRefresh = 1;
break;
default:
break;
}
}
}
#endif
return 0;
}
/*
*********************************************************************************************************
* : DispTopBar
* :
* :
* :
*********************************************************************************************************
*/
static void DispTopBar(void)
{
FONT_T tFont; /* 定义一个字体结构体变量,用于设置字体参数 */
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_WHITE; /* 字体颜色 */
tFont.BackColor = CL_BAR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
LCD_Fill_Rect(0, 0, TOP_BAR_H, g_LcdWidth, CL_BAR);
LCD_DispStr(5, 2, VER_INFO, &tFont); /* 显示软件版本信息 */
}
/*
*********************************************************************************************************
* : DispBottomBar
* :
* :
* :
*********************************************************************************************************
*/
static void DispBottomBar(void)
{
FONT_T tFont; /* 定义一个字体结构体变量,用于设置字体参数 */
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_WHITE; /* 字体颜色 */
tFont.BackColor = CL_BAR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
LCD_Fill_Rect(0, g_LcdHeight - BOTTOM_BAR_H, BOTTOM_BAR_H, g_LcdWidth, CL_BAR);
LCD_DispStr(5, g_LcdHeight - 18, KEY_INFO, &tFont); /* 显示按键操作提示 */
}
/*
*********************************************************************************************************
* : DispBackground
* :
* :
* :
*********************************************************************************************************
*/
static void DispBackground(void)
{
#if 1
if ((g_LcdWidth == 480) && (g_LcdHeight == 272)) /* 480 x 272 */
{
if (s_UI480[s_ColorIndex].pBmp == 0)
{
//LCD_ClrScr(s_UI480[s_ColorIndex].BackColor); /* 清屏, 填充单色 */
LCD_Fill_Rect(0, TOP_BAR_H, g_LcdHeight - TOP_BAR_H - BOTTOM_BAR_H, g_LcdWidth, s_UI480[s_ColorIndex].BackColor);
}
else
{
LCD_DrawBMP(0, TOP_BAR_H, g_LcdHeight - TOP_BAR_H - BOTTOM_BAR_H, g_LcdWidth, s_UI480[s_ColorIndex].pBmp);
}
}
else if ((g_LcdWidth == 480) && (g_LcdHeight == 320)) /* 480 x 320 */
{
if (s_UI480[s_ColorIndex].pBmp == 0)
{
//LCD_ClrScr(s_UI800[s_ColorIndex].BackColor); /* 清屏, 填充单色 */
LCD_Fill_Rect(0, TOP_BAR_H, g_LcdHeight - TOP_BAR_H - BOTTOM_BAR_H, g_LcdWidth, s_UI800[s_ColorIndex].BackColor);
}
else
{
LCD_DrawBMP(0, TOP_BAR_H, g_LcdHeight - TOP_BAR_H - BOTTOM_BAR_H, g_LcdWidth, s_UI800[s_ColorIndex].pBmp);
}
}
else /* 800 x 480 */
{
if (s_UI800[s_ColorIndex].pBmp == 0)
{
//LCD_ClrScr(s_UI800[s_ColorIndex].BackColor); /* 清屏, 填充单色 */
LCD_Fill_Rect(0, TOP_BAR_H, g_LcdHeight - TOP_BAR_H - BOTTOM_BAR_H, g_LcdWidth, s_UI800[s_ColorIndex].BackColor);
}
else
{
LCD_DrawBMP(0, TOP_BAR_H, g_LcdHeight - TOP_BAR_H - BOTTOM_BAR_H, g_LcdWidth, s_UI800[s_ColorIndex].pBmp);
}
}
#else
if ((g_LcdWidth == 480) && (g_LcdHeight == 272)) /* 480 x 272 */
{
if (s_UI480[s_ColorIndex].pBmp == 0)
{
LCD_ClrScr(s_UI480[s_ColorIndex].BackColor); /* 清屏, 填充单色 */
}
else
{
LCD_DrawBMP(0, 0, g_LcdHeight, g_LcdWidth, s_UI480[s_ColorIndex].pBmp);
}
}
else if ((g_LcdWidth == 480) && (g_LcdHeight == 320)) /* 480 x 320 */
{
if (s_UI480[s_ColorIndex].pBmp == 0)
{
LCD_ClrScr(s_UI800[s_ColorIndex].BackColor); /* 清屏, 填充单色 */
}
else
{
LCD_DrawBMP(0, 0, g_LcdHeight, g_LcdWidth, s_UI800[s_ColorIndex].pBmp);
}
}
else /* 800 x 480 */
{
if (s_UI800[s_ColorIndex].pBmp == 0)
{
LCD_ClrScr(s_UI800[s_ColorIndex].BackColor); /* 清屏, 填充单色 */
}
else
{
LCD_DrawBMP(0, 0, g_LcdHeight, g_LcdWidth, s_UI800[s_ColorIndex].pBmp);
}
}
#endif
}
/*
*********************************************************************************************************
* : ArrayIcon
* : s_tMainIcons s_IconsPageNo
* :
* :
*********************************************************************************************************
*/
static void ArrayIcon(void)
{
uint16_t x;
uint16_t y;
uint8_t h_count; /* 水平方向图标排列个数 */
uint8_t v_count; /* 垂直方向图标排列个数 */
uint16_t icon_index; /* 图标索引 */
uint16_t icons_left; /* 图标阵列 X 坐标 */
uint16_t icons_top; /* 图标阵列 Y 坐标 */
uint8_t m, n;
FONT_T tIconFont;
tIconFont.FontCode = FC_ST_12; /* 字体代码 16点阵 */
tIconFont.FrontColor = MAIN_TEXT_COLOR; /* 字体颜色 */
tIconFont.BackColor = CL_MASK; /* 文字背景颜色 */
tIconFont.Space = 1; /* 文字间距,单位 = 像素 */
h_count = g_LcdWidth / ICON_STEP_X;
v_count = (g_LcdHeight - TOP_BAR_H - BOTTOM_BAR_H) / ICON_STEP_Y;
s_IconNumPerPage = h_count * v_count; /* 每个页面包含的图标个数 */
/* 计算需要几个图片页面 */
s_IconsPageMax = (ICONS_COUNT - 1) / (h_count * v_count) + 1;
icons_left = (g_LcdWidth - (h_count - 1) * ICON_STEP_X - ICON_WIDTH) / 2;
icons_top = ICON_TOP;
icon_index = s_IconsPageNo * h_count * v_count;
x = icons_left;
y = icons_top;
for (m = 0; m < v_count; m++)
{
x = icons_left;
y = icons_top + m * ICON_STEP_Y;
for (n = 0; n < h_count; n++)
{
s_tMainIcons[icon_index].Left = x;
s_tMainIcons[icon_index].Top = y;
LCD_DrawIcon32(&s_tMainIcons[icon_index], &tIconFont, 0); /* 0 表示正常显示, 1表示选中 */
icon_index++;
if (icon_index >= ICONS_COUNT)
{
break;
}
x += ICON_STEP_X;
}
if (icon_index >= ICONS_COUNT)
{
break;
}
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,662 +0,0 @@
/*
*********************************************************************************************************
*
* : MEMS I2C ,
* : mems_test.c
* : V1.0
* : MPU-6050, HCM5833L, BMP085, BH1750
* :
*
* v1.0 2013-02-01 armfly
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_mems.h"
/* 4个框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H 120
#define BOX1_W 190
#define BOX1_TEXT "MPU6050 陀螺仪"
#define BOX2_X (BOX1_X + BOX1_W + 5)
#define BOX2_Y BOX1_Y
#define BOX2_H BOX1_H
#define BOX2_W 250
#define BOX2_TEXT "磁力计"
#define BOX3_X BOX1_X
#define BOX3_Y (BOX1_Y + BOX1_H + 5)
#define BOX3_H 52
#define BOX3_W 220
#define BOX3_TEXT "BMP085 气压计和温度"
#define BOX4_X (BOX1_X + BOX3_W + 5)
#define BOX4_Y (BOX1_Y + BOX1_H + 5)
#define BOX4_H 52
#define BOX4_W 220
#define BOX4_TEXT "BH1750 光照度"
#define BOX5_X BOX1_X
#define BOX5_Y (BOX3_Y + BOX3_H + 5)
#define BOX5_H 52
#define BOX5_W 220
#define BOX5_TEXT "DS18B20 温度传感器"
#define BOX6_X (BOX1_X + BOX5_W + 5)
#define BOX6_Y (BOX3_Y + BOX3_H + 5)
#define BOX6_H 52
#define BOX6_W 220
#define BOX6_TEXT "DHT11 温湿度传感器"
/* 返回按钮的坐标(屏幕右下角) */
#define BUTTON_RET_ID 0
#define BUTTON_RET_H 32
#define BUTTON_RET_W 60
#define BUTTON_RET_X (g_LcdWidth - BUTTON_RET_W - 4)
#define BUTTON_RET_Y (g_LcdHeight - BUTTON_RET_H - 4)
#define BUTTON_RET_TEXT "返回"
static void DispInitFace(void);
static void DispMPU6050(void);
static void DispHMC5833L(void);
static void DispBMP085(void);
static void DispBH1750(float _value);
static void DispDS18B20(void);
static void DispDHT11(void);
static void DispButton(uint8_t _id, uint8_t _focus);
static uint8_t s_use_dht11 = 0; /* 用来自动选择 DS18B20和 DHT11 */
/*
*********************************************************************************************************
* : TestMems
* :
*
* :
*********************************************************************************************************
*/
void TestMems(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
// uint8_t fRefresh; /* 刷屏请求标志,1表示需要刷新 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
DispInitFace();
// fRefresh = 1;
/* 重新配置1次BMP085 */
bsp_InitBMP085();
BMP085_ReadTempPress(); /* 读取结果存放在全局变量 */
if (i2c_CheckDevice(HMC5883L_SLAVE_ADDRESS) == 0)
{
bsp_InitHMC5883L();
}
bsp_InitMPU6050();
bsp_InitDS18B20();
/* 进入主程序循环体 */
bsp_StartAutoTimer(0, 250); /* 陀螺仪 加速度 磁力计 定时采样周期 */
bsp_DelayMS(125);
bsp_StartAutoTimer(1, 1000); /* 气压计和光照度定时采样周期 */
while (fQuit == 0)
{
bsp_Idle();
if (bsp_CheckTimer(0))
{
MPU6050_ReadData();
DispMPU6050();
HMC5883L_ReadData();
DispHMC5833L();
DispDS18B20(); /* 读取并显示DS18B20的数据 */
}
if (bsp_CheckTimer(1))
{
BMP085_ReadTempPress();
DispBMP085();
DispBH1750(BH1750_GetLux());
DispDHT11();
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BUTTON_RET_X, BUTTON_RET_Y, BUTTON_RET_H, BUTTON_RET_W))
{
DispButton(BUTTON_RET_ID, 1);
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BUTTON_RET_X, BUTTON_RET_Y, BUTTON_RET_H, BUTTON_RET_W))
{
DispButton(BUTTON_RET_ID, 0);
fQuit = 1; /* 返回 */
}
else /* 按钮失去焦点 */
{
DispButton(BUTTON_RET_ID, 0);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键切换音频格式在下次开始录音和放音时有效 */
break;
case KEY_DOWN_K2: /* K2键按下录音 */
break;
case KEY_DOWN_K3: /* K3键按下放音 */
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
bsp_StopTimer(0);
bsp_StopTimer(1);
}
/*
*********************************************************************************************************
* : DispMPU6050
* : MPU6050输出数据
*
* :
*********************************************************************************************************
*/
static void DispMPU6050(void)
{
FONT_T tFont;
char buf[128];
uint16_t x, y;
uint8_t ucLineCap = 17;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_BLUE; /* 字体颜色 */
tFont.BackColor = CL_BTN_FACE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = BOX1_X + 5;
y = BOX1_Y + 18;
sprintf(buf, "GYRO_X = %6d", g_tMPU6050.GYRO_X);
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
sprintf(buf, "GYRO_Y = %6d", g_tMPU6050.GYRO_Y);
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
sprintf(buf, "GYRO_Z = %6d", g_tMPU6050.GYRO_Z);
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
sprintf(buf, "Accel_X = %6d", g_tMPU6050.Accel_X);
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
sprintf(buf, "Accel_Y = %6d", g_tMPU6050.Accel_Y);
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
sprintf(buf, "Accel_Z = %6d", g_tMPU6050.Accel_Z);
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
}
/*
*********************************************************************************************************
* : DispHMC5833L
* : HMC5833L输出的数据
*
* :
*********************************************************************************************************
*/
static void DispHMC5833L(void)
{
FONT_T tFont;
char buf[128];
uint16_t x, y;
uint8_t ucLineCap = 17;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_BLUE; /* 字体颜色 */
tFont.BackColor = CL_BTN_FACE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = BOX2_X + 5;
y = BOX2_Y + 18;
sprintf(buf, " 当前 | 最小, 最大,范围");
tFont.FrontColor = CL_GREY; /* 红色 异常*/
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
sprintf(buf, "X =%5d|%5d,%5d,%5d", g_tMag.X, g_tMag.X_Min, g_tMag.X_Max,
g_tMag.X_Max - g_tMag.X_Min);
if (g_tMag.X_Max - g_tMag.X_Min < 500)
{
tFont.FrontColor = CL_RED; /* 红色 异常*/
}
else
{
tFont.FrontColor = CL_BLACK; /* 白色 正常 */
}
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
sprintf(buf, "Y =%5d|%5d,%5d,%5d", g_tMag.Y, g_tMag.Y_Min, g_tMag.Y_Max,
g_tMag.Y_Max - g_tMag.Y_Min);
if (g_tMag.Y_Max - g_tMag.Y_Min < 500)
{
tFont.FrontColor = CL_RED; /* 红色 异常*/
}
else
{
tFont.FrontColor = CL_BLACK; /* 白色 正常 */
}
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
sprintf(buf, "Z =%5d|%5d,%5d,%5d", g_tMag.Z, g_tMag.Z_Min, g_tMag.Z_Max,
g_tMag.Z_Max - g_tMag.Z_Min);
if (g_tMag.Z_Max - g_tMag.Z_Min < 500)
{
tFont.FrontColor = CL_RED; /* 红色 异常*/
}
else
{
tFont.FrontColor = CL_BLACK; /* 白色 正常 */
}
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
/* 显示配置寄存器和ID寄存器 */
y += 3;
tFont.FrontColor = CL_GREY; /* 字体颜色 */
sprintf(buf, "CFG_A = 0x%02X,CFG_B = 0x%02X", g_tMag.CfgRegA, g_tMag.CfgRegB);
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
sprintf(buf, "Mode = 0x%02d,ID = %s", g_tMag.ModeReg, (char *)g_tMag.IDReg);
LCD_DispStr(x, y, buf, &tFont);
}
/*
*********************************************************************************************************
* : DispBMP085
* : BMP085输出的数据
*
* :
*********************************************************************************************************
*/
static void DispBMP085(void)
{
FONT_T tFont;
char buf[128];
uint16_t x, y;
uint8_t ucLineCap = 17;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_BLUE; /* 字体颜色 */
tFont.BackColor = CL_BTN_FACE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = BOX3_X + 5;
y = BOX3_Y + 18;
/* 温度值, 单位 0.1摄氏度 */
/* 压力值, 单位 Pa */
sprintf(buf, "环境温度 = %3d.%d℃", g_tBMP085.Temp / 10, g_tBMP085.Temp % 10);
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
sprintf(buf, "大气压力 = %3d.%03dKPa", g_tBMP085.Press / 1000, g_tBMP085.Press % 1000);
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
}
/*
*********************************************************************************************************
* : DispBH1750
* : BH1750输出的数据
* : _value :
* :
*********************************************************************************************************
*/
static void DispBH1750(float _value)
{
FONT_T tFont;
char buf[128];
uint16_t x, y;
uint8_t ucLineCap = 17;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_BLUE; /* 字体颜色 */
tFont.BackColor = CL_BTN_FACE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = BOX4_X + 5;
y = BOX4_Y + 18;
sprintf(buf, "光照度 = %6.2f lux", _value);
LCD_DispStr(x, y, buf, &tFont);
y += ucLineCap;
}
/*
*********************************************************************************************************
* : DispDS18B20
* : DS18B20输出的数据
* :
* :
*********************************************************************************************************
*/
static void DispDS18B20(void)
{
FONT_T tFont;
char buf[128];
uint16_t x, y;
if (s_use_dht11 == 1)
{
/* 在DS18B20程序中 暂时屏蔽, 避免印象 DHT11 */
return;
}
/* 读 ROM ID */
{
uint8_t id[8];
uint8_t ret;
uint8_t i;
x = BOX5_X + 5;
y = BOX5_Y + 18;
ret = DS18B20_ReadID(id);
if (ret == 0)
{
/* 设置字体参数 红色 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_RED; /* 字体颜色 */
tFont.BackColor = CL_BTN_FACE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
}
else
{
/* 设置字体参数 蓝色 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_BLUE; /* 字体颜色 */
tFont.BackColor = CL_BTN_FACE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
}
sprintf(buf, "id = ");
for (i = 0; i < 8; i++)
{
sprintf(&buf[strlen(buf)], "%02X", id[i]);
if (i == 3)
{
sprintf(&buf[strlen(buf)], " ");
}
}
LCD_DispStr(x, y, buf, &tFont);
}
{
int16_t reg;
reg = DS18B20_ReadTempReg();
sprintf(buf, "reg = 0x%04X -> %-4.04f℃ ", (uint16_t)reg, (float)reg / 16);
x = BOX5_X + 5;
y += 17;
/* 设置字体参数 蓝色 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_BLUE; /* 字体颜色 */
tFont.BackColor = CL_BTN_FACE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
LCD_DispStr(x, y, buf, &tFont);
LCD_DispStr(x, y + 26, "DS18B20和DHT11不能同时接入开发板", &tFont);
}
}
/*
*********************************************************************************************************
* : DispDHT11
* : DHT11输出的数据
* :
* :
*********************************************************************************************************
*/
static void DispDHT11(void)
{
FONT_T tFont;
char buf[128];
uint16_t x, y;
DHT11_T tDHT;
uint8_t ret;
x = BOX6_X + 5;
y = BOX6_Y + 18;
ret = DHT11_ReadData(&tDHT);
if (ret == 1)
{
/* 设置字体参数 蓝色 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_BLUE; /* 字体颜色 */
tFont.BackColor = CL_BTN_FACE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
sprintf(buf, "湿度 %d%%,温度 %d℃ ", tDHT.Hum, tDHT.Temp);
LCD_DispStr(x, y, buf, &tFont);
s_use_dht11 = 1; /* 在DS18B20程序中 暂时屏蔽 */
}
else
{
/* 设置字体参数 红色 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_RED; /* 字体颜色 */
tFont.BackColor = CL_BTN_FACE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
sprintf(buf, "未发现DHT11 ");
LCD_DispStr(x, y, buf, &tFont);
s_use_dht11 = 0; /* 在DS18B20程序中 取消屏蔽 */
}
}
/*
*********************************************************************************************************
* : DispInitFace
* :
*
* :
*********************************************************************************************************
*/
static void DispInitFace(void)
{
FONT_T tFontBox; /* 定义一个字体结构体变量,用于设置字体参数 */
GROUP_T tBox;
LCD_ClrScr(CL_BTN_FACE); /* 清屏,背景蓝色 */
/* 设置字体参数 */
{
/* 分组框字体 */
tFontBox.FontCode = FC_ST_16;
tFontBox.BackColor = CL_BTN_FACE;
tFontBox.FrontColor = CL_BLACK;
tFontBox.Space = 0;
}
/* 显示分组框 */
{
tBox.Font = &tFontBox;
tBox.Left = BOX1_X;
tBox.Top = BOX1_Y;
tBox.Height = BOX1_H;
tBox.Width = BOX1_W;
tBox.pCaption = BOX1_TEXT;
LCD_DrawGroupBox(&tBox);
tBox.Left = BOX2_X;
tBox.Top = BOX2_Y;
tBox.Height = BOX2_H;
tBox.Width = BOX2_W;
tBox.pCaption = BOX2_TEXT;
LCD_DrawGroupBox(&tBox);
tBox.Left = BOX3_X;
tBox.Top = BOX3_Y;
tBox.Height = BOX3_H;
tBox.Width = BOX3_W;
tBox.pCaption = BOX3_TEXT;
LCD_DrawGroupBox(&tBox);
tBox.Left = BOX4_X;
tBox.Top = BOX4_Y;
tBox.Height = BOX4_H;
tBox.Width = BOX4_W;
tBox.pCaption = BOX4_TEXT;
LCD_DrawGroupBox(&tBox);
tBox.Left = BOX5_X;
tBox.Top = BOX5_Y;
tBox.Height = BOX5_H;
tBox.Width = BOX5_W;
tBox.pCaption = BOX5_TEXT;
LCD_DrawGroupBox(&tBox);
tBox.Left = BOX6_X;
tBox.Top = BOX6_Y;
tBox.Height = BOX6_H;
tBox.Width = BOX6_W;
tBox.pCaption = BOX6_TEXT;
LCD_DrawGroupBox(&tBox);
}
DispButton(BUTTON_RET_ID, 0);
}
/*
*********************************************************************************************************
* : DispButton
* :
*
* :
*********************************************************************************************************
*/
static void DispButton(uint8_t _id, uint8_t _focus)
{
FONT_T tFontBtn; /* 定义一个字体结构体变量,用于设置字体参数 */
BUTTON_T tBtn;
/* 设置字体参数 */
{
/* 按钮字体 */
tFontBtn.FontCode = FC_ST_16;
tFontBtn.BackColor = CL_MASK; /* 透明色 */
tFontBtn.FrontColor = CL_BLACK;
tFontBtn.Space = 0;
}
tBtn.Font = &tFontBtn;
switch (_id)
{
case BUTTON_RET_ID:
tBtn.Left = BUTTON_RET_X;
tBtn.Top = BUTTON_RET_Y;
tBtn.Height = BUTTON_RET_H;
tBtn.Width = BUTTON_RET_W;
tBtn.Focus = _focus;
tBtn.pCaption = BUTTON_RET_TEXT;
break;
default:
return;
}
LCD_DrawButton(&tBtn);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,799 +0,0 @@
/*
*********************************************************************************************************
*
* : MP3播放器界面
* : "mp3_player.h"
* : V1.1
* : VS1053 MP3模块
* :
*
* V1.0 2013-02-01 armfly
* V1.1 2015-10-17 armfly f_opendir后必须f_closedir
*
* Copyright (C), 2015-2020, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_mp3_player.h"
#include "ff.h" /* FatFS 文件系统头文件 */
#include "ff_gen_drv.h"
#include "sd_diskio_dma.h"
/* 自动播放指定磁盘指定目录下的MP3文件 */
#define MP3_FOLDER "/Music" /* MP3文件夹, 不含磁盘盘符 */
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
LABEL_T Label6;
LABEL_T Label7;
LABEL_T Label8;
LABEL_T Label9;
BUTTON_T BtnRet;
} FormMP3_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "MP3模块测试程序"
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define LABEL1_X (BOX1_X + 6)
#define LABEL1_Y (BOX1_Y + 20)
#define LABEL1_TEXT "芯片型号 :"
#define LABEL2_X (LABEL1_X + 90)
#define LABEL2_Y LABEL1_Y
#define LABEL2_TEXT " "
#define LABEL3_X (LABEL1_X)
#define LABEL3_Y (LABEL1_Y + 20)
#define LABEL3_TEXT "输出音量 :"
#define LABEL4_X (LABEL3_X + 90)
#define LABEL4_Y (LABEL3_Y)
#define LABEL4_TEXT " "
#define LABEL5_X (LABEL1_X)
#define LABEL5_Y (LABEL1_Y + 20 * 2)
#define LABEL5_TEXT "播放进度 : "
#define LABEL6_X (LABEL5_X + 90)
#define LABEL6_Y LABEL5_Y
#define LABEL6_TEXT " "
#define LABEL7_X (LABEL1_X)
#define LABEL7_Y (LABEL1_Y + 20 * 3)
#define LABEL7_TEXT "文件名 : "
#define LABEL8_X (LABEL7_X + 90)
#define LABEL8_Y LABEL7_Y
#define LABEL8_TEXT "---"
#define LABEL9_X LABEL1_X
#define LABEL9_Y 120
#define LABEL9_TEXT "请将MP3文件放到SD卡Music目录下"
#define SONG_LIST_MAX 10 /* 歌曲列表最大数目 */
static void InitFormMP3(void);
static void DispFormMP3(void);
static void FillSongList(void);
static void MP3HardInit(void);
static void ViewDir(char *_path);
static uint8_t Mp3Pro(void);
static void Mp3DispStatus(void);
FormMP3_T *FormMP3;
MP3_T g_tMP3;
PLAY_LIST_T g_tPlayList[SONG_LIST_MAX];
/* 访问Fatfs用到的全局变量 */
FATFS g_fs;
FIL g_Mp3File;
char DiskPath[4]; /* 保存FatFS 磁盘路径 */
/*
*********************************************************************************************************
* : ReserveFunc
* :
*
* :
*********************************************************************************************************
*/
void MP3Player(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
FormMP3_T form;
uint8_t ucRefresh;
uint8_t ucNextSong;
FormMP3 = &form;
InitFormMP3();
DispFormMP3();
MP3HardInit(); /* 配置VS1053B硬件和WM8978硬件 */
//FATFS_LinkDriver(&USBH_Driver, DiskPath);
FATFS_LinkDriver(&SD_Driver, DiskPath);
/* 挂载文件系统 */
if (f_mount(&g_fs, DiskPath, 0) != FR_OK)
{
printf("f_mount文件系统失败");
}
#if 1
/* 打印NAND Flash 根目录和MP3目录下的文件 */
{
char path[60];
sprintf(path, "%s", DiskPath); /* 根目录 */
ViewDir(path);
sprintf(path, "%s%s", DiskPath, MP3_FOLDER); /* 音乐目录 */
ViewDir(path);
}
#endif
FillSongList(); /* 搜索NAND Flash 根目录下的MP3文件并填充到播放列表数组 */
ucRefresh = 1;
g_tMP3.ucPauseEn = 0; /* 缺省开始播放 */
if (g_tMP3.ListCount > 0)
{
ucNextSong = 1; /* 定位下一首歌曲的标志 */
}
else
{
ucNextSong = 0;
}
g_tMP3.ListIndex = 0;
bsp_StartAutoTimer(0, 100); /* 100ms 刷新进度条 */
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
/* 打开歌曲文件 */
if (ucNextSong == 1)
{
ucNextSong = 0;
/* 关闭上一个文件*/
f_close(&g_Mp3File);
printf("\r\n\r\n"); /* 换一行显示 */
/* 打开MUSIC目录下的mp3 文件 */
{
char FileName[256];
FRESULT result;
sprintf(FileName, "%s%s/%s", DiskPath, MP3_FOLDER, g_tPlayList[g_tMP3.ListIndex].FileName);
result = f_open(&g_Mp3File, FileName, FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK)
{
printf("Open MP3 file Error, %s\r\n", g_tPlayList[g_tMP3.ListIndex].FileName);
FormMP3->Label8.pCaption = "打开MP3文件失败";
LCD_DrawLabel(&FormMP3->Label8);
}
else
{
printf("正在播放: %s\r\n", g_tPlayList[g_tMP3.ListIndex].FileName);
/* 显示文件名 */
FormMP3->Label8.pCaption = g_tPlayList[g_tMP3.ListIndex].FileName;
LCD_DrawLabel(&FormMP3->Label8);
}
}
g_tMP3.uiProgress = 0; /* 进度 */
}
if (g_tMP3.ucPauseEn == 0)
{
if (Mp3Pro() == 1)
{
/* 歌曲播放完毕,自动切换到下一首歌 */
if (g_tMP3.ListCount > 0)
{
/* 模拟一个摇杆右键按下,执行换歌操作 */
bsp_PutKey(JOY_DOWN_R);
}
}
}
/* 刷新状态栏 */
if ((ucRefresh == 1) || (bsp_CheckTimer(0)))
{
ucRefresh = 0;
Mp3DispStatus(); /* 显示当前状态,音量等 */
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormMP3->BtnRet.Focus = 1;
LCD_DrawButton(&FormMP3->BtnRet);
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormMP3->BtnRet.Focus = 0;
LCD_DrawButton(&FormMP3->BtnRet);
fQuit = 1; /* 返回 */
}
else /* 按钮失去焦点 */
{
FormMP3->BtnRet.Focus = 0;
LCD_DrawButton(&FormMP3->BtnRet);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键按下 */
if (g_tMP3.ucPauseEn == 0)
{
g_tMP3.ucPauseEn = 1;
}
else
{
g_tMP3.ucPauseEn = 0;
}
ucRefresh = 1;
break;
case KEY_DOWN_K2: /* K2键按下 */
f_lseek(&g_Mp3File, 0); /* 修改文件当前指针到文件头, 从头开始播放 */
g_tMP3.uiProgress = 0; /* 进度 */
ucRefresh = 1;
break;
case KEY_DOWN_K3: /* K3键按下 */
if (g_tMP3.ucMuteOn == 1)
{
g_tMP3.ucMuteOn = 0;
VS1053_SetBASS(0, 0, 0, 0); /* 原音,低音不增强 */
}
else
{
g_tMP3.ucMuteOn = 1;
VS1053_SetBASS(0, 0, 10, 100); /* 设置低音增强(截止频率100Hz),高音不变 */
}
ucRefresh = 1;
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
if (g_tMP3.ucVolume > VS_VOL_MIN)
{
g_tMP3.ucVolume--;
VS1053_SetVolume(g_tMP3.ucVolume);
ucRefresh = 1;
}
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
if (g_tMP3.ucVolume < VS_VOL_MAX)
{
g_tMP3.ucVolume++;
VS1053_SetVolume(g_tMP3.ucVolume);
ucRefresh = 1;
}
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
if (g_tMP3.ListIndex > 0)
{
g_tMP3.ListIndex--; /* 前一首歌 */
}
else
{
g_tMP3.ListIndex = g_tMP3.ListCount - 1; /* 循环 */
}
ucRefresh = 1;
ucNextSong = 1; /* 打开下一首歌曲 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
if (g_tMP3.ListIndex < g_tMP3.ListCount - 1)
{
g_tMP3.ListIndex++; /* 下一首歌 */
}
else
{
g_tMP3.ListIndex = 0; /* 循环 */
}
ucRefresh = 1;
ucNextSong = 1; /* 打开下一首歌曲 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
ucRefresh = 1;
break;
default:
break;
}
}
}
bsp_StopTimer(0); /* 关闭自动定时器 */
/* 关闭文件*/
f_close(&g_Mp3File);
/* 卸载文件系统 */
f_mount(NULL, DiskPath, 0);
FATFS_UnLinkDriver(DiskPath); /* 卸载驱动 */
}
/*
*********************************************************************************************************
* : InitFormMP3
* :
*
* :
*********************************************************************************************************
*/
static void InitFormMP3(void)
{
/* 分组框标题字体 */
FormMP3->FontBox.FontCode = FC_ST_16;
FormMP3->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormMP3->FontBox.FrontColor = CL_BLACK;
FormMP3->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormMP3->FontBlack.FontCode = FC_ST_16;
FormMP3->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormMP3->FontBlack.FrontColor = CL_BLACK;
FormMP3->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormMP3->FontBlue.FontCode = FC_ST_16;
FormMP3->FontBlue.BackColor = CL_BTN_FACE;
FormMP3->FontBlue.FrontColor = CL_BLUE;
FormMP3->FontBlue.Space = 0;
/* 按钮字体 */
FormMP3->FontBtn.FontCode = FC_ST_16;
FormMP3->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormMP3->FontBtn.FrontColor = CL_BLACK;
FormMP3->FontBtn.Space = 0;
/* 分组框 */
FormMP3->Box1.Left = BOX1_X;
FormMP3->Box1.Top = BOX1_Y;
FormMP3->Box1.Height = BOX1_H;
FormMP3->Box1.Width = BOX1_W;
FormMP3->Box1.pCaption = BOX1_TEXT;
FormMP3->Box1.Font = &FormMP3->FontBox;
/* 静态标签 */
FormMP3->Label1.Left = LABEL1_X;
FormMP3->Label1.Top = LABEL1_Y;
FormMP3->Label1.MaxLen = 0;
FormMP3->Label1.pCaption = LABEL1_TEXT;
FormMP3->Label1.Font = &FormMP3->FontBlack;
FormMP3->Label3.Left = LABEL3_X;
FormMP3->Label3.Top = LABEL3_Y;
FormMP3->Label3.MaxLen = 0;
FormMP3->Label3.pCaption = LABEL3_TEXT;
FormMP3->Label3.Font = &FormMP3->FontBlack;
FormMP3->Label5.Left = LABEL5_X;
FormMP3->Label5.Top = LABEL5_Y;
FormMP3->Label5.MaxLen = 0;
FormMP3->Label5.pCaption = LABEL5_TEXT;
FormMP3->Label5.Font = &FormMP3->FontBlack;
FormMP3->Label7.Left = LABEL7_X;
FormMP3->Label7.Top = LABEL7_Y;
FormMP3->Label7.MaxLen = 0;
FormMP3->Label7.pCaption = LABEL7_TEXT;
FormMP3->Label7.Font = &FormMP3->FontBlack;
FormMP3->Label9.Left = LABEL9_X;
FormMP3->Label9.Top = LABEL9_Y;
FormMP3->Label9.MaxLen = 0;
FormMP3->Label9.pCaption = LABEL9_TEXT;
FormMP3->Label9.Font = &FormMP3->FontBlack;
/* 动态标签 */
FormMP3->Label2.Left = LABEL2_X;
FormMP3->Label2.Top = LABEL2_Y;
FormMP3->Label2.MaxLen = 0;
FormMP3->Label2.pCaption = LABEL2_TEXT;
FormMP3->Label2.Font = &FormMP3->FontBlue;
FormMP3->Label4.Left = LABEL4_X;
FormMP3->Label4.Top = LABEL4_Y;
FormMP3->Label4.MaxLen = 0;
FormMP3->Label4.pCaption = LABEL4_TEXT;
FormMP3->Label4.Font = &FormMP3->FontBlue;
FormMP3->Label6.Left = LABEL6_X;
FormMP3->Label6.Top = LABEL6_Y;
FormMP3->Label6.MaxLen = 0;
FormMP3->Label6.pCaption = LABEL6_TEXT;
FormMP3->Label6.Font = &FormMP3->FontBlue;
FormMP3->Label8.Left = LABEL8_X;
FormMP3->Label8.Top = LABEL8_Y;
FormMP3->Label8.MaxLen = 0;
FormMP3->Label8.pCaption = LABEL8_TEXT;
FormMP3->Label8.Font = &FormMP3->FontBlue;
/* 按钮 */
FormMP3->BtnRet.Left = BTN_RET_X;
FormMP3->BtnRet.Top = BTN_RET_Y;
FormMP3->BtnRet.Height = BTN_RET_H;
FormMP3->BtnRet.Width = BTN_RET_W;
FormMP3->BtnRet.pCaption = BTN_RET_TEXT;
FormMP3->BtnRet.Font = &FormMP3->FontBtn;
FormMP3->BtnRet.Focus = 0;
}
/*
*********************************************************************************************************
* : DispFormMP3
* :
* :
* :
*********************************************************************************************************
*/
static void DispFormMP3(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormMP3->Box1);
/* 静态标签 */
LCD_DrawLabel(&FormMP3->Label1);
LCD_DrawLabel(&FormMP3->Label3);
LCD_DrawLabel(&FormMP3->Label5);
LCD_DrawLabel(&FormMP3->Label7);
LCD_DrawLabel(&FormMP3->Label9);
/* 动态标签 */
LCD_DrawLabel(&FormMP3->Label2);
LCD_DrawLabel(&FormMP3->Label4);
LCD_DrawLabel(&FormMP3->Label6);
LCD_DrawLabel(&FormMP3->Label8);
/* 按钮 */
LCD_DrawButton(&FormMP3->BtnRet);
}
/*
*********************************************************************************************************
* : MP3HardInit
* : MP3播放相关的硬件
* :
* :
*********************************************************************************************************
*/
static void MP3HardInit(void)
{
/* 配置VS1053硬件 */
{
VS1053_Init();
/* 等待芯片内部操作完成 */
if (VS1053_WaitTimeOut())
{
/* 如果没有插VS1053B模块DREQ口线将返回低电平这是一种异常情况 */
FormMP3->Label2.pCaption = "没有检测到MP3模块硬件";
LCD_DrawLabel(&FormMP3->Label2); /* 显示芯片型号 */
return;
}
VS1053_SoftReset();
/* 打印MP3解码芯片型号 */
{
char *pModel;
switch (VS1053_ReadChipID())
{
case VS1001:
pModel = "VS1001";
break;
case VS1011:
pModel = "VS1011";
break;
case VS1002:
pModel = "VS1002";
break;
case VS1003:
pModel = "VS1003";
break;
case VS1053:
pModel = "VS1053";
break;
case VS1033:
pModel = "VS1033";
break;
case VS1103:
pModel = "VS1103";
break;
default:
pModel = "unknow";
break;
}
FormMP3->Label2.pCaption = pModel;
LCD_DrawLabel(&FormMP3->Label2); /* 显示芯片型号 */
}
g_tMP3.ucVolume = 200; /* 缺省音量,越大声音越小 */
VS1053_SetVolume(g_tMP3.ucVolume);
VS1053_SetBASS(0, 0, 0, 0); /* 高频和低音不增强 */
}
/* 配置WM8978音频通道, 可以将VS1053B的输出音频接入WM8978的Line输入插座 驱动板子上的扬声器放音 */
{
/* bsp.c 中已经初始化I2C总线 */
wm8978_Init(); /* 复位WM8978到复位状态 */
wm8978_SetSpkVolume(0); /* 临时静音扬声器 */
/* 配置WM8978芯片输入为LINE IN输出为耳机和扬声器 */
wm8978_CfgAudioPath(LINE_ON, EAR_LEFT_ON | EAR_RIGHT_ON | SPK_ON);
/* 调节放音音量,左右相同音量 */
wm8978_SetEarVolume(30); /* 设置耳机音量最大63 */
wm8978_SetSpkVolume(60); /* 设置扬声器音量最大63 */
wm8978_SetLineGain(6); /* 设置Line输入增益 0-7 */
}
}
/*
*********************************************************************************************************
* : FillSongList
* : NAND Flash根目录下的歌曲10
* :
* :
*********************************************************************************************************
*/
static void FillSongList(void)
{
/* 访问Fatfs用到的全局变量 */
FRESULT result;
FILINFO FileInf;
DIR DirInf;
char path[128];
/* 打开歌曲目录 */
sprintf(path, "%s%s", DiskPath, MP3_FOLDER);
result = f_opendir(&DirInf, path); /* path可以带盘符最后一个字符不能是/ */
if (result != FR_OK)
{
printf("Open Root Directory Error (%d)\r\n", result);
}
g_tMP3.ListIndex = 0;
g_tMP3.ListCount = 0; /* 歌曲个数 */
for (;;)
{
result = f_readdir(&DirInf, &FileInf); /* 读取目录项,索引会自动下移 */
if (result != FR_OK || FileInf.fname[0] == 0)
{
break;
}
if (FileInf.fname[0] == '.') /* 表示目录 */
{
continue;
}
if (FileInf.fattrib != AM_DIR)
{
uint8_t Len;
//altname fname
Len = strlen(FileInf.altname);
if (Len >= 5)
{
if (memcmp(&FileInf.altname[Len - 3], "MP3", 3) == 0)
{
/* 复制MP3文件名到播放列表 */
strcpy(g_tPlayList[g_tMP3.ListCount].FileName, FileInf.altname);
g_tPlayList[g_tMP3.ListCount].FileSize = FileInf.fsize;
g_tMP3.ListCount++; /* 歌曲个数 */
/* 如果MP3文件已填满则退出 */
if (g_tMP3.ListCount > SONG_LIST_MAX)
{
break;
}
}
}
}
}
if (g_tMP3.ListCount == 0)
{
printf("没有在根目录下找到 MP3 文件\r\n");
}
}
/*
*********************************************************************************************************
* : Mp3Pro
* : MP3文件播放while循环中调用. VS105B发送32字节
* :
* : 0 ; 1 ,
*********************************************************************************************************
*/
static uint8_t Mp3Pro(void)
{
uint32_t bw, i;
char buf[32];
/* 如果VS1003空闲则写入新的数据 */
if (VS1053_ReqNewData())
{
f_read(&g_Mp3File, &buf, 32, &bw);
if (bw <= 0)
{
return 1;
}
/* 计算进度 */
g_tMP3.uiProgress += bw;
VS1053_PreWriteData(); /* 写数据准备,设置好片选 */
for (i = 0; i < bw; i++)
{
VS1053_WriteData(buf[i]);
}
}
return 0;
}
/*
*********************************************************************************************************
* : Mp3DispStatus
* :
* :
* :
*********************************************************************************************************
*/
static void Mp3DispStatus(void)
{
char buf[5];
/* 显示音量 */
sprintf(buf, "%3d ", g_tMP3.ucVolume);
FormMP3->Label4.pCaption = buf;
LCD_DrawLabel(&FormMP3->Label4);
/* 显示进度 */
sprintf(buf, "%3d%%", g_tMP3.uiProgress * 100 / g_tPlayList[g_tMP3.ListIndex].FileSize);
FormMP3->Label6.pCaption = buf;
LCD_DrawLabel(&FormMP3->Label6);
}
/*
*********************************************************************************************************
* : ViewDir
* :
* :
* :
*********************************************************************************************************
*/
static void ViewDir(char *_path)
{
/* 本函数使用的局部变量占用较多,请修改启动文件,保证堆栈空间够用 */
FRESULT result;
DIR DirInf;
FILINFO FileInf;
uint32_t cnt = 0;
/* 打开根文件夹 - 用完后需要 f_closedir */
result = f_opendir(&DirInf, _path); /* 1: 表示盘符 */
if (result != FR_OK)
{
printf("打开根目录失败 (%d)\r\n", result);
return;
}
printf("\r\n当前目录:%s\r\n", _path);
/* 读取当前文件夹下的文件和目录 */
printf("属性 | 文件大小 | 短文件名 | 长文件名\r\n");
for (cnt = 0;; cnt++)
{
result = f_readdir(&DirInf, &FileInf); /* 读取目录项,索引会自动下移 */
if (result != FR_OK || FileInf.fname[0] == 0)
{
break;
}
if (FileInf.fname[0] == '.')
{
continue;
}
/* 判断是文件还是子目录 */
if (FileInf.fattrib & AM_DIR)
{
printf("(0x%02d)目录 ", FileInf.fattrib);
}
else
{
printf("(0x%02d)文件 ", FileInf.fattrib);
}
/* 打印文件大小, 最大4G */
printf(" %10d", FileInf.fsize);
printf(" %s |", FileInf.altname); /* 短文件名 */
printf(" %s\r\n", (char *)FileInf.fname); /* 长文件名 */
}
f_closedir(&DirInf); /* 关闭打开的目录 */
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,483 +0,0 @@
/*
*********************************************************************************************************
*
* : OLED显示器
* : oled_test.c
* : V1.1
* : OLED显示器模块
* :
*
* v1.0 2013-02-01 armfly
* v1.1 2015-10-14 armfly 2432ASCII显示功能
*
* Copyright (C), 2015-2020, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_oled.h"
#define DEMO_PAGE_COUNT 7 /* OLED演示页面的个数 */
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
LABEL_T Label6;
LABEL_T Label7;
LABEL_T Label8;
BUTTON_T BtnRet;
} FormOLED_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "OLED显示模块测试程序"
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define LABEL1_X (BOX1_X + 6)
#define LABEL1_Y (BOX1_Y + 20)
#define LABEL1_TEXT "摇杆左、右键: "
#define LABEL2_X (LABEL1_X + 135)
#define LABEL2_Y LABEL1_Y
#define LABEL2_TEXT "切换OLED显示界面"
#define LABEL3_X (LABEL1_X)
#define LABEL3_Y (LABEL1_Y + 20)
#define LABEL3_TEXT "摇杆上、下键: "
#define LABEL4_X (LABEL3_X + 135)
#define LABEL4_Y (LABEL3_Y)
#define LABEL4_TEXT "调节OLED对比度"
#define LABEL5_X (LABEL1_X)
#define LABEL5_Y (LABEL1_Y + 20 * 2)
#define LABEL5_TEXT "摇杆OK键 : "
#define LABEL6_X (LABEL5_X + 135)
#define LABEL6_Y LABEL5_Y
#define LABEL6_TEXT "切换显示方向"
#define LABEL7_X (LABEL1_X)
#define LABEL7_Y (LABEL1_Y + 20 * 3)
#define LABEL7_TEXT "当前状态 :"
#define LABEL8_X (LABEL7_X + 135)
#define LABEL8_Y LABEL7_Y
#define LABEL8_TEXT "80"
static void InitFormOLED(void);
static void DispFormOLED(void);
FormOLED_T *FormOLED;
/*
*********************************************************************************************************
* : TestOLED
* : OLED显示模块
* :
* :
*********************************************************************************************************
*/
void TestOLED(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
FormOLED_T form;
uint8_t fRefreshTFT;
FONT_T tFont12, tFont16, tFont24, tFont32;
uint8_t fRefreshOled;
uint8_t ucItem;
uint8_t ucContrast = 0x80; /* 对比度 */
uint8_t ucDir = 0; /* 显示方向, 0 表示正常方向1表示倒180度 */
FormOLED = &form;
InitFormOLED();
DispFormOLED();
OLED_InitHard(); /* 初始化OLED硬件 */
OLED_ClrScr(0x00); /* 清屏0x00表示黑底 0xFF 表示白底 */
/* 设置字体参数 */
{
tFont16.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont16.FrontColor = 1; /* 字体颜色 0 或 1 */
tFont16.BackColor = 0; /* 文字背景颜色 0 或 1 */
tFont16.Space = 0; /* 文字间距,单位 = 像素 */
tFont12.FontCode = FC_ST_12; /* 字体代码 12点阵 */
tFont12.FrontColor = 1; /* 字体颜色 0 或 1 */
tFont12.BackColor = 0; /* 文字背景颜色 0 或 1 */
tFont12.Space = 1; /* 文字间距,单位 = 像素 */
tFont24.FontCode = FC_ST_24; /* 字体代码 24点阵 */
tFont24.FrontColor = 1; /* 字体颜色 0 或 1 */
tFont24.BackColor = 0; /* 文字背景颜色 0 或 1 */
tFont24.Space = 1; /* 文字间距,单位 = 像素 */
tFont32.FontCode = FC_ST_32; /* 字体代码 32点阵 */
tFont32.FrontColor = 1; /* 字体颜色 0 或 1 */
tFont32.BackColor = 0; /* 文字背景颜色 0 或 1 */
tFont32.Space = 1; /* 文字间距,单位 = 像素 */
}
ucItem = 0;
fRefreshOled = 1;
fRefreshTFT = 1;
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
if (fRefreshTFT)
{
char buf[32];
fRefreshTFT = 0;
sprintf(buf, "第%d页 对比度 = %3d", ucItem + 1, ucContrast);
FormOLED->Label8.pCaption = buf;
LCD_DrawLabel(&FormOLED->Label8);
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormOLED->BtnRet.Focus = 1;
LCD_DrawButton(&FormOLED->BtnRet);
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormOLED->BtnRet.Focus = 0;
LCD_DrawButton(&FormOLED->BtnRet);
fQuit = 1; /* 返回 */
}
else /* 按钮失去焦点 */
{
FormOLED->BtnRet.Focus = 0;
LCD_DrawButton(&FormOLED->BtnRet);
}
break;
}
}
if (fRefreshOled == 1)
{
fRefreshOled = 0;
switch (ucItem)
{
case 0:
OLED_ClrScr(0); /* 清屏,黑底 */
OLED_DrawRect(0, 0, 64, 128, 1);
OLED_DispStr(8, 3, "安富莱OLED例程", &tFont16); /* 在(8,3)坐标处显示一串汉字 */
OLED_DispStr(10, 22, "请操作摇杆!", &tFont16);
OLED_DispStr(5, 22 + 20, "www.ARMfly.com", &tFont16);
break;
case 1:
//OLED_StartDraw(); 调用改函数,只刷新缓冲区,不送显示
OLED_ClrScr(0);
OLED_DispStr(0, 0, "故人西辞黄鹤楼,", &tFont16);
OLED_DispStr(0, 16, "烟花三月下扬州。", &tFont16);
OLED_DispStr(0, 32, "孤帆远影碧空尽,", &tFont16);
OLED_DispStr(0, 48, "唯见长江天际流。", &tFont16);
//OLED_EndDraw(); 调用改函数,将缓冲区中数据送显示
break;
case 2:
OLED_ClrScr(0);
OLED_DispStr(5, 0, "《送孟浩然之广陵》", &tFont12);
OLED_DispStr(0, 13, "故人西辞黄鹤楼,", &tFont12);
OLED_DispStr(0, 26, "烟花三月下扬州。", &tFont12);
OLED_DispStr(0, 39, "孤帆远影碧空尽,", &tFont12);
OLED_DispStr(0, 52, "唯见长江天际流。", &tFont12);
OLED_DispStr(110, 14, "", &tFont16);
OLED_DispStr(110, 30, "", &tFont16);
OLED_DispStr(110, 46, "", &tFont16);
OLED_DrawRect(109, 13, 50, 17, 1);
break;
case 3:
OLED_ClrScr(0);
OLED_DispStr(5, 0, "安富莱123", &tFont24);
OLED_DispStr(0, 26, "开发板8", &tFont32);
break;
case 4:
OLED_ClrScr(0);
OLED_DrawRect(0, 0, 10, 10, 1); /* 在(0,0)坐标处绘制一个高10宽10的矩形 */
OLED_DrawRect(10, 10, 20, 30, 1); /* 在(10,10)坐标处绘制一个高20宽30的矩形 */
OLED_DrawCircle(64, 32, 30, 1); /* 在(64,32)绘制半径30的圆 */
OLED_DrawLine(127, 0, 0, 63, 1); /* 在(127,0) 和 (0,63) 之间绘制一条直线 */
break;
case 5:
OLED_ClrScr(0x00); /* 清屏,黑底 */
break;
case 6:
OLED_ClrScr(0xFF); /* 清屏,白底 */
{
//char buf[32];
//sprintf(buf, "%d", ucContrast);
//OLED_DispStr(10,10,buf,&tFont16);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键 */
break;
case KEY_DOWN_K2: /* K2键按下 */
break;
case KEY_DOWN_K3: /* K3键按下 */
break;
case JOY_DOWN_U: /* 摇杆上键按下 */
if (ucContrast < 255)
{
ucContrast++;
}
OLED_SetContrast(ucContrast);
fRefreshOled = 1;
fRefreshTFT = 1;
break;
case JOY_DOWN_D: /* 摇杆下键按下 */
if (ucContrast > 0)
{
ucContrast--;
}
OLED_SetContrast(ucContrast);
fRefreshOled = 1;
fRefreshTFT = 1;
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
if (ucItem > 0)
{
ucItem--;
}
else
{
ucItem = DEMO_PAGE_COUNT - 1;
}
fRefreshOled = 1;
fRefreshTFT = 1;
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
if (ucItem < DEMO_PAGE_COUNT - 1)
{
ucItem++;
}
else
{
ucItem = 0;
}
fRefreshOled = 1;
fRefreshTFT = 1;
break;
case JOY_DOWN_OK: /* 摇杆OK键 */
if (ucDir == 0)
{
ucDir = 1;
OLED_SetDir(1); /* 设置显示方向 */
}
else
{
ucDir = 0;
OLED_SetDir(0); /* 设置显示方向 */
}
fRefreshOled = 1;
break;
default:
break;
}
}
}
}
/*
*********************************************************************************************************
* : InitFormOLED
* :
*
* :
*********************************************************************************************************
*/
static void InitFormOLED(void)
{
/* 分组框标题字体 */
FormOLED->FontBox.FontCode = FC_ST_16;
FormOLED->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormOLED->FontBox.FrontColor = CL_BLACK;
FormOLED->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormOLED->FontBlack.FontCode = FC_ST_16;
FormOLED->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormOLED->FontBlack.FrontColor = CL_BLACK;
FormOLED->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormOLED->FontBlue.FontCode = FC_ST_16;
FormOLED->FontBlue.BackColor = CL_BTN_FACE;
FormOLED->FontBlue.FrontColor = CL_BLUE;
FormOLED->FontBlue.Space = 0;
/* 按钮字体 */
FormOLED->FontBtn.FontCode = FC_ST_16;
FormOLED->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormOLED->FontBtn.FrontColor = CL_BLACK;
FormOLED->FontBtn.Space = 0;
/* 分组框 */
FormOLED->Box1.Left = BOX1_X;
FormOLED->Box1.Top = BOX1_Y;
FormOLED->Box1.Height = BOX1_H;
FormOLED->Box1.Width = BOX1_W;
FormOLED->Box1.pCaption = BOX1_TEXT;
FormOLED->Box1.Font = &FormOLED->FontBox;
/* 静态标签 */
FormOLED->Label1.Left = LABEL1_X;
FormOLED->Label1.Top = LABEL1_Y;
FormOLED->Label1.MaxLen = 0;
FormOLED->Label1.pCaption = LABEL1_TEXT;
FormOLED->Label1.Font = &FormOLED->FontBlack;
FormOLED->Label3.Left = LABEL3_X;
FormOLED->Label3.Top = LABEL3_Y;
FormOLED->Label3.MaxLen = 0;
FormOLED->Label3.pCaption = LABEL3_TEXT;
FormOLED->Label3.Font = &FormOLED->FontBlack;
FormOLED->Label5.Left = LABEL5_X;
FormOLED->Label5.Top = LABEL5_Y;
FormOLED->Label5.MaxLen = 0;
FormOLED->Label5.pCaption = LABEL5_TEXT;
FormOLED->Label5.Font = &FormOLED->FontBlack;
FormOLED->Label7.Left = LABEL7_X;
FormOLED->Label7.Top = LABEL7_Y;
FormOLED->Label7.MaxLen = 0;
FormOLED->Label7.pCaption = LABEL7_TEXT;
FormOLED->Label7.Font = &FormOLED->FontBlack;
/* 动态标签 */
FormOLED->Label2.Left = LABEL2_X;
FormOLED->Label2.Top = LABEL2_Y;
FormOLED->Label2.MaxLen = 0;
FormOLED->Label2.pCaption = LABEL2_TEXT;
FormOLED->Label2.Font = &FormOLED->FontBlue;
FormOLED->Label4.Left = LABEL4_X;
FormOLED->Label4.Top = LABEL4_Y;
FormOLED->Label4.MaxLen = 0;
FormOLED->Label4.pCaption = LABEL4_TEXT;
FormOLED->Label4.Font = &FormOLED->FontBlue;
FormOLED->Label6.Left = LABEL6_X;
FormOLED->Label6.Top = LABEL6_Y;
FormOLED->Label6.MaxLen = 0;
FormOLED->Label6.pCaption = LABEL6_TEXT;
FormOLED->Label6.Font = &FormOLED->FontBlue;
FormOLED->Label8.Left = LABEL8_X;
FormOLED->Label8.Top = LABEL8_Y;
FormOLED->Label8.MaxLen = 0;
FormOLED->Label8.pCaption = LABEL8_TEXT;
FormOLED->Label8.Font = &FormOLED->FontBlue;
/* 按钮 */
FormOLED->BtnRet.Left = BTN_RET_X;
FormOLED->BtnRet.Top = BTN_RET_Y;
FormOLED->BtnRet.Height = BTN_RET_H;
FormOLED->BtnRet.Width = BTN_RET_W;
FormOLED->BtnRet.pCaption = BTN_RET_TEXT;
FormOLED->BtnRet.Font = &FormOLED->FontBtn;
FormOLED->BtnRet.Focus = 0;
}
/*
*********************************************************************************************************
* : DispRSVInitFace
* :
* :
* :
*********************************************************************************************************
*/
static void DispFormOLED(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormOLED->Box1);
/* 静态标签 */
LCD_DrawLabel(&FormOLED->Label1);
LCD_DrawLabel(&FormOLED->Label3);
LCD_DrawLabel(&FormOLED->Label5);
LCD_DrawLabel(&FormOLED->Label7);
/* 动态标签 */
LCD_DrawLabel(&FormOLED->Label2);
LCD_DrawLabel(&FormOLED->Label4);
LCD_DrawLabel(&FormOLED->Label6);
LCD_DrawLabel(&FormOLED->Label8);
/* 按钮 */
LCD_DrawButton(&FormOLED->BtnRet);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,323 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : reserve.c
* : V1.0
* : MPU-6050, HCM5833L, BMP085, BH1750
* :
*
* v1.0 2013-02-01 armfly
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_reserve.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
LABEL_T Label6;
LABEL_T Label7;
LABEL_T Label8;
BUTTON_T BtnRet;
} FormRSV_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "程序开发中..."
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define LABEL1_X (BOX1_X + 6)
#define LABEL1_Y (BOX1_Y + 20)
#define LABEL1_TEXT "xxxx : "
#define LABEL2_X (LABEL1_X + 64)
#define LABEL2_Y LABEL1_Y
#define LABEL2_TEXT "0000.0000"
#define LABEL3_X (LABEL1_X)
#define LABEL3_Y (LABEL1_Y + 20)
#define LABEL3_TEXT "xxxx : "
#define LABEL4_X (LABEL3_X + 64)
#define LABEL4_Y (LABEL3_Y)
#define LABEL4_TEXT "00000.0000"
#define LABEL5_X (LABEL1_X)
#define LABEL5_Y (LABEL1_Y + 20 * 2)
#define LABEL5_TEXT "xxxx : "
#define LABEL6_X (LABEL5_X + 64)
#define LABEL6_Y LABEL5_Y
#define LABEL6_TEXT "0.0"
#define LABEL7_X (LABEL1_X)
#define LABEL7_Y (LABEL1_Y + 20 * 3)
#define LABEL7_TEXT "xxxx : "
#define LABEL8_X (LABEL7_X + 64)
#define LABEL8_Y LABEL7_Y
#define LABEL8_TEXT "0.0"
static void InitFormRSV(void);
static void DispFormRSV(void);
FormRSV_T *FormRSV;
/*
*********************************************************************************************************
* : ReserveFunc
* :
*
* :
*********************************************************************************************************
*/
void ReserveFunc(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
FormRSV_T form;
FormRSV = &form;
InitFormRSV();
DispFormRSV();
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormRSV->BtnRet.Focus = 1;
LCD_DrawButton(&FormRSV->BtnRet);
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (TOUCH_InRect(tpX, tpY, BTN_RET_X, BTN_RET_Y, BTN_RET_H, BTN_RET_W))
{
FormRSV->BtnRet.Focus = 0;
LCD_DrawButton(&FormRSV->BtnRet);
fQuit = 1; /* 返回 */
}
else /* 按钮失去焦点 */
{
FormRSV->BtnRet.Focus = 0;
LCD_DrawButton(&FormRSV->BtnRet);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键 */
break;
case KEY_DOWN_K2: /* K2键按下 */
break;
case KEY_DOWN_K3: /* K3键按下 */
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
}
/*
*********************************************************************************************************
* : InitFormRSV
* :
*
* :
*********************************************************************************************************
*/
static void InitFormRSV(void)
{
/* 分组框标题字体 */
FormRSV->FontBox.FontCode = FC_ST_16;
FormRSV->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormRSV->FontBox.FrontColor = CL_BLACK;
FormRSV->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormRSV->FontBlack.FontCode = FC_ST_16;
FormRSV->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormRSV->FontBlack.FrontColor = CL_BLACK;
FormRSV->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormRSV->FontBlue.FontCode = FC_ST_16;
FormRSV->FontBlue.BackColor = CL_BTN_FACE;
FormRSV->FontBlue.FrontColor = CL_BLUE;
FormRSV->FontBlue.Space = 0;
/* 按钮字体 */
FormRSV->FontBtn.FontCode = FC_ST_16;
FormRSV->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormRSV->FontBtn.FrontColor = CL_BLACK;
FormRSV->FontBtn.Space = 0;
/* 分组框 */
FormRSV->Box1.Left = BOX1_X;
FormRSV->Box1.Top = BOX1_Y;
FormRSV->Box1.Height = BOX1_H;
FormRSV->Box1.Width = BOX1_W;
FormRSV->Box1.pCaption = BOX1_TEXT;
FormRSV->Box1.Font = &FormRSV->FontBox;
/* 静态标签 */
FormRSV->Label1.Left = LABEL1_X;
FormRSV->Label1.Top = LABEL1_Y;
FormRSV->Label1.MaxLen = 0;
FormRSV->Label1.pCaption = LABEL1_TEXT;
FormRSV->Label1.Font = &FormRSV->FontBlack;
FormRSV->Label3.Left = LABEL3_X;
FormRSV->Label3.Top = LABEL3_Y;
FormRSV->Label3.MaxLen = 0;
FormRSV->Label3.pCaption = LABEL3_TEXT;
FormRSV->Label3.Font = &FormRSV->FontBlack;
FormRSV->Label5.Left = LABEL5_X;
FormRSV->Label5.Top = LABEL5_Y;
FormRSV->Label5.MaxLen = 0;
FormRSV->Label5.pCaption = LABEL5_TEXT;
FormRSV->Label5.Font = &FormRSV->FontBlack;
FormRSV->Label7.Left = LABEL7_X;
FormRSV->Label7.Top = LABEL7_Y;
FormRSV->Label7.MaxLen = 0;
FormRSV->Label7.pCaption = LABEL7_TEXT;
FormRSV->Label7.Font = &FormRSV->FontBlack;
/* 动态标签 */
FormRSV->Label2.Left = LABEL2_X;
FormRSV->Label2.Top = LABEL2_Y;
FormRSV->Label2.MaxLen = 0;
FormRSV->Label2.pCaption = LABEL2_TEXT;
FormRSV->Label2.Font = &FormRSV->FontBlue;
FormRSV->Label4.Left = LABEL4_X;
FormRSV->Label4.Top = LABEL4_Y;
FormRSV->Label4.MaxLen = 0;
FormRSV->Label4.pCaption = LABEL4_TEXT;
FormRSV->Label4.Font = &FormRSV->FontBlue;
FormRSV->Label6.Left = LABEL6_X;
FormRSV->Label6.Top = LABEL6_Y;
FormRSV->Label6.MaxLen = 0;
FormRSV->Label6.pCaption = LABEL6_TEXT;
FormRSV->Label6.Font = &FormRSV->FontBlue;
FormRSV->Label8.Left = LABEL8_X;
FormRSV->Label8.Top = LABEL8_Y;
FormRSV->Label8.MaxLen = 0;
FormRSV->Label8.pCaption = LABEL8_TEXT;
FormRSV->Label8.Font = &FormRSV->FontBlue;
/* 按钮 */
FormRSV->BtnRet.Left = BTN_RET_X;
FormRSV->BtnRet.Top = BTN_RET_Y;
FormRSV->BtnRet.Height = BTN_RET_H;
FormRSV->BtnRet.Width = BTN_RET_W;
FormRSV->BtnRet.pCaption = BTN_RET_TEXT;
FormRSV->BtnRet.Font = &FormRSV->FontBtn;
FormRSV->BtnRet.Focus = 0;
}
/*
*********************************************************************************************************
* : DispFormRSV
* :
* :
* :
*********************************************************************************************************
*/
static void DispFormRSV(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormRSV->Box1);
/* 静态标签 */
LCD_DrawLabel(&FormRSV->Label1);
LCD_DrawLabel(&FormRSV->Label3);
LCD_DrawLabel(&FormRSV->Label5);
LCD_DrawLabel(&FormRSV->Label7);
/* 动态标签 */
LCD_DrawLabel(&FormRSV->Label2);
LCD_DrawLabel(&FormRSV->Label4);
LCD_DrawLabel(&FormRSV->Label6);
LCD_DrawLabel(&FormRSV->Label8);
/* 按钮 */
LCD_DrawButton(&FormRSV->BtnRet);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,752 +0,0 @@
/*
*********************************************************************************************************
*
* : RS485测试界面
* : form_rs485.c
* : V1.0
* : LED-485
* :
*
* v1.0 2014-10-15 armfly
*
* Copyright (C), 2013-2014, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_rs485.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
GROUP_T Box2;
GROUP_T Box3;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
LABEL_T Label6;
BUTTON_T BtnRet;
BUTTON_T Btn1;
BUTTON_T Btn2;
BUTTON_T Btn3;
BUTTON_T Btn4;
BUTTON_T Btn5;
BUTTON_T Btn6;
BUTTON_T BtnBright[8]; /* 设置亮度 */
LABEL_T LabelOldAddr;
LABEL_T LabelNewAddr;
EDIT_T EditOldAddr;
EDIT_T EditNewAddr;
BUTTON_T BtnSetAddr;
LABEL_T LblInfo1;
LABEL_T LblInfo2;
} FormRS485_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H 100
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "RS485 LED数码管"
/* 第1个框内的按钮 */
#define BTN1_H 32
#define BTN1_W 100
#define BTN1_X (BOX1_X + 10)
#define BTN1_Y (BOX1_Y + 20)
#define BTN1_TEXT "ASCII协议"
#define BTN2_H BTN1_H
#define BTN2_W BTN1_W
#define BTN2_X (BTN1_X + BTN1_W + 10)
#define BTN2_Y BTN1_Y
#define BTN2_TEXT "Modbus协议"
#define BTN3_H BTN1_H
#define BTN3_W BTN1_W
#define BTN3_X BTN1_X
#define BTN3_Y (BTN1_Y + BTN1_H + 10)
#define BTN3_TEXT "读设备型号"
#define BTN4_H BTN1_H
#define BTN4_W BTN1_W
#define BTN4_X (BTN1_X + BTN1_W + 10)
#define BTN4_Y (BTN1_Y + BTN1_H + 10)
#define BTN4_TEXT "读固件版本"
#define BTN5_H BTN1_H
#define BTN5_W BTN1_W
#define BTN5_X (BTN1_X + 2 * (BTN1_W + 10))
#define BTN5_Y (BTN1_Y + BTN1_H + 10)
#define BTN5_TEXT "测试应答"
#define BTN6_H BTN1_H
#define BTN6_W BTN1_W
#define BTN6_X (BTN1_X + 3 * (BTN1_W + 10))
#define BTN6_Y (BTN1_Y + BTN1_H + 10)
#define BTN6_TEXT "读亮度参数"
#define LABEL1_X (BTN5_X + 10)
#define LABEL1_Y BTN2_Y
#define LABEL1_TEXT "地址: "
#define LABEL2_X (LABEL1_X + 48)
#define LABEL2_Y LABEL1_Y
#define LABEL2_TEXT "0"
#define LABEL3_X (LABEL2_X + 32)
#define LABEL3_Y LABEL1_Y
#define LABEL3_TEXT "波特率: "
#define LABEL4_X (LABEL3_X + 64)
#define LABEL4_Y (LABEL3_Y)
#define LABEL4_TEXT "0"
#define LABEL5_X (LABEL1_X)
#define LABEL5_Y (LABEL1_Y + 20)
#define LABEL5_TEXT "接收:"
#define LABEL6_X (LABEL5_X + 48)
#define LABEL6_Y LABEL5_Y
#define LABEL6_TEXT " "
/* 第2个框 */
#define BOX2_X BOX1_X
#define BOX2_Y (BOX1_Y + BOX1_H + 10)
#define BOX2_H 60
#define BOX2_W (g_LcdWidth - 2 * BOX1_X)
#define BOX2_TEXT "设置亮度"
#define BTNB_H 32
#define BTNB_W 45
#define BTNB_X (BOX2_X + 10)
#define BTNB_Y (BOX2_Y + 20)
/* 第3个框 */
#define BOX3_X BOX1_X
#define BOX3_Y (BOX2_Y + BOX2_H + 10)
#define BOX3_H 72
#define BOX3_W (g_LcdWidth - 2 * BOX1_X)
#define BOX3_TEXT "修改485地址"
#define LABEL_OLDADDR_X (BOX3_X + 10)
#define LABEL_OLDADDR_Y (BOX3_Y + 20)
#define LABEL_OLDADDR_TEXT "当前地址:"
#define EDIT_OLDADDR_X (LABEL_OLDADDR_X + 80)
#define EDIT_OLDADDR_Y LABEL_OLDADDR_Y
#define EDIT_OLDADDR_H 20
#define EDIT_OLDADDR_W 50
#define LABEL_NEWADDR_X LABEL_OLDADDR_X
#define LABEL_NEWADDR_Y (LABEL_OLDADDR_Y + 30)
#define LABEL_NEWADDR_TEXT " 新地址:"
#define EDIT_NEWADDR_X EDIT_OLDADDR_X
#define EDIT_NEWADDR_Y LABEL_NEWADDR_Y
#define EDIT_NEWDDR_H EDIT_OLDADDR_H
#define EDIT_NEWADDR_W EDIT_OLDADDR_W
#define BTN_SETADDR_H 50
#define BTN_SETADDR_W 100
#define BTN_SETADDR_X (EDIT_NEWADDR_X + EDIT_NEWADDR_W + 10)
#define BTN_SETADDR_Y EDIT_OLDADDR_Y
#define BTN_SETADDR_TEXT "修改485地址"
#define LBL_INFO1_X (BOX3_X + 270)
#define LBL_INFO1_Y (BOX3_Y + 11)
#define LBL_INFO1_TEXT "摇杆上下键: 修改新地址"
#define LBL_INFO2_X LBL_INFO1_X
#define LBL_INFO2_Y (LBL_INFO1_Y + 20)
#define LBL_INFO2_TEXT "摇杆左右键: 修改当前地址"
/* 按钮 */
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 80
#define BTN_RET_X (g_LcdWidth - BTN_RET_W - 8)
#define BTN_RET_Y (g_LcdHeight - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
static void InitFormRS485(void);
static void DispFormRS485(void);
static void DispLabelAddr(uint8_t _addr1, uint8_t _addr2);
static void DispLabelBaud(uint32_t _Baud);
static void DispLabelRx(uint8_t *_buf, uint8_t _len);
FormRS485_T *FormRS485;
/*
*********************************************************************************************************
* : FormMainRS485
* : RS485测试主程序
* :
* :
*********************************************************************************************************
*/
void FormMainRS485(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
FormRS485_T form;
uint8_t OldAddr;
uint8_t NewAddr;
uint32_t baud;
uint32_t i;
uint32_t count = 0;
uint8_t fUpdateCount = 1;
uint8_t fUpdateAddr = 1;
uint8_t fLed888 = 0;
FormRS485 = &form;
InitFormRS485();
DispFormRS485();
OldAddr = 1;
NewAddr = 1;
baud = 9600;
DispLabelBaud(baud);
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
MODH_Poll();
if (fUpdateAddr == 1)
{
fUpdateAddr = 0;
DispLabelAddr(OldAddr, NewAddr);
}
if (fUpdateCount == 1)
{
fUpdateCount = 0;
LED485_DispNumberA(OldAddr, count); /* 命令LED数码管显示计数值 */
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
if (LCD_ButtonTouchDown(&FormRS485->BtnRet, tpX, tpY))
{
//fQuit = 1;
}
else if (LCD_ButtonTouchDown(&FormRS485->Btn1, tpX, tpY))
{
LED485_SetProtAscii(OldAddr); /* 设置为ASCII协议 */
}
else if (LCD_ButtonTouchDown(&FormRS485->Btn2, tpX, tpY))
{
LED485_SetProtRTU(OldAddr); /* 设置为Modbus RTU 协议 */
}
else if (LCD_ButtonTouchDown(&FormRS485->Btn3, tpX, tpY))
{
LED485_ReadModel(OldAddr); /* 读设备型号 */
}
else if (LCD_ButtonTouchDown(&FormRS485->Btn4, tpX, tpY))
{
LED485_ReadVersion(OldAddr); /* 读固件版本 */
}
else if (LCD_ButtonTouchDown(&FormRS485->Btn5, tpX, tpY))
{
LED485_TestOk(OldAddr); /* 测试OK应答 */
}
else if (LCD_ButtonTouchDown(&FormRS485->Btn6, tpX, tpY))
{
LED485_ReadBright(OldAddr); /* 读亮度参数 */
}
else if (LCD_ButtonTouchDown(&FormRS485->BtnSetAddr, tpX, tpY))
{
/* 修改地址 */
LED485_ModifyAddrA(OldAddr, NewAddr);
}
else
{
for (i = 0; i < 8; i++)
{
if (LCD_ButtonTouchDown(&FormRS485->BtnBright[i], tpX, tpY))
{
LED485_SetBrightA(OldAddr, i); /* 设置亮度参数(ASCII协议) */
}
}
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (LCD_ButtonTouchRelease(&FormRS485->BtnRet, tpX, tpY))
{
fQuit = 1; /* 返回 */
}
else
{
LCD_ButtonTouchRelease(&FormRS485->BtnRet, tpX, tpY);
LCD_ButtonTouchRelease(&FormRS485->Btn1, tpX, tpY);
LCD_ButtonTouchRelease(&FormRS485->Btn2, tpX, tpY);
LCD_ButtonTouchRelease(&FormRS485->Btn3, tpX, tpY);
LCD_ButtonTouchRelease(&FormRS485->Btn4, tpX, tpY);
LCD_ButtonTouchRelease(&FormRS485->Btn5, tpX, tpY);
LCD_ButtonTouchRelease(&FormRS485->Btn6, tpX, tpY);
LCD_ButtonTouchRelease(&FormRS485->BtnSetAddr, tpX, tpY);
for (i = 0; i < 8; i++)
{
LCD_ButtonTouchRelease(&FormRS485->BtnBright[i], tpX, tpY);
}
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case MSG_485_RX_NOT_RTU: /* 接收到485设备的应答 */
DispLabelRx(g_tModH.AppRxBuf, g_tModH.AppRxCount);
break;
case KEY_DOWN_K1: /* K1键 + 1*/
count++;
fUpdateCount = 1;
break;
case KEY_DOWN_K2: /* K2键 - 1 */
if (count > 0)
{
count--;
}
fUpdateCount = 1;
break;
case KEY_DOWN_K3: /* K3键 - 清0 */
count = 0;
fUpdateCount = 1;
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
NewAddr++;
fUpdateAddr = 1;
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
NewAddr--;
fUpdateAddr = 1;
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
OldAddr++;
fUpdateAddr = 1;
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
OldAddr--;
fUpdateAddr = 1;
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
/* 自动测试 */
if (fLed888 == 0)
{
fLed888 = 1;
LED485_DispStrA(OldAddr, "8.8.8.");
}
else if (fLed888 == 1)
{
fLed888 = 2;
LED485_DispStrA(OldAddr, "8.8.8.8");
}
else
{
fLed888 = 0;
LED485_DispStrA(OldAddr, " ");
}
break;
default:
break;
}
}
}
}
/*
*********************************************************************************************************
* : InitFormRS485
* :
*
* :
*********************************************************************************************************
*/
static void InitFormRS485(void)
{
/* 分组框标题字体 */
FormRS485->FontBox.FontCode = FC_ST_16;
FormRS485->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormRS485->FontBox.FrontColor = CL_BLACK;
FormRS485->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormRS485->FontBlack.FontCode = FC_ST_16;
FormRS485->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormRS485->FontBlack.FrontColor = CL_BLACK;
FormRS485->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormRS485->FontBlue.FontCode = FC_ST_16;
FormRS485->FontBlue.BackColor = CL_BTN_FACE;
FormRS485->FontBlue.FrontColor = CL_BLUE;
FormRS485->FontBlue.Space = 0;
/* 按钮字体 */
FormRS485->FontBtn.FontCode = FC_ST_16;
FormRS485->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormRS485->FontBtn.FrontColor = CL_BLACK;
FormRS485->FontBtn.Space = 0;
/* 分组框 */
FormRS485->Box1.Left = BOX1_X;
FormRS485->Box1.Top = BOX1_Y;
FormRS485->Box1.Height = BOX1_H;
FormRS485->Box1.Width = BOX1_W;
FormRS485->Box1.pCaption = BOX1_TEXT;
FormRS485->Box1.Font = &FormRS485->FontBox;
FormRS485->Box2.Left = BOX2_X;
FormRS485->Box2.Top = BOX2_Y;
FormRS485->Box2.Height = BOX2_H;
FormRS485->Box2.Width = BOX2_W;
FormRS485->Box2.pCaption = BOX2_TEXT;
FormRS485->Box2.Font = &FormRS485->FontBox;
/* 静态标签 */
FormRS485->Label1.Left = LABEL1_X;
FormRS485->Label1.Top = LABEL1_Y;
FormRS485->Label1.MaxLen = 0;
FormRS485->Label1.pCaption = LABEL1_TEXT;
FormRS485->Label1.Font = &FormRS485->FontBlack;
FormRS485->Label3.Left = LABEL3_X;
FormRS485->Label3.Top = LABEL3_Y;
FormRS485->Label3.MaxLen = 0;
FormRS485->Label3.pCaption = LABEL3_TEXT;
FormRS485->Label3.Font = &FormRS485->FontBlack;
FormRS485->Label5.Left = LABEL5_X;
FormRS485->Label5.Top = LABEL5_Y;
FormRS485->Label5.MaxLen = 0;
FormRS485->Label5.pCaption = LABEL5_TEXT;
FormRS485->Label5.Font = &FormRS485->FontBlack;
/* 动态标签 */
FormRS485->Label2.Left = LABEL2_X;
FormRS485->Label2.Top = LABEL2_Y;
FormRS485->Label2.MaxLen = 0;
FormRS485->Label2.pCaption = LABEL2_TEXT;
FormRS485->Label2.Font = &FormRS485->FontBlue;
FormRS485->Label4.Left = LABEL4_X;
FormRS485->Label4.Top = LABEL4_Y;
FormRS485->Label4.MaxLen = 0;
FormRS485->Label4.pCaption = LABEL4_TEXT;
FormRS485->Label4.Font = &FormRS485->FontBlue;
FormRS485->Label6.Left = LABEL6_X;
FormRS485->Label6.Top = LABEL6_Y;
FormRS485->Label6.MaxLen = 0;
FormRS485->Label6.pCaption = LABEL6_TEXT;
FormRS485->Label6.Font = &FormRS485->FontBlue;
/* 按钮 */
FormRS485->BtnRet.Left = BTN_RET_X;
FormRS485->BtnRet.Top = BTN_RET_Y;
FormRS485->BtnRet.Height = BTN_RET_H;
FormRS485->BtnRet.Width = BTN_RET_W;
FormRS485->BtnRet.pCaption = BTN_RET_TEXT;
FormRS485->BtnRet.Font = &FormRS485->FontBtn;
FormRS485->BtnRet.Focus = 0;
FormRS485->Btn1.Left = BTN1_X;
FormRS485->Btn1.Top = BTN1_Y;
FormRS485->Btn1.Height = BTN1_H;
FormRS485->Btn1.Width = BTN1_W;
FormRS485->Btn1.pCaption = BTN1_TEXT;
FormRS485->Btn1.Font = &FormRS485->FontBtn;
FormRS485->Btn1.Focus = 0;
FormRS485->Btn2.Left = BTN2_X;
FormRS485->Btn2.Top = BTN2_Y;
FormRS485->Btn2.Height = BTN2_H;
FormRS485->Btn2.Width = BTN2_W;
FormRS485->Btn2.pCaption = BTN2_TEXT;
FormRS485->Btn2.Font = &FormRS485->FontBtn;
FormRS485->Btn2.Focus = 0;
FormRS485->Btn3.Left = BTN3_X;
FormRS485->Btn3.Top = BTN3_Y;
FormRS485->Btn3.Height = BTN3_H;
FormRS485->Btn3.Width = BTN3_W;
FormRS485->Btn3.pCaption = BTN3_TEXT;
FormRS485->Btn3.Font = &FormRS485->FontBtn;
FormRS485->Btn3.Focus = 0;
FormRS485->Btn4.Left = BTN4_X;
FormRS485->Btn4.Top = BTN4_Y;
FormRS485->Btn4.Height = BTN4_H;
FormRS485->Btn4.Width = BTN4_W;
FormRS485->Btn4.pCaption = BTN4_TEXT;
FormRS485->Btn4.Font = &FormRS485->FontBtn;
FormRS485->Btn4.Focus = 0;
FormRS485->Btn5.Left = BTN5_X;
FormRS485->Btn5.Top = BTN5_Y;
FormRS485->Btn5.Height = BTN5_H;
FormRS485->Btn5.Width = BTN5_W;
FormRS485->Btn5.pCaption = BTN5_TEXT;
FormRS485->Btn5.Font = &FormRS485->FontBtn;
FormRS485->Btn5.Focus = 0;
FormRS485->Btn6.Left = BTN6_X;
FormRS485->Btn6.Top = BTN6_Y;
FormRS485->Btn6.Height = BTN6_H;
FormRS485->Btn6.Width = BTN6_W;
FormRS485->Btn6.pCaption = BTN6_TEXT;
FormRS485->Btn6.Font = &FormRS485->FontBtn;
FormRS485->Btn6.Focus = 0;
{
uint8_t i;
char *BrightStr[8] = {
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
};
for (i = 0; i < 8; i++)
{
FormRS485->BtnBright[i].Left = BTNB_X + (BTNB_W + 10) * i;
FormRS485->BtnBright[i].Top = BTNB_Y;
FormRS485->BtnBright[i].Height = BTNB_H;
FormRS485->BtnBright[i].Width = BTNB_W;
FormRS485->BtnBright[i].pCaption = BrightStr[i];
FormRS485->BtnBright[i].Font = &FormRS485->FontBtn;
FormRS485->BtnBright[i].Focus = 0;
}
}
{
FormRS485->Box3.Left = BOX3_X;
FormRS485->Box3.Top = BOX3_Y;
FormRS485->Box3.Height = BOX3_H;
FormRS485->Box3.Width = BOX3_W;
FormRS485->Box3.pCaption = BOX3_TEXT;
FormRS485->Box3.Font = &FormRS485->FontBox;
FormRS485->LabelOldAddr.Left = LABEL_OLDADDR_X;
FormRS485->LabelOldAddr.Top = LABEL_OLDADDR_Y;
FormRS485->LabelOldAddr.MaxLen = 0;
FormRS485->LabelOldAddr.pCaption = LABEL_OLDADDR_TEXT;
FormRS485->LabelOldAddr.Font = &FormRS485->FontBlack;
FormRS485->LabelNewAddr.Left = LABEL_NEWADDR_X;
FormRS485->LabelNewAddr.Top = LABEL_NEWADDR_Y;
FormRS485->LabelNewAddr.MaxLen = 0;
FormRS485->LabelNewAddr.pCaption = LABEL_NEWADDR_TEXT;
FormRS485->LabelNewAddr.Font = &FormRS485->FontBlack;
FormRS485->EditOldAddr.Left = EDIT_OLDADDR_X;
FormRS485->EditOldAddr.Top = EDIT_OLDADDR_Y;
FormRS485->EditOldAddr.Height = EDIT_OLDADDR_H;
FormRS485->EditOldAddr.Width = EDIT_OLDADDR_W;
FormRS485->EditOldAddr.pCaption = FormRS485->EditOldAddr.Text;
FormRS485->EditOldAddr.Font = &FormRS485->FontBtn;
FormRS485->EditNewAddr.Left = EDIT_NEWADDR_X;
FormRS485->EditNewAddr.Top = EDIT_NEWADDR_Y;
FormRS485->EditNewAddr.Height = EDIT_NEWDDR_H;
FormRS485->EditNewAddr.Width = EDIT_NEWADDR_W;
FormRS485->EditNewAddr.pCaption = FormRS485->EditNewAddr.Text;
FormRS485->EditNewAddr.Font = &FormRS485->FontBtn;
FormRS485->BtnSetAddr.Left = BTN_SETADDR_X;
FormRS485->BtnSetAddr.Top = BTN_SETADDR_Y;
FormRS485->BtnSetAddr.Height = BTN_SETADDR_H;
FormRS485->BtnSetAddr.Width = BTN_SETADDR_W;
FormRS485->BtnSetAddr.pCaption = BTN_SETADDR_TEXT;
FormRS485->BtnSetAddr.Font = &FormRS485->FontBtn;
FormRS485->BtnSetAddr.Focus = 0;
FormRS485->EditOldAddr.Text[0] = 0;
FormRS485->EditNewAddr.Text[0] = 0;
FormRS485->LblInfo1.Left = LBL_INFO1_X;
FormRS485->LblInfo1.Top = LBL_INFO1_Y;
FormRS485->LblInfo1.MaxLen = 0;
FormRS485->LblInfo1.pCaption = LBL_INFO1_TEXT;
FormRS485->LblInfo1.Font = &FormRS485->FontBlack;
FormRS485->LblInfo2.Left = LBL_INFO2_X;
FormRS485->LblInfo2.Top = LBL_INFO2_Y;
FormRS485->LblInfo2.MaxLen = 0;
FormRS485->LblInfo2.pCaption = LBL_INFO2_TEXT;
FormRS485->LblInfo2.Font = &FormRS485->FontBlack;
}
}
/*
*********************************************************************************************************
* : DispFormRS485
* :
* :
* :
*********************************************************************************************************
*/
static void DispFormRS485(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormRS485->Box1);
LCD_DrawGroupBox(&FormRS485->Box2);
LCD_DrawLabel(&FormRS485->Label1);
LCD_DrawLabel(&FormRS485->Label3);
LCD_DrawLabel(&FormRS485->Label5);
LCD_DrawLabel(&FormRS485->Label2);
LCD_DrawLabel(&FormRS485->Label4);
LCD_DrawLabel(&FormRS485->Label6);
/* 按钮 */
LCD_DrawButton(&FormRS485->Btn1);
LCD_DrawButton(&FormRS485->Btn2);
LCD_DrawButton(&FormRS485->Btn3);
LCD_DrawButton(&FormRS485->Btn4);
LCD_DrawButton(&FormRS485->Btn5);
LCD_DrawButton(&FormRS485->Btn6);
{
uint8_t i;
for (i = 0; i < 8; i++)
{
LCD_DrawButton(&FormRS485->BtnBright[i]);
}
}
LCD_DrawGroupBox(&FormRS485->Box3);
LCD_DrawLabel(&FormRS485->LabelOldAddr);
LCD_DrawLabel(&FormRS485->LabelNewAddr);
LCD_DrawEdit(&FormRS485->EditOldAddr);
LCD_DrawEdit(&FormRS485->EditNewAddr);
LCD_DrawButton(&FormRS485->BtnSetAddr);
LCD_DrawLabel(&FormRS485->LblInfo1);
LCD_DrawLabel(&FormRS485->LblInfo2);
LCD_DrawButton(&FormRS485->BtnRet);
}
/*
*********************************************************************************************************
* : DispLabelAddr
* : 485
* :
* :
*********************************************************************************************************
*/
static void DispLabelAddr(uint8_t _addr1, uint8_t _addr2)
{
char buf[10];
sprintf(buf, "%d", _addr1);
/* 动态标签 */
FormRS485->Label2.pCaption = buf;
LCD_DrawLabel(&FormRS485->Label2);
sprintf(FormRS485->EditOldAddr.Text, "%d", _addr1);
LCD_DrawEdit(&FormRS485->EditOldAddr);
sprintf(FormRS485->EditNewAddr.Text, "%d", _addr2);
LCD_DrawEdit(&FormRS485->EditNewAddr);
}
/*
*********************************************************************************************************
* : DispLabelTx
* :
* : _Baud
* _
* :
*********************************************************************************************************
*/
static void DispLabelBaud(uint32_t _Baud)
{
char buf[10];
sprintf(buf, "%d", _Baud);
/* 动态标签 */
FormRS485->Label4.pCaption = buf;
LCD_DrawLabel(&FormRS485->Label4);
}
/*
*********************************************************************************************************
* : DispLabelRx
* :
* : _buf
* _
* :
*********************************************************************************************************
*/
static void DispLabelRx(uint8_t *_buf, uint8_t _len)
{
char buf[16];
_buf[_len] = 0;
sprintf(buf, "%d | %s", _len, _buf);
/* 动态标签 */
FormRS485->Label6.pCaption = buf;
LCD_DrawLabel(&FormRS485->Label6);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

File diff suppressed because it is too large Load Diff

View File

@ -1,577 +0,0 @@
/*
*********************************************************************************************************
*
* : SD卡和NAND Flash模拟U盘程序
* : usbd_msc_test.c
* : V1.1
* : 使USB Device接口PC上虚拟出2个U盘设备:SD卡 NAND Flash
* :
*
* v1.0 2013-02-01 armfly
* V1.1 2015-10-13 armfly K3键启动NAND坏块重新标记, USBPC和STM32同时访问NAND
*
* Copyright (C), 2015-2020, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "usbd_usr.h" /* usb底层驱动 */
#include "form_usbd_msc.h"
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 蓝色 */
FONT_T FontRed; /* 变化的文字字体 红色 */
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T Label1;
LABEL_T Label2; /* SD卡状态 */
LABEL_T Label3;
LABEL_T Label4; /* NAND状态 */
LABEL_T Label5;
LABEL_T Label6; /* USBD状态 */
BUTTON_T Btn1;
BUTTON_T Btn2;
BUTTON_T Btn3;
BUTTON_T Btn4;
BUTTON_T BtnRet;
} FormUSB_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 4个框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "SD卡和NAND Flash模拟U盘"
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define BTN1_H 32
#define BTN1_W 100
#define BTN1_X (BOX1_X + 5)
#define BTN1_Y (BOX1_Y + 100)
#define BTN1_TEXT "打开模拟U盘"
#define BTN2_H 32
#define BTN2_W 100
#define BTN2_X (BTN1_X + BTN1_W + 10)
#define BTN2_Y BTN1_Y
#define BTN2_TEXT "关闭模拟U盘"
#define BTN3_H 32
#define BTN3_W 100
#define BTN3_X BTN1_X
#define BTN3_Y (BTN1_Y + BTN1_H + 10)
#define BTN3_TEXT "低格NAND"
#define BTN4_H 32
#define BTN4_W 100
#define BTN4_X (BTN1_X + BTN1_W + 10)
#define BTN4_Y (BTN1_Y + BTN1_H + 10)
#define BTN4_TEXT "扫描坏块"
/* 标签 */
#define LABEL1_X (BOX1_X + 6)
#define LABEL1_Y (BOX1_Y + 20)
#define LABEL1_TEXT "SD卡状态 : "
#define LABEL2_X (LABEL1_X + 100)
#define LABEL2_Y LABEL1_Y
#define LABEL2_TEXT "--"
#define LABEL3_X (LABEL1_X)
#define LABEL3_Y (LABEL1_Y + 20)
#define LABEL3_TEXT "NAND状态 : "
#define LABEL4_X (LABEL3_X + 100)
#define LABEL4_Y (LABEL3_Y)
#define LABEL4_TEXT "--"
#define LABEL5_X (LABEL1_X)
#define LABEL5_Y (LABEL1_Y + 20 * 2)
#define LABEL5_TEXT "USBD状态 : "
#define LABEL6_X (LABEL5_X + 100)
#define LABEL6_Y (LABEL5_Y)
#define LABEL6_TEXT "--"
static void InitFormUSB(void);
static void DispUSBInitFace(void);
FormUSB_T *FormUSB;
/*
*********************************************************************************************************
* : TestUsbdMsc
* : U盘程序入口
*
* :
*********************************************************************************************************
*/
void TestUsbdMsc(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
uint8_t ucNandOk;
uint8_t ucCardOk;
uint8_t ucUsbOk;
FormUSB_T form;
uint8_t fRefresh;
char buf[64];
FormUSB = &form;
InitFormUSB();
DispUSBInitFace();
{
#if 1
NAND_DispBadBlockInfo(); /* 向串口1打印NAND Flash坏块信息 (此函数开头初始FSMC) */
/* 配置FSMC用于NAND Flash 复位NAND Flash重建LUT表 */
if (NAND_Init() == NAND_OK)
{
printf("NAND_Init() Ok\r\n");
ucNandOk = 1;
}
else
{
/* 建议在正式的产品中采用人为干预的方式启动低级格式化 */
/* 自动检测nand flash是否进行了低级格式化如果没有则执行格式化2秒 */
printf("NAND_Init() Error! \r\n");
printf("Start Format(Low Level) NAND Flash......\r\n");
if (NAND_Format() == NAND_OK)
{
printf("NAND Flash Format Ok\r\n");
}
else
{
printf("NAND Flash Format Error\r\n");
}
ucNandOk = 1;
}
if (NAND_GetBlockInfo(&nand) == 1)
{
ucNandOk = 1;
#if 0
NAND_DispParamPage(); /* 显示NAND 芯片版本信息 */
#endif
}
else
{
ucNandOk = 0;
}
#endif
if (BSP_SD_Init() == MSD_OK)
{
ucCardOk = 1;
}
else
{
ucCardOk = 0;
}
}
ucUsbOk = 1;
usbd_OpenMassStorage(); /* 初始化USB Device配置为Mass Storage */
fRefresh = 1;
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
if (fRefresh)
{
fRefresh = 0;
if (ucCardOk)
{
FormUSB->Label2.Font = &FormUSB->FontBlue;
FormUSB->Label2.pCaption = "Ok ";
}
else
{
FormUSB->Label2.Font = &FormUSB->FontRed;
FormUSB->Label2.pCaption = "Err";
}
LCD_DrawLabel(&FormUSB->Label2);
if (ucNandOk)
{
FormUSB->Label4.pCaption = buf;
sprintf(buf, "OK, %s, Bad=%d, Used=%d, Free=%d", nand.ChipName, nand.Bad, nand.Used, nand.Free);
if (nand.Bad > 30)
{
/* 如果坏块个数大于30个则显示红色 */
FormUSB->Label4.Font = &FormUSB->FontRed;
}
else
{
/* 坏块数量在正常范围内,显示蓝色 */
FormUSB->Label4.Font = &FormUSB->FontBlue;
}
}
else
{
FormUSB->Label4.Font = &FormUSB->FontRed;
FormUSB->Label4.pCaption = "Err";
}
LCD_DrawLabel(&FormUSB->Label4);
if (ucUsbOk)
{
FormUSB->Label6.Font = &FormUSB->FontBlue;
FormUSB->Label6.pCaption = "已打开 ";
}
else
{
FormUSB->Label6.Font = &FormUSB->FontRed;
FormUSB->Label6.pCaption = "已关闭";
}
LCD_DrawLabel(&FormUSB->Label6);
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
LCD_ButtonTouchDown(&FormUSB->BtnRet, tpX, tpY);
LCD_ButtonTouchDown(&FormUSB->Btn1, tpX, tpY);
LCD_ButtonTouchDown(&FormUSB->Btn2, tpX, tpY);
LCD_ButtonTouchDown(&FormUSB->Btn3, tpX, tpY);
LCD_ButtonTouchDown(&FormUSB->Btn4, tpX, tpY);
break;
case TOUCH_MOVE: /* 触笔移动事件 */
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (LCD_ButtonTouchRelease(&FormUSB->BtnRet, tpX, tpY))
{
FormUSB->BtnRet.Focus = 0;
LCD_DrawButton(&FormUSB->BtnRet);
fQuit = 1; /* 返回 */
}
else if (LCD_ButtonTouchRelease(&FormUSB->Btn1, tpX, tpY))
{
FormUSB->Btn1.Focus = 0;
LCD_DrawButton(&FormUSB->Btn1);
if (BSP_SD_Init() == MSD_OK)
{
ucCardOk = 1;
}
else
{
ucCardOk = 0;
}
usbd_OpenMassStorage(); /* 打开U盘 */
ucUsbOk = 1;
fRefresh = 1;
}
else if (LCD_ButtonTouchRelease(&FormUSB->Btn2, tpX, tpY))
{
usbd_CloseMassStorage(); /* 关闭U盘 */
ucUsbOk = 0;
fRefresh = 1;
}
else if (LCD_ButtonTouchRelease(&FormUSB->Btn3, tpX, tpY))
{
if (NAND_Format() == NAND_OK)
{
FormUSB->Label4.pCaption = "低级格式化成功";
}
else
{
FormUSB->Label4.pCaption = "低级格式化失败";
}
LCD_DrawLabel(&FormUSB->Label4);
}
else if (LCD_ButtonTouchRelease(&FormUSB->Btn4, tpX, tpY))
{
if (ucUsbOk == 0) /* 关闭USB连接时才能访问NAND否则USB中断程序会干扰扫描过程 */
{
/* 重新扫描测试坏块,执行时间很长。 用于NAND 磁盘修复 */
uint32_t i;
FormUSB->Label4.pCaption = buf;
FormUSB->Label4.Font = &FormUSB->FontRed;
for (i = 0; i < NAND_BLOCK_COUNT; i++)
{
sprintf(buf, "扫描坏块... %d (%d%%) --- K1键终止", i, (i + 1) * 100 / NAND_BLOCK_COUNT);
LCD_DrawLabel(&FormUSB->Label4);
if (NAND_ScanBlock(i) == NAND_OK)
{
;
}
else
{
NAND_MarkBadBlock(i); /* 标记坏块 */
}
/* 如果有任意键按下,则退出 */
if (bsp_GetKey() == KEY_DOWN_K1)
{
sprintf(buf, "扫描终止");
LCD_DrawLabel(&FormUSB->Label4);
break;
}
}
}
else
{
FormUSB->Label4.Font = &FormUSB->FontRed;
FormUSB->Label4.pCaption = buf;
sprintf(buf, "请先关闭模拟U盘功能");
LCD_DrawLabel(&FormUSB->Label4);
}
}
else /* 按钮失去焦点 */
{
LCD_ButtonTouchRelease(&FormUSB->BtnRet, tpX, tpY);
LCD_ButtonTouchRelease(&FormUSB->Btn1, tpX, tpY);
LCD_ButtonTouchRelease(&FormUSB->Btn2, tpX, tpY);
LCD_ButtonTouchRelease(&FormUSB->Btn3, tpX, tpY);
LCD_ButtonTouchRelease(&FormUSB->Btn4, tpX, tpY);
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键 */
//printf("【1 - 移除U盘】\r\n");
//usbd_CloseMassStorage();
break;
case KEY_DOWN_K2: /* K2键按下 */
/* 使能U盘软件模拟U盘插入 */
//printf("【2 - 使能U盘】\r\n");
//usbd_OpenMassStorage();
break;
case KEY_DOWN_K3: /* K3键按下 */
;
break;
case JOY_DOWN_U: /* 摇杆UP键按下 */
break;
case JOY_DOWN_D: /* 摇杆DOWN键按下 */
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 */
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 */
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
break;
default:
break;
}
}
}
usbd_CloseMassStorage(); /* 移除U盘 */
}
/*
*********************************************************************************************************
* : InitFormUSB
* : GPS初始界面控件
*
* :
*********************************************************************************************************
*/
static void InitFormUSB(void)
{
/* 分组框标题字体 */
FormUSB->FontBox.FontCode = FC_ST_16;
FormUSB->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormUSB->FontBox.FrontColor = CL_BLACK;
FormUSB->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormUSB->FontBlack.FontCode = FC_ST_16;
FormUSB->FontBlack.BackColor = CL_MASK; /* 透明色 */
FormUSB->FontBlack.FrontColor = CL_BLACK;
FormUSB->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormUSB->FontBlue.FontCode = FC_ST_16;
FormUSB->FontBlue.BackColor = CL_BTN_FACE;
FormUSB->FontBlue.FrontColor = CL_BLUE;
FormUSB->FontBlue.Space = 0;
/* 字体3 用于变化的文字 */
FormUSB->FontRed.FontCode = FC_ST_16;
FormUSB->FontRed.BackColor = CL_BTN_FACE;
FormUSB->FontRed.FrontColor = CL_RED;
FormUSB->FontRed.Space = 0;
/* 按钮字体 */
FormUSB->FontBtn.FontCode = FC_ST_16;
FormUSB->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormUSB->FontBtn.FrontColor = CL_BLACK;
FormUSB->FontBtn.Space = 0;
/* 分组框 */
FormUSB->Box1.Left = BOX1_X;
FormUSB->Box1.Top = BOX1_Y;
FormUSB->Box1.Height = BOX1_H;
FormUSB->Box1.Width = BOX1_W;
FormUSB->Box1.pCaption = BOX1_TEXT;
FormUSB->Box1.Font = &FormUSB->FontBox;
/* 静态标签 */
FormUSB->Label1.Left = LABEL1_X;
FormUSB->Label1.Top = LABEL1_Y;
FormUSB->Label1.MaxLen = 0;
FormUSB->Label1.pCaption = LABEL1_TEXT;
FormUSB->Label1.Font = &FormUSB->FontBlack;
FormUSB->Label3.Left = LABEL3_X;
FormUSB->Label3.Top = LABEL3_Y;
FormUSB->Label3.MaxLen = 0;
FormUSB->Label3.pCaption = LABEL3_TEXT;
FormUSB->Label3.Font = &FormUSB->FontBlack;
FormUSB->Label5.Left = LABEL5_X;
FormUSB->Label5.Top = LABEL5_Y;
FormUSB->Label5.MaxLen = 0;
FormUSB->Label5.pCaption = LABEL5_TEXT;
FormUSB->Label5.Font = &FormUSB->FontBlack;
/* 动态标签 */
FormUSB->Label2.Left = LABEL2_X;
FormUSB->Label2.Top = LABEL2_Y;
FormUSB->Label2.MaxLen = 0;
FormUSB->Label2.pCaption = LABEL2_TEXT;
FormUSB->Label2.Font = &FormUSB->FontBlue;
FormUSB->Label4.Left = LABEL4_X;
FormUSB->Label4.Top = LABEL4_Y;
FormUSB->Label4.MaxLen = 0;
FormUSB->Label4.pCaption = LABEL4_TEXT;
FormUSB->Label4.Font = &FormUSB->FontBlue;
FormUSB->Label6.Left = LABEL6_X;
FormUSB->Label6.Top = LABEL6_Y;
FormUSB->Label6.MaxLen = 0;
FormUSB->Label6.pCaption = LABEL6_TEXT;
FormUSB->Label6.Font = &FormUSB->FontBlue;
/* 按钮 */
FormUSB->BtnRet.Left = BTN_RET_X;
FormUSB->BtnRet.Top = BTN_RET_Y;
FormUSB->BtnRet.Height = BTN_RET_H;
FormUSB->BtnRet.Width = BTN_RET_W;
FormUSB->BtnRet.pCaption = BTN_RET_TEXT;
FormUSB->BtnRet.Font = &FormUSB->FontBtn;
FormUSB->BtnRet.Focus = 0;
FormUSB->Btn1.Left = BTN1_X;
FormUSB->Btn1.Top = BTN1_Y;
FormUSB->Btn1.Height = BTN1_H;
FormUSB->Btn1.Width = BTN1_W;
FormUSB->Btn1.pCaption = BTN1_TEXT;
FormUSB->Btn1.Font = &FormUSB->FontBtn;
FormUSB->Btn1.Focus = 0;
FormUSB->Btn2.Left = BTN2_X;
FormUSB->Btn2.Top = BTN2_Y;
FormUSB->Btn2.Height = BTN2_H;
FormUSB->Btn2.Width = BTN2_W;
FormUSB->Btn2.pCaption = BTN2_TEXT;
FormUSB->Btn2.Font = &FormUSB->FontBtn;
FormUSB->Btn2.Focus = 0;
FormUSB->Btn3.Left = BTN3_X;
FormUSB->Btn3.Top = BTN3_Y;
FormUSB->Btn3.Height = BTN3_H;
FormUSB->Btn3.Width = BTN3_W;
FormUSB->Btn3.pCaption = BTN3_TEXT;
FormUSB->Btn3.Font = &FormUSB->FontBtn;
FormUSB->Btn3.Focus = 0;
FormUSB->Btn4.Left = BTN4_X;
FormUSB->Btn4.Top = BTN4_Y;
FormUSB->Btn4.Height = BTN4_H;
FormUSB->Btn4.Width = BTN4_W;
FormUSB->Btn4.pCaption = BTN4_TEXT;
FormUSB->Btn4.Font = &FormUSB->FontBtn;
FormUSB->Btn4.Focus = 0;
}
/*
*********************************************************************************************************
* : DispUSBInitFace
* :
* :
* :
*********************************************************************************************************
*/
static void DispUSBInitFace(void)
{
LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormUSB->Box1);
/* 标签 */
LCD_DrawLabel(&FormUSB->Label1);
LCD_DrawLabel(&FormUSB->Label2);
LCD_DrawLabel(&FormUSB->Label3);
LCD_DrawLabel(&FormUSB->Label4);
LCD_DrawLabel(&FormUSB->Label5);
LCD_DrawLabel(&FormUSB->Label6);
/* 按钮 */
LCD_DrawButton(&FormUSB->BtnRet);
LCD_DrawButton(&FormUSB->Btn1);
LCD_DrawButton(&FormUSB->Btn2);
LCD_DrawButton(&FormUSB->Btn3);
LCD_DrawButton(&FormUSB->Btn4);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,713 +0,0 @@
/*
*********************************************************************************************************
*
* : WIFI模块
* : wifi_test.c
* : V1.0
* : WiFi模块. 使AT指令
* SecureCRT : -> -> -> 仿 ->
* "新行模式"
* :
*
* v1.0 2015-07-16 armfly
*
* Copyright (C), 2015-2016, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "form_wifi.h"
#include "num_pad.h"
#define AP_MAX_NUM 30
/* 定义界面结构 */
typedef struct
{
FONT_T FontBlack; /* 静态的文字 */
FONT_T FontBlue; /* 变化的文字字体 */
FONT_T FontRed;
FONT_T FontBtn; /* 按钮的字体 */
FONT_T FontBox; /* 分组框标题字体 */
GROUP_T Box1;
LABEL_T Label1;
LABEL_T Label2;
LABEL_T Label3;
LABEL_T Label4;
LABEL_T Label5;
LABEL_T Label6;
LABEL_T Label7;
LABEL_T Label8;
LABEL_T Label9;
EDIT_T Edit1; /* WIFI密码 */
BUTTON_T Btn1; /* 列举AP */
BUTTON_T Btn2; /* 加入AP */
BUTTON_T Btn3; /* */
BUTTON_T Btn4; /* */
BUTTON_T BtnRet; /* 返回 */
WIFI_AP_T APList[AP_MAX_NUM]; /* AP 列表 */
} FormWIFI_T;
/* 窗体背景色 */
#define FORM_BACK_COLOR CL_BTN_FACE
/* 框的坐标和大小 */
#define BOX1_X 5
#define BOX1_Y 8
#define BOX1_H (g_LcdHeight - BOX1_Y - 10)
#define BOX1_W (g_LcdWidth - 2 * BOX1_X)
#define BOX1_TEXT "ESP8266 WiFi模块测试程序."
/* 返回按钮的坐标(屏幕右下角) */
#define BTN_RET_H 32
#define BTN_RET_W 60
#define BTN_RET_X ((BOX1_X + BOX1_W) - BTN_RET_W - 4)
#define BTN_RET_Y ((BOX1_Y + BOX1_H) - BTN_RET_H - 4)
#define BTN_RET_TEXT "返回"
#define LABEL1_X (BOX1_X + 6)
#define LABEL1_Y (g_LcdHeight - 28)
#define LABEL1_TEXT "--- "
/* 按钮 */
#define BTN1_H 32
#define BTN1_W 120
#define BTN1_X (g_LcdWidth - BTN1_W - 10)
#define BTN1_Y 20
#define BTN1_TEXT "列举AP"
/* Edit */
#define EDIT1_X BTN1_X
#define EDIT1_Y (BTN1_Y + (BTN1_H + 2))
#define EDIT1_H BTN1_H
#define EDIT1_W BTN1_W
#define LABEL2_X EDIT1_X - 45
#define LABEL2_Y EDIT1_Y + 4
#define LABEL2_TEXT "密码:"
#define BTN2_H BTN1_H
#define BTN2_W BTN1_W
#define BTN2_X BTN1_X
#define BTN2_Y (BTN1_Y + (BTN1_H + 2) * 2)
#define BTN2_TEXT "加入AP"
#define BTN3_H BTN1_H
#define BTN3_W BTN1_W
#define BTN3_X BTN1_X
#define BTN3_Y (BTN1_Y + (BTN1_H + 2) * 3)
#define BTN3_TEXT "查看本机IP"
#define BTN4_H BTN1_H
#define BTN4_W BTN1_W
#define BTN4_X BTN1_X
#define BTN4_Y (BTN1_Y + (BTN1_H + 2) * 4)
#define BTN4_TEXT "创建TCP服务"
static void InitFormWIFI(void);
static void DispFormWIFI(void);
static void DispInfoWiFi(char *_str);
FormWIFI_T *FormWIFI;
int16_t g_APCount = 0;
uint8_t g_TCPServerOk = 0;
static void ScanAP(void);
static void DispAP(void);
void AnlyzeHostCmd(void);
/*
*********************************************************************************************************
* : TestWIFI
* : WiFi模块
*
* :
*********************************************************************************************************
*/
void TestWIFI(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t ucTouch; /* 触摸事件 */
uint8_t fQuit = 0;
int16_t tpX, tpY;
uint8_t ucValue;
uint8_t fRefresh = 0;
FormWIFI_T form;
FormWIFI = &form;
LCD_ClrScr(CL_BTN_FACE);
InitFormWIFI();
DispFormWIFI();
bsp_InitESP8266();
//WiFiDispHelp();
DispInfoWiFi("【1】正在给ESP8266模块上电...(波特率: 74880bsp)");
printf("\r\n【1】正在给ESP8266模块上电...(波特率: 74880bsp)\r\n");
ESP8266_PowerOn();
DispInfoWiFi("【2】上电完成。波特率: 115200bsp");
printf("\r\n【2】上电完成。波特率: 115200bsp\r\n");
//
DispInfoWiFi("【3】测试AT指令");
ESP8266_SendAT("AT");
if (ESP8266_WaitResponse("OK", 50) == 1)
{
DispInfoWiFi("【3】模块应答AT成功");
bsp_DelayMS(1000);
}
else
{
DispInfoWiFi("【3】模块无应答, 请按K3键修改模块的波特率为115200");
bsp_DelayMS(1000);
}
g_TCPServerOk = 0;
/* 进入主程序循环体 */
while (fQuit == 0)
{
bsp_Idle();
if (g_TCPServerOk == 1)
{
AnlyzeHostCmd();
}
else
{
/* 从WIFI收到的数据发送到串口1 */
if (comGetChar(COM_ESP8266, &ucValue))
{
comSendChar(COM1, ucValue);
continue;
}
/* 将串口1的数据发送到MG323模块 */
if (comGetChar(COM1, &ucValue))
{
comSendChar(COM_ESP8266, ucValue);
continue;
}
}
if (fRefresh)
{
fRefresh = 0;
LCD_ClrScr(CL_BTN_FACE);
DispFormWIFI(); /* 刷新所有控件 */
DispAP();
}
ucTouch = TOUCH_GetKey(&tpX, &tpY); /* 读取触摸事件 */
if (ucTouch != TOUCH_NONE)
{
switch (ucTouch)
{
case TOUCH_DOWN: /* 触笔按下事件 */
LCD_ButtonTouchDown(&FormWIFI->BtnRet, tpX, tpY);
LCD_ButtonTouchDown(&FormWIFI->Btn1, tpX, tpY);
LCD_ButtonTouchDown(&FormWIFI->Btn2, tpX, tpY);
LCD_ButtonTouchDown(&FormWIFI->Btn3, tpX, tpY);
LCD_ButtonTouchDown(&FormWIFI->Btn4, tpX, tpY);
/* 编辑框 */
if (TOUCH_InRect(tpX, tpY, EDIT1_X, EDIT1_Y, EDIT1_H, EDIT1_W))
{
{
uint8_t len = 30;
if (InputNumber(NUMPAD_STR, "输入WiFi密码", &len, (void *)FormWIFI->Edit1.Text))
{
;
}
fRefresh = 1;
}
}
break;
case TOUCH_RELEASE: /* 触笔释放事件 */
if (LCD_ButtonTouchRelease(&FormWIFI->BtnRet, tpX, tpY))
{
fQuit = 1; /* 返回 */
}
else if (LCD_ButtonTouchRelease(&FormWIFI->Btn1, tpX, tpY))
{
ScanAP(); /* 扫描AP */
DispAP();
}
else if (LCD_ButtonTouchRelease(&FormWIFI->Btn2, tpX, tpY))
{
int32_t sn = 0;
char buf[64];
if (InputInt("选择AP序号", 0, 20, &sn))
{
LCD_ClrScr(CL_BTN_FACE);
DispFormWIFI(); /* 刷新所有控件 */
DispAP();
if (sn > 1)
{
sn--;
}
sprintf(buf, "正在加入AP... 请等待 %s", FormWIFI->APList[sn].ssid);
DispInfoWiFi(buf);
/* 加入AP 超时时间 10000ms10秒 */
if (ESP8266_JoinAP(FormWIFI->APList[sn].ssid, FormWIFI->Edit1.Text, 15000))
{
DispInfoWiFi("接入AP成功");
}
else
{
DispInfoWiFi("接入AP失败");
}
}
else
{
LCD_ClrScr(CL_BTN_FACE);
DispFormWIFI(); /* 刷新所有控件 */
DispAP();
}
}
else if (LCD_ButtonTouchRelease(&FormWIFI->Btn3, tpX, tpY)) /* 查看本机IP */
{
char ip[20];
char mac[32];
char buf[128];
if (ESP8266_GetLocalIP(ip, mac) == 1)
{
sprintf(buf, "%s, %s", ip, mac);
DispInfoWiFi(buf);
}
else
{
DispInfoWiFi("查询IP失败");
}
}
else if (LCD_ButtonTouchRelease(&FormWIFI->Btn4, tpX, tpY)) /* 拨打10086 */
{
if (g_TCPServerOk == 0)
{
if (ESP8266_CreateTCPServer(1000) == 1)
{
DispInfoWiFi("正在监听1000端口...");
g_TCPServerOk = 1;
}
else
{
DispInfoWiFi("创建TCP服务失败!");
}
}
else
{
ESP8266_CloseTcpUdp(0);
g_TCPServerOk = 0;
DispInfoWiFi("关闭当前TCP连接!");
}
}
break;
}
}
/* 处理按键事件 */
ucKeyCode = bsp_GetKey();
if (ucKeyCode > 0)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_DOWN_K1: /* K1键按下 */
//ESP8266_SendAT("AT+CWLAP"); /* 列举AP */
break;
case KEY_DOWN_K2: /* K2键按下 */
//ESP8266_SendAT("AT+CWJAP=\"Tenda_5BD8A8\",\"123456887af\""); /* 加入某个WIFI 网络 */
//ESP8266_JoinAP("Tenda_5BD8A8", "123456887af");
break;
case KEY_DOWN_K3: /* K3键-9600波特率切换到115200 */
comSetBaud(COM_ESP8266, 9600); /* 模块缺省是9600bps */
ESP8266_SendAT("AT+CIOBAUD=115200"); /* 按 9600bps 发送指令切换为 115200 */
ESP8266_WaitResponse("OK", 2000); /* 这个 OK 是模块按 9600 应答的 */
comSetBaud(COM_ESP8266, 115200); /* 切换STM32的波特率为 115200 */
/* 切换为 Station模式 */
bsp_DelayMS(100);
ESP8266_SendAT("AT+CWMODE=1");
ESP8266_WaitResponse("OK", 2000);
bsp_DelayMS(1500);
ESP8266_SendAT("AT+RST");
break;
case JOY_DOWN_U: /* 摇杆上键, AT+CIFSR获取本地IP地址 */
ESP8266_SendAT("AT+CIFSR");
break;
case JOY_DOWN_D: /* 摇杆DOWN键 AT+CIPSTATUS获得IP连接状态 */
ESP8266_SendAT("AT+CIPSTATUS");
break;
case JOY_DOWN_L: /* 摇杆LEFT键按下 AT+CIPSTART 建立TCP连接. 访问www,armfly.com http服务端口 */
ESP8266_SendAT("AT+CIPSTART=\"TCP\",\"WWW.ARMFLY.COM\",80");
break;
case JOY_DOWN_R: /* 摇杆RIGHT键按下 AT+CIPCLOSE关闭当前的TCP或UDP连接 */
ESP8266_SendAT("AT+CIPCLOSE");
break;
case JOY_DOWN_OK: /* 摇杆OK键按下 */
//printf("\r\n进入固件升级模式\r\n");
break;
default:
break;
}
}
}
}
/*
*********************************************************************************************************
* : AnlyzeHostCmd
* : TCP客户端发来的数据
* :
* :
*********************************************************************************************************
*/
void AnlyzeHostCmd(void)
{
uint8_t cmd_buf[2048];
//uint8_t *cmd_buf;
uint8_t cmd_len;
static uint8_t s_test = 0;
//cmd_buf = (uint8_t *)EXT_SRAM_ADDR; /* 指向外部SRAM */
cmd_len = ESP8266_RxNew(cmd_buf);
if (cmd_len == 0)
{
return;
}
if (s_test == 1)
{
if ((cmd_len == 1) && (memcmp(cmd_buf, "A", 1)) == 0)
{
ESP8266_SendTcpUdp(cmd_buf, 1300);
}
}
else if (s_test == 2)
{
ESP8266_SendTcpUdp("OK", 2);
}
if ((cmd_len == 6) && (memcmp(cmd_buf, "txtest", 6)) == 0)
{
s_test = 1;
ESP8266_SendTcpUdp(cmd_buf, 1300);
}
else if ((cmd_len == 6) && (memcmp(cmd_buf, "rxtest", 6)) == 0)
{
ESP8266_SendTcpUdp("OK", 2);
s_test = 2;
}
else if ((cmd_len == 4) && (memcmp(cmd_buf, "stop", 4)) == 0)
{
s_test = 0;
}
else
{
if (cmd_len == 7)
{
if (memcmp(cmd_buf, "ledon 1 ", 7) == 0)
{
bsp_LedOn(1);
ESP8266_SendTcpUdp("led1 on", 7);
}
else if (memcmp(cmd_buf, "ledon 2 ", 7) == 0)
{
bsp_LedOn(2);
ESP8266_SendTcpUdp("led2 on", 7);
}
else if (memcmp(cmd_buf, "ledon 3 ", 7) == 0)
{
bsp_LedOn(3);
ESP8266_SendTcpUdp("led3 on", 7);
}
else if (memcmp(cmd_buf, "ledon 4 ", 7) == 0)
{
bsp_LedOn(4);
ESP8266_SendTcpUdp("led4 on", 7);
}
}
else if (cmd_len == 8)
{
if (memcmp(cmd_buf, "ledoff 1", 8) == 0)
{
bsp_LedOff(1);
ESP8266_SendTcpUdp("led1 off", 8);
}
else if (memcmp(cmd_buf, "ledoff 2", 8) == 0)
{
bsp_LedOff(2);
ESP8266_SendTcpUdp("led2 off", 8);
}
else if (memcmp(cmd_buf, "ledoff 3", 8) == 0)
{
bsp_LedOff(3);
ESP8266_SendTcpUdp("led3 off", 8);
}
else if (memcmp(cmd_buf, "ledoff 4", 8) == 0)
{
bsp_LedOff(4);
ESP8266_SendTcpUdp("led4 off", 8);
}
}
}
}
/*
*********************************************************************************************************
* : ScanAP
* : AP.
*
* :
*********************************************************************************************************
*/
static void ScanAP(void)
{
/* 扫描 AP列表, 返回AP个数 */
g_APCount = ESP8266_ScanAP(FormWIFI->APList, AP_MAX_NUM);
}
/*
*********************************************************************************************************
* : DispAP
* : AP
*
* :
*********************************************************************************************************
*/
static void DispAP(void)
{
char buf[48];
FONT_T tFont;
uint16_t x, y;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_GREY; /* 字体颜色 */
tFont.BackColor = CL_BTN_FACE; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = 10;
y = 25;
LCD_Fill_Rect(x, y, 234, 280, CL_BTN_FACE);
sprintf(buf, "共扫描到%d个WiFi AP", g_APCount);
DispInfoWiFi(buf);
{
uint8_t i;
uint8_t m;
//const char *ecn_name[5] =
//{
// "OPEN", "WEP", "WPA_PSK", "WPA2_PSK", "WPA_WPA2_PSK"
//};
m = g_APCount;
if (m > 13)
{
m = 13;
}
for (i = 0; i < m; i++)
{
//sprintf(buf, " %02d=%s, rssi=%d, [%s]\r\n", i+1, g_APList[i].ssid, g_APList[i].rssi,
// ecn_name[g_APList[i].ecn]);
sprintf(buf, "%02d=%s, %ddBm", i + 1, FormWIFI->APList[i].ssid, FormWIFI->APList[i].rssi);
LCD_DispStr(x, y, buf, &tFont);
y += 17;
}
}
}
/*
*********************************************************************************************************
* : InitFormWIFI
* :
*
* :
*********************************************************************************************************
*/
static void InitFormWIFI(void)
{
/* 分组框标题字体 */
FormWIFI->FontBox.FontCode = FC_ST_16;
FormWIFI->FontBox.BackColor = CL_BTN_FACE; /* 和背景色相同 */
FormWIFI->FontBox.FrontColor = CL_BLACK;
FormWIFI->FontBox.Space = 0;
/* 字体1 用于静止标签 */
FormWIFI->FontBlack.FontCode = FC_ST_16;
FormWIFI->FontBlack.BackColor = CL_BTN_FACE; /* 透明色 */
FormWIFI->FontBlack.FrontColor = CL_BLACK;
FormWIFI->FontBlack.Space = 0;
/* 字体2 用于变化的文字 */
FormWIFI->FontBlue.FontCode = FC_ST_16;
FormWIFI->FontBlue.BackColor = CL_BTN_FACE;
FormWIFI->FontBlue.FrontColor = CL_BLUE;
FormWIFI->FontBlue.Space = 0;
FormWIFI->FontRed.FontCode = FC_ST_16;
FormWIFI->FontRed.BackColor = CL_BTN_FACE;
FormWIFI->FontRed.FrontColor = CL_RED;
FormWIFI->FontRed.Space = 0;
/* 按钮字体 */
FormWIFI->FontBtn.FontCode = FC_ST_16;
FormWIFI->FontBtn.BackColor = CL_MASK; /* 透明背景 */
FormWIFI->FontBtn.FrontColor = CL_BLACK;
FormWIFI->FontBtn.Space = 0;
/* 分组框 */
FormWIFI->Box1.Left = BOX1_X;
FormWIFI->Box1.Top = BOX1_Y;
FormWIFI->Box1.Height = BOX1_H;
FormWIFI->Box1.Width = BOX1_W;
FormWIFI->Box1.pCaption = BOX1_TEXT;
FormWIFI->Box1.Font = &FormWIFI->FontBox;
/* 静态标签 */
FormWIFI->Label1.Left = LABEL1_X;
FormWIFI->Label1.Top = LABEL1_Y;
FormWIFI->Label1.MaxLen = 0;
FormWIFI->Label1.pCaption = LABEL1_TEXT;
FormWIFI->Label1.Font = &FormWIFI->FontBlack;
FormWIFI->Label2.Left = LABEL2_X;
FormWIFI->Label2.Top = LABEL2_Y;
FormWIFI->Label2.MaxLen = 0;
FormWIFI->Label2.pCaption = LABEL2_TEXT;
FormWIFI->Label2.Font = &FormWIFI->FontBlack;
/* 按钮 */
FormWIFI->BtnRet.Left = BTN_RET_X;
FormWIFI->BtnRet.Top = BTN_RET_Y;
FormWIFI->BtnRet.Height = BTN_RET_H;
FormWIFI->BtnRet.Width = BTN_RET_W;
FormWIFI->BtnRet.pCaption = BTN_RET_TEXT;
FormWIFI->BtnRet.Font = &FormWIFI->FontBtn;
FormWIFI->BtnRet.Focus = 0;
FormWIFI->Btn1.Left = BTN1_X;
FormWIFI->Btn1.Top = BTN1_Y;
FormWIFI->Btn1.Height = BTN1_H;
FormWIFI->Btn1.Width = BTN1_W;
FormWIFI->Btn1.pCaption = BTN1_TEXT;
FormWIFI->Btn1.Font = &FormWIFI->FontBtn;
FormWIFI->Btn1.Focus = 0;
FormWIFI->Btn2.Left = BTN2_X;
FormWIFI->Btn2.Top = BTN2_Y;
FormWIFI->Btn2.Height = BTN2_H;
FormWIFI->Btn2.Width = BTN2_W;
FormWIFI->Btn2.pCaption = BTN2_TEXT;
FormWIFI->Btn2.Font = &FormWIFI->FontBtn;
FormWIFI->Btn2.Focus = 0;
FormWIFI->Btn3.Left = BTN3_X;
FormWIFI->Btn3.Top = BTN3_Y;
FormWIFI->Btn3.Height = BTN3_H;
FormWIFI->Btn3.Width = BTN3_W;
FormWIFI->Btn3.pCaption = BTN3_TEXT;
FormWIFI->Btn3.Font = &FormWIFI->FontBtn;
FormWIFI->Btn3.Focus = 0;
FormWIFI->Btn4.Left = BTN4_X;
FormWIFI->Btn4.Top = BTN4_Y;
FormWIFI->Btn4.Height = BTN4_H;
FormWIFI->Btn4.Width = BTN4_W;
FormWIFI->Btn4.pCaption = BTN4_TEXT;
FormWIFI->Btn4.Font = &FormWIFI->FontBtn;
FormWIFI->Btn4.Focus = 0;
/* 编辑框 */
FormWIFI->Edit1.Left = EDIT1_X;
FormWIFI->Edit1.Top = EDIT1_Y;
FormWIFI->Edit1.Height = EDIT1_H;
FormWIFI->Edit1.Width = EDIT1_W;
sprintf(FormWIFI->Edit1.Text, "123456887af");
FormWIFI->Edit1.pCaption = FormWIFI->Edit1.Text;
FormWIFI->Edit1.Font = &FormWIFI->FontBtn;
}
/*
*********************************************************************************************************
* : DispInfoWiFi
* :
* :
* :
*********************************************************************************************************
*/
static void DispInfoWiFi(char *_str)
{
FormWIFI->Label1.pCaption = _str;
LCD_DrawLabel(&FormWIFI->Label1);
}
/*
*********************************************************************************************************
* : DispFormWIFI
* :
* :
* :
*********************************************************************************************************
*/
static void DispFormWIFI(void)
{
//LCD_ClrScr(CL_BTN_FACE);
/* 分组框 */
LCD_DrawGroupBox(&FormWIFI->Box1);
/* 标签 */
LCD_DrawLabel(&FormWIFI->Label1);
LCD_DrawLabel(&FormWIFI->Label2);
/* 按钮 */
LCD_DrawButton(&FormWIFI->BtnRet);
LCD_DrawButton(&FormWIFI->Btn1);
LCD_DrawButton(&FormWIFI->Btn2);
LCD_DrawButton(&FormWIFI->Btn3);
LCD_DrawButton(&FormWIFI->Btn4);
/* 编辑框 */
LCD_DrawEdit(&FormWIFI->Edit1);
/* 动态标签 */
LCD_DrawLabel(&FormWIFI->Label2);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -1,390 +0,0 @@
/*
*********************************************************************************************************
*
* :
* : status_MenuMain.c
* : V1.0
* :
* :
*
* V1.0 2018-12-06 armfly
*
* Copyright (C), 2018-2030, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "param.h"
#include "main.h"
#include "images.h" /* 图标文件 */
#include "status_menu.h"
#include "modbus_reg_addr.h"
#define FORM_BACK_COLOR CL_BLUE
#define ICON_HEIGHT 48 /* 矩形图标高度 */
#define ICON_WIDTH 48 /* 矩形图标宽度 */
#define ICON_STEP_X 80 /* 图标之间的间隔 */
#define ICON_STEP_Y 70 /* 图标之间的间隔 */
#define MENU_COUNT 5
static const ICON_T s_tMainIcons[MENU_COUNT] =
{
{ID_ICON, 40, 20, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acchujiao, "1.联机模式"},
{ID_ICON, 40, 20, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acLCD, "2.电压表"},
{ID_ICON, 40, 20, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acRadio, "3.NTC测温"},
{ID_ICON, 40, 20, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acRecorder, "4.电阻表"},
{ID_ICON, 40, 20, ICON_HEIGHT, ICON_WIDTH, (uint16_t *)acchujiao, "5.负载电流"},
};
/*
*********************************************************************************************************
* : status_MenuMain
* :
* :
* :
*********************************************************************************************************
*/
void status_MenuMain(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t fRefresh;
FONT_T tFont; /* 定义字体结构体变量 */
FONT_T tIconFont; /* 定义一个字体结构体变量,用于图标文本 */
static uint8_t s_menu_idx = 0;
uint8_t ucIgnoreKey = 0;
/* 设置字体参数 */
{
uint16_t x;
uint16_t y;
char buf[64];
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_YELLOW; /* 字体颜色 */
tFont.BackColor = FORM_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
LCD_ClrScr(FORM_BACK_COLOR); /* 清屏,背景蓝色 */
x = 5;
y = 3;
LCD_DispStr(x, y, "选择功能", &tFont);
y = y + 20;
sprintf(buf, "MAC:%02X-%02X-%02X-%02X-%02X-%02X",
g_tVar.MACaddr[0], g_tVar.MACaddr[1], g_tVar.MACaddr[2],
g_tVar.MACaddr[3], g_tVar.MACaddr[4], g_tVar.MACaddr[5]);
LCD_DispStr(x, y, buf, &tFont);
y = y + 20;
sprintf(buf, "IP:%d.%d.%d.%d",
g_tVar.MACaddr[0], g_tVar.MACaddr[1], g_tVar.MACaddr[2],
g_tVar.MACaddr[3], g_tVar.MACaddr[4], g_tVar.MACaddr[5]);
LCD_DispStr(x, y, buf, &tFont);
LCD_SetBackLight(BRIGHT_DEFAULT); /* 打开背光,设置为缺省亮度 */
/* 设置字体参数 */
{
tIconFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tIconFont.FrontColor = CL_WHITE; /* 字体颜色 */
tIconFont.BackColor = CL_BLUE; /* 文字背景颜色 */
tIconFont.Space = 1; /* 文字间距,单位 = 像素 */
}
}
bsp_ClearKey(); /* 清缓存的按键 */
/* 从其他界面返回后需要忽略第1个C键弹起事件 */
if (bsp_GetKeyState(KID_S) || bsp_GetKeyState(KID_C))
{
ucIgnoreKey = 1;
}
fRefresh = 1;
while (g_MainStatus == MS_MAIN_MENU)
{
bsp_Idle();
if (fRefresh) /* 刷新整个界面 */
{
fRefresh = 0;
LCD_DrawIcon32(&s_tMainIcons[s_menu_idx], &tIconFont, 0);
}
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 */
BEEP_KeyTone();
LCD_ClrScr(CL_BLUE);
if (++s_menu_idx >= MENU_COUNT)
{
s_menu_idx = 0;
}
fRefresh = 1;
break;
case KEY_UP_C: /* C键 */
if (ucIgnoreKey == 1)
{
ucIgnoreKey = 0; /* 丢弃第1个按键弹起事件 */
break;
}
BEEP_KeyTone();
LCD_ClrScr(CL_BLUE);
if (s_menu_idx > 0)
{
s_menu_idx--;
}
else
{
s_menu_idx = MENU_COUNT - 1;
}
fRefresh = 1;
break;
case KEY_LONG_S: /* S键 */
BEEP_KeyTone();
g_MainStatus = MS_SYSTEM_SET;
break;
case KEY_LONG_C: /* C键 */
BEEP_KeyTone();
if (++g_tParam.DispDir > 3)
{
g_tParam.DispDir = 0;
}
LCD_SetDirection(g_tParam.DispDir);
SaveParam();
LCD_ClrScr(CL_BLUE);
fRefresh = 1;
ucIgnoreKey = 1;
break;
default:
break;
}
}
}
}
/*
*********************************************************************************************************
* : status_LinkMode
* :
* :
* :
*********************************************************************************************************
*/
void status_LinkMode(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t fRefresh;
FONT_T tFont; /* 定义字体结构体变量 */
FONT_T tIconFont; /* 定义一个字体结构体变量,用于图标文本 */
static uint8_t s_menu_idx = 0;
uint8_t ucIgnoreKey = 0;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = CL_WHITE; /* 字体颜色 */
tFont.BackColor = FORM_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
LCD_ClrScr(FORM_BACK_COLOR); /* 清屏,背景蓝色 */
LCD_DispStr(5, 3, "直流电压表", &tFont);
}
bsp_ClearKey(); /* 清缓存的按键 */
/* 从其他界面返回后需要忽略第1个C键弹起事件 */
if (bsp_GetKeyState(KID_S) || bsp_GetKeyState(KID_C))
{
ucIgnoreKey = 1;
}
/* 初始化DSO硬件电路 */
{
DSO_InitHard();
DSO_SetDC(1, 1); /* CH1 选DC耦合 */
DSO_SetDC(2, 1); /* CH2 选DC耦合 */
DSO_SetGain(1, 0); /* CH1 增益选择最小(量程最大) */
DSO_SetGain(2, 0); /* CH2 增益选择最小(量程最大) */
}
fRefresh = 1;
bsp_StartAutoTimer(0, 100); /* 100ms 刷新 */
while (g_MainStatus == MS_VOLT_METER)
{
bsp_Idle();
if (fRefresh) /* 刷新整个界面 */
{
fRefresh = 0;
;
}
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 */
BEEP_KeyTone();
LCD_ClrScr(CL_BLUE);
fRefresh = 1;
break;
case KEY_UP_C: /* C键 */
if (ucIgnoreKey == 1)
{
ucIgnoreKey = 0; /* 丢弃第1个按键弹起事件 */
break;
}
BEEP_KeyTone();
LCD_ClrScr(CL_BLUE);
fRefresh = 1;
break;
case KEY_LONG_S: /* S键 */
BEEP_KeyTone();
g_MainStatus = MS_SYSTEM_SET;
break;
case KEY_LONG_C: /* C键 */
BEEP_KeyTone();
if (++g_tParam.DispDir > 3)
{
g_tParam.DispDir = 0;
}
LCD_SetDirection(g_tParam.DispDir);
SaveParam();
LCD_ClrScr(CL_BLUE);
fRefresh = 1;
ucIgnoreKey = 1;
break;
default:
break;
}
}
}
}
/*
*********************************************************************************************************
* : status_VoltMeter
* :
* :
* :
*********************************************************************************************************
*/
void status_VoltMeter(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t fRefresh;
FONT_T tFont; /* 定义字体结构体变量 */
FONT_T tIconFont; /* 定义一个字体结构体变量,用于图标文本 */
static uint8_t s_menu_idx = 0;
uint8_t ucIgnoreKey = 0;
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = CL_WHITE; /* 字体颜色 */
tFont.BackColor = FORM_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
LCD_ClrScr(FORM_BACK_COLOR); /* 清屏,背景蓝色 */
LCD_DispStr(5, 3, "直流电压表", &tFont);
}
bsp_ClearKey(); /* 清缓存的按键 */
/* 从其他界面返回后需要忽略第1个C键弹起事件 */
if (bsp_GetKeyState(KID_S) || bsp_GetKeyState(KID_C))
{
ucIgnoreKey = 1;
}
/* 初始化DSO硬件电路 */
{
DSO_InitHard();
DSO_SetDC(1, 1); /* CH1 选DC耦合 */
DSO_SetDC(2, 1); /* CH2 选DC耦合 */
DSO_SetGain(1, 0); /* CH1 增益选择最小(量程最大) */
DSO_SetGain(2, 0); /* CH2 增益选择最小(量程最大) */
}
fRefresh = 1;
bsp_StartAutoTimer(0, 100); /* 100ms 刷新 */
while (g_MainStatus == MS_VOLT_METER)
{
bsp_Idle();
if (fRefresh) /* 刷新整个界面 */
{
fRefresh = 0;
;
}
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 */
BEEP_KeyTone();
LCD_ClrScr(CL_BLUE);
fRefresh = 1;
break;
case KEY_UP_C: /* C键 */
if (ucIgnoreKey == 1)
{
ucIgnoreKey = 0; /* 丢弃第1个按键弹起事件 */
break;
}
BEEP_KeyTone();
LCD_ClrScr(CL_BLUE);
fRefresh = 1;
break;
case KEY_LONG_S: /* S键 */
BEEP_KeyTone();
g_MainStatus = MS_SYSTEM_SET;
break;
case KEY_LONG_C: /* C键 */
BEEP_KeyTone();
if (++g_tParam.DispDir > 3)
{
g_tParam.DispDir = 0;
}
LCD_SetDirection(g_tParam.DispDir);
SaveParam();
LCD_ClrScr(CL_BLUE);
fRefresh = 1;
ucIgnoreKey = 1;
break;
default:
break;
}
}
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -24,7 +24,7 @@ static void DispHelpCurrentMeter(void);
/*
*********************************************************************************************************
* : status_CurrentMeter
* : .
* : .
* :
* :
*********************************************************************************************************

View File

@ -142,6 +142,8 @@ void status_LinkMode(void)
usbd_CloseCDC();
usbd_OpenCDC(1); /* 启用USB虚拟串口1 用于虚拟串口RS232 RS485 TTL-UART */
}
DSO_StartMode2(); /* 示波器启动模式2-低速多通道扫描 */
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -0,0 +1,214 @@
/*
*********************************************************************************************************
*
* :
* : status_TVccPower.c
* : V1.0
* : TVCC输出可调电压1.2-5.0V400mA
* :
*
* V1.0 2019-11-04 armfly 1
*
* Copyright (C), 2018-2030, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
static void DispTVccVoltCurr(void);
static void DispHelpTVCCPower(void);
static void DispTVccSetting(uint16_t _volt);
/*
*********************************************************************************************************
* : status_TVCCPower
* : TVCC引脚输出电压可调400mA限流
* :
* :
*********************************************************************************************************
*/
void status_TVCCPower(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t fRefresh;
uint8_t ucIgnoreKey = 0;
uint8_t ucAdjustMode = 0;
uint16_t NowVolt; /* 当前设置电压 mV */
DispHeader("微型数控电源");
DispHelpTVCCPower();
fRefresh = 1;
NowVolt = 3300;
DispTVccSetting(NowVolt);
bsp_StartAutoTimer(0, 300);
while (g_MainStatus == MS_TVCC_POWER)
{
bsp_Idle();
if (fRefresh) /* 刷新整个界面 */
{
fRefresh = 0;
bsp_SetTVCC(NowVolt);
DispTVccVoltCurr();
}
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键释放 */
if (ucAdjustMode == 0)
{
g_MainStatus = NextStatus(MS_TVCC_POWER);
}
else
{
if (NowVolt < 5000)
{
NowVolt += 100;
DispTVccSetting(NowVolt);
}
else
{
BEEP_Start(5, 5, 3); /* 叫50ms停50ms循环3次 */
}
}
break;
case KEY_LONG_S: /* S键长按 */
ucAdjustMode = 1;
BEEP_KeyTone();
break;
case KEY_DOWN_C: /* C键按下 */
break;
case KEY_UP_C: /* C键释放 */
if (ucAdjustMode == 0 && ucIgnoreKey == 0)
{
g_MainStatus = LastStatus(MS_TVCC_POWER);
}
else
{
if (NowVolt > 1200)
{
NowVolt -= 100;
DispTVccSetting(NowVolt);
}
else
{
BEEP_Start(5,5,3); /* 叫50ms停50ms循环3次 */
}
}
ucIgnoreKey = 0;
break;
case KEY_LONG_C: /* C键长按 */
ucAdjustMode = 0;
ucIgnoreKey = 1; /* 需要丢弃即将到来的C键弹起事件 */
BEEP_KeyTone();
break;
default:
break;
}
}
}
bsp_StopTimer(0);
bsp_SetTVCC(3300); /* 退出时还原为3.3V */
}
/*
*********************************************************************************************************
* : DispHelpTVCCPower
* :
* :
* :
*********************************************************************************************************
*/
static void DispHelpTVCCPower(void)
{
FONT_T tFont; /* 定义字体结构体变量 */
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = CL_YELLOW; /* 字体颜色 */
tFont.BackColor = FORM_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
tFont.FrontColor = CL_BLACK; /* 黑字 */
LCD_DispStr(5, 240 - 40, "TVCC输出1.2-5.0V, 限流400mA", &tFont);
LCD_DispStr(5, 240 - 20, "长按S进入调节状态", &tFont);
}
/*
*********************************************************************************************************
* : DispTVccVoltCurr
* :
* :
* :
*********************************************************************************************************
*/
static void DispTVccVoltCurr(void)
{
FONT_T tFont;
char buf[64];
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = CL_WHITE; /* 字体颜色 */
tFont.BackColor = HEAD_BAR_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
sprintf(buf, "电压: %8.3fV", g_tVar.TVCCVolt );
LCD_DispStrEx(10, 50 + 32 * 0, buf, &tFont, 220, ALIGN_CENTER);
sprintf(buf, "电流: %8.2fmA", g_tVar.TVCCCurr);
LCD_DispStrEx(10, 50 + 32 * 1, buf, &tFont, 220, ALIGN_CENTER);
sprintf(buf, "功率: %8.3fW", g_tVar.TVCCVolt * g_tVar.TVCCCurr / 1000);
LCD_DispStrEx(10, 50 + 32 * 2, buf, &tFont, 220, ALIGN_CENTER);
}
/*
*********************************************************************************************************
* : DispTVccSetting
* :
* : _volt : mV (1200 - 5000)
* :
*********************************************************************************************************
*/
static void DispTVccSetting(uint16_t _volt)
{
FONT_T tFont;
char buf[64];
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_24; /* 字体代码 16点阵 */
tFont.FrontColor = CL_YELLOW; /* 字体颜色 */
tFont.BackColor = HEAD_BAR_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
sprintf(buf, "设置电压: %d.%dV", _volt / 1000, (_volt % 1000) / 100);
LCD_DispStrEx(10, 70 + 32 * 3, buf, &tFont, 220, ALIGN_CENTER);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -34,8 +34,6 @@ void status_VoltageMeter(void)
DispHeader("电压表");
DSO_StartMode2(); /* 示波器启动模式2-低速多通道扫描 */
fRefresh = 1;
bsp_StartAutoTimer(0, 300);

View File

@ -125,8 +125,8 @@ void bsp_Init(void)
*/
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
HAL_StatusTypeDef ret = HAL_OK;

View File

@ -23,7 +23,7 @@
/* 定时器结构体,成员变量必须是 volatile, 否则C编译器优化时可能有问题 */
typedef enum
{
TMR_ONCE_MODE = 0, /* 一次工作模式 */
TMR_ONCE_MODE = 0, /* 一次工作模式 */
TMR_AUTO_MODE = 1 /* 自动定时工作模式 */
} TMR_MODE_E;
@ -32,8 +32,8 @@ typedef struct
{
volatile uint8_t Mode; /* 计数器模式1次性 */
volatile uint8_t Flag; /* 定时到达标志 */
volatile uint32_t Count; /* 计数器 */
volatile uint32_t PreLoad; /* 计数器预装值 */
volatile uint32_t Count; /* 计数器 */
volatile uint32_t PreLoad; /* 计数器预装值 */
} SOFT_TMR;
/* 提供给其他C文件调用的函数 */

View File

@ -41,11 +41,11 @@
gpio_init.Pin = pin; \
HAL_GPIO_Init(gpio, &gpio_init);
#define GPIO_DIR_SET_OUT(gpio, pin) gpio->BSRRL = pin /* DIR = 1 输出 */
#define GPIO_DIR_SET_OUT(gpio, pin) gpio->BSRRL = pin /* DIR = 1 输出 */
#define GPIO_DIR_SET_IN(gpio, pin) gpio->BSRRH = pin /* DIR = 0 输入 */
#define GPIO_SET_HIGH(gpio, pin) gpio->BSRRL = pin /* pin = 1 */
#define GPIO_SET_LOW(gpio, pin) gpio->BSRRH = pin /* pin = 0 */
#define GPIO_SET_HIGH(gpio, pin) gpio->BSRRL = pin /* pin = 1 */
#define GPIO_SET_LOW(gpio, pin) gpio->BSRRH = pin /* pin = 0 */
#define GPIO_IN_IS_HIGH(gpio, pin) (gpio->IDR & pin)
#define GPIO_OUT_IS_HIGH(gpio, pin) (gpio->ODR & pin)

View File

@ -43,79 +43,79 @@
/* QSPI引脚和时钟相关配置宏定义 */
#if 1
#define QSPI_CLK_ENABLE() __HAL_RCC_QSPI_CLK_ENABLE()
#define QSPI_CLK_DISABLE() __HAL_RCC_QSPI_CLK_DISABLE()
#define QSPI_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define QSPI_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define QSPI_BK1_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define QSPI_BK1_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define QSPI_BK1_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define QSPI_CLK_ENABLE() __HAL_RCC_QSPI_CLK_ENABLE()
#define QSPI_CLK_DISABLE() __HAL_RCC_QSPI_CLK_DISABLE()
#define QSPI_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define QSPI_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define QSPI_BK1_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define QSPI_BK1_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define QSPI_BK1_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define QSPI_MDMA_CLK_ENABLE() __HAL_RCC_MDMA_CLK_ENABLE()
#define QSPI_FORCE_RESET() __HAL_RCC_QSPI_FORCE_RESET()
#define QSPI_RELEASE_RESET() __HAL_RCC_QSPI_RELEASE_RESET()
#define QSPI_MDMA_CLK_ENABLE() __HAL_RCC_MDMA_CLK_ENABLE()
#define QSPI_FORCE_RESET() __HAL_RCC_QSPI_FORCE_RESET()
#define QSPI_RELEASE_RESET() __HAL_RCC_QSPI_RELEASE_RESET()
#define QSPI_CS_PIN GPIO_PIN_6
#define QSPI_CS_GPIO_PORT GPIOG
#define QSPI_CS_GPIO_AF GPIO_AF10_QUADSPI
#define QSPI_CS_PIN GPIO_PIN_6
#define QSPI_CS_GPIO_PORT GPIOG
#define QSPI_CS_GPIO_AF GPIO_AF10_QUADSPI
#define QSPI_CLK_PIN GPIO_PIN_2
#define QSPI_CLK_GPIO_PORT GPIOB
#define QSPI_CLK_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_CLK_PIN GPIO_PIN_2
#define QSPI_CLK_GPIO_PORT GPIOB
#define QSPI_CLK_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D0_PIN GPIO_PIN_11
#define QSPI_BK1_D0_GPIO_PORT GPIOD
#define QSPI_BK1_D0_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D0_PIN GPIO_PIN_11
#define QSPI_BK1_D0_GPIO_PORT GPIOD
#define QSPI_BK1_D0_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D1_PIN GPIO_PIN_12
#define QSPI_BK1_D1_GPIO_PORT GPIOD
#define QSPI_BK1_D1_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D1_PIN GPIO_PIN_12
#define QSPI_BK1_D1_GPIO_PORT GPIOD
#define QSPI_BK1_D1_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D2_PIN GPIO_PIN_7
#define QSPI_BK1_D2_GPIO_PORT GPIOF
#define QSPI_BK1_D2_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D2_PIN GPIO_PIN_7
#define QSPI_BK1_D2_GPIO_PORT GPIOF
#define QSPI_BK1_D2_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D3_PIN GPIO_PIN_13
#define QSPI_BK1_D3_GPIO_PORT GPIOD
#define QSPI_BK1_D3_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D3_PIN GPIO_PIN_13
#define QSPI_BK1_D3_GPIO_PORT GPIOD
#define QSPI_BK1_D3_GPIO_AF GPIO_AF9_QUADSPI
#else
#define QSPI_CLK_ENABLE() __HAL_RCC_QSPI_CLK_ENABLE()
#define QSPI_CLK_DISABLE() __HAL_RCC_QSPI_CLK_DISABLE()
#define QSPI_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define QSPI_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_CLK_ENABLE() __HAL_RCC_QSPI_CLK_ENABLE()
#define QSPI_CLK_DISABLE() __HAL_RCC_QSPI_CLK_DISABLE()
#define QSPI_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define QSPI_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_BK1_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define QSPI_MDMA_CLK_ENABLE() __HAL_RCC_MDMA_CLK_ENABLE()
#define QSPI_FORCE_RESET() __HAL_RCC_QSPI_FORCE_RESET()
#define QSPI_RELEASE_RESET() __HAL_RCC_QSPI_RELEASE_RESET()
#define QSPI_MDMA_CLK_ENABLE() __HAL_RCC_MDMA_CLK_ENABLE()
#define QSPI_FORCE_RESET() __HAL_RCC_QSPI_FORCE_RESET()
#define QSPI_RELEASE_RESET() __HAL_RCC_QSPI_RELEASE_RESET()
#define QSPI_CS_PIN GPIO_PIN_6
#define QSPI_CS_GPIO_PORT GPIOG
#define QSPI_CS_GPIO_AF GPIO_AF10_QUADSPI
#define QSPI_CS_PIN GPIO_PIN_6
#define QSPI_CS_GPIO_PORT GPIOG
#define QSPI_CS_GPIO_AF GPIO_AF10_QUADSPI
#define QSPI_CLK_PIN GPIO_PIN_10
#define QSPI_CLK_GPIO_PORT GPIOF
#define QSPI_CLK_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_CLK_PIN GPIO_PIN_10
#define QSPI_CLK_GPIO_PORT GPIOF
#define QSPI_CLK_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D0_PIN GPIO_PIN_8
#define QSPI_BK1_D0_GPIO_PORT GPIOF
#define QSPI_BK1_D0_GPIO_AF GPIO_AF10_QUADSPI
#define QSPI_BK1_D0_PIN GPIO_PIN_8
#define QSPI_BK1_D0_GPIO_PORT GPIOF
#define QSPI_BK1_D0_GPIO_AF GPIO_AF10_QUADSPI
#define QSPI_BK1_D1_PIN GPIO_PIN_9
#define QSPI_BK1_D1_GPIO_PORT GPIOF
#define QSPI_BK1_D1_GPIO_AF GPIO_AF10_QUADSPI
#define QSPI_BK1_D1_PIN GPIO_PIN_9
#define QSPI_BK1_D1_GPIO_PORT GPIOF
#define QSPI_BK1_D1_GPIO_AF GPIO_AF10_QUADSPI
#define QSPI_BK1_D2_PIN GPIO_PIN_7
#define QSPI_BK1_D2_GPIO_PORT GPIOF
#define QSPI_BK1_D2_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D2_PIN GPIO_PIN_7
#define QSPI_BK1_D2_GPIO_PORT GPIOF
#define QSPI_BK1_D2_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D3_PIN GPIO_PIN_6
#define QSPI_BK1_D3_GPIO_PORT GPIOF
#define QSPI_BK1_D3_GPIO_AF GPIO_AF9_QUADSPI
#define QSPI_BK1_D3_PIN GPIO_PIN_6
#define QSPI_BK1_D3_GPIO_PORT GPIOF
#define QSPI_BK1_D3_GPIO_AF GPIO_AF9_QUADSPI
#endif
/* 供本文件调用的全局变量 */

View File

@ -1,22 +1,22 @@
/*
*********************************************************************************************************
*
* : TIM基本定时中断和PWM驱动模块
* : bsp_tim_pwm.c
* : V1.6
* : STM32F4内部TIM输出PWM信号
* :
*
* V1.0 2013-08-16 armfly
* V1.1 2014-06-15 armfly bsp_SetTIMOutPWM=0100%GPIO配置为输出
* V1.2 2015-05-08 armfly TIM8不能输出PWM的问题
* V1.3 2015-07-23 armfly TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0x0000;
* TIM1 TIM8
* V1.4 2015-07-30 armfly PWM函数 bsp_SetTIMOutPWM_N();
* V1.5 2016-02-01 armfly TIM_OC1PreloadConfig(TIMx, TIM_OCPreload_Enable);
* V1.6 2016-02-27 armfly TIM14无法中断的BUG, TIM8_TRG_COM_TIM14_IRQn
* : TIM基本定时中断和PWM驱动模块
* : bsp_tim_pwm.c
* : V1.6
* : STM32H7内部TIM输出PWM信号
* :
*
* V1.0 2013-08-16 armfly
* V1.1 2014-06-15 armfly bsp_SetTIMOutPWM=0100%GPIO配置为输出
* V1.2 2015-05-08 armfly TIM8不能输出PWM的问题
* V1.3 2015-07-23 armfly TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0x0000;
* TIM1 TIM8
* V1.4 2015-07-30 armfly PWM函数 bsp_SetTIMOutPWM_N();
* V1.5 2016-02-01 armfly TIM_OC1PreloadConfig(TIMx, TIM_OCPreload_Enable);
* V1.6 2016-02-27 armfly TIM14无法中断的BUG, TIM8_TRG_COM_TIM14_IRQn
*
* Copyright (C), 2015-2016, www.armfly.com
* Copyright (C), 2018-2030, www.armfly.com
*
*********************************************************************************************************
*/
@ -24,52 +24,52 @@
#include "bsp.h"
/*
STM32H7有TIM1 TIM17TIM9TIM10和TIM1114
GPIO的TIM通道:
TIM1_CH1, PA8, PE9,
TIM1_CH2, PA9, PE11
TIM1_CH3, PA10, PE13
TIM1_CH4, PA11, PE14
TIM1_CH1, PA8 PE9 PK1
TIM1_CH2, PA9 PE11
TIM1_CH3, PA10 PE13 PJ9
TIM1_CH4, PA11 PE14 PJ11
TIM2_CH1, PA15 (429439) 407
TIM2_CH2, PA1, PB3
TIM2_CH3, PA2, PB10
TIM2_CH4, PA3, PB11
TIM2_CH1, PA0 PA5 PA15
TIM2_CH2, PA1 PB3
TIM2_CH3, PA2
TIM2_CH4, PA3 PB11
TIM3_CH1, PA6, PB4, PC6
TIM3_CH2, PA7, PB5, PC7
TIM3_CH3, PB0, PC8
TIM3_CH4, PB1, PC9
TIM3_CH1, PA6 PC6 PB4
TIM3_CH2, PA7 PC7 PB5
TIM3_CH3, PB0 PC8
TIM3_CH4, PB1 PC9
TIM4_CH1, PB6, PD12
TIM4_CH2, PB7, PD13
TIM4_CH3, PB8, PD14
TIM4_CH4, PB9, PD15
TIM4_CH1, PB6 PD12
TIM4_CH2, PB7 PD13
TIM4_CH3, PB8 PD14
TIM4_CH4, PB9 PD15
TIM5_CH1, PA0, PH10
TIM5_CH2, PA1, PH11
TIM5_CH3, PA2, PH12
TIM5_CH4, PA3, PI10
TIM5_CH1, PA0 PH10
TIM5_CH2, PA1 PH11
TIM5_CH3, PA2 PH12
TIM5_CH4, PA3 PI0
TIM8_CH1, PC6, PI5
TIM8_CH2, PC7, PI6
TIM8_CH3, PC8, PI7
TIM8_CH4, PC9, PI2
TIM8_CH1, PC6 PI5 PJ8
TIM8_CH2, PC7 PI6 PJ10
TIM8_CH3, PC8 PI7 PK0
TIM8_CH4, PC9
TIM9_CH1, PA2, PE5
TIM9_CH2, PA3, PE6
TIM12_CH1, PB14 PH6
TIM12_CH2, PB15 PH9
TIM10_CH1, PB8, PF6
TIM13_CH1, PF8
TIM11_CH1, PB9, PF7
TIM14_CH1, PF9
TIM12_CH1, PB14, PH6
TIM12_CH2, PB15, PH9
TIM15_CH1, PE5
TIM15_CH2, PE6
TIM13_CH1, PA6, PF8
TIM14_CH1, PA7, PF9
TIM16_CH1, PB8 PF6
TIM16_CH2, PF7
APB1 TIM2, TIM3 ,TIM4, TIM5, TIM6, TIM7, TIM12, TIM13, TIM14
APB2 TIM1, TIM8 ,TIM9, TIM10, TIM11
TIM17_CH1, PB9
*/
/*
@ -80,30 +80,19 @@
* :
*********************************************************************************************************
*/
void bsp_RCC_GPIO_Enable(GPIO_TypeDef *GPIOx)
void bsp_RCC_GPIO_Enable(GPIO_TypeDef* GPIOx)
{
if (GPIOx == GPIOA)
__HAL_RCC_GPIOA_CLK_ENABLE();
else if (GPIOx == GPIOB)
__HAL_RCC_GPIOB_CLK_ENABLE();
else if (GPIOx == GPIOC)
__HAL_RCC_GPIOC_CLK_ENABLE();
else if (GPIOx == GPIOD)
__HAL_RCC_GPIOD_CLK_ENABLE();
else if (GPIOx == GPIOE)
__HAL_RCC_GPIOE_CLK_ENABLE();
else if (GPIOx == GPIOF)
__HAL_RCC_GPIOF_CLK_ENABLE();
else if (GPIOx == GPIOG)
__HAL_RCC_GPIOG_CLK_ENABLE();
else if (GPIOx == GPIOH)
__HAL_RCC_GPIOH_CLK_ENABLE();
else if (GPIOx == GPIOI)
__HAL_RCC_GPIOI_CLK_ENABLE();
else if (GPIOx == GPIOJ)
__HAL_RCC_GPIOJ_CLK_ENABLE();
else if (GPIOx == GPIOK)
__HAL_RCC_GPIOK_CLK_ENABLE();
if (GPIOx == GPIOA) __HAL_RCC_GPIOA_CLK_ENABLE();
else if (GPIOx == GPIOB) __HAL_RCC_GPIOB_CLK_ENABLE();
else if (GPIOx == GPIOC) __HAL_RCC_GPIOC_CLK_ENABLE();
else if (GPIOx == GPIOD) __HAL_RCC_GPIOD_CLK_ENABLE();
else if (GPIOx == GPIOE) __HAL_RCC_GPIOE_CLK_ENABLE();
else if (GPIOx == GPIOF) __HAL_RCC_GPIOF_CLK_ENABLE();
else if (GPIOx == GPIOG) __HAL_RCC_GPIOG_CLK_ENABLE();
else if (GPIOx == GPIOH) __HAL_RCC_GPIOH_CLK_ENABLE();
else if (GPIOx == GPIOI) __HAL_RCC_GPIOI_CLK_ENABLE();
else if (GPIOx == GPIOJ) __HAL_RCC_GPIOJ_CLK_ENABLE();
else if (GPIOx == GPIOK) __HAL_RCC_GPIOK_CLK_ENABLE();
}
/*
@ -114,90 +103,62 @@ void bsp_RCC_GPIO_Enable(GPIO_TypeDef *GPIOx)
* :
*********************************************************************************************************
*/
void bsp_RCC_TIM_Enable(TIM_TypeDef *TIMx)
void bsp_RCC_TIM_Enable(TIM_TypeDef* TIMx)
{
if (TIMx == TIM1)
__HAL_RCC_TIM1_CLK_ENABLE();
else if (TIMx == TIM2)
__HAL_RCC_TIM2_CLK_ENABLE();
else if (TIMx == TIM3)
__HAL_RCC_TIM3_CLK_ENABLE();
else if (TIMx == TIM4)
__HAL_RCC_TIM4_CLK_ENABLE();
else if (TIMx == TIM5)
__HAL_RCC_TIM5_CLK_ENABLE();
else if (TIMx == TIM6)
__HAL_RCC_TIM6_CLK_ENABLE();
else if (TIMx == TIM7)
__HAL_RCC_TIM7_CLK_ENABLE();
else if (TIMx == TIM8)
__HAL_RCC_TIM8_CLK_ENABLE();
// else if (TIMx == TIM9) __HAL_RCC_TIM9_CLK_ENABLE();
// else if (TIMx == TIM10) __HAL_RCC_TIM10_CLK_ENABLE();
// else if (TIMx == TIM11) __HAL_RCC_TIM11_CLK_ENABLE();
else if (TIMx == TIM12)
__HAL_RCC_TIM12_CLK_ENABLE();
else if (TIMx == TIM13)
__HAL_RCC_TIM13_CLK_ENABLE();
else if (TIMx == TIM14)
__HAL_RCC_TIM14_CLK_ENABLE();
else if (TIMx == TIM15)
__HAL_RCC_TIM15_CLK_ENABLE();
else if (TIMx == TIM16)
__HAL_RCC_TIM16_CLK_ENABLE();
else if (TIMx == TIM17)
__HAL_RCC_TIM17_CLK_ENABLE();
if (TIMx == TIM1) __HAL_RCC_TIM1_CLK_ENABLE();
else if (TIMx == TIM2) __HAL_RCC_TIM2_CLK_ENABLE();
else if (TIMx == TIM3) __HAL_RCC_TIM3_CLK_ENABLE();
else if (TIMx == TIM4) __HAL_RCC_TIM4_CLK_ENABLE();
else if (TIMx == TIM5) __HAL_RCC_TIM5_CLK_ENABLE();
else if (TIMx == TIM6) __HAL_RCC_TIM6_CLK_ENABLE();
else if (TIMx == TIM7) __HAL_RCC_TIM7_CLK_ENABLE();
else if (TIMx == TIM8) __HAL_RCC_TIM8_CLK_ENABLE();
// else if (TIMx == TIM9) __HAL_RCC_TIM9_CLK_ENABLE();
// else if (TIMx == TIM10) __HAL_RCC_TIM10_CLK_ENABLE();
// else if (TIMx == TIM11) __HAL_RCC_TIM11_CLK_ENABLE();
else if (TIMx == TIM12) __HAL_RCC_TIM12_CLK_ENABLE();
else if (TIMx == TIM13) __HAL_RCC_TIM13_CLK_ENABLE();
else if (TIMx == TIM14) __HAL_RCC_TIM14_CLK_ENABLE();
else if (TIMx == TIM15) __HAL_RCC_TIM15_CLK_ENABLE();
else if (TIMx == TIM16) __HAL_RCC_TIM16_CLK_ENABLE();
else if (TIMx == TIM17) __HAL_RCC_TIM17_CLK_ENABLE();
else
{
Error_Handler(__FILE__, __LINE__);
}
}
}
/*
*********************************************************************************************************
* : bsp_RCC_TIM_Disable
* : TIM RCC
* :
* : TIM外设时钟名
* : bsp_RCC_TIM_Disable
* : TIM RCC
* : TIMx TIM1 - TIM17
* : TIM外设时钟名
*********************************************************************************************************
*/
void bsp_RCC_TIM_Disable(TIM_TypeDef *TIMx)
void bsp_RCC_TIM_Disable(TIM_TypeDef* TIMx)
{
/*
APB1 TIM2, TIM3 ,TIM4, TIM5, TIM6, TIM7, TIM12, TIM13, TIM14
APB2 TIM1, TIM8 ,TIM9, TIM10, TIM11
APB2 TIM1, TIM8 , TIM15, TIM16TIM17
*/
if (TIMx == TIM1)
__HAL_RCC_TIM3_CLK_DISABLE();
else if (TIMx == TIM2)
__HAL_RCC_TIM2_CLK_DISABLE();
else if (TIMx == TIM3)
__HAL_RCC_TIM3_CLK_DISABLE();
else if (TIMx == TIM4)
__HAL_RCC_TIM4_CLK_DISABLE();
else if (TIMx == TIM5)
__HAL_RCC_TIM5_CLK_DISABLE();
else if (TIMx == TIM6)
__HAL_RCC_TIM6_CLK_DISABLE();
else if (TIMx == TIM7)
__HAL_RCC_TIM7_CLK_DISABLE();
else if (TIMx == TIM8)
__HAL_RCC_TIM8_CLK_DISABLE();
// else if (TIMx == TIM9) __HAL_RCC_TIM9_CLK_DISABLE();
// else if (TIMx == TIM10) __HAL_RCC_TIM10_CLK_DISABLE();
// else if (TIMx == TIM11) __HAL_RCC_TIM11_CLK_DISABLE();
else if (TIMx == TIM12)
__HAL_RCC_TIM12_CLK_DISABLE();
else if (TIMx == TIM13)
__HAL_RCC_TIM13_CLK_DISABLE();
else if (TIMx == TIM14)
__HAL_RCC_TIM14_CLK_DISABLE();
else if (TIMx == TIM15)
__HAL_RCC_TIM15_CLK_DISABLE();
else if (TIMx == TIM16)
__HAL_RCC_TIM16_CLK_DISABLE();
else if (TIMx == TIM17)
__HAL_RCC_TIM17_CLK_DISABLE();
if (TIMx == TIM1) __HAL_RCC_TIM3_CLK_DISABLE();
else if (TIMx == TIM2) __HAL_RCC_TIM2_CLK_DISABLE();
else if (TIMx == TIM3) __HAL_RCC_TIM3_CLK_DISABLE();
else if (TIMx == TIM4) __HAL_RCC_TIM4_CLK_DISABLE();
else if (TIMx == TIM5) __HAL_RCC_TIM5_CLK_DISABLE();
else if (TIMx == TIM6) __HAL_RCC_TIM6_CLK_DISABLE();
else if (TIMx == TIM7) __HAL_RCC_TIM7_CLK_DISABLE();
else if (TIMx == TIM8) __HAL_RCC_TIM8_CLK_DISABLE();
// else if (TIMx == TIM9) __HAL_RCC_TIM9_CLK_DISABLE();
// else if (TIMx == TIM10) __HAL_RCC_TIM10_CLK_DISABLE();
// else if (TIMx == TIM11) __HAL_RCC_TIM11_CLK_DISABLE();
else if (TIMx == TIM12) __HAL_RCC_TIM12_CLK_DISABLE();
else if (TIMx == TIM13) __HAL_RCC_TIM13_CLK_DISABLE();
else if (TIMx == TIM14) __HAL_RCC_TIM14_CLK_DISABLE();
else if (TIMx == TIM15) __HAL_RCC_TIM15_CLK_DISABLE();
else if (TIMx == TIM16) __HAL_RCC_TIM16_CLK_DISABLE();
else if (TIMx == TIM17) __HAL_RCC_TIM17_CLK_DISABLE();
else
{
Error_Handler(__FILE__, __LINE__);
@ -206,61 +167,49 @@ void bsp_RCC_TIM_Disable(TIM_TypeDef *TIMx)
/*
*********************************************************************************************************
* : bsp_GetAFofTIM
* : TIM AF寄存器配置
* :
* : AF寄存器配置
* : bsp_GetAFofTIM
* : TIM AF寄存器配置
* : TIMx TIM1 - TIM17
* : AF寄存器配置
*********************************************************************************************************
*/
uint8_t bsp_GetAFofTIM(TIM_TypeDef *TIMx)
uint8_t bsp_GetAFofTIM(TIM_TypeDef* TIMx)
{
uint8_t ret = 0;
if (TIMx == TIM1)
ret = GPIO_AF1_TIM1;
else if (TIMx == TIM2)
ret = GPIO_AF1_TIM2;
else if (TIMx == TIM3)
ret = GPIO_AF2_TIM3;
else if (TIMx == TIM4)
ret = GPIO_AF2_TIM4;
else if (TIMx == TIM5)
ret = GPIO_AF2_TIM5;
else if (TIMx == TIM8)
ret = GPIO_AF3_TIM8;
else if (TIMx == TIM12)
ret = GPIO_AF2_TIM12;
else if (TIMx == TIM13)
ret = GPIO_AF9_TIM13;
else if (TIMx == TIM14)
ret = GPIO_AF9_TIM14;
else if (TIMx == TIM15)
ret = GPIO_AF4_TIM15;
else if (TIMx == TIM16)
ret = GPIO_AF1_TIM16;
else if (TIMx == TIM17)
ret = GPIO_AF1_TIM17;
if (TIMx == TIM1) ret = GPIO_AF1_TIM1;
else if (TIMx == TIM2) ret = GPIO_AF1_TIM2;
else if (TIMx == TIM3) ret = GPIO_AF2_TIM3;
else if (TIMx == TIM4) ret = GPIO_AF2_TIM4;
else if (TIMx == TIM5) ret = GPIO_AF2_TIM5;
else if (TIMx == TIM8) ret = GPIO_AF3_TIM8;
else if (TIMx == TIM12) ret = GPIO_AF2_TIM12;
else if (TIMx == TIM13) ret = GPIO_AF9_TIM13;
else if (TIMx == TIM14) ret = GPIO_AF9_TIM14;
else if (TIMx == TIM15) ret = GPIO_AF4_TIM15;
else if (TIMx == TIM16) ret = GPIO_AF1_TIM16;
else if (TIMx == TIM17) ret = GPIO_AF1_TIM17;
else
{
Error_Handler(__FILE__, __LINE__);
}
return ret;
}
/*
*********************************************************************************************************
* : bsp_ConfigTimGpio
* : GPIO和TIM时钟 GPIO连接到TIM输出通道
* : GPIOx
* GPIO_PinX
* TIMx
* :
* : bsp_ConfigTimGpio
* : GPIO和TIM时钟 GPIO连接到TIM输出通道
* : GPIOx : GPIOA - GPIOK
* GPIO_PinX : GPIO_PIN_0 - GPIO__PIN_15
* TIMx : TIM1 - TIM17
* :
*********************************************************************************************************
*/
void bsp_ConfigTimGpio(GPIO_TypeDef *GPIOx, uint16_t GPIO_PinX, TIM_TypeDef *TIMx)
void bsp_ConfigTimGpio(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinX, TIM_TypeDef* TIMx)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
/* 使能GPIO时钟 */
bsp_RCC_GPIO_Enable(GPIOx);
@ -278,18 +227,18 @@ void bsp_ConfigTimGpio(GPIO_TypeDef *GPIOx, uint16_t GPIO_PinX, TIM_TypeDef *TIM
/*
*********************************************************************************************************
* : bsp_ConfigGpioOut
* : GPIO为推挽输出PWM输出0100
* : GPIOx
* GPIO_PinX
* :
* : bsp_ConfigGpioOut
* : GPIO为推挽输出PWM输出0100
* : GPIOx : GPIOA - GPIOK
* GPIO_PinX : GPIO_PIN_0 - GPIO__PIN_15
* :
*********************************************************************************************************
*/
void bsp_ConfigGpioOut(GPIO_TypeDef *GPIOx, uint16_t GPIO_PinX)
void bsp_ConfigGpioOut(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinX)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
bsp_RCC_GPIO_Enable(GPIOx); /* 使能GPIO时钟 */
bsp_RCC_GPIO_Enable(GPIOx); /* 使能GPIO时钟 */
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
@ -300,65 +249,73 @@ void bsp_ConfigGpioOut(GPIO_TypeDef *GPIOx, uint16_t GPIO_PinX)
/*
*********************************************************************************************************
* : bsp_SetTIMOutPWM
* : PWM信号的频率和占空比. 00GPIO输出0
* 0100%GPIO输出1.
* :
* GPIOx : GPIOA- GPIOK
* GPIO_Pin : GPIO_PIN_1 - GPIO__PIN_15
* TIMx : TIM1 - TIM14
* _ulFreq : PWM信号频率Hz ( 168M / 4 = 42M. 0
* _ulDutyCycle : PWM信号占空比: 500050.00%
* :
* : bsp_SetTIMOutPWM
* : PWM信号的频率和占空比. 00GPIO输出0
* 0100%GPIO输出1.
* : GPIOx : GPIOA - GPIOK
* GPIO_Pin : GPIO_PIN_0 - GPIO__PIN_15
* TIMx : TIM1 - TIM17
* _ucChannel使1 - 4
* _ulFreq : PWM信号频率Hz (100MHz0
* _ulDutyCycle : PWM信号占空比: 500050.00%
* :
*********************************************************************************************************
*/
void bsp_SetTIMOutPWM(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, TIM_TypeDef *TIMx, uint8_t _ucChannel,
uint32_t _ulFreq, uint32_t _ulDutyCycle)
void bsp_SetTIMOutPWM(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, TIM_TypeDef* TIMx, uint8_t _ucChannel,
uint32_t _ulFreq, uint32_t _ulDutyCycle)
{
TIM_HandleTypeDef TimHandle = {0};
TIM_OC_InitTypeDef sConfig = {0};
TIM_HandleTypeDef TimHandle = {0};
TIM_OC_InitTypeDef sConfig = {0};
uint16_t usPeriod;
uint16_t usPrescaler;
uint32_t pulse;
uint32_t uiTIMxCLK;
const uint16_t TimChannel[6 + 1] = {0, TIM_CHANNEL_1, TIM_CHANNEL_2, TIM_CHANNEL_3, TIM_CHANNEL_4, TIM_CHANNEL_5, TIM_CHANNEL_6};
const uint16_t TimChannel[6+1] = {0, TIM_CHANNEL_1, TIM_CHANNEL_2, TIM_CHANNEL_3, TIM_CHANNEL_4, TIM_CHANNEL_5, TIM_CHANNEL_6};
if (_ucChannel > 6)
{
Error_Handler(__FILE__, __LINE__);
}
if (_ulDutyCycle == 0)
{
//bsp_RCC_TIM_Disable(TIMx); /* 关闭TIM时钟, 可能影响其他通道 */
bsp_ConfigGpioOut(GPIOx, GPIO_Pin); /* 配置GPIO为推挽输出 */
GPIOx->BSRRH = GPIO_Pin; /* PWM = 0 */
{
//bsp_RCC_TIM_Disable(TIMx); /* 关闭TIM时钟, 可能影响其他通道 */
bsp_ConfigGpioOut(GPIOx, GPIO_Pin); /* 配置GPIO为推挽输出 */
GPIOx->BSRRH = GPIO_Pin; /* PWM = 0 */
return;
}
else if (_ulDutyCycle == 10000)
{
//bsp_RCC_TIM_Disable(TIMx); /* 关闭TIM时钟, 可能影响其他通道 */
bsp_ConfigGpioOut(GPIOx, GPIO_Pin); /* 配置GPIO为推挽输出 */
GPIOx->BSRRL = GPIO_Pin; /* PWM = 1*/
bsp_ConfigGpioOut(GPIOx, GPIO_Pin); /* 配置GPIO为推挽输出 */
GPIOx->BSRRL = GPIO_Pin; /* PWM = 1*/
return;
}
/* 下面是PWM输出 */
bsp_ConfigTimGpio(GPIOx, GPIO_Pin, TIMx); /* 使能GPIO和TIM时钟并连接TIM通道到GPIO */
bsp_ConfigTimGpio(GPIOx, GPIO_Pin, TIMx); /* 使能GPIO和TIM时钟并连接TIM通道到GPIO */
/*-----------------------------------------------------------------------
system_stm32f4xx.c void SetSysClock(void) :
bsp.c void SystemClock_Config(void) :
HCLK = SYSCLK / 1 (AHB1Periph)
PCLK2 = HCLK / 2 (APB2Periph)
PCLK1 = HCLK / 4 (APB1Periph)
System Clock source = PLL (HSE)
SYSCLK(Hz) = 400000000 (CPU Clock)
HCLK(Hz) = 200000000 (AXI and AHBs Clock)
AHB Prescaler = 2
D1 APB3 Prescaler = 2 (APB3 Clock 100MHz)
D2 APB1 Prescaler = 2 (APB1 Clock 100MHz)
D2 APB2 Prescaler = 2 (APB2 Clock 100MHz)
D3 APB4 Prescaler = 2 (APB4 Clock 100MHz)
APB1 prescaler != 1, APB1上的TIMxCLK = PCLK1 x 2 = SystemCoreClock / 2;
APB2 prescaler != 1, APB2上的TIMxCLK = PCLK2 x 2 = SystemCoreClock;
APB1 prescaler != 1, APB1上的TIMxCLK = APB1 x 2 = 200MHz;
APB2 prescaler != 1, APB2上的TIMxCLK = APB2 x 2 = 200MHz;
APB4上面的TIMxCLK没有分频100MHz;
APB1 TIM2, TIM3 ,TIM4, TIM5, TIM6, TIM7, TIM12, TIM13,TIM14
APB2 TIM1, TIM8 ,TIM15, TIM16, TIM17
APB1 TIM2, TIM3 ,TIM4, TIM5, TIM6, TIM7, TIM12, TIM13, TIM14LPTIM1
APB2 TIM1, TIM8 , TIM15, TIM16TIM17
APB4 LPTIM2LPTIM3LPTIM4LPTIM5
----------------------------------------------------------------------- */
if ((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM15) || (TIMx == TIM16) || (TIMx == TIM17))
@ -366,7 +323,7 @@ void bsp_SetTIMOutPWM(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, TIM_TypeDef *TIMx,
/* APB2 定时器时钟 = 200M */
uiTIMxCLK = SystemCoreClock / 2;
}
else
else
{
/* APB1 定时器 = 200M */
uiTIMxCLK = SystemCoreClock / 2;
@ -374,33 +331,30 @@ void bsp_SetTIMOutPWM(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, TIM_TypeDef *TIMx,
if (_ulFreq < 100)
{
usPrescaler = 10000 - 1; /* 分频比 = 10000 */
usPeriod = (uiTIMxCLK / 10000) / _ulFreq - 1; /* 自动重装的值 */
usPrescaler = 10000 - 1; /* 分频比 = 10000 */
usPeriod = (uiTIMxCLK / 10000) / _ulFreq - 1; /* 自动重装的值 */
}
else if (_ulFreq < 3000)
{
usPrescaler = 100 - 1; /* 分频比 = 100 */
usPeriod = (uiTIMxCLK / 100) / _ulFreq - 1; /* 自动重装的值 */
usPrescaler = 100 - 1; /* 分频比 = 100 */
usPeriod = (uiTIMxCLK / 100) / _ulFreq - 1; /* 自动重装的值 */
}
else /* 大于4K的频率无需分频 */
else /* 大于4K的频率无需分频 */
{
usPrescaler = 0; /* 分频比 = 1 */
usPrescaler = 0; /* 分频比 = 1 */
usPeriod = uiTIMxCLK / _ulFreq - 1; /* 自动重装的值 */
}
pulse = (_ulDutyCycle * usPeriod) / 10000;
HAL_TIM_PWM_DeInit(&TimHandle);
/* Initialize TIMx peripheral as follows:
+ Prescaler = (SystemCoreClock / (2*20000000)) - 1
+ Period = (1000 - 1)
+ ClockDivision = 0
+ Counter direction = Up
*/
/* PWM频率 = TIMxCLK / usPrescaler + 1/usPeriod + 1*/
TimHandle.Instance = TIMx;
TimHandle.Init.Prescaler = usPrescaler;
TimHandle.Init.Period = usPeriod;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.Prescaler = usPrescaler;
TimHandle.Init.Period = usPeriod;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.RepetitionCounter = 0;
TimHandle.Init.AutoReloadPreload = 0;
if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK)
@ -408,23 +362,22 @@ void bsp_SetTIMOutPWM(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, TIM_TypeDef *TIMx,
Error_Handler(__FILE__, __LINE__);
}
/*##-2- Configure the PWM channels #########################################*/
/* Common configuration for all channels */
sConfig.OCMode = TIM_OCMODE_PWM1;
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
/* 配置定时器PWM输出通道 */
sConfig.OCMode = TIM_OCMODE_PWM1;
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
/* Set the pulse value for channel */
/* 占空比 */
sConfig.Pulse = pulse;
if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TimChannel[_ucChannel]) != HAL_OK)
{
Error_Handler(__FILE__, __LINE__);
}
/* Start channel */
/* 启动PWM输出 */
if (HAL_TIM_PWM_Start(&TimHandle, TimChannel[_ucChannel]) != HAL_OK)
{
Error_Handler(__FILE__, __LINE__);
@ -433,54 +386,63 @@ void bsp_SetTIMOutPWM(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, TIM_TypeDef *TIMx,
/*
*********************************************************************************************************
* : bsp_SetTIMforInt
* : TIM和NVIC.
* : TIMx :
* _ulFreq : Hz 0
* _PreemptionPriority :
* _SubPriority :
* :
* : bsp_SetTIMforInt
* : TIM和NVIC
* : TIMx :
* _ulFreq : Hz 0
* _PreemptionPriority :
* _SubPriority :
* :
*********************************************************************************************************
*/
/* TIM定时中断服务程序范例必须清中断标志
void TIM3_IRQHandler(void)
/*
TIM定时中断服务程序范例
void TIM6_DAC_IRQHandler(void)
{
TIM3->SR = ~ (uint32_t)TIM_IT_UPDATE;
HC574_TogglePin(GPIO_PIN_23);
if((TIM6->SR & TIM_FLAG_UPDATE) != RESET)
{
TIM6->SR = ~ TIM_FLAG_UPDATE;
//添加用户代码
}
}
*/
void bsp_SetTIMforInt(TIM_TypeDef *TIMx, uint32_t _ulFreq, uint8_t _PreemptionPriority, uint8_t _SubPriority)
void bsp_SetTIMforInt(TIM_TypeDef* TIMx, uint32_t _ulFreq, uint8_t _PreemptionPriority, uint8_t _SubPriority)
{
TIM_HandleTypeDef TimHandle;
TIM_HandleTypeDef TimHandle = {0};
uint16_t usPeriod;
uint16_t usPrescaler;
uint32_t uiTIMxCLK;
/* 使能TIM时钟 */
bsp_RCC_TIM_Enable(TIMx);
/*-----------------------------------------------------------------------
system_stm32f4xx.c void SetSysClock(void) :
bsp.c void SystemClock_Config(void) :
HCLK = SYSCLK / 1 (AHB1Periph)
PCLK2 = HCLK / 2 (APB2Periph)
PCLK1 = HCLK / 4 (APB1Periph)
System Clock source = PLL (HSE)
SYSCLK(Hz) = 400000000 (CPU Clock)
HCLK(Hz) = 200000000 (AXI and AHBs Clock)
AHB Prescaler = 2
D1 APB3 Prescaler = 2 (APB3 Clock 100MHz)
D2 APB1 Prescaler = 2 (APB1 Clock 100MHz)
D2 APB2 Prescaler = 2 (APB2 Clock 100MHz)
D3 APB4 Prescaler = 2 (APB4 Clock 100MHz)
APB1 prescaler != 1, APB1上的TIMxCLK = PCLK1 x 2 = SystemCoreClock / 2;
APB2 prescaler != 1, APB2上的TIMxCLK = PCLK2 x 2 = SystemCoreClock;
APB1 prescaler != 1, APB1上的TIMxCLK = APB1 x 2 = 200MHz;
APB2 prescaler != 1, APB2上的TIMxCLK = APB2 x 2 = 200MHz;
APB4上面的TIMxCLK没有分频100MHz;
APB1 TIM2, TIM3 ,TIM4, TIM5, TIM6, TIM7, TIM12, TIM13,TIM14
APB2 TIM1, TIM8 ,TIM15, TIM16, TIM17
APB1 TIM2, TIM3 ,TIM4, TIM5, TIM6, TIM7, TIM12, TIM13, TIM14LPTIM1
APB2 TIM1, TIM8 , TIM15, TIM16TIM17
APB4 LPTIM2LPTIM3LPTIM4LPTIM5
----------------------------------------------------------------------- */
if ((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM15) || (TIMx == TIM16) || (TIMx == TIM17))
{
/* APB2 定时器时钟 = 200M */
uiTIMxCLK = SystemCoreClock / 2;
}
else
else
{
/* APB1 定时器 = 200M */
uiTIMxCLK = SystemCoreClock / 2;
@ -488,31 +450,28 @@ void bsp_SetTIMforInt(TIM_TypeDef *TIMx, uint32_t _ulFreq, uint8_t _PreemptionPr
if (_ulFreq < 100)
{
usPrescaler = 10000 - 1; /* 分频比 = 10000 */
usPeriod = (uiTIMxCLK / 10000) / _ulFreq - 1; /* 自动重装的值 */
usPrescaler = 10000 - 1; /* 分频比 = 10000 */
usPeriod = (uiTIMxCLK / 10000) / _ulFreq - 1; /* 自动重装的值 */
}
else if (_ulFreq < 3000)
{
usPrescaler = 100 - 1; /* 分频比 = 100 */
usPeriod = (uiTIMxCLK / 100) / _ulFreq - 1; /* 自动重装的值 */
usPrescaler = 100 - 1; /* 分频比 = 100 */
usPeriod = (uiTIMxCLK / 100) / _ulFreq - 1; /* 自动重装的值 */
}
else /* 大于4K的频率无需分频 */
else /* 大于4K的频率无需分频 */
{
usPrescaler = 0; /* 分频比 = 1 */
usPrescaler = 0; /* 分频比 = 1 */
usPeriod = uiTIMxCLK / _ulFreq - 1; /* 自动重装的值 */
}
/* Initialize TIMx peripheral as follows:
+ Prescaler = (SystemCoreClock / (2*20000000)) - 1
+ Period = (1000 - 1)
+ ClockDivision = 0
+ Counter direction = Up
/*
= TIMxCLK / usPrescaler + 1/usPeriod + 1
*/
TimHandle.Instance = TIMx;
TimHandle.Init.Prescaler = usPrescaler;
TimHandle.Init.Period = usPeriod / 2; /* 除以2才是正确频率 */
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.Prescaler = usPrescaler;
TimHandle.Init.Period = usPeriod;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.RepetitionCounter = 0;
TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&TimHandle) != HAL_OK)
@ -520,49 +479,36 @@ void bsp_SetTIMforInt(TIM_TypeDef *TIMx, uint32_t _ulFreq, uint8_t _PreemptionPr
Error_Handler(__FILE__, __LINE__);
}
/* TIM Interrupts enable */
/* 使能定时器中断 */
__HAL_TIM_ENABLE_IT(&TimHandle, TIM_IT_UPDATE);
/* 配置TIM定时更新中断 (Update) */
{
uint8_t irq = 0; /* 中断号, 定义在 stm32f4xx.h */
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 == TIM16)
irq = TIM17_IRQn;
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_SetPriority((IRQn_Type)irq, _PreemptionPriority, _SubPriority);
HAL_NVIC_EnableIRQ((IRQn_Type)irq);
HAL_NVIC_EnableIRQ((IRQn_Type)irq);
}
HAL_TIM_Base_Start(&TimHandle);
}

View File

@ -89,7 +89,7 @@ static void bsp_SoftTimerDec(SOFT_TMR *_tmr);
*********************************************************************************************************
* : bsp_InitTimer
* : systick中断
* :
* :
* :
*********************************************************************************************************
*/
@ -109,7 +109,7 @@ void bsp_InitTimer(void)
/*
systic中断周期为1mssystick中断
SystemCoreClock STM32F4XX, 168MHz
SystemCoreClock STM32H7, 400MHz
SysTick_Config() Systick定时中断.
-- SystemCoreClock / 1000 1000Hz 1ms
@ -180,7 +180,7 @@ void SysTick_ISR(void)
*********************************************************************************************************
* : bsp_SoftTimerDec
* : 1ms对所有定时器变量减1SysTick_ISR周期性调用
* : _tmr :
* : _tmr :
* :
*********************************************************************************************************
*/
@ -247,7 +247,7 @@ void bsp_DelayMS(uint32_t n)
*********************************************************************************************************
* : bsp_DelayUS
* : us级延迟 systick定时器启动后才能调用此函数
* : n : 1 us
* : n : 1 us
* :
*********************************************************************************************************
*/
@ -295,8 +295,8 @@ void bsp_DelayUS(uint32_t n)
*********************************************************************************************************
* : bsp_StartTimer
* :
* : _id : ID0,TMR_COUNT-1IDID冲突
* _period : 1ms
* : _id : ID0,TMR_COUNT-1IDID冲突
* _period : 1ms
* :
*********************************************************************************************************
*/
@ -306,8 +306,7 @@ void bsp_StartTimer(uint8_t _id, uint32_t _period)
{
/* 打印出错的源代码文件名、函数名称 */
BSP_Printf("Error: file %s, function %s()\r\n", __FILE__, __FUNCTION__);
while (1)
; /* 参数异常,死机等待看门狗复位 */
while (1); /* 参数异常,死机等待看门狗复位 */
}
DISABLE_INT(); /* 关中断 */
@ -324,8 +323,8 @@ void bsp_StartTimer(uint8_t _id, uint32_t _period)
*********************************************************************************************************
* : bsp_StartAutoTimer
* :
* : _id : ID0,TMR_COUNT-1IDID冲突
* _period : 10ms
* : _id : ID0,TMR_COUNT-1IDID冲突
* _period : 10ms
* :
*********************************************************************************************************
*/
@ -363,8 +362,7 @@ void bsp_StopTimer(uint8_t _id)
{
/* 打印出错的源代码文件名、函数名称 */
BSP_Printf("Error: file %s, function %s()\r\n", __FILE__, __FUNCTION__);
while (1)
; /* 参数异常,死机等待看门狗复位 */
while (1); /* 参数异常,死机等待看门狗复位 */
}
DISABLE_INT(); /* 关中断 */
@ -380,8 +378,8 @@ void bsp_StopTimer(uint8_t _id)
*********************************************************************************************************
* : bsp_CheckTimer
* :
* : _id : ID0,TMR_COUNT-1IDID冲突
* _period : 1ms
* : _id : ID0,TMR_COUNT-1IDID冲突
* _period : 1ms
* : 0 1
*********************************************************************************************************
*/
@ -438,8 +436,8 @@ int32_t bsp_CheckRunTime(int32_t _LastTime)
int32_t time_diff;
DISABLE_INT(); /* 关中断 */
now_time = g_iRunTime; /* 这个变量在Systick中断中被改写因此需要关中断进行保护 */
ENABLE_INT(); /* 开中断 */
now_time = g_iRunTime; /* 这个变量在Systick中断中被改写因此需要关中断进行保护 */
ENABLE_INT(); /* 开中断 */
if (now_time >= _LastTime)
{
@ -457,7 +455,7 @@ int32_t bsp_CheckRunTime(int32_t _LastTime)
*********************************************************************************************************
* : bsp_DelayNS
* : us级延迟 systick定时器启动后才能调用此函数
* : n : NS
* : n : NS
* :
*********************************************************************************************************
*/
@ -541,26 +539,34 @@ void SysTick_Handler(void)
*/
void bsp_InitHardTimer(void)
{
TIM_HandleTypeDef TimHandle;
TIM_HandleTypeDef TimHandle = {0};
uint32_t usPeriod;
uint16_t usPrescaler;
uint32_t uiTIMxCLK;
TIM_TypeDef *TIMx = TIM_HARD;
RCC_TIM_HARD_CLK_ENABLE(); /* 使能TIM时钟 */
TIM_TypeDef* TIMx = TIM_HARD;
RCC_TIM_HARD_CLK_ENABLE(); /* 使能TIM时钟 */
/*-----------------------------------------------------------------------
system_stm32f4xx.c void SetSysClock(void) :
bsp.c void SystemClock_Config(void) :
HCLK = SYSCLK / 1 (AHB1Periph)
PCLK2 = HCLK / 2 (APB2Periph)
PCLK1 = HCLK / 4 (APB1Periph)
System Clock source = PLL (HSE)
SYSCLK(Hz) = 400000000 (CPU Clock)
HCLK(Hz) = 200000000 (AXI and AHBs Clock)
AHB Prescaler = 2
D1 APB3 Prescaler = 2 (APB3 Clock 100MHz)
D2 APB1 Prescaler = 2 (APB1 Clock 100MHz)
D2 APB2 Prescaler = 2 (APB2 Clock 100MHz)
D3 APB4 Prescaler = 2 (APB4 Clock 100MHz)
APB1 prescaler != 1, APB1上的TIMxCLK = PCLK1 x 2 = SystemCoreClock / 2;
APB2 prescaler != 1, APB2上的TIMxCLK = PCLK2 x 2 = SystemCoreClock;
APB1 prescaler != 1, APB1上的TIMxCLK = APB1 x 2 = 200MHz;
APB2 prescaler != 1, APB2上的TIMxCLK = APB2 x 2 = 200MHz;
APB4上面的TIMxCLK没有分频100MHz;
APB1 TIM2, TIM3 ,TIM4, TIM5, TIM6, TIM7, TIM12, TIM13,TIM14
APB2 TIM1, TIM8 ,TIM15, TIM16, TIM17
APB1 TIM2, TIM3 ,TIM4, TIM5, TIM6, TIM7, TIM12, TIM13, TIM14LPTIM1
APB2 TIM1, TIM8 , TIM15, TIM16TIM17
APB4 LPTIM2LPTIM3LPTIM4LPTIM5
----------------------------------------------------------------------- */
if ((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM15) || (TIMx == TIM16) || (TIMx == TIM17))
@ -568,116 +574,106 @@ void bsp_InitHardTimer(void)
/* APB2 定时器时钟 = 200M */
uiTIMxCLK = SystemCoreClock / 2;
}
else
else
{
/* APB1 定时器 = 200M */
uiTIMxCLK = SystemCoreClock / 2;
}
usPrescaler = uiTIMxCLK / 1000000 - 1; /* 分频比 = 1 */
// if (TIMx == TIM2 || TIMx == TIM5) H743 无需特殊处理
// {
// usPeriod = 0xFFFFFFFF;
// }
// else
usPrescaler = uiTIMxCLK / 1000000 - 1; /* 分频比 = 1 */
if (TIMx == TIM2 || TIMx == TIM5)
{
usPeriod = 0xFFFFFFFF;
}
else
{
usPeriod = 0xFFFF;
}
/* Initialize TIMx peripheral as follows:
+ Prescaler = (SystemCoreClock / (2*20000000)) - 1
+ Period = (1000 - 1)
+ ClockDivision = 0
+ Counter direction = Up
/*
usPrescaler后11us
usPeriod的值是决定了最大计数
usPeriod = 0xFFFF 0xFFFF
usPeriod = 0xFFFFFFFF 0xFFFFFFFF
*/
TimHandle.Instance = TIMx;
TimHandle.Init.Prescaler = usPrescaler;
TimHandle.Init.Period = usPeriod;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.Prescaler = usPrescaler;
TimHandle.Init.Period = usPeriod;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.RepetitionCounter = 0;
TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&TimHandle) != HAL_OK)
{
Error_Handler(__FILE__, __LINE__);
}
/* 配置TIM定时更新中断 (Update) */
/* 配置定时器中断给CC捕获比较中断使用 */
{
HAL_NVIC_SetPriority(TIM_HARD_IRQn, 0, 2);
HAL_NVIC_EnableIRQ(TIM_HARD_IRQn);
HAL_NVIC_EnableIRQ(TIM_HARD_IRQn);
}
/* 启动定时器 */
HAL_TIM_Base_Start(&TimHandle);
}
/*
*********************************************************************************************************
* : bsp_StartHardTimer
* : 使TIM2-5使, 4
* 1us
* : bsp_StartHardTimer
* : 使TIM2-5使, 4
* 1us
* TIM2和TIM5 32
* TIM3和TIM4 16
* : _CC : 123, 4
* _uiTimeOut : , 1us. 16 65.5ms; 32 4294
* : _CC : 123, 4
* _uiTimeOut : , 1us. 16 65.5ms; 32 4294
* _pCallBack :
* :
* :
*********************************************************************************************************
*/
void bsp_StartHardTimer(uint8_t _CC, uint32_t _uiTimeOut, void *_pCallBack)
{
uint16_t cnt_now;
uint16_t cnt_tar;
TIM_TypeDef *TIMx = TIM_HARD;
/*
H743速度太快1us
407 = 18us (IO翻转)
bsp_StartTimer2(3, 500, (void *)test1);
*/
// if (_uiTimeOut < 1)
// {
// ;
// }
// else
// {
// _uiTimeOut -= 5; 5 for F407
// }
cnt_now = (uint16_t)TIMx->CNT; /* 读取当前的计数器值 CNT实际只有16bit */
cnt_tar = cnt_now + _uiTimeOut; /* 计算捕获的计数器值 */
uint32_t cnt_now;
uint32_t cnt_tar;
TIM_TypeDef* TIMx = TIM_HARD;
/* H743速度较快无需补偿延迟实测精度正负1us */
cnt_now = TIMx->CNT;
cnt_tar = cnt_now + _uiTimeOut; /* 计算捕获的计数器值 */
if (_CC == 1)
{
s_TIM_CallBack1 = (void (*)(void))_pCallBack;
TIMx->CCR1 = cnt_tar; //TIM_SetCompare1(TIM_HARD, cnt_tar); /* 设置捕获比较计数器CC1 */
TIMx->SR = (uint16_t)~TIM_IT_CC1; //TIM_ClearITPendingBit(TIM_HARD, TIM_IT_CC1);
TIMx->DIER |= TIM_IT_CC1; //TIM_ITConfig(TIM_HARD, TIM_IT_CC1, ENABLE); /* 使能CC1中断 */
TIMx->CCR1 = cnt_tar; /* 设置捕获比较计数器CC1 */
TIMx->SR = (uint16_t)~TIM_IT_CC1; /* 清除CC1中断标志 */
TIMx->DIER |= TIM_IT_CC1; /* 使能CC1中断 */
}
else if (_CC == 2)
{
s_TIM_CallBack2 = (void (*)(void))_pCallBack;
TIMx->CCR2 = cnt_tar; /* 设置捕获比较计数器CC2 */
TIMx->SR = (uint16_t)~TIM_IT_CC2;
TIMx->DIER |= TIM_IT_CC2; /* 使能CC2中断 */
TIMx->CCR2 = cnt_tar; /* 设置捕获比较计数器CC2 */
TIMx->SR = (uint16_t)~TIM_IT_CC2; /* 清除CC2中断标志 */
TIMx->DIER |= TIM_IT_CC2; /* 使能CC2中断 */
}
else if (_CC == 3)
{
s_TIM_CallBack3 = (void (*)(void))_pCallBack;
TIMx->CCR3 = cnt_tar; /* 设置捕获比较计数器CC3 */
TIMx->SR = (uint16_t)~TIM_IT_CC3;
TIMx->DIER |= TIM_IT_CC3; /* 使能CC3中断 */
TIMx->CCR3 = cnt_tar; /* 设置捕获比较计数器CC3 */
TIMx->SR = (uint16_t)~TIM_IT_CC3; /* 清除CC3中断标志 */
TIMx->DIER |= TIM_IT_CC3; /* 使能CC3中断 */
}
else if (_CC == 4)
{
s_TIM_CallBack4 = (void (*)(void))_pCallBack;
TIMx->CCR4 = cnt_tar; /* 设置捕获比较计数器CC3 */
TIMx->SR = (uint16_t)~TIM_IT_CC4;
TIMx->DIER |= TIM_IT_CC4; /* 使能CC4中断 */
TIMx->CCR4 = cnt_tar; /* 设置捕获比较计数器CC4 */
TIMx->SR = (uint16_t)~TIM_IT_CC4; /* 清除CC4中断标志 */
TIMx->DIER |= TIM_IT_CC4; /* 使能CC4中断 */
}
else
{
@ -689,7 +685,7 @@ void bsp_StartHardTimer(uint8_t _CC, uint32_t _uiTimeOut, void *_pCallBack)
*********************************************************************************************************
* : TIMx_IRQHandler
* : TIM
*
* :
* :
*********************************************************************************************************
*/

View File

@ -26,108 +26,108 @@
#include "bsp.h"
/* 串口1的GPIO PA9, PA10 RS323 DB9接口 */
#define USART1_CLK_ENABLE() __HAL_RCC_USART1_CLK_ENABLE()
#define USART1_CLK_ENABLE() __HAL_RCC_USART1_CLK_ENABLE()
#define USART1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART1_TX_GPIO_PORT GPIOA
#define USART1_TX_PIN GPIO_PIN_9
#define USART1_TX_AF GPIO_AF7_USART1
#define USART1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART1_TX_GPIO_PORT GPIOA
#define USART1_TX_PIN GPIO_PIN_9
#define USART1_TX_AF GPIO_AF7_USART1
#define USART1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART1_RX_GPIO_PORT GPIOA
#define USART1_RX_PIN GPIO_PIN_10
#define USART1_RX_AF GPIO_AF7_USART1
#define USART1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART1_RX_GPIO_PORT GPIOA
#define USART1_RX_PIN GPIO_PIN_10
#define USART1_RX_AF GPIO_AF7_USART1
/* 串口2的GPIO --- PA2 PA3 GPS (只用RX。 TX被以太网占用 */
#define USART2_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE()
#define USART2_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE()
#define USART2_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART2_TX_GPIO_PORT GPIOA
#define USART2_TX_PIN GPIO_PIN_2
#define USART2_TX_AF GPIO_AF7_USART2
#define USART2_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART2_TX_GPIO_PORT GPIOA
#define USART2_TX_PIN GPIO_PIN_2
#define USART2_TX_AF GPIO_AF7_USART2
#define USART2_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART2_RX_GPIO_PORT GPIOA
#define USART2_RX_PIN GPIO_PIN_3
#define USART2_RX_AF GPIO_AF7_USART2
#define USART2_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART2_RX_GPIO_PORT GPIOA
#define USART2_RX_PIN GPIO_PIN_3
#define USART2_RX_AF GPIO_AF7_USART2
/* 串口3的GPIO --- PB10 PB11 RS485 */
#define USART3_CLK_ENABLE() __HAL_RCC_USART3_CLK_ENABLE()
#define USART3_CLK_ENABLE() __HAL_RCC_USART3_CLK_ENABLE()
#define USART3_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define USART3_TX_GPIO_PORT GPIOB
#define USART3_TX_PIN GPIO_PIN_10
#define USART3_TX_AF GPIO_AF7_USART3
#define USART3_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define USART3_TX_GPIO_PORT GPIOB
#define USART3_TX_PIN GPIO_PIN_10
#define USART3_TX_AF GPIO_AF7_USART3
#define USART3_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define USART3_RX_GPIO_PORT GPIOB
#define USART3_RX_PIN GPIO_PIN_11
#define USART3_RX_AF GPIO_AF7_USART3
#define USART3_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define USART3_RX_GPIO_PORT GPIOB
#define USART3_RX_PIN GPIO_PIN_11
#define USART3_RX_AF GPIO_AF7_USART3
/* 串口4的GPIO --- PH13 PH14 */
#define UART4_CLK_ENABLE() __HAL_RCC_UART4_CLK_ENABLE()
#define UART4_CLK_ENABLE() __HAL_RCC_UART4_CLK_ENABLE()
#define UART4_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define UART4_TX_GPIO_PORT GPIOH
#define UART4_TX_PIN GPIO_PIN_13
#define UART4_TX_AF GPIO_AF8_UART4
#define UART4_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define UART4_TX_GPIO_PORT GPIOH
#define UART4_TX_PIN GPIO_PIN_13
#define UART4_TX_AF GPIO_AF8_UART4
#define UART4_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define UART4_RX_GPIO_PORT GPIOH
#define UART4_RX_PIN GPIO_PIN_14
#define UART4_RX_AF GPIO_AF8_UART4
#define UART4_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define UART4_RX_GPIO_PORT GPIOH
#define UART4_RX_PIN GPIO_PIN_14
#define UART4_RX_AF GPIO_AF8_UART4
/* 串口5的GPIO --- PC12/UART5_TX PD2/UART5_RX (被SD卡占用 */
#define UART5_CLK_ENABLE() __HAL_RCC_UART5_CLK_ENABLE()
#define UART5_CLK_ENABLE() __HAL_RCC_UART5_CLK_ENABLE()
#define UART5_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define UART5_TX_GPIO_PORT GPIOC
#define UART5_TX_PIN GPIO_PIN_12
#define UART5_TX_AF GPIO_AF8_UART5
#define UART5_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define UART5_TX_GPIO_PORT GPIOC
#define UART5_TX_PIN GPIO_PIN_12
#define UART5_TX_AF GPIO_AF8_UART5
#define UART5_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define UART5_RX_GPIO_PORT GPIOD
#define UART5_RX_PIN GPIO_PIN_2
#define UART5_RX_AF GPIO_AF8_UART5
#define UART5_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define UART5_RX_GPIO_PORT GPIOD
#define UART5_RX_PIN GPIO_PIN_2
#define UART5_RX_AF GPIO_AF8_UART5
/* 串口6的GPIO --- PG14 PC7 GPRS */
#define USART6_CLK_ENABLE() __HAL_RCC_USART6_CLK_ENABLE()
#define USART6_CLK_ENABLE() __HAL_RCC_USART6_CLK_ENABLE()
#define USART6_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define USART6_TX_GPIO_PORT GPIOG
#define USART6_TX_PIN GPIO_PIN_14
#define USART6_TX_AF GPIO_AF7_USART6
#define USART6_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define USART6_TX_GPIO_PORT GPIOG
#define USART6_TX_PIN GPIO_PIN_14
#define USART6_TX_AF GPIO_AF7_USART6
#define USART6_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define USART6_RX_GPIO_PORT GPIOC
#define USART6_RX_PIN GPIO_PIN_7
#define USART6_RX_AF GPIO_AF7_USART6
#define USART6_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define USART6_RX_GPIO_PORT GPIOC
#define USART6_RX_PIN GPIO_PIN_7
#define USART6_RX_AF GPIO_AF7_USART6
/* 串口7的GPIO --- PA15 PA8 */
#define UART7_CLK_ENABLE() __HAL_RCC_UART7_CLK_ENABLE()
#define UART7_CLK_ENABLE() __HAL_RCC_UART7_CLK_ENABLE()
#define UART7_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define UART7_TX_GPIO_PORT GPIOA
#define UART7_TX_PIN GPIO_PIN_15
#define UART7_TX_AF GPIO_AF11_UART7
#define UART7_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define UART7_TX_GPIO_PORT GPIOA
#define UART7_TX_PIN GPIO_PIN_15
#define UART7_TX_AF GPIO_AF11_UART7
#define UART7_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define UART7_RX_GPIO_PORT GPIOA
#define UART7_RX_PIN GPIO_PIN_8
#define UART7_RX_AF GPIO_AF11_UART7
#define UART7_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define UART7_RX_GPIO_PORT GPIOA
#define UART7_RX_PIN GPIO_PIN_8
#define UART7_RX_AF GPIO_AF11_UART7
/* 串口8的GPIO --- PB4/UART7_TX, PB3/UART7_RX (被SPI3 占用) */
#define UART8_CLK_ENABLE() __HAL_RCC_UART8_CLK_ENABLE()
#define UART8_CLK_ENABLE() __HAL_RCC_UART8_CLK_ENABLE()
#define UART8_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOJ_CLK_ENABLE()
#define UART8_TX_GPIO_PORT GPIOJ
#define UART8_TX_PIN GPIO_PIN_8
#define UART8_TX_AF GPIO_AF8_UART8
#define UART8_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOJ_CLK_ENABLE()
#define UART8_TX_GPIO_PORT GPIOJ
#define UART8_TX_PIN GPIO_PIN_8
#define UART8_TX_AF GPIO_AF8_UART8
#define UART8_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOJ_CLK_ENABLE()
#define UART8_RX_GPIO_PORT GPIOJ
#define UART8_RX_PIN GPIO_PIN_9
#define UART8_RX_AF GPIO_AF8_UART8
#define UART8_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOJ_CLK_ENABLE()
#define UART8_RX_GPIO_PORT GPIOJ
#define UART8_RX_PIN GPIO_PIN_9
#define UART8_RX_AF GPIO_AF8_UART8
/* 定义每个串口结构体变量 */
#if UART1_FIFO_EN == 1
@ -803,7 +803,7 @@ static void UartVarInit(void)
*/
void bsp_SetUartParam(USART_TypeDef *Instance, uint32_t BaudRate, uint32_t Parity, uint32_t Mode)
{
UART_HandleTypeDef UartHandle;
UART_HandleTypeDef UartHandle = {0};
/* 第2步 配置串口硬件参数 */
/*##-1- Configure the UART peripheral ######################################*/

View File

@ -1246,6 +1246,12 @@ unsigned char const g_Hz16[] = {
0xC8,0xDD, 0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x88,0x24,0x11,0x10,0x22,0x88,0x04,0x40,// 容 //
0x08,0x20,0x30,0x18,0xDF,0xF6,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,
0xBD,0xC5, 0x01,0x00,0x79,0x00,0x49,0x1E,0x4B,0x92,0x49,0x12,0x79,0x12,0x49,0x12,0x4F,0xD2,// 脚 //
0x49,0x12,0x79,0x12,0x4A,0x1A,0x4A,0x94,0x4F,0xD0,0x4A,0x50,0x48,0x10,0x98,0x10,
0xCF,0xDE, 0x00,0x00,0x7B,0xF8,0x4A,0x08,0x52,0x08,0x53,0xF8,0x62,0x08,0x52,0x08,0x4B,0xF8,// 限 //
0x4A,0x44,0x4A,0x48,0x6A,0x30,0x52,0x20,0x42,0x10,0x42,0x88,0x43,0x06,0x42,0x00,
/* 最后一行必须用0xFF,0xFF结束这是字库数组结束标志 */
0xFF,0xFF

View File

@ -431,6 +431,31 @@ unsigned char const g_Hz24[] = {
0x8C,0x61,0x80,0x0C,0x61,0x80,0x0C,0x43,0xC0,0x0C,0xC6,0x60,0x0C,0x8C,0x38,0x0D,
0x30,0x1F,0x0E,0x40,0x0C,0x08,0x00,0x00,
0xBF,0xD8, 0x08,0x06,0x00,0x0E,0x03,0x00,0x0C,0x01,0x80,0x0C,0x21,0x0C,0x0C,0x3F,0xFE,0x0D,// 控 //
0x60,0x0C,0x7F,0x60,0x10,0x0C,0x48,0x40,0x0C,0x0E,0x30,0x0C,0x98,0x18,0x0D,0x30,
0x0C,0x0E,0x20,0x06,0x1C,0x40,0x04,0x7C,0x80,0x30,0x2C,0x7F,0xF8,0x0C,0x03,0x00,
0x0C,0x03,0x00,0x0C,0x03,0x00,0x0C,0x03,0x00,0x0C,0x03,0x00,0x0C,0x03,0x0C,0x7C,
0xFF,0xFE,0x18,0x00,0x00,0x10,0x00,0x00,
0xCE,0xA2, 0x04,0x20,0x40,0x06,0x38,0x70,0x0C,0x30,0x60,0x0D,0x32,0x60,0x19,0xB2,0xC0,0x11,// 微 //
0x32,0xC0,0x21,0x32,0x84,0x49,0x32,0xFE,0x0D,0xFF,0x98,0x0C,0x01,0x18,0x18,0x04,
0x98,0x19,0xFE,0x98,0x38,0x00,0x98,0x38,0x8C,0x90,0x58,0xFE,0xB0,0x98,0xCC,0x70,
0x18,0xCC,0x60,0x18,0xCC,0x60,0x18,0xCD,0xE0,0x19,0x8E,0xF0,0x19,0x9D,0x98,0x1B,
0x09,0x1C,0x1A,0x02,0x0F,0x14,0x04,0x04,
0xD0,0xCD, 0x00,0x00,0x10,0x00,0x30,0x1C,0x3F,0xF9,0x18,0x0C,0x61,0xD8,0x0C,0x61,0x98,0x0C,// 型 //
0x61,0x98,0x0C,0x61,0x98,0x0C,0x69,0x98,0x7F,0xFD,0x98,0x0C,0x61,0x98,0x0C,0x61,
0x98,0x0C,0x61,0x18,0x18,0x60,0x18,0x18,0x60,0xF8,0x30,0x50,0x30,0x40,0x1C,0x00,
0x00,0x18,0x30,0x1F,0xFF,0xF8,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x18,0x0C,0x7F,
0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
0xD4,0xB4, 0x00,0x00,0x00,0x30,0x80,0x0C,0x18,0xFF,0xFE,0x0C,0xC1,0x00,0x08,0xC1,0x80,0x00,// 源 //
0xC9,0x18,0x00,0xCF,0xFC,0x60,0xCC,0x18,0x32,0xCC,0x18,0x1A,0xCF,0xF8,0x12,0xCC,
0x18,0x04,0xCC,0x18,0x04,0xCF,0xF8,0x08,0xC9,0x90,0x18,0xC1,0x80,0x78,0xC9,0xA0,
0x19,0x8D,0x98,0x19,0x99,0x8C,0x19,0x99,0x8E,0x1B,0x31,0x86,0x1B,0x61,0x84,0x1A,
0x8F,0x80,0x0C,0x03,0x00,0x00,0x02,0x00,
/* 最后一行必须用0xFF,0xFF结束这是字库数组结束标志 */
0xFF,0xFF

View File

@ -130,7 +130,6 @@ static int lua_GpioWrite(lua_State* L)
static int lua_GpioRead(lua_State* L)
{
uint8_t _no;
uint8_t _value;
if (lua_type(L, 1) == LUA_TNUMBER) /* 判断第1个参数 */
{

View File

@ -6,8 +6,6 @@
#include "lua_if.h"
#include "bsp.h"
static int lua_udp_print(lua_State* L);
void lua_tim_RegisterFun(void)
{
//将指定的函数注册为Lua的全局函数变量其中第一个字符串参数为Lua代码