33import  cv2 
44
55# Derived from: 
6- # https:// github.com/openmv/openmv/blob/5acf5baf92b4314a549bdd068138e5df6cc0bac7/drivers/sensors/hm01b0.c 
6+ # https:# github.com/openmv/openmv/blob/5acf5baf92b4314a549bdd068138e5df6cc0bac7/drivers/sensors/hm01b0.c 
77class  HM01B0 (DVP_Camera ):
88
99    # Read only registers 
@@ -128,6 +128,8 @@ class HM01B0(DVP_Camera):
128128    HIMAX_FRAME_LENGTH_QQVGA  =  0x084 
129129
130130    INIT_COMMANDS  =  (
131+         (BLC_TGT ,              0x08 ),          #  BLC target :8  at 8 bit mode 
132+         (BLC2_TGT ,             0x08 ),          #  BLI target :8  at 8 bit mode 
131133        (0x3044 ,               0x0A ),          #  Increase CDS time for settling 
132134        (0x3045 ,               0x00 ),          #  Make symmetric for cds_tg and rst_tg 
133135        (0x3047 ,               0x0A ),          #  Increase CDS time for settling 
@@ -145,10 +147,36 @@ class HM01B0(DVP_Camera):
145147        (0x3065 ,               0x04 ),          #  pad pull 0 
146148        (ANA_Register_17 ,      0x00 ),          #  Disable internal oscillator 
147149
150+         (BLC_CFG ,              0x43 ),          #  BLC_on, IIR 
151+ 
152+         (0x1001 ,               0x43 ),          #  BLC dithering en 
153+         (0x1002 ,               0x43 ),          #  blc_darkpixel_thd 
154+         (0x0350 ,               0x7F ),          #  Dgain Control 
155+         (BLI_EN ,               0x01 ),          #  BLI enable 
156+         (0x1003 ,               0x00 ),          #  BLI Target [Def: 0x20] 
157+ 
158+         (DPC_CTRL ,             0x01 ),          #  DPC option 0: DPC off   1 : mono   3 : bayer1   5 : bayer2 
159+         (0x1009 ,               0xA0 ),          #  cluster hot pixel th 
160+         (0x100A ,               0x60 ),          #  cluster cold pixel th 
161+         (SINGLE_THR_HOT ,       0x90 ),          #  single hot pixel th 
162+         (SINGLE_THR_COLD ,      0x40 ),          #  single cold pixel th 
148163        (0x1012 ,               0x00 ),          #  Sync. shift disable 
164+         (STATISTIC_CTRL ,       0x07 ),          #  AE stat en | MD LROI stat en | magic 
165+         (0x2003 ,               0x00 ),
166+         (0x2004 ,               0x1C ),
167+         (0x2007 ,               0x00 ),
168+         (0x2008 ,               0x58 ),
169+         (0x200B ,               0x00 ),
170+         (0x200C ,               0x7A ),
171+         (0x200F ,               0x00 ),
172+         (0x2010 ,               0xB8 ),
173+         (0x2013 ,               0x00 ),
174+         (0x2014 ,               0x58 ),
175+         (0x2017 ,               0x00 ),
176+         (0x2018 ,               0x9B ),
149177
150178        (AE_CTRL ,              0x01 ),          #Automatic Exposure 
151-         (AE_TARGET_MEAN ,       0x80 ),          #AE target mean          [Def: 0x3C] 
179+         (AE_TARGET_MEAN ,       0x64 ),          #AE target mean          [Def: 0x3C] 
152180        (AE_MIN_MEAN ,          0x0A ),          #AE min target mean      [Def: 0x0A] 
153181        (CONVERGE_IN_TH ,       0x03 ),          #Converge in threshold   [Def: 0x03] 
154182        (CONVERGE_OUT_TH ,      0x05 ),          #Converge out threshold  [Def: 0x05] 
@@ -165,12 +193,23 @@ class HM01B0(DVP_Camera):
165193        (DIGITAL_GAIN_H ,       0x01 ),          #Digital Gain High       [Def: 0x01] 
166194        (DIGITAL_GAIN_L ,       0x00 ),          #Digital Gain Low        [Def: 0x00] 
167195
196+         (FS_CTRL ,              0x00 ),          #Flicker Control 
197+ 
198+         (FS_60HZ_H ,            0x00 ),
199+         (FS_60HZ_L ,            0x3C ),
200+         (FS_50HZ_H ,            0x00 ),
201+         (FS_50HZ_L ,            0x32 ),
202+ 
168203        (MD_CTRL ,              0x00 ),
169204        (FRAME_LEN_LINES_H ,    HIMAX_FRAME_LENGTH_QVGA  >>  8 ),
170205        (FRAME_LEN_LINES_L ,    HIMAX_FRAME_LENGTH_QVGA  &  0xFF ),
171206        (LINE_LEN_PCK_H ,       HIMAX_LINE_LEN_PCK_QVGA  >>  8 ),
172207        (LINE_LEN_PCK_L ,       HIMAX_LINE_LEN_PCK_QVGA  &  0xFF ),
173208        (QVGA_WIN_EN ,          0x01 ),          # Enable QVGA window readout 
209+         (0x0383 ,               0x01 ),
210+         (0x0387 ,               0x01 ),
211+         (0x0390 ,               0x00 ),
212+         (0x3011 ,               0x70 ),
174213        (0x3059 ,               0x22 ), # 1-bit mode 
175214        (OSC_CLK_DIV ,          0x14 ),
176215        (IMG_ORIENTATION ,      0x00 ),          # change the orientation 
@@ -217,7 +256,14 @@ def soft_reset(self):
217256        Performs a software reset of the HM01B0 sensor. 
218257        This resets the sensor to its default state. 
219258        """ 
220-         self .writeRegister (self .SW_RESET , self .HIMAX_RESET )
259+         # HM01B0 can require multiple attempts to reset properly 
260+         for  i  in  range (self .HIMAX_BOOT_RETRY ):
261+             self .writeRegister (self .SW_RESET , self .HIMAX_RESET )
262+             sleep_us (1000 )
263+             mode  =  self .readRegister (self .MODE_SELECT )
264+             if  mode [0 ] ==  self .HIMAX_MODE_STANDBY :
265+                 break 
266+             sleep_us (10000 )
221267
222268    def  setMode (self , mode ):
223269        """ 
0 commit comments