Hi all,

I'm drawing arbitrary rectangles pixels to a display using SPI (just the part of the display that is updated). The position and size of the rect could be anything.
From looking at reference code, most of the pixels (except the last ) are written using writeData16, and the last pixel is written using writeData16_last.
The dilemma is that this adds complexity to the code, because I either have to:
Code:
BEGIN SPI TRANSACTION
FOR EACH PIXEL{
    IF (LAST PIXEL) writeData16_last( PIXEL )
    ELSE writeData16( PIXEL )
}
END SPI TRANSACTION
or
Code:
BEGIN SPI TRANSACTION
FOR EACH LINE OF PIXELS EXCEPT THE LAST LINE{
    FOR EACH PIXEL IN THE LINE{
        writeData16( PIXEL )
    }
}
FOR EACH PIXEL IN THE LAST LINE, EXCEPT THE LAST PIXEL{
    writeData16( PIXEL )
}
writeData16_last( LAST PIXEL IN LAST LINE )
END SPI TRANSACTION
The first one is slow as there is a comparison on every pixel.
The second one is complex because the last line and then last pixel need dedicated code.

I'm wondering if there is another way? Any ideas? Perhaps something like:

Code:
BEGIN SPI TRANSACTION
FOR EACH PIXEL{
    writeData16( PIXEL )
}
writeData16_last( NOOP )
END SPI TRANSACTION
Cheers,
Peter