root/platform/ixus30_sd200/kbd.c

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

DEFINITIONS

This source file includes following definitions.
  1. mykbd_task_proceed
  2. mykbd_task
  3. wrap_kbd_p1_f
  4. my_kbd_read_keys
  5. platformsub_kbd_fetch_data_my
  6. usb_power_status_override
  7. kbd_process_task

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 #include "core.h"
   4 #include "conf.h"
   5 #include "keyboard.h"
   6 #include "kbd_common.h"
   7 
   8 long kbd_new_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
   9 long kbd_prev_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  10 long kbd_mod_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  11 
  12 KeyMap keymap[] = {
  13     /* tiny bug: key order matters. see kbd_get_pressed_key()
  14      * for example
  15      */
  16     {1, KEY_UP              , 0x00000020 },
  17     {1, KEY_DOWN            , 0x00000040 },
  18     {1, KEY_LEFT            , 0x00000080 },
  19     {1, KEY_RIGHT           , 0x00000100 },
  20     {1, KEY_SET             , 0x00000200 },
  21     {1, KEY_SHOOT_FULL      , 0x00000006 }, // note 6 here!
  22     {1, KEY_SHOOT_FULL_ONLY , 0x00000004 },
  23     {1, KEY_SHOOT_HALF      , 0x00000002 },
  24     {1, KEY_ZOOM_IN         , 0x00000008 },
  25     {1, KEY_ZOOM_OUT        , 0x00000010 },
  26     {1, KEY_MENU            , 0x00000400 },
  27     {1, KEY_DISPLAY         , 0x00000800 },
  28     {1, KEY_PRINT           , 0x00002000 },
  29     {0, 0, 0 }
  30 };
  31 
  32 //get some vxworks defines for semaphore stuff
  33 #define STATUS int
  34 #define BOOL   int
  35 #define OK    0
  36 #define ERROR (-1)
  37 
  38 #define SEM_Q_FIFO           0x0
  39 #define SEM_Q_PRIORITY       0x1
  40 #define SEM_DELETE_SAFE      0x4
  41 #define SEM_INVERSION_SAFE   0x8
  42 #define SEM_OPTION_MASK     (SEM_Q_FIFO|SEM_Q_PRIORITY|SEM_DELETE_SAFE|SEM_INVERSION_SAFE)
  43 
  44 #define NO_WAIT         0
  45 #define WAIT_FOREVER    (-1)
  46 
  47 typedef enum {
  48 
  49         SEM_EMPTY =0,
  50         SEM_FULL =1
  51 
  52 } SEM_B_STATE;
  53 
  54 typedef int SEM_ID; 
  55 extern SEM_ID _semBCreate(int options, SEM_B_STATE initialState);
  56 //extern STATUS _TakeSemaphore(SEM_ID, int);
  57 //extern STATUS _GiveSemaphore(SEM_ID);
  58 SEM_ID semBinary;
  59 
  60 static int kbd_data_process_request_data=0;
  61 
  62 // extern void _platformsub_kbd_fetch_data(long*);
  63 long __attribute__((naked)) wrap_kbd_p1_f();
  64 
  65 //KBD HACK
  66 // long kbd_process_copy();
  67 // static int key_pressed;
  68 // extern void script_start();
  69 // extern void script_end();
  70 // extern void process_script();
  71 extern void msleep(long);
  72 // static int kbd_blocked;
  73 
  74 
  75 // extern void h_kbd_p2_f();
  76 
  77 
  78 void __attribute__((naked,noinline)) mykbd_task_proceed()
  79         {
  80     asm volatile
  81                 (
  82                                 "STMFD  SP!, {R4-R8,LR}\n"
  83                                 "LDR    R3, =0x20F8\n"
  84                                 "SUB    SP, SP, #8\n"
  85                                 "LDR    R2, [R3]\n"
  86                                 "CMP    R2, #2\n"
  87                                 "BNE    loc_FF830870\n"
  88                                 "LDR    R6, =0x11A48\n"
  89                                 "MOV    R8, SP\n"
  90                                 "ADD    R7, SP, #0x20-0x1C\n"
  91 
  92                 "loc_FF83075C:\n"
  93                                 "MOV    R0, R8\n"
  94                                 "BL             _GetSystemTime\n"
  95                                 "LDR    R1, =wrap_kbd_p1_f\n" // (0xff8308e8)Replaced call to my own function...
  96                                 "LDR    R0, [SP,#0x20-0x20]\n"
  97                                 "MOV    R3, R7\n"
  98                                 "ADD    R0, R0, #0xA\n"
  99                                 "MOV    R2, R1\n"
 100                                 "BL             _SetTimerWhen\n"
 101                                 "CMP    R0, #0x15\n"
 102                                 "MVN    R3, R0\n"
 103                                 "ANDNE  R0, R3, #1\n"
 104                                 "MOVEQ  R0, #1\n"
 105                                 "CMP    R0, #0\n"
 106                                 "BNE    loc_FF8307A8\n"
 107                                 "MOV    R2, #0x1F0\n"
 108                                 "LDR    R0, =0xFF8306F4\n"   //aError_tHtimer1
 109                                 "LDR    R1, =0xFF830000\n"   //=aPhyswmngr_c
 110                                 "ADD    R2, R2, #2\n"
 111                                 "BL             sub_FF814C10\n"
 112 
 113                 "loc_FF8307A8:\n"
 114                                 "LDR    R3, =0x11AA0\n"
 115                                 "LDR    R4, =0x11728\n"
 116                                 "LDR    R5, =0x11A60\n"
 117                                 "LDR    R0, [R3]\n"
 118                                 "MOV    R1, #0\n"
 119                                 "BL             _TakeSemaphore\n"
 120                                 "LDR    R2, [R4,#8]\n"
 121                                 "LDR    R3, [R5,#0x2C]\n"
 122                                 "TST    R2, R3\n"
 123                                 "BEQ    loc_FF8307E0\n"
 124                                 "LDR    R0, =0x119A8\n"
 125                                 "LDR    R1, [R6,#0xC]\n"
 126                                 "BL             sub_FF830C5C\n"
 127                                 "LDR    R2, [R4,#8]\n"
 128 
 129                 "loc_FF8307E0:\n"
 130                                 "LDR    R3, [R5,#0x20]\n"
 131                                 "TST    R2, R3\n"
 132                                 "BEQ    loc_FF8307F8\n"
 133                                 "LDR    R0, =0x11958\n"
 134                                 "LDR    R1, [R6,#8]\n"
 135                                 "BL             sub_FF830C5C\n"
 136 
 137                 "loc_FF8307F8:\n"
 138                                 "LDR    R0, [R4,#4]\n"
 139                                 "LDR    R3, [R5,#0x10]\n"
 140                                 "TST    R0, R3\n"
 141                                 "BEQ    loc_FF830818\n"
 142                                 "LDR    R0, =0x11908\n"
 143                                 "LDR    R1, [R6,#4]\n"
 144                                 "BL             sub_FF830D10\n"
 145                                 "LDR    R0, [R4,#4]\n"
 146 
 147                 "loc_FF830818:\n"
 148                                 "LDR    R1, [R5,#4]\n"
 149                                 "LDR    R2, [R4,#8]\n"
 150                                 "LDR    R3, [R5,#8]\n"
 151                                 "AND    R1, R0, R1\n"
 152                                 "AND    R2, R2, R3\n"
 153                                 "ORRS   R1, R1, R2\n"
 154                                 "BEQ    loc_FF830844\n"
 155                                 "LDR    R0, =0x118b8\n"
 156                                 "LDR    R1, [R6]\n"
 157                                 "BL             sub_FF830C5C\n"
 158                                 "LDR    R0, [R4,#4]\n"
 159 
 160                 "loc_FF830844:\n"
 161                                 "LDR    R3, [R5,#0x34]\n"
 162                                 "TST    R0, R3\n"
 163                                 "BEQ    loc_FF83085C\n"
 164                                 "LDR    R0, =0x119f8\n"
 165                                 "LDR    R1, [R6,#0x10]\n"
 166                                 "BL             sub_FF830C5C\n"
 167 
 168                 "loc_FF83085C:\n"
 169                                 "BL             sub_FF8310C8\n"
 170                                 "LDR    R3, =0x20F8\n"
 171                                 "LDR    R2, [R3]\n"
 172                                 "CMP    R2, #2\n"
 173                                 "BEQ    loc_FF83075C\n"
 174 
 175                 "loc_FF830870:\n"
 176                                 "LDR    R3, =0x11A9C\n"
 177                                 "LDR    R1, =0x20F8\n"
 178                                 "MOV    R2, #3\n"
 179                                 "LDR    R0, [R3]\n"
 180                                 "STR    R2, [R1]\n"
 181                                 "BL             sub_FF823144\n"
 182                                 "BL             _ExitTask\n"
 183                                 "ADD    SP, SP, #8\n"
 184                                 "LDMFD  SP!, {R4-R8,PC}\n"
 185                 );
 186         }//ixus30 ok
 187 
 188 // no stack manipulation needed here, this task does not call kbd_process()
 189 void __attribute__((noinline))
 190         mykbd_task(long ua, long ub, long uc, long ud, long ue, long uf)
 191         {
 192     
 193     //create semaphore, empty = not available
 194      semBinary = _semBCreate(SEM_Q_FIFO|SEM_INVERSION_SAFE, SEM_EMPTY);
 195     //lock until 2nd rtask frees it
 196     //_TakeSemaphore(semBinary,WAIT_FOREVER);
 197 
 198     mykbd_task_proceed();
 199 
 200     _ExitTask();
 201         }
 202 
 203 
 204 
 205 long __attribute__((naked,noinline)) wrap_kbd_p1_f()
 206         {
 207         //    kbd_prev_state[0] = kbd_new_state[0];
 208     kbd_prev_state[1] = kbd_new_state[1];
 209         //    kbd_prev_state[2] = kbd_new_state[2];
 210 
 211     asm volatile
 212                 (
 213                                 "STMFD  SP!, {R4,R5,LR}\n" //@ff8308e8
 214                                 "LDR    R3, =0x20F4\n"
 215                                 "SUB    SP, SP, #8\n"
 216                                 "LDR    R2, [R3]\n"
 217                                 "CMP    R2, #1\n"
 218                                 "BEQ    loc_FF830914\n"
 219                                 "MOV    R2, #0x210\n"
 220                                 "LDR    R0, =0xFF8308D0\n"
 221                                 "LDR    R1, =0xFF830000\n"
 222                                 "ADD    R2, R2, #3\n"
 223                                 "BL     sub_FF814C10\n"
 224 
 225                 "loc_FF830914:\n"
 226                                 "LDR    R1, =0x2108\n"
 227                                 "LDR    R2, [R1]\n"
 228                                 "ADD    R3, R2, #0x32\n"
 229                                 "BIC    R4, R3, #0xFF000000\n"
 230                                 "BIC    R4, R4, #0xF00000\n"
 231                                 "CMP    R2, R4\n"
 232                                 "BCS    loc_FF830954\n"
 233                                 "MOV    R5, R1\n"
 234 
 235                 "loc_FF830934:\n"
 236                                 "BL             _GetCurrentMachineTime\n"
 237                                 "CMP    R0, R4\n"
 238                                 "BCS    loc_FF830984\n"
 239                                 "BL             _GetCurrentMachineTime\n"
 240                                 "LDR    R3, [R5]\n"
 241                                 "CMP    R3, R0\n"
 242                                 "BCC    loc_FF830934\n"
 243                                 "B              loc_FF830984\n"
 244 
 245                 "loc_FF830954:\n"
 246                                 "LDR    R2, =0x2108\n"
 247                                 "LDR    R3, [R2]\n"
 248                                 "CMP    R3, R4\n"
 249                                 "BLS    loc_FF830984\n"
 250                                 "MOV    R5, R2\n"
 251 
 252                 "loc_FF830968:\n"
 253                                 "BL             _GetCurrentMachineTime\n"
 254                                 "CMP    R0, R4\n"
 255                                 "BCC    loc_FF830968\n"
 256                                 "BL             _GetCurrentMachineTime\n"
 257                                 "LDR    R3, [R5]\n"
 258                                 "CMP    R3, R0\n"
 259                                 "BCC    loc_FF830968\n"
 260 
 261                 "loc_FF830984:\n"
 262                                 "LDR    R4, =0x11728\n"
 263                                 "MOV    R0, R4\n"
 264                                 "BL             platformsub_kbd_fetch_data_my\n" // (sub_ff830e90) Replaced to a call to my own function..
 265                                 "BL             sub_FF830AB4\n"
 266                                 "BL             sub_FF830B1C\n"
 267                                 "LDR    R3, =0x20F4\n"
 268                                 "MOV    R2, #0\n"
 269                                 "STR    R2, [R3]\n"
 270                                 "BL             sub_FF83103C\n"
 271                                 "LDR    R3, [R4]\n"
 272                                 "CMP    R3, #0\n"
 273                                 "BNE    loc_FF8309CC\n"
 274                                 "LDR    R3, [R4,#4]\n"
 275                                 "CMP    R3, #0\n"
 276                                 "BNE    loc_FF8309CC\n"
 277                                 "LDR    R3, [R4,#8]\n"
 278                                 "CMP    R3, #0\n"
 279                                 "BEQ    loc_FF830A0C\n"
 280 
 281                 "loc_FF8309CC:\n"
 282                                 "LDR    R3, =0x11728\n" // Address of key structure physw_status[]
 283                                 "ADD    R1, R3, #0xC\n"
 284                                 "LDMIA  R1, {R1,R12}\n"
 285                                 "LDR    R2, [R3,#0x14]\n"
 286                                 "LDMIA  R3, {R0,LR}\n"
 287                                 "LDR    R4, [R3,#8]\n"
 288                                 "LDR    R5, =0x11AA0\n"
 289                                 "EOR    R1, R1, R0\n"
 290                                 "EOR    R12, R12, LR\n"
 291                                 "EOR    R2, R2, R4\n"
 292                                 "LDR    R0, [R5]\n"
 293                                 "STR    R2, [R3,#0x14]\n"
 294                                 "STR    R1, [R3,#0xC]\n"
 295                                 "STR    R12, [R3,#0x10]\n"
 296                                 "BL             sub_FF823144\n"
 297                                 "B              loc_FF830A54\n"
 298 
 299                 "loc_FF830A0C:\n"
 300                                 "CMP    R0, #1\n"
 301                                 "BEQ    loc_FF830A24\n"
 302                                 "LDR    R3, =0x20F8\n"
 303                                 "LDR    R2, [R3]\n"
 304                                 "CMP    R2, #2\n"
 305                                 "BEQ    loc_FF830A34\n"
 306 
 307                 "loc_FF830A24:\n"
 308                                 "LDR    R3, =0x11AA0\n"
 309                                 "LDR    R0, [R3]\n"
 310                                 "BL             sub_FF823144\n"
 311                                 "B              loc_FF830A54\n"
 312 
 313                 "loc_FF830A34:\n"
 314                                 "MOV    R0, SP\n"
 315                                 "BL             _GetSystemTime\n"
 316                                 "LDR    R1, =wrap_kbd_p1_f\n" // Replaced with a call to my own function ---------------------------------------------------------------------
 317                                 "LDR    R0, [SP,#0x14-0x14]\n"
 318                                 "MOV    R2, R1\n"
 319                                 "ADD    R0, R0, #0xA\n"
 320                                 "ADD    R3, SP, #0x14-0x10\n"
 321                                 "BL             _SetTimerWhen\n"
 322 
 323                 "loc_FF830A54:\n"
 324                                 "ADD    SP, SP, #8\n"
 325                                 "LDMFD  SP!, {R4,R5,PC}\n"
 326                 );
 327     return 0; // shut up the compiler
 328 }
 329 
 330 
 331 long my_kbd_read_keys(long x){
 332         kbd_new_state[1]=x & 0xFFFF;
 333   
 334   //give semaphore away
 335   _GiveSemaphore(semBinary);
 336   //this should allow other tasks to grab it: (maybe not necessary)
 337   msleep(0);
 338   
 339   //take semaphore again
 340   _TakeSemaphore(semBinary, WAIT_FOREVER); 
 341   //*p2=0;
 342   
 343   //data is now in kbd_data_process_request_data :)
 344   
 345   //if (kbd_process_copy() == 0)
 346   if (kbd_data_process_request_data == 0){
 347                 return x;
 348   }else{
 349     return (kbd_new_state[1]&~KEYS_MASK1) | (kbd_mod_state[1] & KEYS_MASK1);
 350   }
 351                 
 352 }
 353 
 354 void __attribute__((naked,noinline)) platformsub_kbd_fetch_data_my()
 355         {
 356         asm volatile 
 357                 (
 358                 "STMFD  SP!, {R4-R7,LR}\n" //@ff830e90
 359                 "MOV    R12, #0x220000\n"
 360                 "ORR    R3, R12, #0x204\n"
 361                 "SUB    SP, SP, #0xC\n"
 362                 "ORR    R3, R3, #0xC0000000\n"
 363                 //"LDR     R2, [R3]\n"
 364 
 365                 //**********************************************************
 366                 //WE HAVE READ 0xC0220204
 367                 //SEND IT TO usb_power_status_override():
 368                 "MOV     R4, R0\n"
 369                 "LDR     R0, [R3]\n" 
 370                 "STMFD   SP!, {R1-R11}\n"  
 371                 "BL      usb_power_status_override\n"
 372                 "LDMFD   SP!, {R1-R11}\n"
 373                 "MOV     R2, R0\n"
 374                 "MOV     R0, R4\n"
 375                 "MOV     R12, #0x220000\n"      //restore R12
 376                 //EOF CUSTOM CODE
 377                 //**********************************************************
 378         
 379                 //this is original code, process data somehow
 380                 "LDR    LR, =0x11AB0\n"
 381                 "LDR    R3, [R0,#0x28]\n"
 382                 "LDR    R4, [R0,#0x1C]\n"
 383                 "LDR    R5, [LR,#8]\n"
 384                 "LDR    R1, [LR,#0xC]\n"
 385                 "EOR    R2, R2, R3\n"
 386                 "AND    R2, R2, R4\n"
 387                 "LDR    R3, [R0,#0x10]\n"
 388                 "EOR    R7, R2, R1\n"
 389                 "EOR    R6, R2, R5\n"
 390                 "ORR    R1, R6, R7\n"
 391                 "EOR    R3, R3, R2\n"
 392                 "BIC    R3, R3, R1\n"
 393                 "STR    R3, [R0,#4]\n"
 394                 "STR    R2, [LR,#8]\n"
 395                 "STR    R2, [SP,#0x20-0x1C]\n"
 396                 "STR    R5, [LR,#0xC]\n"
 397                 "ORR    R3, R12, #0x208\n"
 398                 "ORR    R3, R3, #0xC0000000\n"
 399                 "LDR    R1, [R3]\n" // The data read goes into R1 here...
 400                 
 401                 //my code inserted there to fool around with the keyboard data values...
 402         "MOV    R2, R0\n"
 403         "MOV    R0, R1\n" // Pass the keyboard data (in R1) to my function via R0
 404         "STMFD  SP!, {R1-R11}\n"
 405         "BL             my_kbd_read_keys\n"
 406         "LDMFD  SP!, {R1-R11}\n"
 407         "MOV    R1,R0\n"
 408         "MOV    R0,R2\n" // restore registers
 409                 "MOV    R12, #0x220000\n"
 410         "LDR    LR, =0x11AB0\n"
 411                 
 412                 // Original code continues
 413                 "MOV    R2, #0xFF00\n"
 414                 "ADD    R2, R2, #0xFF\n"
 415                 "AND    R1, R1, R2\n"
 416                 "STR    R1, [SP,#0x20-0x18]\n"
 417                 "ADD    R12, R12, #0x3000\n"
 418                 "ADD    R2, R12, #0xC000001C\n"
 419                 "LDR    R3, [R2]\n"
 420                 "AND    R3, R3, #1\n"
 421                 "ORR    R1, R1, R3,LSL#16\n"
 422                 "STR    R1, [SP,#0x20-0x18]\n"
 423                 "ADD    R12, R12, #0xC0000024\n"
 424                 "LDR    R3, [R12]\n"
 425                 "LDR    R2, [R0,#0x2C]\n"
 426     //"AND      R3, R3, #1\n"
 427                 "AND  R3, R3, #0\n"    // - clear SD card R/O flag
 428                 "ORR    R1, R1, R3,LSL#17\n"
 429                 "LDR    R12, [R0,#0x20]\n"
 430                 "LDR    R4, [LR,#0x10]\n"
 431                 "EOR    R1, R1, R2\n"
 432                 "LDR    R2, [LR,#0x14]\n"
 433                 "AND    R1, R1, R12\n"
 434                 "LDR    R3, [R0,#0x14]\n"
 435                 "EOR    R7, R1, R2\n"
 436                 "EOR    R6, R1, R4\n"
 437                 "ORR    R2, R6, R7\n"
 438                 "EOR    R3, R3, R1\n"
 439                 "BIC    R3, R3, R2\n"
 440                 "STR    R3, [R0,#8]\n"
 441                 "STR    R1, [LR,#0x10]\n"
 442                 "STR    R4, [LR,#0x14]\n"
 443                 "STR    R1, [SP,#0x20-0x18]\n"
 444                 "ADD    SP, SP, #0xC\n"
 445                 "LDMFD  SP!, {R4-R7,PC}\n"
 446                 );
 447 }
 448 
 449 
 450 /****************/
 451 
 452 // TODO should add forced_usb_port support
 453 int usb_power_status_override(int status){
 454     if (conf.remote_enable) {
 455         return status &~USB_MASK;
 456     }
 457     return status;
 458 }
 459 
 460 
 461 //hack to get a second thread for the keyboard:
 462 //purpose: check if kbd_new_data flag is set 
 463 void kbd_process_task()
 464 {
 465     while(1){
 466         //try to get semaphore
 467         //volatile long *p; p=(void*) 0xc02200E4; *p=0x46;
 468         _TakeSemaphore(semBinary, WAIT_FOREVER);
 469         //*p=0x0;
 470         
 471         //process data & store result
 472         kbd_data_process_request_data = kbd_process(); //kbd_process_copy();
 473         
 474         //give semaphore
 475         //volatile long *p2; p2=(void*) 0xc02200E0; *p2=0x46;
 476         _GiveSemaphore(semBinary);
 477         //*p2=0x0;
 478         
 479         //sleep to allow other task to grab it
 480         msleep(10);
 481     }
 482 }

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