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 
  54     kbd_new_state[0] = physw_status[0];
  55     kbd_new_state[1] = physw_status[1] ^ keys_inv1;
  56     kbd_new_state[2] = physw_status[2];
  57 
  58     while (physw_run){
  59         _SleepTask(10);
  60 
  61         if (wrap_kbd_p1_f() == 1){ // autorepeat ?
  62             _kbd_p2_f();
  63         }
  64     }
  65 
  66     _ExitTask();
  67 }
  68 
  69 
  70 long __attribute__((naked,noinline)) wrap_kbd_p1_f()
  71 {
  72 
  73     asm volatile(
  74                 "STMFD   SP!, {R1-R5,LR}\n"
  75                 "MOV     R4, #0\n"
  76                 "BL      my_kbd_read_keys\n"
  77                 "B       _kbd_p1_f_cont\n"
  78     );
  79     return 0; // shut up the compiler
  80 }
  81 
  82 void enable_extra_button(short);
  83 
  84 void my_kbd_read_keys()
  85 {
  86     kbd_prev_state[0] = kbd_new_state[0];
  87     kbd_prev_state[1] = kbd_new_state[1];
  88     kbd_prev_state[2] = kbd_new_state[2];
  89 
  90     kbd_fetch_data(kbd_new_state);
  91 
  92     kbd_new_state[1] = kbd_new_state[1] ^ keys_inv1;
  93     
  94     if (kbd_process() == 0){
  95         // leave it alone...
  96         physw_status[0] = kbd_new_state[0];
  97         physw_status[1] = kbd_new_state[1] ^ keys_inv1;
  98         physw_status[2] = kbd_new_state[2];
  99     } else {
 100         // override keys
 101         physw_status[0] = (kbd_new_state[0] & (~KEYS_MASK0)) |
 102                           (kbd_mod_state[0] & KEYS_MASK0);
 103 
 104         physw_status[1] = ((kbd_new_state[1] & (~KEYS_MASK1)) |
 105                           (kbd_mod_state[1] & KEYS_MASK1)) ^ keys_inv1;
 106 
 107         physw_status[2] = (kbd_new_state[2] & (~KEYS_MASK2)) |
 108                           (kbd_mod_state[2] & KEYS_MASK2);
 109     }
 110 
 111     _kbd_read_keys_r2(physw_status);
 112 
 113     // usb and SD read-only are standard
 114     kbd_update_physw_bits();
 115 
 116     if (set_fake_key & 0x10000000) {
 117         enable_extra_button((short)(set_fake_key & 0xffff));
 118         set_fake_key=0;
 119     }
 120 }
 121 
 122 
 123 void enable_extra_button(short key) {
 124 /*
 125  * enable or disable the additional "fake" button
 126  * in this case, the power button will be re-mapped in ALT mode
 127  * called from the kbd task
 128  * beware: the "placeholder" in keymap[] is directly addressed here
 129  * the placeholder has to be the last entry before the terminating { 0, 0, 0 }, if it is ever set to { 0, 0, 0 }
 130  */
 131     if (key) {
 132         keys_mask1=0x04000000;
 133         keys_inv1= 0x04000000;
 134         keymap[10].grp=1;
 135         keymap[10].canonkey=0x04000000;
 136         keymap[10].hackkey=key;
 137     }
 138     else {
 139         keys_mask1=0x00000000;
 140         keys_inv1= 0x00000000;
 141         keymap[10].grp=0;
 142         keymap[10].canonkey=0;
 143         keymap[10].hackkey=0;
 144     }
 145 }
 146 
 147 void kbd_set_extra_button(short key) { // called by core
 148     set_fake_key=key|0x10000000;    
 149 }
 150 
 151 void kbd_fetch_data(long *dst)
 152 {
 153     volatile long *mmio0 = (void*)0xc0220200;
 154     volatile long *mmio1 = (void*)0xc0220204;
 155     volatile long *mmio2 = (void*)0xc0220208;
 156 
 157     dst[0] = *mmio0;
 158     dst[1] = *mmio1;
 159     dst[2] = *mmio2 & 0xffff;
 160 }

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