723 lines
22 KiB
C
723 lines
22 KiB
C
#include "cpg10_dev_mode.h"
|
|
#include "tw1508.h"
|
|
|
|
#include "nrf_gpio.h"
|
|
#include "nrf_log.h"
|
|
|
|
#if (DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_10 || \
|
|
DEF_ELITE_MODEL == DEF_CURRENT_PULSE_GANERATOR_11)
|
|
|
|
// The GPIO corresponding to the pin
|
|
const uint32_t pin_to_gpio_table[] = {
|
|
[6] = NRF_GPIO_PIN_MAP(0, 22),
|
|
[8] = NRF_GPIO_PIN_MAP(0, 25),
|
|
[9] = NRF_GPIO_PIN_MAP(0, 19),
|
|
[10] = NRF_GPIO_PIN_MAP(0, 21),
|
|
[11] = NRF_GPIO_PIN_MAP(1, 00),
|
|
[12] = NRF_GPIO_PIN_MAP(0, 18),
|
|
[13] = NRF_GPIO_PIN_MAP(0, 17),
|
|
[14] = NRF_GPIO_PIN_MAP(0, 20),
|
|
[16] = NRF_GPIO_PIN_MAP(0, 14),
|
|
[17] = NRF_GPIO_PIN_MAP(0, 13),
|
|
[18] = NRF_GPIO_PIN_MAP(0, 11),
|
|
[20] = NRF_GPIO_PIN_MAP(0, 15),
|
|
[25] = NRF_GPIO_PIN_MAP(1, 8),
|
|
[26] = NRF_GPIO_PIN_MAP(0, 12),
|
|
[27] = NRF_GPIO_PIN_MAP(0, 7),
|
|
[28] = NRF_GPIO_PIN_MAP(1, 9),
|
|
[29] = NRF_GPIO_PIN_MAP(0, 8),
|
|
[30] = NRF_GPIO_PIN_MAP(0, 6),
|
|
[31] = NRF_GPIO_PIN_MAP(0, 5),
|
|
[32] = NRF_GPIO_PIN_MAP(0, 27),
|
|
[33] = NRF_GPIO_PIN_MAP(0, 26),
|
|
[34] = NRF_GPIO_PIN_MAP(0, 4),
|
|
[36] = NRF_GPIO_PIN_MAP(0, 1),
|
|
[37] = NRF_GPIO_PIN_MAP(0, 29),
|
|
[38] = NRF_GPIO_PIN_MAP(0, 0),
|
|
[39] = NRF_GPIO_PIN_MAP(0, 31),
|
|
[40] = NRF_GPIO_PIN_MAP(1, 15),
|
|
[41] = NRF_GPIO_PIN_MAP(0, 2),
|
|
[42] = NRF_GPIO_PIN_MAP(0, 30),
|
|
[43] = NRF_GPIO_PIN_MAP(0, 28),
|
|
[44] = NRF_GPIO_PIN_MAP(1, 12),
|
|
[45] = NRF_GPIO_PIN_MAP(1, 14),
|
|
[46] = NRF_GPIO_PIN_MAP(0, 3),
|
|
[47] = NRF_GPIO_PIN_MAP(1, 13),
|
|
[48] = NRF_GPIO_PIN_MAP(1, 3),
|
|
[49] = NRF_GPIO_PIN_MAP(1, 10),
|
|
[50] = NRF_GPIO_PIN_MAP(1, 6),
|
|
[51] = NRF_GPIO_PIN_MAP(1, 11),
|
|
[52] = NRF_GPIO_PIN_MAP(0, 10),
|
|
[53] = NRF_GPIO_PIN_MAP(0, 9),
|
|
[59] = NRF_GPIO_PIN_MAP(1, 2),
|
|
[60] = NRF_GPIO_PIN_MAP(0, 24),
|
|
[61] = NRF_GPIO_PIN_MAP(0, 23),
|
|
[62] = NRF_GPIO_PIN_MAP(0, 16),
|
|
};
|
|
|
|
static pusle_gen_t dev_mode_pusle_gen[2] = {
|
|
{
|
|
.VBxH = VB1H_PIN,
|
|
.VBxL = VB1L_PIN,
|
|
.VAxH = VA1H_PIN,
|
|
.VAxL = VA1L_PIN,
|
|
.idle_us = 1000,
|
|
.point_us[0] = 1,
|
|
.point_us[1] = 250,
|
|
.point_us[2] = 1,
|
|
.point_us[3] = 0,
|
|
.point_us[4] = 1,
|
|
.point_us[5] = 250,
|
|
.point_us[6] = 1,
|
|
.pulse_cnt = 0,
|
|
.op_mode = 0,
|
|
},
|
|
{
|
|
.VBxH = VB2H_PIN,
|
|
.VBxL = VB2L_PIN,
|
|
.VAxH = VA2H_PIN,
|
|
.VAxL = VA2L_PIN,
|
|
.idle_us = 1000,
|
|
.point_us[0] = 1,
|
|
.point_us[1] = 250,
|
|
.point_us[2] = 1,
|
|
.point_us[3] = 0,
|
|
.point_us[4] = 1,
|
|
.point_us[5] = 250,
|
|
.point_us[6] = 1,
|
|
.pulse_cnt = 0xFFFFFFFF,
|
|
.op_mode = 1,
|
|
}
|
|
};
|
|
|
|
static uint32_t bmd380pins_convert_to_gpio(uint32_t pin)
|
|
{
|
|
uint32_t gpio;
|
|
|
|
switch (pin)
|
|
{
|
|
case 6:
|
|
case 8:
|
|
case 9:
|
|
case 10:
|
|
case 11:
|
|
case 12:
|
|
case 13:
|
|
case 14:
|
|
case 16:
|
|
case 17:
|
|
case 18:
|
|
case 20:
|
|
case 25:
|
|
case 26:
|
|
case 27:
|
|
case 28:
|
|
case 29:
|
|
case 30:
|
|
case 31:
|
|
case 32:
|
|
case 33:
|
|
case 34:
|
|
case 36:
|
|
case 37:
|
|
case 38:
|
|
case 39:
|
|
case 40:
|
|
case 41:
|
|
case 42:
|
|
case 43:
|
|
case 44:
|
|
case 45:
|
|
case 46:
|
|
case 47:
|
|
case 48:
|
|
case 49:
|
|
case 50:
|
|
case 51:
|
|
case 52:
|
|
case 53:
|
|
case 59:
|
|
case 60:
|
|
case 61:
|
|
case 62:
|
|
gpio = pin_to_gpio_table[pin];
|
|
break;
|
|
default:
|
|
gpio = UNDEF_GPIO;
|
|
NRF_LOG_INFO("UNDEF_GPIO: pin %d can't convert to gpio number", pin);
|
|
break;
|
|
}
|
|
|
|
return gpio;
|
|
}
|
|
|
|
static void set_bmd380_pin_signal(uint32_t pin, uint32_t high_low)
|
|
{
|
|
uint32_t gpio = bmd380pins_convert_to_gpio(pin);
|
|
|
|
if (gpio != UNDEF_GPIO)
|
|
{
|
|
nrf_gpio_pin_write(gpio, high_low);
|
|
NRF_LOG_INFO("set pin %02d (gpio %02d) = %d", pin, gpio, high_low);
|
|
}
|
|
}
|
|
|
|
#define ELECTRODES_A1HB1L 1
|
|
#define ELECTRODES_A1LB1H 2
|
|
#define ELECTRODES_A2HB2L 3
|
|
#define ELECTRODES_A2LB2H 4
|
|
#define ELECTRODES_A3HB3L 5
|
|
#define ELECTRODES_A3LB3H 6
|
|
#define ELECTRODES_A4HB4L 7
|
|
#define ELECTRODES_A4LB4H 8
|
|
#define ELECTRODE_A1B1_IDLE 9
|
|
#define ELECTRODE_A2B2_IDLE 10
|
|
#define ELECTRODE_A3B3_IDLE 11
|
|
#define ELECTRODE_A4B4_IDLE 12
|
|
#define ELECTRODE_ALL_HIGHZ 13
|
|
static void cpg10_electrodes(uint32_t electrodes_mode)
|
|
{
|
|
switch (electrodes_mode)
|
|
{
|
|
case ELECTRODES_A1HB1L:
|
|
NRF_LOG_INFO("ELECTRODES_A1HB1L()");
|
|
nrf_gpio_pin_write(VA1H_PIN, 1);
|
|
nrf_gpio_pin_write(VB1L_PIN, 1);
|
|
nrf_gpio_pin_write(VB1H_PIN, 0);
|
|
nrf_gpio_pin_write(VA1L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODES_A1LB1H:
|
|
NRF_LOG_INFO("ELECTRODES_A1LB1H()");
|
|
nrf_gpio_pin_write(VB1H_PIN, 1);
|
|
nrf_gpio_pin_write(VA1L_PIN, 1);
|
|
nrf_gpio_pin_write(VA1H_PIN, 0);
|
|
nrf_gpio_pin_write(VB1L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODES_A2HB2L:
|
|
NRF_LOG_INFO("ELECTRODES_A2HB2L()");
|
|
nrf_gpio_pin_write(VA2H_PIN, 1);
|
|
nrf_gpio_pin_write(VB2L_PIN, 1);
|
|
nrf_gpio_pin_write(VB2H_PIN, 0);
|
|
nrf_gpio_pin_write(VA2L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODES_A2LB2H:
|
|
NRF_LOG_INFO("ELECTRODES_A2LB2H()");
|
|
nrf_gpio_pin_write(VB2H_PIN, 1);
|
|
nrf_gpio_pin_write(VA2L_PIN, 1);
|
|
nrf_gpio_pin_write(VA2H_PIN, 0);
|
|
nrf_gpio_pin_write(VB2L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODES_A3HB3L:
|
|
NRF_LOG_INFO("ELECTRODES_A3HB3L()");
|
|
nrf_gpio_pin_write(VA3H_PIN, 1);
|
|
nrf_gpio_pin_write(VB3L_PIN, 1);
|
|
nrf_gpio_pin_write(VB3H_PIN, 0);
|
|
nrf_gpio_pin_write(VA3L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODES_A3LB3H:
|
|
NRF_LOG_INFO("ELECTRODES_A3LB3H()");
|
|
nrf_gpio_pin_write(VB3H_PIN, 1);
|
|
nrf_gpio_pin_write(VA3L_PIN, 1);
|
|
nrf_gpio_pin_write(VA3H_PIN, 0);
|
|
nrf_gpio_pin_write(VB3L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODES_A4HB4L:
|
|
NRF_LOG_INFO("ELECTRODES_A4HB4L()");
|
|
nrf_gpio_pin_write(VA4H_PIN, 1);
|
|
nrf_gpio_pin_write(VB4L_PIN, 1);
|
|
nrf_gpio_pin_write(VB4H_PIN, 0);
|
|
nrf_gpio_pin_write(VA4L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODES_A4LB4H:
|
|
NRF_LOG_INFO("ELECTRODES_A4LB4H()");
|
|
nrf_gpio_pin_write(VB4H_PIN, 1);
|
|
nrf_gpio_pin_write(VA4L_PIN, 1);
|
|
nrf_gpio_pin_write(VA4H_PIN, 0);
|
|
nrf_gpio_pin_write(VB4L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODE_A1B1_IDLE:
|
|
NRF_LOG_INFO("ELECTRODE_A1B1_IDLE()");
|
|
nrf_gpio_pin_write(VA1H_PIN, 1);
|
|
nrf_gpio_pin_write(VB1L_PIN, 0);
|
|
nrf_gpio_pin_write(VB1H_PIN, 1);
|
|
nrf_gpio_pin_write(VA1L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODE_A2B2_IDLE:
|
|
NRF_LOG_INFO("ELECTRODE_A2B2_IDLE()");
|
|
nrf_gpio_pin_write(VA2H_PIN, 1);
|
|
nrf_gpio_pin_write(VB2L_PIN, 0);
|
|
nrf_gpio_pin_write(VB2H_PIN, 1);
|
|
nrf_gpio_pin_write(VA2L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODE_A3B3_IDLE:
|
|
NRF_LOG_INFO("ELECTRODE_A3B3_IDLE()");
|
|
nrf_gpio_pin_write(VA3H_PIN, 1);
|
|
nrf_gpio_pin_write(VB3L_PIN, 0);
|
|
nrf_gpio_pin_write(VB3H_PIN, 1);
|
|
nrf_gpio_pin_write(VA3L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODE_A4B4_IDLE:
|
|
NRF_LOG_INFO("ELECTRODE_A4B4_IDLE()");
|
|
nrf_gpio_pin_write(VA4H_PIN, 1);
|
|
nrf_gpio_pin_write(VB4L_PIN, 0);
|
|
nrf_gpio_pin_write(VB4H_PIN, 1);
|
|
nrf_gpio_pin_write(VA4L_PIN, 0);
|
|
break;
|
|
|
|
case ELECTRODE_ALL_HIGHZ:
|
|
NRF_LOG_INFO("ELECTRODE_ALL_HIGHZ()");
|
|
nrf_gpio_pin_write(VA1H_PIN, 0);
|
|
nrf_gpio_pin_write(VB1L_PIN, 0);
|
|
nrf_gpio_pin_write(VB1H_PIN, 0);
|
|
nrf_gpio_pin_write(VA1L_PIN, 0);
|
|
|
|
nrf_gpio_pin_write(VA2H_PIN, 0);
|
|
nrf_gpio_pin_write(VB2L_PIN, 0);
|
|
nrf_gpio_pin_write(VB2H_PIN, 0);
|
|
nrf_gpio_pin_write(VA2L_PIN, 0);
|
|
|
|
nrf_gpio_pin_write(VA3H_PIN, 0);
|
|
nrf_gpio_pin_write(VB3L_PIN, 0);
|
|
nrf_gpio_pin_write(VB3H_PIN, 0);
|
|
nrf_gpio_pin_write(VA3L_PIN, 0);
|
|
|
|
nrf_gpio_pin_write(VA4H_PIN, 0);
|
|
nrf_gpio_pin_write(VB4L_PIN, 0);
|
|
nrf_gpio_pin_write(VB4H_PIN, 0);
|
|
nrf_gpio_pin_write(VA4L_PIN, 0);
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void electrodes_1_task(void *pArg)
|
|
{
|
|
NRF_LOG_INFO("[test] electrodes_1_task");
|
|
for (;;)
|
|
{
|
|
cpg10_electrodes(ELECTRODES_A1HB1L);
|
|
vTaskDelay(1);
|
|
cpg10_electrodes(ELECTRODES_A1LB1H);
|
|
vTaskDelay(1);
|
|
cpg10_electrodes(ELECTRODE_A1B1_IDLE);
|
|
vTaskDelay(200);
|
|
}
|
|
}
|
|
|
|
static void electrodes_2_task(void *pArg)
|
|
{
|
|
NRF_LOG_INFO("[test] electrodes_2_task");
|
|
for (;;)
|
|
{
|
|
cpg10_electrodes(ELECTRODES_A2HB2L);
|
|
vTaskDelay(1);
|
|
cpg10_electrodes(ELECTRODES_A2LB2H);
|
|
vTaskDelay(1);
|
|
cpg10_electrodes(ELECTRODE_A2B2_IDLE);
|
|
vTaskDelay(200);
|
|
}
|
|
}
|
|
|
|
static void electrodes_3_task(void *pArg)
|
|
{
|
|
NRF_LOG_INFO("[test] electrodes_3_task");
|
|
for (;;)
|
|
{
|
|
cpg10_electrodes(ELECTRODES_A3HB3L);
|
|
vTaskDelay(1);
|
|
cpg10_electrodes(ELECTRODES_A3LB3H);
|
|
vTaskDelay(1);
|
|
cpg10_electrodes(ELECTRODE_A3B3_IDLE);
|
|
vTaskDelay(200);
|
|
}
|
|
}
|
|
|
|
static void electrodes_4_task(void *pArg)
|
|
{
|
|
NRF_LOG_INFO("[test] electrodes_4_task");
|
|
for (;;)
|
|
{
|
|
cpg10_electrodes(ELECTRODES_A4HB4L);
|
|
vTaskDelay(1);
|
|
cpg10_electrodes(ELECTRODES_A4LB4H);
|
|
vTaskDelay(1);
|
|
cpg10_electrodes(ELECTRODE_A4B4_IDLE);
|
|
vTaskDelay(200);
|
|
}
|
|
}
|
|
|
|
void setting_cpg_pulse_parameter(uint8_t *ins)
|
|
{
|
|
NRF_LOG_INFO("%s", __FUNCTION__);
|
|
uint8_t electrodes_num = ins[5];
|
|
uint32_t pulse_width_us = (uint32_t)ins[6] << 24 | (uint32_t)ins[7] << 16 | (uint32_t)ins[8] << 8 | (uint32_t)ins[9];
|
|
uint32_t freq_hz = (uint32_t)ins[10] << 24 | (uint32_t)ins[11] << 16 | (uint32_t)ins[12] << 8 | (uint32_t)ins[13];
|
|
|
|
if (electrodes_num == 1)
|
|
{
|
|
dev_mode_pusle_gen[0].point_us[1] = pulse_width_us;
|
|
dev_mode_pusle_gen[0].point_us[5] = pulse_width_us;
|
|
dev_mode_pusle_gen[0].idle_us = (1000000 / freq_hz) - (dev_mode_pusle_gen[0].point_us[0] + dev_mode_pusle_gen[0].point_us[1] + dev_mode_pusle_gen[0].point_us[2] + dev_mode_pusle_gen[0].point_us[3] + dev_mode_pusle_gen[0].point_us[4] + dev_mode_pusle_gen[0].point_us[5] + dev_mode_pusle_gen[0].point_us[6]);
|
|
NRF_LOG_INFO("[1]a = %d us", dev_mode_pusle_gen[0].point_us[0]);
|
|
NRF_LOG_INFO("[1]b = %d us", dev_mode_pusle_gen[0].point_us[1]);
|
|
NRF_LOG_INFO("[1]c = %d us", dev_mode_pusle_gen[0].point_us[2]);
|
|
NRF_LOG_INFO("[1]d = %d us", dev_mode_pusle_gen[0].point_us[3]);
|
|
NRF_LOG_INFO("[1]e = %d us", dev_mode_pusle_gen[0].point_us[4]);
|
|
NRF_LOG_INFO("[1]f = %d us", dev_mode_pusle_gen[0].point_us[5]);
|
|
NRF_LOG_INFO("[1]g = %d us", dev_mode_pusle_gen[0].point_us[6]);
|
|
NRF_LOG_INFO("[1]idle = %d us", dev_mode_pusle_gen[0].idle_us);
|
|
}
|
|
else if (electrodes_num == 2)
|
|
{
|
|
dev_mode_pusle_gen[1].point_us[1] = pulse_width_us;
|
|
dev_mode_pusle_gen[1].point_us[5] = pulse_width_us;
|
|
dev_mode_pusle_gen[1].idle_us = (1000000 / freq_hz) - (dev_mode_pusle_gen[1].point_us[0] + dev_mode_pusle_gen[1].point_us[1] + dev_mode_pusle_gen[1].point_us[2] + dev_mode_pusle_gen[1].point_us[3] + dev_mode_pusle_gen[1].point_us[4] + dev_mode_pusle_gen[1].point_us[5] + dev_mode_pusle_gen[1].point_us[6]);
|
|
NRF_LOG_INFO("[2]a = %d us", dev_mode_pusle_gen[1].point_us[0]);
|
|
NRF_LOG_INFO("[2]b = %d us", dev_mode_pusle_gen[1].point_us[1]);
|
|
NRF_LOG_INFO("[2]c = %d us", dev_mode_pusle_gen[1].point_us[2]);
|
|
NRF_LOG_INFO("[2]d = %d us", dev_mode_pusle_gen[1].point_us[3]);
|
|
NRF_LOG_INFO("[2]e = %d us", dev_mode_pusle_gen[1].point_us[4]);
|
|
NRF_LOG_INFO("[2]f = %d us", dev_mode_pusle_gen[1].point_us[5]);
|
|
NRF_LOG_INFO("[2]g = %d us", dev_mode_pusle_gen[1].point_us[6]);
|
|
NRF_LOG_INFO("[2]idle = %d us", dev_mode_pusle_gen[1].idle_us);
|
|
}
|
|
}
|
|
|
|
void start_which_electrodes(uint8_t *ins)
|
|
{
|
|
NRF_LOG_INFO("%s", __FUNCTION__);
|
|
uint8_t electrodes1_pulse_gen_en = (ins[5] & 0b10000000) >> 7;
|
|
uint8_t electrodes2_pulse_gen_en = (ins[5] & 0b01000000) >> 6;
|
|
uint8_t electrodes3_pulse_gen_en = (ins[5] & 0b00100000) >> 5;
|
|
uint8_t electrodes4_pulse_gen_en = (ins[5] & 0b00010000) >> 4;
|
|
|
|
if (electrodes1_pulse_gen_en)
|
|
{
|
|
NRF_LOG_INFO("start electrodes1_pulse_gen");
|
|
extern bool cpg10_pulse_gen(uint32_t idx, pusle_gen_t * p_pusle_gen);
|
|
cpg10_pulse_gen(0, &dev_mode_pusle_gen[0]);
|
|
}
|
|
|
|
if (electrodes2_pulse_gen_en)
|
|
{
|
|
NRF_LOG_INFO("start electrodes2_pulse_gen");
|
|
extern bool cpg10_pulse_gen(uint32_t idx, pusle_gen_t * p_pusle_gen);
|
|
cpg10_pulse_gen(1, &dev_mode_pusle_gen[1]);
|
|
}
|
|
}
|
|
|
|
/*
|
|
dev_mode_set_cpg10_electrodes
|
|
(1)0x3000FF0001
|
|
-func: ELECTRODES_A1HB1L
|
|
|
|
(2)0x3000FF0002
|
|
-func: ELECTRODES_A1LB1H
|
|
|
|
(3)0x3000FF0003
|
|
-func: ELECTRODES_A2HB2L
|
|
|
|
(4)0x3000FF0004
|
|
-func: ELECTRODES_A2LB2H
|
|
|
|
(5)0x3000FF0005
|
|
-func: ELECTRODES_A3HB3L
|
|
|
|
(6)0x3000FF0006
|
|
-func: ELECTRODES_A3LB3H
|
|
|
|
(7)0x3000FF0007
|
|
-func: ELECTRODES_A4HB4L
|
|
|
|
(8)0x3000FF0008
|
|
-func: ELECTRODES_A4LB4H
|
|
|
|
(9)0x3000FF0009
|
|
-func: ELECTRODE_A1B1_IDLE
|
|
|
|
(10)0x3000FF000A
|
|
-func: ELECTRODE_A2B2_IDLE
|
|
|
|
(11)0x3000FF000B
|
|
-func: ELECTRODE_A3B3_IDLE
|
|
|
|
(12)0x3000FF000C
|
|
-func: ELECTRODE_A4B4_IDLE
|
|
|
|
(13)0x3000FF000D
|
|
-func: ELECTRODE_ALL_HIGHZ
|
|
*/
|
|
void dev_mode_set_cpg10_electrodes(uint8_t *ins)
|
|
{
|
|
struct __PACKED
|
|
{
|
|
uint8_t id : 4;
|
|
uint8_t : 4;
|
|
uint16_t magic : 16;
|
|
uint8_t dev_opcode;
|
|
uint8_t electrodes_opcode;
|
|
} *p_ins = (void *)ins;
|
|
|
|
cpg10_electrodes(p_ins->electrodes_opcode);
|
|
}
|
|
|
|
/*
|
|
dev_mode_set_cpg10_tw1508
|
|
(1)0x3000FF0100
|
|
-func: tw1508_init()
|
|
|
|
(2)0x3000FF0101aaaabbbb
|
|
-func: tw1508_set()
|
|
-aaaa: out_0 value 0~1023[LSB]
|
|
-bbbb: out_1 value 0~1023[LSB]
|
|
*/
|
|
void dev_mode_set_cpg10_tw1508(uint8_t *ins)
|
|
{
|
|
struct __PACKED
|
|
{
|
|
uint8_t id : 4;
|
|
uint8_t : 4;
|
|
uint16_t magic : 16;
|
|
uint8_t dev_opcode;
|
|
uint8_t tw1508_opcode;
|
|
uint8_t param[];
|
|
} *p_ins = (void *)ins;
|
|
|
|
switch (p_ins->tw1508_opcode)
|
|
{
|
|
case 0x00: {
|
|
tw1508_init();
|
|
NRF_LOG_INFO("tw1508_init()");
|
|
break;
|
|
}
|
|
|
|
case 0x01: {
|
|
uint16_t out_0;
|
|
uint16_t out_1;
|
|
memcpy(&out_0, &p_ins->param[0], sizeof(out_0));
|
|
memcpy(&out_1, &p_ins->param[2], sizeof(out_1));
|
|
NRF_LOG_INFO("tw1508_set(%d, %d)", out_0, out_1);
|
|
tw1508_set(out_0, out_1);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
dev_mode_ctrl_cpg10_electrodes_task
|
|
(1)0x3000FF0201ss
|
|
-func: start/stop electrodes_1_task()
|
|
-ss:
|
|
00h: stop electrodes_1_task
|
|
01h: start electrodes_1_task
|
|
(2)0x3000FF0202ss
|
|
-func: start/stop electrodes_2_task()
|
|
-ss:
|
|
00h: stop electrodes_2_task
|
|
01h: start electrodes_2_task
|
|
(3)0x3000FF0203ss
|
|
-func: start/stop electrodes_3_task()
|
|
-ss:
|
|
00h: stop electrodes_3_task
|
|
01h: start electrodes_3_task
|
|
(4)0x3000FF0204ss
|
|
-func: start/stop electrodes_4_task()
|
|
-ss:
|
|
00h: stop electrodes_4_task
|
|
01h: start electrodes_4_task
|
|
(5)0x3000FF0205
|
|
-func: start cpg_pulse_default_demo()
|
|
(6)0x3000FF0206nnwwwwwwwwffffffff
|
|
-func: setting cpg_pulse_parameter
|
|
-nn: set which group of electrodes
|
|
01h: electrode1
|
|
02h: electrode2
|
|
03h: electrode3
|
|
04h: electrode4
|
|
-wwwwwwww: pulse_width_us
|
|
-ffffffff: freq_hz
|
|
(7)0x3000FF0207nn
|
|
-func: start which electrodes
|
|
-nn: start which electrodes (0x00 to 0xFF)
|
|
0x80 = 0b10000000: electrode1 enable pulse
|
|
0x40 = 0b01000000: electrode2 enable pulse
|
|
0x20 = 0b00100000: electrode3 enable pulse
|
|
0x10 = 0b00010000: electrode4 enable pulse
|
|
......
|
|
0xF0 = 0b11110000: electrode1~4 enable pulse
|
|
*/
|
|
void dev_mode_ctrl_cpg10_electrodes_task(uint8_t *ins)
|
|
{
|
|
struct __PACKED
|
|
{
|
|
uint8_t id : 4;
|
|
uint8_t : 4;
|
|
uint16_t magic : 16;
|
|
uint8_t dev_opcode;
|
|
uint8_t electrodes_task_opcode;
|
|
uint8_t param[];
|
|
} *p_ins = (void *)ins;
|
|
|
|
static TaskHandle_t electrodes1_task_Handle = NULL;
|
|
static TaskHandle_t electrodes2_task_Handle = NULL;
|
|
static TaskHandle_t electrodes3_task_Handle = NULL;
|
|
static TaskHandle_t electrodes4_task_Handle = NULL;
|
|
|
|
switch (p_ins->electrodes_task_opcode)
|
|
{
|
|
case 0x01: {
|
|
uint8_t task_enable = p_ins->param[0];
|
|
|
|
if (task_enable && electrodes1_task_Handle == NULL)
|
|
{
|
|
NRF_LOG_INFO("[test] start electrodes_1_task task");
|
|
xTaskCreate(electrodes_1_task, "electrodes_1_task", 1024, NULL, 4, &electrodes1_task_Handle);
|
|
}
|
|
else if (!task_enable && electrodes1_task_Handle != NULL)
|
|
{
|
|
NRF_LOG_INFO("[test] delete electrodes_1_task task");
|
|
cpg10_electrodes(ELECTRODE_A1B1_IDLE);
|
|
vTaskDelete(electrodes1_task_Handle);
|
|
electrodes1_task_Handle = NULL;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 0x02: {
|
|
uint8_t task_enable = p_ins->param[0];
|
|
|
|
if (task_enable && electrodes2_task_Handle == NULL)
|
|
{
|
|
NRF_LOG_INFO("[test] start electrodes_2_task task");
|
|
xTaskCreate(electrodes_2_task, "electrodes_2_task", 1024, NULL, 4, &electrodes2_task_Handle);
|
|
}
|
|
else if (!task_enable && electrodes2_task_Handle != NULL)
|
|
{
|
|
NRF_LOG_INFO("[test] delete electrodes_2_task task");
|
|
cpg10_electrodes(ELECTRODE_A2B2_IDLE);
|
|
vTaskDelete(electrodes2_task_Handle);
|
|
electrodes2_task_Handle = NULL;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 0x03: {
|
|
uint8_t task_enable = p_ins->param[0];
|
|
|
|
if (task_enable && electrodes3_task_Handle == NULL)
|
|
{
|
|
NRF_LOG_INFO("[test] start electrodes_3_task task");
|
|
xTaskCreate(electrodes_3_task, "electrodes_3_task", 1024, NULL, 4, &electrodes3_task_Handle);
|
|
}
|
|
else if (!task_enable && electrodes3_task_Handle != NULL)
|
|
{
|
|
NRF_LOG_INFO("[test] delete electrodes_3_task task");
|
|
cpg10_electrodes(ELECTRODE_A3B3_IDLE);
|
|
vTaskDelete(electrodes3_task_Handle);
|
|
electrodes3_task_Handle = NULL;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 0x04: {
|
|
uint8_t task_enable = p_ins->param[0];
|
|
|
|
if (task_enable && electrodes4_task_Handle == NULL)
|
|
{
|
|
NRF_LOG_INFO("[test] start electrodes_4_task task");
|
|
xTaskCreate(electrodes_4_task, "electrodes_4_task", 1024, NULL, 4, &electrodes4_task_Handle);
|
|
}
|
|
else if (!task_enable && electrodes4_task_Handle != NULL)
|
|
{
|
|
NRF_LOG_INFO("[test] delete electrodes_4_task task");
|
|
cpg10_electrodes(ELECTRODE_A4B4_IDLE);
|
|
vTaskDelete(electrodes4_task_Handle);
|
|
electrodes4_task_Handle = NULL;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 0x05: {
|
|
NRF_LOG_INFO("[test] cpg_pulse_default_demo()");
|
|
extern void cpg_pulse_default_demo(void);
|
|
cpg_pulse_default_demo();
|
|
break;
|
|
}
|
|
|
|
case 0x06: {
|
|
setting_cpg_pulse_parameter(ins);
|
|
break;
|
|
}
|
|
|
|
case 0x07: {
|
|
start_which_electrodes(ins);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
dev_mode_gpio_function
|
|
(1)0x3000FFA000ppss
|
|
-func: set_bmd380_pin_signal
|
|
-pp: pin number 06h-3Fh
|
|
06h: P0.22_GPIO
|
|
08h: P0.25_GPIO
|
|
......
|
|
3Eh: P0.16_GPIO
|
|
-ss: signal 00h-01h
|
|
00h: low
|
|
01h: high
|
|
|
|
(2)0x3000FFA001ss
|
|
-func: set BMD380 all pin to high/low, except for HV_EN, SPI, and INPUT pins
|
|
-ss: signal 00h-01h
|
|
00h: low
|
|
01h: high
|
|
*/
|
|
void dev_mode_gpio_function(uint8_t *ins)
|
|
{
|
|
struct __PACKED
|
|
{
|
|
uint8_t id : 4;
|
|
uint8_t : 4;
|
|
uint16_t magic : 16;
|
|
uint8_t dev_opcode;
|
|
uint8_t gpio_function_opcode;
|
|
uint8_t param[];
|
|
} *p_ins = (void *)ins;
|
|
|
|
switch (p_ins->gpio_function_opcode)
|
|
{
|
|
case 0x00: {
|
|
uint32_t pin = p_ins->param[0];
|
|
uint32_t high_low = p_ins->param[1];
|
|
set_bmd380_pin_signal(pin, high_low);
|
|
break;
|
|
}
|
|
|
|
case 0x01: {
|
|
uint32_t high_low = p_ins->param[0];
|
|
uint32_t set_pin[] = { 6, 8, 9, 10, 13, 14, 16, 17, 26, 27, 28, 30, 32, 33, 34, 36, 37, 38, 39, 40, 41, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 59, 60, 61, 62 };
|
|
|
|
for (int i = 0; i < sizeof(set_pin) / sizeof(set_pin[0]); i++)
|
|
{
|
|
set_bmd380_pin_signal(set_pin[i], high_low);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|