gpt4 book ai didi

Python IOError : [Errno 90] Message too long, 将长列表传递给 SPI 函数

转载 作者:太空宇宙 更新时间:2023-11-04 04:33:13 24 4
gpt4 key购买 nike

我正在为我的 A13-OLinuXino-MICRO 编程使用提供的 pyA13 0.2.2 SPI 驱动程序将数据发送到 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 ,即:

The solution is to add following lines to /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 模块 - 您需要在进行更改后重新启动以确保您已重新加载它。

关于Python IOError : [Errno 90] Message too long, 将长列表传递给 SPI 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33791995/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com