root/platform/g5x/kbd.c

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

DEFINITIONS

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

   1 
   2 #include "lolevel.h"
   3 #include "platform.h"
   4 #include "keyboard.h"
   5 #include "kbd_common.h"
   6 
   7 long kbd_new_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
   8 long kbd_prev_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
   9 long kbd_mod_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  10 
  11 extern void _GetKbdState(long*);
  12 
  13 int get_usb_bit()
  14 {
  15     long usb_physw[3];
  16     usb_physw[USB_IDX] = 0;
  17     _kbd_read_keys_r2(usb_physw);
  18     return ((usb_physw[USB_IDX] & USB_MASK)==USB_MASK);
  19 }
  20 
  21 KeyMap keymap[] = {
  22     { 0, KEY_SHOOT_FULL_ONLY ,0x00000001 },
  23     { 0, KEY_ZOOM_OUT        ,0x00000002 },
  24     { 0, KEY_ZOOM_IN         ,0x00000004 },
  25     { 0, KEY_VIDEO           ,0x00000008 },
  26     { 0, KEY_MENU            ,0x00000010 },
  27     { 0, KEY_UP              ,0x00000020 },
  28     { 0, KEY_DOWN            ,0x00000040 },
  29     { 0, KEY_RIGHT           ,0x00000080 },
  30     { 0, KEY_LEFT            ,0x00000100 },
  31     { 0, KEY_SET             ,0x00000200 },
  32     { 0, KEY_ERASE           ,0x00000400 },
  33     { 0, KEY_PLAYBACK        ,0x00000800 },
  34     { 0, KEY_WIFI            ,0x00010000 },
  35     { 0, KEY_POWER           ,0x00020000 },
  36     { 0, KEY_SHOOT_HALF      ,0x00040000 },
  37     { 0, KEY_SHOOT_FULL      ,0x00040001 },
  38     { 1, KEY_DISPLAY         ,0x00000010 },
  39     { 0, 0, 0 }
  40 };
  41 
  42 long __attribute__((naked,noinline)) wrap_kbd_p1_f()
  43 {
  44     asm volatile(
  45         "push    {r1-r7, lr}\n"
  46         "movs    r4, #0\n"
  47         "bl      my_kbd_read_keys\n"
  48         "b       kbd_p1_f_cont_my\n"
  49     );
  50 
  51     return 0;
  52 }
  53 
  54 // no stack manipulation needed here, since we create the task directly
  55 void __attribute__((naked,noinline)) mykbd_task()
  56 {
  57     extern void kbd_p2_f_my();
  58 
  59     while (physw_run)
  60     {
  61         _SleepTask(physw_sleep_delay);
  62 
  63         if (wrap_kbd_p1_f() == 1)
  64         {
  65             kbd_p2_f_my();
  66         }
  67     }
  68 
  69     _ExitTask();
  70 }
  71 
  72 #define DIAL_HW_FRONT 1     // Front dial
  73 #define DIAL_HW_REAR  4     // Rear dial
  74 #define DIAL_HW_RING  5     // Lens control ring
  75 
  76 int jogdial_stopped = 0;
  77 extern long dial_positions[6];
  78 
  79 int get_dial_hw_position(int dial)
  80 {
  81     // mask low bits
  82     extern int _get_dial_hw_position(int dial);
  83     return _get_dial_hw_position(dial) & ~3;
  84 }
  85 
  86 long get_jogdial_direction(void)
  87 {
  88     static int new_jogdial = 0, old_jogdial = 0, new_frontdial = 0, old_frontdial = 0;
  89     
  90     old_jogdial = new_jogdial;
  91     new_jogdial = get_dial_hw_position(DIAL_HW_REAR);
  92 
  93     old_frontdial = new_frontdial;
  94     new_frontdial = get_dial_hw_position(DIAL_HW_FRONT);
  95 
  96     if (old_jogdial > new_jogdial) return JOGDIAL_LEFT;
  97     else if (old_jogdial < new_jogdial) return JOGDIAL_RIGHT;
  98     if (old_frontdial > new_frontdial) return FRONTDIAL_LEFT;  // counter clockwise with camera aimed away from you
  99     else if (old_frontdial < new_frontdial) return FRONTDIAL_RIGHT;
 100     else return 0;
 101 }
 102 
 103 int handle_jogdial()
 104 {
 105     // return 0 to prevent fw dial handler
 106     if (jogdial_stopped)
 107     {
 108         // update positions in RAM
 109         dial_positions[0] = dial_positions[3] = get_dial_hw_position(DIAL_HW_REAR);
 110         dial_positions[1] = dial_positions[4] = get_dial_hw_position(DIAL_HW_RING);
 111         dial_positions[2] = dial_positions[5] = get_dial_hw_position(DIAL_HW_FRONT);
 112         return 0;
 113     }
 114     return 1;
 115 }
 116 
 117 void jogdial_control(int c)
 118 {
 119     jogdial_stopped = c;
 120 }
 121 
 122 int physw0_override;
 123 
 124 void my_kbd_read_keys()
 125 {
 126     if (kbd_update_key_state())
 127         physw0_override = physw_status[0];
 128     else
 129         physw0_override = -1;
 130     kbd_update_physw_bits();
 131 }
 132 
 133 void kbd_fetch_data(long *dst)
 134 {
 135     _GetKbdState(dst);
 136     _kbd_read_keys_r2(dst);
 137 }

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