repaper / gratis

EPD Source codes and Documentation
238 stars 132 forks source link

spi_ioc_transfer needs to be initialized in SPI_send and SPI_read #17

Closed photonthunder closed 9 years ago

photonthunder commented 9 years ago

In spi.c, SPI_send and SPI_read don't initialize all the elements of spi_ioc_transfer which caused problems (epdTest: SPI: send failure: Invalid argument) on my SAMA5D3 Xplained board. Need to add the following lines:

transfer_buffer.pad = 0; transfer_buffer.tx_nbits = 0; transfer._buffer.rx_nbits = 0;

A better solution would be to initialize the structure as follows:

struct spi_ioc_transfer transfer = {
    .tx_buf = (unsigned long)(buffer),
    .rx_buf = 0,
    .len = length,
    .delay_usecs = 2,
    .speed_hz = spi-bps,
    .bits_per_word = 8,
    .cs_change = 1,
};
hxw commented 9 years ago

Would you try to see if the above fix is sufficent?

I don't have that particular boaard; so only checked on Raspberry Pi and Beaglebone Black.

photonthunder commented 9 years ago

Works for me, I did have to change .cs_change = 0 for this board to the the channel select to work. Probably just related to a kernel feature not completely implemented on this board.

hxw commented 9 years ago

change cs_change to zero, seems ok on BB and RPi. I expect this is for when there are multiple transfers in a single IOCTL, perhaps for using a fragmented buffer. Since I only ever do single blocks it shoul be ok to use zero.

hxw commented 9 years ago

I'll leave them(BB/RPi) running for a couple of days and if still ok I'll close this issue.

hxw commented 9 years ago

no problems detected - closed issue