@@ -115,6 +115,7 @@ struct hm01b0_ctrls {
115115struct hm01b0_data {
116116 struct hm01b0_ctrls ctrls ;
117117 struct video_format fmt ;
118+ uint16_t cur_frmrate ;
118119};
119120
120121struct hm01b0_config {
@@ -284,6 +285,73 @@ static int hm01b0_soft_reset(const struct device *dev)
284285 return ret ;
285286}
286287
288+ static int hm01b0_set_frmival (const struct device * dev , struct video_frmival * frmival )
289+ {
290+ const struct hm01b0_config * config = dev -> config ;
291+ struct video_format fmt ;
292+ struct hm01b0_data * drv_data = dev -> data ;
293+ int ret ;
294+
295+ uint32_t osc_div = 0 ;
296+ bool highres = false;
297+
298+ ret = hm01b0_get_fmt (dev , & fmt );
299+ if (ret < 0 ) {
300+ LOG_ERR ("Can not get format!" );
301+ return ret ;
302+ }
303+
304+ if (fmt .width == 320 ) {
305+ highres = true;
306+ }
307+
308+
309+ if (frmival -> numerator <= 15 ) {
310+ osc_div = highres ? 0x01 : 0x00 ;
311+ } else if (frmival -> numerator <= 30 ) {
312+ osc_div = highres ? 0x02 : 0x01 ;
313+ } else if (frmival -> numerator <= 60 ) {
314+ osc_div = highres ? 0x03 : 0x02 ;
315+ } else {
316+ /* Set to the max possible FPS at this resolution. */
317+ osc_div = 3 ;
318+ }
319+
320+ osc_div |= 0x8 ;
321+
322+ ret = video_write_cci_reg (& config -> i2c , HM01B0_CCI_OSC_CLOCK_DIV , osc_div );
323+ if (ret < 0 ) {
324+ LOG_ERR ("Failed to write OSC_CLK_DIV = %x reg (%d)" , osc_div , ret );
325+ return ret ;
326+ }
327+
328+ /* GRP_PARAM_HOLD */
329+ ret = video_write_cci_reg (& config -> i2c , HM01B0_CCI_GRP_PARAM_HOLD , 0x01 );
330+ if (ret < 0 ) {
331+ LOG_ERR ("Failed to write GRP_PARAM_HOLD reg (%d)" , ret );
332+ return ret ;
333+ }
334+
335+
336+ drv_data -> cur_frmrate = frmival -> numerator ;
337+
338+ LOG_DBG ("FrameRate selected: %d" , frmival -> numerator );
339+ LOG_DBG ("HIRES Selected: %d" , highres );
340+ LOG_DBG ("OSC DIV: %d" , osc_div );
341+
342+ return 0 ;
343+ }
344+
345+ static int hm01b0_get_frmival (const struct device * dev , struct video_frmival * frmival )
346+ {
347+ struct hm01b0_data * drv_data = dev -> data ;
348+
349+ frmival -> numerator = drv_data -> cur_frmrate ;
350+ frmival -> denominator = 1 ;
351+
352+ return 0 ;
353+ }
354+
287355static int hm01b0_init_controls (const struct device * dev )
288356{
289357 int ret ;
@@ -354,6 +422,8 @@ static DEVICE_API(video, hm01b0_driver_api) = {
354422 .set_ctrl = hm01b0_set_ctrl ,
355423 .set_stream = hm01b0_set_stream ,
356424 .get_caps = hm01b0_get_caps ,
425+ .set_frmival = hm01b0_set_frmival ,
426+ .get_frmival = hm01b0_get_frmival ,
357427};
358428
359429static bool hm01b0_check_connection (const struct device * dev )
0 commit comments