root/platform/a430/kbd.c

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

DEFINITIONS

This source file includes following definitions.
  1. mykbd_task_proceed
  2. mykbd_task
  3. my_kbd_read_keys
  4. wrap_kbd_p1_f
  5. 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 
  11 KeyMap keymap[] = {
  12     /* tiny bug: key order matters. see kbd_get_pressed_key()
  13      * for example
  14      */
  15     {2, KEY_UP              , 0x00000001 }, // KEY_UP/KEY_ZOOM_IN 
  16     {2, KEY_DOWN            , 0x00000002 }, // KEY_DOWN/KEY_ZOOM_OUT/KEY_ERASE
  17     {2, KEY_LEFT            , 0x00000008 },
  18     {2, KEY_RIGHT           , 0x00000004 },
  19     {2, KEY_SET             , 0x00000100 },
  20     {2, KEY_SHOOT_FULL      , 0x00000030 }, // note 3 here!
  21     {2, KEY_SHOOT_FULL_ONLY , 0x00000020 },
  22     {2, KEY_SHOOT_HALF      , 0x00000010 },
  23     {2, KEY_MENU            , 0x00000400 },
  24     {2, KEY_DISPLAY         , 0x00000200 },
  25     {2, KEY_PRINT           , 0x00001000 },
  26     {0, 0, 0 }
  27 };
  28 
  29 #define NEW_SS (0x2000)
  30 
  31 static char kbd_stack[NEW_SS];
  32 
  33 long __attribute__((naked)) wrap_kbd_p1_f() ;
  34 
  35 static void __attribute__((noinline)) mykbd_task_proceed()
  36 {
  37     while (physw_run){
  38         _SleepTask(10);
  39 
  40         if (wrap_kbd_p1_f() == 1){ // autorepeat ?
  41             _kbd_p2_f();
  42         }
  43     }
  44 }
  45 
  46 // TODO using C code in naked is unsafe
  47 void __attribute__((naked,noinline)) mykbd_task()
  48 {
  49     /* WARNING
  50      * Stack pointer manipulation performed here!
  51      * This means (but not limited to):
  52      *        function arguments destroyed;
  53      *        function CAN NOT return properly;
  54      *        MUST NOT call or use stack variables before stack
  55      *        is setup properly;
  56      *
  57      */
  58 
  59     register int i;
  60     register long *newstack;
  61 
  62     newstack = (void*)kbd_stack;
  63 
  64     for (i=0;i<NEW_SS/4;i++)
  65         newstack[i]=0xdededede;
  66 
  67     asm volatile (
  68         "MOV        SP, %0"
  69         :: "r"(((char*)newstack)+NEW_SS)
  70         : "memory"
  71     );
  72 
  73     mykbd_task_proceed();
  74 
  75     /* function can be modified to restore SP here...
  76      */
  77 
  78     _ExitTask();
  79 }
  80 
  81 void my_kbd_read_keys()
  82 {
  83     _kbd_pwr_on();
  84 
  85     kbd_update_key_state();
  86 
  87     _kbd_read_keys_r2(physw_status);
  88 
  89     kbd_update_physw_bits();
  90 
  91     _kbd_pwr_off();
  92 }
  93 
  94 long __attribute__((naked,noinline)) wrap_kbd_p1_f()
  95 {
  96 
  97     asm volatile(
  98                 "STMFD   SP!, {R4-R7,LR}\n"
  99                 "SUB     SP, SP, #0xC\n"
 100                 "BL      my_kbd_read_keys\n"
 101                 "B         _kbd_p1_f_cont\n"
 102     );
 103     return 0; // shut up the compiler
 104 }
 105 
 106 void kbd_fetch_data(long *dst)
 107 {
 108     volatile long *mmio0 = (void*)0xc0220200;
 109     volatile long *mmio1 = (void*)0xc0220204;
 110     volatile long *mmio2 = (void*)0xc0220208;
 111 
 112     dst[0] = *mmio0;
 113     dst[1] = *mmio1;
 114     dst[2] = *mmio2 & 0xffff;
 115 }
 116 

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