Keyboard, how exactly does it work? - General Discussion and Assistance - CHDK Forum

Keyboard, how exactly does it work?

  • 12 Replies
  • 6448 Views
*

Offline RaduP

  • *****
  • 926
Keyboard, how exactly does it work?
« on: 29 / September / 2009, 14:17:53 »
Advertisements
I am at the stage of making the keyboard work, and I am really having a hard time understanding how it works.
For example, the ALT mode key. The porting guide says:
Quote
Next you can define alt_mode_key_mask and the KEY_MASK? macros. The former, as static variable that can be set with a function kbd_set_alt_mode_key_mask(), is only required if you want the port to support a user-selectable "ALT" button (i.e. when you define CAM_ADJUSTABLE_ALT_BUTTON in include/camera.h and add the choices to gui_alt_mode_button_enum() in core/gui.h). Otherwise you can just make it a macro. For alt_mode_key_mask you should take the mask from keymap[] that corresponds to the button that should be used to enable the CHDK "ALT" mode (which should be KEY_PRINT to match the default CHDK configuration). The KEY_MASK? macros should be the or of all the masks of keys that correspond to the specific index (i.e. for KEY_MASK0 you should take the masks of keys that are represented in physw_status[0]).

Well, the alt_mode_key_mask is present in the SX10 port, but only used in one single part of the code. It is not present in some other ports, such as the SD990 port.
Here is how it's used on the SX10:
Code: [Select]
physw_status[1] |= alt_mode_key_mask;That's it, it's not used in any other place. So how does ORing physw_status[1] with the mask going to set the alt mode?
Also, I guess physw_status[1]  is used if that key is in physw_status[1] , otherwise it's physw_status[0] or physw_status[2] , right?

Re: Keyboard, how exactly does it work?
« Reply #1 on: 29 / September / 2009, 15:51:44 »
I am presuming you can currently use the debug print of...
draw_txt_string(20, 10, osd_buf, conf.osd_color);

If not then get that working and you will have best luck.

====

What I did was comment everything out of the my_kbd_read_keys function.  The only thing I kept was the top portion that debugs the new and old keys (see below).  This way you can write down what changes when you press and hold a certain key.  It also makes certain you don't crash by writing to memory with incorrect values....

Once you have all your keys mapped you can construct the KEYS_MASKx by ORing all your keys together.  You determine which "mask#" by which variable changes when you press a key.


You must also know that kbd_fetch_data() works.  If not you need to find the correct memory to inspect for the keyboard info.

As for CAM_ADJUSTABLE_ALT_BUTTON -   Note: in the SD780 case I remapped the DISP key to be a PRINT key.    You don't define an alternate ALT key unless you have additional keys that you want to be equal to the ALT key.  Its a bit confusing.  The CAM_ADJ... only defines an alternate ALT not what the ALT key is (its PRINT) but what is an ALT key in addition to the PRINT.


Clearer?  If not I'll try again.

Harpo

----

#define KEYS_MASK0 (0x0000000F)
#define KEYS_MASK1 (0x00094800)
#define KEYS_MASK2 (0x00007041)


void my_kbd_read_keys()
{

   static char osd_buf[64];
    volatile long *mmio2 = (void*)0xE240;  //VERIFY_SD780 - Should be set with DEFINE or something.
   int isHeldDisp = 0;

   kbd_prev_state[0] = kbd_new_state[0];
   kbd_prev_state[1] = kbd_new_state[1];
   kbd_prev_state[2] = kbd_new_state[2];
   kbd_fetch_data(kbd_new_state);

   
   sprintf(osd_buf, "1:       %8x  --> %8x", physw_status[0],kbd_new_state[0]);
   draw_txt_string(20, 10, osd_buf, conf.osd_color);

   sprintf(osd_buf, "2:       %8x  --> %8x", physw_status[1],kbd_new_state[1]);
   draw_txt_string(20, 11, osd_buf, conf.osd_color);

   sprintf(osd_buf, "3:       %8x  --> %8x", physw_status[2],kbd_new_state[2]);
   draw_txt_string(20, 12, osd_buf, conf.osd_color);
   msleep(500);
}





static KeyMap keymap[] = {
    /* tiny bug: key order matters. see kbd_get_pressed_key()
     * for example
     */

   //SD780 - Keymap
   { 0, KEY_UP          , 0x00000008 },
   { 0, KEY_DOWN      , 0x00000004 },
   { 0, KEY_LEFT      , 0x00000001 },
   { 0, KEY_RIGHT      , 0x00000002 },


   { 1, KEY_SET      , 0x00004000 },
   { 1, KEY_PLAY      , 0x00080000 },
   { 1, KEY_MENU      , 0x00000800 },
   { 1, KEY_POWER      , 0x00010000 },

   //xxxf --> xxxd when in movie mode by switch
   //xxxxxxx4 --> xxxxxxx5 when in lens extended recording mode


   { 2, KEY_SHOOT_FULL   , 0x00001001 },
   { 2, KEY_SHOOT_HALF   , 0x00000001 },
   { 2, KEY_ZOOM_IN   , 0x00004000 },
   { 2, KEY_ZOOM_OUT   , 0x00002000 },
   { 2, KEY_PRINT      , 0x00000040 }, //doesn't exist
   { 2, KEY_DISPLAY   , 0x00000040 }, //swapped for print atm
                              //We will see if I can make KEY_DISPLAY a long KEY_DISPLAY...
   { 0, 0, 0 }
};


