Unverified Commit b018742e authored by DreamSourceLab's avatar DreamSourceLab Committed by GitHub

Merge pull request #262 from abougouffa/master

Fix #258, and add new decoders
parents c5c12248 ce11f856
......@@ -92,6 +92,7 @@ endif()
find_package(Threads)
find_package(PythonLibs 3 EXACT)
find_package(Boost 1.42 COMPONENTS filesystem system thread REQUIRED)
find_package(libusb-1.0 REQUIRED)
find_package(libzip REQUIRED)
......@@ -390,6 +391,7 @@ else()
list(APPEND DSVIEW_LINK_LIBS ${PKGDEPS_LIBRARIES})
endif()
list(APPEND DSVIEW_LINK_LIBS ${PYTHON_LIBRARIES})
add_executable(${PROJECT_NAME}
${DSView_SOURCES}
......
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2019 Marco Geisler <m-sigrok@mageis.de>
##
## 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/>.
##
'''
This decoder stacks on top of the 'spi' PD and decodes the protocol spoken
by the Texas Instruments low-power sub-1GHz RF transceiver chips.
Details:
http://www.ti.com/lit/ds/symlink/cc1101.pdf
'''
from .pd import Decoder
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2019 Marco Geisler <m-sigrok@mageis.de>
##
## 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/>.
##
regs = {
# addr: 'name'
0x00: 'IOCFG2',
0x01: 'IOCFG1',
0x02: 'IOCFG0',
0x03: 'FIFOTHR',
0x04: 'SYNC1',
0x05: 'SYNC0',
0x06: 'PKTLEN',
0x07: 'PKTCTRL1',
0x08: 'PKTCTRL0',
0x09: 'ADDR',
0x0A: 'CHANNR',
0x0B: 'FSCTRL1',
0x0C: 'FSCTRL0',
0x0D: 'FREQ2',
0x0E: 'FREQ1',
0x0F: 'FREQ0',
0x10: 'MDMCFG4',
0x11: 'MDMCFG3',
0x12: 'MDMCFG2',
0x13: 'MDMCFG1',
0x14: 'MDMCFG0',
0x15: 'DEVIATN',
0x16: 'MCSM2',
0x17: 'MCSM1',
0x18: 'MCSM0',
0x19: 'FOCCFG',
0x1A: 'BSCFG',
0x1B: 'AGCTRL2',
0x1C: 'AGCTRL1',
0x1D: 'AGCTRL0',
0x1E: 'WOREVT1',
0x1F: 'WOREVT0',
0x20: 'WORCTRL',
0x21: 'FREND1',
0x22: 'FREND0',
0x23: 'FSCAL3',
0x24: 'FSCAL2',
0x25: 'FSCAL1',
0x26: 'FSCAL0',
0x27: 'RCCTRL1',
0x28: 'RCCTRL0',
0x29: 'FSTEST',
0x2A: 'PTEST',
0x2B: 'AGCTEST',
0x2C: 'TEST2',
0x2D: 'TEST1',
0x2E: 'TEST0',
0x30: 'PARTNUM',
0x31: 'VERSION',
0x32: 'FREQEST',
0x33: 'LQI',
0x34: 'RSSI',
0x35: 'MARCSTATE',
0x36: 'WORTIME1',
0x37: 'WORTIME0',
0x38: 'PKTSTATUS',
0x39: 'VCO_VC_DAC',
0x3A: 'TXBYTES',
0x3B: 'RXBYTES',
0x3C: 'RCCTRL1_STATUS',
0x3D: 'RCCTRL0_STATUS',
0x3E: 'PATABLE',
0x3F: 'FIFO'
}
strobes = {
# addr: 'name'
0x30: 'SRES',
0x31: 'SFSTXON',
0x32: 'SXOFF',
0x33: 'SCAL',
0x34: 'SRX',
0x35: 'STX',
0x36: 'SIDLE',
0x37: '',
0x38: 'SWOR',
0x39: 'SPWD',
0x3A: 'SFRX',
0x3B: 'SFTX',
0x3C: 'SWORRST',
0x3D: 'SNOP'
}
status_reg_states = {
# value: 'state name'
0b000: 'IDLE',
0b001: 'RX',
0b010: 'TX',
0b011: 'FSTXON',
0b100: 'CALIBRATE',
0b101: 'SETTLING',
0b110: 'RXFIFO_OVERFLOW',
0b111: 'TXFIFO_OVERFLOW'
}
This diff is collapsed.
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
##
## 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/>.
##
'''
This decoder stacks on top of the 'onewire_network' PD and decodes the
Maxim DS2408 1-Wire 8-channel addressable switch protocol.
'''
from .pd import Decoder
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2019 Mariusz Bialonczyk <manio@skyboo.net>
##
## 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
# Dictionary of FUNCTION commands and their names.
command = {
0xf0: 'Read PIO Registers',
0xf5: 'Channel Access Read',
0x5a: 'Channel Access Write',
0xcc: 'Write Conditional Search Register',
0xc3: 'Reset Activity Latches',
0x3c: 'Disable Test Mode',
}
class Decoder(srd.Decoder):
api_version = 3
id = 'ds2408'
name = 'DS2408'
longname = 'Maxim DS2408'
desc = '1-Wire 8-channel addressable switch.'
license = 'gplv2+'
inputs = ['onewire_network']
outputs = []
tags = ['Embedded/industrial', 'IC']
annotations = (
('text', 'Human-readable text'),
)
def __init__(self):
self.reset()
def reset(self):
# Bytes for function command.
self.bytes = []
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 decode(self, ss, es, data):
code, val = data
if code == 'RESET/PRESENCE':
self.ss, self.es = ss, es
self.putx([0, ['Reset/presence: %s'
% ('true' if val else 'false')]])
self.bytes = []
elif code == 'ROM':
self.ss, self.es = ss, es
family_code = val & 0xff
self.putx([0, ['ROM: 0x%016x (family code 0x%02x)' % (val, family_code)]])
self.bytes = []
elif code == 'DATA':
self.bytes.append(val)
if 1 == len(self.bytes):
self.ss, self.es = ss, es
if val not in command:
self.putx([0, ['Unrecognized command: 0x%02x' % val]])
else:
self.putx([0, ['%s (0x%02x)' % (command[val], val)]])
elif 0xf0 == self.bytes[0]: # Read PIO Registers
if 2 == len(self.bytes):
self.ss = ss
elif 3 == len(self.bytes):
self.es = es
self.putx([0, ['Target address: 0x%04x'
% ((self.bytes[2] << 8) + self.bytes[1])]])
elif 3 < len(self.bytes):
self.ss, self.es = ss, es
self.putx([0, ['Data: 0x%02x' % self.bytes[-1]]])
elif 0xf5 == self.bytes[0]: # Channel Access Read
if 2 == len(self.bytes):
self.ss = ss
elif 2 < len(self.bytes):
self.ss, self.es = ss, es
self.putx([0, ['PIO sample: 0x%02x' % self.bytes[-1]]])
elif 0x5a == self.bytes[0]: # Channel Access Write
if 2 == len(self.bytes):
self.ss = ss
elif 3 == len(self.bytes):
self.es = es
if (self.bytes[-1] == (self.bytes[-2] ^ 0xff)):
self.putx([0, ['Data: 0x%02x (bit-inversion correct: 0x%02x)' % (self.bytes[-2], self.bytes[-1])]])
else:
self.putx([0, ['Data error: second byte (0x%02x) is not bit-inverse of first (0x%02x)' % (self.bytes[-1], self.bytes[-2])]])
elif 3 < len(self.bytes):
self.ss, self.es = ss, es
if 0xaa == self.bytes[-1]:
self.putx([0, ['Success']])
elif 0xff == self.bytes[-1]:
self.putx([0, ['Fail New State']])
elif 0xcc == self.bytes[0]: # Write Conditional Search Register
if 2 == len(self.bytes):
self.ss = ss
elif 3 == len(self.bytes):
self.es = es
self.putx([0, ['Target address: 0x%04x'
% ((self.bytes[2] << 8) + self.bytes[1])]])
elif 3 < len(self.bytes):
self.ss, self.es = ss, es
self.putx([0, ['Data: 0x%02x' % self.bytes[-1]]])
elif 0xc3 == self.bytes[0]: # Reset Activity Latches
if 2 == len(self.bytes):
self.ss = ss
elif 2 < len(self.bytes):
self.ss, self.es = ss, es
if 0xaa == self.bytes[-1]:
self.putx([0, ['Success']])
else:
self.putx([0, ['Invalid byte']])
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2019 Jiahao Li <reg@ljh.me>
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in all
## copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
'''
This decoder stacks on top of the 'spi' PD and decodes the protocol spoken
by the Microchip ENC28J60 Ethernet chip.
Details:
http://ww1.microchip.com/downloads/en/DeviceDoc/39662e.pdf
'''
from .pd import Decoder
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2019 Jiahao Li <reg@ljh.me>
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in all
## copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
REGS = [
[
'ERDPTL',
'ERDPTH',
'EWRPTL',
'EWRPTH',
'ETXSTL',
'ETXSTH',
'ETXNDL',
'ETXNDH',
'ERXSTL',
'ERXSTH',
'ERXNDL',
'ERXNDH',
'ERXRDPTL',
'ERXRDPTH',
'ERXWRPTL',
'ERXWRPTH',
'EDMASTL',
'EDMASTH',
'EDMANDL',
'EDMANDH',
'EDMADSTL',
'EDMADSTH',
'EDMACSL',
'EDMACSH',
'—',
'—',
'Reserved',
'EIE',
'EIR',
'ESTAT',
'ECON2',
'ECON1',
],
[
'EHT0',
'EHT1',
'EHT2',
'EHT3',
'EHT4',
'EHT5',
'EHT6',
'EHT7',
'EPMM0',
'EPMM1',
'EPMM2',
'EPMM3',
'EPMM4',
'EPMM5',
'EPMM6',
'EPMM7',
'EPMCSL',
'EPMCSH',
'—',
'—',
'EPMOL',
'EPMOH',
'Reserved',
'Reserved',
'ERXFCON',
'EPKTCNT',
'Reserved',
'EIE',
'EIR',
'ESTAT',
'ECON2',
'ECON1',
],
[
'MACON1',
'Reserved',
'MACON3',
'MACON4',
'MABBIPG',
'—',
'MAIPGL',
'MAIPGH',
'MACLCON1',
'MACLCON2',
'MAMXFLL',
'MAMXFLH',
'Reserved',
'Reserved',
'Reserved',
'—',
'Reserved',
'Reserved',
'MICMD',
'—',
'MIREGADR',
'Reserved',
'MIWRL',
'MIWRH',
'MIRDL',
'MIRDH',
'Reserved',
'EIE',
'EIR',
'ESTAT',
'ECON2',
'ECON1',
],
[
'MAADR5',
'MAADR6',
'MAADR3',
'MAADR4',
'MAADR1',
'MAADR2',
'EBSTSD',
'EBSTCON',
'EBSTCSL',
'EBSTCSH',
'MISTAT',
'—',
'—',
'—',
'—',
'—',
'—',
'—',
'EREVID',
'—',
'—',
'ECOCON',
'Reserved',
'EFLOCON',
'EPAUSL',
'EPAUSH',
'Reserved',
'EIE',
'EIR',
'ESTAT',
'ECON2',
'ECON1',
],
]
This diff is collapsed.
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2019 Mickael Bosch <mickael.bosch@linux.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/>.
##
'''
This decoder stacks on top of the 'i2c' PD and decodes the NXP Semiconductors
PCA9571 8-bit I²C output expander protocol.
'''
from .pd import Decoder
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2019 Mickael Bosch <mickael.bosch@linux.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
NUM_OUTPUT_CHANNELS = 8
# TODO: Other I²C functions: general call / reset address, device ID address.
class Decoder(srd.Decoder):
api_version = 3
id = 'pca9571'
name = 'PCA9571'
longname = 'NXP PCA9571'
desc = 'NXP PCA9571 8-bit I²C output expander.'
license = 'gplv2+'
inputs = ['i2c']
outputs = []
tags = ['Embedded/industrial', 'IC']
annotations = (
('register', 'Register type'),
('value', 'Register value'),
('warning', 'Warning messages'),
)
annotation_rows = (
('regs', 'Registers', (0, 1)),
('warnings', 'Warnings', (2,)),
)
def __init__(self):
self.reset()
def reset(self):
self.state = 'IDLE'
self.last_write = 0xFF # Chip port default state is high.
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 handle_io(self, b):
if self.state == 'READ DATA':
operation = ['Outputs read', 'R']
if b != self.last_write:
self.putx([2, ['Warning: read value and last write value '
'(%02X) are different' % self.last_write]])
else:
operation = ['Outputs set', 'W']
self.last_write = b
self.putx([1, [operation[0] + ': %02X' % b,
operation[1] + ': %02X' % b]])
def check_correct_chip(self, addr):
if addr != 0x25:
self.putx([2, ['Warning: I²C slave 0x%02X not a PCA9571 '
'compatible chip.' % addr]])
return False
return True
def decode(self, ss, es, data):
cmd, databyte = data
self.ss, self.es = ss, es
# State machine.
if cmd in ('ACK', 'BITS'): # Discard 'ACK' and 'BITS'.
pass
elif cmd in ('START', 'START REPEAT'): # Start a communication.
self.state = 'GET SLAVE ADDR'
elif cmd in ('NACK', 'STOP'): # Reset the state machine.
self.state = 'IDLE'
elif cmd in ('ADDRESS READ', 'ADDRESS WRITE'):
if ((self.state == 'GET SLAVE ADDR') and
self.check_correct_chip(databyte)):
if cmd == 'ADDRESS READ':
self.state = 'READ DATA'
else:
self.state = 'WRITE DATA'
else:
self.state = 'IDLE'
elif cmd in ('DATA READ', 'DATA WRITE'):
if self.state in ('READ DATA', 'WRITE DATA'):
self.handle_io(databyte)
else:
self.state = 'IDLE'
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2019 Benedikt Otto <benedikt_o@web.de>
##
## 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/>.
##
'''
This decoder decodes the output of a 7-segment display.
'''
from .pd import Decoder
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2019 Benedikt Otto <benedikt_o@web.de>
##
## 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 ChannelError(Exception):
pass
digits = {
(0, 0, 0, 0, 0, 0, 0): ' ',
(1, 1, 1, 1, 1, 1, 0): '0',
(0, 1, 1, 0, 0, 0, 0): '1',
(1, 1, 0, 1, 1, 0, 1): '2',
(1, 1, 1, 1, 0, 0, 1): '3',
(0, 1, 1, 0, 0, 1, 1): '4',
(1, 0, 1, 1, 0, 1, 1): '5',
(1, 0, 1, 1, 1, 1, 1): '6',