#ifndef AL_SMD_H
#define AL_SMD_H

#include <al_common.h>

#define SMD_IS_RUNNING		0x01
#define SMD_IS_ON_BEG_LSW	0x02
#define SMD_IS_ON_END_LSW	0x04

#ifndef SMD_PORT_CLK
#error SMD_PORT_CLK is not defined
#endif

#ifndef SMD_DDR_CLK
#error SMD_DDR_CLK is not defined
#endif

#ifndef SMD_BIT_CLK
#error SMD_BIT_CLK is not defined
#endif

#ifndef SMD_PORT_DIR
#error SMD_PORT_DIR is not defined
#endif

#ifndef SMD_DDR_DIR
#error SMD_DDR_DIR is not defined
#endif

#ifndef SMD_BIT_DIR
#error SMD_BIT_DIR is not defined
#endif

#ifdef SMD_PORT_RESET
#ifndef SMD_DDR_RESET
#error SMD_DDR_RESET is not defined
#endif

#ifndef SMD_BIT_RESET
#error SMD_BIT_RESET is not defined
#endif
#endif

#ifdef SMD_PORT_ENABLE
#ifndef SMD_DDR_ENABLE
#error SMD_DDR_ENABLE is not defined
#endif

#ifndef SMD_BIT_ENABLE
#error SMD_BIT_ENABLE is not defined
#endif
#endif

#ifdef SMD_PORT_HF
#ifndef SMD_DDR_HF
#error SMD_DDR_HF is not defined
#endif

#ifndef SMD_BIT_HF
#error SMD_BIT_HF is not defined
#endif
#endif

#ifdef SMD_PIN_BEG_LSW
#ifndef SMD_DDR_BEG_LSW
#error SMD_DDR_BEG_LSW is not defined
#endif

#ifndef SMD_BIT_BEG_LSW
#error SMD_BIT_BEG_LSW is not defined
#endif
#endif

#ifdef SMD_PIN_END_LSW
#ifndef SMD_DDR_END_LSW
#error SMD_DDR_END_LSW is not defined
#endif

#ifndef SMD_BIT_END_LSW
#error SMD_BIT_BEG_LSW is not defined
#endif
#endif

#define SMD_RESET_DELAY_LOOPS	10


#if !defined(SMD_MOVE_TIMER_0) && !defined(SMD_MOVE_TIMER_1) && !defined(SMD_MOVE_TIMER_2)
#error No move timer defined
#endif

#ifndef SMD_MOVE_TIMER_DIV
#error SMD_MOVE_TIMER_DIV is not defined
#endif

#if defined(SMD_MOVE_TIMER_1) && (defined(SMD_CURCTRL_OC1A) || defined(SMD_CURCTRL_OC1B))
#error Timer T1 conflict
#endif

#if defined(SMD_MOVE_TIMER_2) && defined(SMD_CURCTRL_OC2)
#error Timer T2 conflict
#endif


#define SMD_STEP_FULL		1
#define SMD_STEP_HALF		2
#define SMD_STEP_QUATER		3
#define SMD_STEP_EIGHTH		4


void		smd_init(void);
uint8_t		smd_get_flags(void);
int32_t		smd_get_position(void);
uint16_t	smd_get_speed(void);
uint16_t	smd_get_ramp(void);
void		smd_set_speed(uint16_t speed_);
void		smd_set_ramp(uint16_t ramp_);
void		smd_set_step(uint8_t step_);
void		smd_reset(void);
void		smd_move(int32_t position_);
void		smd_stop(void);
uint8_t		smd_get_current(void);
void		smd_set_current(uint8_t current_);

#endif
