aes2501: Port aes2501 to new API

This commit is contained in:
Benjamin Berg 2019-07-08 18:30:42 +02:00
parent 0a47df7bb7
commit 441b1238a5
2 changed files with 210 additions and 264 deletions

View file

@ -27,12 +27,12 @@
#include "aeslib.h" #include "aeslib.h"
#include "aes2501.h" #include "aes2501.h"
static void start_capture(struct fp_img_dev *dev); static void start_capture(FpImageDevice *dev);
static void complete_deactivation(struct fp_img_dev *dev); static void complete_deactivation(FpImageDevice *dev);
/* FIXME these need checking */ /* FIXME these need checking */
#define EP_IN (1 | LIBUSB_ENDPOINT_IN) #define EP_IN (1 | FPI_USB_ENDPOINT_IN)
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT) #define EP_OUT (2 | FPI_USB_ENDPOINT_OUT)
#define BULK_TIMEOUT 4000 #define BULK_TIMEOUT 4000
@ -63,13 +63,18 @@ static void complete_deactivation(struct fp_img_dev *dev);
/****** GENERAL FUNCTIONS ******/ /****** GENERAL FUNCTIONS ******/
struct aes2501_dev { struct _FpiDeviceAes2501 {
uint8_t read_regs_retry_count; FpImageDevice parent;
guint8 read_regs_retry_count;
GSList *strips; GSList *strips;
size_t strips_len; size_t strips_len;
gboolean deactivating; gboolean deactivating;
int no_finger_cnt; int no_finger_cnt;
}; };
G_DECLARE_FINAL_TYPE(FpiDeviceAes2501, fpi_device_aes2501, FPI, DEVICE_AES2501,
FpImageDevice);
G_DEFINE_TYPE(FpiDeviceAes2501, fpi_device_aes2501, FP_TYPE_IMAGE_DEVICE);
static struct fpi_frame_asmbl_ctx assembling_ctx = { static struct fpi_frame_asmbl_ctx assembling_ctx = {
.frame_width = FRAME_WIDTH, .frame_width = FRAME_WIDTH,
@ -78,73 +83,47 @@ static struct fpi_frame_asmbl_ctx assembling_ctx = {
.get_pixel = aes_get_pixel, .get_pixel = aes_get_pixel,
}; };
typedef void (*aes2501_read_regs_cb)(struct fp_img_dev *dev, int status, typedef void (*aes2501_read_regs_cb)(FpImageDevice *dev, GError *error,
unsigned char *regs, void *user_data); unsigned char *regs, void *user_data);
struct aes2501_read_regs { struct aes2501_read_regs {
struct fp_img_dev *dev; FpImageDevice *dev;
aes2501_read_regs_cb callback; aes2501_read_regs_cb callback;
struct aes_regwrite *regwrite; struct aes_regwrite *regwrite;
void *user_data; void *user_data;
}; };
static void read_regs_data_cb(struct libusb_transfer *transfer, static void read_regs_data_cb(FpiUsbTransfer *transfer, FpDevice *dev,
struct fp_dev *dev, gpointer user_data, GError *error)
fpi_ssm *ssm,
void *user_data)
{ {
struct aes2501_read_regs *rdata = user_data; struct aes2501_read_regs *rdata = user_data;
unsigned char *retdata = NULL;
int r;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { rdata->callback(rdata->dev, error, transfer->buffer, rdata->user_data);
r = -EIO;
} else if (transfer->length != transfer->actual_length) {
r = -EPROTO;
} else {
r = 0;
retdata = transfer->buffer;
}
rdata->callback(rdata->dev, r, retdata, rdata->user_data);
g_free(rdata); g_free(rdata);
} }
static void read_regs_rq_cb(struct fp_img_dev *dev, int result, void *user_data) static void read_regs_rq_cb(FpImageDevice *dev, GError *error, void *user_data)
{ {
struct aes2501_read_regs *rdata = user_data; struct aes2501_read_regs *rdata = user_data;
fpi_usb_transfer *transfer; FpiUsbTransfer *transfer;
unsigned char *data;
int r;
g_free(rdata->regwrite); g_free(rdata->regwrite);
if (result != 0) if (error) {
goto err; rdata->callback(dev, error, NULL, rdata->user_data);
g_free (rdata);
data = g_malloc(READ_REGS_LEN); return;
transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev),
NULL,
EP_IN,
data,
READ_REGS_LEN,
read_regs_data_cb,
rdata,
BULK_TIMEOUT);
r = fpi_usb_submit_transfer(transfer);
if (r < 0) {
result = -EIO;
goto err;
} }
return; transfer = fpi_usb_transfer_new(FP_DEVICE(dev));
err: transfer->short_is_error = TRUE;
rdata->callback(dev, result, NULL, rdata->user_data); fpi_usb_transfer_fill_bulk(transfer, EP_IN, READ_REGS_LEN);
g_free(rdata); fpi_usb_transfer_submit(transfer, BULK_TIMEOUT, NULL,
read_regs_data_cb, rdata);
fpi_usb_transfer_unref(transfer);
} }
static void read_regs(struct fp_img_dev *dev, aes2501_read_regs_cb callback, static void read_regs(FpImageDevice *dev, aes2501_read_regs_cb callback,
void *user_data) void *user_data)
{ {
/* FIXME: regwrite is dynamic because of asynchronity. is this really /* FIXME: regwrite is dynamic because of asynchronity. is this really
* required? */ * required? */
@ -164,16 +143,16 @@ static void read_regs(struct fp_img_dev *dev, aes2501_read_regs_cb callback,
} }
/* Read the value of a specific register from a register dump */ /* Read the value of a specific register from a register dump */
static int regval_from_dump(unsigned char *data, uint8_t target) static int regval_from_dump(unsigned char *data, guint8 target)
{ {
if (*data != FIRST_AES2501_REG) { if (*data != FIRST_AES2501_REG) {
fp_err("not a register dump"); fp_err("not a register dump");
return -EILSEQ; return -1;
} }
if (!(FIRST_AES2501_REG <= target && target <= LAST_AES2501_REG)) { if (!(FIRST_AES2501_REG <= target && target <= LAST_AES2501_REG)) {
fp_err("out of range"); fp_err("out of range");
return -EINVAL; return -1;
} }
target -= FIRST_AES2501_REG; target -= FIRST_AES2501_REG;
@ -181,66 +160,56 @@ static int regval_from_dump(unsigned char *data, uint8_t target)
return data[target + 1]; return data[target + 1];
} }
static void generic_write_regv_cb(struct fp_img_dev *dev, int result, static void generic_write_regv_cb(FpImageDevice *dev, GError *error,
void *user_data) void *user_data)
{ {
fpi_ssm *ssm = user_data; FpiSsm *ssm = user_data;
if (result == 0) if (!error)
fpi_ssm_next_state(ssm); fpi_ssm_next_state(ssm);
else else
fpi_ssm_mark_failed(ssm, result); fpi_ssm_mark_failed(ssm, error);
} }
/* check that read succeeded but ignore all data */ /* check that read succeeded but ignore all data */
static void generic_ignore_data_cb(struct libusb_transfer *transfer, static void generic_ignore_data_cb(FpiUsbTransfer *transfer, FpDevice *dev,
struct fp_dev *dev, gpointer user_data, GError *error)
fpi_ssm *ssm,
void *user_data)
{ {
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) FpiSsm *ssm = transfer->ssm;
fpi_ssm_mark_failed(ssm, -EIO); if (error)
else if (transfer->length != transfer->actual_length) fpi_ssm_mark_failed(ssm, error);
fpi_ssm_mark_failed(ssm, -EPROTO);
else else
fpi_ssm_next_state(ssm); fpi_ssm_next_state(ssm);
} }
/* read the specified number of bytes from the IN endpoint but throw them /* read the specified number of bytes from the IN endpoint but throw them
* away, then increment the SSM */ * away, then increment the SSM */
static void generic_read_ignore_data(fpi_ssm *ssm, struct fp_dev *dev, size_t bytes) static void generic_read_ignore_data(FpiSsm *ssm, FpDevice *dev,
size_t bytes)
{ {
fpi_usb_transfer *transfer; FpiUsbTransfer *transfer;
unsigned char *data;
int r;
data = g_malloc(bytes); transfer = fpi_usb_transfer_new(dev);
transfer = fpi_usb_fill_bulk_transfer(dev, transfer->ssm = ssm;
ssm, transfer->short_is_error = TRUE;
EP_IN, fpi_usb_transfer_fill_bulk(transfer, EP_IN, bytes);
data, fpi_usb_transfer_submit(transfer, BULK_TIMEOUT, NULL,
bytes, generic_ignore_data_cb, NULL);
generic_ignore_data_cb, fpi_usb_transfer_unref(transfer);
NULL,
BULK_TIMEOUT);
r = fpi_usb_submit_transfer(transfer);
if (r < 0)
fpi_ssm_mark_failed(ssm, r);
} }
/****** IMAGE PROCESSING ******/ /****** IMAGE PROCESSING ******/
static int sum_histogram_values(unsigned char *data, uint8_t threshold) static int sum_histogram_values(unsigned char *data, guint8 threshold)
{ {
int r = 0; int r = 0;
int i; int i;
uint16_t *histogram = (uint16_t *)(data + 1); guint16 *histogram = (guint16 *)(data + 1);
if (*data != 0xde) if (*data != 0xde)
return -EILSEQ; return -1;
if (threshold > 0x0f) if (threshold > 0x0f)
return -EINVAL; return -1;
/* FIXME endianness */ /* FIXME endianness */
for (i = threshold; i < 16; i++) for (i = threshold; i < 16; i++)
@ -279,23 +248,18 @@ static const struct aes_regwrite finger_det_reqs[] = {
{ AES2501_REG_LPONT, AES2501_LPONT_MIN_VALUE }, { AES2501_REG_LPONT, AES2501_LPONT_MIN_VALUE },
}; };
static void start_finger_detection(struct fp_img_dev *dev); static void start_finger_detection(FpImageDevice *dev);
static void finger_det_data_cb(struct libusb_transfer *transfer, static void finger_det_data_cb(FpiUsbTransfer *transfer, FpDevice *_dev,
struct fp_dev *_dev, gpointer user_data, GError *error)
fpi_ssm *ssm,
void *user_data)
{ {
struct fp_img_dev *dev = FP_IMG_DEV(_dev); FpImageDevice *dev = FP_IMAGE_DEVICE(_dev);
unsigned char *data = transfer->buffer; unsigned char *data = transfer->buffer;
int i; int i;
int sum = 0; int sum = 0;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { if (error) {
fpi_imgdev_session_error(dev, -EIO); fpi_image_device_session_error(dev, error);
return;
} else if (transfer->length != transfer->actual_length) {
fpi_imgdev_session_error(dev, -EPROTO);
return; return;
} }
@ -304,7 +268,7 @@ static void finger_det_data_cb(struct libusb_transfer *transfer,
sum += (data[i] & 0xf) + (data[i] >> 4); sum += (data[i] & 0xf) + (data[i] >> 4);
if (sum > 20) { if (sum > 20) {
/* finger present, start capturing */ /* finger present, start capturing */
fpi_imgdev_report_finger_status(dev, TRUE); fpi_image_device_report_finger_status(dev, TRUE);
start_capture(dev); start_capture(dev);
} else { } else {
/* no finger, poll for a new histogram */ /* no finger, poll for a new histogram */
@ -312,39 +276,30 @@ static void finger_det_data_cb(struct libusb_transfer *transfer,
} }
} }
static void finger_det_reqs_cb(struct fp_img_dev *dev, int result, static void finger_det_reqs_cb(FpImageDevice *dev, GError *error,
void *user_data) void *user_data)
{ {
fpi_usb_transfer *transfer; FpiUsbTransfer *transfer;
unsigned char *data;
int r;
if (result) { if (error) {
fpi_imgdev_session_error(dev, result); fpi_image_device_session_error (dev, error);
return; return;
} }
data = g_malloc(FINGER_DETECTION_LEN); transfer = fpi_usb_transfer_new(FP_DEVICE(dev));
transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev), transfer->short_is_error = TRUE;
NULL, fpi_usb_transfer_fill_bulk(transfer, EP_IN, FINGER_DETECTION_LEN);
EP_IN, fpi_usb_transfer_submit(transfer, BULK_TIMEOUT, NULL,
data, finger_det_data_cb, NULL);
FINGER_DETECTION_LEN, fpi_usb_transfer_unref(transfer);
finger_det_data_cb,
NULL,
BULK_TIMEOUT);
r = fpi_usb_submit_transfer(transfer);
if (r < 0)
fpi_imgdev_session_error(dev, r);
} }
static void start_finger_detection(struct fp_img_dev *dev) static void start_finger_detection(FpImageDevice *dev)
{ {
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); FpiDeviceAes2501 *self = FPI_DEVICE_AES2501(dev);
G_DEBUG_HERE(); G_DEBUG_HERE();
if (aesdev->deactivating) { if (self->deactivating) {
complete_deactivation(dev); complete_deactivation(dev);
return; return;
} }
@ -428,36 +383,34 @@ enum capture_states {
CAPTURE_NUM_STATES, CAPTURE_NUM_STATES,
}; };
static void capture_read_strip_cb(struct libusb_transfer *transfer, static void capture_read_strip_cb(FpiUsbTransfer *transfer, FpDevice *_dev,
struct fp_dev *_dev, gpointer user_data, GError *error)
fpi_ssm *ssm,
void *user_data)
{ {
FpiSsm *ssm = transfer->ssm;
unsigned char *stripdata; unsigned char *stripdata;
struct fp_img_dev *dev = FP_IMG_DEV(_dev); FpImageDevice *dev = FP_IMAGE_DEVICE(_dev);
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(_dev); FpiDeviceAes2501 *self = FPI_DEVICE_AES2501(_dev);
unsigned char *data = transfer->buffer; unsigned char *data = transfer->buffer;
int sum; int sum;
int threshold; int threshold;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { if (error) {
fpi_ssm_mark_failed(ssm, -EIO); fpi_ssm_mark_failed(ssm, error);
return;
} else if (transfer->length != transfer->actual_length) {
fpi_ssm_mark_failed(ssm, -EPROTO);
return; return;
} }
threshold = regval_from_dump(data + 1 + 192*8 + 1 + 16*2 + 1 + 8, threshold = regval_from_dump(data + 1 + 192*8 + 1 + 16*2 + 1 + 8,
AES2501_REG_DATFMT); AES2501_REG_DATFMT);
if (threshold < 0) { if (threshold < 0) {
fpi_ssm_mark_failed(ssm, threshold); fpi_ssm_mark_failed(ssm,
fpi_device_error_new (FP_DEVICE_ERROR_PROTO));
return; return;
} }
sum = sum_histogram_values(data + 1 + 192*8, threshold & 0x0f); sum = sum_histogram_values(data + 1 + 192*8, threshold & 0x0f);
if (sum < 0) { if (sum < 0) {
fpi_ssm_mark_failed(ssm, sum); fpi_ssm_mark_failed(ssm,
fpi_device_error_new (FP_DEVICE_ERROR_PROTO));
return; return;
} }
fp_dbg("sum=%d", sum); fp_dbg("sum=%d", sum);
@ -477,21 +430,21 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer,
* to ensure * to ensure
*/ */
if (sum == 0) { if (sum == 0) {
aesdev->no_finger_cnt++; self->no_finger_cnt++;
if (aesdev->no_finger_cnt == 3) { if (self->no_finger_cnt == 3) {
struct fp_img *img; FpImage *img;
aesdev->strips = g_slist_reverse(aesdev->strips); self->strips = g_slist_reverse(self->strips);
fpi_do_movement_estimation(&assembling_ctx, fpi_do_movement_estimation(&assembling_ctx,
aesdev->strips, aesdev->strips_len); self->strips, self->strips_len);
img = fpi_assemble_frames(&assembling_ctx, img = fpi_assemble_frames(&assembling_ctx,
aesdev->strips, aesdev->strips_len); self->strips,
img->flags |= FP_IMG_PARTIAL; self->strips_len);
g_slist_free_full(aesdev->strips, g_free); g_slist_free_full(self->strips, g_free);
aesdev->strips = NULL; self->strips = NULL;
aesdev->strips_len = 0; self->strips_len = 0;
fpi_imgdev_image_captured(dev, img); fpi_image_device_image_captured(dev, img);
fpi_imgdev_report_finger_status(dev, FALSE); fpi_image_device_report_finger_status(dev, FALSE);
/* marking machine complete will re-trigger finger detection loop */ /* marking machine complete will re-trigger finger detection loop */
fpi_ssm_mark_completed(ssm); fpi_ssm_mark_completed(ssm);
} else { } else {
@ -505,19 +458,18 @@ static void capture_read_strip_cb(struct libusb_transfer *transfer,
stripe->delta_y = 0; stripe->delta_y = 0;
stripdata = stripe->data; stripdata = stripe->data;
memcpy(stripdata, data + 1, 192*8); memcpy(stripdata, data + 1, 192*8);
aesdev->no_finger_cnt = 0; self->no_finger_cnt = 0;
aesdev->strips = g_slist_prepend(aesdev->strips, stripe); self->strips = g_slist_prepend(self->strips, stripe);
aesdev->strips_len++; self->strips_len++;
fpi_ssm_jump_to_state(ssm, CAPTURE_REQUEST_STRIP); fpi_ssm_jump_to_state(ssm, CAPTURE_REQUEST_STRIP);
} }
} }
static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void capture_run_state(FpiSsm *ssm, FpDevice *device, void *user_data)
{ {
struct fp_img_dev *dev = user_data; FpImageDevice *dev = user_data;
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(_dev); FpiDeviceAes2501 *self = FPI_DEVICE_AES2501(device);
int r;
switch (fpi_ssm_get_cur_state(ssm)) { switch (fpi_ssm_get_cur_state(ssm)) {
case CAPTURE_WRITE_REQS_1: case CAPTURE_WRITE_REQS_1:
@ -525,72 +477,71 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data
generic_write_regv_cb, ssm); generic_write_regv_cb, ssm);
break; break;
case CAPTURE_READ_DATA_1: case CAPTURE_READ_DATA_1:
generic_read_ignore_data(ssm, _dev, READ_REGS_RESP_LEN); generic_read_ignore_data(ssm, device, READ_REGS_RESP_LEN);
break; break;
case CAPTURE_WRITE_REQS_2: case CAPTURE_WRITE_REQS_2:
aes_write_regv(dev, capture_reqs_2, G_N_ELEMENTS(capture_reqs_2), aes_write_regv(dev, capture_reqs_2, G_N_ELEMENTS(capture_reqs_2),
generic_write_regv_cb, ssm); generic_write_regv_cb, ssm);
break; break;
case CAPTURE_READ_DATA_2: case CAPTURE_READ_DATA_2:
generic_read_ignore_data(ssm, _dev, READ_REGS_RESP_LEN); generic_read_ignore_data(ssm, device, READ_REGS_RESP_LEN);
break; break;
case CAPTURE_REQUEST_STRIP: case CAPTURE_REQUEST_STRIP:
if (aesdev->deactivating) if (self->deactivating)
fpi_ssm_mark_completed(ssm); fpi_ssm_mark_completed(ssm);
else else
aes_write_regv(dev, strip_scan_reqs, G_N_ELEMENTS(strip_scan_reqs), aes_write_regv(dev, strip_scan_reqs, G_N_ELEMENTS(strip_scan_reqs),
generic_write_regv_cb, ssm); generic_write_regv_cb, ssm);
break; break;
case CAPTURE_READ_STRIP: ; case CAPTURE_READ_STRIP: {
fpi_usb_transfer *transfer; FpiUsbTransfer *transfer;
unsigned char *data;
data = g_malloc(STRIP_CAPTURE_LEN); transfer = fpi_usb_transfer_new(device);
transfer = fpi_usb_fill_bulk_transfer(FP_DEV(dev), transfer->ssm = ssm;
ssm, transfer->short_is_error = TRUE;
EP_IN, fpi_usb_transfer_fill_bulk(transfer, EP_IN, STRIP_CAPTURE_LEN);
data, fpi_usb_transfer_submit(transfer, BULK_TIMEOUT, NULL,
STRIP_CAPTURE_LEN, capture_read_strip_cb, NULL);
capture_read_strip_cb, fpi_usb_transfer_unref(transfer);
NULL, break;
BULK_TIMEOUT); }
r = fpi_usb_submit_transfer(transfer);
if (r < 0)
fpi_ssm_mark_failed(ssm, r);
break;
}; };
} }
static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void capture_sm_complete(FpiSsm *ssm, FpDevice *_dev, void *user_data,
GError *error)
{ {
struct fp_img_dev *dev = user_data; FpImageDevice *dev = user_data;
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(_dev); FpiDeviceAes2501 *self = FPI_DEVICE_AES2501(_dev);
G_DEBUG_HERE(); G_DEBUG_HERE();
if (aesdev->deactivating)
if (self->deactivating) {
complete_deactivation(dev); complete_deactivation(dev);
else if (fpi_ssm_get_error(ssm)) g_clear_pointer (&error, g_error_free);
fpi_imgdev_session_error(dev, fpi_ssm_get_error(ssm)); } else if (error) {
else fpi_image_device_session_error(dev, error);
} else {
start_finger_detection(dev); start_finger_detection(dev);
}
fpi_ssm_free(ssm); fpi_ssm_free(ssm);
} }
static void start_capture(struct fp_img_dev *dev) static void start_capture(FpImageDevice *dev)
{ {
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); FpiDeviceAes2501 *self = FPI_DEVICE_AES2501(dev);
fpi_ssm *ssm; FpiSsm *ssm;
if (aesdev->deactivating) { if (self->deactivating) {
complete_deactivation(dev); complete_deactivation(dev);
return; return;
} }
aesdev->no_finger_cnt = 0; self->no_finger_cnt = 0;
/* Reset gain */ /* Reset gain */
strip_scan_reqs[4].value = AES2501_ADREFHI_MAX_VALUE; strip_scan_reqs[4].value = AES2501_ADREFHI_MAX_VALUE;
ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev); ssm = fpi_ssm_new(FP_DEVICE(dev), capture_run_state,
CAPTURE_NUM_STATES, dev);
G_DEBUG_HERE(); G_DEBUG_HERE();
fpi_ssm_start(ssm, capture_sm_complete); fpi_ssm_start(ssm, capture_sm_complete);
} }
@ -700,36 +651,36 @@ enum activate_states {
ACTIVATE_NUM_STATES, ACTIVATE_NUM_STATES,
}; };
void activate_read_regs_cb(struct fp_img_dev *dev, int status, void activate_read_regs_cb(FpImageDevice *dev, GError *error,
unsigned char *regs, void *user_data) unsigned char *regs, void *user_data)
{ {
fpi_ssm *ssm = user_data; FpiSsm *ssm = user_data;
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); FpiDeviceAes2501 *self = FPI_DEVICE_AES2501(dev);
if (status != 0) { if (error) {
fpi_ssm_mark_failed(ssm, status); fpi_ssm_mark_failed(ssm, error);
} else { } else {
fp_dbg("reg 0xaf = %x", regs[0x5f]); fp_dbg("reg 0xaf = %x", regs[0x5f]);
if (regs[0x5f] != 0x6b || ++aesdev->read_regs_retry_count == 13) if (regs[0x5f] != 0x6b || ++self->read_regs_retry_count == 13)
fpi_ssm_jump_to_state(ssm, WRITE_INIT_4); fpi_ssm_jump_to_state(ssm, WRITE_INIT_4);
else else
fpi_ssm_next_state(ssm); fpi_ssm_next_state(ssm);
} }
} }
static void activate_init3_cb(struct fp_img_dev *dev, int result, static void activate_init3_cb(FpImageDevice *dev, GError *error,
void *user_data) void *user_data)
{ {
fpi_ssm *ssm = user_data; FpiSsm *ssm = user_data;
if (result == 0) if (!error)
fpi_ssm_jump_to_state(ssm, READ_REGS); fpi_ssm_jump_to_state(ssm, READ_REGS);
else else
fpi_ssm_mark_failed(ssm, result); fpi_ssm_mark_failed(ssm, error);
} }
static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void activate_run_state(FpiSsm *ssm, FpDevice *_dev, void *user_data)
{ {
struct fp_img_dev *dev = user_data; FpImageDevice *dev = user_data;
/* This state machine isn't as linear as it may appear. After doing init1 /* This state machine isn't as linear as it may appear. After doing init1
* and init2 register configuration writes, we have to poll a register * and init2 register configuration writes, we have to poll a register
@ -781,97 +732,92 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_dat
} }
} }
static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void activate_sm_complete(FpiSsm *ssm, FpDevice *dev,
void *user_data, GError *error)
{ {
struct fp_img_dev *dev = user_data; fpi_image_device_activate_complete(FP_IMAGE_DEVICE (dev), error);
fp_dbg("status %d", fpi_ssm_get_error(ssm));
fpi_imgdev_activate_complete(dev, fpi_ssm_get_error(ssm));
if (!fpi_ssm_get_error(ssm)) if (!error)
start_finger_detection(dev); start_finger_detection(FP_IMAGE_DEVICE (dev));
fpi_ssm_free(ssm); fpi_ssm_free(ssm);
} }
static int dev_activate(struct fp_img_dev *dev) static void dev_activate(FpImageDevice *dev)
{ {
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); FpiDeviceAes2501 *self = FPI_DEVICE_AES2501(dev);
fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state, FpiSsm *ssm = fpi_ssm_new(FP_DEVICE(dev), activate_run_state,
ACTIVATE_NUM_STATES, dev); ACTIVATE_NUM_STATES, dev);
aesdev->read_regs_retry_count = 0; self->read_regs_retry_count = 0;
fpi_ssm_start(ssm, activate_sm_complete); fpi_ssm_start(ssm, activate_sm_complete);
return 0;
} }
static void dev_deactivate(struct fp_img_dev *dev) static void dev_deactivate(FpImageDevice *dev)
{ {
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); FpiDeviceAes2501 *self = FPI_DEVICE_AES2501(dev);
/* FIXME: audit cancellation points, probably need more, specifically /* FIXME: audit cancellation points, probably need more, specifically
* in error handling paths? */ * in error handling paths? */
aesdev->deactivating = TRUE; self->deactivating = TRUE;
} }
static void complete_deactivation(struct fp_img_dev *dev) static void complete_deactivation(FpImageDevice *dev)
{ {
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); FpiDeviceAes2501 *self = FPI_DEVICE_AES2501(dev);
G_DEBUG_HERE(); G_DEBUG_HERE();
/* FIXME: if we're in the middle of a scan, we should cancel the scan. /* FIXME: if we're in the middle of a scan, we should cancel the scan.
* maybe we can do this with a master reset, unconditionally? */ * maybe we can do this with a master reset, unconditionally? */
aesdev->deactivating = FALSE; self->deactivating = FALSE;
g_slist_free(aesdev->strips); g_slist_free(self->strips);
aesdev->strips = NULL; self->strips = NULL;
aesdev->strips_len = 0; self->strips_len = 0;
fpi_imgdev_deactivate_complete(dev); fpi_image_device_deactivate_complete(dev, NULL);
} }
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data) static void dev_init(FpImageDevice *dev)
{ {
GError *error = NULL;
/* FIXME check endpoints */ /* FIXME check endpoints */
int r;
struct aes2501_dev *aesdev;
r = libusb_claim_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); g_usb_device_claim_interface(fpi_device_get_usb_device(FP_DEVICE(dev)), 0, 0, &error);
if (r < 0) { fpi_image_device_open_complete(dev, error);
fp_err("could not claim interface 0: %s", libusb_error_name(r));
return r;
}
aesdev = g_malloc0(sizeof(struct aes2501_dev));
fp_dev_set_instance_data(FP_DEV(dev), aesdev);
fpi_imgdev_open_complete(dev, 0);
return 0;
} }
static void dev_deinit(struct fp_img_dev *dev) static void dev_deinit(FpImageDevice *dev)
{ {
struct aes2501_dev *aesdev = FP_INSTANCE_DATA(FP_DEV(dev)); GError *error = NULL;
g_free(aesdev);
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); g_usb_device_release_interface(fpi_device_get_usb_device(FP_DEVICE(dev)),
fpi_imgdev_close_complete(dev); 0, 0, &error);
fpi_image_device_close_complete(dev, error);
} }
static const struct usb_id id_table[] = { static const FpIdEntry id_table [ ] = {
{ .vendor = 0x08ff, .product = 0x2500 }, /* AES2500 */ { .vid = 0x08ff, .pid = 0x2500,
{ .vendor = 0x08ff, .product = 0x2580 }, /* AES2501 */ }, /* AES2500 */
{ 0, 0, 0, }, { .vid = 0x08ff, .pid = 0x2580,
}, /* AES2501 */
{ .vid = 0, .pid = 0, .driver_data = 0 },
}; };
struct fp_img_driver aes2501_driver = { static void fpi_device_aes2501_init(FpiDeviceAes2501 *self) {
.driver = { }
.id = AES2501_ID, static void fpi_device_aes2501_class_init(FpiDeviceAes2501Class *klass) {
.name = FP_COMPONENT, FpDeviceClass *dev_class = FP_DEVICE_CLASS(klass);
.full_name = "AuthenTec AES2501", FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS(klass);
.id_table = id_table,
.scan_type = FP_SCAN_TYPE_SWIPE,
},
.flags = 0,
.img_height = -1,
.img_width = IMAGE_WIDTH,
.open = dev_init, dev_class->id = "aes2501";
.close = dev_deinit, dev_class->full_name = "AuthenTec AES2501";
.activate = dev_activate, dev_class->type = FP_DEVICE_TYPE_USB;
.deactivate = dev_deactivate, dev_class->id_table = id_table;
}; dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
img_class->img_open = dev_init;
img_class->img_close = dev_deinit;
img_class->activate = dev_activate;
img_class->deactivate = dev_deactivate;
img_class->img_width = IMAGE_WIDTH;
img_class->img_height = -1;
}

