feat: 修改cpg_pulse_default_demo_ext(), 可設定e1,e2,e3,e4來輸出脈波

This commit is contained in:
Roy_01
2024-10-30 14:39:04 +08:00
parent 973cc07871
commit de7403ed52
2 changed files with 128 additions and 108 deletions
+2 -2
View File
@@ -15,8 +15,8 @@
#define VERSION_DATE_YEAR 24
#define VERSION_DATE_MONTH 10
#define VERSION_DATE_DAY 30
#define VERSION_DATE_HOUR 11
#define VERSION_DATE_MINUTE 16
#define VERSION_DATE_HOUR 14
#define VERSION_DATE_MINUTE 39
static void cis_version(uint8_t *ins, uint16_t size)
{
NRF_LOG_INFO("%s", __FUNCTION__);
+126 -106
View File
@@ -329,133 +329,153 @@ void cpg11_pulse_init(uint32_t hw_idx, pulse_gen_t *p_pulse_gen, uint32_t len)
void cpg_pulse_default_demo_ext(void)
{
uint32_t pulse_gen_numb = 2;
bool e1 = 0;
bool e2 = 1;
bool e3 = 1;
bool e4 = 1;
pulse_gen_t p_pulse_genA[2];
pulse_gen_t p_pulse_genB[2];
pulse_gen_t *p_pulse_genA = pvPortMalloc(sizeof(pulse_gen_t) * pulse_gen_numb);
pulse_gen_t *p_pulse_genB = pvPortMalloc(sizeof(pulse_gen_t) * pulse_gen_numb);
p_pulse_genA[0] = (pulse_gen_t) {
.VBxH = VB1H_PIN,
.VBxL = VB1L_PIN,
.VAxH = VA1H_PIN,
.VAxL = VA1L_PIN,
.point_us[0] = 1,
.point_us[1] = 50,
.point_us[2] = 1,
.point_us[3] = 0,
.point_us[4] = 1,
.point_us[5] = 50,
.point_us[6] = 1,
.idle_us = 1000,
.pulse_cnt = UINT32_MAX,
.pulse_id = PULSE_ID_A,
};
memset(p_pulse_genA, 0x00, sizeof(pulse_gen_t) * pulse_gen_numb);
memset(p_pulse_genB, 0x00, sizeof(pulse_gen_t) * pulse_gen_numb);
p_pulse_genA[1] = (pulse_gen_t) {
.VBxH = VB2H_PIN,
.VBxL = VB2L_PIN,
.VAxH = VA2H_PIN,
.VAxL = VA2L_PIN,
.point_us[0] = 1,
.point_us[1] = 50,
.point_us[2] = 1,
.point_us[3] = 0,
.point_us[4] = 1,
.point_us[5] = 50,
.point_us[6] = 1,
.idle_us = 1000,
.pulse_cnt = UINT32_MAX,
.pulse_id = PULSE_ID_B,
};
if (pulse_gen_numb > 0)
p_pulse_genB[0] = (pulse_gen_t) {
.VBxH = VB3H_PIN,
.VBxL = VB3L_PIN,
.VAxH = VA3H_PIN,
.VAxL = VA3L_PIN,
.point_us[0] = 1,
.point_us[1] = 50,
.point_us[2] = 1,
.point_us[3] = 0,
.point_us[4] = 1,
.point_us[5] = 50,
.point_us[6] = 1,
.idle_us = 1000,
.pulse_cnt = UINT32_MAX,
.pulse_id = PULSE_ID_C,
};
p_pulse_genB[1] = (pulse_gen_t) {
.VBxH = VB4H_PIN,
.VBxL = VB4L_PIN,
.VAxH = VA4H_PIN,
.VAxL = VA4L_PIN,
.point_us[0] = 1,
.point_us[1] = 50,
.point_us[2] = 1,
.point_us[3] = 0,
.point_us[4] = 1,
.point_us[5] = 50,
.point_us[6] = 1,
.idle_us = 1000,
.pulse_cnt = UINT32_MAX,
.pulse_id = PULSE_ID_B,
};
if(e1)
{
p_pulse_genA[0] = (pulse_gen_t) {
.VBxH = VB1H_PIN,
.VBxL = VB1L_PIN,
.VAxH = VA1H_PIN,
.VAxL = VA1L_PIN,
.point_us[0] = 1,
.point_us[1] = 50,
.point_us[2] = 1,
.point_us[3] = 0,
.point_us[4] = 1,
.point_us[5] = 50,
.point_us[6] = 1,
.idle_us = 1000,
.pulse_cnt = UINT32_MAX,
.pulse_id = 0,
};
nrf_gpio_pin_clear(p_pulse_genA[0].VBxL);
nrf_gpio_pin_clear(p_pulse_genA[0].VBxH);
nrf_gpio_pin_clear(p_pulse_genA[0].VAxL);
nrf_gpio_pin_clear(p_pulse_genA[0].VAxH);
}
if (pulse_gen_numb > 1)
if(e2)
{
p_pulse_genA[1] = (pulse_gen_t) {
.VBxH = VB2H_PIN,
.VBxL = VB2L_PIN,
.VAxH = VA2H_PIN,
.VAxL = VA2L_PIN,
.point_us[0] = 1,
.point_us[1] = 50,
.point_us[2] = 1,
.point_us[3] = 0,
.point_us[4] = 1,
.point_us[5] = 50,
.point_us[6] = 1,
.idle_us = 1000,
.pulse_cnt = UINT32_MAX,
.pulse_id = 1,
};
nrf_gpio_pin_clear(p_pulse_genA[1].VBxL);
nrf_gpio_pin_clear(p_pulse_genA[1].VBxH);
nrf_gpio_pin_clear(p_pulse_genA[1].VAxL);
nrf_gpio_pin_clear(p_pulse_genA[1].VAxH);
}
if (pulse_gen_numb > 0)
if(e3)
{
p_pulse_genB[0] = (pulse_gen_t) {
.VBxH = VB3H_PIN,
.VBxL = VB3L_PIN,
.VAxH = VA3H_PIN,
.VAxL = VA3L_PIN,
.point_us[0] = 1,
.point_us[1] = 50,
.point_us[2] = 1,
.point_us[3] = 0,
.point_us[4] = 1,
.point_us[5] = 50,
.point_us[6] = 1,
.idle_us = 1000,
.pulse_cnt = UINT32_MAX,
.pulse_id = 2,
};
nrf_gpio_pin_clear(p_pulse_genB[0].VBxL);
nrf_gpio_pin_clear(p_pulse_genB[0].VBxH);
nrf_gpio_pin_clear(p_pulse_genB[0].VAxL);
nrf_gpio_pin_clear(p_pulse_genB[0].VAxH);
}
if (pulse_gen_numb > 1)
if(e4)
{
p_pulse_genB[1] = (pulse_gen_t) {
.VBxH = VB4H_PIN,
.VBxL = VB4L_PIN,
.VAxH = VA4H_PIN,
.VAxL = VA4L_PIN,
.point_us[0] = 1,
.point_us[1] = 50,
.point_us[2] = 1,
.point_us[3] = 0,
.point_us[4] = 1,
.point_us[5] = 50,
.point_us[6] = 1,
.idle_us = 1000,
.pulse_cnt = UINT32_MAX,
.pulse_id = 3,
};
nrf_gpio_pin_clear(p_pulse_genB[1].VBxL);
nrf_gpio_pin_clear(p_pulse_genB[1].VBxH);
nrf_gpio_pin_clear(p_pulse_genB[1].VAxL);
nrf_gpio_pin_clear(p_pulse_genB[1].VAxH);
}
for (uint32_t i = 0; i < pulse_gen_numb; i++)
if (e1 && e2)
{
nrf_gpio_pin_clear(p_pulse_genA[i].VBxL);
nrf_gpio_pin_clear(p_pulse_genA[i].VBxH);
nrf_gpio_pin_clear(p_pulse_genA[i].VAxL);
nrf_gpio_pin_clear(p_pulse_genA[i].VAxH);
cpg11_pulse_init(0, p_pulse_genA, 2);
cpg11_pulse_start(0, p_pulse_genA);
}
else if (e1 && e2==0)
{
cpg11_pulse_init(0, p_pulse_genA, 1);
cpg11_pulse_start(0, p_pulse_genA);
}
else if (e2 && e1==0)
{
cpg11_pulse_init(0, &p_pulse_genA[1], 1);
cpg11_pulse_start(0, &p_pulse_genA[1]);
}
for (uint32_t i = 0; i < pulse_gen_numb; i++)
if (e3 && e4)
{
nrf_gpio_pin_clear(p_pulse_genB[i].VBxL);
nrf_gpio_pin_clear(p_pulse_genB[i].VBxH);
nrf_gpio_pin_clear(p_pulse_genB[i].VAxL);
nrf_gpio_pin_clear(p_pulse_genB[i].VAxH);
cpg11_pulse_init(1, p_pulse_genB, 2);
cpg11_pulse_start(1, p_pulse_genB);
}
else if (e3 && e4==0)
{
cpg11_pulse_init(1, p_pulse_genB, 1);
cpg11_pulse_start(1, p_pulse_genB);
}
else if (e4 && e3==0)
{
cpg11_pulse_init(1, &p_pulse_genB[1], 1);
cpg11_pulse_start(1, &p_pulse_genB[1]);
}
cpg11_pulse_init(0, p_pulse_genA, pulse_gen_numb);
cpg11_pulse_init(1, p_pulse_genB, pulse_gen_numb);
cpg11_pulse_start(0, p_pulse_genA);
cpg11_pulse_start(1, p_pulse_genB);
for (;;)
{
vTaskDelay(10);
cpg11_pulse_suspend_by_pulse_id(p_pulse_genA[0].pulse_id);
vTaskDelay(10);
cpg11_pulse_resume_by_pulse_id(p_pulse_genA[0].pulse_id);
}
// cpg11_pulse_suspend_by_pulse_id(p_pulse_gen[0].pulse_id);
// cpg11_pulse_suspend_by_pulse_id(p_pulse_gen[1].pulse_id);
// cpg11_pulse_suspend_by_pulse_id(p_pulse_gen[2].pulse_id);
// cpg11_pulse_suspend_by_pulse_id(p_pulse_gen[3].pulse_id);
// cpg11_pulse_suspend_by_pulse_id(p_pulse_gen[4].pulse_id);
vPortFree(p_pulse_genA);
vPortFree(p_pulse_genB);
// for (;;)
// {
// vTaskDelay(10);
// cpg11_pulse_suspend_by_pulse_id(p_pulse_genA[0].pulse_id);
// vTaskDelay(10);
// cpg11_pulse_resume_by_pulse_id(p_pulse_genA[0].pulse_id);
// }
for (;;)
{