-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_eeprom_rc.py
executable file
·73 lines (66 loc) · 1.48 KB
/
update_eeprom_rc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
REGISTERS = {
'IOCFG2': 0x00,
'IOCFG1': 0x01,
'IOCFG0': 0x02,
'FIFOTHR': 0x03,
'SYNC1': 0x04,
'SYNC0': 0x05,
'PKTLEN': 0x06,
'PKTCTRL1': 0x07,
'PKTCTRL0': 0x08,
'ADDR': 0x09,
'CHANNR': 0x0A,
'FSCTRL1': 0x0B,
'FSCTRL0': 0x0C,
'FREQ2': 0x0D,
'FREQ1': 0x0E,
'FREQ0': 0x0F,
'MDMCFG4': 0x10,
'MDMCFG3': 0x11,
'MDMCFG2': 0x12,
'MDMCFG1': 0x13,
'MDMCFG0': 0x14,
'DEVIATN': 0x15,
'MCSM2': 0x16,
'MCSM1': 0x17,
'MCSM0': 0x18,
'FOCCFG': 0x19,
'BSCFG': 0x1A,
'AGCCTRL2': 0x1B,
'AGCCTRL1': 0x1C,
'AGCCTRL0': 0x1D,
'WOREVT1': 0x1E,
'WOREVT0': 0x1F,
'WORCTRL': 0x20,
'FREND1': 0x21,
'FREND0': 0x22,
'FSCAL3': 0x23,
'FSCAL2': 0x24,
'FSCAL1': 0x25,
'FSCAL0': 0x26,
'RCCTRL1': 0x27,
'RCCTRL0': 0x28,
'FSTEST': 0x29,
'PTEST': 0x2A,
'AGCTEST': 0x2B,
'TEST2': 0x2C,
'TEST1': 0x2D,
'TEST0': 0x2E,
'PATABLE': 0x3E,
}
if __name__ == '__main__':
import sys
import re
with open('eeprom', 'r+b') as fh:
fh.seek(20)
for line in sys.stdin:
if re.match('^\s*#', line):
continue
m = re.match('(?P<reg>\w+)\s+(?P<value>[0-9a-fA-F]+)', line)
if not m:
continue
m = m.groupdict()
fh.write(chr(REGISTERS[m['reg']]))
fh.write(chr(int(m['value'], 16)))
fh.write(b"\xff" * (512 - fh.tell()))