2121// ----------------------------------------------------------------------------------
2222// Define the pins being used for operation
2323//
24- // The FPC2534 uses one pin for reset, and for I2C requires an interrupt pin to signal
25- // when data is available to read.
24+ // The FPC2534 uses one pin for reset, No interrupt pin is needed for UART operation
2625//
2726// The following pin definitions were used for testing - but can be modified as needed.
2827//
2928// ESP32 thing plus
30- // #define IRQ_PIN 16
3129// #define RST_PIN 21
3230
3331// ESP32 thing plus C
34- // #define IRQ_PIN 32
3532// #define RST_PIN 14
3633
3734// RP2350 thing plus
38- // #define IRQ_PIN 11
3935#define RST_PIN 12
4036
4137// IoT RedBoard - RP2350
42- // #define IRQ_PIN 28
4338// #define RST_PIN 29
4439
45- // TODO: WTF on the uart / serial layer
46- // #define UART_RX 32
47- // #define UART_TX 14
40+ // ----------------------------------------------------------------------------------
41+ // NOTE:
42+ // This example makes use of the Serial1 hardware serial port for communication with the FPC2534. If the board
43+ // being used does not have a Serial1 port, you will need to modify the code to use SoftwareSerial or another
44+ // serial port available on your board.
45+ //
4846
47+ // variable used to keep track of the number of enrolled templates on the sensor
4948uint16_t numberOfTemplates = 0 ;
5049
5150// Declare our sensor object
@@ -111,11 +110,17 @@ static void drawMenu()
111110 Serial.println (" Starting finger enrollment - place finger and remove a finger on the sensor to enroll "
112111 " a fingerprint" );
113112 mySensor.setLED (true );
114- fpc_id_type_t id = {.type = ID_TYPE_GENERATE_NEW, .id = 0 };
113+ fpc_id_type_t id;
114+ id.type = ID_TYPE_GENERATE_NEW;
115+ id.id = 0 ;
115116 fpc_result_t rc = mySensor.requestEnroll (id);
116117 if (rc != FPC_RESULT_OK)
117- Serial.printf (" [ERROR]\t Failed to start enroll - error: %d\n\r " , rc);
118- Serial.print (" \t samples remaining 12.." );
118+ {
119+ Serial.print (" [ERROR]\t Failed to start enroll - error: " );
120+ Serial.println (rc);
121+ }
122+ else
123+ Serial.print (" \t samples remaining 12.." );
119124 }
120125 else if (chIn == ' 2' )
121126 {
@@ -128,10 +133,15 @@ static void drawMenu()
128133 else
129134 {
130135 Serial.println (" Deleting all templates on the fingerprint sensor" );
131- fpc_id_type_t id = {.type = ID_TYPE_ALL, .id = 0 };
136+ fpc_id_type_t id = {0 };
137+ id.type = ID_TYPE_ALL;
138+ id.id = 0 ;
132139 fpc_result_t rc = mySensor.requestDeleteTemplate (id);
133140 if (rc != FPC_RESULT_OK)
134- Serial.printf (" [ERROR]\t Failed to delete templates - error: %d\n\r " , rc);
141+ {
142+ Serial.print (" [ERROR]\t Failed to delete templates - error: " );
143+ Serial.println (rc);
144+ }
135145 else
136146 numberOfTemplates = 0 ;
137147 }
@@ -147,10 +157,15 @@ static void drawMenu()
147157 else
148158 {
149159 Serial.print (" Place a finger on the sensor for validation..." );
150- fpc_id_type_t id = {.type = ID_TYPE_ALL, .id = 0 };
160+ fpc_id_type_t id = {0 };
161+ id.type = ID_TYPE_ALL;
162+ id.id = 0 ;
151163 fpc_result_t rc = mySensor.requestIdentify (id, 1 );
152164 if (rc != FPC_RESULT_OK)
153- Serial.printf (" [ERROR]\t Failed to start identity - error: %d\n\r " , rc);
165+ {
166+ Serial.print (" [ERROR]\t Failed to start identity - error: " );
167+ Serial.println (rc);
168+ }
154169 }
155170 }
156171 else
@@ -169,7 +184,8 @@ static void drawMenu()
169184static void on_error (uint16_t error)
170185{
171186 // hal_set_led_status(HAL_LED_STATUS_ERROR);
172- Serial.printf (" [ERROR]\t Sensor Error Code: %d\n\r " , error);
187+ Serial.print (" [ERROR]\t Sensor Error Code: " );
188+ Serial.println (error);
173189 // this could indicated the sensor communications is out of synch - a reset might be needed
174190 reset_sensor ();
175191}
@@ -191,25 +207,31 @@ static void on_is_ready_change(bool isReady)
191207 // Request the templates on the device ...
192208 fpc_result_t rc = mySensor.requestListTemplates ();
193209 if (rc != FPC_RESULT_OK)
194- Serial.printf (" [ERROR]\t Failed to get template list - error: %d\n\r " , rc);
210+ {
211+ Serial.println (" [ERROR]\t Failed to get template list - error: " );
212+ Serial.println (rc);
213+ }
195214 }
196215}
197216
198217// ----------------------------------------------------------------------------
199218static void on_identify (bool is_match, uint16_t id)
200219{
201- Serial.printf (" %sMATCH %s" , is_match ? " " : " NO " );
220+
221+ Serial.print (is_match ? " NO " : " " );
222+ Serial.print (" MATCH" );
202223 if (is_match)
203- Serial.printf (" {Template ID: %d}" , id);
224+ {
225+ Serial.print (" {Template ID: " );
226+ Serial.print (id);
227+ Serial.print (" }" );
228+ }
204229 Serial.println ();
205230}
206231// ----------------------------------------------------------------------------
207232static void on_enroll (uint8_t feedback, uint8_t samples_remaining)
208233{
209234
210- // Serial.printf("[INFO]\t\tEnroll samples remaining: %d, feedback: %s (%d)\n\r", samples_remaining,
211- // mySensor.getEnrollFeedBackString(feedback), feedback);
212-
213235 if (samples_remaining == 0 )
214236 {
215237 Serial.println (" ..done!" );
@@ -229,7 +251,6 @@ static void on_enroll(uint8_t feedback, uint8_t samples_remaining)
229251static void on_list_templates (uint16_t num_templates, uint16_t *template_ids)
230252{
231253 numberOfTemplates = num_templates;
232- // Serial.printf("[INFO]\t\tNumber of templates on the sensor: %d\n\r", num_templates);
233254
234255 isInitialized = true ;
235256 // lets draw the menu!
@@ -240,7 +261,6 @@ static void on_list_templates(uint16_t num_templates, uint16_t *template_ids)
240261// on_status()
241262static void on_status (uint16_t event, uint16_t state)
242263{
243- // Serial.printf("[STATUS]\tEvent: 0x%04X, State: 0x%04X\n\r", event, state);
244264
245265 // Check the system state, to determine when to draw the menu.
246266 //
@@ -275,28 +295,14 @@ static void on_status(uint16_t event, uint16_t state)
275295 drawTheMenu = true ; // just in
276296 }
277297 }
278-
279- // if checking identity and we get an image ready event - the device hangs until finger up
280- // Let's prompt the user to remove the finger
281- // NOTE on UART this is okay - just part of ID sequence - using I2C this seems to hang the process
282- //
283- // else if (mySensor.currentMode() == STATE_IDENTIFY && event == EVENT_IMAGE_READY)
284- // {
285- // Serial.println("[INFO]\t\tUnable to perform ID check - remove finger and try again");
286- // }
287298 else if (mySensor.currentMode () == STATE_ENROLL && event == EVENT_FINGER_LOST)
288299 {
289300 Serial.print (" ." );
290301 }
291302}
292303
293- // Define our command callbacks the library will call on events from the sensor
294- static const sfDevFPC2534Callbacks_t cmd_cb = {.on_error = on_error,
295- .on_status = on_status,
296- .on_enroll = on_enroll,
297- .on_identify = on_identify,
298- .on_list_templates = on_list_templates,
299- .on_is_ready_change = on_is_ready_change};
304+ // Define our command callback struct - functions are set in the setup function
305+ static sfDevFPC2534Callbacks_t cmd_cb = {0 };
300306
301307// ------------------------------------------------------------------------------------
302308// reset_sensor()
@@ -332,8 +338,14 @@ void setup()
332338 Serial.println (" ----------------------------------------------------------------" );
333339 Serial.println ();
334340
335- // RP2350 call.
341+ // The internal UART buffer can fill up quickly and overflow. As such, increase its size.
342+ // This example is supporting ESP32 and RP2040 based boards - adjust as needed for other platforms.
343+ #if defined(ARDUINO_ARCH_RP2040)
336344 Serial1.setFIFOSize (512 );
345+ #elif defined(ESP32)
346+ Serial1.setRxBufferSize (512 );
347+ #endif
348+
337349 Serial1.begin (921600 , SERIAL_8N1);
338350 delay (100 );
339351 for (uint32_t startMS = millis (); !Serial1 && (millis () - startMS < 5000 );) // Wait for the serial port to be ready
@@ -353,6 +365,14 @@ void setup()
353365 }
354366 Serial.println (" [STARTUP]\t FPC2534 initialized." );
355367
368+ // setup our callback functions structure
369+ cmd_cb.on_error = on_error;
370+ cmd_cb.on_status = on_status;
371+ cmd_cb.on_enroll = on_enroll;
372+ cmd_cb.on_identify = on_identify;
373+ cmd_cb.on_list_templates = on_list_templates;
374+ cmd_cb.on_is_ready_change = on_is_ready_change;
375+
356376 // set the callbacks for the sensor library to call
357377 mySensor.setCallbacks (cmd_cb);
358378
@@ -372,7 +392,8 @@ void loop()
372392 fpc_result_t rc = mySensor.processNextResponse ();
373393 if (rc != FPC_RESULT_OK && rc != FPC_PENDING_OPERATION)
374394 {
375- Serial.printf (" [ERROR] Processing Error: %d\n\r " , rc);
395+ Serial.print (" [ERROR] Processing Error: " );
396+ Serial.println (rc);
376397 // Hmm - reset the sensor and start again?
377398 reset_sensor ();
378399 }
0 commit comments