void kbd_fetch_data(long *dst)
{
   //SD780 0xFF8431EC GetKbdState
    volatile long *mmio0 = (void*)0xc0220200;
    volatile long *mmio1 = (void*)0xc0220204;
    volatile long *mmio2 = (void*)0xc0220208;

    dst[0] = *mmio0;
    dst[1] = *mmio1;
    dst[2] = *mmio2 & 0xffff;
}
« Last Edit: 29 / September / 2009, 15:53:36 by HarpoMa »
Canon Models - SD300, SD780, & SX210

*

Offline RaduP

  • *****
  • 926
Re: Keyboard, how exactly does it work?
« Reply #2 on: 29 / September / 2009, 20:33:10 »
Hi, and thanks for the reply.
Perhaps I should have been more clear.
I can display texts, and reading the keyboard works, at least at the with the debug mode that displays the active keys (this is how I was able to get their masks).
But I do not understand WHERE in the code CHDK says: "woah, the ALT key was pressed, let me switch to the onscreen display mode and display my menus".

*

Offline reyalp

  • ******
  • 14110
Re: Keyboard, how exactly does it work?
« Reply #3 on: 29 / September / 2009, 20:45:18 »
core/kbc.c kbd_process()
Don't forget what the H stands for.


*

Offline RaduP

  • *****
  • 926
Re: Keyboard, how exactly does it work?
« Reply #4 on: 29 / September / 2009, 20:56:30 »
Oh... the gui_kbd_enter() thing. Ok, thanks, I've been looking for that for at least 8 hours :/

I looked quite a few times over:
Code: [Select]
       // deals with alt-mode switch and delay emulation
        if (key_pressed)
        {
                if (kbd_is_key_pressed(conf.alt_mode_button) ||
                        ((key_pressed >= CAM_EMUL_KEYPRESS_DELAY) &&
                         (key_pressed < CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION)))
                {

And always missed gui_kbd_enter() :/

*

Offline RaduP

  • *****
  • 926
Re: Keyboard, how exactly does it work?
« Reply #5 on: 29 / September / 2009, 21:11:07 »
BTW, as a suggestion, it would perhaps be nice for future developer if that function was renamed to something more descriptive, such as: switch_to_alt_mode()
That way you can search for "alt" and actually find it.

*

Offline RaduP

  • *****
  • 926
Re: Keyboard, how exactly does it work?
« Reply #6 on: 30 / September / 2009, 00:59:55 »
Ok, now another question...
Where the hell is set_key_press() called to set key_pressed to 1?
I can only find calls to it in the remote control stuff.. And without it being set to 1, kbd_process() will not start the alt mode...

Re: Keyboard, how exactly does it work?
« Reply #7 on: 30 / September / 2009, 01:20:16 »
Are you using an IDE to help with finding calls and such?  Are you using a reference camera?  SD990 helped me greatly to answer a lot of my questions.  Eclipse as an IDE works wonderfully.

As for your specific question I think you may be looking at the kbd_process() function and missing a close bracket....          if (key_pressed) {
does not enclose everything...

Harpo
Canon Models - SD300, SD780, & SX210


*

Offline reyalp

  • ******
  • 14110
Re: Keyboard, how exactly does it work?
« Reply #8 on: 30 / September / 2009, 01:31:41 »
Also, you shouldn't have to change anything in the core keyboard processing code. It works for all the other cameras. If it doesn't work for yours, chances are you are doing something wrong in your platform code.

Yes, the code and formatting in kbd_process() is hideous ;)

FWIW, I use gvim for editing (syntax highlighting, easy delimiter matching, regex search within files, top of the line 1970s user interface), and use http://tools.tortoisesvn.net/grepWin for searching the whole codebase.
Don't forget what the H stands for.

*

Offline RaduP

  • *****
  • 926
Re: Keyboard, how exactly does it work?
« Reply #9 on: 30 / September / 2009, 01:41:12 »
I am not looking to change stuff, but I like using debug stuff in the code so that I can see where I might do something wrong.

Unless if I am going totally crazy, this is where the magic part happens (where you switch to the GUI mode)

Code: [Select]
        if (key_pressed)
        {
blink_led(1);
                if (kbd_is_key_pressed(conf.alt_mode_button) ||
                        ((key_pressed >= CAM_EMUL_KEYPRESS_DELAY) &&
                         (key_pressed < CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION)))
                {
blink_led(1);
                        if (key_pressed <= CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION)
                                key_pressed++;
                        if (key_pressed == CAM_EMUL_KEYPRESS_DELAY)
                                kbd_key_press(conf.alt_mode_button);
                        else if (key_pressed == +CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION)
                                kbd_key_release(conf.alt_mode_button);
                        return 1;
                } else
                if (kbd_get_pressed_key() == 0)
                {
                        if (key_pressed != 100 && (key_pressed < CAM_EMUL_KEYPRESS_DELAY))
                        {
                                kbd_blocked = 1-kbd_blocked;
                                if (kbd_blocked) gui_kbd_enter(); else gui_kbd_leave();
                        }
                        key_pressed = 0;
                        return 1;
                }
                return 1;
        }

Now, how can gui_kbd_enter() ever be called if key_pressed is 0?

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal