Bear Pie Huawei IoT operating system LiteOS bare metal driver transplantation 02-LCD driver transplantation and use
[Copy link]
1. LCD bare metal driver
The LCD screen used by the Bear Pi development board is a 1.3-inch TFT color screen with a color depth of 16 bits and a resolution of 240*240. It uses the SPI interface to communicate with the MCU.
2. Transplant LCD bare metal driver to LiteOS
Copy bare metal driver file to LiteOS project
The underlying layer of LCD is driven by SPI. In addition to the spi.h and spi.c files generated by STM32CubeMX, you also need to write the driver files for the LCD screen by hand.
When copying files, follow the instructions in the previous article to copy spi.h to the Inc folder, copy spi.c to the Src folder, and then copy the self-written driver files lcd.c, lcd.h and font file font.h to the Hardware folder.
The default project provided in IoT-Studio has already copied these files, so there is no need to add them again, as shown in the figure:
Add driver file path
Because the entire LiteOS project is built using make, after copying the driver file, you need to add the driver file path to the makefile and add it to the compilation.
The project.mk file specifies the paths of all files in the project:
In this file:
- C file path
- HARDWARE_SRC: corresponds to the Src folder under the Hardware folder
- USER_SRC: corresponds to the Src folder
- Header file path
- HARDWARE_INC: corresponds to the Inc folder under the Hardware folder
- USER_INC: corresponds to the Inc folder
As shown below, the underlying SPI interface code spi.c of the LCD driver is added to USER_SRC:
The low-level SPI interface code spi.h of the LCD driver is added to USER_INC:
The SPI-driven LCD screen driver file lcd.c is added to HARDWARE_SRC:
The SPI-driven LCD screen driver header file lcd.h and font file font.h are added to HARDWARE_INC:
At this point, copy the file to the LiteOS project, add the newly copied file path to the makefile, add the project to compile, and the driver porting is complete.
3. Use LCD bare metal driver
to initialize LCD
In the previous article, two ways to initialize the device in LiteOS were described in detail:
- Initialize before the system starts scheduling: the device can be used by any task in the system at any time
- Initialize in a task: The device is generally only used in this task
The LCD device transplanted in this article does not require a dedicated task to operate the LCD, so it should be initialized before the system starts, and then each task can operate the LCD device for display.
Add LCD initialization code in the HardWare_Init() function in main.c:
In order not to affect the subsequent experiments, the default character display code in the project is commented out:
Operating LCD
Next, create a folder ( if it already exists, you don’t need to create it again ) to store the code for this series of tutorial experiments:
Create a file in that folder:
Write the code:
#include <osal.h>
#include <lcd.h>
static int lcd_demo_entry()
{
//Test display characters
POINT_COLOR = BLUE;
LCD_ShowString(0, 0, 240, 32, 32, "Welcome To IoT");
POINT_COLOR = RED;
LCD_ShowString(0, 32, 240, 24, 24, "I am BearPi");
POINT_COLOR = BLACK;
LCD_ShowString(0, 56, 240, 16, 16, "LCD Test...");
POINT_COLOR = GREEN;
LCD_ShowString(0, 72, 240, 12, 12, "Powerd by Huawei LiteOS!");
//Test to draw a rectangle
POINT_COLOR = BLUE;
LCD_DrawRectangle(20, 100, 120, 200);
//Test drawing circle
POINT_COLOR = RED;
LCD_Draw_Circle(180, 150, 50);
return 0;
}
int standard_app_demo_main()
{
osal_task_create("lcd_demo",lcd_demo_entry,NULL,0x400,NULL,2);
return 0;
}
Then follow the previous method, add the lcd_driver_demo.c file to the makefile in user_demo.mk and add compilation:
Finally, configure the macro definition in .sdkconfig :
Compile and burn, and you can see the display on the LCD screen:
Follow the WeChat public account of "Xiaoxiongpai Open Source Community" and reply "LiteOS Internal Core Practice" to obtain the actual source code.
Xiaoxiongpai Open Source Community focuses on sharing cutting-edge technologies such as IoT, AI, and 5G. Follow the WeChat public account of "Xiaoxiongpai Open Source Community" to obtain more information and tutorials.
---------------------------------END-----------------------------------------
|