55#include "global.h"
66#include "hardware.h"
77#include "i2c.h"
8+ #include "msp_displayport.h"
89#include "print.h"
910
1011uint8_t g_camera_switch = SWITCH_TYPE_NONE ;
1112uint8_t g_camera_id = 0 ;
1213uint8_t g_max_camera = 0 ;
1314uint8_t g_manual_camera_sel = 0 ;
15+ static uint8_t camera_list [3 ] = {255 , 254 , 253 };
1416
1517/////////////////////////////////////////////////////////////////
1618// MAX7315
@@ -140,70 +142,95 @@ void pca9557_set(uint8_t reg, uint8_t val) {
140142 I2C_Write8 (ADDR_PCA9557 , reg , val );
141143}
142144
145+ // Read from 3 camera switch
146+ uint8_t hdzcs_get (uint8_t reg ) {
147+ return I2C_Read8 (ADDR_HDZCS , reg );
148+ }
149+
150+ // Write to 3 camera switch
151+ void hdzcs_set (uint8_t reg , uint8_t val ) {
152+ I2C_Write8_Wait (10 , ADDR_HDZCS , reg , val );
153+ }
154+
143155uint8_t get_camera_switch_type (void ) {
144156 uint8_t camera_switch = SWITCH_TYPE_NONE ;
145157
146158 if ((pi4io_get (0x01 ) & 0xE0 ) == 0xA0 ) { // device ID register
147159 camera_switch = SWITCH_TYPE_PI4IO ;
148160 } else if (pca9557_get (0x02 ) == 0xF0 ) { // polarity inversion register defaults to 0xF0
149161 camera_switch = SWITCH_TYPE_PCA9557 ;
162+ } else if (hdzcs_get (0xff ) == 0x01 ) {
163+ camera_switch = SWITCH_TYPE_HDZCS ;
150164 }
151165
152166 return camera_switch ;
153167}
154168
155169void select_camera (uint8_t camera_id ) {
156- if ( g_camera_switch )
157- {
170+ static uint8_t camera_last = 0x00 ;
171+ if ( g_camera_switch ) {
158172 // Check camera id is within range, else default to 1
159173 uint8_t camera = (camera_id == 0 || camera_id > g_max_camera ) ? 1 : camera_id ;
160174 if (g_camera_id != camera ) {
161175 g_camera_id = camera ;
162176
163177 uint8_t command ;
164178 switch (g_camera_id ) {
165- case 1 :
166- default :
167- command = (g_camera_switch == SWITCH_TYPE_PI4IO ) ? 0x11 : 0x1B ;
168- break ;
169- case 2 :
170- command = (g_camera_switch == SWITCH_TYPE_PI4IO ) ? 0x64 : 0x16 ;
171- break ;
172- case 3 :
173- command = (g_camera_switch == SWITCH_TYPE_PI4IO ) ? 0x11 : 0x0D ;
174- break ;
179+ case 1 :
180+ default :
181+ command = (g_camera_switch == SWITCH_TYPE_PI4IO ) ? 0x11 : 0x1B ;
182+ break ;
183+ case 2 :
184+ command = (g_camera_switch == SWITCH_TYPE_PI4IO ) ? 0x64 : 0x16 ;
185+ break ;
186+ case 3 :
187+ command = (g_camera_switch == SWITCH_TYPE_PI4IO ) ? 0x11 : 0x0D ;
188+ break ;
175189 }
176190
177191 if (g_camera_switch == SWITCH_TYPE_PI4IO ) {
178192 pi4io_set (0x05 , command );
179- }
180- else { // SWITCH_TYPE_PCA9557
193+ } else if (g_camera_switch == SWITCH_TYPE_PCA9557 ) { // SWITCH_TYPE_PCA9557
181194 pca9557_set (0x01 , command );
182- WAIT (200 ); // wait for camera power up
195+ WAIT (200 ); // wait for camera power up
196+ } else if (g_camera_switch == SWITCH_TYPE_HDZCS ) {
197+ hdzcs_set (0x00 , g_camera_id );
183198 }
184- camera_switch_profile ();
199+
200+ if (camera_last != camera_list [g_camera_id - 1 ]) {
201+ if (camera_list [g_camera_id - 1 ] < CAMERA_TYPE_NUM ) { // camera has inited
202+ camera_reinit ();
203+ } else {
204+ camera_init ();
205+ camera_list [g_camera_id - 1 ] = camera_type ;
206+ }
207+ camera_last = camera_type ;
208+ }
209+
210+ resync_vrx_vtmg ();
185211 }
186212 }
187213}
188214
189215void camera_switch_init () {
190216 g_camera_switch = get_camera_switch_type ();
191217 if (g_camera_switch == SWITCH_TYPE_PI4IO ) {
192- //pi4io_set(0x01, 0xFF); // reset
193- pi4io_set (0x0B , 0xFF ); // Disable pullup/pulldown resistors
194- pi4io_set (0x11 , 0xFF ); // Disable interrupts on inputs
195- pi4io_get (0x13 ); // De-assert the interrrupt
196- pi4io_set (0x03 , 0x77 ); // Set P3 and P7 as inputs
197- pi4io_set (0x07 , 0x00 ); // Set outputs to follow the output port register
198- pi4io_set (0x05 , 0x11 ); // camera 1 default
218+ // pi4io_set(0x01, 0xFF); // reset
219+ pi4io_set (0x0B , 0xFF ); // Disable pullup/pulldown resistors
220+ pi4io_set (0x11 , 0xFF ); // Disable interrupts on inputs
221+ pi4io_get (0x13 ); // De-assert the interrrupt
222+ pi4io_set (0x03 , 0x77 ); // Set P3 and P7 as inputs
223+ pi4io_set (0x07 , 0x00 ); // Set outputs to follow the output port register
224+ pi4io_set (0x05 , 0x11 ); // camera 1 default
199225 g_max_camera = PI4IO_CAMS ;
200226 } else if (g_camera_switch == SWITCH_TYPE_PCA9557 ) {
201227 g_max_camera = PCA9557_CAMS ;
202- pca9557_set (0x03 , 0x00 ); // all outputs
203- pca9557_set (0x01 , 0x1B ); // camera 1 default
204- WAIT (200 ); // wait for camera power up
205- } else {
206- g_camera_id = 1 ;
228+ pca9557_set (0x03 , 0x00 ); // all outputs
229+ pca9557_set (0x01 , 0x1B ); // camera 1 default
230+ WAIT (200 ); // wait for camera power up
231+ } else if (g_camera_switch == SWITCH_TYPE_HDZCS ) {
232+ g_max_camera = HDZCS_CAMS ;
233+ hdzcs_set (0x00 , 0x01 ); // camera 1 default
207234 }
208235}
209236
@@ -217,5 +244,28 @@ void manual_select_camera(void) {
217244 uint8_t camera_id = ((command & 0x80 ) >> 7 ) + 1 ;
218245 select_camera (camera_id );
219246 }
247+ } else if (g_camera_switch == SWITCH_TYPE_HDZCS ) {
248+ uint8_t command = hdzcs_get (0x01 );
249+ switch (command ) {
250+ case 0 :
251+ g_manual_camera_sel = 3 ; // manual analog camera
252+ break ;
253+ case 1 :
254+ g_manual_camera_sel = 2 ; // manual mipi camera 2
255+ break ;
256+ case 2 :
257+ g_manual_camera_sel = 1 ; // manual mipi camera 1
258+ break ;
259+ case 3 :
260+ g_manual_camera_sel = 0 ;
261+ break ; // assign by FC
262+ default :
263+ g_manual_camera_sel = 0 ;
264+ break ;
265+ }
266+
267+ if (g_manual_camera_sel ) {
268+ select_camera (g_manual_camera_sel );
269+ }
220270 }
221271}
0 commit comments