Update:
I added some #defines to support the various permutations, and converted some cameras as examples. The defines are documented in the top of kbd_common.c
This ends up being a lot of ifdefs, but most of them are used in a straightforward way (if cam needs FOO, do FOO without a lot of nested conditionals), so I'm still fairly happy with it.
The following cameras are converted, untested.
Powershot N
Example of a touch screen cam. More of the touch screen specific stuff could be made generic, but there's currently only 4 touch screen cams so it doesn't have to happen right away.
This is similar to the patch I posted earlier for N, with a few additional changes
* The current N code defines a mask and index for SD read only bit, even though the camera presumably doesn't have have one. I took this out.
* One of the KEY_DISPLAY entries in the keymap had a blank name. I assume this means it wouldn't be meant to be touched, so I converted it to TS_ZOMBIE
A495
Example of a cam with some inverted key logic. I think support for this could be rolled into the common kbd_update_key_state, but again there's only a few cameras that use this so it may not be worth it.
ixus30_sd200
example of a camera that completely does it's own thing, ignoring the common code. Having a platform_kbd.h define for this is somewhat roundabout, but makes it easy to grep for such cameras. This could probably be converted to use the common key_press* functions
Additionally, ixus140_elph130 is converted and tested.
Some other notes and issues
There are two common styles of using _GetKbdState (aka kbd_fetch_data) and _kbd_read_keys_r2.
On cameras like d10 (edit for posterity: I subsequently converted d10 to the second style, a540 is an example of the first):
kbd_fetch_data into new_state
run kbd_process (all chdk kbd task code)
copy into physw_status, fiddling key bits as required
_kbd_read_keys_r2, into physw_status
fiddle USB and SD read-only bits.
On cameras like sx160:
kbd_fetch_data into new_state
_kbd_read_keys_r2, into new_state
run kbd_process (all chdk kbd task code)
copy into physw_status, fiddling key bits as required
fiddle USB and SD read-only bits.
I think this difference in ports mostly depends on which port people started form, not a difference in camera behavior.
The new code can support either (see the d10 and sx160 conversions) but might be simplified if we standardized on one or the other.
CAM_USE_ZOOM_FOR_MF
This is defined by default. Rather than undef'ing it in platform_camera.h, some cameras just make kbd_use_zoom_as_mf return 0 (a800 is an example)
Cameras with an MF (old S series) key treat this differently, using the MF key when it's active. This isn't supported yet in the common code.
G9 (and possibly others) have a jogdial, but only have support for scripted wheel_left/wheel_right, not using the jogdial in CHDK or masking it from the canon firmware when in alt mode.
GPS cameras have a strange thing:
if (gps_key_trap > 0)
that makes kbd_task sleep for 1 second. I'm not sure what it does, but it seems odd.
Many old cameras have a KEY_DUMMY in the key map. AFAIK this is for some power saving prevention code that no longer exists, and can be removed.
a470 has a weird hack involving the power button
a490 and a800 have some code to swap the print and display keys when a script is running(?), but doesn't actually define either key in the key map
some cameras (e.g. s5is, inverted key logic cams like a495) read directly into physw_status rather than new_state