Line data Source code
1 1 : /*
2 : * Copyright (c) 2022 Linumiz
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @brief Header file for extended sensor API of Grow R502A sensor
10 : * @ingroup grow_r502a_interface
11 : */
12 :
13 : #ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_GROW_R502A_H_
14 : #define ZEPHYR_INCLUDE_DRIVERS_SENSOR_GROW_R502A_H_
15 :
16 : /**
17 : * @defgroup grow_r502a_interface Grow R502A
18 : * @ingroup sensor_interface_ext
19 : * @brief HZ-Grow GROW_R502A fingerprint sensor
20 : * @{
21 : */
22 :
23 : #ifdef __cplusplus
24 : extern "C" {
25 : #endif
26 :
27 : #include <zephyr/drivers/sensor.h>
28 :
29 : /*LED color code*/
30 0 : enum r502a_led_color_idx {
31 : R502A_LED_COLOR_RED = 0x01,
32 : R502A_LED_COLOR_BLUE,
33 : R502A_LED_COLOR_PURPLE,
34 : };
35 :
36 : /**
37 : * @name Baud rates
38 : * @{
39 : */
40 :
41 1 : #define R502A_BAUD_9600 1 /**< 9600 bps */
42 1 : #define R502A_BAUD_19200 2 /**< 19200 bps */
43 1 : #define R502A_BAUD_38400 4 /**< 38400 bps */
44 1 : #define R502A_BAUD_57600 6 /**< 57600 bps */
45 1 : #define R502A_BAUD_115200 12 /**< 115200 bps */
46 :
47 : /** @} */
48 :
49 : /**
50 : * Security level
51 : *
52 : * This enumeration lists all the supported security levels controlling the matching threshold
53 : * value for fingerprint matching.
54 : */
55 1 : enum r502a_sec_level {
56 : R502A_SEC_LEVEL_1 = 1, /**< Level 1 (lowest security) */
57 : R502A_SEC_LEVEL_2, /**< Level 2 */
58 : R502A_SEC_LEVEL_3, /**< Level 3 */
59 : R502A_SEC_LEVEL_4, /**< Level 4 */
60 : R502A_SEC_LEVEL_5 /**< Level 5 (highest security) */
61 : };
62 :
63 : /**
64 : * Data packet length
65 : *
66 : * This enumeration lists all the supported data packet lengths for when the sensor communicates
67 : * with the host.
68 : */
69 1 : enum r502a_data_len {
70 : R502A_PKG_LEN_32, /**< 32 bytes */
71 : R502A_PKG_LEN_64, /**< 64 bytes */
72 : R502A_PKG_LEN_128, /**< 128 bytes */
73 : R502A_PKG_LEN_256 /**< 256 bytes */
74 : };
75 :
76 : /**
77 : * System parameter set
78 : *
79 : * This enumeration lists all the system parameters that can be set.
80 : */
81 1 : enum r502a_sys_param_set {
82 : R502A_BAUD_RATE = 4, /**< Baud rate */
83 : R502A_SECURITY_LEVEL, /**< Security level */
84 : R502A_DATA_PKG_LEN /**< Data package length */
85 : };
86 :
87 : /**
88 : * System parameter
89 : *
90 : * This structure holds the values for the sensor's status register and system parameters.
91 : */
92 1 : struct r502a_sys_param {
93 : /** Status register */
94 1 : uint16_t status_reg;
95 : /** System identifier code */
96 1 : uint16_t system_id;
97 : /** Finger library size */
98 1 : uint16_t lib_size;
99 : /** Security level (1 to 5) */
100 1 : uint16_t sec_level;
101 : /** Device address */
102 1 : uint32_t addr;
103 : /** Data packet length */
104 1 : uint16_t data_pkt_size;
105 : /** Baud rate */
106 1 : uint32_t baud;
107 : } __packed;
108 :
109 : /**
110 : * Fingerprint template
111 : *
112 : * This structure holds the template data for fingerprint matching.
113 : */
114 1 : struct r502a_template {
115 0 : uint8_t *data;
116 0 : size_t len;
117 : };
118 :
119 : /**
120 : * Custom sensor channels for Grow R502A
121 : */
122 1 : enum sensor_channel_grow_r502a {
123 : /** Fingerprint template count, ID number for enrolling and searching*/
124 : SENSOR_CHAN_FINGERPRINT = SENSOR_CHAN_PRIV_START,
125 : };
126 :
127 : /**
128 : * Custom trigger types for Grow R502A
129 : */
130 1 : enum sensor_trigger_type_grow_r502a {
131 : /** Trigger fires when a touch is detected. */
132 : SENSOR_TRIG_TOUCH = SENSOR_TRIG_PRIV_START,
133 : };
134 :
135 : /**
136 : * Custom sensor attributes for Grow R502A
137 : */
138 1 : enum sensor_attribute_grow_r502a {
139 : /** To capture finger and store as feature file in
140 : * RAM buffers char_buf_1 and char_buf_2.
141 : */
142 : SENSOR_ATTR_R502A_CAPTURE = SENSOR_ATTR_PRIV_START,
143 : /** create template from feature files at RAM buffers
144 : * char_buf_1 & char_buf_2 and store a template data
145 : * back in both RAM buffers char_buf_1 and char_buf_2.
146 : */
147 : SENSOR_ATTR_R502A_TEMPLATE_CREATE,
148 : /** Add template to the sensor record storage
149 : *
150 : * sensor_value.val1 is the record index for template to be stored in the sensor device's
151 : * flash
152 : */
153 : SENSOR_ATTR_R502A_RECORD_ADD,
154 : /** Find requested data in record storage
155 : *
156 : * sensor_value.val1 is the matched record index.
157 : * sensor_value.val2 is the matching score.
158 : */
159 : SENSOR_ATTR_R502A_RECORD_FIND,
160 : /** Delete mentioned data from record storage
161 : *
162 : * sensor_value.val1 is the record start index to be deleted.
163 : * sensor_value.val2 is the number of records to be deleted.
164 : */
165 : SENSOR_ATTR_R502A_RECORD_DEL,
166 : /** Get available position to store data on record storage */
167 : SENSOR_ATTR_R502A_RECORD_FREE_IDX,
168 : /** Empty the storage record*/
169 : SENSOR_ATTR_R502A_RECORD_EMPTY,
170 : /** Load template from storage to RAM buffer of sensor
171 : *
172 : * sensor_value.val1 is the record start index to be loaded in
173 : * device internal RAM buffer.
174 : */
175 : SENSOR_ATTR_R502A_RECORD_LOAD,
176 : /** Template data stored in sensor's RAM buffer
177 : *
178 : * sensor_value.val1 is the match result (R502A_FINGER_MATCH_FOUND or
179 : * R502A_FINGER_MATCH_NOT_FOUND)
180 : * sensor_value.val2 is the matching score.
181 : */
182 : SENSOR_ATTR_R502A_COMPARE,
183 : /** Set device's system parameters
184 : *
185 : * sensor_value.val1 is the parameter number from enum r502a_sys_param_set.
186 : * sensor_value.val2 is the content to be written for the respective parameter.
187 : */
188 : SENSOR_ATTR_R502A_SYS_PARAM,
189 : };
190 :
191 : /**
192 : * Read system parameters
193 : *
194 : * This function reads the system parameters from the sensor.
195 : *
196 : * @param dev Pointer to the sensor device
197 : * @param val Pointer to the system parameter structure
198 : * @retval 0 success
199 : * @retval -errno negative error code on failure
200 : */
201 1 : int r502a_read_sys_param(const struct device *dev, struct r502a_sys_param *val);
202 :
203 : /**
204 : * Upload finger template
205 : *
206 : * This function uploads a finger template to the sensor.
207 : *
208 : * @param dev Pointer to the sensor device
209 : * @param temp Pointer to the template structure
210 : * @retval 0 success
211 : * @retval -errno negative error code on failure
212 : */
213 1 : int fps_upload_char_buf(const struct device *dev, struct r502a_template *temp);
214 :
215 : /**
216 : * Download finger template
217 : *
218 : * This function downloads a finger template from the sensor.
219 : *
220 : * @param dev Pointer to the sensor device
221 : * @param char_buf_id Character buffer ID (1 or 2)
222 : * @param temp Pointer to the template structure
223 : * @retval 0 success
224 : * @retval -errno negative error code on failure
225 : */
226 1 : int fps_download_char_buf(const struct device *dev, uint8_t char_buf_id,
227 : const struct r502a_template *temp);
228 :
229 : #ifdef __cplusplus
230 : }
231 : #endif
232 :
233 : /**
234 : * @}
235 : */
236 :
237 : #endif /* ZEPHYR_INCLUDE_ZEPHYR_DRIVERS_SENSOR_GROW_R502A_H_ */
|