我正在使用提供的 pyA13 0.2.2 SPI 驱动程序对我的 A13-OLinuXino-MICRO 进行编程,以将数据发送到 LCD。理想情况下,我想发送一个包含 320*240*2(320*240 像素,每种颜色 16 位)字节的列表,以便在一个连续写入命令中写入,以提高速度效率。 spi.c 和 spi_lib.c 中的驱动程序有一个 8 位 tx_len ,这将我限制为 256 个字节,因此我将它们修改为 32 位,这可以工作,但现在当我尝试在我的列表中传递长度超过 4096 个值的列表时,我收到错误spi.write(data[:]) 函数。下面是我用来用 16 位纯色填充屏幕的代码:
def FillScreen(c):
LCD_SetPos(0, 0, 239, 319)
ch = c>>8 & 0x00FF
cl = c & 0x00FF
d =[]
for x in range (0,76800):
d += [ch, cl]
spi.write(d[:])
这是我运行该函数时遇到的错误:
Traceback (most recent call last):
File "lcd.py", line 205, in <module>
FillScreen(0x00FF)
File "lcd.py", line 200, in FillScreen
spi.write(d[:])
IOError: [Errno 90] Message too long
给我这个错误的代码片段包含在 spi.c 中
/* Send data */
if(spi_write(fd, tx_buffer, tx_len) < 0){
return PyErr_SetFromErrno(PyExc_IOError);
}
有什么方法可以将更长的消息传递给 spi.write 函数吗?我对 python 很陌生,但对 C 很熟悉,请简单地编写我的代码...另外,我尝试循环较小的消息来填充屏幕,但这需要太长时间。任何帮助将不胜感激。
谢谢, 迈克尔
查看 Linux spidev 文档中的注释 - https://www.kernel.org/doc/Documentation/spi/spidev:
- There's a limit on the number of bytes each I/O request can transfer to the SPI device. It defaults to one page, but that can be changed using a module parameter.
(您可以使用
$ getconf PAGESIZE
找出页面大小 - 我相信它几乎总是 4096 字节。)
我还没有测试过,但我认为Maxim在这里的答案应该适合你:https://stackoverflow.com/a/16440226/5527382,即:
解决方案是将以下行添加到/etc/modprobe.d/local.conf:
options spidev bufsiz=<NEEDED BUFFER SIZE>
spidev 驱动程序默认为 4096 字节,然后使用该参数的值(如果提供)覆盖它 - https://github.com/beagleboard/linux/blob/4.1/drivers/spi/spidev.c#L92-L94 :
static unsigned bufsiz = 4096;
module_param(bufsiz, uint, S_IRUGO);
MODULE_PARM_DESC(bufsiz, "data bytes in biggest supported SPI message");
将该行放入
/etc/modprobe.d/local.conf
应在加载时将该参数传递给 spidev 模块 - 进行更改后您需要重新启动以确保已重新加载它。
我找到了一个似乎对我有用的解决方案,因为我不知道如何添加 Alex Haim 描述的“选项”方法。相反,我编写了一个 bash 脚本来编辑 /sys/module/spidev/parameters/bufsiz 文件
#!/bin/bash
# Spi Bufsiz Script
cd /sys/module/spidev/parameters
chmod 666 bufsiz
echo 65534 > bufsiz
这个解决方案是在这里找到的。