我使用提供的 A13-OLinuXino-MICRO SPI驱动程序对pyA13 0.2.2进行编程,以便将数据发送到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非常熟悉,请轻松使用我的代码...此外,我已经尝试循环较小的消息来填充屏幕,但这需要太长时间。任何帮助将不胜感激。
谢谢, 迈克尔
答案 0 :(得分:0)
请查看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模块 - 当你加载它时 - 你需要在进行更改后重新启动以确保重新加载它
答案 1 :(得分:0)
我找到了一个似乎对我有用的解决方案,因为我无法弄清楚如何添加Alex Haim描述的'options'方法。相反,我编写了一个编辑/ sys / module / spidev / parameters / bufsiz文件的bash脚本
#!/bin/bash
# Spi Bufsiz Script
cd /sys/module/spidev/parameters
chmod 666 bufsiz
echo 65534 > bufsiz
找到此解决方案here。