//*****************************************************************************
// Micron MT9T111 camera driver setup file for ONLY_ALICIA
//*****************************************************************************
//
// NOTE: this setup file is only for Micron MT9T111 rev2 and rev3 sensor,
//       rev1 sensor is not supported.
//
// Release history:
//
// 2008-03-21  Rev 4.0  - Changed CCM setting for VPT
//                        Deleted old LSC settings
// 2008-03-19  Rev xxx  - Diabled CCM normalization for VTP
//                        Corrected AWB_ALGO for MWB
//                        Adjusted MWB again
// 2008-03-18  Rev xxx  - Corrected VPT LSC settings
// 2008-03-17  Rev xxx  - Modified AWB limits for VPT and STW
//                        Aedded/Mdified MWB settings for VPT and STW
// 2008-03-14  Rev xxx  - Added new LSC for VPT, [Lens Correction 85%G/B+81%R] is enabled
// 2008-03-13  Rev xxx  - Enabled auto 2nd source detection.
// 2008-03-12  Rev xxx  - Changed for Rev3-gamma sensor
//                         for STW: Changed LSC and AWB limits
//                         for VPT: Changed LSC and AWB limits/wieght and CCM
// 2008-02-29  Rev xxx  - Added Remi, but the same as Akiko
// 2008-02-19  Rev xxx  - Updated Rev3 patch to Rev8 for histogram stretch issue of STW
// 2008-02-07  Rev xxx  - Added auto 2nd source detection (GPIO solution) for VPT module
// 2008-02-05  Rev xxx  - Updated VPT settings (LSC/CCM/AWB), provided on 28/Jan/2008
// 2008-01-31  Rev 3.4  - Release for Akiko/Madonna/Kumiko signaling build
// 2008-01-26  Rev xxx  - Added OTPM read sequence and LSC callibration (type method)
//                         But still disabled
// 2008-01-25  Rev xxx  - Changed SOC pipeline clock to be 33.04MHz for JPEG corrupt issue
//                        Changed JPEG snapshot re-try sequence for JPEG capture fail issue
//                        Changed JPEG Q-scale (fine) and buffer size for DMS00248021
//                        Changed EV settings
// 2008-01-18  Rev xxx  - Added configurations of Linda and Kumiko
// 2008-01-16  Rev xxx  - Added VPT settings
// 2007-12-20  Rev 3.3  - Release for Akiko/Madonna ITP and signaling build
//                        Changed lens shading correction
//                        Changed AE target
//                        Changed AWB/CCM settings
//                        Changed LowLight, NR and sharpness settings
//                        Changed Max fdzones for fixed frame rate of VT/VR (DMS00262260)
//                        Updated Rev3 patch to Rev7 to fix digital gain issue
// 2007-12-14  Rev 3.2  - Release for Akiko/Madonna ITP and signaling build
//                        Added Rev3 patch Rev6
//                        Changed cpature sequence for EMP platform P1U
//                        Changed AWB/MWB settings
//                        Changed Default Lens Shading Correction to B
// 2007-12-06  Rev xxx  - Changed Lens Shading Correction
//                        Changed FD search period to improve performance
//                        Changed wait time of the Rev3 patch
//                        Changed AE Level diagram of AE normal mode
// 2007-12-01  Rev xxx  - Added new Rev3 patch for AWB window issue
// 2007-11-28  Rev xxx  - Changed Sepia color to be the same as Sofia's
// 2007-11-20  Rev xxx  - Changed aperture settings
// 2007-11-20  Rev 3.1  - Release for Akiko ITP and signaling build
//                        Changed power on sequence of Akiko
// 2007-11-16  Rev xxx  - Corrected fixed frame rate settings for VR/VT
//                        Adjusted AE target for Rev3
//                        Added Rev3 patch for AE over exposure issue
//                        Added lens shading correction for Rev3
// 2007-11-13  Rev 3.0  - Release for Akiko ITP and signaling build
//                        Added Rev3 settings and sequences
//                        Changed power on/off sequences
// 2007-10-30  Rev 2.5  - Release for Akiko/Madonna signaling build
//                        Changed all settings based on Micron recommended ver2.5
//                          Changed Gamma settings to be SEMC Gamma
//                          Disabled Exposure Compensation
//                          Changed AE base target (EV settings)
//                          Added lens correction settings for 4P lens
//                          Changed AE gate to be 0x06
//                          Changed Max FDZone 50Hz/60Hz (min 7.5fps for normal mode)
//                          Changed Sharpness (Apacon) settings
//                        Changed JPEG sequence and quality settings
// 2007-10-26  Rev 2.4  - Added Alicia's power on/off sequence
// 2007-10-09  Rev 2.3  - Release for Akiko/Madonna ITP and signaling build
// 2007-10-09  Rev xxx  - Corrected exposure time calculation of Exif 
// 2007-10-05  Rev xxx  - Added burst mode property 19 to improve burst time
// 2007-10-05  Rev xxx  - Corrected JPEG status register address
// 2007-10-02  Rev xxx  - Changed GPIO port num of Madonna power on/off sequences
// 2007-09-27  Rev 2.2  - Release for Akiko/Madonna ITP and signaling build
// 2007-09-27  Rev xxx  - Changed JPEG re-try sequence for DMS00196527
// 2007-09-26  Rev 2.1  - Release for Akiko/Madonna ITP and signaling build
// 2007-09-25  Rev xxx  - Changed JPEG buffer size
// 2007-09-22  Rev xxx  - Corrected zoom settings
// 2007-09-15  Rev xxx  - Added Dark Frame workaround for rev2 sensor
//                        Added manually setting FIFO watermark for zoom issue
// 2007-09-02  Rev xxx  - Release for Madonna ITP and signaling build
//                        Modified power on/off sequence (AppGPIO port#) for Madonna from Akiko
// 2007-09-03  Rev 2.0  - Release for Akiko ITP and signaling build
// 2007-09-02  Rev xxx  - Change vf_config/vf_start to reduce wait time
// 2007-09-01  Rev xxx  - Modified for dark picture issue
//                         Changed capture sequence
//                         Added wait at vf_start 
// 2007-08-31  Rev xxx  - Modified for Rev2 sensor
//                        Added/Merged Rev2 sensor settings ver1.3 provided from Micron
//                        Changed power on sequence for camera doesn't startup issue
// 2007-07-09  Rev 1.0  - Release for Akiko ITP and signaling build
//                        Modified JPEG capture sequence to be stable
//                        Added VF/VR/VT resolutions for rev1
//                        Added Manual White balance (MWB color is still tentative)
//                        Added Night mode, frame rate is still tentative
//                        Added get Exif info 1 (currently, return register value directly)
//                        Modified get Exif info 2
//                        Added experimental lens shading correction
//                        Disabled color correction for rev1
// 2007-07-04  Rev 0.5  - Changed for rev1 silicon
//                         Modified power on/off sequence for rev1
//                         Added initialize settings for rev1
//                         Added rev1 workaround for context switching of VF and SS sequence
//                         Changed Q scale of normal and fine
//                         Deleted SEQ_CMD=6 at EV settings to improve unstable AE
//                         Added Special Effect property (8)
//                         Added Test pattern property (1e) for ITP
// 2007-06-21  Rev 0.4  - Corrected Q-scale setting (deleted setting of context B)
//                        Added experimental EV settings
// 2007-06-14  Rev 0.3  - Corrected 2M resolution ID to be 0x04
//                        Corrected 2M resolution settings
//                        Added vf confings of 0x29/0x2b/0x2c
//                        Changed JPEG capture settings
//                        Changed Q-scale registers
// 2007-06-01  Rev 0.2  - Modified for new FPGA baord
//                        Changed JPEG/YUV capture sequence/settings
//                        Changed VF resolution settings
// 2007-05-25  Rev 0.1  - Copeid from Shinobu's setup file
//                        Modified for Micorn MT9T111 FPGA board
//                        Added 3MP resolutions
//                        Added resolution settings
//                        Changed Q-scale factors for MT9T111
//
// =========== <Reserved Internal Registers> ==================================
//
// REG_0 : temporary register
// REG_1 : temporary register
// REG_2 : temporary register
// REG_3 : temporary register
// REG_4 :
// REG_5 :
// REG_6 :
// REG_7 :
// REG_8 :
// REG_9 :
// REG_A :
// REG_B : save Resolution ID
// REG_C : JPEG re-try counter
// REG_D : save Exposure Time [100us] of EXIF information
// REG_E : save ISO Speed Ratings of EXIF information
// REG_F : save JPEG Q scale
// REG_G : CANNOT USE FOR $c COMMAND
// REG_H :
// REG_I : Sensor Revision
// REG_J : save 2nd source distinguish flag (0 = SWT, 1 = VPT)
// REG_K : save type of LSC paramters (0=A, 1=B, 2=C)
// REG_L :
// REG_M : for debug purpose
// REG_N : for debug purpose
//
//*****************************************************************************

// Information section
//=========================================================
info_name=MT9T111_ALICIA;    // ONLY_ALICIA
info_vendor=Micron;
info_major_ver=4;
info_minor_ver=0;
seq_get_prop_0=$s1 04 $s0 00; // This property GET is put here so that it gets changed when the version number is changed

// Camera characteristics section
//=========================================================

// I2C address is 0x60.  EMP doesn't consider low bit (the R/W indicator)
// to be part of address, so cam_i2c_address is (true I2C address / 2)

// Default is 0x3c (0x78/2) for Module
cam_i2c_address=3c;     // 3MP Slave address
I2C_SELECT_CAMERA=$a3c; // 3MP Slave address

// Alternate is 0x3d (0x7a/2) for FPGA
// cam_i2c_address=3d;
// I2C_SELECT_CAMERA=$a3d;

// VSYNC active level high, last data is sampled before VSYNC goes inactive
// HSYNC active level high, last data is sampled before HSYNC goes inactive
cam_vf_sync=5;
cam_ss_sync=5;

// TODO: define any of these that are needed:
cam_i2c_clock_freq=64;	// 100kHz
//       The desired I2C clock frequency in kHz (hexadecimal). Default is 100 kHz
// cam_frame_skip=1;	// temprary solution for dark picture issue
// cam_frame_skip_11=0;	// temprary solution for dark picture issue
//       The number of frames to be skipped before the
//       final image frame is captured when taking a
//       snapshot (hexadecimal)
cam_ss_retries=2;
cam_ss_retries_11=0;
//       The number of times to retry taking a snapshot
// cam_post_processing_x=
//       Post processing for size configuration x:
//          0 =   0 degrees rotation
//          1 =  90 degrees clockwise rotation
//          2 = 180 degrees clockwise rotation
//          3 = 270 degrees clockwise rotation

// Rotation setting
//  for VF
cam_post_processing_20=01;  // for VF 320 x 240 @ max 15fps

//  for VT
cam_post_processing_25=01;  // for VT  96 x 128 @ 12fps
cam_post_processing_26=01;  // for VT 144 x 176 @ 12fps

//  for VR
cam_post_processing_29=01;  // for VR 144 x 176 @ 10fps


// clock ID 9 is SYSCON_SYSCLK_13MHZ
cam_vf_clock_freq=9,32C8;  // Clock #9 on, frequency 13MHz
cam_ss_clock_freq=9,32C8;  // Clock #9 on, frequency 13MHz










//----ONLY_ALICIA POWER ON SEQUENCE----------------------------------------------------------------
//---------------------------------------ONLY_ALICIA----PORT NAME--------STATUS-----------WAIT
cam_power_on_0= 5, 2, A1,    0,  1;   // ONLY_ALICIA    CIF_STANDY       Low             1ms
cam_power_on_1= 5, 2, 85,    1,  5;   // ONLY_ALICIA    CAM_LDO_EN       High             5ms
cam_power_on_2= 5, 3, 09, 32C8, 0A;   // ONLY_ALICIA    CAMSYSCLK#9      13MHz           10ms
cam_power_on_3= 5, 0, 00,    0,  1;   // ONLY_ALICIA    CIR_RES          High             1ms
//cam_power_on_4= 5, 2, d0,    0,  5;   // ONLY_ALICIA    CAM_LDO_EN       Low              5ms
//cam_power_on_5= 5, 2, d0,    1, 64;   // ONLY_ALICIA    CAM_LDO_EN       High           100ms
 

//----ONLY_ALICIA POWER OFF SEQUENCE---------------------------------------------------------------
//---------------------------------------ONLY_ALICIA----PORT NAME--------STATUS-----------WAIT
cam_power_off_0= 5, 0, 00,   1,  1;   // ONLY_ALICIA    CIRES_N          Low              1ms
cam_power_off_1= 5, 3, 09,   0,  1;   // ONLY_ALICIA    CAMSYSCLK#9      Off &inv         1ms 
cam_power_off_2= 5, 2, 85,   0,  A;   // ONLY_ALICIA    CAM_LDO_EN       Low             10ms 
cam_power_off_3= 5, 2, A1,   1,  0;   // ONLY_ALICIA    CIF_STANDBY      High              0ms













// Support section

//=========================================================
// Sizes:
//
sup_sizes=
  // CAPTURE MODE
  // JPEG
  1[280,1E0,0],   // SS  640 x  480, JPEG
  2[500,3C0,0],   // SS 1280 x  960, JPEG

  4[660,4C8,0],   // SS 1632 x 1224, JPEG
  5[800,600,0],   // SS 2048 x 1536, JPEG

  // YUV
 11[280,1E0,0],   // SS  640 x  480,  YUV

  // DRAFT MODE
 20[140,F0,5DC],  // VF  320 x  240, Akiko   max 15.0 fps
 23[F0,B4,5DC],   // VF  240 x  180, Madonna max 15.0 fps

  // VT MODE for Vertical UI
 25[60,80,4B0],   // VT   96 x  128,   max 12.0 fps
 26[90,B0,4B0],   // VT  144 x  176,   max 12.0 fps

  // VT MODE for Horizontal UI
 27[80,60,4B0],   // VT  128 x   96,   max 12.0 fps
 28[B0,90,4B0],   // VT  176 x  144,   max 12.0 fps

  // VR MODE for Vertical UI
 29[90,B0,3E8],   // VR  144 x  176, fixed 10.0 fps

  // VR MODE
 2b[140,F0,5DC],  // VR  320 x  240, fixed 15.0 fps (night mode OFF)
 2c[140,F0,2EE],  // VR  320 x  240, fixed  7.5 fps (night mode ON)

  // VR MODE for Horizontal UI
 2d[B0,90,3E8],   // VT  176 x  144, fixed 10.0 fps (night mode OFF)
  ;
//=========================================================

// all viewfinder (and video record)
cam_vf_format=B100; // this one is YUV422, U, Y1, V, Y2

// Most capture modes are JPEG
cam_ss_format=0001;
cam_ss_format_11=B100; // this one is YUV422, U, Y1, V, Y2

//       The number of bytes in the data stream to be
//       skipped before the image data appears when
//       taking a snapshot (hexadecimal)
cam_data_offset=2;    // skip SOI of JPEG stream
cam_data_offset_11=0; // YUV

//-- JPEG buffer sizes (only used for ITP)
// Suggested snapshot buffer size in bytes (hexadecimal)
// NOTE!!! these values were copied from Clara camera driver
// TODO:  get realistic values for Micron sensor
cam_ss_jpeg_buf_size_1=2A000;  //  168 KB buffer for   640x480 JPEG snap
cam_ss_jpeg_buf_size_2=96000;  //  600 KB buffer for  1280x960 JPEG snap
cam_ss_jpeg_buf_size_4=F4000;  //  976 KB buffer for 1632x1224 JPEG snap
cam_ss_jpeg_buf_size_5=170000; // 1472 KB buffer for 2048x1536 JPEG snap

//=========================================================
// Properties:
//
// NOTE: properties 11 (0x0b) and 12 (0x0c) are GET only
//       property 0 is used for driver version, so it is defined near the top of this file
//
sup_properties=
  0[3,F,9],   // Exposure
  1[0,4,0],   // White balance
  2[0,3,0],   // Flicker
  3[0,1,0],   // Vertical mirror
  4[0,1,0],   // Horizontal mirror
  5[0,1,0],   // JPEG compression level
  6[a,28,a],  // Zoom (NOTE: this gives 1x to 4x)
  7[0,1,0],   // Night mode
  8[0,4,0],   // Effect
  b[0,0,0],   // Get Exif Information 1
  c[0,0,0],   // Get Exif Information 2
  d[0,1,0],   // internal LED flash
  e[0,1,0],   // external xenon flash
 13[0,1,0],   // Burst mode
 1e[0,1,0],   // Test Pattern for ITP
 20[0,ff,0],  // set page address for debug
 21[0,ff,0],  // register read for debug
 22[0,ff,0],  // variable read for debug
 23[0,ff,0],  // for debug
 24[0,ff,0],  // for debug
  ;
//=========================================================


//================================================
//================= MACROS =======================
//================================================

REGISTER_READ= !0 $r2 1 0; // $"RR==%1_%0==";    // read 2 byte from cam reg !0 into internal 1 and 0
REGISTER_WRITE=!0 $w1 $w0 $f; // write internal register 0 and 1 to selected register

// Reads out register !0, performs operation !1, then writes back
// register !0.  Register is read so that high byte is in internal
// register 1, and low byte is in internal register 0.
REGISTER_MODIFY=
  #REGISTER_READ(!0)  // read 2 bytes from cam reg !0 into internal 0 and 1
  !1                  // perform !1
  #REGISTER_WRITE(!0) // write back to selected register
  ;

// Micron MT9T111 Variable Read/Write
VAR_READ=  098E !0 $f 0990 $r2 1 0; // $"VR==%1_%0==";    // read 2 byte from cam var !0 into internal 1 and 0
VAR_WRITE= 098E !0 $f 0990 !1 $f;      // write 2 byte from !1 to selected variable
VAR_WRITE2=098E !0 $f 0990 $w1 $w0 $f; // write internal register 0 and 1 to selected variable

VAR_MODIFY=
  #VAR_READ(!0)   // read 2 bytes from cam var !0 into internal 0 and 1
  !1              // perform !1
  #VAR_WRITE2(!0) // write back to selected variable
  ;

SEQ_CMD_1= 098E 8400 $f 0990 0001 $f;  // Context Switch from B(capture) to A(preview)
SEQ_CMD_2= 098E 8400 $f 0990 0002 $f;  // Context Switch from A(preview) to B(capture)
SEQ_CMD_5= 098E 8400 $f 0990 0005 $f;  // Refresh
SEQ_CMD_6= 098E 8400 $f 0990 0006 $f;  // Refresh Mode

FRAME_OUTPUT_ON=  #REGISTER_MODIFY(001A, $s1.01 1);	// RESET_AND_MISC_CONTROL
FRAME_OUTPUT_OFF= #REGISTER_MODIFY(001A, $s1.01 0);


SELECT_STW_OR_VPT= $cj 00 !0 $cl !1 $cx ;


CHECK_SEQ_STATUS=
  #VAR_READ(8400)
  $c0 00
  $cl
      $h0 V 0500
  $cx
  ;

