pse-firmware/Core/Src/pse_stepper_planer.c
2023-08-16 11:26:42 +02:00

45 lines
961 B
C

/*
* pse_stepper_planer.c
*
* Created on: Aug 14, 2023
* Author: leo
*/
#include <stdint.h>
#include "PSE_unit.h"
unsigned int tick_counter = 0;
void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num){
for(int i = 0; i < units_num; i++){
pse_stepper_conf* c = units[i].stepper_conf;
int state;
if(c->step_max){
state = tick_counter % 2;
}
else{
state = (tick_counter % c->step_itvl) == 0;
}
HAL_GPIO_WritePin(c->STEP_GPIO_Port, c->STEP_GPIO_Pin, tick_counter%2);
}
tick_counter++;
}
unsigned int get_tick_counter(){
return tick_counter;
}
void pse_sp_start_axis(pse_stepper_conf* conf){
HAL_GPIO_WritePin(conf->EN_GPIO_Port, conf->EN_GPIO_Pin, GPIO_PIN_RESET);
}
void pse_sp_stop_axis(pse_stepper_conf* conf){
HAL_GPIO_WritePin(conf->EN_GPIO_Port, conf->EN_GPIO_Pin, GPIO_PIN_SET);
}
void pse_sp_set_dir(pse_stepper_conf* conf, int dir){
HAL_GPIO_WritePin(conf->DIR_GPIO_Port, conf->DIR_GPIO_Pin, dir);
}