#include "p18f6520.h"
#include "timers.h"
#include "spi.h"
#include "pwm.h"

enum{
	kMotorX = 1,
	kMotorY,
	kMotorZ,
	kMotorLimits,
	kMotorPinch
};

//command set
enum{
	kMotorStop = 101,
	kMotorLED,
	kMotorVelocity,
	kMotorVoltage,
	kMotorJog,
	kMotorGotoX,
	kMotorGotoY,
	kMotorGotoZ,
	kMotorCenterEncoders,
	kMotorSetVelocity,
	kMotorSetAcceleration,
	kMotorSetDuration
};

//quadrature encoder constants from datasheet of LS7166 from usdigital.com
#define ENCODER_DATA 0b11101111				//named "DATA1" in datasheet
#define ENCODER_CONTROL 0b11111111			//named "CONTROL1" in datasheet

#define MASTER_RESET 0x20
#define INPUT_SETUP  0x68
#define QUAD_X1      0xC1
#define QUAD_X2      0xC2
#define QUAD_X4      0xC3
#define ADDR_RESET   0x01
#define LATCH_CNTR   0x02
#define CNTR_RESET   0x04
#define PRESET_CTR   0x08

/*
#define ENCODER_DATA6 PIN_E6
#define ENCODER_DATA7 PIN_E7

#define ENCODER_WR   PIN_D0
#define ENCODER_LL   PIN_D1
#define ENCODER_RCTR PIN_D2
#define ENCODER_RD   PIN_D3
#define ENCODER_CD   PIN_D4

#define ENCODER_CS_X PIN_D5
#define ENCODER_CS_Y PIN_D6
#define ENCODER_CS_Z PIN_D7
*/

#define ENCODER_CENTER_HI 0x80                 //center of the encoder range
#define ENCODER_CENTER_MID 0x00
#define ENCODER_CENTER_LO 0x00
