From 10d2cb60580e206ccc32b37f1b2f43e2acea8b8b Mon Sep 17 00:00:00 2001 From: Roy_01 Date: Wed, 12 Mar 2025 13:45:11 +0800 Subject: [PATCH] feat: new implementation for R_external_calibration_mode --- pel.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- pel.h | 6 ++-- 2 files changed, 94 insertions(+), 8 deletions(-) diff --git a/pel.c b/pel.c index 36817e6..a6ef942 100644 --- a/pel.c +++ b/pel.c @@ -713,8 +713,93 @@ static void auto_scan_mode(uint8_t *ins, uint16_t size) } } -#define MANUAL_SCAN_MODE 0x01 -#define AUTO_SCAN_MODE 0x02 +static void R_external_calibration_mode(uint8_t *ins, uint16_t size) +{ +#define R1 PEL_0P5R_MASK +#define R2 PEL_1P0R_MASK +#define R3 PEL_2P0R_MASK +#define R4 PEL_4P0R_MASK +#define R5 PEL_8P0R_MASK +#define R6 PEL_16P2R_MASK +#define R7 PEL_32P4R_MASK +#define R8 PEL_63P4R_MASK +#define R9 PEL_127R_MASK +#define R10 PEL_255R_MASK +#define R11 PEL_511R_MASK +#define R12 PEL_1000R_MASK + + struct __PACKED + { + uint8_t id : 4; + uint8_t ins_type : 4; + uint8_t pkg_size; + uint8_t mode; + uint8_t opcode; + uint8_t param[]; + } *p_ins = (void *)ins; + + uint32_t calibration_bits_pattern_tab[] = { + R1, + R2, + R1 | R2, + R3, + R2 | R3, + R4, + R3 | R4, + R5, + R4 | R5, + R6, + R5 | R6, + R7, + R6 | R7, + R8, + R7 | R8, + }; + + global_memoryboard_id = p_ins->id; + + static pel_scan_msg_t pel_scan_msg; + pel20_notify_packet1_t packet_buf = { 0 }; + + switch (p_ins->opcode) + { + case 0x01: { + // R_external_calibration_mode start with drop n * 10ms + // 30 00 03 01 00 0A 00 05 + uint32_t drop_10ms = u8_to_u16(p_ins->param[0], p_ins->param[1]); + uint32_t notify_count = u8_to_u16(p_ins->param[2], p_ins->param[3]); + + send_start_package(&packet_buf, sizeof(packet_buf)); + + for (uint32_t i = 0; i < COUNTOF(calibration_bits_pattern_tab); i++) + { + pel_scan_msg.opcode = PEL_START; + pel_scan_msg.resistor_setting.is_pattern = false; + pel_scan_msg.resistor_setting.value = calibration_bits_pattern_tab[i]; + ASSERT(xMessageBufferSend(pel_scan_msqQ, &pel_scan_msg, sizeof(pel_scan_msg.opcode) + sizeof(pel_scan_msg.resistor_setting), pdMS_TO_TICKS(500))); + + pel_scan_msg.opcode = PEL_NOTIFY; + pel_scan_msg.notify_setting.count = notify_count; + pel_scan_msg.notify_setting.drop = drop_10ms; + pel_scan_msg.notify_setting.complete_cb = auto_scan_complete; + ASSERT(xMessageBufferSend(pel_scan_msqQ, &pel_scan_msg, sizeof(pel_scan_msg.opcode) + sizeof(pel_scan_msg.notify_setting), pdMS_TO_TICKS(500))); + + wait_auto_scan_complete(); + } + + pel_scan_msg.opcode = PEL_STOP; + ASSERT(xMessageBufferSend(pel_scan_msqQ, &pel_scan_msg, sizeof(pel_scan_msg.opcode), pdMS_TO_TICKS(500))); + } + break; + + default: + break; + } +} + +#define MANUAL_SCAN_MODE 0x01 +#define AUTO_SCAN_MODE 0x02 +#define R_EXTERNAL_CALIBRATION_MODE 0x03 const elite_instance_t pel_elite_instance = { .cis_func = { @@ -724,9 +809,10 @@ const elite_instance_t pel_elite_instance = { [VIS_RST] = vis_rst, }, .ris_func = { - [MANUAL_SCAN_MODE] = manual_scan_mode, - [AUTO_SCAN_MODE] = auto_scan_mode, - [DEV_MODE] = dev_mode, + [MANUAL_SCAN_MODE] = manual_scan_mode, + [AUTO_SCAN_MODE] = auto_scan_mode, + [R_EXTERNAL_CALIBRATION_MODE] = R_external_calibration_mode, + [DEV_MODE] = dev_mode, } }; diff --git a/pel.h b/pel.h index a8b53cd..63c3549 100644 --- a/pel.h +++ b/pel.h @@ -12,9 +12,9 @@ extern "C" #define VERSION_DATE_YEAR 25 #define VERSION_DATE_MONTH 3 -#define VERSION_DATE_DAY 11 -#define VERSION_DATE_HOUR 17 -#define VERSION_DATE_MINUTE 22 +#define VERSION_DATE_DAY 12 +#define VERSION_DATE_HOUR 13 +#define VERSION_DATE_MINUTE 45 #define PEL_0P5R_MASK (0x01 << 0) #define PEL_1P0R_MASK (0x01 << 1)