Rockbox Technical Forums

Support and General Use => Hardware => Topic started by: jhMikeS on July 10, 2006, 01:14:16 AM

Title: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: jhMikeS on July 10, 2006, 01:14:16 AM
I've read a request on another thread about shutting down the LCD panel when the backlight is off. Some code is in place already to facilitate this and I almost know how to procede on the X5 (the only player I have right now). Is it even worth it?

I'm new to just about EVERYTHING as far as what each file is for in rockbox, cygwin, UNIX shell, the utilities used for building rockbox (cvs, gcc, etc.), little familiarity with the MCF5249 and HC66773R but I believe I'm making progress in my knowledge.

The MFC5249 User's manual is quite daunting at 450 pages and the HD667733R at 133 pages too. I just need a little help!

I do have some questions (better asked on IRC?):
The LCD command register and data register are listed in the twiki as 0x20008000 and 0x20008002 repectively but the driver writes to 0xF0008000 and 0xF0008002. Why this descrepancy?

How is the mapping of the LCD chip to CPU memory addresses accomplished? Is it hardwired on the board or done in the software somewhere? Which lines? Knowing this would help my understanding of the CPU greatly.

Which interface does the LCD driver use? I know it's 18-bit but serial or parallel?

I still need to get my setup completed and learn how build the sources for the X5 port but the wiki is down and I'm left with cached pages on Google which is slowing me down a lot.

