1
Bus Pirate Development / Patch to add hardware PWM support down to 2Hz
Some observations:
1) I needed to enable [tt:]getlong[/tt:] for BPv3, previously it was only used with BPv4.
2) Confusingly [tt:]getlong[/tt:] is actually the equivalent of [tt:]getnumber[/tt:] and not [tt:]getint[/tt:] as one might think, and there is no [tt:]long[/tt:] version of [tt:]getint[/tt:]. As such it is not possible to specify a command-line argument to "G" with a frequency higher than [tt:]INT_MAX[/tt:]. I don't see this as a major problem, though, since one can use the "g" version in KHz with higher frequencies (that wouldn't have 1 Hz precision anyhow).
3) I also changed the [tt:]g[/tt:] command (PWM in KHz) to use my modified method for calculating the register values. This saves code space so the size impact of adding this command is fairly minimal (essentially just [tt:]getlong[/tt:]). However, this means that any bugs in my patch will also affect the old "g" command. I did test this with various options, though, and my calculation method is simpler with fewer magic numbers.
(There is still an internally used [tt:]updatePWM[/tt:] that I didn't touch. Personally I think the cleanest solution would be to have that use the same PWM calculation methods as well instead of duplicating everything for the interactive and non-interactive versions as seems to be done throughout the codebase.)
4) I don't know where the thresholds used for prescaler selection come from, but I kept the existing values (4 KHz, 31 KHz, and 245 KHz).
The patch is against the latest SVN sources, and can be applied in the firmware sources directory ([tt:]trunk/Firmware[/tt:]) with [tt:]patch -p0 <my_patch.diff[/tt:].
Oh, the patch itself:
http://arkku.com/misc/buspirate_hz_pwm_patch.diff