enhancement/39-digio-cmd-profile-language #44

Merged
mhu merged 5 commits from enhancement/39-digio-cmd-profile-language into dev 2021-12-26 21:20:15 +01:00
6 changed files with 86 additions and 15 deletions

View File

@ -52,17 +52,10 @@ static void digio_setup_pin_int(uint8_t bit_no, uint8_t in_out, uint8_t alt_func
} }
void digio_setup_default_all(void) void digio_init(void)
{ {
unsigned int i;
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(DIGIO_RCC_MASK)); rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(DIGIO_RCC_MASK));
digio_set_default_values();
for (i = 0; i < COUNT_OF(digio_pins); i++) {
digio_setup_pin_int(digio_pins[i], digio_default_io[i], digio_default_altfunc[i]);
if (digio_default_io[i] == 1)
digio_set(i, 0);
}
} }
void digio_setup_pin(uint8_t num, uint8_t in_out, uint8_t alt_func) void digio_setup_pin(uint8_t num, uint8_t in_out, uint8_t alt_func)
@ -74,12 +67,22 @@ void digio_setup_pin(uint8_t num, uint8_t in_out, uint8_t alt_func)
void digio_set(uint8_t num, int val) void digio_set(uint8_t num, int val)
{ {
uint8_t pin;
if (num >= COUNT_OF(digio_pins)) if (num >= COUNT_OF(digio_pins))
return; return;
pin = digio_pins[num];
/* Check if port is an output. If not, do noting. */
if ((DIGIO_PORT->MODER & (0x3<<pin)) != OUTPUT(pin)) {
return;
}
if (val) if (val)
DIGIO_PORT->ODR |= (1<<digio_pins[num]); DIGIO_PORT->ODR |= (1<<pin);
else else
DIGIO_PORT->ODR &= ~(1<<digio_pins[num]); DIGIO_PORT->ODR &= ~(1<<pin);
} }
int digio_get(uint8_t num) int digio_get(uint8_t num)
@ -219,3 +222,14 @@ void TIM7_IRQHandler(void)
#endif #endif
/** @} */ /** @} */
void digio_set_default_values()
{
unsigned int i;
for (i = 0; i < COUNT_OF(digio_pins); i++) {
digio_setup_pin_int(digio_pins[i], digio_default_io[i], digio_default_altfunc[i]);
if (digio_default_io[i] == 1)
digio_set(i, 0);
}
}

View File

@ -65,11 +65,19 @@
#define BEEPER_RCC_MASK RCC_AHB1ENR_GPIOBEN #define BEEPER_RCC_MASK RCC_AHB1ENR_GPIOBEN
/** /**
* @brief Enable all clocks and setup pins in default setting * @brief Enable all clocks and setup pins in default setting.
* @warning This function uses @ref rcc_manager_enable_clock to enable the clocks. Therefore, it must not be called * @warning This function uses @ref rcc_manager_enable_clock to enable the clocks. Therefore, it must not be called
* multiple times. * multiple times.
* @note Calls @ref digio_set_default_values() internally.
*/ */
void digio_setup_default_all(void); void digio_init(void);
/**
* @brief Setup or restore the default DIGIO settings.
*
* This function can be called multiple times.
*/
void digio_set_default_values(void);
/** /**
* @brief Set up a DIGIO pin. * @brief Set up a DIGIO pin.

View File

@ -41,6 +41,9 @@ enum pl_command_type {
PL_LOUDSPEAKER_SET, /**< @brief Set the loudspeaker/beeper */ PL_LOUDSPEAKER_SET, /**< @brief Set the loudspeaker/beeper */
PL_OFF, /**< @brief Disable the temperature output and shutdown the PID controller */ PL_OFF, /**< @brief Disable the temperature output and shutdown the PID controller */
PL_CLEAR_FLAGS, /**< @brief Try clear all flags */ PL_CLEAR_FLAGS, /**< @brief Try clear all flags */
PL_DIGIO_CONF, /**< @brief Configure a DIGIO pin */
PL_DIGIO_SET, /**< @brief Set a DIGIO pin */
PL_DIGIO_WAIT, /**< @brief Wait until a DIGIO pin is set to the specified level */
_PL_NUM_CMDS, /**< @brief Sentinel to determine the total amount of commands */ _PL_NUM_CMDS, /**< @brief Sentinel to determine the total amount of commands */
}; };

View File

@ -219,8 +219,8 @@ static inline void setup_system(void)
/** - Initialize the oven output driver outputting the wavepacket control signal for the SSR and */ /** - Initialize the oven output driver outputting the wavepacket control signal for the SSR and */
oven_driver_init(); oven_driver_init();
/** - Initialize all DIGIO Pins to theri default state and pin functions */ /** - Initialize all DIGIO Pins to their default state and pin functions */
digio_setup_default_all(); digio_init();
/** - Set-up the LED outputs */ /** - Set-up the LED outputs */
led_setup(); led_setup();

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;
@ -250,6 +280,17 @@ int temp_profile_executer_handle(void)
cmd_ack_flags(); cmd_ack_flags();
advance = true; advance = true;
break; break;
case PL_DIGIO_CONF:
advance = true;
cmd_digio_conf((uint8_t)current_cmd->params[0], (uint8_t)current_cmd->params[1]);
break;
case PL_DIGIO_SET:
digio_set((uint8_t)current_cmd->params[0], current_cmd->params[1] ? 1u : 0u);
advance = true;
break;
case PL_DIGIO_WAIT:
advance = cmd_digio_wait((uint8_t)current_cmd->params[0], current_cmd->params[1] ? 1u : 0u);
break;
default: default:
tpe_abort(); tpe_abort();
advance = true; advance = true;
@ -290,7 +331,9 @@ int temp_profile_executer_stop(void)
if (command_list) if (command_list)
temp_profile_free_command_list(&command_list); temp_profile_free_command_list(&command_list);
/* Reset loudspeaker and reset default state of DIGIO channels */
loudspeaker_set(0); loudspeaker_set(0);
digio_set_default_values();
return 0; return 0;
} }

View File

@ -48,6 +48,9 @@ static const struct pl_command_list_map cmd_list_map[_PL_NUM_CMDS] = {
{PL_LOUDSPEAKER_SET, "beep", 1u}, {PL_LOUDSPEAKER_SET, "beep", 1u},
{PL_OFF, "temp_off", 0u}, {PL_OFF, "temp_off", 0u},
{PL_CLEAR_FLAGS, "clear_flags", 0u}, {PL_CLEAR_FLAGS, "clear_flags", 0u},
{PL_DIGIO_CONF, "digio_conf", 2u},
{PL_DIGIO_SET, "digio_set", 2u},
{PL_DIGIO_WAIT, "digio_wait", 2u},
}; };
/** /**