📄 fpsensor.c
字号:
/*********************************************************************
*
* Copyright:
* MOTOROLA, INC. All Rights Reserved.
* You are hereby granted a copyright license to use, modify, and
* distribute the SOFTWARE so long as this entire notice is
* retained without alteration in any modified and/or redistributed
* versions, and that such modified versions are clearly identified
* as such. No licenses are granted by implication, estoppel or
* otherwise under any patents or trademarks of Motorola, Inc. This
* software is provided on an "AS IS" basis and without warranty.
*
* To the maximum extent permitted by applicable law, MOTOROLA
* DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED, INCLUDING
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
* PURPOSE AND ANY WARRANTY AGAINST INFRINGEMENT WITH REGARD TO THE
* SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF) AND ANY
* ACCOMPANYING WRITTEN MATERIALS.
*
* To the maximum extent permitted by applicable law, IN NO EVENT
* SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING
* WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS
* INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY
* LOSS) ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
*
* Motorola assumes no responsibility for the maintenance and support
* of this software
********************************************************************/
/*
* File: FPsensor.c
*
* Purpose: routines for writing to and reading from the Fujitsu MBF200
* fingerprint sensor.
*
* Notes:
*
* Modifications:
*
*/
#define _FPSENSOR
#include "mcf5249.h"
#include "FPsensor.h"
#include "init.h"
/*--- MBF200 Basic Read and Write Functions ---*/
void FPWriteReg(uint8 REG, uint8 DATA)
{
FPWriteIndexReg(REG);
FPWriteDataReg(DATA);
}
uint8 FPReadReg(uint8 REG)
{
FPWriteIndexReg(REG);
return(FPReadDataReg());
}
/*--- Sensor Basic Functions ---*/
/*--- Enable the Sensor ---*/
void FPEnable(void)
{
FPWriteReg(FP_CTRLB, (FPReadReg(FP_CTRLB) | FP_ENABLE)); //Sets the enable bit in CTRLB
}
/*--- Put the Sensor into Low Power Mode ---*/
void FPLowPower(void)
{
FPWriteReg(FP_CTRLB, (FPReadReg(FP_CTRLB) & ~FP_ENABLE)); //Clears the enable bit in CTRLB
}
/*--- Initialise Sensor Control ---*/
void FPSensorInit()
{
FPWriteReg(FP_CTRLA, 0x00);
FPWriteReg(FP_THR, FP_THV_STARTUP | FP_THC_STARTUP); //Setup threshold values
FPWriteReg(FP_CTRLB, FP_ENABLE | FP_XTALSEL | FP_AUTOINCEN | AFDEN); //Setup sensor control
FPAdjustParams(FP_DT_STARTUP, FP_DC_STARTUP, FP_GAIN_STARTUP); //Setup discharge values
FPWriteReg(FP_ISR, 0x03); //Clears any pending interrupts
FPWriteReg(FP_ICR, FP_IP_FINGER | FP_IT_FINGER | FP_IE_FINGER); //Enable finger detect interrupt
}
/*--- Adjust Parameters ---*/
void FPAdjustParams(uint8 discharge_time, uint8 discharge_current, uint8 gain)
{
FPWriteReg(FP_DTR, discharge_time);
FPWriteReg(FP_DCR, discharge_current);
FPWriteReg(FP_PGC, gain);
}
/*--- Image retrieval Functions ---*/
/*--- MCU Get Row ---*/
void FPMCUGetRow(FP_ROW data, uint8 row_MSB, uint8 row_LSB)
{
uint16 i;
FPWriteReg(FP_RAH, row_MSB); //set MSB of row address
FPWriteReg(FP_RAL, row_LSB); //set LSB of row address
FPWriteReg(FP_CTRLA, FP_GET_ROW); //start row A/D sequence
/*--- Wait Row Capture Time ---*/
delay(2); //delay for 2 * 5us = 10us
for (i=0; i<FP_MAX_COLUMN; i++) //loop for 256 pixels in row
{
data[i] = FPReadReg(FP_CTRLA);
/*--- Wait A/D Conversion Time ---*/
delay(2);
}
}
/*--- MCU Get Whole Image ---*/
void FPMCUGetWhole(FP_IMAGE data)
{
uint16 i, j;
uint32 reg1, reg2;
FPWriteReg(FP_CTRLA, FP_GET_ROW); //start image A/D sequence
for (j=0; j<FP_MAX_ROW; j++) //loop for 300 rows in whole image
{
/*--- Wait Row Capture Time ---*/
delay(2); //delay for 2 * 5us = 10us
for (i=0; i<FP_MAX_COLUMN; i++) //loop for 256 pixels in row
{
data[j] [i] = FPReadReg(FP_CTRLA);
/*--- Wait A/D Conversion Time ---*/
delay(1);
}
}
}
/*--- MCU Get Sub-Image ---*/
void FPMCUGetSub(FP_IMAGE data, uint8 row_MSB, uint8 row_LSB, uint8 column,
uint8 end_row_MSB, uint8 end_row_LSB, uint8 end_column)
{
uint16 i, j, row_end;
FPWriteReg(FP_RAH, row_MSB); //set MSB of row address
FPWriteReg(FP_RAL, row_LSB); //set LSB of row address
FPWriteReg(FP_CAL, column); //set coluimn address
FPWriteReg(FP_REH, end_row_MSB); //set MSB of end row address
FPWriteReg(FP_REL, end_row_LSB); //set LSB of end row address
FPWriteReg(FP_CEL, end_column); //set end column address
FPWriteReg(FP_CTRLA, FP_GET_ROW); //start sub-image A/D sequence
row_end = end_row_MSB;
row_end = (row_end << 8) | (end_row_LSB);
j = row_MSB;
j = (j << 8) | (row_LSB - 1);
for (j; j<row_end; j++) //loop for rows in sub-image
{
/*--- Wait Row Capture Time ---*/
delay(2); //delay for 2 * 5us = 10us
for (i=column - 1; i<end_column; i++) //loop for pixels in sub-image row
{
data[0] [i] = FPReadReg(FP_CTRLA);
/*--- Wait A/D Conversion Time ---*/
delay(1);
}
}
}
/*--- Finger Detect Routine Using Polling ---*/
void FPMCUFingerDetect(void)
{
while(1)
{
uint16 i;
uint16 count = 0;
uint32 result = 0;
FP_ROW detect_row;
FPMCUGetRow(detect_row,0,0x96); //Get 1 row of image data from sensor
for(i=0; i<FP_MAX_COLUMN; i++)
{
if(i !=0)
result = detect_row[i-1];
result = ((result + detect_row[i]) / 2);
if (result < 0xA0)
count++;
}
if(count > 100) //If number of pixels < 0xA0 is > 100 its a finger
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -