root/platform/sx60hs/kbd.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. get_usb_bit
  2. wrap_kbd_p1_f
  3. mykbd_task
  4. get_dial_hw_position
  5. get_jogdial_counter
  6. get_jogdial_direction
  7. handle_jogdial
  8. jogdial_control
  9. my_kbd_read_keys
  10. kbd_fetch_data

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 #include "keyboard.h"
   4 #include "kbd_common.h"
   5 
   6 long kbd_new_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
   7 long kbd_prev_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
   8 long kbd_mod_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
   9 
  10 extern void _GetKbdState(long*);
  11 extern void _LogCameraEvent(int id, const char *fmt,...);
  12 
  13 
  14 
  15 int get_usb_bit() {
  16     long usb_physw[3];
  17     usb_physw[USB_IDX] = 0;
  18     _kbd_read_keys_r2(usb_physw);
  19     return(( usb_physw[USB_IDX] & USB_MASK)==USB_MASK) ;
  20 }
  21 /* some other keys
  22   shortcut 0x4000 bit 14
  23 
  24   AvExpress/Trash 0x400 bit 10
  25   AFFrame 0x800 bit 11
  26   Assist  0x2 bit 1
  27   FIS 0x4 bit 2
  28 */
  29 KeyMap keymap[] = {
  30     { 0, KEY_SHOOT_FULL      ,0x00040001 }, // Found @0xfc5cfb3c, levent 0x01
  31     { 0, KEY_SHOOT_HALF      ,0x00040000 }, // Found @0xfc5cfbc4, levent 0x00
  32     { 0, KEY_SHOOT_FULL_ONLY ,0x00000001 }, // Found @0xfc5cfb3c, levent 0x01
  33     { 0, KEY_VIDEO           ,0x00000008 }, // Found @0xfc5cfb54, levent 0x02
  34     { 0, KEY_MENU            ,0x00000010 }, // Found @0xfc5cfb5c, levent 0x14
  35     { 0, KEY_UP              ,0x00000020 }, // Found @0xfc5cfb64, levent 0x06
  36     { 0, KEY_DOWN            ,0x00000040 }, // Found @0xfc5cfb6c, levent 0x07
  37     { 0, KEY_RIGHT           ,0x00000080 }, // Found @0xfc5cfb74, levent 0x09
  38     { 0, KEY_LEFT            ,0x00000100 }, // Found @0xfc5cfb7c, levent 0x08
  39     { 0, KEY_SET             ,0x00000200 }, // Found @0xfc5cfb84, levent 0x0a
  40     { 0, KEY_ERASE           ,0x00000400 }, //found by testing 
  41     { 0, KEY_WIFI            ,0x00002000 }, // found by testing 
  42     { 0, KEY_FACE            ,0x00000800 },
  43     { 0, KEY_PRINT           ,0x00004000 },
  44     { 0, KEY_FRAMING_ASSIST  ,0x00000002 },
  45     { 0, KEY_ZOOM_ASSIST     ,0x00000004 },
  46     { 0, KEY_PLAYBACK        ,0x00010000 }, // Found @0xfc5cfbb4, levent 0x101
  47 //    { 0, KEY_POWER           ,0x00020000 }, // Found @0xfc5cfbbc, levent 0x100
  48     { 2, KEY_ZOOM_OUT        ,0x00000008 }, // full speed
  49     { 2, KEY_ZOOM_OUT        ,0x00000018 }, // middle speed
  50     { 2, KEY_ZOOM_OUT        ,0x00000010 }, // low speed
  51     { 2, KEY_ZOOM_IN         ,0x00000002 }, // full speed
  52     { 2, KEY_ZOOM_IN         ,0x00000006 }, // middle speed
  53     { 2, KEY_ZOOM_IN         ,0x00000004 }, // low speed
  54 
  55     { 0, 0, 0 }
  56 };
  57 long __attribute__((naked,noinline)) wrap_kbd_p1_f() {
  58 
  59     asm volatile(
  60         "push    {r1-r7, lr}\n"
  61         "movs    r4, #0\n"
  62         "bl      my_kbd_read_keys\n"
  63         "b       _kbd_p1_f_cont\n"
  64     );
  65 
  66     return 0;
  67 }
  68 
  69 // no stack manipulation needed here, since we create the task directly
  70 void __attribute__((noinline)) mykbd_task() {
  71     extern void kbd_p2_f_my();
  72     while (physw_run) {
  73         _SleepTask(physw_sleep_delay);
  74 
  75         if (wrap_kbd_p1_f() == 1) {
  76             kbd_p2_f_my();                      // replacement of _kbd_p2_f (in sub/<fwver>/boot.c)
  77         }
  78     }
  79 
  80     _ExitTask();
  81 }
  82 
  83 // sx60hs jogdial hw counter (19 bits) 0xd9854004 
  84 // 0x7fff8 .. 0x7fffc .. 0 (start pos) .. 4
  85 // intermediate positions are also available, but they are ignored by the fw for a good reason
  86 int jogdial_stopped = 0;
  87 extern int _get_dial_hw_position(int dial);
  88 int get_dial_hw_position(int dial)
  89 {
  90     // mask low bits
  91     return _get_dial_hw_position(dial)&~3;
  92 }
  93 
  94 extern long dial_positions[4];
  95 extern long jog_hw_pos;
  96 int get_jogdial_counter() {
  97     int p;
  98    p = get_dial_hw_position(5);
  99 //    _LogCameraEvent(0x20,"jd: p: %08x %08x ",jog_hw_pos, p);
 100 //    p = jog_hw_pos & 0x7fffc;
 101 /*
 102     if (p > 0x3fffc) {
 103         p |= 0xfff80000;
 104     }
 105 */
 106     return p;
 107 }
 108 long get_jogdial_direction(void) {
 109     static int new_jogdial=0, old_jogdial=0 ;
 110 
 111     old_jogdial=new_jogdial;
 112     new_jogdial=get_jogdial_counter();
 113 
 114 //    _LogCameraEvent(0x20,"gjdd:  f:%08x %08x", old_jogdial, new_jogdial );
 115     if (old_jogdial>new_jogdial) return JOGDIAL_RIGHT;
 116     else if (old_jogdial<new_jogdial) return JOGDIAL_LEFT;
 117     else return 0;
 118 }
 119 int handle_jogdial() {
 120     // return 0 to prevent fw dial handler
 121 //    _LogCameraEvent(0x20,"hjd: %i %08x", jogdial_stopped, dial_positions[0]);
 122     if (jogdial_stopped) {
 123         // update positions in RAM
 124         dial_positions[0] = dial_positions[2] = get_jogdial_counter();
 125 
 126         return 0;
 127     }
 128     return 1;
 129 }
 130 
 131 void jogdial_control(int c) {
 132     jogdial_stopped = c;
 133 }
 134 
 135 void my_kbd_read_keys() {
 136     kbd_update_key_state();
 137     kbd_update_physw_bits();
 138 }
 139 
 140 void kbd_fetch_data(long *dst)
 141 {
 142     _GetKbdState(dst);
 143     _kbd_read_keys_r2(dst);
 144 //     if (dst[0] != 0x00077fff || dst[1] != 0x20808030 || dst[2] != 0x1480043e ) {
 145  //     _LogCameraEvent(0x20,"kb: %08x %08x %08x",  dst[0], dst[1], dst[2]);
 146   //  } 
 147 }

/* [<][>][^][v][top][bottom][index][help] */