root/platform/ixus870_sd880/kbd.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_usb_bit
  2. mykbd_task_proceed
  3. mykbd_task
  4. wrap_kbd_p1_f
  5. my_kbd_read_keys
  6. kbd_fetch_data
  7. jogdial_control
  8. Get_JogDial
  9. get_jogdial_direction

   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 _platformsub_kbd_fetch_data(long*);
  11 
  12 #define NEW_SS (0x2000)
  13 
  14 // from sub_FF846198 (via aSdProtect (just above it))
  15 // LDR  R1, =dword_FFAD6F20     R1 = 0xFFAD6F20 = a
  16 // MOV  R3, #1                  R3 = 1
  17 // LDRB R2, [R1,#0x114]         R2 = a[0x114] = 0x51
  18 // LDRB R1, [R1,#0x114]         R1 = a[0x114] = 0x51
  19 // MOV  R2, R2,LSR#5            R2 = 0x51 >> 5 = 2 = SD_READONLY_REG
  20 // LDR  R0, [R0,R2,LSL#2]       R0 = R0[2] = b[2]
  21 // AND  R1, R1, #0x1F           R1 = 0x51 & 0x1F = 0x11
  22 // AND  R0, R0, R3,LSL R1       R0 = b[2] & (1 << 0x11)
  23 // MOV  R0, R0,LSR R1           R0 = (b[2] & (1 << 0x11)) >> 0x11
  24 // AND  R0, R0, #1              R0 = ((b[2] & (1 << 0x11)) >> 0x11) & 0x1
  25 // BX   LR                      return
  26 
  27 int get_usb_bit() 
  28 {
  29         long usb_physw[3];
  30         usb_physw[USB_IDX] = 0;
  31         _kbd_read_keys_r2(usb_physw);
  32         return(( usb_physw[USB_IDX] & USB_MASK)==USB_MASK) ; 
  33 }
  34 
  35 
  36 static char kbd_stack[NEW_SS];
  37 
  38 KeyMap keymap[] = {
  39         /* tiny bug: key order matters. see kbd_get_pressed_key()
  40          * for example
  41          * KEY_SHOOT_FULL and KEY_SHOOT_HALF overlap and the first has precedence
  42          */
  43 
  44     // (note: key is in group i if it changes a bit in physw_status[i])
  45     // group, CHDK key      , mask
  46     { 2, KEY_SHOOT_FULL , 0x00000003 },
  47     { 2, KEY_SHOOT_FULL_ONLY, 0x00000002 },
  48     { 2, KEY_SHOOT_HALF , 0x00000001 },
  49 
  50     { 2, KEY_UP         , 0x00000080 },
  51     { 2, KEY_DOWN               , 0x00000040 },
  52     { 2, KEY_LEFT               , 0x00000010 },
  53     { 2, KEY_RIGHT              , 0x00000020 },
  54     { 2, KEY_SET                , 0x00000100 },
  55     { 2, KEY_ZOOM_IN    , 0x00000004 },
  56     { 2, KEY_ZOOM_OUT   , 0x00000008 },
  57     { 2, KEY_MENU               , 0x00000400 },
  58     { 2, KEY_DISPLAY    , 0x00000200 },
  59     { 2, KEY_PRINT              , 0x00000800 },
  60     { 0, 0, 0 }
  61 };
  62 
  63 
  64 long __attribute__((naked)) wrap_kbd_p1_f();
  65 
  66 
  67 static void __attribute__((noinline)) mykbd_task_proceed()
  68 {
  69   int i;
  70         while (physw_run){
  71                 _SleepTask(10);
  72                 
  73                 if (wrap_kbd_p1_f() == 1){ // autorepeat ?
  74                         _kbd_p2_f();
  75                 }
  76         }
  77 }
  78 
  79 void __attribute__((naked,noinline)) mykbd_task()
  80 {
  81     /* WARNING
  82      * Stack pointer manipulation performed here!
  83      * This means (but not limited to):
  84      *  function arguments destroyed;
  85      *  function CAN NOT return properly;
  86      *  MUST NOT call or use stack variables before stack
  87      *  is setup properly;
  88      *
  89      */
  90 
  91         register int i;
  92         register long *newstack;
  93 
  94         newstack = (void*)kbd_stack;
  95 
  96         for (i=0;i<NEW_SS/4;i++)
  97                 newstack[i]=0xdededede;
  98 
  99         asm volatile (
 100                 "MOV    SP, %0"
 101                 :: "r"(((char*)newstack)+NEW_SS)
 102                 : "memory"
 103         );
 104 
 105         mykbd_task_proceed();
 106 
 107         /* function can be modified to restore SP here...
 108          */
 109 
 110         _ExitTask();
 111 }
 112 
 113 
 114 long __attribute__((naked,noinline)) wrap_kbd_p1_f()
 115 {
 116         // first three lines from kbd_p1_f plus a jump to the fourth
 117         asm volatile(
 118                 "STMFD   SP!, {R1-R5,LR}\n"
 119                 "MOV     R4, #0\n"
 120                 "BL      my_kbd_read_keys\n"
 121                 "B       _kbd_p1_f_cont\n"
 122         );
 123         return 0; // shut up the compiler
 124 }
 125 
 126 int jogdial_stopped=0;
 127 
 128 void my_kbd_read_keys()
 129 {
 130     _kbd_pwr_on();
 131 
 132     kbd_update_key_state();
 133 
 134     _kbd_read_keys_r2(physw_status);
 135 
 136     kbd_update_physw_bits();
 137 
 138     _kbd_pwr_off();
 139 }
 140 
 141 void kbd_fetch_data(long *dst)
 142 {
 143     _platformsub_kbd_fetch_data(dst);
 144 }
 145 
 146 void jogdial_control(int n) {
 147     // this camera did not have jog_position defined
 148     /*
 149     if (jogdial_stopped && !n) {
 150         // If re-enabling jogdial set the task code current & previous positions to the actual
 151         // dial positions so that the change won't get processed by the firmware
 152         jog_position[0] = jog_position[2] = rear_dial_position;   // Rear dial
 153     }
 154     */
 155     jogdial_stopped = n;
 156 }
 157 
 158 /****************/
 159 
 160 
 161 static int new_jogdial=0, old_jogdial=0;
 162 
 163 int Get_JogDial(void){
 164  // address from sub above aJogdail (sub_FF84B8D8)
 165  return (*(int*)0xC0240104)>>16;
 166 }
 167 
 168 long get_jogdial_direction(void) {
 169  // XXX this seems to have a overflow bug: old=MIN_INT, new = old-1 = MAX_INT  ->  old-1 < old < new = old - 1
 170  // not likely to happen though (very long runs with a bias for tuning one direction; bias is probably to the right due to menus)
 171  old_jogdial=new_jogdial;
 172  new_jogdial=Get_JogDial();
 173  if (old_jogdial<new_jogdial) return JOGDIAL_RIGHT; 
 174  else if (old_jogdial>new_jogdial) return JOGDIAL_LEFT;
 175  else return 0;
 176 }

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