/*
 * PWM2 output is used to control LCD blightness.
 */
#include <t_services.h>
#include <lpc23xx.h>

#define	COUNTER_ENABLE	(1<<0)
#define	PWM_ENABLE	(1<<3)

#define	PWMMR0R		(1<<1)

#define	PWMENA2		(1<<10)

void pwm_init()
{
    PWM1TCR = 0;	/* Stop counting */
    PWM1CTCR = 0;
    PWM1PR = 0;

    PWM1MCR = PWMMR0R;
    PWM1MR0 = 1024;
    PWM1MR2 = 512;

    PWM1PCR = PWMENA2;	/* Enable PWM2 output */
    PWM1TCR = PWM_ENABLE|COUNTER_ENABLE;	/* Start counting */
}

void set_pwm_duty(int pval)
{
    PWM1MR2 = pval;
    PWM1LER = (1<<2);
}