WAIT_SEQ_CMD_END=
  $s0 01
  [0 32 #CHECK_SEQ_STATUS]	// wait until status bits become 00
  ;


CHECK_SEQ_STATUS2=
  #VAR_READ(8400)  // SEQ_CMD
  $c0 00
  $cl
      $d0042
  $cx
  ;

WAIT_SEQ_CMD_END2=
  $s0 01
  [0 32 #CHECK_SEQ_STATUS2]	// wait until status bits become 00
  ;


CHECK_STANDBY_STATUS=
  #REGISTER_READ(0018) // STANDBY_CONTROL_AND_STATUS
  $c1 40
      $d000a
  $cl
  $cx
  ;

POLL_STANDBY=
  $s1 01
  [1 32 #CHECK_STANDBY_STATUS]	// wait until status bits become 00
  ;


CHECK_PATCH_STATUS=
  #VAR_READ(800A) // MON_PATCH_0
  $c0 00
      $s0 01
      $d000a
  $cl
      $s0 00
  $cx
  ;

POLL_PATCH=
  $s0 01
  [0 64 #CHECK_PATCH_STATUS]
  ;


//--------------------------------------------------------
// White Balance Settings
//--------------------------------------------------------

AWB_CCM_L_LOW_COLOR_TEMP=
  // CAM1_AWB_CCM_L_0--8
  // [SOC3130 CCM settings 3200-6500] 
  #VAR_WRITE(48B0, 01E6) #VAR_WRITE(48B2, FEBE) #VAR_WRITE(48B4, 005A)
  #VAR_WRITE(48B6, FFE0) #VAR_WRITE(48B8, 014B) #VAR_WRITE(48BA, FFD3)
  #VAR_WRITE(48BC, 0003) #VAR_WRITE(48BE, FF4A) #VAR_WRITE(48C0, 01B2)
  ;

AWB_CCM_L_LOW_COLOR_TEMP_REV2=
  #VAR_WRITE(48B0, 0180) #VAR_WRITE(48B2, FF7A) #VAR_WRITE(48B4, 0018)
  #VAR_WRITE(48B6, FFCA) #VAR_WRITE(48B8, 017C) #VAR_WRITE(48BA, FFCC)
  #VAR_WRITE(48BC, 000C) #VAR_WRITE(48BE, FF1F) #VAR_WRITE(48C0, 01E8)
  ;

AWB_CCM_L_HIGH_COLOR_TEMP=
  #VAR_WRITE(48B0, 01F9) #VAR_WRITE(48B2, FF27) #VAR_WRITE(48B4, FFFA)
  #VAR_WRITE(48B6, FFFD) #VAR_WRITE(48B8, 01A6) #VAR_WRITE(48BA, FF76)
  #VAR_WRITE(48BC, 0023) #VAR_WRITE(48BE, FF6A) #VAR_WRITE(48C0, 018D)
  ;

DEFAULT_AWB_CCM_L_VPT=
  #VAR_WRITE(48B0, 01E6) #VAR_WRITE(48B2, FEBE) #VAR_WRITE(48B4, 005A)
  #VAR_WRITE(48B6, FFE0) #VAR_WRITE(48B8, 014B) #VAR_WRITE(48BA, FFD3)
  #VAR_WRITE(48BC, 0003) #VAR_WRITE(48BE, FF4A) #VAR_WRITE(48C0, 01B2)
  ;

AWB_CCM_L_LOW_COLOR_TEMP_VPT=
  #VAR_WRITE(48B0, 0110) #VAR_WRITE(48B2, FFBB) #VAR_WRITE(48B4, 0035)
  #VAR_WRITE(48B6, FFBC) #VAR_WRITE(48B8, 0188) #VAR_WRITE(48BA, FFBA)
  #VAR_WRITE(48BC, 0003) #VAR_WRITE(48BE, FF5C) #VAR_WRITE(48C0, 01A0)
  ;

AWB_CCM_L_MID_COLOR_TEMP_VPT=
  #VAR_WRITE(48B0, 012B) #VAR_WRITE(48B2, FFDB) #VAR_WRITE(48B4, 0006)
  #VAR_WRITE(48B6, FFE3) #VAR_WRITE(48B8, 0150) #VAR_WRITE(48BA, FFDA)
  #VAR_WRITE(48BC, 0006) #VAR_WRITE(48BE, FFD1) #VAR_WRITE(48C0, 0135)
  ;

AWB_CCM_L_HIGH_COLOR_TEMP_VPT=
  #VAR_WRITE(48B0, 0116) #VAR_WRITE(48B2, FFDD) #VAR_WRITE(48B4, 0006)
  #VAR_WRITE(48B6, FFE4) #VAR_WRITE(48B8, 0141) #VAR_WRITE(48BA, FFDB)
  #VAR_WRITE(48BC, 0006) #VAR_WRITE(48BE, FFD3) #VAR_WRITE(48C0, 0125)
  ;

DEFAULT_AWB_CCM_RL=
  // CAM1_AWB_CCM_RL_0--10
  #VAR_WRITE(48C6, 0017) #VAR_WRITE(48C8, 0020) #VAR_WRITE(48CA, FFAF)
  #VAR_WRITE(48CC, 0001) #VAR_WRITE(48CE, 0018) #VAR_WRITE(48D0, FFE6)
  #VAR_WRITE(48D2, FFFE) #VAR_WRITE(48D4, 0020) #VAR_WRITE(48D6, FFE1)
  #VAR_WRITE(48D8, 0012) #VAR_WRITE(48DA, FFEC)
  ;

DEFAULT_AWB_CCM_RL_VPT=
  #VAR_WRITE(48C6, 0017) #VAR_WRITE(48C8, 0020) #VAR_WRITE(48CA, FFAF)
  #VAR_WRITE(48CC, 0010) #VAR_WRITE(48CE, FFFB) #VAR_WRITE(48D0, FFF4)
  #VAR_WRITE(48D2, 0009) #VAR_WRITE(48D4, 004B) #VAR_WRITE(48D6, FFAB)
  #VAR_WRITE(48D8, 0012) #VAR_WRITE(48DA, FFF4) 
  ;

DEFAULT_AWB_CCM_RL_REV2=
  #VAR_WRITE(48C6, 0079) #VAR_WRITE(48C8, FFAD) #VAR_WRITE(48CA, FFE2)
  #VAR_WRITE(48CC, 0033) #VAR_WRITE(48CE, 002A) #VAR_WRITE(48D0, FFAA)
  #VAR_WRITE(48D2, 0017) #VAR_WRITE(48D4, 004B) #VAR_WRITE(48D6, FFA5)
  #VAR_WRITE(48D8, 0015) #VAR_WRITE(48DA, FFEB)
  ;

DISABLE_AWB_CCM_RL=
  #VAR_WRITE(48C6, 0000) #VAR_WRITE(48C8, 0000) #VAR_WRITE(48CA, 0000)
  #VAR_WRITE(48CC, 0000) #VAR_WRITE(48CE, 0000) #VAR_WRITE(48D0, 0000)
  #VAR_WRITE(48D2, 0000) #VAR_WRITE(48D4, 0000) #VAR_WRITE(48D6, 0000)
  #VAR_WRITE(48D8, 0000) #VAR_WRITE(48DA, 0000)
  ;

DEFAULT_AWB_DGAIN_REV2=
  // CAM1_AWB_DGAIN_MIN/MAX_R/B
  #VAR_WRITE(C8EE, 005F) #VAR_WRITE(C8EF, 00AF)
  #VAR_WRITE(C8F0, 0064) #VAR_WRITE(C8F1, 00AC)
  ; 

DISABLE_AWB_DGAIN=
  #VAR_WRITE(C8EE, 0080) #VAR_WRITE(C8EF, 0080)
  #VAR_WRITE(C8F0, 0080) #VAR_WRITE(C8F1, 0080)
  ;

SET_AWB_SCENE_RATIO_DEFAULT_STW=
  // AWB limit window for STW
  #VAR_WRITE(AC38, 003E)	// AWB_R_SCENE_RATIO_LOWER
  #VAR_WRITE(AC39, 005C)	// AWB_R_SCENE_RATIO_UPPER
  #VAR_WRITE(AC3A, 003E)	// AWB_B_SCENE_RATIO_LOWER
  #VAR_WRITE(AC3B, 0060)	// AWB_B_SCENE_RATIO_UPPER
  ;

SET_AWB_SCENE_RATIO_DEFAULT_VPT=
  // AWB limit window for VPT
  #VAR_WRITE(AC38, 003E) 	// AWB_R_SCENE_RATIO_LOWER
  #VAR_WRITE(AC39, 0058) 	// AWB_R_SCENE_RATIO_UPPER
  #VAR_WRITE(AC3A, 0040) 	// AWB_B_SCENE_RATIO_LOWER
  #VAR_WRITE(AC3B, 0062) 	// AWB_B_SCENE_RATIO_UPPER
  ;

SET_AWB_SCENE_RATIO=
  #VAR_WRITE(AC3C, !0)	// AWB_R_RATIO_PRE_AWB
  #VAR_WRITE(AC3D, !1)	// AWB_B_RATIO_PRE_AWB
  ;

AWB_WEIGHT_REV2=
  //AWB Weight
  #VAR_WRITE(C8F4, 0004)	// CAM1_AWB_AWB_XSCALE
  #VAR_WRITE(C8F5, 0002)	// CAM1_AWB_AWB_YSCALE
  #VAR_WRITE(48F6, 85E8)	// CAM1_AWB_AWB_WEIGHTS_0
  #VAR_WRITE(48F8, 8D27)	// CAM1_AWB_AWB_WEIGHTS_1
  #VAR_WRITE(48FA, 4A1B)	// CAM1_AWB_AWB_WEIGHTS_2
  #VAR_WRITE(48FC, 73A8)	// CAM1_AWB_AWB_WEIGHTS_3
  #VAR_WRITE(48FE, 3ECD)	// CAM1_AWB_AWB_WEIGHTS_4
  #VAR_WRITE(4900, 1A06)	// CAM1_AWB_AWB_WEIGHTS_5
  #VAR_WRITE(4902, 3FF8)	// CAM1_AWB_AWB_WEIGHTS_6
  #VAR_WRITE(4904, 0003)	// CAM1_AWB_AWB_WEIGHTS_7
  #VAR_WRITE(4906, 0027)	// CAM1_AWB_AWB_XSHIFT_PRE_ADJ
  #VAR_WRITE(4908, 0034)	// CAM1_AWB_AWB_YSHIFT_PRE_ADJ
  ;

AWB_WEIGHT_STW=
  // [K26A Rev3 SEMC weight table - SJ2 reduced red2 ]
  #VAR_WRITE(C8F4, 0004)    // CAM1_AWB_AWB_XSCALE 
  #VAR_WRITE(C8F5, 0002)    // CAM1_AWB_AWB_YSCALE 
  #VAR_WRITE(48F6, 7154)    // CAM1_AWB_AWB_WEIGHTS_0 
  #VAR_WRITE(48F8, 190D)    // CAM1_AWB_AWB_WEIGHTS_1 
  #VAR_WRITE(48FA, A23E)    // CAM1_AWB_AWB_WEIGHTS_2 
  #VAR_WRITE(48FC, 7B31)    // CAM1_AWB_AWB_WEIGHTS_3 
  #VAR_WRITE(48FE, 6EE3)    // CAM1_AWB_AWB_WEIGHTS_4 
  #VAR_WRITE(4900, 0B0D)    // CAM1_AWB_AWB_WEIGHTS_5 
  #VAR_WRITE(4902, DFF8)    // CAM1_AWB_AWB_WEIGHTS_6 
  #VAR_WRITE(4904, 0017)    // CAM1_AWB_AWB_WEIGHTS_7 
  #VAR_WRITE(4906, 0027)    // CAM1_AWB_AWB_XSHIFT_PRE_ADJ 
  #VAR_WRITE(4908, 0032)    // CAM1_AWB_AWB_YSHIFT_PRE_ADJ 
  ;

AWB_WEIGHT_VPT=
  // [SOC3130 VPT AWB]
  #VAR_WRITE(C8F4, 0004) 	// CAM1_AWB_AWB_XSCALE
  #VAR_WRITE(C8F5, 0002) 	// CAM1_AWB_AWB_YSCALE
  #VAR_WRITE(48F6, 6C3B) 	// CAM1_AWB_AWB_WEIGHTS_0
  #VAR_WRITE(48F8, C606) 	// CAM1_AWB_AWB_WEIGHTS_1
  #VAR_WRITE(48FA, 290C) 	// CAM1_AWB_AWB_WEIGHTS_2
  #VAR_WRITE(48FC, 5F6C) 	// CAM1_AWB_AWB_WEIGHTS_3
  #VAR_WRITE(48FE, EF47) 	// CAM1_AWB_AWB_WEIGHTS_4
  #VAR_WRITE(4900, 013C) 	// CAM1_AWB_AWB_WEIGHTS_5
  #VAR_WRITE(4902, 7FFA) 	// CAM1_AWB_AWB_WEIGHTS_6
  #VAR_WRITE(4904, 000F) 	// CAM1_AWB_AWB_WEIGHTS_7
  #VAR_WRITE(4906, 0029) 	// CAM1_AWB_AWB_XSHIFT_PRE_ADJ
  #VAR_WRITE(4908, 0032) 	// CAM1_AWB_AWB_YSHIFT_PRE_ADJ
  ;


//------------------------------------------------
//   INITIALIZATION
//------------------------------------------------

// This patch for K26A Rev3 fixes
// - Fix for Image brightness varies between preview and capture
// - Fix for OB_TX_CONTROL setting during context switch 
// - Fix for o/p format order cannot be byte swapped
// - Fix for LL parameters should be scaled by gain metric
// - Fix for AE target zone
// - Fix for coarse int time on mode change
// - Calling flash run in flash enter to improve flash UI
// - SOC3130 REV3 AWB Window Setup Bug
// - Fix for slow startup issue
// - Fix Digital gain issue
// - Histogram Stretch always enabled

//  3130SOC_REV03_PATCH02_REV8
SOC3130_REV3_PATCH_1=
  0982 0000 $f
  098A 0351 $f 0990 3C3C C640 F730 C4FC 0BED FD30 C0FC 0BEF $f
  098A 0361 $f 0990 FD30 C2DE 1DEC 25FD 30C5 0101 01FC 30C2 $f
  098A 0371 $f 0990 FD06 D6EC 0C5F 8402 4416 4F30 E703 F10C $f
  098A 0381 $f 0990 DC27 15F1 0CDC 2309 FC06 D604 FD06 D620 $f
  098A 0391 $f 0990 07FC 06D6 05FD 06D6 DE1D E60B C407 30E7 $f
  098A 03A1 $f 0990 02F1 0CDB 272C 7D0C DB27 275D 2724 7F30 $f
  098A 03B1 $f 0990 C4FC 06D6 FD30 C5F6 0CDB 4FFD 30C7 C640 $f
  098A 03C1 $f 0990 F730 C4E6 024F FD30 C501 0101 FC30 C2FD $f
  098A 03D1 $f 0990 06D6 7D06 CB27 2EC6 40F7 30C4 FC06 C104 $f
  098A 03E1 $f 0990 F306 D6ED 005F 6D00 2A01 5317 FD30 C0EC $f
  098A 03F1 $f 0990 00FD 30C2 FC06 C1FD 30C5 0101 01FC 30C2 $f
  098A 0401 $f 0990 FD06 C720 227F 30C4 DE1D EC25 FD30 C5FC $f
  098A 0411 $f 0990 06D6 FD30 C701 FC30 C0FD 06D0 FC30 C2FD $f
  098A 0421 $f 0990 06D2 EC25 FD06 C3BD 953C DE3F EE10 AD00 $f
  098A 0431 $f 0990 DE1D FC06 CCED 3E38 3839 3C3C BD61 D5CE $f
  ;

SOC3130_REV3_PATCH_2=
  098A 0441 $f 0990 04CD 1F17 0211 CC33 2E30 ED02 CCFF FDED $f
  098A 0451 $f 0990 00CC 0002 BD70 6D18 DE1F 181F 8E01 10CC $f
  098A 0461 $f 0990 3C52 30ED 0018 ECA0 C4FD BD70 2120 1ECC $f
  098A 0471 $f 0990 3C52 30ED 00DE 1FEC A0BD 7021 CC3C 5230 $f
  098A 0481 $f 0990 ED02 CCFF FCED 00CC 0002 BD70 6D38 3839 $f
  098A 0AE0 $f 0990 37DE 1DEC 0C5F 8402 4416 4FF7 0CDC E60B $f
  098A 0AF0 $f 0990 C407 F70C DB7F 30C4 EC25 FD30 C5FC 06D6 $f
  098A 0B00 $f 0990 FD30 C701 FC30 C0FD 0BED FC30 C2FD 0BEF $f
  098A 0B10 $f 0990 30E6 00BD 5203 3139 3CBD 776D CC32 5C30 $f
  098A 0B20 $f 0990 ED00 FC13 8683 0001 BD70 21CC 325E 30ED $f
  098A 0B30 $f 0990 00FC 1388 8300 01BD 7021 3839 3C3C 3C34 $f
  098A 0B40 $f 0990 CE06 6A1E 0210 06BD 8427 7E0B D87F 30C4 $f
  098A 0B50 $f 0990 CC01 00FD 30C5 CC00 FFFD 30C7 C640 F730 $f
  098A 0B60 $f 0990 C4F6 13A7 4F30 ED00 CC00 FFA3 00FD 30C5 $f
  098A 0B70 $f 0990 0101 01FC 30C2 ED04 C300 01ED 046F 06C6 $f
  ;

SOC3130_REV3_PATCH_3=
  098A 0B80 $f 0990 80F7 30C4 E606 4F05 C306 738F EC00 FD30 $f
  098A 0B90 $f 0990 C530 EC04 FD30 C7C6 C0F7 30C4 CC01 00FD $f
  098A 0BA0 $f 0990 30C5 0101 01FC 30C2 ED02 8307 FF2F 07CC $f
  098A 0BB0 $f 0990 07FF ED02 200C EC02 83F8 012C 05CC F801 $f
  098A 0BC0 $f 0990 ED02 E606 4F05 C306 7318 8FEC 0218 ED00 $f
  098A 0BD0 $f 0990 6C06 E606 C109 25A7 3838 3831 $f
  098A 8BDC $f 0990 0039 $f 	// MCU_DATA_0
  098A 0CE5 $f 0990 3C3C 3C3C FC06 D230 ED06 FC06 D0ED 04FC $f
  098A 0CF5 $f 0990 0CD5 ED02 FC0C D3ED 00BD D4D0 2356 FC0C $f
  098A 0D05 $f 0990 D3FD 06D0 FC0C D5FD 06D2 FC06 D0FD 0CCB $f
  098A 0D15 $f 0990 FC06 D2FD 0CCD 8640 B730 C4FC 0CCB FD30 $f
  098A 0D25 $f 0990 C0FC 0CCD FD30 C2FC 0CD9 FD30 C501 017F $f
  098A 0D35 $f 0990 30C4 FC0C D1FD 30C5 FC30 C2FD 30C7 01FC $f
  098A 0D45 $f 0990 30C2 FD0C D17C 06CB FE06 C708 FF06 C77A $f
  098A 0D55 $f 0990 0CCF 202F DE1F EC31 30ED 065F 4FED 04FC $f
  ;

SOC3130_REV3_PATCH_4=
  098A 0D65 $f 0990 06D2 ED02 FC06 D0ED 00BD D4D0 2312 CE06 $f
  098A 0D75 $f 0990 AD1C 0101 DE1F 5F4F FD06 D0EC 31FD 06D2 $f
  098A 0D85 $f 0990 7F0C CF38 3838 3839 3C3C 3C3C 7F30 C4FC $f
  098A 0D95 $f 0990 06CC FD30 C5F6 0CD0 4FFD 30C7 C640 F730 $f
  098A 0DA5 $f 0990 C4FC 0CD1 FD30 C501 0101 FC30 C0FD 0CCB $f
  098A 0DB5 $f 0990 FC30 C2FD 0CCD DE1F EC33 30ED 065F 4FED $f
  098A 0DC5 $f 0990 04FC 0CCD ED02 FC0C CBED 00BD D4D0 2331 $f
  098A 0DD5 $f 0990 7F30 C4DE 1FEC 33FD 30C5 FC0C D1FD 30C7 $f
  098A 0DE5 $f 0990 C640 F730 C4FC 06CC FD30 C501 0101 FC30 $f
  098A 0DF5 $f 0990 C2FD 0CD1 EC33 FD06 CC7A 06CB 7A0C CF20 $f
  098A 0E05 $f 0990 35DE 1FEC 3530 ED06 5F4F ED04 FC0C CDED $f
  098A 0E15 $f 0990 02FC 0CCB ED00 BDD4 D024 12DE 1F5F 4FFD $f
  098A 0E25 $f 0990 0CCB EC35 FD0C CDCE 06AD 1C01 02FC 0CCD $f
  098A 0E35 $f 0990 FD06 CC7F 0CCF 3838 3838 39C6 40F7 30C4 $f
  098A 0E45 $f 0990 FC0C CBFD 30C0 FC0C CDFD 30C2 DE1F EC37 $f
  ;

SOC3130_REV3_PATCH_5=
  098A 0E55 $f 0990 FD30 C501 0101 FC30 C2FD 06C7 EC3B B306 $f
  098A 0E65 $f 0990 C723 427F 30C4 FC0C D1FD 30C5 EC37 FD30 $f
  098A 0E75 $f 0990 C7C6 40F7 30C4 FC0C D9FD 30C5 0101 01FC $f
  098A 0E85 $f 0990 30C2 FD0C D1EC 37FD 06CE FC0C D3FD 06D0 $f
  098A 0E95 $f 0990 FC0C D5FD 06D2 EC3B 8300 01FD 06C7 7A06 $f
  098A 0EA5 $f 0990 CB7A 0CCF 39C6 40F7 30C4 FC0C CBFD 30C0 $f
  098A 0EB5 $f 0990 FC0C CDFD 30C2 FC06 C7FD 30C5 0101 01FC $f
  098A 0EC5 $f 0990 30C2 FD06 CE7F 0CCF 39FC 06C5 FD06 C786 $f
  098A 0ED5 $f 0990 40B7 30C4 FC0C CBFD 30C0 FC0C CDFD 30C2 $f
  098A 0EE5 $f 0990 FC06 C7FD 30C5 0101 01FC 30C2 FD06 CEDE $f
  098A 0EF5 $f 0990 1FEC 39B3 06CE 2324 C640 F730 C4FC 0CCB $f
  098A 0F05 $f 0990 FD30 C0FC 0CCD FD30 C2FC 06C5 FD30 C501 $f
  098A 0F15 $f 0990 0101 FC30 C2FD 06CE 7F0C CF39 DE1F EC39 $f
  098A 0F25 $f 0990 FD06 CE7F 30C4 EC39 FE06 C5BD D479 FD30 $f
  098A 0F35 $f 0990 C5FC 0CD1 FD30 C7C6 40F7 30C4 FC0C D9FD $f
  ;

SOC3130_REV3_PATCH_6=
  098A 0F45 $f 0990 30C5 0101 01FC 30C2 FD0C D17C 06CB 7A0C $f
  098A 0F55 $f 0990 CF39 3C3C 3C3C 3C34 BDAD 15DE 198F C301 $f
  098A 0F65 $f 0990 168F E600 F705 14E6 03F7 0515 EC35 FD05 $f
  098A 0F75 $f 0990 0EEC 37FD 0510 FC05 5BFD 0512 DE37 EE08 $f
  098A 0F85 $f 0990 AD00 30E7 0ADE 198F C301 178F E600 F705 $f
  098A 0F95 $f 0990 14E6 03F7 0515 DE37 EE08 AD00 30E7 09DE $f
  098A 0FA5 $f 0990 198F C301 188F E600 F705 14E6 03F7 0515 $f
  098A 0FB5 $f 0990 DE37 EE08 AD00 30E7 08CC 328E ED00 E60A $f
  098A 0FC5 $f 0990 4FBD 7021 CC32 6C30 ED02 CCF8 00ED 00E6 $f
  098A 0FD5 $f 0990 094F 175F ED06 E608 4FED 04E3 0684 07BD $f
  098A 0FE5 $f 0990 706D 30C6 0B3A 3539 $f
  098A 1000 $f 0990 CC10 09BD 4224 7E10 09C6 02F7 018A C608 $f
  098A 1010 $f 0990 F701 8BDE 3F18 CE0B F1CC 0011 BDD7 00CC $f
  098A 1020 $f 0990 0BF1 DD3F DE3B 18CE 0C03 CC00 15BD D700 $f
  098A 1030 $f 0990 CC0C 03DD 3BDE 3518 CE0C 19CC 003F BDD7 $f
  ;

SOC3130_REV3_PATCH_7=
  098A 1040 $f 0990 00CC 0C19 DD35 DE47 18CE 0C59 CC00 15BD $f
  098A 1050 $f 0990 D700 CC0C 59DD 47DE 4118 CE0C 6FCC 000D $f
  098A 1060 $f 0990 BDD7 00CC 0C6F DD41 DE39 18CE 0C7D CC00 $f
  098A 1070 $f 0990 23BD D700 CC0C 7DDD 39DE 3118 CE0C A1CC $f
  098A 1080 $f 0990 0029 BDD7 00CC 0CA1 DD31 CC03 51FD 0BFD $f
  098A 1090 $f 0990 CC10 BEFD 0BFB CC0B 3CFD 0C0F CC04 3BFD $f
  098A 10A0 $f 0990 0C35 CC0F 57FD 0C67 CC10 BBFD 0C71 CC0B $f
  098A 10B0 $f 0990 18FD 0C89 CC0A E0FD 0CAB 397E 9E14 308F $f
  098A 10C0 $f 0990 C3FF F08F 35F6 06BC 4FFD 0CD1 7F30 C4FC $f
  098A 10D0 $f 0990 06C1 FD30 C5FC 06C3 0404 FD30 C701 FC30 $f
  098A 10E0 $f 0990 C0FD 0CD3 FC30 C2FD 0CD5 FC06 D2ED 02FC $f
  098A 10F0 $f 0990 06D0 ED00 C602 BDD6 E030 EC00 FD06 D0EC $f
  098A 1100 $f 0990 02FD 06D2 C604 F70C CFFC 0CD1 2606 CC00 $f
  098A 1110 $f 0990 01FD 0CD1 7D0C D127 07C6 FF30 E70C 2006 $f
  098A 1120 $f 0990 F60C D230 E70C F606 BA54 5454 54E7 0D6C $f
  ;

SOC3130_REV3_PATCH_8=
  098A 1130 $f 0990 0DF6 06C9 C101 260B F606 BAE7 0EE6 0CE7 $f
  098A 1140 $f 0990 0F20 09E6 0CE7 0EF6 06BA E70F E60E E10F $f
  098A 1150 $f 0990 2206 7F06 C97E 1353 E60E E00F E70F DE1F $f
  098A 1160 $f 0990 E62C 4F30 ED0A E60F 4FEE 0A02 8F30 E70F $f
  098A 1170 $f 0990 E10D 2404 E60D E70F F606 C9C1 0126 09E6 $f
  098A 1180 $f 0990 0CEB 0FF7 0CD0 2007 E60C E00F F70C D0F6 $f
  098A 1190 $f 0990 06CB 270D C101 275D C102 2603 7E13 4820 $f
  098A 11A0 $f 0990 51FC 06D0 FD0C D7FC 06D2 FD0C D986 40B7 $f
  098A 11B0 $f 0990 30C4 FC0C D7FD 30C0 FC0C D9FD 30C2 FC0C $f
  098A 11C0 $f 0990 D1FD 30C5 0101 7F30 C4F6 0CD0 4FFD 30C5 $f
  098A 11D0 $f 0990 FC30 C2FD 30C7 01FC 30C0 FD0C CBFC 30C2 $f
  098A 11E0 $f 0990 FD0C CDFC 0CCB FD06 D0FC 0CCD FD06 D2BD $f
  098A 11F0 $f 0990 0CE5 7E13 4B7F 30C4 FC06 C7FD 30C5 FC06 $f
  098A 1200 $f 0990 CEFD 30C7 01FC 30C0 FD0C D7FC 30C2 FD0C $f
  098A 1210 $f 0990 D97F 30C4 FD30 C5F6 0CD0 4FFD 30C7 C640 $f
  ;

SOC3130_REV3_PATCH_9=
  098A 1220 $f 0990 F730 C4FC 0CD1 FD30 C501 0101 FC30 C0FD $f
  098A 1230 $f 0990 0CCB FC30 C2FD 0CCD DE1F 3C18 38EC 2DCD $f
  098A 1240 $f 0990 EE37 BDD4 7930 ED0A 5F6D 0A2A 0153 17ED $f
  098A 1250 $f 0990 08EC 0AED 06EC 08ED 04FC 0CCD ED02 FC0C $f
  098A 1260 $f 0990 CBED 00BD D4D0 2305 BD0E 4020 85DE 1F3C $f
  098A 1270 $f 0990 1838 EC2D CDEE 2FBD D479 30ED 0A5F 6D0A $f
  098A 1280 $f 0990 2A01 5317 ED08 EC0A ED06 EC08 ED04 FC0C $f
  098A 1290 $f 0990 CDED 02FC 0CCB ED00 BDD4 D024 72C6 40F7 $f
  098A 12A0 $f 0990 30C4 FC0C CBFD 30C0 FC0C CDFD 30C2 DE1F $f
  098A 12B0 $f 0990 EC2F FD30 C501 0101 FC30 C2FD 06C7 FC30 $f
  098A 12C0 $f 0990 C727 07FE 06C7 08FF 06C7 C640 F730 C4FC $f
  098A 12D0 $f 0990 0CCB FD30 C0FC 0CCD FD30 C2FC 06C7 FD30 $f
  098A 12E0 $f 0990 C501 0101 FC30 C2FD 06CE FC06 C7B3 06C5 $f
  098A 12F0 $f 0990 2305 BD0E CE20 54DE 1FEC 3BB3 06C7 230A $f
  098A 1300 $f 0990 EC3B FD06 C77A 0CCF 2041 7F0C CF20 3CDE $f
  ;

SOC3130_REV3_PATCH_10=
  098A 1310 $f 0990 1FEC 2DFD 06C7 EC2D B306 C523 06FC 06C5 $f
  098A 1320 $f 0990 FD06 C7C6 40F7 30C4 FC0C CBFD 30C0 FC0C $f
  098A 1330 $f 0990 CDFD 30C2 FC06 C7FD 30C5 0101 01FC 30C2 $f
  098A 1340 $f 0990 FD06 CE7F 0CCF 2003 BD0D 8D7D 0CCF 2703 $f
  098A 1350 $f 0990 7E11 09FC 06D2 30ED 02FC 06D0 ED00 C602 $f
  098A 1360 $f 0990 BDD6 C030 EC00 FD06 D0EC 02FD 06D2 30C6 $f
  098A 1370 $f 0990 103A 3539 $f

  #VAR_WRITE(0010, 1000)	// FIELD_WR=MON_ADDR, 0x1000   // hard coded start address of the patch at "patchSetup"
  #VAR_MODIFY(0003, $s0.02 1)	// FIELD_WR=MON_ALGO, MON_EXEC_CALL_ADDRESS, 1    // execute the patch
  #POLL_PATCH
  #VAR_WRITE(68A0, 082E)	//(2) PRI_A_CONFIG_JPEG_OB_TX_CONTROL_VAR
  #VAR_WRITE(6CA0, 083E)	//(2) PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR  // Enable SOI/EOI for Akiko
  ;


// [K26A_REV2_patch]
K26A_REV2_PATCHE_1=
  098A 0C20 $f 0990 3C3C 34F6 0689 30E7 04BD 9B10 30E6 044F $f
  098A 0C30 $f 0990 ED02 F60C 15ED 00E3 02ED 02F6 0689 4FA3 $f
  098A 0C40 $f 0990 022C 1DE6 044F ED02 F60C 15ED 00EC 02A3 $f
  098A 0C50 $f 0990 00ED 02F6 0689 4FA3 022F 05E6 04F7 0689 $f
  098A 0C60 $f 0990 3838 3139 3CBD 9034 18DE 1418 EC43 2C11 $f
  098A 0C70 $f 0990 CC32 3C30 ED00 5F4F 18A3 43C3 0400 BD81 $f
  098A 0C80 $f 0990 8F18 DE14 18EC 452C 11CC 323E 30ED 005F $f
  098A 0C90 $f 0990 4F18 A345 C304 00BD 818F 3839 37DC 0327 $f
  098A 0CA0 $f 0990 1930 6D00 260B DE10 3C18 38EC 7EED 3620 $f
  098A 0CB0 $f 0990 09DE 103C 1838 EC36 ED7E 30E6 00BD 71AA $f
  098A 0CC0 $f 0990 DE0E EE14 AD00 3139 BDB5 74DE 14E6 1FF7 $f
  098A 0CD0 $f 0990 06A5 $f
  098A 8CD2 $f 0990 0039 $f
  098A 0D67 $f 0990 FC01 9083 0D67 2606 CE01 801D 0404 CC0D $f
  098A 0D77 $f 0990 7EBD 621E 7E0D 7E3C C62B F701 8ADE 2418 $f
  098A 0D87 $f 0990 CE0B 59CC 0015 BDE2 29CC 0B59 DD24 DE26 $f
  098A 0D97 $f 0990 18CE 0B91 CC00 23BD E229 CC0B 91DD 26DE $f
  098A 0DA7 $f 0990 2218 CE0B B5CC 0023 BDE2 29CC 0BB5 DD22 $f
  098A 0DB7 $f 0990 DE28 18CE 0B6F CC00 0FBD E229 CC0B 6FDD $f
  ;

K26A_REV2_PATCHE_2=
  098A 0DC7 $f 0990 28DE 2E18 CE0B 7FCC 0011 BDE2 29CC 0B7F $f
  098A 0DD7 $f 0990 DD2E DE1A 18CE 0BD9 CC00 1DBD E229 CC0B $f
  098A 0DE7 $f 0990 D9DD 1ACC 0F1A FD0B 5DCC 0C20 FD0B 65CC $f
  098A 0DF7 $f 0990 0CC8 FD0B 89CC 0E49 FD0B 9FCC 0F0B FD0B $f
  098A 0E07 $f 0990 AFCC 0C64 FD0B D3CC 0F4C FD0B 79CC 0C9C $f
  098A 0E17 $f 0990 FD0B E1FC 04A8 30ED 001A EE00 CDEE 0B18 $f
  098A 0E27 $f 0990 CE0B F7CC 001D BDE2 2930 EE00 CC0B F7ED $f
  098A 0E37 $f 0990 0BDD 0EFC 0C13 FD0B 57CC 0E48 FD0C 1338 $f
  098A 0E47 $f 0990 3939 308F C3FF DA8F 35BD 9E80 308F C300 $f
  098A 0E57 $f 0990 2630 ED0E FC0D 26C3 0012 ED0C 8300 08ED $f
  098A 0E67 $f 0990 0A20 3F1A EE0C 1809 1809 1AEF 0C18 EC00 $f
  098A 0E77 $f 0990 ED08 EC10 0505 05CA 04ED 1020 08EC 0847 $f
  098A 0E87 $f 0990 56ED 086A 101F 08FF 0A1E 08FF 061F 1107 $f
  098A 0E97 $f 0990 0220 EA1A EE0E 1809 1809 1AEF 0EEC 0818 $f
  098A 0EA7 $f 0990 ED00 EC0C A30A 22BB FC0D 26A3 0A27 0BFC $f
  098A 0EB7 $f 0990 0D26 ED0A EC10 ED12 20E8 CC32 B6ED 028F $f
  098A 0EC7 $f 0990 C300 1030 ED00 C602 BD81 A8CC 32A0 30ED $f
  098A 0ED7 $f 0990 028F C300 1430 ED00 C609 BD81 A8CC 32B2 $f
  098A 0EE7 $f 0990 30ED 00F6 0D2A 4F17 5FFA 0D29 BA0D 28ED $f
  ;

K26A_REV2_PATCHE_3=
  098A 0EF7 $f 0990 06F6 0D2B 4FED 04EA 07AA 06BD 818F 30C6 $f
  098A 0F07 $f 0990 263A 3539 CE0D 001F 3010 05FE 0B57 AD00 $f
  098A 0F17 $f 0990 7EA6 153C FC05 2FB3 052B 30ED 002C 065F $f
  098A 0F27 $f 0990 4FA3 00ED 00EC 0083 0008 2C04 C606 2002 $f
  098A 0F37 $f 0990 C603 F70C 157D 06AB 2609 BD95 FECE 0D00 $f
  098A 0F47 $f 0990 1C04 0438 393C 3C3C 3C34 306F 08FC 06BD $f
  098A 0F57 $f 0990 30ED 02FC 06BB ED00 C601 BDE2 0930 EC00 $f
  098A 0F67 $f 0990 FD06 BBEC 02FD 06BD 6C08 ED06 EC00 ED04 $f
  098A 0F77 $f 0990 CCFF FCED 02CC 0003 ED00 BDDF F922 CE30 $f
  098A 0F87 $f 0990 E608 FE06 AEBD DFBB FD06 AEBD AAE1 FC06 $f
  098A 0F97 $f 0990 BD30 ED02 FC06 BBED 00E6 08BD E1E9 30EC $f
  098A 0FA7 $f 0990 00FD 06BB EC02 FD06 BDE6 08FE 06AE BDDF $f
  098A 0FB7 $f 0990 AFFD 06AE 30C6 093A 3539 $f

  098E 0010 $f	// MCU_ADDRESS
  0990 0D67 $f	// MON_ADDR
  098E 0003 $f	// MCU_ADDRESS
  0990 8004 $f	// MON_ALGO
  ;


//=====================================
// OTPM read sequence for Rev3 only

OTPM_INIT=
  #VAR_WRITE(6037, 0001)
  $s0 01
  [0 32
     #VAR_READ(E039)
     $c0.00 1
         $s0 00
     $cl
         $s0 01
         $d000A
     $cx
  ]
  #VAR_WRITE(6037, 8000)
  ;

OTPM_READ=
  #VAR_WRITE(6031, !0)
  #VAR_WRITE(6037, A010)
  $s0 01
  [0 64
     #VAR_READ(6037)
     $c0.04 0
         $s0 00
     $cl
         $s0 01
         $d0005
     $cx
  ]
  #VAR_READ(6033)
  $"=CAM=OTPM_R==%1_%0=="
  ;

OTPM_END=
  #VAR_WRITE(6037, 0000)
  ;


//=====================================
// Lens Shasing Corrections

LENS_CORRECTION_REV3_GAMMA_STW=
  // goldenLSC.ini on 2008/03/11
  3640 0630 A7AA 3311 FA2B F211 0170 A2EC 4F11 6A0C A251
       00B0 818C 0B51 2CCD C7F0 00F0 FE89 2CF1 B42C F871 $f
  3680 85CC ACEF D20F 1C10 0592 944C 48EF A530 DCD0 0AD2
       CC4B 918F AFB0 74F0 1B12 EEE3 296F DBAF C3B0 4831 $f
  36C0 2352 988C B8B3 BED0 3973 3A92 938E B2F1 61C9 83D5
       1692 A0EE E8B2 3570 EF12 2892 944B B433 D5D0 1A93 $f
  3700 A26F F5B0 01B3 4D73 9F15 B150 D5EB 5FF3 83EF E675
       C60F F44F 5C33 3112 D915 AECF 0870 33F2 C512 F434 $f
  3740 8492 F371 BC54 7154 1CF6 9C11 ABD2 8416 7494 4EB7
       97F0 8470 FD14 3D73 6D76 9092 AF72 EF74 0CB5 4416 $f
  3782 0300 0410 $f
  #REGISTER_MODIFY(3210, $s0.03 1) //PGA_ENABLE
  ;

LENS_CORRECTION_4P_REV2=
  //[Lens Correction 10/03/07 01:19:16 - 90%] for Rev2
  3640 0370 5CEA 2CD1 05AD D171 7FAF 312A 4F11 2B2D BCD1 
       7E2F 6BA9 1971 2FAD 9951 7FCF 734A 2AB1 7ACC D6D1 $f
  3680 3C2C FACC 2BAC 31AC 450E 080D 8C6D 8B8B FBAE 256D
       7EE7 CB0C 92CE 83CE 6A4F D1A8 99CC DFAB 2BAC 124F $f
  36C0 15F2 FCEE C9D3 6710 10D4 3152 B6CF EAB2 03D1 94D3
       0652 9070 9233 06B1 6032 1FF2 C3EE D1F3 51B0 04D4 $f
  3700 8CEF 6A0F E650 F090 0153 9FF0 3D90 2A8F 3710 3751
       A630 52D0 1612 DB70 AA2F B26F 084F 4C6F 8390 04F2 $f
  3740 8352 4272 A634 8EF4 0CB6 A092 3173 A8F5 AD74 0357
       D30E 5F53 BF15 CC74 1A57 8E72 5492 B4D4 A654 2A76 $f
  3782 0318 03E0 $f
  // enable lens shading correction
  #REGISTER_MODIFY(3210, $s0.03 1) // COLOR_PIPELINE_CONTROL
  ;

LENS_CORRECTION_VPTECH_R81=
  // [Lens Correction 85%G/B+81%R]
  3640 0450 43AA 18D1 12CB C171 00D0 94E4 3D91 63EC D6B1
       0150 89AB 04D1 028E EA50 0110 50AB 1731 9D4C CDB1 $f
  3680 828C E52F A210 14D1 6351 8A2D 1F8F 8B30 86D0 3B31
       878D A48F A610 1731 5DD1 820B 1AEF 83D0 F86F 0A51 $f
  36C0 0632 3010 8D71 BCF2 D194 0E72 6BB0 308B D633 A2B5
       7471 5890 AF52 B133 8A53 03F2 0170 8451 A712 CB54 $f
  3700 8790 A2CC 0853 4B90 F2B4 8C70 74AF 02B4 DF33 E7F5
       C30E 48EE 4573 DB32 BD55 F44F 0BB0 0433 AB73 F454 $f
  3740 C1D0 83F2 C0F6 22B5 47F8 3CB0 E1B3 E9B6 7076 5158
       7CEF 8653 FD95 3E36 0238 DBEF D692 CC16 3A95 4958 $f
  3782 0300 0410 $f
  #REGISTER_MODIFY(3210, $s0.03 1) // COLOR_PIPELINE_CONTROL
  ;


INIT_SETTINGS_1=
  //[Micron Rev3 Default] of Ver2.1 (01/16/2008)
  // SOC3130 Preview Parallel EXTCLK 13MHz
  // PIXCLK 26.53MHz
  // 14.6fps
  // wait for K26A to come out of reset
// POLL_REG=0x0000,0xFFFF,!=0x2680,DELAY=10,TIMEOUT=1000

  // Setup PLL
  #REGISTER_MODIFY(0014, $s0.00 1)         // Bypass PLL
  #REGISTER_MODIFY(0014, $s0.01 0)         // Power-down PLL
  0014 2145 $f        //PLL control: BYPASS PLL = 8517
  0010 033D $f        //PLL Dividers = 829
  0012 00E0 $f        //PLL P Dividers = 224
  002A 77BB $f        //PLL P Dividers 4-5-6 = 32491
  0014 2545 $f        //PLL control: TEST_BYPASS on = 9541
  0014 2547 $f        //PLL control: PLL_ENABLE on = 9543
  0014 3447 $f        //PLL control: SEL_LOCK_DET on = 13383
  $d0001               // Allow PLL to lock
  0014 3047 $f        //PLL control: TEST_BYPASS off = 12359
  0014 3046 $f        //PLL control: PLL_BYPASS off = 12358

  0016 0400 $f        // for Rev3 and Rev2

  // set powerup stop bit
  #REGISTER_MODIFY(0018, $s0.02 1)

  // release MCU from standby
  #REGISTER_MODIFY(0018, $s0.00 0)

  // wait for K26A to come out of standby
// POLL_REG=0x0018,0x4000,!=0x0000,DELAY=10,TIMEOUT=1000
  #POLL_STANDBY

  #REGISTER_READ(31FE)
  $mi 0    // store rev to reg i
  $"=CAM=sensor_revision=%i="

  //optimal power consumption
  //analog settings
  3084 2409 $f
  3092 0A49 $f
  3094 4949 $f
  3096 4950 $f

  // Increase slew rates on the pads
//  001E 0777 $f        // Pad slew pad config
  001E 0200 $f	//(1) PAD_SLEW_PAD_CONFIG changed for AKiko H/W

  //Disable adaptive clock
  #VAR_WRITE(68A0, 082E)	//(2) PRI_A_CONFIG_JPEG_OB_TX_CONTROL_VAR
  #VAR_WRITE(6CA0, 083C)	//(2) PRI_B_CONFIG_JPEG_OB_TX_CONTROL_VAR  // Enable SOI/EOI for Akiko

  //Brightness_Metric
  #VAR_WRITE(C913, 000C)	// CAM1_STAT_BRIGHTNESS_METRIC_PREDIVIDER
  #VAR_WRITE(686B, 1388)	// PRI_A_CONFIG_LL_START_BRIGHTNESS
  #VAR_WRITE(686D, 4650)	// PRI_A_CONFIG_LL_STOP_BRIGHTNESS
  #VAR_WRITE(6C6B, 1388)	// PRI_B_CONFIG_LL_START_BRIGHTNESS
  #VAR_WRITE(6C6D, 4650)	// PRI_B_CONFIG_LL_STOP_BRIGHTNESS

  $ci 02  //Exposure Patch for Rev2
      #VAR_WRITE(6C25, 0001)	// PRI_B_CONFIG_AE_TRACK_ALGO_ENTER
      #VAR_WRITE(6C27, 0001)	// PRI_B_CONFIG_AE_TRACK_ALGO_RUN
  $cl
      #VAR_WRITE(6c25, 0008)    // for Rev3
      #VAR_WRITE(6c27, 0000)
  $cx

  //Noise_reduction
  #VAR_WRITE(C91C, 0096)	// CAM1_LL_START_GAIN
  #VAR_WRITE(C91D, 00FF)	// CAM1_LL_STOP_GAIN
  #VAR_WRITE(C91E, 0010)	// CAM1_LL_NR_START_0
  #VAR_WRITE(C91F, 0008)	// CAM1_LL_NR_START_1
  #VAR_WRITE(C920, 0010)	// CAM1_LL_NR_START_2
  #VAR_WRITE(C921, 000C)	// CAM1_LL_NR_START_3
  #VAR_WRITE(C922, 0020)	// CAM1_LL_NR_STOP_0
  #VAR_WRITE(C923, 0018)	// CAM1_LL_NR_STOP_1
  #VAR_WRITE(C924, 0018)	// CAM1_LL_NR_STOP_2
  #VAR_WRITE(C925, 0020)	// CAM1_LL_NR_STOP_3
  #VAR_WRITE(C916, 0014)	// CAM1_LL_LL_START_0
  #VAR_WRITE(C919, 0020)	// CAM1_LL_LL_STOP_0
  #VAR_WRITE(C917, 0004)	// CAM1_LL_LL_START_1
  #VAR_WRITE(C918, 0003)	// CAM1_LL_LL_START_2
  #VAR_WRITE(C91A, 0001)	// CAM1_LL_LL_STOP_1
  #VAR_WRITE(C91B, 0005)	// CAM1_LL_LL_STOP_2
  326C 1403 $f	// APERTURE_PARAMETERS_2D
  #VAR_WRITE(BC02, 0000)	// LL_MODE
  #VAR_WRITE(BC05, 000E)	// LL_CLUSTER_DC_TH

  //DarkCCM
  #VAR_WRITE(DC2A, 001F)	// SYS_DELTA_GAIN
  #VAR_WRITE(DC2B, 0012)	// SYS_DELTA_THRESH
  $ci 02
      #VAR_WRITE(AC02, 0000)	// AWB_MODE	2007/10/26 -- Disable AWB LL for Rev2
  $cl
      #VAR_WRITE(AC02, 0018)  	// AWB_MODE (don't apply dark CCM)
      //#VAR_WRITE(AC02, 000A)  	// AWB_MODE (apply dark CCM; should enable this only after perform dark CCM tuning)
  $cx
  #VAR_WRITE(C914, 0000)	// CAM1_LL_START_DESATURATION
  #VAR_WRITE(C915, 00FF)	// CAM1_LL_END_DESATURATION
  #VAR_WRITE(48DC, 004D)	// CAM1_AWB_LL_CCM_0
  #VAR_WRITE(48DE, 0096)	// CAM1_AWB_LL_CCM_1
  #VAR_WRITE(48E0, 001D)	// CAM1_AWB_LL_CCM_2
  #VAR_WRITE(48E2, 004D)	// CAM1_AWB_LL_CCM_3
  #VAR_WRITE(48E4, 0096)	// CAM1_AWB_LL_CCM_4
  #VAR_WRITE(48E6, 001D)	// CAM1_AWB_LL_CCM_5
  #VAR_WRITE(48E8, 004D)	// CAM1_AWB_LL_CCM_6
  #VAR_WRITE(48EA, 0096)	// CAM1_AWB_LL_CCM_7
  #VAR_WRITE(48EC, 001D)	// CAM1_AWB_LL_CCM_8
  ;

INIT_SETTINGS_2=
  //AE_Settings
  #VAR_WRITE(6821, 1B58)	// PRI_A_CONFIG_AE_RULE_EXP_COMP_CENTER
  #VAR_WRITE(E823, 0080)	// PRI_A_CONFIG_AE_RULE_EXP_COMP_LOW_LIGHT	2007/10/19 -- Disable AE compensation
  #VAR_WRITE(E824, 0080)	// PRI_A_CONFIG_AE_RULE_EXP_COMP_BRIGHT_LIGHT
  #VAR_WRITE(6C21, 1B58)	// PRI_B_CONFIG_AE_RULE_EXP_COMP_CENTER
  #VAR_WRITE(EC23, 0080)	// PRI_B_CONFIG_AE_RULE_EXP_COMP_LOW_LIGHT
  #VAR_WRITE(EC24, 0080)        // PRI_B_CONFIG_AE_RULE_EXP_COMP_BRIGHT_LIGHT
  #VAR_WRITE(A415, 0004)	// AE_RULE_OFFSET_DAMPENING
  #VAR_WRITE(E82B, 0002)	// PRI_A_CONFIG_AE_TRACK_SKIP_FRAMES

  $ci 02
      #VAR_WRITE(E81F, 0024)	// PRI_A_CONFIG_AE_RULE_BASE_TARGET	2007/10/26 -- Adjusted AE target for Rev2
  $cl
      #VAR_WRITE(E81F, 0032)	// PRI_A_CONFIG_AE_RULE_BASE_TARGET	2007/12/21 -- Adjusted AE target for Rev3
  $cx

  #VAR_WRITE(A80E, 0006)	// AE_TRACK_GATE for Gamma and Target evaluation	2007/10/26 -- Changed AE gate

  //AE Limits	2007/10/26 -- Changed AE Limits for normal mode
  #VAR_WRITE(6815, 000D)	// PRI_A_CONFIG_FD_MAX_FDZONE_50HZ
  #VAR_WRITE(6817, 0010)	// PRI_A_CONFIG_FD_MAX_FDZONE_60HZ
  #VAR_WRITE(682D, 000A)	// PRI_A_CONFIG_AE_TRACK_TARGET_FDZONE
  #VAR_WRITE(682F, 0080)	// PRI_A_CONFIG_AE_TRACK_TARGET_AGAIN
  #VAR_WRITE(6831, 0020)	// PRI_A_CONFIG_AE_TRACK_AE_MIN_VIRT_INT_TIME_PCLK
  #VAR_WRITE(6833, 0080)	// PRI_A_CONFIG_AE_TRACK_AE_MIN_VIRT_DGAIN
  #VAR_WRITE(6835, 0080)	// PRI_A_CONFIG_AE_TRACK_AE_MAX_VIRT_DGAIN
  #VAR_WRITE(6839, 012C)	// PRI_A_CONFIG_AE_TRACK_AE_MAX_VIRT_AGAIN
  #VAR_WRITE(6837, 0040)	// PRI_A_CONFIG_AE_TRACK_AE_MIN_VIRT_AGAIN

  // AE oscillation workaround
  #VAR_WRITE(4815, 0001)	//(1) CAM1_CTX_A_COARSE_ITMIN
  #VAR_WRITE(485D, 0001)	//(1) CAM1_CTX_B_COARSE_ITMIN
  #VAR_WRITE(681B, 0004)	//(1) PRI_A_CONFIG_AE_RULE_ALGO_RUN

  //FD settings
  098E C8A5 $f        //search_f1_50
  0990 0019 $f
  098E C8A6 $f        //search_f2_50
  0990 001C $f
  098E C8A7 $f        //search_f1_60
  0990 001E $f
  098E C8A8 $f        //search_f2_60
  0990 0021 $f

  //Gamma Correction	2007/10/19 -- Changed all gammas to be SEMC gamma
  #VAR_WRITE(BC31, 0000)	// LL_GAMMA_NRCURVE_0
  #VAR_WRITE(BC32, 0013)	// LL_GAMMA_NRCURVE_1
  #VAR_WRITE(BC33, 0027)	// LL_GAMMA_NRCURVE_2
  #VAR_WRITE(BC34, 004D)	// LL_GAMMA_NRCURVE_3
  #VAR_WRITE(BC35, 0078)	// LL_GAMMA_NRCURVE_4
  #VAR_WRITE(BC36, 0092)	// LL_GAMMA_NRCURVE_5
  #VAR_WRITE(BC37, 00A6)	// LL_GAMMA_NRCURVE_6
  #VAR_WRITE(BC38, 00B6)	// LL_GAMMA_NRCURVE_7
  #VAR_WRITE(BC39, 00C3)	// LL_GAMMA_NRCURVE_8
  #VAR_WRITE(BC3A, 00CE)	// LL_GAMMA_NRCURVE_9
  #VAR_WRITE(BC3B, 00D8)	// LL_GAMMA_NRCURVE_10
  #VAR_WRITE(BC3C, 00E1)	// LL_GAMMA_NRCURVE_11
  #VAR_WRITE(BC3D, 00E9)	// LL_GAMMA_NRCURVE_12
  #VAR_WRITE(BC3E, 00EF)	// LL_GAMMA_NRCURVE_13
  #VAR_WRITE(BC3F, 00F4)	// LL_GAMMA_NRCURVE_14
  #VAR_WRITE(BC40, 00F7)	// LL_GAMMA_NRCURVE_15
  #VAR_WRITE(BC41, 00FA)	// LL_GAMMA_NRCURVE_16
  #VAR_WRITE(BC42, 00FD)	// LL_GAMMA_NRCURVE_17
  #VAR_WRITE(BC43, 00FF)	// LL_GAMMA_NRCURVE_18

  #VAR_WRITE(BC1E, 0000)	// LL_GAMMA_NEUTRAL_0
  #VAR_WRITE(BC1F, 0013)	// LL_GAMMA_NEUTRAL_1
  #VAR_WRITE(BC20, 0027)	// LL_GAMMA_NEUTRAL_2
  #VAR_WRITE(BC21, 004D)	// LL_GAMMA_NEUTRAL_3
  #VAR_WRITE(BC22, 0078)	// LL_GAMMA_NEUTRAL_4
  #VAR_WRITE(BC23, 0092)	// LL_GAMMA_NEUTRAL_5
  #VAR_WRITE(BC24, 00A6)	// LL_GAMMA_NEUTRAL_6
  #VAR_WRITE(BC25, 00B6)	// LL_GAMMA_NEUTRAL_7
  #VAR_WRITE(BC26, 00C3)	// LL_GAMMA_NEUTRAL_8
  #VAR_WRITE(BC27, 00CE)	// LL_GAMMA_NEUTRAL_9
  #VAR_WRITE(BC28, 00D8)	// LL_GAMMA_NEUTRAL_10
  #VAR_WRITE(BC29, 00E1)	// LL_GAMMA_NEUTRAL_11
  #VAR_WRITE(BC2A, 00E9)	// LL_GAMMA_NEUTRAL_12
  #VAR_WRITE(BC2B, 00EF)	// LL_GAMMA_NEUTRAL_13
  #VAR_WRITE(BC2C, 00F4)	// LL_GAMMA_NEUTRAL_14
  #VAR_WRITE(BC2D, 00F7)	// LL_GAMMA_NEUTRAL_15
  #VAR_WRITE(BC2E, 00FA)	// LL_GAMMA_NEUTRAL_16
  #VAR_WRITE(BC2F, 00FD)	// LL_GAMMA_NEUTRAL_17
  #VAR_WRITE(BC30, 00FF)	// LL_GAMMA_NEUTRAL_18

  #VAR_WRITE(BC0B, 0000)	// LL_GAMMA_CONTRAST_CURVE_0
  #VAR_WRITE(BC0C, 0013)	// LL_GAMMA_CONTRAST_CURVE_1
  #VAR_WRITE(BC0D, 0027)	// LL_GAMMA_CONTRAST_CURVE_2
  #VAR_WRITE(BC0E, 004D)	// LL_GAMMA_CONTRAST_CURVE_3
  #VAR_WRITE(BC0F, 0078)	// LL_GAMMA_CONTRAST_CURVE_4
  #VAR_WRITE(BC10, 0092)	// LL_GAMMA_CONTRAST_CURVE_5
  #VAR_WRITE(BC11, 00A6)	// LL_GAMMA_CONTRAST_CURVE_6
  #VAR_WRITE(BC12, 00B6)	// LL_GAMMA_CONTRAST_CURVE_7
  #VAR_WRITE(BC13, 00C3)	// LL_GAMMA_CONTRAST_CURVE_8
  #VAR_WRITE(BC14, 00CE)	// LL_GAMMA_CONTRAST_CURVE_9
  #VAR_WRITE(BC15, 00D8)	// LL_GAMMA_CONTRAST_CURVE_10
  #VAR_WRITE(BC16, 00E1)	// LL_GAMMA_CONTRAST_CURVE_11
  #VAR_WRITE(BC17, 00E9)	// LL_GAMMA_CONTRAST_CURVE_12
  #VAR_WRITE(BC18, 00EF)	// LL_GAMMA_CONTRAST_CURVE_13
  #VAR_WRITE(BC19, 00F4)	// LL_GAMMA_CONTRAST_CURVE_14
  #VAR_WRITE(BC1A, 00F7)	// LL_GAMMA_CONTRAST_CURVE_15
  #VAR_WRITE(BC1B, 00FA)	// LL_GAMMA_CONTRAST_CURVE_16
  #VAR_WRITE(BC1C, 00FD)	// LL_GAMMA_CONTRAST_CURVE_17
  #VAR_WRITE(BC1D, 00FF)	// LL_GAMMA_CONTRAST_CURVE_18

  #VAR_WRITE(4926, 1388)	// CAM1_LL_START_GAMMA_BM
  #VAR_WRITE(4928, 2710)	// CAM1_LL_MID_GAMMA_BM
  #VAR_WRITE(492A, 3A98)	// CAM1_LL_STOP_GAMMA_BM
  #VAR_WRITE(4D26, 1388)	// CAM2_LL_START_GAMMA_BM
  #VAR_WRITE(4D28, 2710)	// CAM2_LL_MID_GAMMA_BM
  #VAR_WRITE(4D2A, 3A98)	// CAM2_LL_STOP_GAMMA_BM
  #VAR_WRITE(BC44, 002C)	// LL_TCLIMIT
  #VAR_WRITE(BC45, 001C)	// LL_TCBASE
  #VAR_WRITE(3C46, 2710)	// LL_START_TCAUTO_LIMITER
  #VAR_WRITE(3C48, 4E20)	// LL_STOP_TCAUTO_LIMITER

  326E 00A4 $f	// LOW_PASS_YUV_FILTER
  ;

INIT_SETTINGS_3=
  #REGISTER_READ(060A)	// GPIO_DATA
  $c0.02 0
       $sj 00 $"=CAM=1st=STW=="
  $cl
       $sj 01 $"=CAM=2nd=VPT=="
  $cx

//   $ci 03
//       #OTPM_INIT
//       #OTPM_READ(0006)
//       #OTPM_END

//       // module vendor
//       $cs1 10
//            $sj 00 $"=CAM=1st=STW=="
//       $cl
//            $sj 01 $"=CAM=2nd=VPT=="
//       $cx

//       // shading callibration
//       $s0.04 0  $s0.05 0  $s0.06 0  $s0.07 0
//       $mk 0
//   $cl $cx

  $sk 00 // forced type mothoed A
  ;  

INIT_SETTINGS_4=
  $ci 02
      #AWB_WEIGHT_REV2

      //AWB_limits
      #DEFAULT_AWB_DGAIN_REV2
      #VAR_WRITE(C910, 0004) // CAM1_STAT_LUMA_THRESH_LOW
      #VAR_WRITE(C911, 00C8) // CAM1_STAT_LUMA_THRESH_HIGH
  $cl
      #SELECT_STW_OR_VPT(
        #AWB_WEIGHT_STW
        #SET_AWB_SCENE_RATIO_DEFAULT_STW
      ,
        #AWB_WEIGHT_VPT
        #SET_AWB_SCENE_RATIO_DEFAULT_VPT
      )

      #DEFAULT_AWB_DGAIN_REV2
      #VAR_WRITE(C910, 0010) // CAM1_STAT_LUMA_THRESH_LOW
      #VAR_WRITE(C911, 00E6) // CAM1_STAT_LUMA_THRESH_HIGH
  $cx

  #VAR_WRITE(B839, 0001)	// STAT_AWB_STAT_DAMPENING

  //AWB_CCM
  $ci 02
      #AWB_CCM_L_LOW_COLOR_TEMP_REV2
      #DEFAULT_AWB_CCM_RL_REV2
      #VAR_WRITE(48C2, 0020)	// CAM1_AWB_CCM_L_9
      #VAR_WRITE(48C4, 0044)	// CAM1_AWB_CCM_L_10
  $cl
      #SELECT_STW_OR_VPT(
        #AWB_CCM_L_LOW_COLOR_TEMP
        #DEFAULT_AWB_CCM_RL
        #VAR_WRITE(48C2, 0024)	// CAM1_AWB_CCM_L_9
        #VAR_WRITE(48C4, 0035)	// CAM1_AWB_CCM_L_10
        #VAR_MODIFY(AC02, $s0.04 1) // AWB_MODE disable CCM normalization
      ,
        #DEFAULT_AWB_CCM_L_VPT
        #DEFAULT_AWB_CCM_RL_VPT
        #VAR_WRITE(48C2, 0022) 	// CAM1_AWB_CCM_L_9
        #VAR_WRITE(48C4, 002F) 	// CAM1_AWB_CCM_L_10
        #VAR_MODIFY(AC02, $s0.04 1) // AWB_MODE disable CCM normalization
      )
      //Mode control
      #VAR_WRITE(2C03, 01FF)	// AWB_ALGO
      #VAR_WRITE(683F, 01FF)	// PRI_A_CONFIG_AWB_ALGO_RUN
  $cx
  ;

INIT_SETTINGS_5=
  //Saturation
  #VAR_WRITE(C949, 0000)	// CAM1_SYS_DARK_COLOR_KILL
  #VAR_WRITE(C94A, 0062)	// CAM1_SYS_BRIGHT_COLORKILL
  35A2 0080 $f	// DARK_COLOR_KILL_CONTROLS
  35A4 0596 $f	// BRIGHT_COLOR_KILL_CONTROLS

  #VAR_WRITE(E86F, 0044)	// PRI_A_CONFIG_LL_START_SATURATION
  #VAR_WRITE(E870, 0036)	// PRI_A_CONFIG_LL_END_SATURATION
  #VAR_WRITE(EC6F, 0044)	// PRI_B_CONFIG_LL_START_SATURATION
  #VAR_WRITE(EC70, 0036)	// PRI_B_CONFIG_LL_END_SATURATION

  //AntiShake
  #VAR_WRITE(490A, 0541)	// CAM1_AS_INTEG_SCALE_FIRST_PASS
  #VAR_WRITE(490C, 0080)	// CAM1_AS_MIN_INT_TIME_FIRST_PASS
  #VAR_WRITE(6857, 001E)	// PRI_A_CONFIG_IS_FEATURE_THRESHOLD
  #VAR_WRITE(6C57, 001E)	// PRI_B_CONFIG_IS_FEATURE_THRESHOLD
  #VAR_WRITE(685C, 0004)	// PRI_A_CONFIG_IS_BLUR_INPUT_PARAMETER
  #VAR_WRITE(6C5C, 0004)	// PRI_B_CONFIG_IS_BLUR_INPUT_PARAMETER
  #VAR_WRITE(490E, 00A4)	// CAM1_AS_MAX_DIGITAL_GAIN_ALLOWED

  //lens correction
  $ci 02
      #LENS_CORRECTION_4P_REV2	// for Rev2 with STW 4P lens
  $cl
      #SELECT_STW_OR_VPT(
        #LENS_CORRECTION_REV3_GAMMA_STW
      ,
        #LENS_CORRECTION_VPTECH_R81		// for Rev3-gamma with VPT lens
      )
  $cx   

  //Speed override
  //REG=0x3C86, 0x0002	//(1) OB_PCLK1_CONFIG

  //Dark Frame Workaround for Rev2
  #VAR_WRITE(4886, 0080)	// CAM1_CTX_B_DIGITAL_GAIN

  //Continue
  0018 0028 $f	// STANDBY_CONTROL_AND_STATUS
  ;

INIT_SETTINGS_6=
  $ci 02  // load patch for Rev2 sensor
      #K26A_REV2_PATCHE_1
      #K26A_REV2_PATCHE_2
      #K26A_REV2_PATCHE_3
  $cl     // load patch for Rev3 sensor
      #SOC3130_REV3_PATCH_1
      #SOC3130_REV3_PATCH_2
      #SOC3130_REV3_PATCH_3
      #SOC3130_REV3_PATCH_4
      #SOC3130_REV3_PATCH_5
      #SOC3130_REV3_PATCH_6
      #SOC3130_REV3_PATCH_7
      #SOC3130_REV3_PATCH_8
      #SOC3130_REV3_PATCH_9
      #SOC3130_REV3_PATCH_10
  $cx
  ;

INIT_SETTINGS_7=
  //Timing Setting
  098E 4802 $f        //Row Start (A)
  0990 0000 $f        //      = 0
  098E 4804 $f        //Column Start (A)
  0990 0000 $f        //      = 0
  098E 4806 $f        //Row End (A)
  0990 060D $f        //      = 1549
  098E 4808 $f        //Column End (A)
  0990 080D $f        //      = 2061
  098E 480A $f        //Row Speed (A)
  0990 0111 $f        //      = 273
  098E 480C $f        //Read Mode (A)
  0990 046C $f        //      = 1132
  098E 480F $f        //Fine Correction (A)
  0990 00C0 $f        //      = 192
  098E 4811 $f        //Fine IT Min (A)
  0990 0375 $f        //      = 885
  098E 4813 $f        //Fine IT Max Margin (A)
  0990 025B $f        //      = 603
  098E 481D $f        //Base Frame Lines (A)
  0990 035C $f        //      = 860
  098E 481F $f        //Min Line Length (A)
  0990 05D0 $f        //      = 1488
  098E 4825 $f        //Line Length (A)
  0990 0A3D $f        //      = 2621
  098E 484A $f        //Row Start (B)
  0990 0004 $f        //      = 4
  098E 484C $f        //Column Start (B)
  0990 0004 $f        //      = 4
  098E 484E $f        //Row End (B)
  0990 060B $f        //      = 1547
  098E 4850 $f        //Column End (B)
  0990 080B $f        //      = 2059
  098E 4852 $f        //Row Speed (B)
  0990 0111 $f        //      = 273
  098E 4854 $f        //Read Mode (B)
  0990 0024 $f        //      = 36
  098E 4857 $f        //Fine Correction (B)
  0990 0080 $f        //      = 128
  098E 4859 $f        //Fine IT Min (B)
  0990 01E5 $f        //      = 485
  098E 485B $f        //Fine IT Max Margin (B)
  0990 010B $f        //      = 267
  098E 4865 $f        //Base Frame Lines (B)
  0990 06BA $f        //      = 1722
  098E 4867 $f        //Min Line Length (B)
  0990 0378 $f        //      = 888
  098E 486D $f        //Line Length (B)
  0990 0A3D $f        //      = 2621
  098E C844 $f        //period_50Hz (A)
  0990 007E $f        //      = 126
  098E C845 $f        //period_60Hz (A)
  0990 0069 $f        //      = 105
  098E C88C $f        //period_50Hz (B)
  0990 007E $f        //      = 126
  098E C88D $f        //period_60Hz (B)
  0990 0069 $f        //      = 105
  098E 4846 $f        //RX FIFO Watermark (A)
  0990 0014 $f        //      = 20
  098E 68AA $f        //TX FIFO Watermark (A)
  0990 02C4 $f        //      = 708
  098E E8AC $f        //TX FIFO Manual Watermark (A)
  0990 0001 $f        //      = 1
  098E 488E $f        //RX FIFO Watermark (B)
  0990 0014 $f        //      = 20
  //Setting correct watermark for context B
  098E 6CAA $f        //TX FIFO Watermark (B)
  0990 02C4 $f        //      = 0
  098E ECAC $f        //TX FIFO Manual Watermark (B)
  0990 0001 $f        //      = 1
  #VAR_WRITE(6800, 0140)	//(1) PRI_A_IMAGE_WIDTH
  #VAR_WRITE(6802, 00F0)	//(1) PRI_A_IMAGE_HEIGHT
  ;

INIT_SETTINGS_8=
  //workaround for centering QCIF/SubQCIF
  #VAR_WRITE(687F, 002E)	// PRI_A_CONFIG_SYSCTRL_ALGO_RUN

  #VAR_WRITE(8400, 0006)	// SEQ_CMD
  // wait for mode refresh to complete
// POLL_FIELD=SEQ_CMD,!=0,DELAY=10,TIMEOUT=1000
  #WAIT_SEQ_CMD_END2

  //inverting PCLK for SEMC platform
  3C20 0001 $f	//(1) TX_SS_CONTROL

  //default settings
  3088 FFFF $f
  3172 0003 $f
  316C 0406 $f
  30FE 4A38 $f
  3100 4738 $f
  3126 00FF $f

  //Enable Output
  001A 0218 $f	// RESET_AND_MISC_CONTROL
  ;



//--------------------------------------------------------
// Wait for Context Switching
//--------------------------------------------------------

CHECK_CONTEXT_A=
  #VAR_READ(C893)  // CAM1_CONTEXT
  $c0.00 0   // context A
  $cl        // context B
      $d0042 // wait 66ms (=1/15fps)
  $cx
  ;

WAIT_CONTEXT_A=
  $s0 01
  [0 12 #CHECK_CONTEXT_A] // wait for context A(preview)
  ;

CHECK_CONTEXT_B=
  #VAR_READ(C893)  // CAM1_CONTEXT
  $c0.00 0    // context A
      $d0042 // wait 66ms (=1/15fps)
      $s0 01 
  $cl         // context B
      $s0 00
  $cx
  ;

WAIT_CONTEXT_B=
  $s0 01
  [0 12 #CHECK_CONTEXT_B] // wait for context B(capture)
  ;


DELAY_30MS=
  $d001E
  $-0 01
  ;

// workaround for rev2 1st jpeg fail issue for EMP P1U
WAIT_CONTEXT_B_REV2=
  #VAR_READ(281A) // fdzone
  $d0190  // wait >= 1/7.5*3sec
  $cg0 0D
       $-0 0D
       [0 10 #DELAY_30MS]
  $cl
  $cx
  ;

//--------------------------------------------------------
// ViewFinder (Preview) Settings
//--------------------------------------------------------

PREVIEW_START=
  #VAR_READ(C893)
  $c0.00 0  // from context A
      #SEQ_CMD_6
      #WAIT_SEQ_CMD_END2
  $cl       // from context B
      #SEQ_CMD_1
      #WAIT_CONTEXT_A
  $cx
  // fix image-stuck between context switching: preview <-> jpeg
  3c54 00a7 $f
  ;

VF_CONFIG_SET=
  $z0

  $cb 01  // case of previous mode SS
      $u06 #PREVIEW_START $t0100
  $cl     // case of previous mode VF/VR/VT
      $c0 rb
      $cl
          !0
          $u06 #PREVIEW_START $t0180
      $cx
  $cx
  $zb
  ;


//--------------------------------------------------------
// YUV Capture settings
//--------------------------------------------------------

YUV_CAPTURE_START=
  #VAR_WRITE(EC05, 0002)	//(2) PRI_B_NUM_OF_FRAMES_RUN
  #VAR_WRITE(EC8E, 0000)	//(1) PRI_B_CONFIG_JPEG_JP_MODE
  #SEQ_CMD_2
  ;


//--------------------------------------------------------
// JPEG Capture settings
 //--------------------------------------------------------

JPEG_CAPTURE_START=
//   #VAR_WRITE(6C90, 8034)	// PRI_B_CONFIG_JPEG_CONFIG
  #VAR_WRITE(6C90, 8014)	// PRI_B_CONFIG_JPEG_CONFIG
  #VAR_WRITE(EC05, 0000)	//(1) PRI_B_NUM_OF_FRAMES_RUN
  #VAR_WRITE(EC8E, 0001)	// PRI_B_PRI_B_CONFIG_JPEG_JP_MODE
  #VAR_WRITE(5800, 0000)	// JPEG_STATUS
  #VAR_WRITE(D805, 0000)	// JPEG_JP_STATUS

  $p0 13  // burst mode
  $c0 00
      #SEQ_CMD_2
  $cl
      #VAR_READ(C893)
      $c0.00 0  // from context A
          #SEQ_CMD_2
      $cl       // from context B
          #SEQ_CMD_6
          #WAIT_SEQ_CMD_END2
      $cx
  $cx

  $sc 00	// reset JEPG re-try counter
  ;

GET_JPEG_STATUS=
  #REGISTER_READ(3C54) // OB_JPEG_CONTROL_STATUS
  $s0.00 0 $s0.05 0 $s0.06 0 $s0.07 0
  $+0 r1
  $m3 0  

  #VAR_READ(5800)  // JPEG_STATUS
  $s0.00 0 $s0.05 0 $s0.06 0 $s0.07 0
  $+0 r1

  $+0 r3
  $"==jpeg_status==%0=="
  #VAR_WRITE(5800, 0000)	// JPEG_STATUS
  ;

GET_JPEG_Q_SCALE=
  #VAR_READ(D805)  // JPEG_JP_STATUS
  $c0.03 0
      #VAR_READ(EC94) // Q scale 1
  $cl
      #VAR_READ(EC95) // Q scale 2
  $cx
  $mf 0
  $sf.07 0
  $"==JPEG_Q==%f=="
  ;

SET_JPEG_Q_SCALE_NORMAL=
  $z0        // PRI_B_CONFIG_JPEG_QSCALE1/2
      $c0 01 #VAR_WRITE(EC94, 0089) #VAR_WRITE(EC95, 0090) // VGA: 85, 75
  $cl $c0 02 #VAR_WRITE(EC94, 0089) #VAR_WRITE(EC95, 0090) // 1MP: 85, 75
  $cl        #VAR_WRITE(EC94, 0088) #VAR_WRITE(EC95, 0090) // 2MP/3MP: 87, 75
  $cx $cx
  ;

SET_JPEG_Q_SCALE_FINE=
  $z0        // PRI_B_CONFIG_JPEG_QSCALE1/2
      $c0 01 #VAR_WRITE(EC94, 0086) #VAR_WRITE(EC95, 008C) // VGA: 90, 81
  $cl $c0 02 #VAR_WRITE(EC94, 0086) #VAR_WRITE(EC95, 008C) // 1MP: 90, 81
  $cl        #VAR_WRITE(EC94, 0085) #VAR_WRITE(EC95, 008C) // 2MP/3MP: 92, 81
  $cx $cx
  ;

JPEG_RETRY=
      $cc 00 #VAR_WRITE(6C90, 8054)	// select q-scale 2
  $cl $cc 01 #VAR_WRITE(EC95, 00A0)	// 50
  $cl $cx $cx
  $+c 01
  $"==JP=RETRY=%c=="
  ;


//--------------------------------------------------------
// AE settings
//--------------------------------------------------------

AE_SET=
  // AE Level Diagram Set
  #VAR_WRITE(6815, !0)  // PRI_A_CONFIG_FD_MAX_FDZONE_50HZ
  #VAR_WRITE(6817, !1)  // PRI_A_CONFIG_FD_MAX_FDZONE_60HZ
  #VAR_WRITE(682D, !2)  // PRI_A_CONFIG_AE_TRACK_TARGET_FDZONE
  #VAR_WRITE(682F, !3)  // PRI_A_CONFIG_AE_TRACK_TARGET_AGAIN 
//#VAR_WRITE(6831,   )  // PRI_A_CONFIG_AE_TRACK_AE_MIN_VIRT_INT_TIME_PCLK
//#VAR_WRITE(6833,   )  // PRI_A_CONFIG_AE_TRACK_AE_MIN_VIRT_DGAIN
  $ci 03
      #VAR_WRITE(6835, !5)  // PRI_A_CONFIG_AE_TRACK_AE_MAX_VIRT_DGAIN
  $cl
      // Cannot change DGAIN due to dark picture issue of Rev2
  $cx
//#VAR_WRITE(6837,   )  // PRI_A_CONFIG_AE_TRACK_AE_MIN_VIRT_AGAIN
  #VAR_WRITE(6839, !4)  // PRI_A_CONFIG_AE_TRACK_AE_MAX_VIRT_AGAIN
  ;

NORMAL_LIGHT_MODE=
  $z0
      $cs0 25  #AE_SET(000D, 0010, 000A, 0080, 012C, 0080)  // VF max 15fps, min (TBD)
  $cl $cs0 29  #AE_SET(0008, 000A, 0004, 0040, 012C, 0080)  // VT fixed 12fps
  $cl $c0  29  #AE_SET(000A, 000C, 0004, 0040, 012C, 0080)  // VR fixed 10.0 fps
  $cl $c0  2b  #AE_SET(0006, 0008, 0004, 0040, 012C, 0080)  // VR fixed 15.0 fps
  $cl $c0  2c  #AE_SET(000D, 0010, 0004, 0040, 012C, 0080)  // VR fixed  7.5 fps
  $cl $c0  2d  #AE_SET(000A, 000C, 0004, 0040, 012C, 0080)  // VR fixed 10.0 fps
  $cl
  $cx $cx $cx $cx $cx $cx
  ;

DARK_LIGHT_MODE=
  $z0
      $cs0 25  #AE_SET(0018, 001C, 000A, 0080, 012C, 00C0)  // VF max 15fps, min (TBD)
  $cl $cs0 29  #AE_SET(0018, 001C, 000A, 0080, 012C, 0100)  // VT max 12fps, min (TBD)
  $cl $c0  29  #AE_SET(000A, 000C, 0004, 0040, 012C, 0100)  // VR fixed 10.0 fps
  $cl $c0  2b  #AE_SET(0006, 0008, 0004, 0040, 012C, 0100)  // VR fixed 15.0 fps
  $cl $c0  2c  #AE_SET(000D, 0010, 0004, 0040, 012C, 0100)  // VR fixed  7.5 fps
  $cl $c0  2d  #AE_SET(000A, 000C, 0004, 0040, 012C, 0100)  // VR fixed 10.0 fps
  $cl
  $cx $cx $cx $cx $cx $cx
  ;

AE_MODE_SET=
  $p1 07
  $c1 00
      #NORMAL_LIGHT_MODE
  $cl
      #DARK_LIGHT_MODE
  $cx
  ;

EV_SET=
  #VAR_WRITE(A80E, 0002)
  #VAR_WRITE(E81F, !0)
  $ci 02
  $cl
      #VAR_WRITE(3C4D, !1)
      #VAR_WRITE(3C4F, !2)
  $cx
  $d00D0
  #VAR_WRITE(A80E, 0006)
  ;

//--------------------------------------------------------
// Zoom Settings
//--------------------------------------------------------

SIZE_640_480_ZOOM=
  // 640 x 480:  zoom from 1.0 to 3.2
      $c2 0b  #VAR_WRITE(5C18, 006E)
  $cl $c2 0c  #VAR_WRITE(5C18, 0078)
  $cl $c2 0d  #VAR_WRITE(5C18, 0082)
  $cl $c2 0e  #VAR_WRITE(5C18, 008C)
  $cl $c2 0f  #VAR_WRITE(5C18, 0096)
  $cl $c2 10  #VAR_WRITE(5C18, 00A0)
  $cl $c2 11  #VAR_WRITE(5C18, 00AA)
  $cl $c2 12  #VAR_WRITE(5C18, 00B4)
  $cl $c2 13  #VAR_WRITE(5C18, 00BE)
  $cl $c2 14  #VAR_WRITE(5C18, 00C8)
  $cl $c2 15  #VAR_WRITE(5C18, 00D2)
  $cl $c2 16  #VAR_WRITE(5C18, 00DC)
  $cl $c2 17  #VAR_WRITE(5C18, 00E6)
  $cl $c2 18  #VAR_WRITE(5C18, 00F0)
  $cl $c2 19  #VAR_WRITE(5C18, 00FA)
  $cl $c2 1a  #VAR_WRITE(5C18, 0104)
  $cl $c2 1b  #VAR_WRITE(5C18, 010E)
  $cl $c2 1c  #VAR_WRITE(5C18, 0118)
  $cl $c2 1d  #VAR_WRITE(5C18, 0122)
  $cl $c2 1e  #VAR_WRITE(5C18, 012C)
  $cl $c2 1f  #VAR_WRITE(5C18, 0136)
  $cl $c2 20  #VAR_WRITE(5C18, 0140)
  $cl         #VAR_WRITE(5C18, 0064)
  $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx
  $cx $cx $cx $cx $cx $cx $cx
  ;

SIZE_320_240_ZOOM=
  // 320 x 240:  zoom from 1.0 to 3.2
      $c2 0b  #VAR_WRITE(5C18, 006E)
  $cl $c2 0c  #VAR_WRITE(5C18, 0078)
  $cl $c2 0d  #VAR_WRITE(5C18, 0082)
  $cl $c2 0e  #VAR_WRITE(5C18, 008C)
  $cl $c2 0f  #VAR_WRITE(5C18, 0096)
  $cl $c2 10  #VAR_WRITE(5C18, 00A0)
  $cl $c2 11  #VAR_WRITE(5C18, 00AC)
  $cl $c2 12  #VAR_WRITE(5C18, 00B4)
  $cl $c2 13  #VAR_WRITE(5C18, 00BE)
  $cl $c2 14  #VAR_WRITE(5C18, 00C8)
  $cl $c2 15  #VAR_WRITE(5C18, 00D4)
  $cl $c2 16  #VAR_WRITE(5C18, 00DC)
  $cl $c2 17  #VAR_WRITE(5C18, 00E8)
  $cl $c2 18  #VAR_WRITE(5C18, 00F0)
  $cl $c2 19  #VAR_WRITE(5C18, 00FA)
  $cl $c2 1a  #VAR_WRITE(5C18, 0104)
  $cl $c2 1b  #VAR_WRITE(5C18, 010E)
  $cl $c2 1c  #VAR_WRITE(5C18, 0118)
  $cl $c2 1d  #VAR_WRITE(5C18, 0122)
  $cl $c2 1e  #VAR_WRITE(5C18, 012C)
  $cl $c2 1f  #VAR_WRITE(5C18, 0138)
  $cl $c2 20  #VAR_WRITE(5C18, 0140)
  $cl         #VAR_WRITE(5C18, 0064)
  $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx
  $cx $cx $cx $cx $cx $cx $cx
  ;

SIZE__96_128_ZOOM=
  // 96 x 128:  zoom from 1.0 to 4.0
      $c2 0b  #VAR_WRITE(5C18, 006E)
  $cl $c2 0c  #VAR_WRITE(5C18, 0078)
  $cl $c2 0d  #VAR_WRITE(5C18, 0082)
  $cl $c2 0e  #VAR_WRITE(5C18, 008C)
  $cl $c2 0f  #VAR_WRITE(5C18, 0096)
  $cl $c2 10  #VAR_WRITE(5C18, 00A0)
  $cl $c2 11  #VAR_WRITE(5C18, 00AA)
  $cl $c2 12  #VAR_WRITE(5C18, 00B4)
  $cl $c2 13  #VAR_WRITE(5C18, 00BE)
  $cl $c2 14  #VAR_WRITE(5C18, 00C8)
  $cl $c2 15  #VAR_WRITE(5C18, 00D2)
  $cl $c2 16  #VAR_WRITE(5C18, 00DC)
  $cl $c2 17  #VAR_WRITE(5C18, 00E6)
  $cl $c2 18  #VAR_WRITE(5C18, 00F0)
  $cl $c2 19  #VAR_WRITE(5C18, 00FA)
  $cl $c2 1a  #VAR_WRITE(5C18, 0104)
  $cl $c2 1b  #VAR_WRITE(5C18, 010E)
  $cl $c2 1c  #VAR_WRITE(5C18, 0118)
  $cl $c2 1d  #VAR_WRITE(5C18, 0122)
  $cl $c2 1e  #VAR_WRITE(5C18, 012C)
  $cl $c2 1f  #VAR_WRITE(5C18, 0136)
  $cl $c2 20  #VAR_WRITE(5C18, 0140)
  $cl $c2 21  #VAR_WRITE(5C18, 014A)
  $cl $c2 22  #VAR_WRITE(5C18, 0154)
  $cl $c2 23  #VAR_WRITE(5C18, 015E)
  $cl $c2 24  #VAR_WRITE(5C18, 016A)
  $cl $c2 25  #VAR_WRITE(5C18, 0172)
  $cl $c2 26  #VAR_WRITE(5C18, 017C)
  $cl $c2 27  #VAR_WRITE(5C18, 0186)
  $cl $c2 28  #VAR_WRITE(5C18, 0190)
  $cl         #VAR_WRITE(5C18, 0064)
  $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx
  $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx
  ;

SIZE_144_176_ZOOM=
  // 144 x 176:  zoom from 1.0 to 4.0
      $c2 0b  #VAR_WRITE(5C18, 006B)
  $cl $c2 0c  #VAR_WRITE(5C18, 0077)
  $cl $c2 0d  #VAR_WRITE(5C18, 0084)
  $cl $c2 0e  #VAR_WRITE(5C18, 008B)
  $cl $c2 0f  #VAR_WRITE(5C18, 0096)
  $cl $c2 10  #VAR_WRITE(5C18, 00A0)
  $cl $c2 11  #VAR_WRITE(5C18, 00A9)
  $cl $c2 12  #VAR_WRITE(5C18, 00B4)
  $cl $c2 13  #VAR_WRITE(5C18, 00BE)
  $cl $c2 14  #VAR_WRITE(5C18, 00C8)
  $cl $c2 15  #VAR_WRITE(5C18, 00D4)
  $cl $c2 16  #VAR_WRITE(5C18, 00DE)
  $cl $c2 17  #VAR_WRITE(5C18, 00E6)
  $cl $c2 18  #VAR_WRITE(5C18, 00F0)
  $cl $c2 19  #VAR_WRITE(5C18, 00FA)
  $cl $c2 1a  #VAR_WRITE(5C18, 0104)
  $cl $c2 1b  #VAR_WRITE(5C18, 0109)
  $cl $c2 1c  #VAR_WRITE(5C18, 0115)
  $cl $c2 1d  #VAR_WRITE(5C18, 0122)
  $cl $c2 1e  #VAR_WRITE(5C18, 012C)
  $cl $c2 1f  #VAR_WRITE(5C18, 0138)
  $cl $c2 20  #VAR_WRITE(5C18, 0142)
  $cl $c2 21  #VAR_WRITE(5C18, 014A)
  $cl $c2 22  #VAR_WRITE(5C18, 0151)
  $cl $c2 23  #VAR_WRITE(5C18, 015D)
  $cl $c2 24  #VAR_WRITE(5C18, 016C)
  $cl $c2 25  #VAR_WRITE(5C18, 0171)
  $cl $c2 26  #VAR_WRITE(5C18, 017C)
  $cl $c2 27  #VAR_WRITE(5C18, 0186)
  $cl $c2 28  #VAR_WRITE(5C18, 0190)
  $cl         #VAR_WRITE(5C18, 0064)
  $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx
  $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx
  ;

SIZE_128__96_ZOOM=
  // 128 x 96:  zoom from 1.0 to 4.0
      $c2 0b  #VAR_WRITE(5C18, 006E)
  $cl $c2 0c  #VAR_WRITE(5C18, 0078)
  $cl $c2 0d  #VAR_WRITE(5C18, 0082)
  $cl $c2 0e  #VAR_WRITE(5C18, 008C)
  $cl $c2 0f  #VAR_WRITE(5C18, 0096)
  $cl $c2 10  #VAR_WRITE(5C18, 00A0)
  $cl $c2 11  #VAR_WRITE(5C18, 00AA)
  $cl $c2 12  #VAR_WRITE(5C18, 00B4)
  $cl $c2 13  #VAR_WRITE(5C18, 00BE)
  $cl $c2 14  #VAR_WRITE(5C18, 00C8)
  $cl $c2 15  #VAR_WRITE(5C18, 00D2)
  $cl $c2 16  #VAR_WRITE(5C18, 00DC)
  $cl $c2 17  #VAR_WRITE(5C18, 00E6)
  $cl $c2 18  #VAR_WRITE(5C18, 00F0)
  $cl $c2 19  #VAR_WRITE(5C18, 00FA)
  $cl $c2 1a  #VAR_WRITE(5C18, 0104)
  $cl $c2 1b  #VAR_WRITE(5C18, 010E)
  $cl $c2 1c  #VAR_WRITE(5C18, 0118)
  $cl $c2 1d  #VAR_WRITE(5C18, 0122)
  $cl $c2 1e  #VAR_WRITE(5C18, 012C)
  $cl $c2 1f  #VAR_WRITE(5C18, 0136)
  $cl $c2 20  #VAR_WRITE(5C18, 0140)
  $cl $c2 21  #VAR_WRITE(5C18, 014A)
  $cl $c2 22  #VAR_WRITE(5C18, 0154)
  $cl $c2 23  #VAR_WRITE(5C18, 015E)
  $cl $c2 24  #VAR_WRITE(5C18, 0168)
  $cl $c2 25  #VAR_WRITE(5C18, 0172)
  $cl $c2 26  #VAR_WRITE(5C18, 017C)
  $cl $c2 27  #VAR_WRITE(5C18, 0186)
  $cl $c2 28  #VAR_WRITE(5C18, 0190)
  $cl         #VAR_WRITE(5C18, 0064)
  $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx
  $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx
  ;

ZOOM_SET_REV2=
  $z1     // int reg 1 gets size config
      $c1 01 #SIZE_640_480_ZOOM
  $cl $c1 02 #VAR_WRITE(5C18, 0064)
  $cl $c1 04 #VAR_WRITE(5C18, 0064)
  $cl $c1 05 #VAR_WRITE(5C18, 0064)
  $cl $c1 11 #SIZE_640_480_ZOOM
  $cl $c1 20 #SIZE_320_240_ZOOM
  $cl $c1 23 #SIZE_320_240_ZOOM     // 280 x 180, same as QVGA
  $cl $c1 25 #SIZE__96_128_ZOOM
  $cl $c1 26 #SIZE_144_176_ZOOM
  $cl $c1 27 #SIZE_128__96_ZOOM
  $cl $c1 28 #SIZE_128__96_ZOOM     // 176 x 144, same as 128 x 96
  $cl $c1 29 #SIZE_144_176_ZOOM
  $cl $c1 2b #SIZE_320_240_ZOOM
  $cl $c1 2c #SIZE_320_240_ZOOM
  $cl $c1 2d #SIZE_128__96_ZOOM     // 176 x 144, same as 128 x 96
  $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx $cx
  ;

//--------------------------------------------------------
// EXIF Information
//--------------------------------------------------------

//*************************************************************************
// name :        CALC_EXP_TIME
// description : Get Exposure Time in previous capture.
// input :       none
// output :      REG_D ExposureTime [1/10,000s = 100us]
// reg usage :   REG0, REG1, REG2
//*************************************************************************
CALC_EXP_TIME=
  // integration_time[us]  = ( ( COARSE_INTEGRATION_TIME * LINE_LENGTH_PCK ) + FINE_INTEGRATION_TIME ) / sensor_core_freq
  // sensor_core_freq[MHz] = ( ( EXTCLK * 2 * 0x0010[7:0] ) / ( 0x0010[13:8] + 1 ) ) / ( 0x002A[3:0] + 1 )

  #REGISTER_READ(3012) // REG_D = COARSE_INTEGRATION_TIME
  $<1 8 $+1 r0 $md 1

  #REGISTER_READ(300C) // REG_2 = LINE_LENGTH_PCK
  $<1 8 $+1 r0 $m2 1

  $*d r2               // REG_D = REG_D * REG_2

  #REGISTER_READ(3014) // REG_2 = FINE_INTEGRATION_TIME
  $<1 8 $+1 r0 $m2 1   

  $+d r2               // REG_D = REG_D + REG_2

  $s2 0c $<2 8 $+2 e8  // REG_2 = 0x0CE8 = 3304 = 33.04 * 100	// TODO: change this when pll changed
  $/d r2               // REG_D = REG_D / REG_2 [100us]

  $"==EXP_TIME==%d=="
  ;

//*************************************************************************
// name :        CALC_ISO_SPEED
// description : Get ISOSpeedRatings in previous capture.
// input :       none
// output :      REG_E ISOSpeedRatings
// reg usage :   REG0 REG1
//*************************************************************************
CALC_ISO_SPEED=
  #REGISTER_READ(302A)  // ANALOGUE_GAIN_CODE_GREENR

  $ci 02  // Rev2
      // Register 0x302A |       ISO Speeds
      //-----------------+------------------------
      //        R0 < 20  |           R_E < ISO40 
      //  20 <= R0 < 32  | ISO40  <= R_E < ISO65 
      //  32 <= R0 < 64  | ISO65  <= R_E < ISO131
      //  64 <= R0 < 127 | ISO131 <= R_E < ISO260
      // 127 <= R0       |           R_E = ISO260
      $me 0
          $cs0 14 $se 28                      
      $cl $cs0 20 $-e 14 $*e 19 $/e 0c $+e 28  // linear interpolation
      $cl $cs0 40 $-e 20 $*e 42 $/e 20 $+e 41  // linear interpolation 
      $cl $cs0 7F $-e 40 $*e 81 $/e 3f $+e 83  // linear interpolation
      $cl         $se 10 $<e 4 $+e 04         
      $cx $cx $cx $cx
  $cl
      // Register 0x302A |       ISO Speeds
      //-----------------+------------------------
      //        R0 < 14  |           R_E < ISO52
      //  14 <= R0 < 20  | ISO52  <= R_E < ISO75 
      //  20 <= R0 < 32  | ISO75  <= R_E < ISO120 
      //  32 <= R0 < 64  | ISO120 <= R_E < ISO233
      //  64 <= R0 < 127 | ISO233 <= R_E < ISO400
      // 127 <= R0       |           R_E = ISO400
      $me 0
          $cs0 0E $se 34                      
      $cl $cs0 14 $-e 0E $*e 17 $/e 06 $+e 34  // linear interpolation
      $cl $cs0 20 $-e 14 $*e 2D $/e 0C $+e 4B
      $cl $cs0 40 $-e 20 $*e 71 $/e 20 $+e 78
      $cl $cs0 7F $-e 40 $*e A7 $/e 3F $+e E9
      $cl         $se 19 $<e 4
      $cx $cx $cx $cx $cx
  $cx

//   #VAR_READ(281F)  // AE_TRACK_VIRT_DGAIN
  #VAR_READ(5C22)  // SYS_DGAIN
  $<1 8 $+1 r0
  $*e r1 $>e 7

  $"==ISO==%e=="
  ;

GET_EXIF_INFO=
  #CALC_EXP_TIME  
  #CALC_ISO_SPEED  
  ;



seq_ping=#REGISTER_READ(0000);
cam_ping_result=80 26;


//================================================
//=============== PROPERTIES =====================
//================================================


// --- Get Exif info 1 property 11 (b) -----------
//
// R0 = ISO Speed Ratings (Low)
// R1 = ISO Speed Ratings (High)
// R2 = Exposure Time (Low)
// R3 = Exposure Time (High)
//------------------------------------------------
seq_get_prop_b=
  $m0 e // load ISO from REG_E
  $m1 0 $<0 9 $<0 f $>0 f $>0 9 // R0 = L_ISO = ISO & 0x000000FF
  $>1 8 $<1 9 $<1 f $>1 f $>1 9 // R1 = H_ISO = (ISO>>8) & 0x000000FF
  $m2 d // load ExpTime from REG_D
  $m3 2 $<2 9 $<2 f $>2 f $>2 9 // R2 = L_SHUTTERSPEED = SHT & 0x000000FF
  $>3 8 $<3 9 $<3 f $>3 f $>3 9 // R3 = H_SHUTTERSPEED = (SHT>>8) & 0x000000FF
  ;

// --- Get Exif info 2 property 12 (c) -----------
//
// R0 = White balance (0 = auto, 1 = manual)
// R1 = Distance      (0 = unknown)
// R2 = Flash         (0 = not flashed, 1 = flashed)
// R3 = Q scaling factor
//------------------------------------------------
seq_get_prop_c=
  $m3 f                        // R3 = Q scaling factor
  $s2 00                       // R2 = Flash         (0 = not flashed, 1 = flashed)
  $s1 00                       // R1 = Distance      (0 = unknown)
  $p0 01 $c0 00 $cl $s0 01 $cx // R0 = White balance (0 = auto, 1 = manual)
  ;


// --- Brightness property 0 ---------------------
// TODO: EV values are sitll tentative. To be optimized
//  0 => -3 EV  1=> -(2 2/3) EV ....
//  9 =>  0 EV  ....
// 15 =>  2 EV
//------------------------------------------------
//seq_set_prop_0_0=; // -3.0EV (no supported)
//seq_set_prop_0_1=; // -2.7EV (no supported)
//seq_set_prop_0_2=; // -2.3EV (no supported)
seq_set_prop_0_3=$ci 02 #EV_SET(0009) $cl #EV_SET(000D, 04E2, 08CA) $cx; // -2.0EV
seq_set_prop_0_4=$ci 02 #EV_SET(000B) $cl #EV_SET(0010, 0627, 0B13) $cx; // -1.7EV
seq_set_prop_0_5=$ci 02 #EV_SET(000E) $cl #EV_SET(0014, 07C0, 0DF4) $cx; // -1.3EV
seq_set_prop_0_6=$ci 02 #EV_SET(0012) $cl #EV_SET(0019, 09C4, 1194) $cx; // -1.0EV
seq_set_prop_0_7=$ci 02 #EV_SET(0017) $cl #EV_SET(001F, 0C4E, 1626) $cx; // -0.7EV
seq_set_prop_0_8=$ci 02 #EV_SET(001D) $cl #EV_SET(0028, 0F81, 1BE7) $cx; // -0.3EV
seq_set_prop_0_9=$ci 02 #EV_SET(0024) $cl #EV_SET(0032, 1388, 2328) $cx; // default
seq_set_prop_0_a=$ci 02 #EV_SET(002D) $cl #EV_SET(003F, 189C, 2C4B) $cx; //  0.3EV
seq_set_prop_0_b=$ci 02 #EV_SET(0039) $cl #EV_SET(004F, 1F01, 37CF) $cx; //  0.7EV
seq_set_prop_0_c=$ci 02 #EV_SET(0048) $cl #EV_SET(0064, 2710, 4650) $cx; //  1.0EV
seq_set_prop_0_d=$ci 02 #EV_SET(005B) $cl #EV_SET(007E, 3137, 5897) $cx; //  1.3EV
seq_set_prop_0_e=$ci 02 #EV_SET(0072) $cl #EV_SET(009F, 3E02, 6F9D) $cx; //  1.7EV
seq_set_prop_0_f=$ci 02 #EV_SET(0090) $cl #EV_SET(00C8, 4E20, 8CA0) $cx; //  2.0EV

// --- White balance property 1 ------------------
//
//  0 => auto         1 => incandescent    2 => fluorescent
//  3 => clear sky    4 => cloudy
//------------------------------------------------
seq_set_prop_1_0=
  $ci 02
      #DEFAULT_AWB_CCM_RL_REV2
      #DEFAULT_AWB_DGAIN_REV2
      #AWB_CCM_L_LOW_COLOR_TEMP_REV2
      #VAR_WRITE(48C2, 0020) // CAM1_AWB_CCM_L_9/10
      #VAR_WRITE(48C4, 0044)
  $cl 
      #SELECT_STW_OR_VPT(
        #DEFAULT_AWB_CCM_RL
        #AWB_CCM_L_LOW_COLOR_TEMP
        #SET_AWB_SCENE_RATIO_DEFAULT_STW
      ,
        #DEFAULT_AWB_CCM_L_VPT
        #DEFAULT_AWB_CCM_RL_VPT
        #SET_AWB_SCENE_RATIO_DEFAULT_VPT
      )

      #VAR_WRITE(2C03, 01FF)	// AWB_ALGO
      #VAR_MODIFY(AC02, $s0.03 1) // AWB_MODE
      #VAR_WRITE(683F, 01FF)	// PRI_A_CONFIG_AWB_ALGO_RUN
  $cx
  ;
seq_set_prop_1_1= // [Incandescent 2800K]
  #DISABLE_AWB_CCM_RL
  $ci 02
      #DISABLE_AWB_DGAIN
      #AWB_CCM_L_LOW_COLOR_TEMP_REV2
      #VAR_WRITE(48C2, 0028)
      #VAR_WRITE(48C4, 0034)
  $cl
      #SELECT_STW_OR_VPT(
        #AWB_CCM_L_LOW_COLOR_TEMP_REV2
        #VAR_MODIFY(AC02, $s0.03 0) // AWB_MODE
        #VAR_WRITE(2C03, 0030)	// AWB_ALGO
        #SET_AWB_SCENE_RATIO(0065, 0039)
        #VAR_WRITE(683F, 0030)	// PRI_A_CONFIG_AWB_ALGO_RUN
      ,
        #AWB_CCM_L_LOW_COLOR_TEMP_VPT
        #VAR_MODIFY(AC02, $s0.03 0) // AWB_MODE
        #VAR_WRITE(2C03, 0030)	// AWB_ALGO
        #SET_AWB_SCENE_RATIO(0060, 003A)
        #VAR_WRITE(683F, 0030)	// PRI_A_CONFIG_AWB_ALGO_RUN
      )
  $cx
  ;
seq_set_prop_1_2= // [Fluorescent 4200K]
  #DISABLE_AWB_CCM_RL
  $ci 02
      #DISABLE_AWB_DGAIN
      #AWB_CCM_L_HIGH_COLOR_TEMP
      #VAR_WRITE(48C2, 002D)
      #VAR_WRITE(48C4, 002A)
  $cl
      #SELECT_STW_OR_VPT(
        #AWB_CCM_L_HIGH_COLOR_TEMP
        #VAR_MODIFY(AC02, $s0.03 0) // AWB_MODE
        #VAR_WRITE(2C03, 0030)	// AWB_ALGO
        #SET_AWB_SCENE_RATIO(0049, 0047)
        #VAR_WRITE(683F, 0030)	// PRI_A_CONFIG_AWB_ALGO_RUN
      ,
        #AWB_CCM_L_MID_COLOR_TEMP_VPT
        #VAR_MODIFY(AC02, $s0.03 0) // AWB_MODE
        #VAR_WRITE(2C03, 0030)	// AWB_ALGO
        #SET_AWB_SCENE_RATIO(0047, 0049)
        #VAR_WRITE(683F, 0030)	// PRI_A_CONFIG_AWB_ALGO_RUN
      )
  $cx
  ;
seq_set_prop_1_3= // [Daylight 5500K]
  #DISABLE_AWB_CCM_RL
  $ci 02
      #DISABLE_AWB_DGAIN
      #AWB_CCM_L_HIGH_COLOR_TEMP
      #VAR_WRITE(48C2, 0037)
      #VAR_WRITE(48C4, 0020)
  $cl
      #SELECT_STW_OR_VPT(
        #AWB_CCM_L_HIGH_COLOR_TEMP
        #VAR_MODIFY(AC02, $s0.03 0) // AWB_MODE
        #VAR_WRITE(2C03, 0030)	// AWB_ALGO
        #SET_AWB_SCENE_RATIO(0040, 0061)
        #VAR_WRITE(683F, 0030)	// PRI_A_CONFIG_AWB_ALGO_RUN
      ,
        #AWB_CCM_L_HIGH_COLOR_TEMP_VPT
        #VAR_MODIFY(AC02, $s0.03 0) // AWB_MODE
        #VAR_WRITE(2C03, 0030)	// AWB_ALGO
        #SET_AWB_SCENE_RATIO(003D, 0064)
        #VAR_WRITE(683F, 0030)	// PRI_A_CONFIG_AWB_ALGO_RUN
      )
  $cx
  ;
