#ifndef COM_TABLES_H
#define COM_TABLES_H

const uint16_t bldc_ccw_ccer[] = // counter clockwise
{
	(1 << TIM_CCER_CC1NE_Pos)|(1 << TIM_CCER_CC1E_Pos)|(1 << TIM_CCER_CC3NE_Pos)|(1 << TIM_CCER_CC3E_Pos), // ch1 pwm, ch2 z, ch3 low
	(1 << TIM_CCER_CC1NE_Pos)|(1 << TIM_CCER_CC1E_Pos)|(1 << TIM_CCER_CC2NE_Pos)|(1 << TIM_CCER_CC2E_Pos), // ch1 low, ch2 pwm, ch3 z
	(1 << TIM_CCER_CC2NE_Pos)|(1 << TIM_CCER_CC2E_Pos)|(1 << TIM_CCER_CC3NE_Pos)|(1 << TIM_CCER_CC3E_Pos), // ch1 z, ch2 pwm, ch3 low
	(1 << TIM_CCER_CC2NE_Pos)|(1 << TIM_CCER_CC2E_Pos)|(1 << TIM_CCER_CC3NE_Pos)|(1 << TIM_CCER_CC3E_Pos), // ch1 z, ch2 low, ch3 pwm
	(1 << TIM_CCER_CC1NE_Pos)|(1 << TIM_CCER_CC1E_Pos)|(1 << TIM_CCER_CC2NE_Pos)|(1 << TIM_CCER_CC2E_Pos), // ch1 pwm, ch2 low, ch3 z
	(1 << TIM_CCER_CC1NE_Pos)|(1 << TIM_CCER_CC1E_Pos)|(1 << TIM_CCER_CC3NE_Pos)|(1 << TIM_CCER_CC3E_Pos)  // ch1 low, ch2 z, ch3 pwm
};

const uint16_t bldc_ccw_ccmr1[] = // counter clockwise
{
	(6 << TIM_CCMR1_OC1M_Pos),
	(5 << TIM_CCMR1_OC1M_Pos)|(6 << TIM_CCMR1_OC2M_Pos),
	(6 << TIM_CCMR1_OC2M_Pos),
	(5 << TIM_CCMR1_OC2M_Pos),
	(6 << TIM_CCMR1_OC1M_Pos)|(5 << TIM_CCMR1_OC2M_Pos),
	(5 << TIM_CCMR1_OC1M_Pos)
};

const uint16_t bldc_ccw_ccmr2[] = // counter clockwise
{
	(5 << TIM_CCMR2_OC3M_Pos),
	0,
	(5 << TIM_CCMR2_OC3M_Pos),
	(6 << TIM_CCMR2_OC3M_Pos),
	0,
	(6 << TIM_CCMR2_OC3M_Pos)
};

const uint16_t bldc_cw_ccer[] = // clockwise
{
	(1 << TIM_CCER_CC1NE_Pos)|(1 << TIM_CCER_CC1E_Pos)|(1 << TIM_CCER_CC3NE_Pos)|(1 << TIM_CCER_CC3E_Pos), // ch1 low, ch2 z, ch3 pwm
	(1 << TIM_CCER_CC1NE_Pos)|(1 << TIM_CCER_CC1E_Pos)|(1 << TIM_CCER_CC2NE_Pos)|(1 << TIM_CCER_CC2E_Pos), // ch1 pwm, ch2 low, ch3 z
	(1 << TIM_CCER_CC2NE_Pos)|(1 << TIM_CCER_CC2E_Pos)|(1 << TIM_CCER_CC3NE_Pos)|(1 << TIM_CCER_CC3E_Pos), // ch1 z, ch2 low, ch3 pwm
	(1 << TIM_CCER_CC2NE_Pos)|(1 << TIM_CCER_CC2E_Pos)|(1 << TIM_CCER_CC3NE_Pos)|(1 << TIM_CCER_CC3E_Pos), // ch1 z, ch2 pwm, ch3 low
	(1 << TIM_CCER_CC1NE_Pos)|(1 << TIM_CCER_CC1E_Pos)|(1 << TIM_CCER_CC2NE_Pos)|(1 << TIM_CCER_CC2E_Pos), // ch1 low, ch2 pwm, ch3 z
	(1 << TIM_CCER_CC1NE_Pos)|(1 << TIM_CCER_CC1E_Pos)|(1 << TIM_CCER_CC3NE_Pos)|(1 << TIM_CCER_CC3E_Pos)  // ch1 pwm, ch2 z, ch3 low
};

const uint16_t bldc_cw_ccmr1[] = // clockwise
{
	(5 << TIM_CCMR1_OC1M_Pos),
	(6 << TIM_CCMR1_OC1M_Pos)|(5 << TIM_CCMR1_OC2M_Pos),
	(5 << TIM_CCMR1_OC2M_Pos),
	(6 << TIM_CCMR1_OC2M_Pos),
	(5 << TIM_CCMR1_OC1M_Pos)|(6 << TIM_CCMR1_OC2M_Pos),
	(6 << TIM_CCMR1_OC1M_Pos)
};

const uint16_t bldc_cw_ccmr2[] = // clockwise
{
	(6 << TIM_CCMR2_OC3M_Pos),
	0,
	(6 << TIM_CCMR2_OC3M_Pos),
	(5 << TIM_CCMR2_OC3M_Pos),
	0,
	(5 << TIM_CCMR2_OC3M_Pos)
};

const uint8_t bldc_rot_lut[] = {3, 5, 4, 1, 2, 0};

#endif // COM_TABLES_H
