Files
microchip-application-bmd38…/edc20.c
T
2024-11-25 14:49:04 +08:00

1015 lines
31 KiB
C

#include "app_config.h"
#include "elite_board.h"
#include "edc.h"
#include "elite.h"
#include "elite_adc.h"
#include "elite_correction.h"
#include "elite_dac.h"
#include "adc_drv.h"
#include "dac_drv.h"
#include "led_drv.h"
#include "sw_drv.h"
#include "nrf_log.h"
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_V2_0)
extern ret_code_t le_event_update(uint8_t *p_value, uint16_t len);
static void dummy(uint8_t *ins, uint16_t size)
{
NRF_LOG_INFO("%s", __FUNCTION__);
}
/*
dev_mode_set_led
(1)0x3000FF0400
-func: LED initialization
(2)0x3000FF0401ccbb
-func: LED uses predefined colors
-cc: custom color index 00h-07h
00h = LED_NONE
01h = LED_RED
02h = LED_ORANGE
03h = LED_YELLOW
04h = LED_GREEN
05h = LED_CYAN
06h = LED_BLUE
07h = LED_PURPLE
-bb: brightness 00h-1Fh
(3)0x3000FF0402nnbbrrggbb
-func: control the color of an LED
-nn: which LED 00h-0Bh
+-------------+
| 2 3 4 5 |
| 1 hole 6 |
| 0 mcu 7 |
| 11 10 9 8 |
+-------------+
-bb: brightness 00h-1Fh
-rrggbb: RGB color code 000000h-FFFFFFh
(4)0x3000FF0403
-func: rainbow-colored LED
*/
static void dev_mode_set_led(uint8_t *ins, uint16_t size)
{
#define LED_ITEM_INIT_LED 0x00
#define LED_ITEM_ALL_LED 0x01
#define LED_ITEM_SINGLE_LED 0x02
#define LED_ITEM_RAINBOW_LED 0x03
uint8_t led_item = ins[4];
switch (led_item)
{
case LED_ITEM_INIT_LED:
led_init();
break;
case LED_ITEM_ALL_LED: {
struct led_color color[8] = { LED_NONE, LED_RED, LED_ORANGE, LED_YELLOW, LED_GREEN, LED_CYAN, LED_BLUE, LED_PURPLE };
char *color_str[8] = { "LED_NONE", "LED_RED", "LED_ORANGE", "LED_YELLOW", "LED_GREEN", "LED_CYAN", "LED_BLUE", "LED_PURPLE" };
uint8_t color_idx = ins[5];
uint8_t brightness = ins[6];
if (color_idx >= COUNT_ARRAY_SIZE(color))
{
NRF_LOG_INFO("[LED] color not provided");
}
else
{
for (int i = 0; i < DEF_LED_COUNT; i++)
led_single_led_set(i, color[color_idx], brightness);
NRF_LOG_INFO("[LED] set color(%s) bright(%d)", color_str[color_idx], brightness);
}
break;
}
case LED_ITEM_SINGLE_LED: {
struct led_color color;
uint8_t brightness = ins[6];
uint32_t idx = ins[5];
color.R = ins[7];
color.G = ins[8];
color.B = ins[9];
led_single_led_set(idx, color, brightness);
NRF_LOG_INFO("[LED] set idx(%d) color(rgb #%02X%02X%02X) bright(%d)", idx, color.R, color.G, color.B, brightness);
break;
}
case LED_ITEM_RAINBOW_LED:
led_as_rainbow();
NRF_LOG_INFO("[LED] set rainbow color");
break;
}
}
/*
dev_mode_set_dac
(1)0x3000FF9000
-func: DAC initialization
(2)0x3000FF9001ccvvvv
-func: set DAC_CH0 & DAC_CH1 DAC codes, and output voltage
-cc: channel 00h-02h
00h = DAC_CH0
01h = DAC_CH1
02h = DAC_CH0|DAC_CH1
-vvvv: DAC code 0000h-FFFFh
*/
static void dev_mode_set_dac(uint8_t *ins, uint16_t size)
{
#define DAC_ITEM_INIT_DAC 0x00
#define DAC_ITEM_WRITE_THROUGH 0x01
uint8_t dac_item = ins[4];
switch (dac_item)
{
case DAC_ITEM_INIT_DAC:
dac_init();
break;
case DAC_ITEM_WRITE_THROUGH: {
uint8_t channel_idx = ins[5];
uint16_t dac_code = __REVSH(*(uint16_t *)&ins[6]);
int32_t mv = dac_code * 2440 / 65536;
if (channel_idx == 0x00)
{
dac_write_through(DAC_CH0, dac_code);
NRF_LOG_INFO("[DAC_CH0] set 0x%04X, about %d mV", dac_code, mv);
}
else if (channel_idx == 0x01)
{
dac_write_through(DAC_CH1, dac_code);
NRF_LOG_INFO("[DAC_CH1] set 0x%04X, about %d mV", dac_code, mv);
}
else if (channel_idx == 0x02)
{
dac_write_through(DAC_CH0 | DAC_CH1, dac_code);
NRF_LOG_INFO("[DAC_CH0] set 0x%04X, about %d mV", dac_code, mv);
NRF_LOG_INFO("[DAC_CH1] set 0x%04X, about %d mV", dac_code, mv);
}
break;
}
}
}
/*
dev_mode_set_adc
(1)0x3000FF9100
-func: ADC initialization
(2)0x3000FF9101gg
-func: set ADC input range gain
-gg: RANGE_SEL 00h-08h
00h = NP_GAIN_3P000
01h = NP_GAIN_2P500
02h = NP_GAIN_1P500
03h = NP_GAIN_1P250
04h = NP_GAIN_0P625
05h = P_GAIN_3P000
06h = P_GAIN_2P500
07h = P_GAIN_1P500
08h = P_GAIN_1P250
(3)0x3000FF9102cc
-func: read the ADC value of a specific channel
00h = S1(AIN0) = Iin
01h = S2(AIN1) = Vin
02h = S3(AIN2) = Vout_in
03h = S4(AIN3)
04h = S5(AIN4)
05h = S6(AIN5)
06h = S7(AIN6)
07h = S8(AIN7)
-FFF1 read
gatt[0] channel
gatt[1] range_sel
gatt[2:5] 18bit_adc_val
*/
static void dev_mode_set_adc(uint8_t *ins, uint16_t size)
{
#define ADC_ITEM_INIT_ADC 0x00
#define ADC_ITEM_SET_ADC_GAIN 0x01
#define ADC_ITEM_READ_ADC_VAL 0x02
uint8_t adc_item = ins[4];
switch (adc_item)
{
case ADC_ITEM_INIT_ADC:
adc_init();
break;
case ADC_ITEM_SET_ADC_GAIN: {
uint8_t range_sel = ins[5];
char *color_str[5] = { "NP_GAIN_3P000", "NP_GAIN_2P500", "NP_GAIN_1P500", "NP_GAIN_1P250", "NP_GAIN_0P625" };
switch (range_sel)
{
case 0x00:
adc_gain(GAIN_3P000);
NRF_LOG_INFO("[ADC] set range_sel(%s)", color_str[range_sel]);
break;
case 0x01:
adc_gain(GAIN_2P500);
NRF_LOG_INFO("[ADC] set range_sel(%s)", color_str[range_sel]);
break;
case 0x02:
adc_gain(GAIN_1P500);
NRF_LOG_INFO("[ADC] set range_sel(%s)", color_str[range_sel]);
break;
case 0x03:
adc_gain(GAIN_1P250);
NRF_LOG_INFO("[ADC] set range_sel(%s)", color_str[range_sel]);
break;
case 0x04:
adc_gain(GAIN_0P625);
NRF_LOG_INFO("[ADC] set range_sel(%s)", color_str[range_sel]);
break;
default:
break;
}
break;
}
case ADC_ITEM_READ_ADC_VAL: {
int32_t val;
uint32_t channel = ins[5];
adc_read(channel, &val);
break;
}
}
}
/*
dev_mode_set_switch
(1)0x3000FF9200
-func: switch initialization
(2)0x3000FF9201oott
-func: set two switch
-oo: one switch(U12) config 00h-0Fh
00000000b = all open
00000001b = U12 S1 close(conductivity)
00000011b = U12 S2&S1 close(conductivity)
00000111b = U12 S3&S2&S1 close(conductivity)
00001111b = U12 S4&S3&S2&S1 close(conductivity)
-tt: two switch(U13) config 00h-0Fh
00000000b = all open
00000001b = U13 S1 close(conductivity)
00000011b = U13 S2&S1 close(conductivity)
00000111b = U13 S3&S2&S1 close(conductivity)
00001111b = U13 S4&S3&S2&S1 close(conductivity)
(3)0x3000FF9204gg
-func: out_1 gain config
-gg: out_1 resistance idx 00h-02h
00h = gain0, the smallest voltage output (15K)
01h = gain1 (39K)
02h = gain2, the largest voltage output (100K)
*/
static void dev_mode_set_switch(uint8_t *ins, uint16_t size)
{
#define SW_ITEM_INIT_SW 0x00
#define SW_ITEM_WRITE_SW 0x01
#define SW_ITEM_SET_OUT_1_GAIN 0x04
uint8_t sw_item = ins[4];
switch (sw_item)
{
case SW_ITEM_INIT_SW:
sw_init();
break;
case SW_ITEM_WRITE_SW: {
sw_t sw;
uint32_t sw_cnt;
sw_count(&sw_cnt);
sw_read(&sw);
sw.val = (uint64_t)ins[6] << 4 | (uint64_t)ins[5];
NRF_LOG_INFO("sw.val= %08X", sw.val);
NRF_LOG_INFO("sw.sw7~sw4=%X %X %X %X", sw.sw7, sw.sw6, sw.sw5, sw.sw4);
NRF_LOG_INFO("sw.sw3~sw0=%X %X %X %X", sw.sw3, sw.sw2, sw.sw1, sw.sw0);
sw_write(sw);
break;
}
case SW_ITEM_SET_OUT_1_GAIN: {
uint8_t out_1_gain = ins[5];
sw_t sw;
uint32_t sw_cnt;
sw_count(&sw_cnt);
sw_read(&sw);
if (out_1_gain == 0x00)
{
sw.sw0 = 0;
sw.sw1 = 0;
sw.sw2 = 1;
sw.sw3 = 0;
}
if (out_1_gain == 0x01)
{
sw.sw0 = 0;
sw.sw1 = 0;
sw.sw2 = 0;
sw.sw3 = 1;
}
if (out_1_gain == 0x02)
{
sw.sw0 = 0;
sw.sw1 = 0;
sw.sw2 = 0;
sw.sw3 = 0;
}
NRF_LOG_INFO("sw.val= %08X", sw.val);
NRF_LOG_INFO("sw.sw7~sw4=%X %X %X %X", sw.sw7, sw.sw6, sw.sw5, sw.sw4);
NRF_LOG_INFO("sw.sw3~sw0=%X %X %X %X", sw.sw3, sw.sw2, sw.sw1, sw.sw0);
sw_write(sw);
break;
}
}
}
static void dev_mode_read_output_pin(void)
{
struct pin_out_t
{
uint32_t resvd : 11,
power_5v_en : 1,
power_12v_en : 1,
off : 1,
vout_fb : 1,
vout_in : 1,
iin4_test : 1,
iin3_sel : 1,
iin3 : 1,
iin2 : 1,
iin1 : 1,
vin2 : 1,
vin1 : 1,
cv_ctrl : 1,
adc_a2 : 1,
adc_a1 : 1,
adc_a0 : 1,
rst_sw : 1,
cs_sw : 1,
cs_mem : 1,
cs_adc : 1,
cs_dac : 1;
} output;
uint32_t pin_out_status;
output.power_5v_en = nrf_gpio_pin_out_read(POWER_5V_EN_PIN);
output.power_12v_en = nrf_gpio_pin_out_read(POWER_12V_EN_PIN);
output.off = nrf_gpio_pin_out_read(OFF_PIN);
output.vout_fb = nrf_gpio_pin_out_read(Vout_FB_PIN);
output.vout_in = nrf_gpio_pin_out_read(Vout_IN_PIN);
output.iin4_test = nrf_gpio_pin_out_read(Iin4_TEST_PIN);
output.iin3_sel = nrf_gpio_pin_out_read(Iin3_SEL_PIN);
output.iin3 = nrf_gpio_pin_out_read(Iin3_PIN);
output.iin2 = nrf_gpio_pin_out_read(Iin2_PIN);
output.iin1 = nrf_gpio_pin_out_read(Iin1_PIN);
output.vin2 = nrf_gpio_pin_out_read(Vin2_PIN);
output.vin1 = nrf_gpio_pin_out_read(Vin1_PIN);
output.cv_ctrl = nrf_gpio_pin_out_read(CV_CTRL_PIN);
output.adc_a2 = nrf_gpio_pin_out_read(ADCA2_PIN);
output.adc_a1 = nrf_gpio_pin_out_read(ADCA1_PIN);
output.adc_a0 = nrf_gpio_pin_out_read(ADCA0_PIN);
output.rst_sw = nrf_gpio_pin_out_read(RST_SW_PIN);
output.cs_sw = nrf_gpio_pin_out_read(CS_SW_PIN);
output.cs_mem = nrf_gpio_pin_out_read(CS_MEM_PIN);
output.cs_adc = nrf_gpio_pin_out_read(CS_ADC_PIN);
output.cs_dac = nrf_gpio_pin_out_read(CS_DAC_PIN);
pin_out_status = (output.resvd << 21) |
(output.power_5v_en << 20) |
(output.power_12v_en << 19) |
(output.off << 18) |
(output.vout_fb << 17) |
(output.vout_in << 16) |
(output.iin4_test << 15) |
(output.iin3_sel << 14) |
(output.iin3 << 13) |
(output.iin2 << 12) |
(output.iin1 << 11) |
(output.vin2 << 10) |
(output.vin1 << 9) |
(output.cv_ctrl << 8) |
(output.adc_a2 << 7) |
(output.adc_a1 << 6) |
(output.adc_a0 << 5) |
(output.rst_sw << 4) |
(output.cs_sw << 3) |
(output.cs_mem << 2) |
(output.cs_adc << 1) |
output.cs_dac;
le_event_update((uint8_t *)&pin_out_status, sizeof(pin_out_status));
NRF_LOG_INFO("pin_out_status = 0x%08X", pin_out_status);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[31:21] resvd", output.resvd);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[20] power_5v_en", output.power_5v_en);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[19] power_12v_en", output.power_12v_en);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[18] off", output.off);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[17] vout_fb", output.vout_fb);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[16] vout_in", output.vout_in);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[15] iin4_test", output.iin4_test);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[14] iin3_sel", output.iin3_sel);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[13] iin3", output.iin3);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[12] iin2", output.iin2);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[11] iin1", output.iin1);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[10] vin2", output.vin2);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[9] vin1", output.vin1);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[8] cv_ctrl", output.cv_ctrl);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[7] adc_a2", output.adc_a2);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[6] adc_a1", output.adc_a1);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[5] adc_a0", output.adc_a0);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[4] rst_sw", output.rst_sw);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[3] cs_sw", output.cs_sw);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[2] cs_mem", output.cs_mem);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[1] cs_adc", output.cs_adc);
NRF_LOG_INFO("| %-32s | %d |", "pin_out_status[0] cs_dac", output.cs_dac);
}
static void dev_mode_read_input_pin(void)
{
struct pin_input_t
{
uint32_t resvd : 29,
vbat : 1,
shut_down : 1,
int9466 : 1;
} input;
uint32_t pin_input_status;
input.vbat = nrf_gpio_pin_read(VBAT_PIN);
input.shut_down = nrf_gpio_pin_read(SHUT_DOWN_PIN);
input.int9466 = nrf_gpio_pin_read(INT9466_PIN);
pin_input_status = (input.resvd << 3) |
(input.vbat << 2) |
(input.shut_down << 1) |
input.int9466;
le_event_update((uint8_t *)&pin_input_status, sizeof(pin_input_status));
NRF_LOG_INFO("pin_input_status = 0x%08X", pin_input_status);
NRF_LOG_INFO("| %-32s | %d |", "pin_input_status[31:3] resvd", input.resvd);
NRF_LOG_INFO("| %-32s | %d |", "pin_input_status[2] vbat", input.vbat);
NRF_LOG_INFO("| %-32s | %d |", "pin_input_status[1] shut_down", input.shut_down);
NRF_LOG_INFO("| %-32s | %d |", "pin_input_status[0] int9466", input.int9466);
}
/*
dev_mode_set_gpio_output_high_low
(1)0x3000FFA0ppnnss
-func: control GPIO high/low
-ppnn: pin number 0000h-0031h, 0100h-0115h (0017h represents GPIO P0.17)
-ss: high/low 00h-01h
*/
static void dev_mode_set_gpio_output_high_low(uint8_t *ins, uint16_t size)
{
uint16_t user_pin_number = __REVSH(*(uint16_t *)&ins[4]);
uint8_t pin_signal = ins[6];
uint32_t pin;
switch (user_pin_number)
{
case 0x0015:
pin = OFF_PIN;
break;
case 0x0020: // special pin for BMD380 EVK
pin = CS_SW_PIN;
break;
case 0x0008:
pin = CS_MEM_PIN;
break;
case 0x0006:
pin = CS_ADC_PIN;
break;
case 0x0005:
pin = CS_DAC_PIN;
break;
case 0x0025:
pin = ADCA2_PIN;
break;
case 0x0019: // special pin for BMD380 EVK
pin = ADCA1_PIN;
break;
case 0x0021: // special pin for BMD380 EVK
pin = ADCA0_PIN;
break;
case 0x0017: // special pin for BMD380 EVK
pin = RST_SW_PIN;
break;
case 0x0026:
pin = Vout_FB_PIN;
break;
case 0x0004:
pin = Vout_IN_PIN;
break;
case 0x0112:
pin = Iin4_TEST_PIN;
break;
case 0x0114:
pin = Iin3_SEL_PIN;
break;
case 0x0113:
pin = Iin3_PIN;
break;
case 0x0103:
pin = Iin2_PIN;
break;
case 0x0110:
pin = Iin1_PIN;
break;
case 0x0106:
pin = Vin2_PIN;
break;
case 0x0111:
pin = Vin1_PIN;
break;
case 0x0016:
pin = CV_CTRL_PIN;
break;
default:
NRF_LOG_INFO("[GPIO] wrong pin number");
return;
break;
}
if (pin_signal == 0)
{
nrf_gpio_pin_clear(pin);
NRF_LOG_INFO("[GPIO] P%X.%02X(%d)", user_pin_number >> 8, user_pin_number & 0x00FF, pin_signal);
}
else if (pin_signal == 1)
{
nrf_gpio_pin_set(pin);
NRF_LOG_INFO("[GPIO] P%X.%02X(%d)", user_pin_number >> 8, user_pin_number & 0x00FF, pin_signal);
}
else
{
NRF_LOG_INFO("[GPIO] pin_signal must be high/low");
}
}
/*
dev_mode_spi1_transfer
(1)0x3000FFA1ssttrrcccccccc
-func: control spi1
-ss: chip selector 00h(EDC2.0 SPI1 does not use the CS pin)
-tt: MOSI data length 00h-FFh
-rr: MISO data length 00h(EDC2.0 SPI1 does not use the MISO pin)
-cccccccc: MOSI content
example to control led:
FFF2 write: 3000FFA100040000000000
3000FFA1000400E100FF00 * 12 times
3000FFA1000400FFFFFFFF
*/
static void dev_mode_spi1_transfer(uint8_t *ins, uint16_t size)
{
uint8_t chip_seletor = ins[4];
uint8_t mosi_data_len = ins[5];
uint8_t miso_data_len = ins[6];
uint8_t *mosi_data = &ins[7];
switch (chip_seletor)
{
case 0x00:
spi1_write(mosi_data, mosi_data_len);
break;
default:
NRF_LOG_INFO("[SPI(1)] wrong module chip seletor");
return;
break;
}
}
/*
dev_mode_spi2_transfer
(1)0x3000FFA2ssttrrcccccccc
-func: control spi2
-ss: chip selector 00h-03h
00h = CS_SW
01h = CS_MEM
02h = CS_ADC
03h = CS_DAC
-tt: MOSI data length 00h-FFh
-rr: MISO data length 00h-FFh
-cccccccc: MOSI content
*/
static void dev_mode_spi2_transfer(uint8_t *ins, uint16_t size)
{
uint8_t chip_seletor = ins[4];
uint8_t mosi_data_len = ins[5];
uint8_t miso_data_len = ins[6];
uint8_t *mosi_data = &ins[7];
uint8_t miso_data[255];
switch (chip_seletor)
{
case 0x00:
spim_xfer(CS_SW_PIN, NRF_SPIM_MODE_0, mosi_data, mosi_data_len, miso_data, miso_data_len);
break;
case 0x01:
spim_xfer(CS_MEM_PIN, NRF_SPIM_MODE_0, mosi_data, mosi_data_len, miso_data, miso_data_len);
break;
case 0x02:
spim_xfer(CS_ADC_PIN, NRF_SPIM_MODE_0, mosi_data, mosi_data_len, miso_data, miso_data_len);
break;
case 0x03:
spim_xfer(CS_DAC_PIN, NRF_SPIM_MODE_2, mosi_data, mosi_data_len, miso_data, miso_data_len);
break;
default:
NRF_LOG_INFO("[SPI(2)] wrong module chip seletor");
return;
break;
}
if (miso_data_len > 0)
{
le_event_update(miso_data, miso_data_len);
}
}
/*
dev_mode_circuit_selection
(1)0x3000FFB1ss
-func: set circuit selection
-ss: Iin, Vin, DAC, CC, CV3 selection 00h-0Dh
00h = vin_0 gain
01h = vin_1 gain
02h = vin_2 gain
03h = Iin_0 gain
04h = Iin_1 gain
05h = Iin_2 gain
06h = Iin_3 gain
07h = Iin_4 gain
08h = dac_coarse_tune_c (only calibration will use it)
09h = dac_fune_tune_f0
0Ah = dac_fune_tune_f1
0Bh = dac_fune_tune_f2
0Ch = cv3_config
0Dh = cc_config
*/
static void dev_mode_circuit_selection(uint8_t *ins, uint16_t size)
{
uint8_t circuit_select = ins[4];
switch (circuit_select)
{
case 0x00:
circuit_selection_vin_0();
break;
case 0x01:
circuit_selection_vin_1();
break;
case 0x02:
circuit_selection_vin_2();
break;
case 0x03:
circuit_selection_Iin_0();
break;
case 0x04:
circuit_selection_Iin_1();
break;
case 0x05:
circuit_selection_Iin_2();
break;
case 0x06:
circuit_selection_Iin_3();
break;
case 0x07:
circuit_selection_Iin_4();
break;
case 0x08:
circuit_selection_dac_coarse_tune_c();
break;
case 0x09:
circuit_selection_dac_fine_tune_f0();
break;
case 0x0A:
circuit_selection_dac_fine_tune_f1();
break;
case 0x0B:
circuit_selection_dac_fine_tune_f2();
break;
case 0x0C:
circuit_selection_cv3_config();
break;
case 0x0D:
circuit_selection_cc_config();
break;
}
}
static void dev_mode(uint8_t *ins, uint16_t size)
{
uint32_t dev_mode_func = __REV(*(uint32_t *)ins) & 0xF000FFFF;
switch (dev_mode_func)
{
case 0x3000FF01:
NRF_LOG_INFO("return_software_version() is unimplemented.");
break;
case 0x3000FF02:
NRF_LOG_INFO("return_battery_volt() is unimplemented.");
break;
case 0x3000FF03:
NRF_LOG_INFO("return_temperature() is unimplemented.");
break;
case 0x3000FF04:
dev_mode_set_led(ins, size);
break;
case 0x3000FF90:
dev_mode_set_dac(ins, size);
break;
case 0x3000FF91:
dev_mode_set_adc(ins, size);
break;
case 0x3000FF92:
dev_mode_set_switch(ins, size);
break;
case 0x3000FF9E:
dev_mode_read_output_pin();
break;
case 0x3000FF9F:
dev_mode_read_input_pin();
break;
case 0x3000FFA0:
dev_mode_set_gpio_output_high_low(ins, size);
break;
case 0x3000FFA1:
dev_mode_spi1_transfer(ins, size);
break;
case 0x3000FFA2:
dev_mode_spi2_transfer(ins, size);
break;
case 0x3000FFA3:
// i2c0
break;
case 0x3000FFB1:
dev_mode_circuit_selection(ins, size);
break;
default:
NRF_LOG_INFO("unknown dev_mode instruction");
break;
}
}
static void cis_version(uint8_t *ins, uint16_t size)
{
NRF_LOG_INFO("%s", __FUNCTION__);
struct
{
uint8_t opcode;
uint8_t year;
uint8_t mon;
uint8_t day;
uint8_t hh;
uint8_t mm;
} __PACKED cis_ver = {
.opcode = CIS_VERSION,
.year = 24,
.mon = 5,
.day = 21,
.hh = 22,
.mm = 40,
};
extern ret_code_t le_data_update(uint8_t * p_value, uint16_t len);
le_data_update((void *)&cis_ver, sizeof(cis_ver));
}
__WEAK uint16_t bat_volt_read(void)
{
static uint16_t bat_volt = 3936;
bat_volt--;
return bat_volt;
}
static void cis_volt(uint8_t *ins, uint16_t size)
{
NRF_LOG_INFO("%s", __FUNCTION__);
struct
{
uint8_t opcode;
uint16_t volt;
} __PACKED cis_volt = {
.opcode = CIS_VOLT,
.volt = bat_volt_read(),
};
extern ret_code_t le_data_update(uint8_t * p_value, uint16_t len);
le_data_update((void *)&cis_volt, sizeof(cis_volt));
}
__WEAK uint16_t temperature_read(void)
{
static uint16_t bat_volt = 3936;
bat_volt--;
return bat_volt;
}
static void cis_temperature(uint8_t *ins, uint16_t size)
{
NRF_LOG_INFO("%s", __FUNCTION__);
struct
{
uint8_t opcode;
uint32_t temperature;
} __PACKED cis_temperature = {
.opcode = CIS_TEMPERATURE,
.temperature = __REV(temperature_read()),
};
extern ret_code_t le_data_update(uint8_t * p_value, uint16_t len);
le_data_update((void *)&cis_temperature, sizeof(cis_temperature));
}
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__);
edc.instru.eliteFxn = VIS_RST;
edc.instru.VinADCGainLv = VIN_GAIN_1K;
VinADCGainCtrl(edc.instru.VinADCGainLv);
edc.instru.IinADCGainLv = I_GAIN_100R;
IinADCGainCtrl(edc.instru.IinADCGainLv);
edc.instru.VoutGainLv = VOUT_GAIN_15K;
VoutGainControl(edc.instru.VoutGainLv);
uint16_t volt = Usercode_Correction_to_DAC(edc.instru.VoutGainLv, 25000);
dac_write_through(DAC0, volt);
led_mode(NO_EVENT);
}
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__);
led_set(LED_IDENTICY_DEV);
}
static void vis_shiny_dis(uint8_t *ins, uint16_t size)
{
NRF_LOG_INFO("%s", __FUNCTION__);
led_set(LED_IDEL_CONNECTED);
}
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__);
extern void edc20_cycle_iv_mode_start(uint8_t * ins, uint16_t size);
edc20_cycle_iv_mode_start(ins, size);
}
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 edc20_elite_instance = {
.cis_func = {
[CIS_VERSION] = cis_version,
[CIS_VOLT] = cis_volt,
[CIS_TEMPERATURE] = cis_temperature,
[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,
[DEV_MODE] = dev_mode,
}
};
static void init(void)
{
dac_init();
adc_gain(GAIN_3P000);
circuit_selection_dac_fine_tune_f2();
}
edc20_t edc = {
.init = init,
.p_elite_instance = &edc20_elite_instance,
};
#endif /* ! DEF_ELITE_MODEL */