Rockbox

Tasklist

FS#11119 - Implement software pwm to control c200v2 display brightness

Attached to Project: Rockbox
Opened by Tobias Diedrich (ranma) - Wednesday, 17 March 2010, 16:38 GMT
Last edited by Tobias Diedrich (ranma) - Tuesday, 23 March 2010, 09:07 GMT
Task Type Patches
Category LCD
Status Closed
Assigned To Tobias Diedrich (ranma)
Operating System Sansa c200
Severity Low
Priority Normal
Reported Version Release 3.4
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

The original firmware uses software pwm to control display brightness.
Attached patch implements this on rockbox.
This task depends upon

Closed by  Tobias Diedrich (ranma)
Tuesday, 23 March 2010, 09:07 GMT
Reason for closing:  Accepted
Additional comments about closing:  Committed.
Comment by Thomas Martitz (kugel.) - Wednesday, 17 March 2010, 18:20 GMT
The style of your code is quite a bit strange IMO, confusing to read.

Is there no other way to set the backlight brightness on your c200v2?
Comment by Tobias Diedrich (ranma) - Wednesday, 17 March 2010, 18:38 GMT
Which part is confusing?

AFAICS there's no other way. They don't use the current source that's used in other models and the original firmware also does PWM (see http://forums.rockbox.org/index.php?topic=14064.msg163799#msg163799 "OF (c200-03.02.05) has fiq handler for backlight pwm at 0x3d38, which reads the model variable from 0x202e9 (at 0x3d48) and backlight toggling at 0x3d8c (on) and 0x3da0 (off).").
Comment by Tobias Diedrich (ranma) - Wednesday, 17 March 2010, 18:43 GMT
Without my microoptimization do_sw_pwm should look like this:

static inline void do_sw_pwm(void)
{
if (!timer2_pwm_on) {
do_scrollwheel(); /* Handle scrollwheel and tick tasks */
TIMER2_INTCLR = 0; /* clear interrupt */
return;
}

timer2_pwm_state ^= 1;
if (timer2_pwm_state) {
TIMER2_BGLOAD = timer2_cycles_pwmon;
_backlight_pwm(1);
} else {
TIMER2_BGLOAD = timer2_cycles_pwmoff;
_backlight_pwm(0);
do_scrollwheel(); /* Handle scrollwheel and tick tasks */
}

TIMER2_INTCLR = 0; /* clear interrupt */
}
Comment by Tobias Diedrich (ranma) - Wednesday, 17 March 2010, 18:50 GMT
patch without the 'weird' switch usage.
Comment by Tobias Diedrich (ranma) - Wednesday, 17 March 2010, 19:25 GMT
19:51 < kugel> ranmachan: IMO, unless you write a generic driver that can be
used by other (non-samsa) targets, the #define shouldn't be in
the <target>.h file. that's usually for optional stuff that
works on more on a single (or related range of) target(s)

#ifdef HAVE_BACKLIGHT_SW_PWM replaced by #if defined(SANSA_C200V2)
Comment by Tobias Diedrich (ranma) - Thursday, 18 March 2010, 03:26 GMT
Oops, I found that I had swapped the on/off time variables (In two places, so it _did_ the right thing, but :))
Fixed that.
Also, I thought a bit about it and changed it so that the 'upper layer' is always called during the longer cycle.
Otherwise in the very worst case the cpu would only have less than about 3000 cycles at 60MHz to execute all tick handlers.
This way it should always have about 15000000 cycles instead in the very worst case. ;)
Comment by Thomas Martitz (kugel.) - Thursday, 18 March 2010, 11:16 GMT
Actually, I have thought about implementing buttonlight brightness with software pwm, should be easily doable with your work :)
Comment by Tobias Diedrich (ranma) - Thursday, 18 March 2010, 12:06 GMT
I already have that working on my local tree.
However it doesn't work reliably for the 'other' c200v2 buttunlight, since the on/off-function accesses SD_MCI_POWER, if you'd call that from interrupt context it would race against other accesses to that register. I tried it: It resulted in occasional random display freezes for some reason.. I haven't looked at what SD_MCI_POWER actually is used for though. On my variant the main buttonlight is on A5, so it's not an issue for me.

Loading...