When writing an SPI protocol decoder, almost every higher-level PD has to internally keep track of the CS status, buffer up the individual bytes as they are received, and then interpret them when CS becomes deasserted. I feel that writing SPI-attached PDs would be simpler if the SPI decoder itself would perform this basic step for them. Currently it has two types of data output: BITS [list of [bitvalue, ss, es] * 2] * 2 DATA bytevalue * 2 I'd like to propose a new type, called perhaps "TRANSFER", whose contents are the full byte-wise collection of DATA bytes to cover the entire CS transaction. Thus, where currently it outputs e.g. ['CS-CHANGE', 1, 0] ['DATA', 0x10, 0xff] at times ss=100, es=110 ['DATA', 0x23, 0xff] at times ss=111, es=121 ['CS-CHANGE', 0, 1] I'd like to add a new single extra item that looks like: ['TRANSFER', [[0x10, 100, 110], [0x23, 111, 121]], [[0xff, 100, 110], [0xff, 111, 121]]] That is, data1 relates to MISO and data2 relates to MOSI as with DATA, but the value in each is a list of elements, each element being a [bytevalue, ss, es] triple. This structure would make it much simpler to write most SPI-based PDs.
(FTR I'm quite happy to implement this and provide a patch; I'm just asking first if that's a good idea to :) )
An initial attempt at implementing this can now be found at: https://github.com/leonerd/libsigrokdecode/compare/spi-transfer
Created attachment 183 [details] Code simplification to 'max7219' PD
Attached above is the patch of simplification to my (proposed) max7219 PD that having a TRANSFER packet type allows. It removes a few lines of logic, but moreover requires a lot less "stateful" handling within the PD; it just gets invoked once on the TRANSFER packet and inspects things entirely through local variables. Crucially, it removes having to store stateful things on the PD itself. This alone is surely a useful improvement.
The feature got implemented in 8c90d7bdf21f. Can the report get closed?
The feature has been in mainline since 2015-11-22.