X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fnrf24l01%2Fpd.py;h=06755ff3495b75f7beb27ba6aa320a7b4abf9d39;hb=81bf080fdb9d6ef9b0357148a41e0610df75ab61;hp=410a84704923bd28928e23b2e81e5595201b9fec;hpb=8aeedf9ee376f1b48fe9c42924ebf34f9c8c2ddd;p=libsigrokdecode.git diff --git a/decoders/nrf24l01/pd.py b/decoders/nrf24l01/pd.py index 410a847..06755ff 100644 --- a/decoders/nrf24l01/pd.py +++ b/decoders/nrf24l01/pd.py @@ -14,13 +14,12 @@ ## 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, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## along with this program; if not, see . ## import sigrokdecode as srd -class MissingDataError(Exception): +class ChannelError(Exception): pass regs = { @@ -53,25 +52,36 @@ regs = { 0x1d: ('FEATURE', 1), } +xn297_regs = { + 0x19: ('DEMOD_CAL', 5), + 0x1e: ('RF_CAL', 7), + 0x1f: ('BB_CAL', 5), +} + class Decoder(srd.Decoder): - api_version = 2 + api_version = 3 id = 'nrf24l01' name = 'nRF24L01(+)' - longname = 'Nordic Semiconductor nRF24L01/nRF24L01+' - desc = '2.4GHz transceiver chip.' + longname = 'Nordic Semiconductor nRF24L01(+)' + desc = '2.4GHz RF transceiver chip.' license = 'gplv2+' inputs = ['spi'] - outputs = ['nrf24l01'] + outputs = [] + tags = ['IC', 'Wireless/RF'] + options = ( + {'id': 'chip', 'desc': 'Chip type', + 'default': 'nrf24l01', 'values': ('nrf24l01', 'xn297')}, + ) annotations = ( # Sent from the host to the chip. - ('cmd', 'Commands sent to the device'), - ('tx-data', 'Payload sent to the device'), + ('cmd', 'Command'), + ('tx-data', 'Payload'), # Returned by the chip. - ('register', 'Registers read from the device'), - ('rx-data', 'Payload read from the device'), + ('register', 'Register read'), + ('rx-data', 'Payload read'), - ('warning', 'Warnings'), + ('warning', 'Warning'), ) ann_cmd = 0 ann_tx = 1 @@ -84,11 +94,18 @@ class Decoder(srd.Decoder): ('warnings', 'Warnings', (ann_warn,)), ) - def __init__(self, **kwargs): + def __init__(self): + self.reset() + + def reset(self): self.next() + self.requirements_met = True + self.cs_was_released = False def start(self): self.out_ann = self.register(srd.OUTPUT_ANN) + if self.options['chip'] == 'xn297': + regs.update(xn297_regs) def warn(self, pos, msg): '''Put a warning message 'msg' at 'pos'.''' @@ -264,9 +281,19 @@ class Decoder(srd.Decoder): self.warn(pos, 'wrong data for "ACTIVATE" command') def decode(self, ss, es, data): + if not self.requirements_met: + return + ptype, data1, data2 = data if ptype == 'CS-CHANGE': + if data1 is None: + if data2 is None: + self.requirements_met = False + raise ChannelError('CS# pin required.') + elif data2 == 1: + self.cs_was_released = True + if data1 == 0 and data2 == 1: # Rising edge, the complete command is transmitted, process # the bytes that were send after the command byte. @@ -279,12 +306,14 @@ class Decoder(srd.Decoder): self.finish_command((self.mb_s, self.mb_e)) self.next() - elif ptype == 'DATA': + self.cs_was_released = True + elif ptype == 'DATA' and self.cs_was_released: mosi, miso = data1, data2 pos = (ss, es) if miso is None or mosi is None: - raise MissingDataError('Both MISO and MOSI pins required.') + self.requirements_met = False + raise ChannelError('Both MISO and MOSI pins required.') if self.first: self.first = False