stm32使用自定义打点函数方式移植stemwin
2024-05-22 03:34:29
stm32使用自定义打点函数方式移植stemwin
- 背景
- 显示过程
- 移植简述
- 打点函数
- stemwin移植要点
- 实物效果
背景
- oled屏移植stemwin,有两种方式,通过自定义打点方式进行移植,或使用stemwin自带驱动库函数移植。
- 使用自带驱动库移植过程中,发现stemwin在emwin基础上进行了"缩水"。
- emwin支持oled屏的GUIDRV_Spage驱动移植,但最新的stemwin544版本并不支持GUIDRV_Spage驱动,只能采用自定义打点方式移植。
显示过程
- 通过显存的方式进行显示:
打点函数定义显存,打点、读点函数;
stemwin负责更改显存内存;
spi负责将显存内存送至oled进行显示;
移植简述
- 打点函数:
定义显存,unsigned char disbuff[8][128],共128*64个点;
写自定义打点、读点函数; - stemwin移植(仅要点):
stm32移植stemwin(自定义打点方式); - spi(略):
stm32与oled屏使用spi通信,刷新时间点送显存内容到oled;
打点函数
oled.c
uint8_t s_ucGRAM[8][128];/*
*********************************************************************************************************
* 函 数 名: OLED_PutPixel
* 功能说明: 画1个像素
* 形 参:
* _usX,_usY : 像素坐标
* _ucColor :像素颜色
* 返 回 值: 无
*********************************************************************************************************
*/
void OLED_PutPixel(uint16_t _usX, uint16_t _usY, uint8_t _ucColor)
{uint8_t ucValue;uint8_t ucPageAddr;uint8_t ucColAddr;const uint8_t aOrTab[8] = {0x01, 0x02, 0x04, 0x08,0x10,0x20,0x40,0x80};const uint8_t aAndTab[8] = {0xFE, 0xFD, 0xFB, 0xF7,0xEF,0xDF,0xBF,0x7F};ucPageAddr = _usY / 8; //计算横坐标地址属于哪一页ucColAddr = _usX; //列地址ucValue = s_ucGRAM[ucPageAddr][ucColAddr]; //获取显存中这一字节的数据if (_ucColor == 0) //该点不显显示{ucValue &= aAndTab[_usY % 8]; //将该字节对应位清零}else{ucValue |= aOrTab[_usY % 8]; //该点对应位置位}s_ucGRAM[ucPageAddr][ucColAddr] = ucValue; //更新显存
}/*
*********************************************************************************************************
* 函 数 名: OLED_GetPixel
* 功能说明: 读取1个像素
* 形 参:
* _usX,_usY : 像素坐标
* 返 回 值: 颜色值 (0, 1)
*********************************************************************************************************
*/
uint8_t OLED_GetPixel(uint16_t _usX, uint16_t _usY)
{uint8_t ucValue;uint8_t ucPageAddr;uint8_t ucColAddr;ucPageAddr = _usY / 8;ucColAddr = _usX;ucValue = s_ucGRAM[ucPageAddr][ucColAddr];if (ucValue & (_usY % 8)){return 1;}else{return 0;}
}
oled.h
#ifndef __OLED_H
#define __OLED_H #include "stm32f10x.h"void OLED_PutPixel(uint16_t _usX, uint16_t _usY, uint8_t _ucColor) ; // 画1个像素
uint8_t OLED_GetPixel(uint16_t _usX, uint16_t _usY); // 读1个像素#endif
stemwin移植要点
- iar工程文件使能crc模块
- Config文件夹下删除LCDConf_Lin_Template.c、LCDConf_Lin_Template.h,更改LCDConf_FlexColor_Template.h为LCDConf.h
- Lib文件夹下仅保留STemWin532_CM4_IAR.a(官网下载),或仅保留
- 添加内部延时函数,
stm32f4xx_it.c
#include "GUI.h" //新增
extern volatile GUI_TIMER_TIME OS_TimeMS; //新增
void SysTick_Handler(void)
{HAL_IncTick();OS_TimeMS++; //新增
}
- stemwin增加打点、读点函数,共修改三处,
GUIDRV_Template.c
#include "oled.h" //添加自己驱动的头文件
/*********************************************************************
*
* _SetPixelIndex
*
* Purpose:
* Sets the index of the given pixel. The upper layers
* calling this routine make sure that the coordinates are in range, so
* that no check on the parameters needs to be performed.
*/
static void _SetPixelIndex(GUI_DEVICE * pDevice, int x, int y, int PixelIndex) {//// Convert logical into physical coordinates (Dep. on LCDConf.h)//#if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)int xPhys, yPhys;xPhys = LOG2PHYS_X(x, y);yPhys = LOG2PHYS_Y(x, y);#else#define xPhys x#define yPhys y#endifGUI_USE_PARA(pDevice);GUI_USE_PARA(x);GUI_USE_PARA(y);GUI_USE_PARA(PixelIndex);{//修改1:插入自己的画点函数OLED_PutPixel(x,y,PixelIndex);}#if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)#undef xPhys#undef yPhys#endif
}
/*********************************************************************
*
* _GetPixelIndex
*
* Purpose:
* Returns the index of the given pixel. The upper layers
* calling this routine make sure that the coordinates are in range, so
* that no check on the parameters needs to be performed.
*/
static unsigned int _GetPixelIndex(GUI_DEVICE * pDevice, int x, int y) {unsigned int PixelIndex;//// Convert logical into physical coordinates (Dep. on LCDConf.h)//#if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)int xPhys, yPhys;xPhys = LOG2PHYS_X(x, y);yPhys = LOG2PHYS_Y(x, y);#else#define xPhys x#define yPhys y#endifGUI_USE_PARA(pDevice);GUI_USE_PARA(x);GUI_USE_PARA(y);{//插入自己的读点函数PixelIndex = OLED_GetPixel(x,y);}#if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)#undef xPhys#undef yPhys#endifreturn PixelIndex;
}/*********************************************************************
** _GetDevData
*/
static void * _GetDevData(GUI_DEVICE * pDevice, int Index) {GUI_USE_PARA(pDevice);#if GUI_SUPPORT_MEMDEVswitch (Index) {case LCD_DEVDATA_MEMDEV://return (void *)&GUI_MEMDEV_DEVICE_16; return (void *)&GUI_MEMDEV_DEVICE_1; //将16改为1}#elseGUI_USE_PARA(Index);#endifreturn NULL;
}
- stemwin选择移植方式为自定义打点,
GUIDRV_FlexColor.c
#define XSIZE_PHYS 128 // 屏幕宽度
#define YSIZE_PHYS 64 // 高度
#define VXSIZE_PHYS 128 // 虚拟内存宽度
#define VYSIZE_PHYS 64 // 虚拟内存高度
/*********************************************************************
** LCD_X_Config* * Function description:* Called during the initialization process in order to set up the* display driver configuration.* */
void LCD_X_Config(void)
{//GUI_DEVICE_CreateAndLink(GUIDRV_FLEXCOLOR, GUICC_565, 0, 0);//采用设备自己定义初始化 单色屏幕,其余的写寄存器 写数据 连续读 连续写的操作都是基于彩屏或者其他驱动芯片的,直接删除就可以否则GUI会初始化失败GUI_DEVICE_CreateAndLink(GUIDRV_TEMPLATE, GUICC_1, 0, 0);LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);
}
- stemwin修改内存分配,
GUIConfig.c
#define GUI_NUMBYTES (1024*30)
- stemwin修改不必要的支持,
GUIConfig.h
#define GUI_SUPPORT_TOUCH (0) //新增,在"#ifndef GUI_SUPPORT_TOUCH"语句之前
#define GUI_SUPPORT_MOUSE (0) //修改
#define GUI_SUPPORT_MEMDEV (0) //修改
- iar堆栈大小修改,iar工程文件右键"options"->“linker”->“Config”->“Edit”->"Stack/Head
Size"中,CSTACK修改为0xA000 - 主程序进行测试,
main.c
int main()
{...... //初始化TNS_G12864FGDISW_60W_Init(); //spi初始化;发送显示初始化命令GUI_Init();GUI_DispString("1234"); //更改显存数据DispWriteData(); //将显存写入oledwhile(1){}
}
实物效果
stm32使用自定义打点函数方式移植stemwin相关推荐
- EntityFramework Core 2.0自定义标量函数两种方式
前言 上一节我们讲完原始查询如何防止SQL注入问题同时并提供了几种方式.本节我们继续来讲讲EF Core 2.0中的新特性自定义标量函数. 自定义标量函数两种方式 在EF Core 2.0中我们可以将 ...
- STM32移植STemwin
一.准备基础程序 基于正点原子stm32战舰开发板的移植 1. 正点原子程序下载: 资料盘 战舰 开发板资料A盘: https://pan.baidu.com/s/1qZgG-UAznhQWg ...
- 9.STM32中对SysTick_Init()函数(sysTick_Config()、TimingDelay_Decrement()自定义)和Delay_us()的理解
STM32中对SysTick_Init()函数(sysTick_Config().TimingDelay_Decrement()自定义)和Delay_us()的理解: 实验:3个LED灯以500ms的 ...
- 7.STM32中对DMA_Config()函数的理解(自定义)测试DMA传输数据时CPU还可继续工作其他的事
STM32中对DMA_Config()函数的理解(自定义):
- 3.STM32中对EXTI_PE5_Config()函数的理解(自定义)之中断控制按键LED
STM32中对EXTI_PE5_Config()函数的理解(自定义)
- 2.STM32中对Key_GPIO_Config()函数的理解(自定义)之轮询控制按键LED
STM32中对Key_GPIO_Config()函数的理解(自定义)
- 1.STM32中对LED_GPIO_Config()函数的理解(自定义)之流水灯
STM32中对LED_GPIO_Config()函数的理解(自定义)
- 8.STM32中对ADC1_Config()函数(ADC1_GPIO_Config()和ADC1_Mode_Config())的理解(自定义)测试ADC转换电压值输出到终端上。
STM32中对ADC1_Config()函数(ADC1_GPIO_Config()和ADC1_Mode_Config())的理解:
- 4.STM32中对USART1_Config()函数的理解(自定义)
STM32中对USART1_Config()函数的理解
最新文章
- matlab loopcount,求助一个数值积分问题,用matlab的quadgk函数来计算,谢谢!
- linux常见紧急情况处理
- python天天向上的力量三天打鱼两天晒网_017 示例3-天天向上的力量-Go语言中文社区...
- leetcode题解108-将有序数组转换为二叉排序树
- 使用ssh公钥密钥自动登陆linux服务器
- mysql grant 用户权限总结
- 消息队列的介绍及配置
- Day11:麦卡锡91函数(McCarthy 91)
- bootstrap按钮组btn-group
- VS Code配置C/C++环境
- ArcGIS应用基础1 数据显示、查询及可视化
- 线性代数 计算机网络,计算机应用、计算机网络专业《线性代数》课程.doc
- OSG入门即osgEarth建立一个地球的详细步骤
- 零基础入门FPGA,如何学习?
- android复制粘贴功能
- 2007年3月12日
- 我愿为这二极管奉献我的一生
- 人岗精确匹配算法比赛
- JavaScript中join方法用法
- python爬取豆瓣书籍_Python爬虫-爬取豆瓣图书Top250