/** 
 * \file tool.h
 * \brief tool header file
 * \details File contains structures, enumerations and functions declarations for Axis Z stepper motor controller
 *
 * \author Juraj Golej
 * \version 1.0
 */


#ifndef TOOL_H_
#define TOOL_H_

#include "sam.h"
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <drivers/pio/pio.h>
#include <drivers/pwm/pwm.h>
#include <drivers/timer/timer.h>
#include <utils/retcode/retcode.h>
#include <utils/assert/arm_assert.h>
#include <app/axis/axis.h>
#include <pins.h>
#include "tool_cfg.h"

/**
 * \brief Move to motion finish user defined function (callback)
 */
typedef void (*tool_move_end)(void);

/**
 * \brief Initialize application
 * 
 * \return \b enum \b retCode Return code value
 * \retval ENone everything OK
 * \retval EInvalidParameter Can't initialize PWM or TIMER periphery
 *
 * \note Call this function before anything else
 */
enum retCode TOOL_init();

/**
 * \brief Execute free movement with defined speed
 *
 * \param[in] speed Speed in mm/s
 * 
 * \return \b enum \b retCode Return code value
 * \retval ENone everything OK
 * \retval EInvalidParameter Defined speed is higher than maximum speed
 * \retval EDenied There is currently controlled movement (MOVE TO)
 */
enum retCode TOOL_moveFree(const int16_t speed);

/**
 * \brief Execute controlled movement with defined absolute position and speed
 * 
 * \param[in] position Absolute position in mm
 * \param[in] speed Speed in mm/s
 * 
 * \return \b enum \b retCode Return code value
 * \retval ENone everything OK
 * \retval EInvalidParameter Defined speed is higher than maximum speed
 * \retval EDenied There is currently another controlled movement (MOVE TO) or free movement (MOVE FREE)
 */
enum retCode TOOL_moveToAbs(const float pos, const uint16_t speed);

/**
 * \brief Execute controlled movement with defined incremental position and speed
 * 
 * \param[in] position Incremental position in mm (can be negative)
 * \param[in] speed Speed in mm/s
 * 
 * \return \b enum \b retCode Return code value
 * \retval ENone everything OK
 * \retval EInvalidParameter Defined speed is higher than maximum speed
 * \retval EDenied There is currently another controlled movement (MOVE TO) or free movement (MOVE FREE)
 */
enum retCode TOOL_moveToInc(const float pos, const uint16_t speed);

/**
 * \brief Return pointer on Z axis structure
 * 
 * \return \b struct \b AXIS_app* Pointer on axis structure
 */
struct AXIS_app* TOOL_getAxis();

/**
 * \brief Register user defined callback function for movement end
 *
 * \param[in] callback Pointer on callback function
 */
void TOOL_registerCallback(tool_move_end callback);

#endif /* TOOL_H_ */