feat: 實作 edc2.0 / eis 2.0 樣板

This commit is contained in:
chain40
2024-03-05 00:38:05 +08:00
parent 0b3d60d1b3
commit f192bb44c5
7 changed files with 293 additions and 72 deletions
+4
View File
@@ -180,6 +180,8 @@
<ClCompile Include="..\bmd380_sdk\integration\nrfx\legacy\nrf_drv_uart.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="edc_2_0.c" />
<ClCompile Include="eis_2_0.c" />
<ClCompile Include="elite.c" />
<ClCompile Include="i2c.c" />
<ClCompile Include="led.c" />
@@ -335,6 +337,8 @@
<ClInclude Include="..\bmd380_sdk\integration\nrfx\nrfx_glue.h" />
<ClInclude Include="..\bmd380_sdk\integration\nrfx\nrfx_log.h" />
<ClInclude Include="app_config.h" />
<ClInclude Include="edc.h" />
<ClInclude Include="eis.h" />
<ClInclude Include="elite.h" />
<ClInclude Include="FreeRTOSConfig.h" />
<ClInclude Include="elite_def.h" />
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#ifndef __EDC_H__
#define __EDC_H__
#include "elite_def.h"
extern elite_instance_t edc_2_0;
#endif // !__EDC_H__
+79
View File
@@ -0,0 +1,79 @@
#include "edc.h"
#include "nrf_log.h"
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
static void dummy(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void cis_version(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void cis_volt(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void cis_cali(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void vis_rst(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void vis_sti(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void vis_int(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void vis_device_shiny(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void vis_shiny_dis(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_iv(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_iv_cy(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_vo(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_rt(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_vt(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_it(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_cc(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_ocp(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_cv(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_lsv(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_ca(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_cp(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_uni_pulse(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_dpv(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_dpv_advance(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_dpv_smprate(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_dpv_advance_smprate(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_eis(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_cf(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_cali(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void set_sample_rate(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
elite_instance_t edc_2_0 = {
.cis_func = {
[CIS_VERSION] = cis_version,
[CIS_VOLT] = cis_volt,
[CIS_CALI] = cis_cali,
},
.vis_func = {
[VIS_RST] = vis_rst,
[VIS_STI] = vis_sti,
[VIS_INT] = vis_int,
[VIS_DEVICE_SHINY] = vis_device_shiny,
[VIS_SHINY_DIS] = vis_shiny_dis,
},
.ris_func = {
[CURVE_IV] = curve_iv,
[CURVE_IV_CY] = curve_iv_cy,
[CURVE_VO] = curve_vo,
[CURVE_RT] = curve_rt,
[CURVE_VT] = curve_vt,
[CURVE_IT] = curve_it,
[CURVE_CC] = curve_cc,
[CURVE_OCP] = curve_ocp,
[CURVE_CV] = curve_cv,
[CURVE_LSV] = curve_lsv,
[CURVE_CA] = curve_ca,
[CURVE_CP] = curve_cp,
[CURVE_UNI_PULSE] = curve_uni_pulse,
[CURVE_DPV] = curve_dpv,
[CURVE_DPV_ADVANCE] = curve_dpv_advance,
[CURVE_DPV_SMPRATE] = curve_dpv_smprate,
[CURVE_DPV_ADVANCE_SMPRATE] = curve_dpv_advance_smprate,
[CURVE_EIS] = curve_eis,
[CURVE_CF] = curve_cf,
[CURVE_CALI] = curve_cali,
[SET_SAMPLE_RATE] = set_sample_rate,
},
};
#endif
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#ifndef __EIS_H__
#define __EIS_H__
#include "elite_def.h"
extern elite_instance_t eis_2_0;
#endif // !__EIS_H__
+79
View File
@@ -0,0 +1,79 @@
#include "eis.h"
#include "nrf_log.h"
#if (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
static void dummy(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void cis_version(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void cis_volt(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void cis_cali(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void vis_rst(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void vis_sti(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void vis_int(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void vis_device_shiny(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void vis_shiny_dis(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_iv(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_iv_cy(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_vo(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_rt(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_vt(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_it(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_cc(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_ocp(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_cv(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_lsv(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_ca(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_cp(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_uni_pulse(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_dpv(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_dpv_advance(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_dpv_smprate(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_dpv_advance_smprate(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_eis(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_cf(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void curve_cali(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
static void set_sample_rate(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); }
elite_instance_t eis_2_0 = {
.cis_func = {
[CIS_VERSION] = cis_version,
[CIS_VOLT] = cis_volt,
[CIS_CALI] = cis_cali,
},
.vis_func = {
[VIS_RST] = vis_rst,
[VIS_STI] = vis_sti,
[VIS_INT] = vis_int,
[VIS_DEVICE_SHINY] = vis_device_shiny,
[VIS_SHINY_DIS] = vis_shiny_dis,
},
.ris_func = {
[CURVE_IV] = curve_iv,
[CURVE_IV_CY] = curve_iv_cy,
[CURVE_VO] = curve_vo,
[CURVE_RT] = curve_rt,
[CURVE_VT] = curve_vt,
[CURVE_IT] = curve_it,
[CURVE_CC] = curve_cc,
[CURVE_OCP] = curve_ocp,
[CURVE_CV] = curve_cv,
[CURVE_LSV] = curve_lsv,
[CURVE_CA] = curve_ca,
[CURVE_CP] = curve_cp,
[CURVE_UNI_PULSE] = curve_uni_pulse,
[CURVE_DPV] = curve_dpv,
[CURVE_DPV_ADVANCE] = curve_dpv_advance,
[CURVE_DPV_SMPRATE] = curve_dpv_smprate,
[CURVE_DPV_ADVANCE_SMPRATE] = curve_dpv_advance_smprate,
[CURVE_EIS] = curve_eis,
[CURVE_CF] = curve_cf,
[CURVE_CALI] = curve_cali,
[SET_SAMPLE_RATE] = set_sample_rate,
},
};
#endif
+47 -6
View File
@@ -1,5 +1,7 @@
#include "elite.h"
#include "edc.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
@@ -12,13 +14,55 @@
#include <stdlib.h>
#include <string.h>
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
static elite_instance_t *p_instance = &edc_2_0;
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
static elite_instance_t *p_instance = &eis_2_0;
#else
#error "Unknown DEF_ELITE_MODEL"
static elite_instance_t *p_instance = NULL;
#endif
MessageBufferHandle_t instr_msg = NULL;
__WEAK void decode_ris_ins(uint8_t *ins, uint16_t size) { }
static void decode_ris_ins(uint8_t *ins, uint16_t size)
{
uint8_t oper = ins[2];
if (p_instance->ris_func[oper])
{
p_instance->ris_func[oper](ins, size);
}
else
{
NRF_LOG_INFO("unknown ris instruction");
}
}
__WEAK void decode_vis_ins(uint8_t *ins, uint16_t size) { }
static void decode_vis_ins(uint8_t *ins, uint16_t size)
{
uint8_t oper = ins[1] & 0xF0; // this is don't care in RISASD;//
if (p_instance->vis_func[oper])
{
p_instance->vis_func[oper](ins, size);
}
else
{
NRF_LOG_INFO("unknown vis instruction");
}
}
__WEAK void decode_cis_ins(uint8_t *ins, uint16_t size) { }
static void decode_cis_ins(uint8_t *ins, uint16_t size)
{
uint8_t oper = ins[1] & 0xF0;
if (p_instance->cis_func[oper])
{
p_instance->cis_func[oper](ins, size);
}
else
{
NRF_LOG_INFO("unknown vis instruction");
}
}
static void elite_instr_task(void *p_arg)
{
@@ -33,17 +77,14 @@ static void elite_instr_task(void *p_arg)
{
uint16_t ins_type = instr[0] & 0b11110000;
uint16_t chip_id = instr[0] & 0b00001111;
switch (ins_type)
{
case INS_TYPE_RIS:
decode_ris_ins(instr, instr_size);
break;
case INS_TYPE_VIS:
decode_vis_ins(instr, instr_size);
break;
case INS_TYPE_CIS:
decode_cis_ins(instr, instr_size);
break;
+66 -66
View File
@@ -2,6 +2,8 @@
#ifndef __ELITE_DEF_H__
#define __ELITE_DEF_H__
#include <stdint.h>
// define BT instruction
#define INS_TYPE_RIS 0x30
#define INS_TYPE_VIS 0xC0
@@ -11,11 +13,7 @@
#define VIS_RST 0xF0
#define VIS_ASK 0x30
#define VIS_STI 0xC0
#define VIS_FUH 0x90
#define VIS_INT 0x60
#define VIS_SHIFT_200K 0xA0
#define VIS_SHIFT_10K 0xE0
#define VIS_SHIFT_200R 0x80
#define VIS_DEVICE_SHINY 0x10
#define VIS_SHINY_DIS 0x20
@@ -33,80 +31,82 @@ enum all_mode_e
CURVE_CV = 0x09, // Cyclic Voltammetry (CV)
CURVE_LSV = 0x0A, // Linear Sweep Voltammetry (LSV)
CURVE_CA = 0x0B, // Chronoamperometric Graph (CA)
CURVE_CP = 0x0C,
CURVE_CP = 0x0C, // Chronopotentiometry (CP)
CURVE_UNI_PULSE = 0x0D, // Pulse Sensing (universal pulse)
CURVE_DPV = 0x0E, // Differential Pulse Voltammetry (DPV)
CURVE_DPV_SMPRATE = 0x0F,
CURVE_DPV_ADVANCE = 0x10,
CURVE_DPV_ADVANCE = 0x0F,
CURVE_DPV_SMPRATE = 0x10,
CURVE_DPV_ADVANCE_SMPRATE = 0x11,
CURVE_CALI = 0xF1,
SET_SAMPLE_RATE = 0xE0,
SET_ADC_DAC_GAIN = 0xE1,
SET_PARA = 0xE2
};
enum set_para_e
{
DAC_VOLT = 0x01,
};
enum dev_para_e
{
VERSION_DEV_TEST = 0x01,
BAT_DEV_TEST = 0x02,
TEMP_DEV_TEST = 0x03,
LED_DEV_TEST = 0x04,
CURVE_EIS = 0x12,
CURVE_CF = 0x13, // Constant Frequency(CF)
CURVE_CALI = 0xF1,
SET_SAMPLE_RATE = 0xE0,
};
// CIS (control instruction)
#define CIS_VERSION 0x40
#define CIS_VOLT 0x10
#define CIS_TEMPERATURE 0x80
#define CIS_VERSION 0x40
#define CIS_VOLT 0x10
#define CIS_LED_TEST 0x70
#define CIS_CALI 0x30
#define CIS_CALI2 0x90
#define CTL_WRT 0x20
#define CTL_RD 0x21
#define CTL_RD_DFTR 0x78
#define CTL_RD_DFTI 0x7C
#define CTL_RD_ADC 0x7A
#define CTL_RESET 0x11
// mode parameter
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
#define VMAX(v1, v2) ((v1 >= v2) ? v1 : v2)
#define VMIN(v1, v2) ((v1 < v2) ? v1 : v2)
#define VDIRECTION(v1, v2) ((v1 > v2) ? 0 : 1)
#define AFTER_READ_I 0
#define AFTER_READ_V 1
#define VMAX(v1, v2) ((v1 >= v2) ? v1 : v2)
#define VMIN(v1, v2) ((v1 < v2) ? v1 : v2)
#define VDIRECTION(v1, v2) ((v1 > v2) ? 0 : 1)
#define AFTER_READ_I 0
#define AFTER_READ_V 1
#define PARA_1 0x01
#define PARA_2 0x02
#define PARA_3 0x03
#define PARA_4 0x04
#define PARA_5 0x05
#define PARA_6 0x06
#define PARA_7 0x07
#define PARA_8 0x08
#define PARA_9 0x09
#define PARA_10 0x0A
#define PARA_11 0x0B
#define PARA_12 0x0C
#define PARA_13 0x0D
#define PARA_14 0x0E
#define PARA_15 0x0F
#define PARA_16 0x10
#define PARA_17 0x11
// Elite LED
#define COLOR_BLACK 0x00
#define COLOR_RED 0x01
#define COLOR_ORANGE 0x02
#define COLOR_YELLOW 0x03
#define COLOR_GREEN 0x04
#define COLOR_BLUE 0x05
#define COLOR_CYAN 0x06
#define COLOR_MAGENTA 0x07
#define COLOR_PURPLE 0x08
#define COLOR_WHITE 0x09
#define COLOR_YELLOWGREEN 0x0A
#define COLOR_EMERALD 0x0B
#define COLOR_YELLOW_DARK 0xF3
#define COLOR_GREEN_DARK 0xF4
#define COLOR_BLUE_DARK 0xF5
#define COLOR_CYAN_DARK 0xF6
#define COLOR_PURPLE_DARK 0xF8
#define COLOR_BLACK 0x00
#define COLOR_RED 0x01
#define COLOR_ORANGE 0x02
#define COLOR_YELLOW 0x03
#define COLOR_GREEN 0x04
#define COLOR_BLUE 0x05
#define COLOR_CYAN 0x06
#define COLOR_MAGENTA 0x07
#define COLOR_PURPLE 0x08
#define COLOR_WHITE 0x09
#define COLOR_YELLOWGREEN 0x0A
#define BT_WAIT 0x01
#define NO_EVENT 0x02
#define PRE_WORK 0x03
#define WORKING 0x04
#define POST_WORK 0x05
#define BT_WAIT 0x01
#define NO_EVENT 0x02
#define PRE_WORK 0x03
#define WORKING 0x04
#define POST_WORK 0x05
#define VALUE_ZERO_TO_ONE(_v) (_v == 0) ? 1 : _v
typedef struct
{
void (*cis_func[256])(uint8_t *ins, uint16_t size);
void (*vis_func[256])(uint8_t *ins, uint16_t size);
void (*ris_func[256])(uint8_t *ins, uint16_t size);
} elite_instance_t;
// plot_type
#define IT_PLOT 1
#define VT_PLOT 2
#define VOUT_PLOT 3
#define IIN_VIN_PLOT 4
#define IIN_VIN_VOUT_PLOT 5
#define CLOCK_ONE_SECOND 10000
#endif /* ! __ELITE_DEF_H__ */