42#define CHIP_NAME "EM Microelectronic EM4100"
43#define MANUFACTURER_NAME "EM Microelectronic"
44#define SUPPLY_VOLTAGE_MIN 1.5f
45#define SUPPLY_VOLTAGE_MAX 7.5f
46#define MAX_CURRENT 10.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
64static uint8_t a_em4100_manchester_decode(uint8_t *input, uint16_t input_len, uint8_t *output, uint16_t *output_len)
72 for (i = 0; i < (l - 1); i++)
74 if ((input[i] == 0x01) && (input[i + 1] == 0x01))
85 for (i = start; i < (l - 1); i += 2)
87 if (cnt >= (*output_len))
91 if ((input[i] == 0x01) && (input[i + 1] == 0x00))
96 else if ((input[i] == 0x00) && (input[i + 1] == 0x01))
123static uint8_t a_em4100_raw_decode(uint8_t *input, uint16_t input_len, uint8_t *output, uint16_t *output_len)
131 for (i = 0; i < (l - 9); i++)
133 if ((input[i + 0] == 0x01) && (input[i + 1] == 0x01) && (input[i + 2] == 0x01) &&
134 (input[i + 3] == 0x01) && (input[i + 4] == 0x01) && (input[i + 5] == 0x01) &&
135 (input[i + 6] == 0x01) && (input[i + 7] == 0x01) && (input[i + 8] == 0x01))
146 for (i = start; i < (l - 9); i++)
148 if (cnt >= (*output_len))
152 output[cnt] = input[i];
172static uint8_t a_em4100_frame_decode(uint8_t input[64], uint8_t output[5])
178 if ((input[0] != 0x01) || (input[1] != 0x01) || (input[2] != 0x01) ||
179 (input[3] != 0x01) || (input[4] != 0x01) || (input[5] != 0x01) ||
180 (input[6] != 0x01) || (input[7] != 0x01) || (input[8] != 0x01))
190 for (i = 9; i < 59; i += 5)
197 t |= input[i + 0] << 3;
198 t |= input[i + 1] << 2;
199 t |= input[i + 2] << 1;
200 t |= input[i + 3] << 0;
201 check = input[i + 0] ^ input[i + 1] ^ input[i + 2] ^
202 input[i + 3] ^ input[i + 4];
210 for (i = 0; i < 4; i++)
215 check = input[9 + 0 * 5 + i] ^ input[9 + 1 * 5 + i] ^
216 input[9 + 2 * 5 + i] ^ input[9 + 3 * 5 + i] ^
217 input[9 + 4 * 5 + i] ^ input[9 + 5 * 5 + i] ^
218 input[9 + 6 * 5 + i] ^ input[9 + 7 * 5 + i] ^
219 input[9 + 8 * 5 + i] ^ input[9 + 9 * 5 + i] ^
220 input[9 + 10 * 5 + i];
226 for (i = 0; i < 5; i++)
228 output[i] = (buf[i * 2 + 0] << 4) | buf[i * 2 + 1];
244static uint8_t a_em4100_read(
em4100_handle_t *handle, uint8_t *buf, uint16_t len)
278 handle->
debug_print(
"em4100: contactless_init is null.\n");
284 handle->
debug_print(
"em4100: contactless_deinit is null.\n");
290 handle->
debug_print(
"em4100: contactless_read is null.\n");
296 handle->
debug_print(
"em4100: delay_ms is null.\n");
304 handle->
debug_print(
"em4100: contactless init failed.\n");
339 handle->
debug_print(
"em4100: contactless deinit failed.\n");
365 uint16_t manchester_len;
377 res = a_em4100_read(handle, handle->
buf, 256);
382 manchester_len = 128;
383 res = a_em4100_manchester_decode(handle->
buf, 256, handle->
manchester_buf, &manchester_len);
398 res = a_em4100_frame_decode(handle->
raw_buf,
id);
431 handle->
debug_print(
"id: 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\n",
432 buf[0], buf[1], buf[2], buf[3], buf[4]);
433 id = ((uint32_t)buf[1] << 24) | ((uint32_t)buf[2] << 16) |
434 ((uint32_t)buf[3] << 8) | ((uint32_t)buf[4] << 0);
435 wiegand26 = ((uint16_t)buf[3] << 8) | ((uint16_t)buf[4] << 0);
436 handle->
debug_print(
"%010d %03d, %05d.\n",
id, buf[2], wiegand26);
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
driver em4100 header file
uint8_t em4100_deinit(em4100_handle_t *handle)
close the chip
struct em4100_info_s em4100_info_t
em4100 information structure definition
uint8_t em4100_info(em4100_info_t *info)
get chip's information
uint8_t em4100_init(em4100_handle_t *handle)
initialize the chip
struct em4100_handle_s em4100_handle_t
em4100 handle structure definition
uint8_t em4100_print(em4100_handle_t *handle, uint8_t buf[5])
print id
uint8_t em4100_read(em4100_handle_t *handle, uint8_t id[5])
read data
uint8_t manchester_buf[128]
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* contactless_deinit)(void)
uint8_t(* contactless_read)(uint32_t clock_div, uint8_t *buf, uint16_t len)
uint8_t(* contactless_init)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v