Not quite entirely related:
Will full 18-bit color ever be supported? The driver expands colors from 5-6-5 to 6-6-6 before writing them to the gram. It appears that color values would have to be longs and not ints and that would mean changing a lot of code (not that I wouldn't take it on). I've been warned about changing everything!
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: Llorean on July 10, 2006, 01:17:15 AM
Yes, your best bet is to ask in the IRC channel.

The only one of these I *might* be able to answer is relating to the 16/18 issue. I do believe 16 bit is used even on 18-bit targets simply because it's faster. 18 bit is possible, if I understand correctly, but would be considerably slower.

Oh, and shutting the LCD off won't gain *much* since all the drawing calculations have to be done anyway to keep the screen updated, as the various threads don't know the whole screen's state.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: jhMikeS on July 10, 2006, 01:31:07 AM
All the code for writing to gram would be skipped while the display is off though. There's quite a bit of writing going from the screen buffer to gram. You're saying this extra step doesn't consume much power? Additionally , how 'bout shutting the chip down entirely when (sleep or standby) not in use? The powerup sequence doesn't appear to take too long.

As far as full color support goes, I seriously wouldn't mind *gasp* wasting the memory and just using 32 bits per pixel for simplicity and speed. The memory requirement would only be doubled. It can also be dithered easily enough if someone wants super high quality.

Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: Llorean on July 10, 2006, 01:36:14 AM
Well, tests on another color player showed that shutting off the screen entirely, but leaving the drawing routines as-is, didn't affect things significantly (if I recall.) There was some increase in battery life, but not as much as was hoped.
Though to be honest, at the time they were hoping for a LOT. And I don't really recall hard numbers as to the actual improvement.

As for doubling the memory used by the screen, you'd also have to double the memory available for the WPS buffer. I can't really see 18-bit color offering a major improvement for the while playing screen or for the menuing system. Maybe for image-viewing though. But that's just me.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: jhMikeS on July 10, 2006, 01:55:58 AM
It can certainly be tried-out and would be educational for me. For the X5 it looks like some rather simple changes to the lcd and backlight files.

A parallel API to use full native color depth for image viewing (and maybe eventually video) might be worth working on.  Only one additional function call that expects 24 or 32 bit pixel data (with optional dithering) should be needed to start out. How about lcd_blit_ex? It could be used concurrently with existing functions when extra color quality is desired.

I'll get set up on IRC and not get too much heavier here.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: Llorean on July 10, 2006, 01:59:13 AM
Sounds like a good idea. I would personally suggest talking to Amiconn in IRC (when he's around) about the improved bit depths. He's either likely to be able to answer your questions, or point you in the right direction for who to discuss it with.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: Bagder on July 10, 2006, 02:59:25 AM
The X5 LCD can't display 18bit colors, only 16bit.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: RaeNye on July 10, 2006, 03:25:50 AM
Quote
The MFC5249 User's manual is quite daunting at 450 pages and the HD667733R at 133 pages too. I just need a little help!
Actually X5 uses the SCF5250. Not that I could find any difference except for IRAM size / clock speed.
The important part of the LCD specs is the set of commands.

Quote
The LCD command register and data register are listed in the twiki as 0x20008000 and 0x20008002 repectively but the driver writes to 0xF0008000 and 0xF0008002. Why this descrepancy?

The default value of CS2 (a "segment" register) is 0x20000000, also used by the OF. RB uses 0xF0000000, hence all memory addresses in this area (LCD, IDE, USBOTG) are rebased.

Quote
How is the mapping of the LCD chip to CPU memory addresses accomplished? Is it hardwired on the board or done in the software somewhere? Which lines? Knowing this would help my understanding of the CPU greatly.

RB sets CS2 in crt0.S. The offset 0x8000 is probably hardwired. You care not.

Quote
Which interface does the LCD driver use? I know it's 18-bit but serial or parallel?
The interface used, probably hardwired, is two memory mapped registers (LCD_CMD and LCD_DATA), addressed using "stupid 16-bit to 18-bit mode". This means you have to read/write the high 8 bits as 9 bits and then separately the low 8 bits as 9 bits, rendering IO twice as slow.
RB uses a look-up table to ease this a bit.

LCD commands tend to look like "write XXX to LCD_CMD, then read/write YYY from/to LCD_DATA". Note that when copying framebuffer to the LCD you only need to issue the write command once and afterwards you just keep writing the data.

Also, you should check out the HWM (sp?) mode that allows 4 aligned LCD writes to be done in parallel. It probably requires changing the direction the framebuffer is stored, but maybe it's faster.

Quote
As far as full color support goes, I seriously wouldn't mind *gasp* wasting the memory and just using 32 bits per pixel for simplicity and speed. The memory requirement would only be doubled. It can also be dithered easily enough if someone wants super high quality.
Currently the framebuffer takes 0xF000 bytes out of the available 0x20000 bytes in IRAM. You would have to either get it out of IRAM (-33% performance IIRC) or get everything else out.

Quote
I've read a request on another thread about shutting down the LCD panel when the backlight is off. ... Is it even worth it?
I think this should come with a more global device standby scheme, e.g.,
Even if not such implemented,  I want LCD to be shut down gracefully on player shutdown. It's The Right ThingTM to do and might extend its life.

Feel free to ask more, I might be nice enough to answer ;),
R.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: jhMikeS on July 10, 2006, 03:39:51 AM
You're right. Things are making more sense now. I'm looking at the data sheet now and it says the 18 bit color is hardware dithered to 16-bit 565 if the DIT bit is set to "1".

I knew it! The 262,144 colors is a scam!

Is the chip interface hardwired for 18-bit or can 16-bit be used instead without modding? That probably would have been done already.

Image viewing/video could still be improved a little using the hard dithering anyway.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: jhMikeS on July 10, 2006, 04:08:31 AM
RaeNye, thanks. You ansered some important things while I was replying to Badger.

Quote
The default value of CS2 (a "segment" register) is 0x20000000, also used by the OF. RB uses 0xF0000000, hence all memory addresses in this area (LCD, IDE, USBOTG) are rebased.
Can you tell what pins are involved in the addressing? That would help me understand the CPU better in general as far as hooking up external devices. I do care so!  ;D

Quote
backlight is off after 5 seconds w/o keypresses (actually I want a fade-out )
Why is there no backlight dimming? That thing eats power and it doesn't need to be fullbright when looking at the WPS or browsing.

Quote
Also, you should check out the HWM (sp?) mode that allows 4 aligned LCD writes to be done in parallel. It probably requires changing the direction the framebuffer is stored, but maybe it's faster.
The lcd_x5.c is easy to understand in general. I'm curious about that burst RAM write stuff. It says you have to write four words (goes into registers) and writes that to GRAM while you write the next four words.

Quote
I want LCD to be shut down gracefully on player shutdown.
Yeah, I don't see the recommended power down sequence being observed anywhere in the driver.

I'm off to sleep now. Hopefully I can get on IRC and ask lots of questions later.  I just don't want to frustrate the gurus too much.   ;D
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: RaeNye on July 10, 2006, 04:19:21 AM
Quote
Can you tell what pins are involved in the addressing? That would help me understand the CPU better in general as far as hooking up external devices. I do care so!  Grin
Sorry, now you actually have to read the whole specs :o.

Quote
The lcd_x5.c is easy to understand in general. I'm curious about that burst RAM write stuff. It says you have to write four words (goes into registers) and writes that to GRAM while you write the next four words.
That's what I meant. Alignment and other restrictions might kill us though.

Quote
Why is there no backlight dimming? That thing eats power and it doesn't need to be fullbright when looking at the WPS or browsing.
If you mean contrast/brightness control, checkout FS #5474 (http://"http://www.rockbox.org/tracker/task/5474").
I was talking about gradually dimming the backlight instead of just cancelling backlight altogether when 5 seconds have elasped.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: infamis on July 10, 2006, 01:38:14 PM
damn RaeNye you've come a long way...props

Quote from: RaeNye, from a while ago
In fact, I tried to open the firmware in IDA, but I don't really know which segments to create. Huh

I do see functions and data (e.g., strings, CRC-16 lookup tables, ...) but I cannot resolve absolute addresses.

I saw http://www.rockbox.org/twiki/bin/view/Main/IaudioPort#Original_firmware_information, but I just don't understand what exactly is considered ROM, RAM, "ports", etc. (what are IRAM and GPIO anyway?)

Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: RaeNye on July 10, 2006, 04:23:56 PM
LOL.
But I really did learn much about embedded platforms from RB.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: jhMikeS on July 11, 2006, 05:01:52 PM
I basically finished the patch last night however I want it tweaked to prevent backlight flicker on power off. I'm doing that now.

It does two main things:
1) Shuts the LCD down gracefully.
2) Shuts the LCD off and puts it in standy mode when the backlight goes off and of course restarts it when the backlight is turned back on.