seq_set_prop_1_4= // [Cloudy 7200K]
  #DISABLE_AWB_CCM_RL
  $ci 02
      #DISABLE_AWB_DGAIN
      #AWB_CCM_L_HIGH_COLOR_TEMP
      #VAR_WRITE(48C2, 003D)
      #VAR_WRITE(48C4, 001C)
  $cl
      #SELECT_STW_OR_VPT(
        #AWB_CCM_L_HIGH_COLOR_TEMP
        #VAR_MODIFY(AC02, $s0.03 0) // AWB_MODE
        #VAR_WRITE(2C03, 0030)	// AWB_ALGO
        #SET_AWB_SCENE_RATIO(003A, 006F)
        #VAR_WRITE(683F, 0030)	// PRI_A_CONFIG_AWB_ALGO_RUN
      ,
        #AWB_CCM_L_HIGH_COLOR_TEMP_VPT
        #VAR_MODIFY(AC02, $s0.03 0) // AWB_MODE
        #VAR_WRITE(2C03, 0030)	// AWB_ALGO
        #SET_AWB_SCENE_RATIO(0037, 0071)
        #VAR_WRITE(683F, 0030)	// PRI_A_CONFIG_AWB_ALGO_RUN
      )
  $cx
  ;

// --- Flicker correction property 2 -------------
//
//  0 => auto, 1 => 50 Hz, 2 => 60 Hz,
//  TODO: 3 => disable
//------------------------------------------------
seq_set_prop_2_0=;
seq_set_prop_2_1=;
seq_set_prop_2_2=;
// seq_set_prop_2_3=;

