• 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 #if !defined( __AWB_FSM_H__ )
21 #define __AWB_FSM_H__
22 
23 #include "acamera_isp_core_nomem_settings.h"
24 
25 typedef struct _AWB_fsm_t AWB_fsm_t;
26 typedef struct _AWB_fsm_t *AWB_fsm_ptr_t;
27 typedef const struct _AWB_fsm_t *AWB_fsm_const_ptr_t;
28 
29 
30 #define ISP_HAS_AWB_FSM 1
31 #define MAX_AWB_ZONES ( ISP_METERING_ZONES_MAX_V * ISP_METERING_ZONES_MAX_H )
32 #define AWB_LIGHT_SOURCE_UNKNOWN 0
33 #define AWB_LIGHT_SOURCE_A 0x01
34 #define AWB_LIGHT_SOURCE_D40 0x02
35 #define AWB_LIGHT_SOURCE_D50 0x03
36 #define AWB_LIGHT_SOURCE_A_TEMPERATURE 2850
37 #define AWB_LIGHT_SOURCE_D40_TEMPERATURE 4000
38 #define AWB_LIGHT_SOURCE_D50_TEMPERATURE 5000
39 #define AWB_DLS_LIGHT_SOURCE_A_D40_BORDER ( AWB_LIGHT_SOURCE_A_TEMPERATURE + AWB_LIGHT_SOURCE_D40_TEMPERATURE ) / 2
40 #define AWB_DLS_LIGHT_SOURCE_D40_D50_BORDER ( AWB_LIGHT_SOURCE_D40_TEMPERATURE + AWB_LIGHT_SOURCE_D50_TEMPERATURE ) / 2
41 #define AWB_DLS_SWITCH_LIGHT_SOURCE_DETECT_FRAMES_QUANTITY 15
42 #define AWB_DLS_SWITCH_LIGHT_SOURCE_CHANGE_FRAMES_QUANTITY 35
43 #define D50_DEFAULT 256
44 
45 typedef struct _awb_zone_t {
46     uint16_t rg;
47     uint16_t bg;
48     uint32_t sum;
49 } awb_zone_t;
50 
51 void awb_init( AWB_fsm_ptr_t p_fsm );
52 void awb_coeffs_write( AWB_fsm_const_ptr_t p_fsm );
53 void awb_set_identity( AWB_fsm_ptr_t p_fsm );
54 void awb_read_statistics( AWB_fsm_ptr_t p_fsm );
55 void awb_update_ccm( AWB_fsm_ptr_t p_fsm );
56 void awb_normalise( AWB_fsm_ptr_t p_fsm );
57 void awb_roi_update( AWB_fsm_ptr_t p_fsm );
58 int awb_set_zone_weight(AWB_fsm_ptr_t p_fsm, void *u_wg_ptr);
59 
60 #include "acamera_metering_stats_mem_config.h"
61 
62 
63 struct _AWB_fsm_t {
64     fsm_common_t cmn;
65 
66     acamera_fsm_mgr_t *p_fsm_mgr;
67     fsm_irq_mask_t mask;
68     uint16_t curr_AWB_ZONES;
69     uint8_t awb_enabled;
70     uint32_t sum;
71     uint16_t rg_coef;
72     uint16_t bg_coef;
73     uint8_t p_high;
74     uint8_t p_low;
75     int32_t high_temp;
76     int32_t low_temp;
77     int32_t sfact;
78     int16_t g_avgShift;
79     uint32_t avg_GR;
80     uint32_t avg_GB;
81     uint32_t stable_avg_RG;
82     uint32_t stable_avg_BG;
83     uint32_t valid_threshold;
84     uint8_t gPrintCnt;
85     uint16_t color_wb_matrix[9];
86     int32_t wb_log2[4];
87     int32_t temperature_detected;
88     uint8_t light_source_detected;
89     uint8_t light_source_candidate;
90     uint8_t detect_light_source_frames_count;
91     uint32_t mode;
92     int32_t max_temp;
93     int32_t min_temp;
94     uint16_t max_temp_rg;
95     uint16_t max_temp_bg;
96     uint16_t min_temp_rg;
97     uint16_t min_temp_bg;
98     uint32_t roi;
99 
100     int32_t awb_warming[3];
101     uint32_t switch_light_source_detect_frames_quantity;
102     uint32_t switch_light_source_change_frames_quantity;
103 
104     uint32_t pre_result_gain_frame_id;
105     uint32_t cur_result_gain_frame_id;
106 	int32_t wb[4];
107 };
108 
109 
110 void AWB_fsm_clear( AWB_fsm_ptr_t p_fsm );
111 
112 void AWB_fsm_init( void *fsm, fsm_init_param_t *init_param );
113 int AWB_fsm_set_param( void *fsm, uint32_t param_id, void *input, uint32_t input_size );
114 int AWB_fsm_get_param( void *fsm, uint32_t param_id, void *input, uint32_t input_size, void *output, uint32_t output_size );
115 
116 uint8_t AWB_fsm_process_event( AWB_fsm_ptr_t p_fsm, event_id_t event_id );
117 
118 void AWB_fsm_process_interrupt( AWB_fsm_const_ptr_t p_fsm, uint8_t irq_event );
119 
120 void AWB_request_interrupt( AWB_fsm_ptr_t p_fsm, system_fw_interrupt_mask_t mask );
121 
122 #endif /* __AWB_FSM_H__ */
123