mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add set_color_palette
This commit is contained in:
parent
2944d42bea
commit
164f2e71c1
@ -435,6 +435,22 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args)
|
|||||||
return ret_obj;
|
return ret_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static mp_obj_t py_sensor_set_color_palette(mp_obj_t palette_obj) {
|
||||||
|
int palette = mp_obj_get_int(palette_obj);
|
||||||
|
switch (palette) {
|
||||||
|
case COLOR_PALETTE_RAINBOW:
|
||||||
|
sensor_set_color_palette(rainbow_table);
|
||||||
|
break;
|
||||||
|
case COLOR_PALETTE_IRONBOW:
|
||||||
|
sensor_set_color_palette(ironbow_table);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid color palette!"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return mp_const_true;
|
||||||
|
}
|
||||||
|
|
||||||
static mp_obj_t py_sensor_write_reg(mp_obj_t addr, mp_obj_t val) {
|
static mp_obj_t py_sensor_write_reg(mp_obj_t addr, mp_obj_t val) {
|
||||||
sensor_write_reg(mp_obj_get_int(addr), mp_obj_get_int(val));
|
sensor_write_reg(mp_obj_get_int(addr), mp_obj_get_int(val));
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
@ -482,9 +498,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_vflip_obj, py_sensor_se
|
|||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_special_effect_obj, py_sensor_set_special_effect);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_special_effect_obj, py_sensor_set_special_effect);
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(py_sensor_set_lens_correction_obj, py_sensor_set_lens_correction);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_3(py_sensor_set_lens_correction_obj, py_sensor_set_lens_correction);
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_vsync_output_obj, py_sensor_set_vsync_output);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_vsync_output_obj, py_sensor_set_vsync_output);
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(py_sensor_ioctl_obj, 1, 5, py_sensor_ioctl);
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_color_palette_obj, py_sensor_set_color_palette);
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_sensor_write_reg_obj, py_sensor_write_reg);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_sensor_write_reg_obj, py_sensor_write_reg);
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_read_reg_obj, py_sensor_read_reg);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_read_reg_obj, py_sensor_read_reg);
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(py_sensor_ioctl_obj, 1, 5, py_sensor_ioctl);
|
|
||||||
|
|
||||||
STATIC const mp_map_elem_t globals_dict_table[] = {
|
STATIC const mp_map_elem_t globals_dict_table[] = {
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_sensor) },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_sensor) },
|
||||||
@ -534,6 +551,10 @@ STATIC const mp_map_elem_t globals_dict_table[] = {
|
|||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SXGA), MP_OBJ_NEW_SMALL_INT(FRAMESIZE_SXGA)}, /* 1280x1024 */
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_SXGA), MP_OBJ_NEW_SMALL_INT(FRAMESIZE_SXGA)}, /* 1280x1024 */
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_UXGA), MP_OBJ_NEW_SMALL_INT(FRAMESIZE_UXGA)}, /* 1600x1200 */
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_UXGA), MP_OBJ_NEW_SMALL_INT(FRAMESIZE_UXGA)}, /* 1600x1200 */
|
||||||
|
|
||||||
|
// Color Palettes
|
||||||
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_PALETTE_RAINBOW), MP_OBJ_NEW_SMALL_INT(COLOR_PALETTE_RAINBOW)},
|
||||||
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_PALETTE_IRONBOW), MP_OBJ_NEW_SMALL_INT(COLOR_PALETTE_IRONBOW)},
|
||||||
|
|
||||||
// IOCTLs
|
// IOCTLs
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_SET_TRIGGERED_MODE), MP_OBJ_NEW_SMALL_INT(IOCTL_SET_TRIGGERED_MODE)},
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_SET_TRIGGERED_MODE), MP_OBJ_NEW_SMALL_INT(IOCTL_SET_TRIGGERED_MODE)},
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_GET_TRIGGERED_MODE), MP_OBJ_NEW_SMALL_INT(IOCTL_GET_TRIGGERED_MODE)},
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_GET_TRIGGERED_MODE), MP_OBJ_NEW_SMALL_INT(IOCTL_GET_TRIGGERED_MODE)},
|
||||||
@ -573,6 +594,7 @@ STATIC const mp_map_elem_t globals_dict_table[] = {
|
|||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_lens_correction), (mp_obj_t)&py_sensor_set_lens_correction_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_lens_correction), (mp_obj_t)&py_sensor_set_lens_correction_obj },
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_vsync_output), (mp_obj_t)&py_sensor_set_vsync_output_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_vsync_output), (mp_obj_t)&py_sensor_set_vsync_output_obj },
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&py_sensor_ioctl_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_ioctl), (mp_obj_t)&py_sensor_ioctl_obj },
|
||||||
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_color_palette), (mp_obj_t)&py_sensor_set_color_palette_obj },
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___write_reg), (mp_obj_t)&py_sensor_write_reg_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR___write_reg), (mp_obj_t)&py_sensor_write_reg_obj },
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___read_reg), (mp_obj_t)&py_sensor_read_reg_obj },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR___read_reg), (mp_obj_t)&py_sensor_read_reg_obj },
|
||||||
};
|
};
|
||||||
|
|||||||
@ -50,6 +50,7 @@ Q(CORNER_AGAST)
|
|||||||
Q(load_descriptor)
|
Q(load_descriptor)
|
||||||
Q(save_descriptor)
|
Q(save_descriptor)
|
||||||
Q(match_descriptor)
|
Q(match_descriptor)
|
||||||
|
|
||||||
// Image class
|
// Image class
|
||||||
Q(find_template)
|
Q(find_template)
|
||||||
Q(kp_desc)
|
Q(kp_desc)
|
||||||
@ -205,6 +206,10 @@ Q(NEGATIVE)
|
|||||||
Q(IOCTL_SET_TRIGGERED_MODE)
|
Q(IOCTL_SET_TRIGGERED_MODE)
|
||||||
Q(IOCTL_GET_TRIGGERED_MODE)
|
Q(IOCTL_GET_TRIGGERED_MODE)
|
||||||
|
|
||||||
|
// Color Palettes
|
||||||
|
Q(PALETTE_RAINBOW)
|
||||||
|
Q(PALETTE_IRONBOW)
|
||||||
|
|
||||||
Q(reset)
|
Q(reset)
|
||||||
Q(flush)
|
Q(flush)
|
||||||
Q(snapshot)
|
Q(snapshot)
|
||||||
@ -240,6 +245,7 @@ Q(set_vflip)
|
|||||||
Q(set_special_effect)
|
Q(set_special_effect)
|
||||||
Q(set_lens_correction)
|
Q(set_lens_correction)
|
||||||
Q(ioctl)
|
Q(ioctl)
|
||||||
|
Q(set_color_palette)
|
||||||
Q(__write_reg)
|
Q(__write_reg)
|
||||||
Q(__read_reg)
|
Q(__read_reg)
|
||||||
|
|
||||||
|
|||||||
@ -364,6 +364,9 @@ int sensor_init()
|
|||||||
// This is executed only once to initialize the FB enabled flag.
|
// This is executed only once to initialize the FB enabled flag.
|
||||||
JPEG_FB()->enabled = 0;
|
JPEG_FB()->enabled = 0;
|
||||||
|
|
||||||
|
// Set default color palette.
|
||||||
|
sensor.color_palette = rainbow_table;
|
||||||
|
|
||||||
/* All good! */
|
/* All good! */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -377,6 +380,8 @@ int sensor_reset()
|
|||||||
sensor.framerate = 0;
|
sensor.framerate = 0;
|
||||||
sensor.gainceiling = 0;
|
sensor.gainceiling = 0;
|
||||||
sensor.vsync_gpio = NULL;
|
sensor.vsync_gpio = NULL;
|
||||||
|
// Reset default color palette.
|
||||||
|
sensor.color_palette = rainbow_table;
|
||||||
|
|
||||||
// Call sensor-specific reset function
|
// Call sensor-specific reset function
|
||||||
if (sensor.reset(&sensor) != 0) {
|
if (sensor.reset(&sensor) != 0) {
|
||||||
@ -733,6 +738,12 @@ int sensor_set_vsync_output(GPIO_TypeDef *gpio, uint32_t pin)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sensor_set_color_palette(const uint16_t *color_palette)
|
||||||
|
{
|
||||||
|
sensor.color_palette = color_palette;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void DCMI_VsyncExtiCallback()
|
void DCMI_VsyncExtiCallback()
|
||||||
{
|
{
|
||||||
__HAL_GPIO_EXTI_CLEAR_FLAG(1 << DCMI_VSYNC_IRQ_LINE);
|
__HAL_GPIO_EXTI_CLEAR_FLAG(1 << DCMI_VSYNC_IRQ_LINE);
|
||||||
|
|||||||
@ -118,12 +118,13 @@ typedef struct _sensor {
|
|||||||
uint8_t slv_addr; // Sensor I2C slave address.
|
uint8_t slv_addr; // Sensor I2C slave address.
|
||||||
uint16_t gs_bpp; // Grayscale bytes per pixel.
|
uint16_t gs_bpp; // Grayscale bytes per pixel.
|
||||||
uint32_t hw_flags; // Hardware flags (clock polarities/hw capabilities)
|
uint32_t hw_flags; // Hardware flags (clock polarities/hw capabilities)
|
||||||
|
const uint16_t *color_palette; // Color palette used for color lookup.
|
||||||
|
|
||||||
uint32_t vsync_pin; // VSYNC GPIO output pin.
|
uint32_t vsync_pin; // VSYNC GPIO output pin.
|
||||||
GPIO_TypeDef *vsync_gpio; // VSYNC GPIO output port.
|
GPIO_TypeDef *vsync_gpio; // VSYNC GPIO output port.
|
||||||
|
|
||||||
polarity_t pwdn_pol; // PWDN polarity (TODO move to hw_flags)
|
polarity_t pwdn_pol; // PWDN polarity (TODO move to hw_flags)
|
||||||
polarity_t reset_pol; // Reset polarity (TODO move to hw_flags)
|
polarity_t reset_pol; // Reset polarity (TODO move to hw_flags)
|
||||||
|
|
||||||
// Sensor state
|
// Sensor state
|
||||||
sde_t sde; // Special digital effects
|
sde_t sde; // Special digital effects
|
||||||
@ -254,6 +255,9 @@ int sensor_ioctl(int request, ...);
|
|||||||
// Set vsync output pin
|
// Set vsync output pin
|
||||||
int sensor_set_vsync_output(GPIO_TypeDef *gpio, uint32_t pin);
|
int sensor_set_vsync_output(GPIO_TypeDef *gpio, uint32_t pin);
|
||||||
|
|
||||||
|
// Set color palette
|
||||||
|
int sensor_set_color_palette(const uint16_t *color_palette);
|
||||||
|
|
||||||
// Default snapshot function.
|
// Default snapshot function.
|
||||||
int sensor_snapshot(sensor_t *sensor, image_t *image, streaming_cb_t streaming_cb);
|
int sensor_snapshot(sensor_t *sensor, image_t *image, streaming_cb_t streaming_cb);
|
||||||
#endif /* __SENSOR_H__ */
|
#endif /* __SENSOR_H__ */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user