// --- Vertical mirror property 3 ----------------
//
//  0 => off, 1 => on
//------------------------------------------------
seq_set_prop_3=;

// --- Horizontal mirror property 4 --------------
//
//  0 => off, 1 => on
//------------------------------------------------
seq_set_prop_4=;

// --- JPEG Compression property 5 ---------------
//
//  0 => normal
//  1 => low compression ("Fine" quality)
//------------------------------------------------
seq_set_prop_5_0= // normal quality
  $"=CAM=seq_set_prop_5_0=="
  #SET_JPEG_Q_SCALE_NORMAL
  ;
seq_set_prop_5_1= // fine quality
  $"=CAM=seq_set_prop_5_1=="
  #SET_JPEG_Q_SCALE_FINE
  ;

// --- Zoom property 6 ---------------------------
//
// 10 => 1.0 x zoom
// 11 => 1.1 x zoom
//    ...
// 25 => 2.5 x zoom
//  many of these values only work with certain sizes
//  if zoom selection is too great for current size,
//  then zoom will be 1.0x
//------------------------------------------------
seq_set_prop_6=
  $s2 %0    // int reg 2 gets new property selection
  $"=CAM=seq_set_prop_6_%2=="

  $ci 02
      #ZOOM_SET_REV2
  $cl
      $*2 0A
      $m1 2 $>1 8
      $<2 9 $<2 f $>2 f $>2 9
      #VAR_WRITE(5C18, $w1 $w2)
  $cx
  ;

