Hello everyone,
Never mind, turned out its not that complicated to count bits manually. An
example is attached.
And here is a screenshot:
https://afiskon.ru/s/70/61b22f6692_temp.png
On Sun, May 6, 2018 at 2:15 AM, Aleksander Alekseev <afis...@gmail.com>
wrote:
> Hello,
>
> I'm working on a decoder for ST7735 TFT display controller. You can find a
> draft of the decoder in the attachment. Currently it doesn't do much.
>
> The protocol of ST7735 is based on SPI, but it also uses one additional
> pin, DC, to distinguish data and commands. This is quite a common practice,
> SSD1306 and compatible controllers do this as well.
>
> Unfortunately I didn't find a way to combine input for my decoder from
> different sources - in this case from spi and logic. Naturally I could just
> write a decoder that wouldn't rely on spi decoder, but I would like to
> avoid counting bits (which is already implemented in spi decoder) if
> possible.
>
> Here is how protocol looks like:
>
> https://afiskon.ru/s/06/845b982943_temp.png
>
> On the screenshot you can see the command 0x2A which if followed 3 data
> bytes: 0x00, 0x02, 0x00. Note how CS and DC are changing. Ignoring DC is
> not an option in this case since data length is varying for some commands.
> Also I can't rely on CS since it can be changed after sending every byte.
>
> How would you suggest to solve this issue?
>
> --
> Best regards,
> Aleksander Alekseev
>
--
Best regards,
Aleksander Alekseev
## vim: set ai et ts=4 sw=4:
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2018 Aleksander Alekseev <afis...@gmail.com>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
import sigrokdecode as srd
class Ann:
BITS, CMD, DATA, DESC = range(4)
class Decoder(srd.Decoder):
# see https://sigrok.org/wiki/Protocol_decoder_API
api_version = 3
id = 'st7735' # this is shown in `sigrok-cli -L`
name = 'ST7735' # this is shown in PulseView
longname = 'ST7735 TFT controller' # this is shown in `sigrok-cli -L`
desc = 'ST7735 TFT controller protocol decoder'
license = 'gplv2+'
inputs = ['logic']
outputs = ['st7735']
channels = (
{'id': 'cs', 'name': 'CS#', 'desc': 'Chip-select'},
{'id': 'clk', 'name': 'CLK', 'desc': 'Clock'},
{'id': 'mosi', 'name': 'MOSI', 'desc': 'Master out, slave in'},
{'id': 'dc', 'name': 'DC', 'desc': 'Data or command'}
)
optional_channels = ( )
annotations = (
('bits', 'Bits'), # Ann.BITS
('command', 'Command'), # Ann.CMD
('data', 'Data'), # Ann.DATA
('description', 'Description'), # Ann.DESC
)
annotation_rows = (
('bits', 'Bits', (Ann.BITS,)),
('fields', 'Fields', (Ann.CMD, Ann.DATA,)),
('description', 'Description', (Ann.DESC,)),
)
options = ( ) # see examples in spiflash decoder
def __init__(self):
self.reset()
def reset(self):
pass # do nothing, yet
# This function is called before the beginning of the decoding. This is the
# place to register() the output types, check the user-supplied PD options
# for validity, and so on
def start(self):
self.out_ann = self.register(srd.OUTPUT_ANN)
def putx(self, data):
self.put(self.ss, self.es, self.out_ann, data)
def reset_state(self):
self.accum_byte = 0
self.accum_bits_num = 0
self.is_command = False
self.clk_prev = 1
self.bit_ss = -1
self.bit_es = -1
self.current_bit = -1
# This is a function that is called by the libsigrokdecode backend whenever
# it has a chunk of data for the protocol decoder to handle.
# Arguments:
# ss = startsample, the absolute samplenumber of the first sample in this chunk of data
# es = endsample, the absolute samplenumber of the last sample in this chunk of data
# data = a list containing the data to decode. Depends on whether the decoder decodes
# raw samples or is stacked onto another decoder
def decode(self):
counter = -1 # start counter with zero, see loop beginning
self.reset_state()
while(True):
(cs, clk, mosi, dc) = self.wait({})
counter += 1
# print("decode: pins = %s" % ( (cs, clk, mosi, dc) ,) )
if cs == 1: # wait for CS = LOW, ignore the rest
self.reset_state()
continue
if (clk == 1) and (self.clk_prev == 0):
# read one bit
self.bit_ss = counter
self.current_bit = mosi
# print("BIT: %s" % ( mosi, ))
if (clk == 0) and (self.current_bit >= 0):
self.bit_es = counter
self.put(self.bit_ss, self.bit_es, self.out_ann, [Ann.BITS, [str(self.current_bit)]])
self.current_bit = -1
self.bit_ss = -1
self.bit_es = -1
self.clk_prev = clk
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel