Implement binning.

This commit is contained in:
iabdalkader 2016-06-03 23:01:28 +02:00
parent 48a973a586
commit 440c9dc8bc
4 changed files with 31 additions and 6 deletions

View File

@ -139,6 +139,22 @@ static mp_obj_t py_sensor_set_framesize(mp_obj_t framesize) {
return mp_const_true;
}
static mp_obj_t py_sensor_set_binning(mp_obj_t roi_obj) {
mp_obj_t *array;
mp_obj_get_array_fixed_n(roi_obj, 4, &array);
int x = mp_obj_get_int(array[0]);
int y = mp_obj_get_int(array[1]);
int w = mp_obj_get_int(array[2]);
int h = mp_obj_get_int(array[3]);
if (sensor_set_binning(x, y, w, h) != 0) {
return mp_const_false;
}
return mp_const_true;
}
static mp_obj_t py_sensor_set_gainceiling(mp_obj_t gainceiling) {
gainceiling_t gain;
switch (mp_obj_get_int(gainceiling)) {
@ -278,6 +294,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(py_sensor_get_id_obj, py_sensor_ge
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_pixformat_obj, py_sensor_set_pixformat);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_framerate_obj, py_sensor_set_framerate);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_framesize_obj, py_sensor_set_framesize);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_binning_obj, py_sensor_set_binning);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_gainceiling_obj, py_sensor_set_gainceiling);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_contrast_obj, py_sensor_set_contrast);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_brightness_obj, py_sensor_set_brightness);
@ -330,6 +347,7 @@ STATIC const mp_map_elem_t globals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_pixformat), (mp_obj_t)&py_sensor_set_pixformat_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_framerate), (mp_obj_t)&py_sensor_set_framerate_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_framesize), (mp_obj_t)&py_sensor_set_framesize_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_binning), (mp_obj_t)&py_sensor_set_binning_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_gainceiling), (mp_obj_t)&py_sensor_set_gainceiling_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_contrast), (mp_obj_t)&py_sensor_set_contrast_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_brightness), (mp_obj_t)&py_sensor_set_brightness_obj },

View File

@ -166,6 +166,7 @@ Q(get_id)
Q(set_pixformat)
Q(set_framerate)
Q(set_framesize)
Q(set_binning)
Q(set_gainceiling)
Q(set_contrast)
Q(set_brightness)

View File

@ -119,10 +119,6 @@ static int dcmi_config(uint32_t jpeg_mode)
// Configure and enable DCMI IRQ Channel
HAL_NVIC_SetPriority(DCMI_IRQn, IRQ_PRI_DCMI, IRQ_SUBPRI_DCMI);
HAL_NVIC_EnableIRQ(DCMI_IRQn);
// Uncomment the following to configure DCMI crop for testing (use width*2-1 and height-1).
//HAL_DCMI_ConfigCROP(&DCMIHandle, 0, 0, 320*2-1, 240-1);
//HAL_DCMI_EnableCROP(&DCMIHandle);
return 0;
}
@ -361,10 +357,8 @@ int sensor_set_framesize(framesize_t framesize)
// Skip the first frame.
fb->bpp = 0;
// Set framebuffer dimensions
fb->w = resolution[framesize][0];
fb->h = resolution[framesize][1];
return 0;
}
@ -388,6 +382,15 @@ int sensor_set_framerate(framerate_t framerate)
return 0;
}
int sensor_set_binning(int x, int y, int w, int h)
{
fb->w = w;
fb->h = h;
HAL_DCMI_ConfigCROP(&DCMIHandle, x*2, y, w*2-1, h-1);
HAL_DCMI_EnableCROP(&DCMIHandle);
return 0;
}
int sensor_set_contrast(int level)
{
if (sensor.set_contrast != NULL) {

View File

@ -168,6 +168,9 @@ int sensor_set_framesize(framesize_t framesize);
// Set the sensor frame rate.
int sensor_set_framerate(framerate_t framerate);
// Set window size.
int sensor_set_binning(int x, int y, int w, int h);
// Set the sensor contrast level (from -3 to +3).
int sensor_set_contrast(int level);