I'll post when I'm basically happy with it.  :D
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: nicolinux on July 11, 2006, 05:36:21 PM
It's a good idea I think.

Thanks !  :)
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: jhMikeS on July 11, 2006, 06:57:53 PM
I think I'm gonna forget about the backlight flicker for now because I can see it's rather involved and so would be out of context for this patch. But something turns it back on again right before power shuts down...maybe the backlight thread running during yield(). I dunno.  ???
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: RaeNye on July 11, 2006, 08:11:48 PM
Release... I promise to take a look ;)
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: jhMikeS on July 11, 2006, 09:31:59 PM
 :o  ;D
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: snowgoon on July 18, 2006, 12:01:52 AM
Sorry if this is slightly off topic (lcd backlight), but it is related to lcd performance on x5...

Is it the best use of the extra iram on the x5 to stick the lcd buffer in it?  What is the benefit as opposed to giving audio plugins (or all plugins) a bigger share of the iram?  I have tested increased iram allocation to the mpc codec and found that it reduced cpu boost quite a bit (should apply to at least some other codecs as well).  Since this would result in longer battery life for people who use the x5 mainly for listening to music (instead of looking at pretty wps' ;-) wouldn't it be worth it?  For plugins that need fast lcd performance, eg. video playback, could they create their own lcd buffer?
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: Bagder on July 18, 2006, 05:24:51 AM
Quote
Is it the best use of the extra iram on the x5 to stick the lcd buffer in it?

Perhaps not, but nothing was using that ram so I decided to put the framebuffer there to boost performance bit. Remember that everything that runs needs to run faster, and the LCD is getting updated a lot while music is playing.

In order to put codec data in iram, we "just" need to create defines in similar spirit as I did for the framebuffer and use that define for the specific data parts of the codecs. I think.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: jhMikeS on July 19, 2006, 01:59:27 PM
The design of the X5's LCD is unfortunate. I'm trying to implement all the empty driver functions except lcd_roll() just doesn't seems workable as a hardware remap  >:(. The 90deg flip of the display is the reason as most remap features are on the vertical. (I also think the contrast should be implemented through the gamma/ramp control and not the overall voltage settings).

BTW: HWM may work despite this and I'll experiment. You want faster so I'll try to deliver the goods.

Who knows if its possible to read from the LCD? Are all the LCD pin assignments accounted for yet? (Stupid question. Updates to that would be in the Wiki already, right?)

Anyone got a busted unit to sell cheap for pattern tracing or gut what you want but give me the circuit boards?
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: arielext on July 28, 2006, 02:42:19 AM
Is this patch in CVS yet?
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: jhMikeS on August 02, 2006, 03:04:48 PM
FS#5651 itself is deprecated so it won't be but an updated version is coming soon with a couple of related options that RaeNye suggested be included with LCD power handling. See also FS#5735 by Bernych.
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: arielext on August 11, 2006, 05:28:14 AM
yah I saw that, the new patch works great!
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: Suicide_Guy on August 11, 2006, 05:47:25 AM
Wow I love this patch...especially since it was committed to a daily build. :D I love you guys...I really do. 8-)
Title: Re: X5: Itching to create a patch that shuts the LCD off when backlight is off.
Post by: madcow on August 11, 2006, 02:27:42 PM
It's containing a bug!
After awaking from sleep the screens contrast isn't right (way too dark).

http://www.rockbox.org/tracker/task/5800 (http://www.rockbox.org/tracker/task/5800)