记录一下利用树莓派3B驱动ST778V显示用户桌面的问题。
最开始是用香橙派orangepi one驱动ST7789V的,但是一直没成功,最后放弃了,改用树莓派3B驱动。
参考的例程是微雪官方的文档https://www.waveshare.net/wiki/1.3inch_LCD_Module,
可以根据自己的屏幕尺寸进行修改,我的屏幕是在网上买的,商家说的是2.4寸,分辨率是240*320的。我按照这个教程,修改了一些参数,之后发现屏幕有反应,但是无图像显示,一片空白。
微雪的文档中提供了测试例程
sudo apt-get install unzip -y
sudo wget https://www.waveshare.net/w/upload/8/8d/LCD_Module_RPI_code.zip
sudo unzip ./LCD_Module_RPI_code.zip
cd LCD_Module_RPI_code/RaspberryPi/
cd c
sudo make clean
sudo make -j 8
sudo ./main 2.4 //我的屏幕尺寸是2.4寸
这个测试例程是完全没有问题的,但是显示的颜色好像不太对
最后参考了另一位博主的文章,解决了问题https://blog.csdn.net/u010280030/article/details/146280843?spm=1001.2014.3001.5502
LCD_2IN4_WriteData_Byte(0x55);
LCD_2IN4_Write_Command(0x36); // Memory Access Control
LCD_2IN4_WriteData_Byte(0x08);
LCD_2IN4_Write_Command(0x21); //添加0x21命令
LCD_2IN4_Write_Command(0xB1);
具体的得去参考ST7789V的手册了,这是修改后的效果
最后就是显示树莓派桌面了,这个参照微雪的文档做就行了,但是有一个问题,我的屏幕明明是2.4寸的,按照文档执行
sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH4_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 ..
屏幕是无显示的,但是有反应,就是屏幕会息屏,然后点击鼠标,屏幕又会点亮。最后突发奇想执行了另外的命令
sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 ..
然后就成功了,用2寸屏幕的命令点亮了2.4.寸的屏幕,搞不懂为什么。
但是还有一个问题,这个显示颜色好像还是反色的,还是跟初始化代码有关?最后看了源码后,在Waveshare_fbcp/src/config下面有一个config.h,打开后找到#define DISPLAY_INVERT_COLORS,发现这个宏定义是被注释掉的,而在st7789.cpp文件中,可以看见
#ifdef ST7789
//SPI_TRANSFER(0xBA/*DGMEN: Enable Gamma*/, 0x04);
bool invertColors = true;
#else
bool invertColors = false;
#endif
#ifdef DISPLAY_INVERT_COLORS
invertColors = !invertColors;
#endif
if (invertColors)
SPI_TRANSFER(0x21 /*Display Inversion On*/);
else
SPI_TRANSFER(0x20 /*Display Inversion Off*/);
SPI_TRANSFER(0x13 /*NORON: Partial off (normal)*/);
usleep(10 * 1000);
这里定义的是ST7789,而我用的屏幕芯片是ST7789V,invertColors默认应该是false,如果没有定义DISPLAY_INVERT_COLORS,执行的是SPI_TRANSFER(0x20);所以,将注释的#define DISPLAY_INVERT_COLORS恢复,然后在重新编译和运行就正常了。
mkdir build
cd build
cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 .. //这里用2寸屏幕的,不知道为啥
sudo make -j
sudo ./fbcp
其他的开机启动的,参考微雪的文档操作就可以了。
更新
在运行sudo ./fbcp的时候,树莓派可能会报错
pi@raspberrypi:~/myfiles/Waveshare_fbcp/build $ sudo ./fbcp
bcm_host_get_peripheral_address: 0x3f000000, bcm_host_get_peripheral_size: 16777216, bcm_host_get_sdram_address: 0xc0000000
BCM core speed: current: 250000000hz, max turbo: 400000000hz. SPI CDIV: 20, SPI max frequency: 20000000hz
Allocated DMA channel 7
Allocated DMA channel 1
Enabling DMA channels Tx:7 and Rx:1
DMA hardware register file is at ptr: 0x75cab000, using DMA TX channel: 7 and DMA RX channel: 1
DMA hardware TX channel register file is at ptr: 0x75cab700, DMA RX channel register file is at ptr: 0x75cab100
DMA RX channel 1 was assigned another peripheral map 5!
DMA channel 0 has peripheral map 0 (is lite channel: 0, currently active: 0, current control block: (nil))
DMA channel 1 has peripheral map 5 (is lite channel: 0, currently active: 1, current control block: 0xff4ce620)
DMA channel 2 has peripheral map 11 (is lite channel: 0, currently active: 1, current control block: (nil))
DMA channel 3 has peripheral map 17 (is lite channel: 0, currently active: 1, current control block: (nil))
DMA channel 4 has peripheral map 13 (is lite channel: 0, currently active: 1, current control block: (nil))
DMA channel 5 has peripheral map 0 (is lite channel: 0, currently active: 0, current control block: (nil))
DMA channel 6 has peripheral map 13 (is lite channel: 0, currently active: 1, current control block: (nil))
DMA channel 7 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 8 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 9 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 10 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 11 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 12 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 13 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA channel 14 has peripheral map 0 (is lite channel: 1, currently active: 0, current control block: (nil))
DMA RX channel was assigned another peripheral map!
大概意思是说DMA被占用,导致冲突了,只需要将树莓派的配置文件/boot/config.txt中的dtparam=audio=on给注释掉就可以了。