/*
 * pse_stepper_planer.h
 *
 *  Created on: Aug 14, 2023
 *      Author: leo
 */

#ifndef INC_PSE_STEPPER_PLANER_H_
#define INC_PSE_STEPPER_PLANER_H_

#include "PSE_unit.h"

#define PSE_STEPPER_INTERRUPT_RATE 20000 // 64Mhz (Presc 64, count 50) : 20kHz
#define PSE_STEPPER_SCREW_PITCH 1000 // M6 : 1000µm / rotation
#define PSE_STEPPER_STEPS_PER_ROTATION 6400 // NEMA17 200 steps/rotation with 32x microstepping

void pse_sp_start_axis(pse_stepper_conf* conf);
void pse_sp_stop_axis(pse_stepper_conf* conf);
void pse_sp_set_dir(pse_stepper_conf* conf, int dir);
int pse_sp_get_dir(pse_stepper_conf* conf);
void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num);


void pse_sp_set_dir_all(pse_unit* units, int unit_num, int dir);
void pse_sp_start_all(pse_unit* units, int unit_num);
void pse_sp_stop_all(pse_unit* units, int unit_num);

void pse_sp_set_timer(TIM_HandleTypeDef* tim);

void pse_stepper_planer_compute_sps(pse_unit* unit);

#endif /* INC_PSE_STEPPER_PLANER_H_ */
