-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths5k5baf-cfg.py
executable file
·182 lines (171 loc) · 7.67 KB
/
s5k5baf-cfg.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python3
S5K5BAF_FW_TAG = b'SF00'
# Register interface pages
PAGE_IF_SW = 0x7000
# Pointers to color correction matrices
REG_PTR_CCM_HORIZON = 0x06d0
REG_PTR_CCM_INCANDESCENT = 0x06d4
REG_PTR_CCM_WARM_WHITE = 0x06d8
REG_PTR_CCM_COOL_WHITE = 0x06dc
REG_PTR_CCM_DL50 = 0x06e0
REG_PTR_CCM_DL65 = 0x06e4
REG_PTR_CCM_OUTDOOR = 0x06ec
def reg_arr_ccm(n):
return 0x2800 + 36 * n
# add items count at the beginning of the list
def nseq(*seq):
return [len(seq)] + list(seq)
nseq_patch = nseq(0x1668,
0xb5fe, 0x0007, 0x683c, 0x687e, 0x1da5, 0x88a0, 0x2800, 0xd00b,
0x88a8, 0x2800, 0xd008, 0x8820, 0x8829, 0x4288, 0xd301, 0x1a40,
0xe000, 0x1a08, 0x9001, 0xe001, 0x2019, 0x9001, 0x4916, 0x466b,
0x8a48, 0x8118, 0x8a88, 0x8158, 0x4814, 0x8940, 0x0040, 0x2103,
0xf000, 0xf826, 0x88a1, 0x4288, 0xd908, 0x8828, 0x8030, 0x8868,
0x8070, 0x88a8, 0x6038, 0xbcfe, 0xbc08, 0x4718, 0x88a9, 0x4288,
0xd906, 0x8820, 0x8030, 0x8860, 0x8070, 0x88a0, 0x6038, 0xe7f2,
0x9801, 0xa902, 0xf000, 0xf812, 0x0033, 0x0029, 0x9a02, 0x0020,
0xf000, 0xf814, 0x6038, 0xe7e6, 0x1a28, 0x7000, 0x0d64, 0x7000,
0x4778, 0x46c0, 0xf004, 0xe51f, 0xa464, 0x0000, 0x4778, 0x46c0,
0xc000, 0xe59f, 0xff1c, 0xe12f, 0x6009, 0x0000, 0x4778, 0x46c0,
0xc000, 0xe59f, 0xff1c, 0xe12f, 0x622f, 0x0000) + nseq(0x2080,
0xb510, 0xf000, 0xf8f4, 0xbc10, 0xbc08, 0x4718, 0xb5f0, 0xb08b,
0x0006, 0x2000, 0x9004, 0x6835, 0x6874, 0x68b0, 0x900a, 0x68f0,
0x9009, 0x4f7d, 0x8979, 0x084a, 0x88a8, 0x88a3, 0x4298, 0xd300,
0x0018, 0xf000, 0xf907, 0x9007, 0x0021, 0x0028, 0xaa04, 0xf000,
0xf909, 0x9006, 0x88a8, 0x2800, 0xd102, 0x27ff, 0x1c7f, 0xe047,
0x88a0, 0x2800, 0xd101, 0x2700, 0xe042, 0x8820, 0x466b, 0x8198,
0x8860, 0x81d8, 0x8828, 0x8118, 0x8868, 0x8158, 0xa802, 0xc803,
0xf000, 0xf8f8, 0x9008, 0x8aba, 0x9808, 0x466b, 0x4342, 0x9202,
0x8820, 0x8198, 0x8860, 0x81d8, 0x980a, 0x9903, 0xf000, 0xf8ea,
0x9a02, 0x17d1, 0x0e09, 0x1889, 0x1209, 0x4288, 0xdd1f, 0x8820,
0x466b, 0x8198, 0x8860, 0x81d8, 0x980a, 0x9903, 0xf000, 0xf8da,
0x9001, 0x8828, 0x466b, 0x8118, 0x8868, 0x8158, 0x980a, 0x9902,
0xf000, 0xf8d0, 0x8ab9, 0x9a08, 0x4351, 0x17ca, 0x0e12, 0x1851,
0x120a, 0x9901, 0xf000, 0xf8b6, 0x0407, 0x0c3f, 0xe000, 0x2700,
0x8820, 0x466b, 0xaa05, 0x8198, 0x8860, 0x81d8, 0x8828, 0x8118,
0x8868, 0x8158, 0xa802, 0xc803, 0x003b, 0xf000, 0xf8bb, 0x88a1,
0x88a8, 0x003a, 0xf000, 0xf8be, 0x0004, 0xa804, 0xc803, 0x9a09,
0x9b07, 0xf000, 0xf8af, 0xa806, 0xc805, 0x0021, 0xf000, 0xf8b2,
0x6030, 0xb00b, 0xbcf0, 0xbc08, 0x4718, 0xb5f1, 0x9900, 0x680c,
0x493a, 0x694b, 0x698a, 0x4694, 0x69cd, 0x6a0e, 0x4f38, 0x42bc,
0xd800, 0x0027, 0x4937, 0x6b89, 0x0409, 0x0c09, 0x4a35, 0x1e92,
0x6bd2, 0x0412, 0x0c12, 0x429f, 0xd801, 0x0020, 0xe031, 0x001f,
0x434f, 0x0a3f, 0x42a7, 0xd301, 0x0018, 0xe02a, 0x002b, 0x434b,
0x0a1b, 0x42a3, 0xd303, 0x0220, 0xf000, 0xf88c, 0xe021, 0x0029,
0x4351, 0x0a09, 0x42a1, 0xd301, 0x0028, 0xe01a, 0x0031, 0x4351,
0x0a09, 0x42a1, 0xd304, 0x0220, 0x0011, 0xf000, 0xf87b, 0xe010,
0x491e, 0x8c89, 0x000a, 0x4372, 0x0a12, 0x42a2, 0xd301, 0x0030,
0xe007, 0x4662, 0x434a, 0x0a12, 0x42a2, 0xd302, 0x0220, 0xf000,
0xf869, 0x4b16, 0x4d18, 0x8d99, 0x1fca, 0x3af9, 0xd00a, 0x2001,
0x0240, 0x8468, 0x0220, 0xf000, 0xf85d, 0x9900, 0x6008, 0xbcf8,
0xbc08, 0x4718, 0x8d19, 0x8469, 0x9900, 0x6008, 0xe7f7, 0xb570,
0x2200, 0x490e, 0x480e, 0x2401, 0xf000, 0xf852, 0x0022, 0x490d,
0x480d, 0x2502, 0xf000, 0xf84c, 0x490c, 0x480d, 0x002a, 0xf000,
0xf847, 0xbc70, 0xbc08, 0x4718, 0x0d64, 0x7000, 0x0470, 0x7000,
0xa120, 0x0007, 0x0402, 0x7000, 0x14a0, 0x7000, 0x208d, 0x7000,
0x622f, 0x0000, 0x1669, 0x7000, 0x6445, 0x0000, 0x21ab, 0x7000,
0x2aa9, 0x0000, 0x4778, 0x46c0, 0xc000, 0xe59f, 0xff1c, 0xe12f,
0x5f49, 0x0000, 0x4778, 0x46c0, 0xc000, 0xe59f, 0xff1c, 0xe12f,
0x5fc7, 0x0000, 0x4778, 0x46c0, 0xc000, 0xe59f, 0xff1c, 0xe12f,
0x5457, 0x0000, 0x4778, 0x46c0, 0xc000, 0xe59f, 0xff1c, 0xe12f,
0x5fa3, 0x0000, 0x4778, 0x46c0, 0xc000, 0xe59f, 0xff1c, 0xe12f,
0x51f9, 0x0000, 0x4778, 0x46c0, 0xf004, 0xe51f, 0xa464, 0x0000,
0x4778, 0x46c0, 0xc000, 0xe59f, 0xff1c, 0xe12f, 0xa007, 0x0000,
0x6546, 0x2062, 0x3120, 0x3220, 0x3130, 0x0030, 0xe010, 0x0208,
0x0058, 0x0000) + [0]
# custom color correction matrices for various illuminations
nseq_ccm = nseq(REG_PTR_CCM_HORIZON,
reg_arr_ccm(0), PAGE_IF_SW,
reg_arr_ccm(1), PAGE_IF_SW,
reg_arr_ccm(2), PAGE_IF_SW,
reg_arr_ccm(3), PAGE_IF_SW,
reg_arr_ccm(4), PAGE_IF_SW,
reg_arr_ccm(5), PAGE_IF_SW) + \
nseq(REG_PTR_CCM_OUTDOOR,
reg_arr_ccm(6), PAGE_IF_SW) + \
nseq(reg_arr_ccm(0),
# horizon
0x010d, 0xffa7, 0xfff5, 0x003b, 0x00ef, 0xff38,
0xfe42, 0x0270, 0xff71, 0xfeed, 0x0198, 0x0198,
0xff95, 0xffa3, 0x0260, 0x00ec, 0xff33, 0x00f4,
# incandescent
0x010d, 0xffa7, 0xfff5, 0x003b, 0x00ef, 0xff38,
0xfe42, 0x0270, 0xff71, 0xfeed, 0x0198, 0x0198,
0xff95, 0xffa3, 0x0260, 0x00ec, 0xff33, 0x00f4,
# warm white
0x01ea, 0xffb9, 0xffdb, 0x0127, 0x0109, 0xff3c,
0xff2b, 0x021b, 0xff48, 0xff03, 0x0207, 0x0113,
0xffca, 0xff93, 0x016f, 0x0164, 0xff55, 0x0163,
# cool white
0x01ea, 0xffb9, 0xffdb, 0x0127, 0x0109, 0xff3c,
0xff2b, 0x021b, 0xff48, 0xff03, 0x0207, 0x0113,
0xffca, 0xff93, 0x016f, 0x0164, 0xff55, 0x0163,
# daylight 5000K
0x0194, 0xffad, 0xfffe, 0x00c5, 0x0103, 0xff5d,
0xfee3, 0x01ae, 0xff27, 0xff18, 0x018f, 0x00c8,
0xffe8, 0xffaa, 0x01c8, 0x0132, 0xff3e, 0x0100,
# daylight 6500K
0x0194, 0xffad, 0xfffe, 0x00c5, 0x0103, 0xff5d,
0xfee3, 0x01ae, 0xff27, 0xff18, 0x018f, 0x00c8,
0xffe8, 0xffaa, 0x01c8, 0x0132, 0xff3e, 0x0100,
# outdoor
0x01cc, 0xffc3, 0x0009, 0x00a2, 0x0106, 0xff3f,
0xfed8, 0x01fe, 0xff08, 0xfec7, 0x00f5, 0x0119,
0xffdf, 0x0024, 0x01a8, 0x0170, 0xffad, 0x011b) + \
[0]
# CIS sensor tuning, based on undocumented android driver code
nseq_cis = \
nseq(0xc202, 0x0700) + \
nseq(0xf260, 0x0001) + \
nseq(0xf414, 0x0030) + \
nseq(0xc204, 0x0100) + \
nseq(0xf402, 0x0092, 0x007f) + \
nseq(0xf700, 0x0040) + \
nseq(0xf708,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0040, 0x0040, 0x0040, 0x0040, 0x0040,
0x0001, 0x0015, 0x0001, 0x0040) + \
nseq(0xf48a, 0x0048) + \
nseq(0xf10a, 0x008b) + \
nseq(0xf900, 0x0067) + \
nseq(0xf406, 0x0092, 0x007f, 0x0003, 0x0003, 0x0003) + \
nseq(0xf442, 0x0000, 0x0000) + \
nseq(0xf448, 0x0000) + \
nseq(0xf456, 0x0001, 0x0010, 0x0000) + \
nseq(0xf41a, 0x00ff, 0x0003, 0x0030) + \
nseq(0xf410, 0x0001, 0x0000) + \
nseq(0xf416, 0x0001) + \
nseq(0xf424, 0x0000) + \
nseq(0xf422, 0x0000) + \
nseq(0xf41e, 0x0000) + \
nseq(0xf428, 0x0000, 0x0000, 0x0000) + \
nseq(0xf430, 0x0000, 0x0000, 0x0008, 0x0005, 0x000f, 0x0001,
0x0040, 0x0040, 0x0010) + \
nseq(0xf4d6, 0x0090, 0x0000) + \
nseq(0xf47c, 0x000c, 0x0000) + \
nseq(0xf49a, 0x0008, 0x0000) + \
nseq(0xf4a2, 0x0008, 0x0000) + \
nseq(0xf4b2, 0x0013, 0x0000, 0x0013, 0x0000) + \
nseq(0xf4aa, 0x009b, 0x00fb, 0x009b, 0x00fb) + \
[0]
def write_bytes(f, n):
f.write(n.to_bytes(2, byteorder='little'))
with open('s5k5baf-cfg.bin', 'wb') as f:
# header
f.write(S5K5BAF_FW_TAG) # magic
write_bytes(f, 3) # count
# nseq_patch (id + offset)
write_bytes(f, 0)
write_bytes(f, 0)
# nseq_ccm (id + offset)
write_bytes(f, 1)
write_bytes(f, len(nseq_patch))
# nseq_cis (id + offset)
write_bytes(f, 2)
write_bytes(f, len(nseq_patch) + len(nseq_ccm))
for seq in nseq_patch:
write_bytes(f, seq)
for seq in nseq_ccm:
write_bytes(f, seq)
for seq in nseq_cis:
write_bytes(f, seq)