// --- Exposure property 7 -----------------------
//
//  0 => Normal mode, 1 => Dark mode
//------------------------------------------------
seq_set_prop_7_0=$"=CAM=seq_set_prop_7_0" #NORMAL_LIGHT_MODE #SEQ_CMD_6;
seq_set_prop_7_1=$"=CAM=seq_set_prop_7_1" #DARK_LIGHT_MODE   #SEQ_CMD_6;

// --- Effect property 8 -------------------------
//
//  0 => normal,  1 => negative,      2 => solarize
//  3 => sepia,   4 => black & white
//------------------------------------------------
seq_set_prop_8_0=$"=CAM=seq_set_prop_8_0" #VAR_WRITE(E883, 0000) #VAR_WRITE(EC83, 0000) #SEQ_CMD_6;
seq_set_prop_8_1=$"=CAM=seq_set_prop_8_1" #VAR_WRITE(E883, 0003) #VAR_WRITE(EC83, 0003) #SEQ_CMD_6;
seq_set_prop_8_2=$"=CAM=seq_set_prop_8_2" #VAR_WRITE(E883, 0004) #VAR_WRITE(EC83, 0004) #SEQ_CMD_6;
seq_set_prop_8_3=$"=CAM=seq_set_prop_8_3" #VAR_WRITE(E883, 0002) #VAR_WRITE(EC83, 0002) #SEQ_CMD_6;
seq_set_prop_8_4=$"=CAM=seq_set_prop_8_4" #VAR_WRITE(E883, 0001) #VAR_WRITE(EC83, 0001) #SEQ_CMD_6;

