/*
 * 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_TIMER_CLOCK 64 // 64Mhz
#define PSE_STEPPER_SCREW_PITCH 1000 // M6 : 1000µm / rotation
#define PSE_STEPPER_STEPS_PER_ROTATION 3200 // NEMA17 200 steps/rotation with 16x microstepping
#define PSE_STEPPER_JOG_PRESC 64 // jog step frequency 50kHz
#define PSE_STEPPER_JOG_PERIOD 25 // 64Mhz / 64 / 10 / 2
#define PSE_STEPPER_WARN_MAX_KSPS 10 // maximum (kilo) steps per second before we issue a warning

void pse_sp_start_axis(pse_stepper_conf* conf, pse_stepper_status* status);
void pse_sp_stop_axis(pse_stepper_conf* conf);
void pse_sp_set_dir(pse_unit* unit, int dir);
int pse_sp_get_dir(pse_unit* unit);
void pse_stepper_planer_tick(pse_unit* unit);
void pse_sp_jog_speed(pse_stepper_conf* conf, pse_stepper_status* sta, int status);

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_stepper_planer_compute_sps(pse_unit* unit);

#endif /* INC_PSE_STEPPER_PLANER_H_ */
