@@ -52,44 +52,44 @@ struct hm0360_data {
5252#define FRAME_COUNT_H 0x0005
5353#define FRAME_COUNT_L 0x0006
5454#define PIXEL_ORDER 0x0007
55- // Sensor mode control
55+ /* Sensor mode control */
5656#define MODE_SELECT 0x0100
5757#define IMG_ORIENTATION 0x0101
5858#define EMBEDDED_LINE_EN 0x0102
5959#define SW_RESET 0x0103
6060#define COMMAND_UPDATE 0x0104
61- // Sensor exposure gain control
61+ /* Sensor exposure gain control */
6262#define INTEGRATION_H 0x0202
6363#define INTEGRATION_L 0x0203
6464#define ANALOG_GAIN 0x0205
6565#define DIGITAL_GAIN_H 0x020E
6666#define DIGITAL_GAIN_L 0x020F
67- // Clock control
67+ /* Clock control */
6868#define PLL1_CONFIG 0x0300
6969#define PLL2_CONFIG 0x0301
7070#define PLL3_CONFIG 0x0302
71- // Frame timing control
71+ /* Frame timing control */
7272#define FRAME_LEN_LINES_H 0x0340
7373#define FRAME_LEN_LINES_L 0x0341
7474#define LINE_LEN_PCK_H 0x0342
7575#define LINE_LEN_PCK_L 0x0343
76- // Monochrome programming
76+ /* Monochrome programming */
7777#define MONO_MODE 0x0370
7878#define MONO_MODE_ISP 0x0371
7979#define MONO_MODE_SEL 0x0372
80- // Binning mode control
80+ /* Binning mode control */
8181#define H_SUBSAMPLE 0x0380
8282#define V_SUBSAMPLE 0x0381
8383#define BINNING_MODE 0x0382
84- // Test pattern control
84+ /* Test pattern control */
8585#define TEST_PATTERN_MODE 0x0601
86- // Black level control
86+ /* Black level control */
8787#define BLC_TGT 0x1004
8888#define BLC2_TGT 0x1009
8989#define MONO_CTRL 0x100A
90- // VSYNC / HSYNC / pixel shift registers
90+ /* VSYNC / HSYNC / pixel shift registers */
9191#define OPFM_CTRL 0x1014
92- // Tone mapping registers
92+ /* Tone mapping registers */
9393#define CMPRS_CTRL 0x102F
9494#define CMPRS_01 0x1030
9595#define CMPRS_02 0x1031
@@ -107,7 +107,7 @@ struct hm0360_data {
107107#define CMPRS_14 0x103D
108108#define CMPRS_15 0x103E
109109#define CMPRS_16 0x103F
110- // Automatic exposure control
110+ /* Automatic exposure control */
111111#define AE_CTRL 0x2000
112112#define AE_CTRL1 0x2001
113113#define CNT_ORGH_H 0x2002
@@ -145,13 +145,13 @@ struct hm0360_data {
145145#define AE_MEAN 0x205D
146146#define AE_CONVERGE 0x2060
147147#define AE_BLI_TGT 0x2070
148- // Interrupt control
148+ /* Interrupt control */
149149#define PULSE_MODE 0x2061
150150#define PULSE_TH_H 0x2062
151151#define PULSE_TH_L 0x2063
152152#define INT_INDIC 0x2064
153153#define INT_CLEAR 0x2065
154- // Motion detection control
154+ /* Motion detection control */
155155#define MD_CTRL 0x2080
156156#define ROI_START_END_V 0x2081
157157#define ROI_START_END_H 0x2082
@@ -163,20 +163,20 @@ struct hm0360_data {
163163#define MD_LATENCY 0x209C
164164#define MD_LATENCY_TH 0x209D
165165#define MD_CTRL1 0x209E
166- // Context switch control registers
166+ /* Context switch control registers */
167167#define PMU_CFG_3 0x3024
168168#define PMU_CFG_4 0x3025
169- // Operation mode control
169+ /* Operation mode control */
170170#define WIN_MODE 0x3030
171- // IO and clock control
171+ /* IO and clock control */
172172#define PAD_REGISTER_07 0x3112
173173
174- // Register bits/values
174+ /* Register bits/values */
175175#define HIMAX_RESET 0x01
176176#define HIMAX_MODE_STANDBY 0x00
177- #define HIMAX_MODE_STREAMING 0x01 // I2C triggered streaming enable
178- #define HIMAX_MODE_STREAMING_NFRAMES 0x03 // Output N frames
179- #define HIMAX_MODE_STREAMING_TRIG 0x05 // Hardware Trigger
177+ #define HIMAX_MODE_STREAMING 0x01 /* I2C triggered streaming enable */
178+ #define HIMAX_MODE_STREAMING_NFRAMES 0x03 /* Output N frames */
179+ #define HIMAX_MODE_STREAMING_TRIG 0x05 /* Hardware Trigger */
180180#define HIMAX_SET_HMIRROR (r , x ) ((r&0xFE)|((x&1)<<0))
181181#define HIMAX_SET_VMIRROR (r , x ) ((r&0xFD)|((x&1)<<1))
182182
@@ -203,7 +203,7 @@ static const struct hm0360_reg hm0360_default_regs[] = {
203203 {MONO_MODE_ISP , 0x01 },
204204 {MONO_MODE_SEL , 0x01 },
205205
206- // BLC control
206+ /* BLC control */
207207 {0x1000 , 0x01 },
208208 {0x1003 , 0x04 },
209209 {BLC_TGT , 0x04 },
@@ -212,10 +212,10 @@ static const struct hm0360_reg hm0360_default_regs[] = {
212212 {BLC2_TGT , 0x04 },
213213 {MONO_CTRL , 0x01 },
214214
215- // Output format control
215+ /* Output format control */
216216 {OPFM_CTRL , 0x0C },
217217
218- // Reserved regs
218+ /* Reserved regs */
219219 {0x101D , 0x00 },
220220 {0x101E , 0x01 },
221221 {0x101F , 0x00 },
@@ -240,28 +240,28 @@ static const struct hm0360_reg hm0360_default_regs[] = {
240240 {CMPRS_15 , 0xCC },
241241 {CMPRS_16 , 0xE6 },
242242
243- {0x3112 , 0x00 }, // PCLKO_polarity falling
243+ {0x3112 , 0x00 }, /* PCLKO_polarity falling */
244244
245- {PLL1_CONFIG , 0x08 }, // Core = 24MHz PCLKO = 24MHz I2C = 12MHz
246- {PLL2_CONFIG , 0x0A }, // MIPI pre-dev (default)
247- {PLL3_CONFIG , 0x77 }, // PMU/MIPI pre-dev (default)
245+ {PLL1_CONFIG , 0x08 }, /* Core = 24MHz PCLKO = 24MHz I2C = 12MHz */
246+ {PLL2_CONFIG , 0x0A }, /* MIPI pre-dev (default) */
247+ {PLL3_CONFIG , 0x77 }, /* PMU/MIPI pre-dev (default) */
248248
249- {PMU_CFG_3 , 0x08 }, // Disable context switching
250- {PAD_REGISTER_07 , 0x00 }, // PCLKO_polarity falling
249+ {PMU_CFG_3 , 0x08 }, /* Disable context switching */
250+ {PAD_REGISTER_07 , 0x00 }, /* PCLKO_polarity falling */
251251
252- {AE_CTRL , 0x5F }, // Automatic Exposure (NOTE: Auto framerate enabled)
252+ {AE_CTRL , 0x5F }, /* Automatic Exposure (NOTE: Auto framerate enabled) */
253253 {AE_CTRL1 , 0x00 },
254- {T_DAMPING , 0x20 }, // AE T damping factor
255- {N_DAMPING , 0x00 }, // AE N damping factor
256- {AE_TARGET_MEAN , 0x64 }, // AE target
257- {AE_MIN_MEAN , 0x0A }, // AE min target mean
258- {AE_TARGET_ZONE , 0x23 }, // AE target zone
259- {CONVERGE_IN_TH , 0x03 }, // AE converge in threshold
260- {CONVERGE_OUT_TH , 0x05 }, // AE converge out threshold
254+ {T_DAMPING , 0x20 }, /* AE T damping factor */
255+ {N_DAMPING , 0x00 }, /* AE N damping factor */
256+ {AE_TARGET_MEAN , 0x64 }, /* AE target */
257+ {AE_MIN_MEAN , 0x0A }, /* AE min target mean */
258+ {AE_TARGET_ZONE , 0x23 }, /* AE target zone */
259+ {CONVERGE_IN_TH , 0x03 }, /* AE converge in threshold */
260+ {CONVERGE_OUT_TH , 0x05 }, /* AE converge out threshold */
261261 {MAX_INTG_H , (HIMAX_FRAME_LENGTH_QVGA - 4 ) >> 8 },
262262 {MAX_INTG_L , (HIMAX_FRAME_LENGTH_QVGA - 4 ) & 0xFF },
263263
264- {MAX_AGAIN , 0x04 }, // Maximum analog gain
264+ {MAX_AGAIN , 0x04 }, /* Maximum analog gain */
265265 {MAX_DGAIN_H , 0x03 },
266266 {MAX_DGAIN_L , 0x3F },
267267 {INTEGRATION_H , 0x01 },
@@ -271,7 +271,7 @@ static const struct hm0360_reg hm0360_default_regs[] = {
271271 {MD_TH_MIN , 0x01 },
272272 {MD_BLOCK_NUM_TH , 0x01 },
273273 {MD_CTRL1 , 0x06 },
274- {PULSE_MODE , 0x00 }, // Interrupt in level mode.
274+ {PULSE_MODE , 0x00 }, /* Interrupt in level mode. */
275275 {ROI_START_END_V , 0xF0 },
276276 {ROI_START_END_H , 0xF0 },
277277
@@ -286,15 +286,15 @@ static const struct hm0360_reg hm0360_default_regs[] = {
286286 {IMG_ORIENTATION , 0x00 },
287287 {COMMAND_UPDATE , 0x01 },
288288
289- /// SYNC function config.
289+ /* SYNC function config. */
290290 {0x3010 , 0x00 },
291291 {0x3013 , 0x01 },
292292 {0x3019 , 0x00 },
293293 {0x301A , 0x00 },
294294 {0x301B , 0x20 },
295295 {0x301C , 0xFF },
296296
297- // PREMETER config.
297+ /* PREMETER config. */
298298 {0x3026 , 0x03 },
299299 {0x3027 , 0x81 },
300300 {0x3028 , 0x01 },
@@ -303,7 +303,7 @@ static const struct hm0360_reg hm0360_default_regs[] = {
303303 {0x302E , 0x00 },
304304 {0x302F , 0x00 },
305305
306- // Magic regs 🪄.
306+ /* Magic regs 🪄. */
307307 {0x302B , 0x2A },
308308 {0x302C , 0x00 },
309309 {0x302D , 0x03 },
@@ -477,8 +477,8 @@ static const struct hm0360_reg hm0360_default_regs[] = {
477477 {0x317D , 0x02 },
478478 {0x318C , 0x00 },
479479
480- {0x310F , 0x00 }, // puts it in 8bit mode
481- {0x3112 , 0x04 }, // was 0x0c
480+ {0x310F , 0x00 }, /* puts it in 8bit mode */
481+ {0x3112 , 0x04 }, /* was 0x0c */
482482
483483 {COMMAND_UPDATE , 0x01 },
484484};
@@ -522,7 +522,7 @@ static const struct hm0360_reg hm0360_qvga_regs[] = {
522522};
523523
524524static const struct hm0360_reg hm0360_qqvga_regs [] = {
525- {PLL1_CONFIG , 0x09 }, // Core = 12MHz PCLKO = 24MHz I2C = 12MHz
525+ {PLL1_CONFIG , 0x09 }, /* Core = 12MHz PCLKO = 24MHz I2C = 12MHz */
526526 {H_SUBSAMPLE , 0x02 },
527527 {V_SUBSAMPLE , 0x02 },
528528 {BINNING_MODE , 0x00 },
@@ -612,19 +612,6 @@ static int hm0360_write_reg(const struct i2c_dt_spec *spec, const uint16_t addr,
612612 return i2c_transfer_dt (spec , msg , 2 );
613613}
614614
615- static int hm0360_modify_reg (const struct i2c_dt_spec * spec , const uint16_t addr ,
616- const uint8_t mask , const uint8_t val )
617- {
618- uint8_t regVal = 0 ;
619- int ret = hm0360_read_reg (spec , addr , & regVal , sizeof (regVal ));
620-
621- if (ret ) {
622- return ret ;
623- }
624-
625- return hm0360_write_reg (spec , addr , (regVal & ~mask ) | (val & mask ));
626- }
627-
628615static int hm0360_write_multi_regs (const struct i2c_dt_spec * spec , const struct hm0360_reg * regs ,
629616 const uint32_t num_regs )
630617{
@@ -654,7 +641,10 @@ static int hm0360_set_frmival(const struct device *dev, struct video_frmival *fr
654641 bool highres = false;
655642
656643 ret = video_get_format (dev , & fmt );
657-
644+ if (ret < 0 ) {
645+ LOG_ERR ("Can not get video format" );
646+ return ret ;
647+ }
658648 /* Set output resolution */
659649 while (fmts [i ].pixelformat ) {
660650 if (fmts [i ].width_min == fmt .width && fmts [i ].height_min == fmt .height ) {
@@ -666,13 +656,12 @@ static int hm0360_set_frmival(const struct device *dev, struct video_frmival *fr
666656 case 320 : /* QVGA */
667657 highres = false;
668658 break ;
669- default : /* VGA */
659+ case 640 : /* VGA */
670660 highres = true;
671661 break ;
672- }
673- if (ret < 0 ) {
662+ default :
674663 LOG_ERR ("Resolution not set!" );
675- return ret ;
664+ return - ENOTSUP ;
676665 }
677666 }
678667 i ++ ;
@@ -681,24 +670,24 @@ static int hm0360_set_frmival(const struct device *dev, struct video_frmival *fr
681670 drv_data -> cur_frmrate = frmival -> numerator ;
682671
683672 if (frmival -> numerator <= 10 ) {
684- osc_div = ( highres == true) ? 0x03 : 0x03 ;
673+ osc_div = 0x03 ;
685674 } else if (frmival -> numerator <= 15 ) {
686675 osc_div = (highres == true) ? 0x02 : 0x03 ;
687676 } else if (frmival -> numerator <= 30 ) {
688677 osc_div = (highres == true) ? 0x01 : 0x02 ;
689678 } else {
690- // Set to the max possible FPS at this resolution.
679+ /* Set to the max possible FPS at this resolution. */
691680 osc_div = (highres == true) ? 0x00 : 0x01 ;
692681 }
693682
694683 ret = hm0360_write_reg (& config -> bus , PLL1_CONFIG , pll_cfg );
695- if (ret < 0 ) {
684+ if (ret ) {
696685 LOG_ERR ("Could not read PLL1 Config" );
697686 return ret ;
698687 }
699688
700689 ret = hm0360_write_reg (& config -> bus , PLL1_CONFIG , (pll_cfg & 0xFC ) | osc_div );
701- if (ret < 0 ) {
690+ if (ret ) {
702691 LOG_ERR ("Could not set PLL1 Config" );
703692 return ret ;
704693 }
@@ -746,7 +735,7 @@ static int hm0360_set_fmt(const struct device *dev, struct video_format *fmt)
746735 memcpy (& data -> fmt , fmt , sizeof (data -> fmt ));
747736
748737 k_msleep (300 );
749- // Note: hm0360 only supports grayscale so pixelformat does not need to be set
738+ /* Note: hm0360 only supports grayscale so pixelformat does not need to be set */
750739 LOG_INF ("hm0360_set_fmt: W:%u H:%u fmt:%x" , fmt -> width , fmt -> height , fmt -> pixelformat );
751740 /* Set output resolution */
752741 while (fmts [i ].pixelformat ) {
@@ -885,7 +874,7 @@ static int hm0360_init(const struct device *dev)
885874 /* Reset camera registers */
886875 ret = hm0360_write_reg (& config -> bus , SW_RESET , HIMAX_RESET );
887876
888- if (ret < 0 ) {
877+ if (ret ) {
889878 LOG_ERR ("Could not write reset: %d" , ret );
890879 return ret ;
891880 }
@@ -922,7 +911,7 @@ static int hm0360_set_stream(const struct device *dev, bool enable, enum video_b
922911 const struct hm0360_config * config = dev -> config ;
923912
924913 ret = hm0360_write_reg (& config -> bus , MODE_SELECT , HIMAX_MODE_STREAMING );
925- if (ret < 0 ) {
914+ if (ret ) {
926915 LOG_ERR ("Could not set streaming" );
927916 return ret ;
928917 }
@@ -947,12 +936,12 @@ static int hm0360_set_ctrl(const struct device *dev, uint32_t id)
947936 return ret ;
948937 case VIDEO_CID_HFLIP :
949938 ret = hm0360_read_reg (& config -> bus , IMG_ORIENTATION , & data , sizeof (data ));
950- ret = hm0360_write_reg (& config -> bus , IMG_ORIENTATION , HIMAX_SET_HMIRROR (data , ctrls -> hflip .val ));
939+ ret | = hm0360_write_reg (& config -> bus , IMG_ORIENTATION , HIMAX_SET_HMIRROR (data , ctrls -> hflip .val ));
951940 ret |= hm0360_write_reg (& config -> bus , COMMAND_UPDATE , 0x01 );
952941 return ret ;
953942 case VIDEO_CID_VFLIP :
954943 ret = hm0360_read_reg (& config -> bus , IMG_ORIENTATION , & data , sizeof (data ));
955- ret = hm0360_write_reg (& config -> bus , IMG_ORIENTATION , HIMAX_SET_VMIRROR (data , ctrls -> vflip .val ));
944+ ret | = hm0360_write_reg (& config -> bus , IMG_ORIENTATION , HIMAX_SET_VMIRROR (data , ctrls -> vflip .val ));
956945 ret |= hm0360_write_reg (& config -> bus , COMMAND_UPDATE , 0x01 );
957946 return ret ;
958947 default :
0 commit comments