// --- LED flash property 13 (d) -----------------
//
//  0 => off, 1 => on
//------------------------------------------------
seq_set_prop_d_0=; // turn off LED immediately
seq_set_prop_d_1=; // turn on LED at next frame vysnc blanking period

// --- Xenon flash property 14 (e) ---------------
//  
//  0 => off, 1 => auto external Xenon flash
//------------------------------------------------
seq_set_prop_e=;

// --- Burst mode property 19 (13) ---------------
//  
//  0 => burst has ended, 1 => burst will begin
//------------------------------------------------
seq_set_prop_13_0=$"=CAM=seq_set_prop_13_0" #PREVIEW_START;
seq_set_prop_13_1=$"=CAM=seq_set_prop_13_1";

// --- Test Pattern property 30 (1e) -------------
//  for ITP
//  0 => off, 1 => horizontal ramp,
//------------------------------------------------
seq_set_prop_1e_0= 3330 0000 $f;
seq_set_prop_1e_1= 3330 0008 $f;


//================================================
//=============== RESOLUTIONS ====================
//================================================

// JPEG SS
seq_ss_config_1=$"=CAM=seq_ss_config_1" $u06 #VAR_WRITE(6C00, 0280) #VAR_WRITE(6C02, 01E0) $sb 01;
seq_ss_config_2=$"=CAM=seq_ss_config_2" $u06 #VAR_WRITE(6C00, 0500) #VAR_WRITE(6C02, 03C0) $sb 01;
seq_ss_config_4=$"=CAM=seq_ss_config_4" $u06 #VAR_WRITE(6C00, 0660) #VAR_WRITE(6C02, 04C8) $sb 01;
seq_ss_config_5=$"=CAM=seq_ss_config_5" $u06 #VAR_WRITE(6C00, 0800) #VAR_WRITE(6C02, 0600) $sb 01;

