root/platform/a470/kbd.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_usb_bit
  2. mykbd_task
  3. wrap_kbd_p1_f
  4. my_kbd_read_keys
  5. enable_extra_button
  6. kbd_set_extra_button
  7. kbd_fetch_data

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 #include "core.h"
   4 #include "keyboard.h"
   5 #include "conf.h"
   6 #include "kbd_common.h"
   7 
   8 KeyMap keymap[] = {
   9     /* tiny bug: key order matters. see kbd_get_pressed_key()
  10      * for example
  11      */
  12 //  { 1, KEY_POWER      ,     0x04000000 }, // levent 0x600 (uses inverted logic in physw_status)
  13     { 2, KEY_UP         ,     0x00000001 },
  14     { 2, KEY_DOWN       ,     0x00000002 },
  15     { 2, KEY_LEFT       ,     0x00000008 },
  16     { 2, KEY_RIGHT      ,     0x00000004 },
  17     { 2, KEY_SET        ,     0x00000100 },
  18     { 2, KEY_SHOOT_FULL ,     0x00000030 },
  19     { 2, KEY_SHOOT_FULL_ONLY, 0x00000020 },
  20     { 2, KEY_SHOOT_HALF ,     0x00000010 },
  21     { 2, KEY_MENU       ,     0x00000400 },
  22     { 2, KEY_PRINT      ,     0x00001000 },
  23     { 0, 0, 0 }, // placeholder for fake key
  24     { 0, 0, 0 }
  25 };
  26 
  27 long kbd_new_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  28 long kbd_prev_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  29 long kbd_mod_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  30 
  31 int keys_mask1 = 0x00000000;
  32 int keys_inv1 = 0x00000000;
  33 static int set_fake_key=0;
  34 
  35 int get_usb_bit() 
  36 {
  37         long usb_physw[3];
  38         usb_physw[USB_IDX] = 0;
  39         _kbd_read_keys_r2(usb_physw);
  40         return(( usb_physw[USB_IDX] & USB_MASK)==USB_MASK) ; 
  41 }
  42 
  43 void kbd_fetch_data(long*);
  44 
  45 
  46 long __attribute__((naked)) wrap_kbd_p1_f() ;
  47 
  48 
  49 // task created directly, stack manipulation is not needed
  50 void __attribute__((naked,noinline))
  51 mykbd_task(long ua, long ub, long uc, long ud, long ue, long uf)
  52 {
  53     (void)ua; (void)ub; (void)uc; (void)ud; (void)ue; (void)uf;
  54 
  55     kbd_new_state[0] = physw_status[0];
  56     kbd_new_state[1] = physw_status[1] ^ keys_inv1;
  57     kbd_new_state[2] = physw_status[2];
  58 
  59     while (physw_run){
  60         _SleepTask(10);
  61 
  62         if (wrap_kbd_p1_f() == 1){ // autorepeat ?
  63             _kbd_p2_f();
  64         }
  65     }
  66 
  67     _ExitTask();
  68 }
  69 
  70 
  71 long __attribute__((naked,noinline)) wrap_kbd_p1_f()
  72 {
  73 
  74     asm volatile(
  75                 "STMFD   SP!, {R1-R5,LR}\n"
  76                 "MOV     R4, #0\n"
  77                 "BL      my_kbd_read_keys\n"
  78                 "B       _kbd_p1_f_cont\n"
  79     );
  80     return 0; // shut up the compiler
  81 }
  82 
  83 void enable_extra_button(short);
  84 
  85 void my_kbd_read_keys()
  86 {
  87     kbd_prev_state[0] = kbd_new_state[0];
  88     kbd_prev_state[1] = kbd_new_state[1];
  89     kbd_prev_state[2] = kbd_new_state[2];
  90 
  91     kbd_fetch_data(kbd_new_state);
  92 
  93     kbd_new_state[1] = kbd_new_state[1] ^ keys_inv1;
  94     
  95     if (kbd_process() == 0){
  96         // leave it alone...
  97         physw_status[0] = kbd_new_state[0];
  98         physw_status[1] = kbd_new_state[1] ^ keys_inv1;
  99         physw_status[2] = kbd_new_state[2];
 100     } else {
 101         // override keys
 102         physw_status[0] = (kbd_new_state[0] & (~KEYS_MASK0)) |
 103                           (kbd_mod_state[0] & KEYS_MASK0);
 104 
 105         physw_status[1] = ((kbd_new_state[1] & (~KEYS_MASK1)) |
 106                           (kbd_mod_state[1] & KEYS_MASK1)) ^ keys_inv1;
 107 
 108         physw_status[2] = (kbd_new_state[2] & (~KEYS_MASK2)) |
 109                           (kbd_mod_state[2] & KEYS_MASK2);
 110     }
 111 
 112     _kbd_read_keys_r2(physw_status);
 113 
 114     // usb and SD read-only are standard
 115     kbd_update_physw_bits();
 116 
 117     if (set_fake_key & 0x10000000) {
 118         enable_extra_button((short)(set_fake_key & 0xffff));
 119         set_fake_key=0;
 120     }
 121 }
 122 
 123 
 124 void enable_extra_button(short key) {
 125 /*
 126  * enable or disable the additional "fake" button
 127  * in this case, the power button will be re-mapped in ALT mode
 128  * called from the kbd task
 129  * beware: the "placeholder" in keymap[] is directly addressed here
 130  * the placeholder has to be the last entry before the terminating { 0, 0, 0 }, if it is ever set to { 0, 0, 0 }
 131  */
 132     if (key) {
 133         keys_mask1=0x04000000;
 134         keys_inv1= 0x04000000;
 135         keymap[10].grp=1;
 136         keymap[10].canonkey=0x04000000;
 137         keymap[10].hackkey=key;
 138     }
 139     else {
 140         keys_mask1=0x00000000;
 141         keys_inv1= 0x00000000;
 142         keymap[10].grp=0;
 143         keymap[10].canonkey=0;
 144         keymap[10].hackkey=0;
 145     }
 146 }
 147 
 148 void kbd_set_extra_button(short key) { // called by core
 149     set_fake_key=key|0x10000000;    
 150 }
 151 
 152 void kbd_fetch_data(long *dst)
 153 {
 154     volatile long *mmio0 = (void*)0xc0220200;
 155     volatile long *mmio1 = (void*)0xc0220204;
 156     volatile long *mmio2 = (void*)0xc0220208;
 157 
 158     dst[0] = *mmio0;
 159     dst[1] = *mmio1;
 160     dst[2] = *mmio2 & 0xffff;
 161 }

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