root/platform/sx710hs/kbd.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_usb_bit
  2. get_hdmi_hpd_bit
  3. get_analog_av_bit
  4. wrap_kbd_p1_f
  5. mykbd_task
  6. get_dial_hw_position
  7. get_jogdial_direction
  8. handle_jogdial
  9. jogdial_control
  10. my_kbd_read_keys
  11. 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 extern void _GetKbdState(long*);
  11 
  12 int get_usb_bit() {
  13     long usb_physw[3];
  14     usb_physw[USB_IDX] = 0;
  15     _kbd_read_keys_r2(usb_physw);
  16     return(( usb_physw[USB_IDX] & USB_MASK)==USB_MASK) ;
  17 }
  18 
  19 int get_hdmi_hpd_bit() {
  20     long hpd_physw[3];
  21     hpd_physw[HDMI_HPD_IDX] = 0;
  22     _GetKbdState(hpd_physw);
  23     return( ((hpd_physw[HDMI_HPD_IDX] & HDMI_HPD_FLAG)==HDMI_HPD_FLAG)?0:1) ;
  24 }
  25 
  26 int get_analog_av_bit() {
  27     long av_physw[3];
  28     av_physw[ANALOG_AV_IDX] = 0;
  29     _GetKbdState(av_physw);
  30     return( ((av_physw[ANALOG_AV_IDX] & ANALOG_AV_FLAG)==ANALOG_AV_FLAG)?0:1) ;
  31 }
  32 
  33 KeyMap keymap[] = {
  34 //    { 0, KEY_POWER           ,0x00000001 }, // Found @0xfc5bfa70, levent 0x100
  35     { 0, KEY_PLAYBACK        ,0x00000002 }, // Found @0xfc5bfa78, levent 0x101
  36     { 0, KEY_SHOOT_FULL      ,0x0000000c }, // Found @0xfc5bfa88, levent 0x01
  37     { 0, KEY_SHOOT_FULL_ONLY ,0x00000008 }, // Found @0xfc5bfa88, levent 0x01
  38     { 0, KEY_SHOOT_HALF      ,0x00000004 }, // Found @0xfc5bfa80, levent 0x00
  39     { 0, KEY_VIDEO           ,0x00000100 }, // Found @0xfc5bfa98, levent 0x02
  40     { 0, KEY_MENU            ,0x00000200 }, // Found @0xfc5bfaa0, levent 0x14
  41     { 0, KEY_DISPLAY         ,0x00002000 }, // was detected as HELP, Found @0xfc5bfaa8, levent 0x0d
  42     { 0, KEY_UP              ,0x00004000 }, // Found @0xfc5bfab0, levent 0x06
  43     { 0, KEY_DOWN            ,0x00008000 }, // Found @0xfc5bfab8, levent 0x07
  44     { 0, KEY_RIGHT           ,0x00010000 }, // Found @0xfc5bfac0, levent 0x09
  45     { 1, KEY_LEFT            ,0x00000004 }, // Found @0xfc5bfac8, levent 0x08
  46     { 1, KEY_SET             ,0x00000008 }, // Found @0xfc5bfad0, levent 0x0a
  47     { 1, KEY_WIFI            ,0x00000020 },
  48     { 1, KEY_FRAMING_ASSIST  ,0x00000400 },
  49     { 2, KEY_ZOOM_IN         ,0x00000002 }, // full speed
  50     { 2, KEY_ZOOM_IN         ,0x00000004 }, // low speed
  51     { 2, KEY_ZOOM_OUT        ,0x00000008 }, // full speed
  52     { 2, KEY_ZOOM_OUT        ,0x00000010 }, // low speed
  53     { 0, 0, 0 }
  54 };
  55 
  56 // flash open word 1, 0x00000200 = open
  57 // no battery door switch, cam runs with door open, no physw change
  58 
  59 long __attribute__((naked,noinline)) wrap_kbd_p1_f() {
  60 
  61     asm volatile(
  62         "push    {r1-r7, lr}\n"
  63         "movs    r4, #0\n"
  64         "bl      my_kbd_read_keys\n"
  65         "b       _kbd_p1_f_cont\n"
  66     );
  67 
  68     return 0;
  69 }
  70 
  71 // no stack manipulation needed here, since we create the task directly
  72 void __attribute__((noinline)) mykbd_task() {
  73     extern void kbd_p2_f_my();
  74 
  75     while (physw_run) {
  76         _SleepTask(physw_sleep_delay);
  77 
  78         if (wrap_kbd_p1_f() == 1) {
  79 #ifdef CAM_HAS_JOGDIAL
  80             kbd_p2_f_my();                      // replacement of _kbd_p2_f (in sub/<fwver>/boot.c)
  81 #else
  82             _kbd_p2_f();
  83 #endif
  84         }
  85     }
  86 
  87     _ExitTask();
  88 }
  89 
  90 // jogdial hw counters (19 bits) are at 0xd9854004 and 0xd9855004, use fw func to read + sign extend them
  91 // 0x7fff8 .. 0x7fffc .. 0 (start pos) .. 4
  92 // intermediate positions are also available, but they are ignored by the fw for a good reason
  93 #ifdef CAM_HAS_JOGDIAL
  94 extern int _get_dial_hw_position(int dial);
  95 #define DIAL_HW_REAR  4
  96 int get_dial_hw_position(int dial)
  97 {
  98     // mask low bits
  99     return _get_dial_hw_position(dial)&~3;
 100 }
 101 int jogdial_stopped=0;
 102 
 103 extern long dial_positions[2];
 104 
 105 long get_jogdial_direction(void) {
 106     static int new_jogdial=0, old_jogdial=0;
 107     
 108     old_jogdial=new_jogdial;
 109     new_jogdial=get_dial_hw_position(DIAL_HW_REAR);
 110 
 111     if (old_jogdial>new_jogdial) return JOGDIAL_RIGHT; 
 112     else if (old_jogdial<new_jogdial) return JOGDIAL_LEFT;
 113     else return 0;
 114 }
 115 
 116 int handle_jogdial() {
 117     // return 0 to prevent fw dial handler
 118     if (jogdial_stopped) {
 119         // update positions in RAM
 120         dial_positions[0] = dial_positions[1] = get_dial_hw_position(DIAL_HW_REAR);
 121         return 0;
 122     }
 123     return 1;
 124 }
 125 
 126 void jogdial_control(int c) {
 127     jogdial_stopped = c;
 128 }
 129 #endif
 130 
 131 void my_kbd_read_keys() {
 132     kbd_update_key_state();
 133     kbd_update_physw_bits();
 134 }
 135 
 136 void kbd_fetch_data(long *dst)
 137 {
 138     _GetKbdState(dst);
 139     _kbd_read_keys_r2(dst);
 140 }

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