欢迎来到我司Viking代理产品网站!
一个值得学习的LCD驱动器框架
Viking代理 2024-04-19

今天,我看到了由哥哥Xiao Yao分享的一篇文章:[体系结构]如何在嵌入式编程中对代码结构进行分层,提到了高内聚,低耦合,软件分层等概念。

以前,一个小伙伴在后台留下了一条消息,告诉我分享这样的文章,所以今天就在这里!废话不多,讲太多理论是没有道理的。

这些规则的本质是基于与面向对象设计模式有关的一些理论。

设计模式是一组易于使用的前辈,他们发现了一些规则并在实践中进行了总结。

框架,让我们直接运送干货,坚硬的肝脏!以Cubs提供的SPI OLED驱动程序为例。

我们将对原始开发套件中的LCD驱动器进行一些简单的转换。

然后根据需求设计以下驱动程序模型框架,分为三个部分:模型,驱动程序和设备。

考虑到过于详细的内容,一开始并不会使其变得特别复杂,不利于理解,因此我们构建了以下框架思维导图:1. LCD驱动程序框架数据结构框架提供哪些功能?这就是我的操作方式,非常简单:这是将驱动程序框架与驱动程序连接的能力,& amp; lcd_driver获得了在驱动程序文件中定义的已分配结构lcd_driver,因此当我进入“定义变量”时LCD_Driver_Model的位置,然后将此变量与驱动器结构连接,以便您可以使用此变量来操作驱动器结构中的接口。

2. LCD驱动器数据结构LCD驱动器数据结构要做的是提供一个用于操作LCD驱动器功能的接口。

该接口的设计与硬件无关。

如上一节所述,驱动程序框架取决于驱动程序接口。

在这种情况下,我们需要在驱动程序接口中实现该方法。

在相应的方法中,我们需要调用与LCD设备相关的接口来操作LCD设备。

以下是与该接口对应的实现:3. LCD设备数据结构LCD设备需要做的是将该数据结构中的功能功能与实际的LCD驱动器接口相连。

例如,让我们看一下LCD_Init接口的实现。

这是实际调用LCD的实际硬件操作:4.如何使用int& nbmain; & nbsp;& nbsp;& nbsp; / *& nbsp; USER  USER& nbsp ; CODEBEGIN& nbsp; * / & nbsp;& nbsp;& nbsp; LCD_Driver_Model& nbsp;& nbsp; lcd_model& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp; nbsp; LCD_Ascii_Show_Para& nbsp; ascii_para []  =& nbsp;& nbsp;& nbsp;& nbsp; {& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp; ;& nbsp;& nbsp; {80,& nbsp; 100,& nbsp; 240-80,“ RED”,& nbsp; BLACK,& nbsp; RED,& nbsp ; 32},& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp; {80,& nbsp; 100,& nbsp; 240 -80,“ GREEN”,“黑色”,“ GREEN”和“ 32”,& nbsp;& nbsp;& nbsp;& nbsp;& nbsp ;& nbsp; {80,& nbsp; 100,& nbsp; 240-80,“ BLUE”,& nbsp; BLACK,& nbsp; BLUE,& nbsp; 32}, & nbsp;& nbsp;& nbsp;};& ; nbsp; LCD_Fill_Para& nbsp; fill_para []& nbsp; =& nbsp;& nbsp;& nbsp; {& nbsp;& nbsp;& nbsp; {ascii_para [0]。

x,ascii_para [0] .max_width,ascii_para [0] .y,ascii_para [0] .y + 32},& nbsp;& nbsp; {ascii_para [1] .x,ascii_para [1] .max_width,ascii_para [1] .y,ascii_para [1] .y + 32},& nbsp;& nbsp;& nbsp; {ascii_para [2]。

x,ascii_para [2] .max_width,ascii_para [2] .y,as cii_para [2] .y + 32},& nbsp;}& nbsp ;;& nbsp;& nbsp;& amp; ; nbsp; / *& nbsp; USER& nbsp; CODE& nbsp; END& nbsp; 1& nbsp; * /& nbsp;& nbsp;& nbsp;& nbsp; / * * ; nbsp; MCU& nbsp;配置------------------------------------------ --- ----------- * /& nbsp;& nbsp;& nbsp; / *& nbsp;重置& nbsp; all& nbsp;全部 外围设备,并初始化Flash和界面接口以及Systick。

* // nbsp;和/ nbsp;                    & nbsp; HAL_Init();& nbsp;& nbsp;& nbsp; / *& nbsp; USER& nbsp; CODE& nbsp; BEGIN& nbsp; Init& nbsp; * /& nbsp;& nbsp;& nbsp; / *& nbsp; USER& nbsp; CODE& nbsp; END& nbsp; Init& nbsp; * /& nbsp;& nbsp;& nbsp;  & nb sp; / *& nbsp;配置& nbsp;系统& nbsp; clock& nbsp; * /& nbsp;& nbsp;& nbsp;& nbsp; SystemClock_Config();  & nbsp;& nbsp; / *& nbsp;用户  CODE& nbsp; BEGIN& nbsp; SysInit& nbsp; * /& nbsp;& nbsp;& nbsp;& n nbsp; / *& nbsp; USER& nbsp; CODE& nbsp;