• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 *
3 * SPDX-License-Identifier: GPL-2.0
4 *
5 * Copyright (C) 2011-2018 ARM or its affiliates
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19 
20 #include "acamera_fw.h"
21 #include "color_matrix_fsm.h"
22 
23 #ifdef LOG_MODULE
24 #undef LOG_MODULE
25 #define LOG_MODULE LOG_MODULE_COLOR_MATRIX
26 #endif
27 
color_matrix_fsm_clear(color_matrix_fsm_t * p_fsm)28 void color_matrix_fsm_clear( color_matrix_fsm_t *p_fsm )
29 {
30     p_fsm->light_source = AWB_LIGHT_SOURCE_D50;
31     p_fsm->light_source_previous = AWB_LIGHT_SOURCE_D50;
32     p_fsm->light_source_ccm = AWB_LIGHT_SOURCE_D50;
33     p_fsm->light_source_ccm_previous = AWB_LIGHT_SOURCE_D50;
34     p_fsm->light_source_change_frames = 20;
35     p_fsm->light_source_change_frames_left = 0;
36     p_fsm->manual_CCM = 0;
37 }
38 
color_matrix_request_interrupt(color_matrix_fsm_ptr_t p_fsm,system_fw_interrupt_mask_t mask)39 void color_matrix_request_interrupt( color_matrix_fsm_ptr_t p_fsm, system_fw_interrupt_mask_t mask )
40 {
41     acamera_isp_interrupts_disable( ACAMERA_FSM2MGR_PTR( p_fsm ) );
42     p_fsm->mask.irq_mask |= mask;
43     acamera_isp_interrupts_enable( ACAMERA_FSM2MGR_PTR( p_fsm ) );
44 }
45 
color_matrix_fsm_init(void * fsm,fsm_init_param_t * init_param)46 void color_matrix_fsm_init( void *fsm, fsm_init_param_t *init_param )
47 {
48     color_matrix_fsm_t *p_fsm = (color_matrix_fsm_t *)fsm;
49     p_fsm->cmn.p_fsm_mgr = init_param->p_fsm_mgr;
50     p_fsm->cmn.isp_base = init_param->isp_base;
51     p_fsm->p_fsm_mgr = init_param->p_fsm_mgr;
52 
53     color_matrix_fsm_clear( p_fsm );
54 
55     color_matrix_initialize( p_fsm );
56     color_matrix_request_interrupt( p_fsm, ACAMERA_IRQ_MASK( ACAMERA_IRQ_FRAME_END ) );
57 }
58 
59 
color_matrix_fsm_set_param(void * fsm,uint32_t param_id,void * input,uint32_t input_size)60 int color_matrix_fsm_set_param( void *fsm, uint32_t param_id, void *input, uint32_t input_size )
61 {
62     int rc = 0;
63     color_matrix_fsm_t *p_fsm = (color_matrix_fsm_t *)fsm;
64 
65     switch ( param_id ) {
66     case FSM_PARAM_SET_CCM_INFO: {
67         if ( !input || input_size != sizeof( fsm_param_ccm_info_t ) ) {
68             LOG( LOG_ERR, "Invalid param, param_id: %d.", param_id );
69             rc = -1;
70             break;
71         }
72 
73         fsm_param_ccm_info_t *p_info = (fsm_param_ccm_info_t *)input;
74 
75         p_fsm->light_source = p_info->light_source;
76         p_fsm->light_source_previous = p_info->light_source_previous;
77         p_fsm->light_source_ccm = p_info->light_source_ccm;
78         p_fsm->light_source_ccm_previous = p_info->light_source_ccm_previous;
79         p_fsm->light_source_change_frames = p_info->light_source_change_frames;
80         p_fsm->light_source_change_frames_left = p_info->light_source_change_frames_left;
81 
82         break;
83     }
84 
85     case FSM_PARAM_SET_CCM_CHANGE:
86         color_matrix_change_CCMs( p_fsm );
87         break;
88 
89     case FSM_PARAM_SET_SHADING_MESH_RELOAD:
90         color_matrix_shading_mesh_reload( p_fsm );
91         break;
92 
93     case FSM_PARAM_SET_MANUAL_CCM: {
94         if ( !input || input_size != sizeof( fsm_param_ccm_manual_t ) ) {
95             LOG( LOG_ERR, "Invalid param, param_id: %d.", param_id );
96             rc = -1;
97             break;
98         }
99 
100         fsm_param_ccm_manual_t *p_manual = (fsm_param_ccm_manual_t *)input;
101 
102         p_fsm->manual_CCM = p_manual->manual_CCM;
103         if ( p_fsm->manual_CCM ) {
104             system_memcpy( p_fsm->manual_color_matrix, p_manual->manual_color_matrix, sizeof( p_manual->manual_color_matrix ) );
105         }
106     }
107 
108     default:
109         rc = -1;
110         break;
111     }
112 
113     return rc;
114 }
115 
116 
color_matrix_fsm_get_param(void * fsm,uint32_t param_id,void * input,uint32_t input_size,void * output,uint32_t output_size)117 int color_matrix_fsm_get_param( void *fsm, uint32_t param_id, void *input, uint32_t input_size, void *output, uint32_t output_size )
118 {
119     int rc = 0;
120     color_matrix_fsm_t *p_fsm = (color_matrix_fsm_t *)fsm;
121 
122     switch ( param_id ) {
123     case FSM_PARAM_GET_CCM_INFO: {
124         if ( !output || output_size != sizeof( fsm_param_ccm_info_t ) ) {
125             LOG( LOG_ERR, "Invalid param, param_id: %d.", param_id );
126             rc = -1;
127             break;
128         }
129 
130         fsm_param_ccm_info_t *p_info = (fsm_param_ccm_info_t *)output;
131 
132         p_info->light_source = p_fsm->light_source;
133         p_info->light_source_previous = p_fsm->light_source_previous;
134         p_info->light_source_ccm = p_fsm->light_source_ccm;
135         p_info->light_source_ccm_previous = p_fsm->light_source_ccm_previous;
136         p_info->light_source_change_frames = p_fsm->light_source_change_frames;
137         p_info->light_source_change_frames_left = p_fsm->light_source_change_frames_left;
138 
139         break;
140     }
141 
142     case FSM_PARAM_GET_SHADING_ALPHA:
143         if ( !output || output_size != sizeof( int32_t ) ) {
144             LOG( LOG_ERR, "Invalid param, param_id: %d.", param_id );
145             rc = -1;
146             break;
147         }
148 
149         *(int32_t *)output = p_fsm->shading_alpha;
150 
151         break;
152 
153     default:
154         rc = -1;
155         break;
156     }
157 
158 
159     return rc;
160 }
161 
162 
color_matrix_fsm_process_event(color_matrix_fsm_t * p_fsm,event_id_t event_id)163 uint8_t color_matrix_fsm_process_event( color_matrix_fsm_t *p_fsm, event_id_t event_id )
164 {
165     uint8_t b_event_processed = 0;
166     switch ( event_id ) {
167     default:
168         break;
169     case event_id_frame_end:
170         color_matrix_update( p_fsm );
171         color_matrix_request_interrupt( p_fsm, ACAMERA_IRQ_MASK( ACAMERA_IRQ_FRAME_END ) );
172         b_event_processed = 1;
173         break;
174     }
175 
176     return b_event_processed;
177 }
178