Hardware Coding


cxzuk

Still Fresh
Joined
Aug 4, 2006
Messages
34
Hi there,

Could someone point me in to the best place(s) of a list of what hardware there is avaible, what it can do and a small tutorial of how it works?

Id like to learn about all hardware stuff the GP2x can offer, such as the blitter, sound, LED, etc..

Cheers

Mike
 
Squidge posted on Aug 16 2006 at 03:21 PM said:
The MMSP2 datasheet is available on the Wiki.

Which is missing =)
 
Last edited by a moderator:
Ok, im very new to this =) Could someone help me?

Ive got the manual above /\... and im trying to understand it abit...

Lets take the contrast as an example... (p434).

16.2.6.2 Contrast
The contrast of Luminance is controlled by ISP_CNTRSTGAIN.
Contrast Control Register (ISP_CNTRSTGAIN)
Address : C000 3036h
Bit R/W Symbol Description Reset Value
[15:3] W Reserved Must be 0 0
[2:0] R/W ISP_CNTRSTGAIN
Contrast Gain Control
0 : 0.25, 1 : 0.5, 2 : 0.75, 3 : 1.0, 4 : 1.25, 5 : 1.5, 6 : 1.75, 7 : 2.0
3’h3
TABLE 16-21. CONTRAST CONTROL REGISTER (ISP_CNTRSTAIN)

I presume that the 0-2 bits are the contrast settings. with a value of 0-7 (so 3bits)..

Now how exactly do i access that?

Mike
 
cxzuk posted on Aug 16 2006 at 05:47 PM said:
Ok, im very new to this =) Could someone help me?

Ive got the manual above /\... and im trying to understand it abit...

Lets take the contrast as an example... (p434).

16.2.6.2 Contrast
The contrast of Luminance is controlled by ISP_CNTRSTGAIN.
Contrast Control Register (ISP_CNTRSTGAIN)
Address : C000 3036h
Bit R/W Symbol Description Reset Value
[15:3] W Reserved Must be 0 0
[2:0] R/W ISP_CNTRSTGAIN
Contrast Gain Control
0 : 0.25, 1 : 0.5, 2 : 0.75, 3 : 1.0, 4 : 1.25, 5 : 1.5, 6 : 1.75, 7 : 2.0
3’h3
TABLE 16-21. CONTRAST CONTROL REGISTER (ISP_CNTRSTAIN)

I presume that the 0-2 bits are the contrast settings. with a value of 0-7 (so 3bits)..

Now how exactly do i access that?

Mike

Here is an example for you:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#ifdef WIN32
#else
#include <sys/mman.h>
#include <linux/fb.h>
#include <unistd.h>
#include <stropts.h>

int memfd;

volatile unsigned long *memregs32;
volatile unsigned short *memregs16;

unsigned char initphys (void)
{
	memfd = open("/dev/mem", O_RDWR);
	if (memfd == -1)
	{
		printf ("Open failed for /dev/mem\n");
		return 0;
	}

	memregs32 = (unsigned long*) mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, memfd, 0xc0000000);
	
	if (memregs32 == (unsigned long *)0xFFFFFFFF) return 0;
	memregs16 = (unsigned short *)memregs32;

	return 1;
}

void closephys (void)
{
	close (memfd);
}
#endif

void LowPowerMode()
{
#ifdef WIN32
  return;
#else
  SetClock(25);
  
	if (!initphys()) return;
	
  //Turn off backlight
  memregs16[0x106E>>1] &=~0x0004;
  //Turn off LCD controller
  memregs16[0x2800>>1] &=~0x0001;
  //Set LCD to sleep mode
  memregs16[0x1062>>1] |= 0x0004;
  
	closephys();
#endif
}

void EndLowPowerMode(unsigned int NewSpeed)
{
#ifdef WIN32
  return;
#else
  SetClock(NewSpeed);
	if (!initphys()) return;
	
  //Set LCD from sleep mode
  memregs16[0x1062>>1] &=~0x0004;
  //Turn on LCD controller
  memregs16[0x2800>>1] |= 0x0001;
  //Turn on backlight
  memregs16[0x106E>>1] |= 0x0004;
  
	closephys();
#endif
}
This code accesses registers:
C000 106E (memregs16[0x106E>>1]) for turning on/off the backlight (that register controlls a GIO pin, where the backlight is connected to)
C000 2800 (memregs16[0x2800>>1]) for turning off the internal LCD controller (look it up in the manual)
and
C000 1063 (memregs16[0x1063>>1]) for setting the actual LCD screen in 'sleep' mode.

(that I mmap in every routine is a bit of a design bug, better to call the initphys() on program start and closephys() on program end)
(also note that I'm not 100% sure that my low power mode currently works at all, turning every thing off seemed to work, but dunno if everything comes up right again, that's WIP)

You could access the register you want with:
memregs16[0x3036] = (MyPersonalGainVariable & 0x7);
(after doing initphys() ofcourse)
 
Last edited by a moderator:
Back
Top