View file

@ -51,7 +51,7 @@ mathlib_dep = cc.find_library('m', required: false)
drivers = get_option('drivers').split(',') drivers = get_option('drivers').split(',')
virtual_drivers = [ 'virtual_image' ] virtual_drivers = [ 'virtual_image' ]
#default_drivers = [ 'upekts', 'upektc', 'upeksonly', 'vcom5s', 'uru4000', 'aes1610', 'aes1660', 'aes2501', 'aes2550', 'aes2660', 'aes3500', 'aes4000', 'vfs101', 'vfs301', 'vfs5011', 'upektc_img', 'etes603', 'vfs0050', 'elan' ] #default_drivers = [ 'upekts', 'upektc', 'upeksonly', 'vcom5s', 'uru4000', 'aes1610', 'aes1660', 'aes2501', 'aes2550', 'aes2660', 'aes3500', 'aes4000', 'vfs101', 'vfs301', 'vfs5011', 'upektc_img', 'etes603', 'vfs0050', 'elan' ]
default_drivers = [ 'upektc_img', 'vfs5011', 'aes3500', 'aes4000', 'aes1610', 'aes1660', 'aes2660' ] default_drivers = [ 'upektc_img', 'vfs5011', 'aes3500', 'aes4000', 'aes1610', 'aes1660', 'aes2660', 'aes2501' ]
all_drivers = default_drivers + virtual_drivers all_drivers = default_drivers + virtual_drivers