// YUV SS
seq_ss_config_11=$"=CAM=seq_ss_config_11" $u06 #VAR_WRITE(6C00, 0280) #VAR_WRITE(6C02, 01E0) $sb 01;

// VF
seq_vf_config_20=$"=CAM=seq_vf_config_20"
  #VF_CONFIG_SET(
    // Context A QVGA YUV var 15fps (14.6fps)
    #AE_MODE_SET
  
    #VAR_WRITE(481D, 035C)	//(1) CAM1_CTX_A_BASE_FRAME_LENGTH_LINES

    //QVGA
    #VAR_WRITE(6800, 0140)	//(1) PRI_A_IMAGE_WIDTH
    #VAR_WRITE(6802, 00F0)	//(1) PRI_A_IMAGE_HEIGHT
    #VAR_WRITE(482B, 0408)	//(1) CAM1_CTX_A_OUTPUT_SIZE_WIDTH
    #VAR_WRITE(482D, 0308)	//(1) CAM1_CTX_A_OUTPUT_SIZE_HEIGHT
  )
  ;

seq_vf_config_23=$"=CAM=seq_vf_config_23"
  #VF_CONFIG_SET(
    // Context A 240x180 YUV var 15fps (14.6fps)
    #AE_MODE_SET
  
    #VAR_WRITE(481D, 035C)	//(1) CAM1_CTX_A_BASE_FRAME_LENGTH_LINES

    //240x180
    #VAR_WRITE(6800, 00F0)	//(1) PRI_A_IMAGE_WIDTH
    #VAR_WRITE(6802, 00B4)	//(1) PRI_A_IMAGE_HEIGHT
    #VAR_WRITE(482B, 0408)	//(1) CAM1_CTX_A_OUTPUT_SIZE_WIDTH
    #VAR_WRITE(482D, 0308)	//(1) CAM1_CTX_A_OUTPUT_SIZE_HEIGHT
  )
  ;

// VT
seq_vf_config_25=$"=CAM=seq_vf_config_25"
  #VF_CONFIG_SET(
    // Context A 96x128 YUV fixed 12fps (11.5fps)
    #AE_MODE_SET
  
    #VAR_WRITE(481D, 044A)	//(1) CAM1_CTX_A_BASE_FRAME_LENGTH_LINES

    #VAR_WRITE(6800, 0060)	//(1) PRI_A_IMAGE_WIDTH
    #VAR_WRITE(6802, 0080)	//(1) PRI_A_IMAGE_HEIGHT
    #VAR_WRITE(482B, 0241)	//(1) CAM1_CTX_A_OUTPUT_SIZE_WIDTH
    #VAR_WRITE(482D, 0300)	//(1) CAM1_CTX_A_OUTPUT_SIZE_HEIGHT
  )
  ;

