1 /*
2  * Copyright 2018, 2020 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_video_common.h"
10 #include "fsl_camera.h"
11 #include "fsl_camera_device.h"
12 #include "fsl_max9286.h"
13 
14 /*******************************************************************************
15  * Definitions
16  ******************************************************************************/
17 #ifndef MAX9271_RETRY
18 #define MAX9271_RETRY 20U
19 #endif
20 
21 #ifndef OV10635_RETRY
22 #define OV10635_RETRY 20U
23 #endif
24 
25 #define I2C_ADDR_MAX9286 0x6AU
26 #define I2C_ADDR_MAX9271 0x40U
27 #define I2C_ADDR_OV10635 0x30U
28 /*
29  * 0: Initial value
30  * 1-4: Address for each camera
31  * 5: Broadcast address
32  */
33 #define I2C_ADDR_MAX9271_N(n) (I2C_ADDR_MAX9271 + (uint8_t)(n))
34 
35 #define I2C_ADDR_OV10635_N(n) (I2C_ADDR_OV10635 + (uint8_t)(n))
36 
37 #define MAX9271_MAX_COUNT 4U /* 4 MAX9271 at most. */
38 
39 #define MAX9286_Write(handle, reg, value)                                                         \
40     VIDEO_I2C_WriteReg(I2C_ADDR_MAX9286, kVIDEO_RegAddr8Bit, (reg), kVIDEO_RegWidth8Bit, (value), \
41                        ((const max9286_resource_t *)((handle)->resource))->i2cSendFunc)
42 
43 #define MAX9286_Read(handle, reg, value)                                                         \
44     VIDEO_I2C_ReadReg(I2C_ADDR_MAX9286, kVIDEO_RegAddr8Bit, (reg), kVIDEO_RegWidth8Bit, (value), \
45                       ((const max9286_resource_t *)((handle)->resource))->i2cReceiveFunc)
46 
47 #define OV10635_REG_PID 0x300AU
48 #define OV10635_REG_VER 0x300BU
49 #define OV10635_PID     0xA6U
50 #define OV10635_VER     0x35U
51 
52 #define MAX9286_REG_ID 0x1EU
53 #define MAX9286_ID     0x40U
54 
55 #define OV10635_RESOLUTION_CONFIG_REG_NUM 9U
56 
57 typedef struct _ov10635_reg
58 {
59     uint16_t reg;
60     uint8_t value;
61 } ov10635_reg_t;
62 
63 typedef struct _ov10635_resolution_config
64 {
65     uint8_t framePerSec;
66     uint32_t resolution;
67     ov10635_reg_t regs[OV10635_RESOLUTION_CONFIG_REG_NUM];
68 } ov10635_resolution_config_t;
69 
70 /*******************************************************************************
71  * Prototypes
72  ******************************************************************************/
73 status_t MAX9286_Init(camera_device_handle_t *handle, const camera_config_t *config);
74 status_t MAX9286_Deinit(camera_device_handle_t *handle);
75 status_t MAX9286_Start(camera_device_handle_t *handle);
76 status_t MAX9286_Stop(camera_device_handle_t *handle);
77 status_t MAX9286_Control(camera_device_handle_t *handle, camera_device_cmd_t cmd, int32_t arg);
78 status_t MAX9286_InitExt(camera_device_handle_t *handle, const camera_config_t *config, const void *extConfig);
79 
80 /*******************************************************************************
81  * Variables
82  ******************************************************************************/
83 const camera_device_operations_t max9286_ops = {
84     .init     = MAX9286_Init,
85     .deinit   = MAX9286_Deinit,
86     .start    = MAX9286_Start,
87     .stop     = MAX9286_Stop,
88     .control  = MAX9286_Control,
89     .init_ext = MAX9286_InitExt,
90 };
91 
92 static const ov10635_reg_t ov10635Firmware[] = {
93     {0x0103, 0x01}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61},
94     {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61},
95     {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61},
96     {0x300C, 0x61}, {0x300C, 0x61}, {0x300C, 0x61}, {0x301B, 0xFF}, {0x301C, 0xFF}, {0x301A, 0xFF}, {0x3011, 0x42},
97     {0x6900, 0x0C}, {0x6901, 0x11}, {0x3503, 0x10}, {0x3025, 0x03}, {0x3003, 0x20}, {0x3004, 0x21}, {0x3005, 0x20},
98     {0x3006, 0x91}, {0x3600, 0x74}, {0x3601, 0x2B}, {0x3612, 0x00}, {0x3611, 0x67}, {0x3633, 0xCA}, {0x3602, 0x2F},
99     {0x3603, 0x00}, {0x3630, 0x28}, {0x3631, 0x16}, {0x3714, 0x10}, {0x371D, 0x01}, {0x4300, 0x38}, {0x3007, 0x01},
100     {0x3024, 0x01}, {0x3020, 0x0B}, {0x3702, 0x20}, {0x3703, 0x48}, {0x3704, 0x32}, {0x3709, 0xA8}, {0x3709, 0xA8},
101     {0x370C, 0xC7}, {0x370D, 0x80}, {0x3712, 0x00}, {0x3713, 0x20}, {0x3715, 0x04}, {0x381D, 0x40}, {0x381C, 0x00},
102     {0x3822, 0x50}, {0x3824, 0x50}, {0x3815, 0x8C}, {0x3804, 0x05}, {0x3805, 0x1F}, {0x3800, 0x00}, {0x3801, 0x00},
103     {0x3806, 0x03}, {0x3807, 0x29}, {0x3802, 0x00}, {0x3803, 0x04}, {0x3808, 0x05}, {0x3809, 0x00}, {0x380A, 0x03},
104     {0x380B, 0x20}, {0x380C, 0x07}, {0x380D, 0x71}, {0x6E42, 0x03}, {0x6E43, 0x48}, {0x380E, 0x03}, {0x380F, 0x48},
105     {0x3813, 0x02}, {0x3811, 0x10}, {0x381F, 0x0C}, {0x3828, 0x03}, {0x3829, 0x10}, {0x382A, 0x10}, {0x382B, 0x10},
106     {0x3621, 0x64}, {0x5005, 0x08}, {0x56D5, 0x00}, {0x56D6, 0x80}, {0x56D7, 0x00}, {0x56D8, 0x00}, {0x56D9, 0x00},
107     {0x56DA, 0x80}, {0x56DB, 0x00}, {0x56DC, 0x00}, {0x56E8, 0x00}, {0x56E9, 0x7F}, {0x56EA, 0x00}, {0x56EB, 0x7F},
108     {0x5100, 0x00}, {0x5101, 0x80}, {0x5102, 0x00}, {0x5103, 0x80}, {0x5104, 0x00}, {0x5105, 0x80}, {0x5106, 0x00},
109     {0x5107, 0x80}, {0x5108, 0x00}, {0x5109, 0x00}, {0x510A, 0x00}, {0x510B, 0x00}, {0x510C, 0x00}, {0x510D, 0x00},
110     {0x510E, 0x00}, {0x510F, 0x00}, {0x5110, 0x00}, {0x5111, 0x80}, {0x5112, 0x00}, {0x5113, 0x80}, {0x5114, 0x00},
111     {0x5115, 0x80}, {0x5116, 0x00}, {0x5117, 0x80}, {0x5118, 0x00}, {0x5119, 0x00}, {0x511A, 0x00}, {0x511B, 0x00},
112     {0x511C, 0x00}, {0x511D, 0x00}, {0x511E, 0x00}, {0x511F, 0x00}, {0x56D0, 0x00}, {0x5006, 0x24}, {0x5608, 0x0D},
113     {0x52D7, 0x06}, {0x528D, 0x08}, {0x5293, 0x12}, {0x52D3, 0x12}, {0x5288, 0x06}, {0x5289, 0x20}, {0x52C8, 0x06},
114     {0x52C9, 0x20}, {0x52CD, 0x04}, {0x5381, 0x00}, {0x5382, 0xFF}, {0x5589, 0x76}, {0x558A, 0x47}, {0x558B, 0xEF},
115     {0x558C, 0xC9}, {0x558D, 0x49}, {0x558E, 0x30}, {0x558F, 0x67}, {0x5590, 0x3F}, {0x5591, 0xF0}, {0x5592, 0x10},
116     {0x55A2, 0x6D}, {0x55A3, 0x55}, {0x55A4, 0xC3}, {0x55A5, 0xB5}, {0x55A6, 0x43}, {0x55A7, 0x38}, {0x55A8, 0x5F},
117     {0x55A9, 0x4B}, {0x55AA, 0xF0}, {0x55AB, 0x10}, {0x5581, 0x52}, {0x5300, 0x01}, {0x5301, 0x00}, {0x5302, 0x00},
118     {0x5303, 0x0E}, {0x5304, 0x00}, {0x5305, 0x0E}, {0x5306, 0x00}, {0x5307, 0x36}, {0x5308, 0x00}, {0x5309, 0xD9},
119     {0x530A, 0x00}, {0x530B, 0x0F}, {0x530C, 0x00}, {0x530D, 0x2C}, {0x530E, 0x00}, {0x530F, 0x59}, {0x5310, 0x00},
120     {0x5311, 0x7B}, {0x5312, 0x00}, {0x5313, 0x22}, {0x5314, 0x00}, {0x5315, 0xD5}, {0x5316, 0x00}, {0x5317, 0x13},
121     {0x5318, 0x00}, {0x5319, 0x18}, {0x531A, 0x00}, {0x531B, 0x26}, {0x531C, 0x00}, {0x531D, 0xDC}, {0x531E, 0x00},
122     {0x531F, 0x02}, {0x5320, 0x00}, {0x5321, 0x24}, {0x5322, 0x00}, {0x5323, 0x56}, {0x5324, 0x00}, {0x5325, 0x85},
123     {0x5326, 0x00}, {0x5327, 0x20}, {0x5609, 0x01}, {0x560A, 0x40}, {0x560B, 0x01}, {0x560C, 0x40}, {0x560D, 0x00},
124     {0x560E, 0xFA}, {0x560F, 0x00}, {0x5610, 0xFA}, {0x5611, 0x02}, {0x5612, 0x80}, {0x5613, 0x02}, {0x5614, 0x80},
125     {0x5615, 0x01}, {0x5616, 0x2C}, {0x5617, 0x01}, {0x5618, 0x2C}, {0x563B, 0x01}, {0x563C, 0x01}, {0x563D, 0x01},
126     {0x563E, 0x01}, {0x563F, 0x03}, {0x5640, 0x03}, {0x5641, 0x03}, {0x5642, 0x05}, {0x5643, 0x09}, {0x5644, 0x05},
127     {0x5645, 0x05}, {0x5646, 0x05}, {0x5647, 0x05}, {0x5651, 0x00}, {0x5652, 0x80}, {0x521A, 0x01}, {0x521B, 0x03},
128     {0x521C, 0x06}, {0x521D, 0x0A}, {0x521E, 0x0E}, {0x521F, 0x12}, {0x5220, 0x16}, {0x5223, 0x02}, {0x5225, 0x04},
129     {0x5227, 0x08}, {0x5229, 0x0C}, {0x522B, 0x12}, {0x522D, 0x18}, {0x522F, 0x1E}, {0x5241, 0x04}, {0x5242, 0x01},
130     {0x5243, 0x03}, {0x5244, 0x06}, {0x5245, 0x0A}, {0x5246, 0x0E}, {0x5247, 0x12}, {0x5248, 0x16}, {0x524A, 0x03},
131     {0x524C, 0x04}, {0x524E, 0x08}, {0x5250, 0x0C}, {0x5252, 0x12}, {0x5254, 0x18}, {0x5256, 0x1E}, {0x4606, 0x07},
132     {0x4607, 0x71}, {0x460A, 0x02}, {0x460B, 0x70}, {0x460C, 0x00}, {0x4620, 0x0E}, {0x4700, 0x04}, {0x4701, 0x00},
133     {0x4702, 0x01}, {0x4004, 0x04}, {0x4005, 0x18}, {0x4001, 0x06}, {0x4050, 0x22}, {0x4051, 0x24}, {0x4052, 0x02},
134     {0x4057, 0x9C}, {0x405A, 0x00}, {0x4202, 0x02}, {0x3023, 0x10}, {0x0100, 0x01}, {0x0100, 0x01}, {0x6F10, 0x07},
135     {0x6F11, 0x82}, {0x6F12, 0x04}, {0x6F13, 0x00}, {0x6F14, 0x1F}, {0x6F15, 0xDD}, {0x6F16, 0x04}, {0x6F17, 0x04},
136     {0x6F18, 0x36}, {0x6F19, 0x66}, {0x6F1A, 0x04}, {0x6F1B, 0x08}, {0x6F1C, 0x0C}, {0x6F1D, 0xE7}, {0x6F1E, 0x04},
137     {0x6F1F, 0x0C}, {0xD000, 0x19}, {0xD001, 0xA0}, {0xD002, 0x00}, {0xD003, 0x01}, {0xD004, 0xA9}, {0xD005, 0xAD},
138     {0xD006, 0x10}, {0xD007, 0x40}, {0xD008, 0x44}, {0xD009, 0x00}, {0xD00A, 0x68}, {0xD00B, 0x00}, {0xD00C, 0x15},
139     {0xD00D, 0x00}, {0xD00E, 0x00}, {0xD00F, 0x00}, {0xD010, 0x19}, {0xD011, 0xA0}, {0xD012, 0x00}, {0xD013, 0x01},
140     {0xD014, 0xA9}, {0xD015, 0xAD}, {0xD016, 0x13}, {0xD017, 0xD0}, {0xD018, 0x44}, {0xD019, 0x00}, {0xD01A, 0x68},
141     {0xD01B, 0x00}, {0xD01C, 0x15}, {0xD01D, 0x00}, {0xD01E, 0x00}, {0xD01F, 0x00}, {0xD020, 0x19}, {0xD021, 0xA0},
142     {0xD022, 0x00}, {0xD023, 0x01}, {0xD024, 0xA9}, {0xD025, 0xAD}, {0xD026, 0x14}, {0xD027, 0xB8}, {0xD028, 0x44},
143     {0xD029, 0x00}, {0xD02A, 0x68}, {0xD02B, 0x00}, {0xD02C, 0x15}, {0xD02D, 0x00}, {0xD02E, 0x00}, {0xD02F, 0x00},
144     {0xD030, 0x19}, {0xD031, 0xA0}, {0xD032, 0x00}, {0xD033, 0x01}, {0xD034, 0xA9}, {0xD035, 0xAD}, {0xD036, 0x14},
145     {0xD037, 0xDC}, {0xD038, 0x44}, {0xD039, 0x00}, {0xD03A, 0x68}, {0xD03B, 0x00}, {0xD03C, 0x15}, {0xD03D, 0x00},
146     {0xD03E, 0x00}, {0xD03F, 0x00}, {0xD040, 0x9C}, {0xD041, 0x21}, {0xD042, 0xFF}, {0xD043, 0xE4}, {0xD044, 0xD4},
147     {0xD045, 0x01}, {0xD046, 0x48}, {0xD047, 0x00}, {0xD048, 0xD4}, {0xD049, 0x01}, {0xD04A, 0x50}, {0xD04B, 0x04},
148     {0xD04C, 0xD4}, {0xD04D, 0x01}, {0xD04E, 0x60}, {0xD04F, 0x08}, {0xD050, 0xD4}, {0xD051, 0x01}, {0xD052, 0x70},
149     {0xD053, 0x0C}, {0xD054, 0xD4}, {0xD055, 0x01}, {0xD056, 0x80}, {0xD057, 0x10}, {0xD058, 0x19}, {0xD059, 0xC0},
150     {0xD05A, 0x00}, {0xD05B, 0x01}, {0xD05C, 0xA9}, {0xD05D, 0xCE}, {0xD05E, 0x02}, {0xD05F, 0xA4}, {0xD060, 0x9C},
151     {0xD061, 0xA0}, {0xD062, 0x00}, {0xD063, 0x00}, {0xD064, 0x84}, {0xD065, 0x6E}, {0xD066, 0x00}, {0xD067, 0x00},
152     {0xD068, 0xD8}, {0xD069, 0x03}, {0xD06A, 0x28}, {0xD06B, 0x76}, {0xD06C, 0x1A}, {0xD06D, 0x00}, {0xD06E, 0x00},
153     {0xD06F, 0x01}, {0xD070, 0xAA}, {0xD071, 0x10}, {0xD072, 0x03}, {0xD073, 0xF0}, {0xD074, 0x18}, {0xD075, 0x60},
154     {0xD076, 0x00}, {0xD077, 0x01}, {0xD078, 0xA8}, {0xD079, 0x63}, {0xD07A, 0x07}, {0xD07B, 0x80}, {0xD07C, 0xE0},
155     {0xD07D, 0xA0}, {0xD07E, 0x00}, {0xD07F, 0x04}, {0xD080, 0x18}, {0xD081, 0xC0}, {0xD082, 0x00}, {0xD083, 0x00},
156     {0xD084, 0xA8}, {0xD085, 0xC6}, {0xD086, 0x00}, {0xD087, 0x00}, {0xD088, 0x8C}, {0xD089, 0x63}, {0xD08A, 0x00},
157     {0xD08B, 0x00}, {0xD08C, 0xD4}, {0xD08D, 0x01}, {0xD08E, 0x28}, {0xD08F, 0x14}, {0xD090, 0xD4}, {0xD091, 0x01},
158     {0xD092, 0x30}, {0xD093, 0x18}, {0xD094, 0x07}, {0xD095, 0xFF}, {0xD096, 0xF8}, {0xD097, 0xFD}, {0xD098, 0x9C},
159     {0xD099, 0x80}, {0xD09A, 0x00}, {0xD09B, 0x03}, {0xD09C, 0xA5}, {0xD09D, 0x6B}, {0xD09E, 0x00}, {0xD09F, 0xFF},
160     {0xD0A0, 0x18}, {0xD0A1, 0xC0}, {0xD0A2, 0x00}, {0xD0A3, 0x01}, {0xD0A4, 0xA8}, {0xD0A5, 0xC6}, {0xD0A6, 0x01},
161     {0xD0A7, 0x02}, {0xD0A8, 0xE1}, {0xD0A9, 0x6B}, {0xD0AA, 0x58}, {0xD0AB, 0x00}, {0xD0AC, 0x84}, {0xD0AD, 0x8E},
162     {0xD0AE, 0x00}, {0xD0AF, 0x00}, {0xD0B0, 0xE1}, {0xD0B1, 0x6B}, {0xD0B2, 0x30}, {0xD0B3, 0x00}, {0xD0B4, 0x98},
163     {0xD0B5, 0xB0}, {0xD0B6, 0x00}, {0xD0B7, 0x00}, {0xD0B8, 0x8C}, {0xD0B9, 0x64}, {0xD0BA, 0x00}, {0xD0BB, 0x6E},
164     {0xD0BC, 0xE5}, {0xD0BD, 0xA5}, {0xD0BE, 0x18}, {0xD0BF, 0x00}, {0xD0C0, 0x10}, {0xD0C1, 0x00}, {0xD0C2, 0x00},
165     {0xD0C3, 0x06}, {0xD0C4, 0x95}, {0xD0C5, 0x8B}, {0xD0C6, 0x00}, {0xD0C7, 0x00}, {0xD0C8, 0x94}, {0xD0C9, 0xA4},
166     {0xD0CA, 0x00}, {0xD0CB, 0x70}, {0xD0CC, 0xE5}, {0xD0CD, 0x65}, {0xD0CE, 0x60}, {0xD0CF, 0x00}, {0xD0D0, 0x0C},
167     {0xD0D1, 0x00}, {0xD0D2, 0x00}, {0xD0D3, 0x62}, {0xD0D4, 0x15}, {0xD0D5, 0x00}, {0xD0D6, 0x00}, {0xD0D7, 0x00},
168     {0xD0D8, 0x18}, {0xD0D9, 0x60}, {0xD0DA, 0x80}, {0xD0DB, 0x06}, {0xD0DC, 0xA8}, {0xD0DD, 0x83}, {0xD0DE, 0x38},
169     {0xD0DF, 0x29}, {0xD0E0, 0xA8}, {0xD0E1, 0xE3}, {0xD0E2, 0x40}, {0xD0E3, 0x08}, {0xD0E4, 0x8C}, {0xD0E5, 0x84},
170     {0xD0E6, 0x00}, {0xD0E7, 0x00}, {0xD0E8, 0xA8}, {0xD0E9, 0xA3}, {0xD0EA, 0x40}, {0xD0EB, 0x09}, {0xD0EC, 0xA8},
171     {0xD0ED, 0xC3}, {0xD0EE, 0x38}, {0xD0EF, 0x2A}, {0xD0F0, 0xD8}, {0xD0F1, 0x07}, {0xD0F2, 0x20}, {0xD0F3, 0x00},
172     {0xD0F4, 0x8C}, {0xD0F5, 0x66}, {0xD0F6, 0x00}, {0xD0F7, 0x00}, {0xD0F8, 0xD8}, {0xD0F9, 0x05}, {0xD0FA, 0x18},
173     {0xD0FB, 0x00}, {0xD0FC, 0x18}, {0xD0FD, 0x60}, {0xD0FE, 0x00}, {0xD0FF, 0x01}, {0xD100, 0x98}, {0xD101, 0x90},
174     {0xD102, 0x00}, {0xD103, 0x00}, {0xD104, 0x84}, {0xD105, 0xAE}, {0xD106, 0x00}, {0xD107, 0x00}, {0xD108, 0xA8},
175     {0xD109, 0x63}, {0xD10A, 0x06}, {0xD10B, 0x4C}, {0xD10C, 0x9C}, {0xD10D, 0xC0}, {0xD10E, 0x00}, {0xD10F, 0x00},
176     {0xD110, 0xD8}, {0xD111, 0x03}, {0xD112, 0x30}, {0xD113, 0x00}, {0xD114, 0x8C}, {0xD115, 0x65}, {0xD116, 0x00},
177     {0xD117, 0x6E}, {0xD118, 0xE5}, {0xD119, 0x84}, {0xD11A, 0x18}, {0xD11B, 0x00}, {0xD11C, 0x10}, {0xD11D, 0x00},
178     {0xD11E, 0x00}, {0xD11F, 0x07}, {0xD120, 0x18}, {0xD121, 0x80}, {0xD122, 0x80}, {0xD123, 0x06}, {0xD124, 0x94},
179     {0xD125, 0x65}, {0xD126, 0x00}, {0xD127, 0x70}, {0xD128, 0xE5}, {0xD129, 0x43}, {0xD12A, 0x60}, {0xD12B, 0x00},
180     {0xD12C, 0x0C}, {0xD12D, 0x00}, {0xD12E, 0x00}, {0xD12F, 0x3E}, {0xD130, 0xA8}, {0xD131, 0x64}, {0xD132, 0x38},
181     {0xD133, 0x24}, {0xD134, 0x18}, {0xD135, 0x80}, {0xD136, 0x80}, {0xD137, 0x06}, {0xD138, 0xA8}, {0xD139, 0x64},
182     {0xD13A, 0x38}, {0xD13B, 0x24}, {0xD13C, 0x8C}, {0xD13D, 0x63}, {0xD13E, 0x00}, {0xD13F, 0x00}, {0xD140, 0xA4},
183     {0xD141, 0x63}, {0xD142, 0x00}, {0xD143, 0x40}, {0xD144, 0xBC}, {0xD145, 0x23}, {0xD146, 0x00}, {0xD147, 0x00},
184     {0xD148, 0x0C}, {0xD149, 0x00}, {0xD14A, 0x00}, {0xD14B, 0x2A}, {0xD14C, 0xA8}, {0xD14D, 0x64}, {0xD14E, 0x6E},
185     {0xD14F, 0x44}, {0xD150, 0x19}, {0xD151, 0x00}, {0xD152, 0x80}, {0xD153, 0x06}, {0xD154, 0xA8}, {0xD155, 0xE8},
186     {0xD156, 0x3D}, {0xD157, 0x05}, {0xD158, 0x8C}, {0xD159, 0x67}, {0xD15A, 0x00}, {0xD15B, 0x00}, {0xD15C, 0xB8},
187     {0xD15D, 0x63}, {0xD15E, 0x00}, {0xD15F, 0x18}, {0xD160, 0xB8}, {0xD161, 0x63}, {0xD162, 0x00}, {0xD163, 0x98},
188     {0xD164, 0xBC}, {0xD165, 0x03}, {0xD166, 0x00}, {0xD167, 0x00}, {0xD168, 0x10}, {0xD169, 0x00}, {0xD16A, 0x00},
189     {0xD16B, 0x10}, {0xD16C, 0xA9}, {0xD16D, 0x48}, {0xD16E, 0x67}, {0xD16F, 0x02}, {0xD170, 0xB8}, {0xD171, 0xA3},
190     {0xD172, 0x00}, {0xD173, 0x19}, {0xD174, 0x8C}, {0xD175, 0x8A}, {0xD176, 0x00}, {0xD177, 0x00}, {0xD178, 0xA9},
191     {0xD179, 0x68}, {0xD17A, 0x67}, {0xD17B, 0x03}, {0xD17C, 0xB8}, {0xD17D, 0xC4}, {0xD17E, 0x00}, {0xD17F, 0x08},
192     {0xD180, 0x8C}, {0xD181, 0x6B}, {0xD182, 0x00}, {0xD183, 0x00}, {0xD184, 0xB8}, {0xD185, 0x85}, {0xD186, 0x00},
193     {0xD187, 0x98}, {0xD188, 0xE0}, {0xD189, 0x63}, {0xD18A, 0x30}, {0xD18B, 0x04}, {0xD18C, 0xE0}, {0xD18D, 0x64},
194     {0xD18E, 0x18}, {0xD18F, 0x00}, {0xD190, 0xA4}, {0xD191, 0x83}, {0xD192, 0xFF}, {0xD193, 0xFF}, {0xD194, 0xB8},
195     {0xD195, 0x64}, {0xD196, 0x00}, {0xD197, 0x48}, {0xD198, 0xD8}, {0xD199, 0x0A}, {0xD19A, 0x18}, {0xD19B, 0x00},
196     {0xD19C, 0xD8}, {0xD19D, 0x0B}, {0xD19E, 0x20}, {0xD19F, 0x00}, {0xD1A0, 0x9C}, {0xD1A1, 0x60}, {0xD1A2, 0x00},
197     {0xD1A3, 0x00}, {0xD1A4, 0xD8}, {0xD1A5, 0x07}, {0xD1A6, 0x18}, {0xD1A7, 0x00}, {0xD1A8, 0xA8}, {0xD1A9, 0x68},
198     {0xD1AA, 0x38}, {0xD1AB, 0x22}, {0xD1AC, 0x9C}, {0xD1AD, 0x80}, {0xD1AE, 0x00}, {0xD1AF, 0x70}, {0xD1B0, 0xA8},
199     {0xD1B1, 0xE8}, {0xD1B2, 0x38}, {0xD1B3, 0x43}, {0xD1B4, 0xD8}, {0xD1B5, 0x03}, {0xD1B6, 0x20}, {0xD1B7, 0x00},
200     {0xD1B8, 0x9C}, {0xD1B9, 0xA0}, {0xD1BA, 0x00}, {0xD1BB, 0x00}, {0xD1BC, 0xA8}, {0xD1BD, 0xC8}, {0xD1BE, 0x38},
201     {0xD1BF, 0x42}, {0xD1C0, 0x8C}, {0xD1C1, 0x66}, {0xD1C2, 0x00}, {0xD1C3, 0x00}, {0xD1C4, 0x9C}, {0xD1C5, 0xA5},
202     {0xD1C6, 0x00}, {0xD1C7, 0x01}, {0xD1C8, 0xB8}, {0xD1C9, 0x83}, {0xD1CA, 0x00}, {0xD1CB, 0x08}, {0xD1CC, 0xA4},
203     {0xD1CD, 0xA5}, {0xD1CE, 0x00}, {0xD1CF, 0xFF}, {0xD1D0, 0x8C}, {0xD1D1, 0x67}, {0xD1D2, 0x00}, {0xD1D3, 0x00},
204     {0xD1D4, 0xE0}, {0xD1D5, 0x63}, {0xD1D6, 0x20}, {0xD1D7, 0x00}, {0xD1D8, 0xA4}, {0xD1D9, 0x63}, {0xD1DA, 0xFF},
205     {0xD1DB, 0xFF}, {0xD1DC, 0xBC}, {0xD1DD, 0x43}, {0xD1DE, 0x00}, {0xD1DF, 0x07}, {0xD1E0, 0x0C}, {0xD1E1, 0x00},
206     {0xD1E2, 0x00}, {0xD1E3, 0x5B}, {0xD1E4, 0xBC}, {0xD1E5, 0x05}, {0xD1E6, 0x00}, {0xD1E7, 0x02}, {0xD1E8, 0x03},
207     {0xD1E9, 0xFF}, {0xD1EA, 0xFF}, {0xD1EB, 0xF6}, {0xD1EC, 0x9C}, {0xD1ED, 0xA0}, {0xD1EE, 0x00}, {0xD1EF, 0x00},
208     {0xD1F0, 0xA8}, {0xD1F1, 0xA4}, {0xD1F2, 0x55}, {0xD1F3, 0x86}, {0xD1F4, 0x8C}, {0xD1F5, 0x63}, {0xD1F6, 0x00},
209     {0xD1F7, 0x00}, {0xD1F8, 0xA8}, {0xD1F9, 0xC4}, {0xD1FA, 0x6E}, {0xD1FB, 0x45}, {0xD1FC, 0xA8}, {0xD1FD, 0xE4},
210     {0xD1FE, 0x55}, {0xD1FF, 0x87}, {0xD200, 0xD8}, {0xD201, 0x05}, {0xD202, 0x18}, {0xD203, 0x00}, {0xD204, 0x8C},
211     {0xD205, 0x66}, {0xD206, 0x00}, {0xD207, 0x00}, {0xD208, 0xA8}, {0xD209, 0xA4}, {0xD20A, 0x6E}, {0xD20B, 0x46},
212     {0xD20C, 0xD8}, {0xD20D, 0x07}, {0xD20E, 0x18}, {0xD20F, 0x00}, {0xD210, 0xA8}, {0xD211, 0x84}, {0xD212, 0x55},
213     {0xD213, 0x88}, {0xD214, 0x8C}, {0xD215, 0x65}, {0xD216, 0x00}, {0xD217, 0x00}, {0xD218, 0xD8}, {0xD219, 0x04},
214     {0xD21A, 0x18}, {0xD21B, 0x00}, {0xD21C, 0x03}, {0xD21D, 0xFF}, {0xD21E, 0xFF}, {0xD21F, 0xCE}, {0xD220, 0x19},
215     {0xD221, 0x00}, {0xD222, 0x80}, {0xD223, 0x06}, {0xD224, 0x8C}, {0xD225, 0x63}, {0xD226, 0x00}, {0xD227, 0x00},
216     {0xD228, 0xA4}, {0xD229, 0x63}, {0xD22A, 0x00}, {0xD22B, 0x40}, {0xD22C, 0xBC}, {0xD22D, 0x23}, {0xD22E, 0x00},
217     {0xD22F, 0x00}, {0xD230, 0x13}, {0xD231, 0xFF}, {0xD232, 0xFF}, {0xD233, 0xC8}, {0xD234, 0x9D}, {0xD235, 0x00},
218     {0xD236, 0x00}, {0xD237, 0x40}, {0xD238, 0xA8}, {0xD239, 0x64}, {0xD23A, 0x55}, {0xD23B, 0x86}, {0xD23C, 0xA8},
219     {0xD23D, 0xA4}, {0xD23E, 0x55}, {0xD23F, 0x87}, {0xD240, 0xD8}, {0xD241, 0x03}, {0xD242, 0x40}, {0xD243, 0x00},
220     {0xD244, 0xA8}, {0xD245, 0x64}, {0xD246, 0x55}, {0xD247, 0x88}, {0xD248, 0xD8}, {0xD249, 0x05}, {0xD24A, 0x40},
221     {0xD24B, 0x00}, {0xD24C, 0xD8}, {0xD24D, 0x03}, {0xD24E, 0x40}, {0xD24F, 0x00}, {0xD250, 0x03}, {0xD251, 0xFF},
222     {0xD252, 0xFF}, {0xD253, 0xC1}, {0xD254, 0x19}, {0xD255, 0x00}, {0xD256, 0x80}, {0xD257, 0x06}, {0xD258, 0x94},
223     {0xD259, 0x84}, {0xD25A, 0x00}, {0xD25B, 0x72}, {0xD25C, 0xE5}, {0xD25D, 0xA4}, {0xD25E, 0x60}, {0xD25F, 0x00},
224     {0xD260, 0x0C}, {0xD261, 0x00}, {0xD262, 0x00}, {0xD263, 0x3F}, {0xD264, 0x9D}, {0xD265, 0x60}, {0xD266, 0x01},
225     {0xD267, 0x00}, {0xD268, 0x85}, {0xD269, 0x4E}, {0xD26A, 0x00}, {0xD26B, 0x00}, {0xD26C, 0x98}, {0xD26D, 0x70},
226     {0xD26E, 0x00}, {0xD26F, 0x00}, {0xD270, 0x8C}, {0xD271, 0x8A}, {0xD272, 0x00}, {0xD273, 0x6F}, {0xD274, 0xE5},
227     {0xD275, 0x63}, {0xD276, 0x20}, {0xD277, 0x00}, {0xD278, 0x10}, {0xD279, 0x00}, {0xD27A, 0x00}, {0xD27B, 0x07},
228     {0xD27C, 0x15}, {0xD27D, 0x00}, {0xD27E, 0x00}, {0xD27F, 0x00}, {0xD280, 0x8C}, {0xD281, 0xAA}, {0xD282, 0x00},
229     {0xD283, 0x6E}, {0xD284, 0xE0}, {0xD285, 0x63}, {0xD286, 0x28}, {0xD287, 0x02}, {0xD288, 0xE0}, {0xD289, 0x84},
230     {0xD28A, 0x28}, {0xD28B, 0x02}, {0xD28C, 0x07}, {0xD28D, 0xFF}, {0xD28E, 0xF8}, {0xD28F, 0x66}, {0xD290, 0xE0},
231     {0xD291, 0x63}, {0xD292, 0x5B}, {0xD293, 0x06}, {0xD294, 0x8C}, {0xD295, 0x6A}, {0xD296, 0x00}, {0xD297, 0x77},
232     {0xD298, 0xE0}, {0xD299, 0x63}, {0xD29A, 0x5B}, {0xD29B, 0x06}, {0xD29C, 0xBD}, {0xD29D, 0x63}, {0xD29E, 0x00},
233     {0xD29F, 0x00}, {0xD2A0, 0x0C}, {0xD2A1, 0x00}, {0xD2A2, 0x00}, {0xD2A3, 0x3C}, {0xD2A4, 0x15}, {0xD2A5, 0x00},
234     {0xD2A6, 0x00}, {0xD2A7, 0x00}, {0xD2A8, 0x8C}, {0xD2A9, 0x8A}, {0xD2AA, 0x00}, {0xD2AB, 0x78}, {0xD2AC, 0xB8},
235     {0xD2AD, 0x63}, {0xD2AE, 0x00}, {0xD2AF, 0x88}, {0xD2B0, 0xE1}, {0xD2B1, 0x64}, {0xD2B2, 0x5B}, {0xD2B3, 0x06},
236     {0xD2B4, 0xBD}, {0xD2B5, 0x6B}, {0xD2B6, 0x00}, {0xD2B7, 0x00}, {0xD2B8, 0x0C}, {0xD2B9, 0x00}, {0xD2BA, 0x00},
237     {0xD2BB, 0x34}, {0xD2BC, 0xD4}, {0xD2BD, 0x01}, {0xD2BE, 0x18}, {0xD2BF, 0x14}, {0xD2C0, 0xB9}, {0xD2C1, 0x6B},
238     {0xD2C2, 0x00}, {0xD2C3, 0x88}, {0xD2C4, 0x85}, {0xD2C5, 0x01}, {0xD2C6, 0x00}, {0xD2C7, 0x14}, {0xD2C8, 0xBD},
239     {0xD2C9, 0x68}, {0xD2CA, 0x00}, {0xD2CB, 0x00}, {0xD2CC, 0x0C}, {0xD2CD, 0x00}, {0xD2CE, 0x00}, {0xD2CF, 0x2C},
240     {0xD2D0, 0xD4}, {0xD2D1, 0x01}, {0xD2D2, 0x58}, {0xD2D3, 0x18}, {0xD2D4, 0x84}, {0xD2D5, 0x81}, {0xD2D6, 0x00},
241     {0xD2D7, 0x14}, {0xD2D8, 0xBD}, {0xD2D9, 0xA4}, {0xD2DA, 0x01}, {0xD2DB, 0x00}, {0xD2DC, 0x10}, {0xD2DD, 0x00},
242     {0xD2DE, 0x00}, {0xD2DF, 0x05}, {0xD2E0, 0x84}, {0xD2E1, 0xC1}, {0xD2E2, 0x00}, {0xD2E3, 0x18}, {0xD2E4, 0x9C},
243     {0xD2E5, 0xA0}, {0xD2E6, 0x01}, {0xD2E7, 0x00}, {0xD2E8, 0xD4}, {0xD2E9, 0x01}, {0xD2EA, 0x28}, {0xD2EB, 0x14},
244     {0xD2EC, 0x84}, {0xD2ED, 0xC1}, {0xD2EE, 0x00}, {0xD2EF, 0x18}, {0xD2F0, 0xBD}, {0xD2F1, 0x66}, {0xD2F2, 0x00},
245     {0xD2F3, 0x00}, {0xD2F4, 0x0C}, {0xD2F5, 0x00}, {0xD2F6, 0x00}, {0xD2F7, 0x20}, {0xD2F8, 0x9D}, {0xD2F9, 0x00},
246     {0xD2FA, 0x00}, {0xD2FB, 0x00}, {0xD2FC, 0x84}, {0xD2FD, 0x61}, {0xD2FE, 0x00}, {0xD2FF, 0x18}, {0xD300, 0xBD},
247     {0xD301, 0xA3}, {0xD302, 0x01}, {0xD303, 0x00}, {0xD304, 0x10}, {0xD305, 0x00}, {0xD306, 0x00}, {0xD307, 0x03},
248     {0xD308, 0x9C}, {0xD309, 0x80}, {0xD30A, 0x01}, {0xD30B, 0x00}, {0xD30C, 0xD4}, {0xD30D, 0x01}, {0xD30E, 0x20},
249     {0xD30F, 0x18}, {0xD310, 0x18}, {0xD311, 0x60}, {0xD312, 0x80}, {0xD313, 0x06}, {0xD314, 0x85}, {0xD315, 0x01},
250     {0xD316, 0x00}, {0xD317, 0x14}, {0xD318, 0xA8}, {0xD319, 0x83}, {0xD31A, 0x38}, {0xD31B, 0x29}, {0xD31C, 0xA8},
251     {0xD31D, 0xC3}, {0xD31E, 0x40}, {0xD31F, 0x08}, {0xD320, 0x8C}, {0xD321, 0x84}, {0xD322, 0x00}, {0xD323, 0x00},
252     {0xD324, 0xA8}, {0xD325, 0xA3}, {0xD326, 0x38}, {0xD327, 0x2A}, {0xD328, 0xA8}, {0xD329, 0xE3}, {0xD32A, 0x40},
253     {0xD32B, 0x09}, {0xD32C, 0xE0}, {0xD32D, 0x64}, {0xD32E, 0x40}, {0xD32F, 0x00}, {0xD330, 0xD8}, {0xD331, 0x06},
254     {0xD332, 0x18}, {0xD333, 0x00}, {0xD334, 0x8C}, {0xD335, 0x65}, {0xD336, 0x00}, {0xD337, 0x00}, {0xD338, 0x84},
255     {0xD339, 0x81}, {0xD33A, 0x00}, {0xD33B, 0x18}, {0xD33C, 0xE3}, {0xD33D, 0xE3}, {0xD33E, 0x20}, {0xD33F, 0x00},
256     {0xD340, 0xD8}, {0xD341, 0x07}, {0xD342, 0xF8}, {0xD343, 0x00}, {0xD344, 0x03}, {0xD345, 0xFF}, {0xD346, 0xFF},
257     {0xD347, 0x6F}, {0xD348, 0x18}, {0xD349, 0x60}, {0xD34A, 0x00}, {0xD34B, 0x01}, {0xD34C, 0x0F}, {0xD34D, 0xFF},
258     {0xD34E, 0xFF}, {0xD34F, 0x9D}, {0xD350, 0x18}, {0xD351, 0x60}, {0xD352, 0x80}, {0xD353, 0x06}, {0xD354, 0x00},
259     {0xD355, 0x00}, {0xD356, 0x00}, {0xD357, 0x11}, {0xD358, 0xA8}, {0xD359, 0x83}, {0xD35A, 0x6E}, {0xD35B, 0x43},
260     {0xD35C, 0xE0}, {0xD35D, 0x6C}, {0xD35E, 0x28}, {0xD35F, 0x02}, {0xD360, 0xE0}, {0xD361, 0x84}, {0xD362, 0x28},
261     {0xD363, 0x02}, {0xD364, 0x07}, {0xD365, 0xFF}, {0xD366, 0xF8}, {0xD367, 0x30}, {0xD368, 0xB8}, {0xD369, 0x63},
262     {0xD36A, 0x00}, {0xD36B, 0x08}, {0xD36C, 0x03}, {0xD36D, 0xFF}, {0xD36E, 0xFF}, {0xD36F, 0xC0}, {0xD370, 0x85},
263     {0xD371, 0x4E}, {0xD372, 0x00}, {0xD373, 0x00}, {0xD374, 0x03}, {0xD375, 0xFF}, {0xD376, 0xFF}, {0xD377, 0xE7},
264     {0xD378, 0xD4}, {0xD379, 0x01}, {0xD37A, 0x40}, {0xD37B, 0x18}, {0xD37C, 0x9C}, {0xD37D, 0x60}, {0xD37E, 0x00},
265     {0xD37F, 0x00}, {0xD380, 0x03}, {0xD381, 0xFF}, {0xD382, 0xFF}, {0xD383, 0xDB}, {0xD384, 0xD4}, {0xD385, 0x01},
266     {0xD386, 0x18}, {0xD387, 0x14}, {0xD388, 0x03}, {0xD389, 0xFF}, {0xD38A, 0xFF}, {0xD38B, 0xCE}, {0xD38C, 0x9D},
267     {0xD38D, 0x6B}, {0xD38E, 0x00}, {0xD38F, 0xFF}, {0xD390, 0x03}, {0xD391, 0xFF}, {0xD392, 0xFF}, {0xD393, 0xC6},
268     {0xD394, 0x9C}, {0xD395, 0x63}, {0xD396, 0x00}, {0xD397, 0xFF}, {0xD398, 0xA8}, {0xD399, 0xE3}, {0xD39A, 0x38},
269     {0xD39B, 0x0F}, {0xD39C, 0x8C}, {0xD39D, 0x84}, {0xD39E, 0x00}, {0xD39F, 0x00}, {0xD3A0, 0xA8}, {0xD3A1, 0xA3},
270     {0xD3A2, 0x38}, {0xD3A3, 0x0E}, {0xD3A4, 0xA8}, {0xD3A5, 0xC3}, {0xD3A6, 0x6E}, {0xD3A7, 0x42}, {0xD3A8, 0xD8},
271     {0xD3A9, 0x07}, {0xD3AA, 0x20}, {0xD3AB, 0x00}, {0xD3AC, 0x8C}, {0xD3AD, 0x66}, {0xD3AE, 0x00}, {0xD3AF, 0x00},
272     {0xD3B0, 0xD8}, {0xD3B1, 0x05}, {0xD3B2, 0x18}, {0xD3B3, 0x00}, {0xD3B4, 0x85}, {0xD3B5, 0x21}, {0xD3B6, 0x00},
273     {0xD3B7, 0x00}, {0xD3B8, 0x85}, {0xD3B9, 0x41}, {0xD3BA, 0x00}, {0xD3BB, 0x04}, {0xD3BC, 0x85}, {0xD3BD, 0x81},
274     {0xD3BE, 0x00}, {0xD3BF, 0x08}, {0xD3C0, 0x85}, {0xD3C1, 0xC1}, {0xD3C2, 0x00}, {0xD3C3, 0x0C}, {0xD3C4, 0x86},
275     {0xD3C5, 0x01}, {0xD3C6, 0x00}, {0xD3C7, 0x10}, {0xD3C8, 0x44}, {0xD3C9, 0x00}, {0xD3CA, 0x48}, {0xD3CB, 0x00},
276     {0xD3CC, 0x9C}, {0xD3CD, 0x21}, {0xD3CE, 0x00}, {0xD3CF, 0x1C}, {0xD3D0, 0x9C}, {0xD3D1, 0x21}, {0xD3D2, 0xFF},
277     {0xD3D3, 0xFC}, {0xD3D4, 0xD4}, {0xD3D5, 0x01}, {0xD3D6, 0x48}, {0xD3D7, 0x00}, {0xD3D8, 0x18}, {0xD3D9, 0x60},
278     {0xD3DA, 0x00}, {0xD3DB, 0x01}, {0xD3DC, 0xA8}, {0xD3DD, 0x63}, {0xD3DE, 0x07}, {0xD3DF, 0x80}, {0xD3E0, 0x8C},
279     {0xD3E1, 0x63}, {0xD3E2, 0x00}, {0xD3E3, 0x68}, {0xD3E4, 0xBC}, {0xD3E5, 0x03}, {0xD3E6, 0x00}, {0xD3E7, 0x00},
280     {0xD3E8, 0x10}, {0xD3E9, 0x00}, {0xD3EA, 0x00}, {0xD3EB, 0x0C}, {0xD3EC, 0x15}, {0xD3ED, 0x00}, {0xD3EE, 0x00},
281     {0xD3EF, 0x00}, {0xD3F0, 0x07}, {0xD3F1, 0xFF}, {0xD3F2, 0xD9}, {0xD3F3, 0x98}, {0xD3F4, 0x15}, {0xD3F5, 0x00},
282     {0xD3F6, 0x00}, {0xD3F7, 0x00}, {0xD3F8, 0x18}, {0xD3F9, 0x60}, {0xD3FA, 0x80}, {0xD3FB, 0x06}, {0xD3FC, 0xA8},
283     {0xD3FD, 0x63}, {0xD3FE, 0xC4}, {0xD3FF, 0xB8}, {0xD400, 0x8C}, {0xD401, 0x63}, {0xD402, 0x00}, {0xD403, 0x00},
284     {0xD404, 0xBC}, {0xD405, 0x23}, {0xD406, 0x00}, {0xD407, 0x01}, {0xD408, 0x10}, {0xD409, 0x00}, {0xD40A, 0x00},
285     {0xD40B, 0x25}, {0xD40C, 0x9D}, {0xD40D, 0x00}, {0xD40E, 0x00}, {0xD40F, 0x00}, {0xD410, 0x00}, {0xD411, 0x00},
286     {0xD412, 0x00}, {0xD413, 0x0B}, {0xD414, 0xB8}, {0xD415, 0xE8}, {0xD416, 0x00}, {0xD417, 0x02}, {0xD418, 0x07},
287     {0xD419, 0xFF}, {0xD41A, 0xD6}, {0xD41B, 0x24}, {0xD41C, 0x15}, {0xD41D, 0x00}, {0xD41E, 0x00}, {0xD41F, 0x00},
288     {0xD420, 0x18}, {0xD421, 0x60}, {0xD422, 0x80}, {0xD423, 0x06}, {0xD424, 0xA8}, {0xD425, 0x63}, {0xD426, 0xC4},
289     {0xD427, 0xB8}, {0xD428, 0x8C}, {0xD429, 0x63}, {0xD42A, 0x00}, {0xD42B, 0x00}, {0xD42C, 0xBC}, {0xD42D, 0x23},
290     {0xD42E, 0x00}, {0xD42F, 0x01}, {0xD430, 0x10}, {0xD431, 0x00}, {0xD432, 0x00}, {0xD433, 0x1B}, {0xD434, 0x9D},
291     {0xD435, 0x00}, {0xD436, 0x00}, {0xD437, 0x00}, {0xD438, 0xB8}, {0xD439, 0xE8}, {0xD43A, 0x00}, {0xD43B, 0x02},
292     {0xD43C, 0x9C}, {0xD43D, 0xC0}, {0xD43E, 0x00}, {0xD43F, 0x00}, {0xD440, 0x18}, {0xD441, 0xA0}, {0xD442, 0x80},
293     {0xD443, 0x06}, {0xD444, 0xE0}, {0xD445, 0x67}, {0xD446, 0x30}, {0xD447, 0x00}, {0xD448, 0xA8}, {0xD449, 0xA5},
294     {0xD44A, 0xCE}, {0xD44B, 0xB0}, {0xD44C, 0x19}, {0xD44D, 0x60}, {0xD44E, 0x00}, {0xD44F, 0x01}, {0xD450, 0xA9},
295     {0xD451, 0x6B}, {0xD452, 0x06}, {0xD453, 0x14}, {0xD454, 0xE0}, {0xD455, 0x83}, {0xD456, 0x28}, {0xD457, 0x00},
296     {0xD458, 0x9C}, {0xD459, 0xC6}, {0xD45A, 0x00}, {0xD45B, 0x01}, {0xD45C, 0xE0}, {0xD45D, 0x63}, {0xD45E, 0x18},
297     {0xD45F, 0x00}, {0xD460, 0x8C}, {0xD461, 0x84}, {0xD462, 0x00}, {0xD463, 0x00}, {0xD464, 0xE0}, {0xD465, 0xA3},
298     {0xD466, 0x58}, {0xD467, 0x00}, {0xD468, 0xA4}, {0xD469, 0xC6}, {0xD46A, 0x00}, {0xD46B, 0xFF}, {0xD46C, 0xB8},
299     {0xD46D, 0x64}, {0xD46E, 0x00}, {0xD46F, 0x18}, {0xD470, 0xBC}, {0xD471, 0x46}, {0xD472, 0x00}, {0xD473, 0x03},
300     {0xD474, 0x94}, {0xD475, 0x85}, {0xD476, 0x00}, {0xD477, 0x00}, {0xD478, 0xB8}, {0xD479, 0x63}, {0xD47A, 0x00},
301     {0xD47B, 0x98}, {0xD47C, 0xE0}, {0xD47D, 0x64}, {0xD47E, 0x18}, {0xD47F, 0x00}, {0xD480, 0x0F}, {0xD481, 0xFF},
302     {0xD482, 0xFF}, {0xD483, 0xF0}, {0xD484, 0xDC}, {0xD485, 0x05}, {0xD486, 0x18}, {0xD487, 0x00}, {0xD488, 0x9C},
303     {0xD489, 0x68}, {0xD48A, 0x00}, {0xD48B, 0x01}, {0xD48C, 0xA5}, {0xD48D, 0x03}, {0xD48E, 0x00}, {0xD48F, 0xFF},
304     {0xD490, 0xBC}, {0xD491, 0x48}, {0xD492, 0x00}, {0xD493, 0x01}, {0xD494, 0x0F}, {0xD495, 0xFF}, {0xD496, 0xFF},
305     {0xD497, 0xEA}, {0xD498, 0xB8}, {0xD499, 0xE8}, {0xD49A, 0x00}, {0xD49B, 0x02}, {0xD49C, 0x18}, {0xD49D, 0x60},
306     {0xD49E, 0x00}, {0xD49F, 0x01}, {0xD4A0, 0xA8}, {0xD4A1, 0x63}, {0xD4A2, 0x06}, {0xD4A3, 0x14}, {0xD4A4, 0x07},
307     {0xD4A5, 0xFF}, {0xD4A6, 0xE4}, {0xD4A7, 0x05}, {0xD4A8, 0x9C}, {0xD4A9, 0x83}, {0xD4AA, 0x00}, {0xD4AB, 0x10},
308     {0xD4AC, 0x85}, {0xD4AD, 0x21}, {0xD4AE, 0x00}, {0xD4AF, 0x00}, {0xD4B0, 0x44}, {0xD4B1, 0x00}, {0xD4B2, 0x48},
309     {0xD4B3, 0x00}, {0xD4B4, 0x9C}, {0xD4B5, 0x21}, {0xD4B6, 0x00}, {0xD4B7, 0x04}, {0xD4B8, 0x18}, {0xD4B9, 0x60},
310     {0xD4BA, 0x00}, {0xD4BB, 0x01}, {0xD4BC, 0x9C}, {0xD4BD, 0x80}, {0xD4BE, 0xFF}, {0xD4BF, 0xFF}, {0xD4C0, 0xA8},
311     {0xD4C1, 0x63}, {0xD4C2, 0x09}, {0xD4C3, 0xEF}, {0xD4C4, 0xD8}, {0xD4C5, 0x03}, {0xD4C6, 0x20}, {0xD4C7, 0x00},
312     {0xD4C8, 0x18}, {0xD4C9, 0x60}, {0xD4CA, 0x80}, {0xD4CB, 0x06}, {0xD4CC, 0xA8}, {0xD4CD, 0x63}, {0xD4CE, 0xC9},
313     {0xD4CF, 0xEF}, {0xD4D0, 0xD8}, {0xD4D1, 0x03}, {0xD4D2, 0x20}, {0xD4D3, 0x00}, {0xD4D4, 0x44}, {0xD4D5, 0x00},
314     {0xD4D6, 0x48}, {0xD4D7, 0x00}, {0xD4D8, 0x15}, {0xD4D9, 0x00}, {0xD4DA, 0x00}, {0xD4DB, 0x00}, {0xD4DC, 0x18},
315     {0xD4DD, 0x80}, {0xD4DE, 0x00}, {0xD4DF, 0x01}, {0xD4E0, 0xA8}, {0xD4E1, 0x84}, {0xD4E2, 0x0A}, {0xD4E3, 0x12},
316     {0xD4E4, 0x8C}, {0xD4E5, 0x64}, {0xD4E6, 0x00}, {0xD4E7, 0x00}, {0xD4E8, 0xBC}, {0xD4E9, 0x03}, {0xD4EA, 0x00},
317     {0xD4EB, 0x00}, {0xD4EC, 0x13}, {0xD4ED, 0xFF}, {0xD4EE, 0xFF}, {0xD4EF, 0xFE}, {0xD4F0, 0x15}, {0xD4F1, 0x00},
318     {0xD4F2, 0x00}, {0xD4F3, 0x00}, {0xD4F4, 0x44}, {0xD4F5, 0x00}, {0xD4F6, 0x48}, {0xD4F7, 0x00}, {0xD4F8, 0x15},
319     {0xD4F9, 0x00}, {0xD4FA, 0x00}, {0xD4FB, 0x00}, {0xD4FC, 0x00}, {0xD4FD, 0x00}, {0xD4FE, 0x00}, {0xD4FF, 0x00},
320     {0xD500, 0x00}, {0xD501, 0x00}, {0xD502, 0x00}, {0xD503, 0x00}, {0x6F0E, 0x33}, {0x6F0F, 0x33}, {0x460E, 0x08},
321     {0x460F, 0x01}, {0x4610, 0x00}, {0x4611, 0x01}, {0x4612, 0x00}, {0x4613, 0x01}, {0x4605, 0x08}, {0x4608, 0x00},
322     {0x4609, 0x08}, {0x6804, 0x00}, {0x6805, 0x06}, {0x6806, 0x00}, {0x5120, 0x00}, {0x3510, 0x00}, {0x3504, 0x00},
323     {0x6800, 0x00}, {0x6F0D, 0x0F}, {0x5000, 0xFF}, {0x5001, 0xBF}, {0x5002, 0x7E}, {0x5003, 0x0C}, {0x503D, 0x00},
324     {0xC450, 0x01}, {0xC452, 0x04}, {0xC453, 0x00}, {0xC454, 0x00}, {0xC455, 0x00}, {0xC456, 0x00}, {0xC457, 0x00},
325     {0xC458, 0x00}, {0xC459, 0x00}, {0xC45B, 0x00}, {0xC45C, 0x00}, {0xC45D, 0x00}, {0xC45E, 0x00}, {0xC45F, 0x00},
326     {0xC460, 0x00}, {0xC461, 0x01}, {0xC462, 0x01}, {0xC464, 0x88}, {0xC465, 0x00}, {0xC466, 0x8A}, {0xC467, 0x00},
327     {0xC468, 0x86}, {0xC469, 0x00}, {0xC46A, 0x40}, {0xC46B, 0x50}, {0xC46C, 0x30}, {0xC46D, 0x28}, {0xC46E, 0x60},
328     {0xC46F, 0x40}, {0xC47C, 0x01}, {0xC47D, 0x38}, {0xC47E, 0x00}, {0xC47F, 0x00}, {0xC480, 0x00}, {0xC481, 0xFF},
329     {0xC482, 0x00}, {0xC483, 0x40}, {0xC484, 0x00}, {0xC485, 0x18}, {0xC486, 0x00}, {0xC487, 0x18}, {0xC488, 0x34},
330     {0xC489, 0x00}, {0xC48A, 0x34}, {0xC48B, 0x00}, {0xC48C, 0x00}, {0xC48D, 0x04}, {0xC48E, 0x00}, {0xC48F, 0x04},
331     {0xC490, 0x07}, {0xC492, 0x20}, {0xC493, 0x08}, {0xC498, 0x02}, {0xC499, 0x00}, {0xC49A, 0x02}, {0xC49B, 0x00},
332     {0xC49C, 0x02}, {0xC49D, 0x00}, {0xC49E, 0x02}, {0xC49F, 0x60}, {0xC4A0, 0x03}, {0xC4A1, 0x00}, {0xC4A2, 0x04},
333     {0xC4A3, 0x00}, {0xC4A4, 0x00}, {0xC4A5, 0x10}, {0xC4A6, 0x00}, {0xC4A7, 0x40}, {0xC4A8, 0x00}, {0xC4A9, 0x80},
334     {0xC4AA, 0x0D}, {0xC4AB, 0x00}, {0xC4AC, 0x0F}, {0xC4AD, 0xC0}, {0xC4B4, 0x01}, {0xC4B5, 0x01}, {0xC4B6, 0x00},
335     {0xC4B7, 0x01}, {0xC4B8, 0x00}, {0xC4B9, 0x01}, {0xC4BA, 0x01}, {0xC4BB, 0x00}, {0xC4BC, 0x01}, {0xC4BD, 0x60},
336     {0xC4BE, 0x02}, {0xC4BF, 0x33}, {0xC4C8, 0x03}, {0xC4C9, 0xD0}, {0xC4CA, 0x0E}, {0xC4CB, 0x00}, {0xC4CC, 0x10},
337     {0xC4CD, 0x18}, {0xC4CE, 0x10}, {0xC4CF, 0x18}, {0xC4D0, 0x04}, {0xC4D1, 0x80}, {0xC4E0, 0x04}, {0xC4E1, 0x02},
338     {0xC4E2, 0x01}, {0xC4E4, 0x10}, {0xC4E5, 0x20}, {0xC4E6, 0x30}, {0xC4E7, 0x40}, {0xC4E8, 0x50}, {0xC4E9, 0x60},
339     {0xC4EA, 0x70}, {0xC4EB, 0x80}, {0xC4EC, 0x90}, {0xC4ED, 0xA0}, {0xC4EE, 0xB0}, {0xC4EF, 0xC0}, {0xC4F0, 0xD0},
340     {0xC4F1, 0xE0}, {0xC4F2, 0xF0}, {0xC4F3, 0x80}, {0xC4F4, 0x00}, {0xC4F5, 0x20}, {0xC4F6, 0x02}, {0xC4F7, 0x00},
341     {0xC4F8, 0x04}, {0xC4F9, 0x0B}, {0xC4FA, 0x00}, {0xC4FB, 0x00}, {0xC4FC, 0x01}, {0xC4FD, 0x00}, {0xC4FE, 0x04},
342     {0xC4FF, 0x02}, {0xC500, 0x48}, {0xC501, 0x74}, {0xC502, 0x58}, {0xC503, 0x80}, {0xC504, 0x05}, {0xC505, 0x80},
343     {0xC506, 0x03}, {0xC507, 0x80}, {0xC508, 0x01}, {0xC509, 0xC0}, {0xC50A, 0x01}, {0xC50B, 0xA0}, {0xC50C, 0x01},
344     {0xC50D, 0x2C}, {0xC50E, 0x01}, {0xC50F, 0x0A}, {0xC510, 0x00}, {0xC511, 0x01}, {0xC512, 0x01}, {0xC513, 0x80},
345     {0xC514, 0x04}, {0xC515, 0x00}, {0xC518, 0x03}, {0xC519, 0x48}, {0xC51A, 0x07}, {0xC51B, 0x70}, {0xC2E0, 0x00},
346     {0xC2E1, 0x51}, {0xC2E2, 0x00}, {0xC2E3, 0xD6}, {0xC2E4, 0x01}, {0xC2E5, 0x5E}, {0xC2E9, 0x01}, {0xC2EA, 0x7A},
347     {0xC2EB, 0x90}, {0xC2ED, 0x00}, {0xC2EE, 0x7A}, {0xC2EF, 0x64}, {0xC308, 0x00}, {0xC309, 0x00}, {0xC30A, 0x00},
348     {0xC30C, 0x00}, {0xC30D, 0x01}, {0xC30E, 0x00}, {0xC30F, 0x00}, {0xC310, 0x01}, {0xC311, 0x60}, {0xC312, 0xFF},
349     {0xC313, 0x08}, {0xC314, 0x01}, {0xC315, 0x7F}, {0xC316, 0xFF}, {0xC317, 0x0B}, {0xC318, 0x00}, {0xC319, 0x0C},
350     {0xC31A, 0x00}, {0xC31B, 0xE0}, {0xC31C, 0x00}, {0xC31D, 0x14}, {0xC31E, 0x00}, {0xC31F, 0xC5}, {0xC320, 0xFF},
351     {0xC321, 0x4B}, {0xC322, 0xFF}, {0xC323, 0xF0}, {0xC324, 0xFF}, {0xC325, 0xE8}, {0xC326, 0x00}, {0xC327, 0x46},
352     {0xC328, 0xFF}, {0xC329, 0xD2}, {0xC32A, 0xFF}, {0xC32B, 0xE4}, {0xC32C, 0xFF}, {0xC32D, 0xBB}, {0xC32E, 0x00},
353     {0xC32F, 0x61}, {0xC330, 0xFF}, {0xC331, 0xF9}, {0xC332, 0x00}, {0xC333, 0xD9}, {0xC334, 0x00}, {0xC335, 0x2E},
354     {0xC336, 0x00}, {0xC337, 0xB1}, {0xC338, 0xFF}, {0xC339, 0x64}, {0xC33A, 0xFF}, {0xC33B, 0xEB}, {0xC33C, 0xFF},
355     {0xC33D, 0xE8}, {0xC33E, 0x00}, {0xC33F, 0x48}, {0xC340, 0xFF}, {0xC341, 0xD0}, {0xC342, 0xFF}, {0xC343, 0xED},
356     {0xC344, 0xFF}, {0xC345, 0xAD}, {0xC346, 0x00}, {0xC347, 0x66}, {0xC348, 0x01}, {0xC349, 0x00}, {0x6700, 0x04},
357     {0x6701, 0x7B}, {0x6702, 0xFD}, {0x6703, 0xF9}, {0x6704, 0x3D}, {0x6705, 0x71}, {0x6706, 0x78}, {0x6708, 0x05},
358     {0x6F06, 0x6F}, {0x6F07, 0x00}, {0x6F0A, 0x6F}, {0x6F0B, 0x00}, {0x6F00, 0x03}, {0xC34C, 0x01}, {0xC34D, 0x00},
359     {0xC34E, 0x46}, {0xC34F, 0x55}, {0xC350, 0x00}, {0xC351, 0x40}, {0xC352, 0x00}, {0xC353, 0xFF}, {0xC354, 0x04},
360     {0xC355, 0x08}, {0xC356, 0x01}, {0xC357, 0xEF}, {0xC358, 0x30}, {0xC359, 0x01}, {0xC35A, 0x64}, {0xC35B, 0x46},
361     {0xC35C, 0x00}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0},
362     {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0},
363     {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0},
364     {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x3042, 0xF0}, {0x301B, 0xF0},
365     {0x301C, 0xF0}, {0x301A, 0xF0}, {0xCEB0, 0x00}, {0xCEB1, 0x00}, {0xCEB2, 0x00}, {0xCEB3, 0x00}, {0xCEB4, 0x00},
366     {0xCEB5, 0x00}, {0xCEB6, 0x00}, {0xCEB7, 0x00}, {0xC4BC, 0x01}, {0xC4BD, 0x60}, {0x4709, 0x10}, {0x4300, 0x3A},
367     {0x3832, 0x01}, {0x3833, 0x1A}, {0x3834, 0x03}, {0x3835, 0x48}, {0x302E, 0x01},
368 };
369 
370 static const ov10635_resolution_config_t s_ov10635ResolutionConfigs[] = {{.framePerSec = 30,
371                                                                           .resolution = (uint32_t)kVIDEO_ResolutionWXGA,
372                                                                           .regs =
373                                                                               {
374                                                                                   {0x3024, 0x01},
375                                                                                   {0x3003, 0x20},
376                                                                                   {0x3004, 0x21},
377                                                                                   {0x3005, 0x20},
378                                                                                   {0x3006, 0x91},
379                                                                                   {0x3808, 0x05},
380                                                                                   {0x3809, 0x00},
381                                                                                   {0x380a, 0x03},
382                                                                                   {0x380b, 0x20},
383                                                                               }},
384                                                                          {.framePerSec = 30,
385                                                                           .resolution = (uint32_t)kVIDEO_Resolution720P,
386                                                                           .regs       = {
387                                                                               {0x3024, 0x01},
388                                                                               {0x3003, 0x20},
389                                                                               {0x3004, 0x21},
390                                                                               {0x3005, 0x20},
391                                                                               {0x3006, 0x91},
392                                                                               {0x3808, 0x05},
393                                                                               {0x3809, 0x00},
394                                                                               {0x380a, 0x02},
395                                                                               {0x380b, 0xD0},
396                                                                           }}};
397 
398 /*******************************************************************************
399  * Code
400  ******************************************************************************/
401 
MAX9271_Write(camera_device_handle_t * handle,uint8_t i2cAddr,uint32_t reg,uint8_t value)402 static status_t MAX9271_Write(camera_device_handle_t *handle, uint8_t i2cAddr, uint32_t reg, uint8_t value)
403 {
404     uint32_t retry  = MAX9271_RETRY;
405     status_t status = kStatus_Fail;
406 
407     while (0U != (retry--))
408     {
409         status = VIDEO_I2C_WriteReg(i2cAddr, kVIDEO_RegAddr8Bit, reg, kVIDEO_RegWidth8Bit, value,
410                                     ((max9286_resource_t *)(handle->resource))->i2cSendFunc);
411         if (kStatus_Success == status)
412         {
413             break;
414         }
415         VIDEO_DelayMs(1);
416     }
417 
418     return status;
419 }
420 
OV10635_Write(camera_device_handle_t * handle,uint8_t i2cAddr,uint32_t reg,uint8_t value)421 static status_t OV10635_Write(camera_device_handle_t *handle, uint8_t i2cAddr, uint32_t reg, uint8_t value)
422 {
423     uint32_t retry  = OV10635_RETRY;
424     status_t status = kStatus_Fail;
425 
426     while (0U != (retry--))
427     {
428         status = VIDEO_I2C_WriteReg(i2cAddr, kVIDEO_RegAddr16Bit, reg, kVIDEO_RegWidth8Bit, value,
429                                     ((max9286_resource_t *)(handle->resource))->i2cSendFunc);
430         if (kStatus_Success == status)
431         {
432             break;
433         }
434         VIDEO_DelayMs(1);
435     }
436 
437     return status;
438 }
439 
OV10635_Read(camera_device_handle_t * handle,uint8_t i2cAddr,uint32_t reg,uint8_t * value)440 static status_t OV10635_Read(camera_device_handle_t *handle, uint8_t i2cAddr, uint32_t reg, uint8_t *value)
441 {
442     uint32_t retry  = OV10635_RETRY;
443     status_t status = kStatus_Fail;
444 
445     while (0U != (retry--))
446     {
447         status = VIDEO_I2C_ReadReg(i2cAddr, kVIDEO_RegAddr16Bit, reg, kVIDEO_RegWidth8Bit, value,
448                                    ((max9286_resource_t *)(handle->resource))->i2cReceiveFunc);
449         if (kStatus_Success == status)
450         {
451             break;
452         }
453         VIDEO_DelayMs(1);
454     }
455 
456     return status;
457 }
458 
OV10635_GetResolutionConfig(const camera_config_t * cameraConfig)459 static const ov10635_resolution_config_t *OV10635_GetResolutionConfig(const camera_config_t *cameraConfig)
460 {
461     uint8_t i;
462     const ov10635_resolution_config_t *config = NULL;
463 
464     for (i = 0; i < ARRAY_SIZE(s_ov10635ResolutionConfigs); i++)
465     {
466         if ((cameraConfig->resolution == s_ov10635ResolutionConfigs[i].resolution) &&
467             (cameraConfig->framePerSec == s_ov10635ResolutionConfigs[i].framePerSec))
468         {
469             config = &s_ov10635ResolutionConfigs[i];
470             break;
471         }
472     }
473 
474     return config;
475 }
476 
OV10635_SetResolutionConfig(camera_device_handle_t * handle,uint8_t index,const ov10635_resolution_config_t * config)477 static status_t OV10635_SetResolutionConfig(camera_device_handle_t *handle,
478                                             uint8_t index,
479                                             const ov10635_resolution_config_t *config)
480 {
481     uint32_t i;
482     status_t status;
483     uint8_t i2cAddr = I2C_ADDR_OV10635_N(index);
484 
485     for (i = 0; i < OV10635_RESOLUTION_CONFIG_REG_NUM; i++)
486     {
487         status = OV10635_Write(handle, i2cAddr, config->regs[i].reg, config->regs[i].value);
488         if (status != kStatus_Success)
489         {
490             return status;
491         }
492     }
493 
494     return kStatus_Success;
495 }
496 
MAX9286_ReorderVC(camera_device_handle_t * handle,uint8_t linkAvailableMask)497 static status_t MAX9286_ReorderVC(camera_device_handle_t *handle, uint8_t linkAvailableMask)
498 {
499     uint8_t reg           = 0;
500     uint8_t i             = 0;
501     uint8_t availableVC   = 0;
502     uint8_t unavailableVC = 3;
503 
504     for (i = 0; i < MAX9271_MAX_COUNT; i++)
505     {
506         if (0U != (linkAvailableMask & (1U << i)))
507         {
508             /* Link available. */
509             reg |= (availableVC << (2U * i));
510             availableVC++;
511         }
512         else
513         {
514             /* Link not available. */
515             reg |= (unavailableVC << (2U * i));
516             unavailableVC--;
517         }
518     }
519 
520     return MAX9286_Write(handle, 0x0B, reg);
521 }
522 
OV10635_Init(camera_device_handle_t * handle,uint8_t index)523 static status_t OV10635_Init(camera_device_handle_t *handle, uint8_t index)
524 {
525     uint32_t i;
526     status_t status;
527     uint8_t i2cAddr = I2C_ADDR_OV10635_N(index);
528     uint8_t reg     = 0U;
529 
530     /* Verify the camera ID. */
531     status = OV10635_Read(handle, i2cAddr, OV10635_REG_PID, &reg);
532     if ((status != kStatus_Success) || (reg != OV10635_PID))
533     {
534         return kStatus_Fail;
535     }
536 
537     status = OV10635_Read(handle, i2cAddr, OV10635_REG_VER, &reg);
538     if ((status != kStatus_Success) || (reg != OV10635_VER))
539     {
540         return kStatus_Fail;
541     }
542 
543     for (i = 0; i < ARRAY_SIZE(ov10635Firmware); i++)
544     {
545         status = OV10635_Write(handle, i2cAddr, ov10635Firmware[i].reg, ov10635Firmware[i].value);
546         if (status != kStatus_Success)
547         {
548             return status;
549         }
550     }
551 
552     return kStatus_Success;
553 }
554 
MAX9286_InitHardware(camera_device_handle_t * handle,uint8_t enableCameraMask,const camera_config_t * config)555 static status_t MAX9286_InitHardware(camera_device_handle_t *handle,
556                                      uint8_t enableCameraMask,
557                                      const camera_config_t *config)
558 {
559     uint32_t i;
560     uint8_t enabledLink = 0;
561     status_t status;
562     const ov10635_resolution_config_t *resolutionConfig;
563 
564     resolutionConfig = OV10635_GetResolutionConfig(config);
565 
566     if (NULL == resolutionConfig)
567     {
568         return kStatus_InvalidArgument;
569     }
570 
571     /* Disable CSI output. */
572     (void)MAX9286_Write(handle, 0x15, 0x03);
573 
574     /* Enable PRBS test. */
575     (void)MAX9286_Write(handle, 0x0E, 0x5F);
576     VIDEO_DelayMs(10);
577 
578     /* Enable Custom Reverse Channel & First Pulse Length*/
579     (void)MAX9286_Write(handle, 0x3F, 0x4F);
580     VIDEO_DelayMs(2);
581 
582     /* First pulse length rise time changed from 300ns to 200ns */
583     (void)MAX9286_Write(handle, 0x3B, 0x1E);
584     VIDEO_DelayMs(2);
585 
586     /* Optional - Enable configuration link */
587     (void)MAX9271_Write(handle, I2C_ADDR_MAX9271_N(0), 0x04, 0x43);
588     VIDEO_DelayMs(5);
589 
590     /* Enable high threshold for reverse channel input
591      * buffer. This increases immunity to power supply
592      * noise when the coaxial link is used for power as
593      * well as signal.
594      */
595     (void)MAX9271_Write(handle, I2C_ADDR_MAX9271_N(0), 0x08, 0x01);
596     VIDEO_DelayMs(2);
597 
598     /* Increase reverse amplitude from 100mV to 170mV. */
599     (void)MAX9286_Write(handle, 0x3B, 0x19);
600     VIDEO_DelayMs(10);
601 
602     /*
603      * CSI-2 Output uses YUV 422 8-bit.
604      * Use double input mode.
605      * Enable CSI data lanes D0-D3.
606      */
607     (void)MAX9286_Write(handle, 0x12, 0xF3);
608 
609     /* Internal frame sync uses automatic mode */
610     (void)MAX9286_Write(handle, 0x01, 0x02);
611 
612     /*
613      * Auto detect link used for CSI clock source.
614      * Disable Internal VSYNC generation.
615      * Enable all input link
616      */
617     (void)MAX9286_Write(handle, 0x00, 0xEF);
618     VIDEO_DelayMs(2);
619 
620     /* Frame Sync, Automatic mode. */
621     (void)MAX9286_Write(handle, 0x01, 0x02);
622     VIDEO_DelayMs(200);
623 
624     /*
625      * Detect available link.
626      */
627     (void)MAX9286_Read(handle, 0x49, &enabledLink);
628 
629     enabledLink = (enabledLink | (enabledLink >> 4)) & 0x0FU;
630 
631     enabledLink &= enableCameraMask;
632 
633     /* The camera not valid. */
634     if (0U == enabledLink)
635     {
636         /* No valid link. */
637         return kStatus_Fail;
638     }
639 
640     /* Disable PRBS test. */
641     (void)MAX9286_Write(handle, 0x0E, 0x50);
642 
643     /* Select the first valid. */
644     enabledLink = (~(enabledLink - 1U)) & enabledLink;
645 
646     (void)MAX9286_ReorderVC(handle, enabledLink);
647 
648     /* Enable available links. */
649     (void)MAX9286_Write(handle, 0x00, 0xE0UL | enabledLink);
650 
651     /*
652      * Enable DBL
653      * Set Edge Select 1=Rise / 0=Fall
654      * Enable HS/VS encoding
655      */
656     (void)MAX9271_Write(handle, I2C_ADDR_MAX9271_N(0), 0x07, 0x84);
657 
658     /* Setup the links. */
659     for (i = 1; i <= MAX9271_MAX_COUNT; i++)
660     {
661         if ((enabledLink & (1U << (i - 1U))) == 0U)
662         {
663             continue;
664         }
665 
666         /* Enable Link i Reverse Channel. */
667         (void)MAX9286_Write(handle, 0x0A, (0x11UL << (i - 1U)));
668         VIDEO_DelayMs(2);
669 
670         /* Change serializer slave address. */
671         (void)MAX9271_Write(handle, I2C_ADDR_MAX9271_N(0), 0x00, I2C_ADDR_MAX9271_N(i) << 1);
672         VIDEO_DelayMs(2);
673 
674         /* Deserializer device address. */
675         (void)MAX9271_Write(handle, I2C_ADDR_MAX9271_N(0), 0x01, I2C_ADDR_MAX9286 << 1);
676 
677         VIDEO_DelayMs(2);
678 
679         /* Unique Link i image sensor slave address */
680         (void)MAX9271_Write(handle, I2C_ADDR_MAX9271_N(i), 0x09, I2C_ADDR_OV10635_N(i) << 1);
681 
682         /* Link i image sensor slave address */
683         (void)MAX9271_Write(handle, I2C_ADDR_MAX9271_N(i), 0x0A, I2C_ADDR_OV10635_N(0) << 1);
684 
685         /* Serializer broadcast address */
686         (void)MAX9271_Write(handle, I2C_ADDR_MAX9271_N(i), 0x0B, I2C_ADDR_MAX9271_N(5) << 1);
687 
688         /* Link i serializer address */
689         (void)MAX9271_Write(handle, I2C_ADDR_MAX9271_N(i), 0x0C, I2C_ADDR_MAX9271_N(i) << 1);
690         VIDEO_DelayMs(1);
691     }
692 
693     /* Enable Link Reverse Channel. */
694     (void)MAX9286_Write(handle, 0x0A, (uint32_t)enabledLink | ((uint32_t)enabledLink << 4U));
695 
696     /* Disable auto acknowledge. */
697     (void)MAX9286_Write(handle, 0x34, 0x36);
698 
699     for (i = 1; i <= MAX9271_MAX_COUNT; i++)
700     {
701         if ((enabledLink & (1U << (i - 1U))) == 0U)
702         {
703             continue;
704         }
705 
706         status = OV10635_Init(handle, (uint8_t)i);
707 
708         if (status != kStatus_Success)
709         {
710             return status;
711         }
712 
713         status = OV10635_SetResolutionConfig(handle, (uint8_t)i, resolutionConfig);
714 
715         if (status != kStatus_Success)
716         {
717             return status;
718         }
719     }
720 
721     /* Enable auto acknowledge. */
722     (void)MAX9286_Write(handle, 0x34, 0xB6);
723 
724     /* Enable all serial links */
725     (void)MAX9271_Write(handle, I2C_ADDR_MAX9271_N(5), 0x04, 0x83);
726     VIDEO_DelayMs(5);
727 
728     /* Enable CSI output. */
729     (void)MAX9286_Write(handle, 0x15, 0x9B);
730     VIDEO_DelayMs(10);
731 
732     return kStatus_Success;
733 }
734 
MAX9286_Init(camera_device_handle_t * handle,const camera_config_t * config)735 status_t MAX9286_Init(camera_device_handle_t *handle, const camera_config_t *config)
736 {
737     /* Any camera could be used. */
738     const max9286_ext_config_t extConfig = {0xFF};
739 
740     return MAX9286_InitExt(handle, config, &extConfig);
741 }
742 
MAX9286_InitExt(camera_device_handle_t * handle,const camera_config_t * config,const void * extConfig)743 status_t MAX9286_InitExt(camera_device_handle_t *handle, const camera_config_t *config, const void *extConfig)
744 {
745     status_t status;
746     uint8_t reg = 0;
747     uint8_t enableCameraMask;
748 
749     const max9286_resource_t *resource = (const max9286_resource_t *)(handle->resource);
750 
751     if (NULL != extConfig)
752     {
753         enableCameraMask = ((const max9286_ext_config_t *)extConfig)->enableCameraMask & 0x0FU;
754     }
755     else
756     {
757         enableCameraMask = 0xFFU;
758     }
759 
760     if (kCAMERA_InterfaceMIPI != config->interface)
761     {
762         return kStatus_InvalidArgument;
763     }
764 
765     /* Only support YUV422 */
766     if (kVIDEO_PixelFormatYUYV != config->pixelFormat)
767     {
768         return kStatus_InvalidArgument;
769     }
770 
771     /* Perform hardware reset. */
772     resource->pullPowerDownPin(false);
773     VIDEO_DelayMs(1);
774     resource->pullPowerDownPin(true);
775     VIDEO_DelayMs(10);
776 
777     /* Identify the device. */
778     status = MAX9286_Read(handle, MAX9286_REG_ID, &reg);
779     if ((status != kStatus_Success) || (reg != MAX9286_ID))
780     {
781         return kStatus_Fail;
782     }
783 
784     return MAX9286_InitHardware(handle, enableCameraMask, config);
785 }
786 
MAX9286_Deinit(camera_device_handle_t * handle)787 status_t MAX9286_Deinit(camera_device_handle_t *handle)
788 {
789     ((max9286_resource_t *)(handle->resource))->pullPowerDownPin(false);
790 
791     return kStatus_Success;
792 }
793 
MAX9286_Start(camera_device_handle_t * handle)794 status_t MAX9286_Start(camera_device_handle_t *handle)
795 {
796     return MAX9286_Write(handle, 0x15, 0x1B);
797 }
798 
MAX9286_Stop(camera_device_handle_t * handle)799 status_t MAX9286_Stop(camera_device_handle_t *handle)
800 {
801     return MAX9286_Write(handle, 0x15, 0x03);
802 }
803 
MAX9286_Control(camera_device_handle_t * handle,camera_device_cmd_t cmd,int32_t arg)804 status_t MAX9286_Control(camera_device_handle_t *handle, camera_device_cmd_t cmd, int32_t arg)
805 {
806     return kStatus_InvalidArgument;
807 }
808