/*
 * File: soft_pwm.h
 * Date: 04.01.2013
 * Denis Zheleznyakov aka ZiB @ http://ziblog.ru
 */

#ifndef SOFT_PWM_H_
#define SOFT_PWM_H_

//------------------------------------------------------------------------------
#define SOFT_PWM_PIN(line_number)	\
{ \
	if (soft_pwm_value < soft_pwm_channel[line_number]) \
	{ \
		PIN_ON(PIN_LINE_OUTPUT_CH##line_number); \
	} \
	else \
	{ \
		PIN_OFF(PIN_LINE_OUTPUT_CH##line_number); \
	} \
}

//------------------------------------------------------------------------------
#define SOFT_PWM_REFRESH() \
{ \
	static volatile uint8_t soft_pwm_value = 0; \
	SOFT_PWM_PIN(0); \
	SOFT_PWM_PIN(1); \
	SOFT_PWM_PIN(2); \
	SOFT_PWM_PIN(3); \
	SOFT_PWM_PIN(4); \
	SOFT_PWM_PIN(5); \
	SOFT_PWM_PIN(6); \
	SOFT_PWM_PIN(7); \
	SOFT_PWM_PIN(8); \
	SOFT_PWM_PIN(9); \
	SOFT_PWM_PIN(10); \
	SOFT_PWM_PIN(11); \
	SOFT_PWM_PIN(12); \
	SOFT_PWM_PIN(13); \
	SOFT_PWM_PIN(14); \
	SOFT_PWM_PIN(15); \
	soft_pwm_value++; \
	if(soft_pwm_value == 255) soft_pwm_value++; \
}

extern volatile uint8_t soft_pwm_channel[LINE_OUTPUTS_QUANTITY];

void soft_pwm_refresh(void);

#endif /* SOFT_PWM_H_ */
