TS-8390-47XX Backlight

From embeddedTS Manuals
Revision as of 11:04, 25 March 2014 by Mark (talk | contribs)

The backlight brightness can be adjusted by controlling the duty cycle of PWM on the processor DIO. This example takes an integer percentage as the only argument which will set the brightness.

/* Compile with:
 * gcc name.c -o output -mcpu=arm9
 */
#include <stdio.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <assert.h>
#include <fcntl.h>

volatile uint32_t *mvpwmregs = 0;
void set_brightness(int pct) 
{
	if(mvpwmregs == 0) {
		int mem = open("/dev/mem", O_RDWR|O_SYNC);
		assert(mem != -1);
		mvpwmregs = (unsigned int *) mmap(0, 4096,
	  	  PROT_READ | PROT_WRITE, MAP_SHARED, mem, 0xd401a000);
	}

	// duty cycle floor is 57, max is 128
	mvpwmregs[0x004/4] = 57 + ((pct * 71)/100);
}

int main(int argc, char **argv)
{
	set_brightness(atoi(argv[1]));
	return 0;
}