Issue #39: Implement DIGIO profile commands

This commit is contained in:
Mario Hüttel 2021-12-26 20:54:04 +01:00
parent 3bb4607798
commit 1e45c8b5d7

View File

@ -185,6 +185,36 @@ static void cmd_ack_flags(void)
} }
static void cmd_digio_conf(uint8_t digio_num, uint8_t mode)
{
uint8_t pin_mode;
uint8_t alt_func = 0;
if (mode == 0 || mode == 1) {
pin_mode = mode;
} else if (mode >= 0x80 && mode <= 0x87) {
/* Alternate function */
pin_mode = 2;
alt_func = mode - 0x80;
} else {
return;
}
digio_setup_pin(digio_num, pin_mode, alt_func);
}
bool cmd_digio_wait(uint8_t digio_num, uint8_t digio_state)
{
bool advance = false;
int res;
res = digio_get(digio_num);
if (res < 0 || (uint8_t)res == digio_state)
advance = true;
return advance;
}
int temp_profile_executer_handle(void) int temp_profile_executer_handle(void)
{ {
struct pl_command *current_cmd; struct pl_command *current_cmd;
@ -252,12 +282,14 @@ int temp_profile_executer_handle(void)
break; break;
case PL_DIGIO_CONF: case PL_DIGIO_CONF:
advance = true; advance = true;
cmd_digio_conf((uint8_t)current_cmd->params[0], (uint8_t)current_cmd->params[1]);
break; break;
case PL_DIGIO_SET: case PL_DIGIO_SET:
digio_set((uint8_t)current_cmd->params[0], current_cmd->params[1] ? 1u : 0u);
advance = true; advance = true;
break; break;
case PL_DIGIO_WAIT: case PL_DIGIO_WAIT:
advance = true; advance = cmd_digio_wait((uint8_t)current_cmd->params[0], current_cmd->params[1] ? 1u : 0u);
break; break;
default: default:
tpe_abort(); tpe_abort();