seq_vf_config_26=$"=CAM=seq_vf_config_26"
  #VF_CONFIG_SET(
    // Context A 144x176 YUV fixed 12fps (11.5fps)
    #AE_MODE_SET
  
    #VAR_WRITE(481D, 044A)	//(1) CAM1_CTX_A_BASE_FRAME_LENGTH_LINES

    #VAR_WRITE(6800, 0090)	//(1) PRI_A_IMAGE_WIDTH
    #VAR_WRITE(6802, 00B0)	//(1) PRI_A_IMAGE_HEIGHT
    #VAR_WRITE(482B, 0277)	//(1) CAM1_CTX_A_OUTPUT_SIZE_WIDTH
    #VAR_WRITE(482D, 0300)	//(1) CAM1_CTX_A_OUTPUT_SIZE_HEIGHT
  )
  ;

seq_vf_config_27=$"=CAM=seq_vf_config_27"
  #VF_CONFIG_SET(
    // Context A 128x96 YUV fixed 12fps (11.5fps)
    #AE_MODE_SET
  
    #VAR_WRITE(481D, 044A)	//(1) CAM1_CTX_A_BASE_FRAME_LENGTH_LINES

    #VAR_WRITE(6800, 0080)	//(1) PRI_A_IMAGE_WIDTH
    #VAR_WRITE(6802, 0060)	//(1) PRI_A_IMAGE_HEIGHT
    #VAR_WRITE(482B, 03AA)	//(1) CAM1_CTX_A_OUTPUT_SIZE_WIDTH
    #VAR_WRITE(482D, 0308)	//(1) CAM1_CTX_A_OUTPUT_SIZE_HEIGHT
  )
  ;

seq_vf_config_28=$"=CAM=seq_vf_config_28"
  #VF_CONFIG_SET(
    // Context A 176x144 YUV fixed 12fps (11.5fps)
    #AE_MODE_SET
  
    #VAR_WRITE(481D, 044A)	//(1) CAM1_CTX_A_BASE_FRAME_LENGTH_LINES

    #VAR_WRITE(6800, 00B0)	//(1) PRI_A_IMAGE_WIDTH
    #VAR_WRITE(6802, 0090)	//(1) PRI_A_IMAGE_HEIGHT
    #VAR_WRITE(482B, 03AA)	//(1) CAM1_CTX_A_OUTPUT_SIZE_WIDTH
    #VAR_WRITE(482D, 0308)	//(1) CAM1_CTX_A_OUTPUT_SIZE_HEIGHT
  )
  ;

// VR
seq_vf_config_29=$"=CAM=seq_vf_config_29"
  #VF_CONFIG_SET(
    // Context A 144x176 YUV fixed 10fps (9.5fps)
    #AE_MODE_SET
  
    #VAR_WRITE(481D, 0528)	//(1) CAM1_CTX_A_BASE_FRAME_LENGTH_LINES

    #VAR_WRITE(6800, 0090)	//(1) PRI_A_IMAGE_WIDTH
    #VAR_WRITE(6802, 00B0)	//(1) PRI_A_IMAGE_HEIGHT
    #VAR_WRITE(482B, 0277)	//(1) CAM1_CTX_A_OUTPUT_SIZE_WIDTH
    #VAR_WRITE(482D, 0300)	//(1) CAM1_CTX_A_OUTPUT_SIZE_HEIGHT
  )
  ;

seq_vf_config_2b=$"=CAM=seq_vf_config_2b"
  #VF_CONFIG_SET(
    // Context A QVGA YUV fixed 15fps (14.6fps)
    #AE_MODE_SET
  
    #VAR_WRITE(481D, 035C)	//(1) CAM1_CTX_A_BASE_FRAME_LENGTH_LINES

    //QVGA
    #VAR_WRITE(6800, 0140)	//(1) PRI_A_IMAGE_WIDTH
    #VAR_WRITE(6802, 00F0)	//(1) PRI_A_IMAGE_HEIGHT
    #VAR_WRITE(482B, 0408)	//(1) CAM1_CTX_A_OUTPUT_SIZE_WIDTH
    #VAR_WRITE(482D, 0308)	//(1) CAM1_CTX_A_OUTPUT_SIZE_HEIGHT
  )
  ;

seq_vf_config_2c=$"=CAM=seq_vf_config_2c"
  #VF_CONFIG_SET(
    // Context A QVGA YUV fixed 7.5fps (7.32fps)
    #AE_MODE_SET

    #VAR_WRITE(481D, 06C2)	//(1) CAM1_CTX_A_BASE_FRAME_LENGTH_LINES

    //QVGA
    #VAR_WRITE(6800, 0140)	//(1) PRI_A_IMAGE_WIDTH
    #VAR_WRITE(6802, 00F0)	//(1) PRI_A_IMAGE_HEIGHT
    #VAR_WRITE(482B, 0408)	//(1) CAM1_CTX_A_OUTPUT_SIZE_WIDTH
    #VAR_WRITE(482D, 0308)	//(1) CAM1_CTX_A_OUTPUT_SIZE_HEIGHT
  )
  ;

seq_vf_config_2d=$"=CAM=seq_vf_config_2d"
  #VF_CONFIG_SET(
    // Context A 176x144 YUV fixed 10fps (9.5fps)
    #AE_MODE_SET
  
    #VAR_WRITE(481D, 0528)	//(1) CAM1_CTX_A_BASE_FRAME_LENGTH_LINES

    #VAR_WRITE(6800, 00B0)	//(1) PRI_A_IMAGE_WIDTH
    #VAR_WRITE(6802, 0090)	//(1) PRI_A_IMAGE_HEIGHT
    #VAR_WRITE(482B, 03AA)	//(1) CAM1_CTX_A_OUTPUT_SIZE_WIDTH
    #VAR_WRITE(482D, 0308)	//(1) CAM1_CTX_A_OUTPUT_SIZE_HEIGHT
  )
  ;


//------------------------------------------------
// VIEW FINDER SEQUENCES
//------------------------------------------------
seq_vf_start=$"=CAM=seq_vf_start" #FRAME_OUTPUT_ON;

seq_vf_stop= $"=CAM=seq_vf_stop" #FRAME_OUTPUT_OFF;


//------------------------------------------------
// SNAP SHOT SEQUENCES
//------------------------------------------------
seq_ss_start=$"=CAM=seq_ss_start: %tr"
  $z0
  $c0 11  // YUV capture
      #YUV_CAPTURE_START
  $cl     // JPEG capture
      $u05
      #JPEG_CAPTURE_START
  $cx
  #WAIT_CONTEXT_B
  #FRAME_OUTPUT_ON

  // workaround for rev2 1st jpeg fail issue for EMP P1U
  $ci 02
      $z0
      $c0 11 // YUV
      $cl    // JPEG
          #WAIT_CONTEXT_B_REV2
      $cx
  $cl $cx
  ;

seq_ss_take=//$"=CAM=seq_ss_take"
  $z0
  $c0 11  // YUV
  $cl     // JPEG
      $cc 00
      $cl // to enable new Q-scale for re-try
          #SEQ_CMD_6
          #WAIT_SEQ_CMD_END2
      $cx
  $cx
  ;

seq_ss_verify=//$"=CAM=seq_ss_verify"
  $z1
  $c1 11  // YUV capture
      #GET_EXIF_INFO
      $s0 01 // dummy: always JPEG ok
  $cl
      #GET_JPEG_STATUS
      $c0 00 // OK
          #GET_JPEG_Q_SCALE
          #GET_EXIF_INFO
          $s0 01
      $cl    // NG
          $s0 00
      $cx
      #JPEG_RETRY
  $cx
  ;

seq_ss_stop=
  $p0 13  // burst mode
  $c0 00
      #PREVIEW_START
  $cl
      // do nothing during burst
  $cx
  #FRAME_OUTPUT_OFF
  $"=CAM=seq_ss_stop: %td"
  ;


// TODO: define any of these that are needed:
// seq_read_data=;

// TODO: define any of these that are needed:
// cam_exif_ifd_x=
// cam_exif_type_x=
// cam_exif_tag_x=
// cam_exif_value_x=


//================================================
//=============== INITIALIZATION =================
//================================================

seq_init=$"=CAM=SETUP:seq_init:start %tr"
  #REGISTER_READ(0000)
  $"=CAM=read_Chip_ID__should_be_0x2680==%1=%0="

  #INIT_SETTINGS_1
  #INIT_SETTINGS_2
  #INIT_SETTINGS_3
  #INIT_SETTINGS_4
  #INIT_SETTINGS_5
  #INIT_SETTINGS_6
  #INIT_SETTINGS_7
  #INIT_SETTINGS_8

  //----------------------------------------------
  // SEMC original initial sittings

  // SEMC Sepia colour: Cr=+14=0x0E, Cb=-15=0xF1
  #VAR_WRITE(E885, 000E) #VAR_WRITE(E886, 00F1) // PRI_A_CONFIG_SYSCTRL_SEPIA_CR/CB
  #VAR_WRITE(EC85, 000E) #VAR_WRITE(EC86, 00F1) // PRI_B_CONFIG_SYSCTRL_SEPIA_CR/CB

  // zoom enable
  #VAR_MODIFY(687F, $s0.05 1)  // PRI_A_CONFIG_SYSCTRL_ALGO_RUN
  #VAR_MODIFY(6C7F, $s0.05 1)  // PRI_B_CONFIG_SYSCTRL_ALGO_RUN

  // Properties
  $u00 $u01 $u05

  // horizontal mirror and vertical flip for ONLY_ALICIA 
// #VAR_MODIFY(480C, $s0.00 1 $s0.01 1) // ONLY_ALICIA 
// #VAR_MODIFY(4854, $s0.00 1 $s0.01 1) // ONLY_ALICIA 

  $sb FF

  $"=CAM=SETUP:seq_init:end %td"
  ;

// cam_init_result=


//================================================
//============ JPEG HEADER CREATION ==============
//================================================
jpeg_qtable_selector_0=$"jpeg_qtable_selector_0" $s2 00 $m0 f;
jpeg_qtable_selector_1=$"jpeg_qtable_selector_1" $s2 01 $m0 f;

jpeg_qtable_0=
  10 0B 0C 0E 0C 0A 10 0E
  0D 0E 12 11 10 13 18 28
  1A 18 16 16 18 31 23 25
  1D 28 3A 33 3D 3C 39 33
  38 37 40 48 5C 4E 40 44
  57 45 37 38 50 6D 51 57
  5F 62 67 68 67 3E 4D 71
  79 70 64 78 5C 65 67 63
  ;

jpeg_qtable_1=
  11 12 12 18 15 18 2F 1A
  1A 2F 63 42 38 42 63 63
  63 63 63 63 63 63 63 63
  63 63 63 63 63 63 63 63
  63 63 63 63 63 63 63 63
  63 63 63 63 63 63 63 63
  63 63 63 63 63 63 63 63
  63 63 63 63 63 63 63 63
  ;

// Q-scale factors for MT9T111
jpeg_qtable_factors=
      1,   800,  1000,  1800,  2000,  2800,  3000,  3800,
   4000,  4800,  5000,  5800,  6000,  6800,  7000,  7800,
   8000,  8800,  9000,  9800,  A000,  A800,  B000,  B800,
   C000,  C800,  D000,  D800,  E000,  E800,  F000,  F800,
  10000, 10800, 11000, 11800, 12000, 12800, 13000, 13800,
  14000, 14800, 15000, 15800, 16000, 16800, 17000, 17800,
  18000, 18800, 19000, 19800, 1A000, 1A800, 1B000, 1B800,
  1C000, 1C800, 1D000, 1D800, 1E000, 1E800, 1F000, 1F800,
  20000, 20800, 21000, 21800, 22000, 22800, 23000, 23800,
  24000, 24800, 25000, 25800, 26000, 26800, 27000, 27800,
  28000
  ;

jpeg_header=
  FF D8
  FF E0 00 10 4A 46 49 46 00 01 01 00 00 01 00 01 00 00
  FF DB 00 84 00 $qt0  01 $qt1                             
  FF C4 01 A2 00 00 01 05 01 01 01 01 01 01 00 00 00 00 00 00 00 
                 00 01 02 03 04 05 06 07 08 09 0A 0B
              01 00 03 01 01 01 01 01 01 01 01 01 00 00 00 00 00 
                 00 01 02 03 04 05 06 07 08 09 0A 0B
              10 00 02 01 03 03 02 04 03 05 05 04 04 00 00 01 7D
                 01 02 03 00 04 11 05 12 21 31 41 06 13 51 61 07 
                 22 71 14 32 81 91 a1 08 23 42 b1 c1 15 52 d1 f0 
                 24 33 62 72 82 09 0a 16 17 18 19 1a 25 26 27 28 
                 29 2a 34 35 36 37 38 39 3a 43 44 45 46 47 48 49 
                 4a 53 54 55 56 57 58 59 5a 63 64 65 66 67 68 69 
                 6a 73 74 75 76 77 78 79 7a 83 84 85 86 87 88 89 
                 8a 92 93 94 95 96 97 98 99 9a a2 a3 a4 a5 a6 a7 
                 a8 a9 aa b2 b3 b4 b5 b6 b7 b8 b9 ba c2 c3 c4 c5 
                 c6 c7 c8 c9 ca d2 d3 d4 d5 d6 d7 d8 d9 da e1 e2
                 e3 e4 e5 e6 e7 e8 e9 ea f1 f2 f3 f4 f5 f6 f7 f8 
                 f9 fa
              11 00 02 01 02 04 04 03 04 07 05 04 04 00 01 02 77
                 00 01 02 03 11 04 05 21 31 06 12 41 51 07 61 71 
                 13 22 32 81 08 14 42 91 a1 b1 c1 09 23 33 52 f0 
                 15 62 72 d1 0a 16 24 34 e1 25 f1 17 18 19 1a 26 
                 27 28 29 2a 35 36 37 38 39 3a 43 44 45 46 47 48 
                 49 4a 53 54 55 56 57 58 59 5a 63 64 65 66 67 68 
                 69 6a 73 74 75 76 77 78 79 7a 82 83 84 85 86 87 
                 88 89 8a 92 93 94 95 96 97 98 99 9a a2 a3 a4 a5 
                 a6 a7 a8 a9 aa b2 b3 b4 b5 b6 b7 b8 b9 ba c2 c3 
                 c4 c5 c6 c7 c8 c9 ca d2 d3 d4 d5 d6 d7 d8 d9 da
                 e2 e3 e4 e5 e6 e7 e8 e9 ea f2 f3 f4 f5 f6 f7 f8 
                 f9 fa
  FF C0 00 11 08 $h $w 03 01 21 00 02 11 01 03 11 01
  FF DA 00 0C 03 01 00 02 11 03 11 00 3F 00
  ;


//================================================
//================ DEBUG & TEST ==================
//================================================

// --- set register page address 32 (20) ---------
//  instead of I2CR
//------------------------------------------------
seq_set_prop_20=
  $sm %0
  ;

// --- register read 33 (21) ---------------------
//  instead of I2CR
//------------------------------------------------
seq_set_prop_21=
  $sn %0
  $wm $wn $r2 1 0
  $"===REG_%m_%n==%1_%0==="
  ;

// --- var read 34 (22) --------------------------
//  instead of I2CR
//------------------------------------------------
seq_set_prop_22=
  $sn %0
  098E $wm $wn $f 0990 $r2 1 0
  $"===VAR_%m_%n==%1_%0==="
  ;

// --- debug 35 (23) -----------------------------
//  for debug
//------------------------------------------------
seq_set_prop_23_0=;
seq_set_prop_23_1=
  #SEQ_CMD_1
  ;

seq_set_prop_23_2=
  #SEQ_CMD_2
  ;

seq_set_prop_23_3=;
seq_set_prop_23_4=;

seq_set_prop_23_5=
  #SEQ_CMD_5
  ;

seq_set_prop_23_6=
  #SEQ_CMD_6
  ;

seq_set_prop_23_7=
  0800 0000 $f
  0800 0000 $f
  #REGISTER_READ(0800) $<1 8 $+1 r0 $m2 1  $"=ver1=%2=="
  0802 0000 $f
  0802 0000 $f
  #REGISTER_READ(0802) $<1 8 $+1 r0 $m3 1  $"=ver2=%3=="

  $s0 20 $<0 8 $+0 FA  $"=20FA=%0=="
  $c3 r0
      $c2 00
          080A 0000 $f
          080A 0000 $f
          #REGISTER_READ(080A) $mi 0  $"=ver3_1=%i=="
      $cl 
          $s0 F8 $<0 8 $+0 03  $"=F803=%0=="
          $c2 r0
              080A 0000 $f
              080A 0000 $f
              #REGISTER_READ(080A) $mi 0   $"=ver3_2=%i=="
          $cl
              0808 0000 $f
              0808 0000 $f
              #REGISTER_READ(0808) $mi 0   $"=ver3_3=%i=="
          $cx
      $cx
  $cl
      0808 0000 $f
      0808 0000 $f
      #REGISTER_READ(0808) $mi 0   $"=ver3_4=%i=="
  $cx

  $ci.07 0 $>i 5

  $"==Sensor=Rev=%i=="
  ;

seq_set_prop_23_8=
  0800 0000 $f
  0800 0000 $f
  #REGISTER_READ(0800)

  0802 0000 $f
  0802 0000 $f
  #REGISTER_READ(0802)

  0804 0000 $f
  0804 0000 $f
  #REGISTER_READ(0804)

  0806 0000 $f
  0806 0000 $f
  #REGISTER_READ(0806)

  0808 0000 $f
  0808 0000 $f
  #REGISTER_READ(0808)

  080A 0000 $f
  080A 0000 $f
  #REGISTER_READ(080A)
  ;

seq_set_prop_23_9=
  #REGISTER_READ(3C5C)
  #VAR_WRITE(68AA, $w1 $w0)
  #VAR_READ(68AA)
  #VAR_WRITE(6CAA, $w1 $w0)
  #VAR_READ(6CAA)

  #VAR_WRITE(E8AC, 0001)
  #VAR_WRITE(ECAC, 0001)
  ;

seq_set_prop_23_a=
  #REGISTER_READ(3C5C)
  ;

seq_set_prop_23_b=
  #VAR_WRITE(E8AC, 0000)
  #VAR_WRITE(ECAC, 0000)
  ;

seq_set_prop_23_c=
  $u06
  #VAR_WRITE(6C00, 0800) #VAR_WRITE(6C02, 0600)
  $u05
  #JPEG_CAPTURE_START
  ;

seq_set_prop_23_d=
  #OTPM_INIT
  #OTPM_READ(0004)
  #OTPM_READ(0006)
  #OTPM_END
  ;

// --- debug 36 (24) -----------------------------
//  for zoom debug
//------------------------------------------------
seq_set_prop_24=
  #VAR_WRITE(5C18, 00 %0);
  ;
