source: trunk/platform/sx230hs/kbd.c @ 1786

Revision 1786, 9.8 KB checked in by msl, 15 months ago (diff)

ALT button SX220/230

+ Change default button for ALT mode: playback button [>]

  • Delete combination [DISP. + SET] for ALT button
  • Property svn:eol-style set to native
Line 
1#include "stdlib.h"
2#include "lolevel.h"
3#include "platform.h"
4#include "core.h"
5#include "keyboard.h"
6#include "conf.h"
7#include "../../core/gui_draw.h"
8
9void keys_new();
10typedef struct {
11    short grp;
12    short hackkey;
13    long canonkey;
14} KeyMap;
15
16static long kbd_new_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
17static long kbd_prev_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
18static long kbd_mod_state[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
19
20static KeyMap keymap[];
21static long last_kbd_key = 0;
22static int alt_mode_led=0;
23extern void _GetKbdState(long*);
24
25#ifdef CAM_HAS_GPS
26extern int Taste_Funktion;
27extern int Taste_Taste;
28extern int Taste_Druck;
29extern int Taste_press;
30#endif
31
32// override key and feather bits to avoid feather osd messing up chdk display in ALT mode
33#define KEYS_MASK0 (0x000FFC0F)     // physw_status[0] was 7FC05
34#define KEYS_MASK1 (0x00200000)
35#define KEYS_MASK2 (0x00002182) 
36
37#define NEW_SS (0x2000)
38
39#define SD_READONLY_FLAG (0x20000)
40#define SD_READONLY_IDX     2
41
42#define USB_MASK (0x4000000)
43#define USB_IDX  2
44
45extern void usb_remote_key( int ) ;
46int get_usb_bit()
47{
48        long usb_physw[3];
49        usb_physw[USB_IDX] = 0;
50        _kbd_read_keys_r2(usb_physw);
51        return(( usb_physw[USB_IDX] & USB_MASK)==USB_MASK) ;
52}
53
54#ifndef MALLOCD_STACK
55static char kbd_stack[NEW_SS];
56#endif
57
58static KeyMap keymap[] = {
59
60    { 0, KEY_ZOOM_OUT        , 0x00000001 },
61    { 0, KEY_ZOOM_OUT1       , 0x00000001 },
62    { 0, KEY_ZOOM_OUT        , 0x00000002 },
63    { 0, KEY_ZOOM_OUT3       , 0x00000002 },
64    { 0, KEY_ZOOM_OUT        , 0x00000003 },
65    { 0, KEY_ZOOM_OUT2       , 0x00000003 },
66    { 0, KEY_ZOOM_IN         , 0x00000004 },
67    { 0, KEY_ZOOM_IN1        , 0x00000004 },
68    { 0, KEY_ZOOM_IN         , 0x00000008 },
69    { 0, KEY_ZOOM_IN3        , 0x00000008 },
70    { 0, KEY_ZOOM_IN         , 0x0000000C },
71    { 0, KEY_ZOOM_IN2        , 0x0000000C },
72    { 0, KEY_UP_SOFT         , 0x00000400 },
73    { 0, KEY_DISPLAY         , 0x00000800 },
74    { 0, KEY_UP              , 0x00001000 },
75    { 0, KEY_RIGHT_SOFT      , 0x00002000 },
76    { 0, KEY_RIGHT           , 0x00006000 },
77    { 0, KEY_DOWN_SOFT       , 0x00008000 },
78    { 0, KEY_SET             , 0x00010000 },
79    { 0, KEY_DOWN            , 0x00020000 },
80    { 0, KEY_MENU            , 0x00040000 },
81    { 0, KEY_VIDEO           , 0x00080000 },
82
83    { 1, KEY_PRINT           , 0x00200000 }, // playback = alt button
84    { 1, KEY_PLAYBACK        , 0x00200000 },
85
86    { 2, KEY_LEFT_SOFT       , 0x00000080 },
87    { 2, KEY_LEFT            , 0x00000100 },
88    { 2, KEY_SHOOT_FULL      , 0x00002002 },
89    { 2, KEY_SHOOT_FULL_ONLY , 0x00000002 },
90    { 2, KEY_SHOOT_HALF      , 0x00002000 },
91
92    { 0, 0, 0 }
93};
94
95// NOP
96void kbd_set_alt_mode_key_mask(long key)
97{
98}
99
100void my_blinkk(void) {
101        int i;
102        while(1) {
103                *((volatile int *) 0xC0220130) = 0x46; // Turn on LED
104                for (i=0; i<0x200000; i++) { asm volatile ( "nop\n" ); }
105
106                *((volatile int *) 0xC0220130) = 0x44; // Turn off LED
107                for (i=0; i<0x200000; i++) { asm volatile ( "nop\n" ); }
108
109                *((volatile int *) 0xC0220130) = 0x46; // Turn on LED
110                for (i=0; i<0x200000; i++) { asm volatile ( "nop\n" ); }
111
112                *((volatile int *) 0xC0220130) = 0x44; // Turn off LED
113                for (i=0; i<0x900000; i++) { asm volatile ( "nop\n" ); }
114        }
115}
116
117volatile int jogdial_stopped=0;
118
119extern long __attribute__((naked)) wrap_kbd_p1_f();
120
121
122static void __attribute__((noinline)) mykbd_task_proceed() {
123       
124        while (physw_run) {
125        _SleepTask(*((int*)(0x1c44 +0x8))); //  @FF0248AC
126
127                if (wrap_kbd_p1_f() == 1) {   // autorepeat ?
128                _kbd_p2_f();
129        }
130    }
131}
132
133// no stack manipulation needed here, since we create the task directly
134void __attribute__((naked,noinline)) mykbd_task() {
135        mykbd_task_proceed();
136
137// function can be modified to restore SP here...
138        _ExitTask();
139}
140
141// copied from g12 and sx30, thx to philmoz
142// Pointer to stack location where jogdial task records previous and current
143// jogdial positions
144
145extern short* jog_position;
146
147void jogdial_control(int n)
148{
149    if (jogdial_stopped && !n)
150    {
151        // If re-enabling jogdial set the task code current & previous positions to the actual
152        // dial positions so that the change won't get processed by the firmware
153        jog_position[0] = jog_position[2] = (*(short*)0xC0240106);  // Rear dial
154    }
155    jogdial_stopped = n;
156}
157
158// like SX110
159void my_kbd_read_keys() {
160               
161
162    kbd_prev_state[0] = kbd_new_state[0];
163    kbd_prev_state[1] = kbd_new_state[1];
164    kbd_prev_state[2] = kbd_new_state[2];
165
166        _GetKbdState( kbd_new_state );
167        _kbd_read_keys_r2( kbd_new_state);
168
169#ifdef CAM_HAS_GPS
170        if (Taste_Funktion != 0)
171        {
172                if (Taste_Taste == kbd_get_pressed_key())
173                {
174                        Taste_Druck=1;
175                        kbd_key_release(Taste_Taste);
176                        kbd_key_press(0);
177                        Taste_Funktion=0;
178                        Taste_Taste=0;
179                        msleep(1000);
180                        }
181        }
182#endif 
183//    kbd_new_state[0] = physw_status[0];  //sx220 changed from physw_status[0]
184 //   kbd_new_state[2] = physw_status[2];
185 //   kbd_new_state[3] = physw_status[3]; //sx220 added
186
187    if (kbd_process() == 0) {
188        // we read keyboard state with _kbd_read_keys()
189                physw_status[0] = kbd_new_state[0];
190                physw_status[1] = kbd_new_state[1];
191                physw_status[2] = kbd_new_state[2];             
192                jogdial_control(0);
193    } else {
194        // override keys
195        physw_status[0] = (kbd_new_state[0] | KEYS_MASK0) & (~KEYS_MASK0 | kbd_mod_state[0]);
196        physw_status[1] = (kbd_new_state[1] | KEYS_MASK1) & (~KEYS_MASK1 | kbd_mod_state[1]);
197        physw_status[2] = (kbd_new_state[2] | KEYS_MASK2) & (~KEYS_MASK2 | kbd_mod_state[2]);
198
199        if ((jogdial_stopped==0) && !state_kbd_script_run) {
200            jogdial_control(1);
201            get_jogdial_direction();
202        }
203        else if (jogdial_stopped && state_kbd_script_run)
204            jogdial_control(0);
205    }
206
207        usb_remote_key(physw_status[USB_IDX]) ;
208
209        if (conf.remote_enable) {
210                physw_status[USB_IDX] = physw_status[USB_IDX] & ~(SD_READONLY_FLAG | USB_MASK);
211        } else {
212                physw_status[USB_IDX] = physw_status[USB_IDX] & ~SD_READONLY_FLAG;
213        }
214
215}
216
217
218void kbd_key_press(long key) {
219   
220        int i;
221    for (i=0;keymap[i].hackkey;i++){
222        if (keymap[i].hackkey == key){
223            kbd_mod_state[keymap[i].grp] &= ~keymap[i].canonkey;
224            return;
225        }
226    }
227}
228
229void kbd_key_release(long key) {
230 
231   int i;
232    for (i=0;keymap[i].hackkey;i++) {
233        if (keymap[i].hackkey == key){
234            kbd_mod_state[keymap[i].grp] |= keymap[i].canonkey;
235            return;
236        }
237    }
238}
239
240void kbd_key_release_all() {
241   
242        kbd_mod_state[0] |= KEYS_MASK0;
243    kbd_mod_state[1] |= KEYS_MASK1;
244    kbd_mod_state[2] |= KEYS_MASK2;
245}
246
247long kbd_is_key_pressed(long key) {
248 
249        int i;
250    for (i=0;keymap[i].hackkey;i++) {
251        if (keymap[i].hackkey == key) {
252            return ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0) ? 1:0;
253        }
254    }
255    return 0;
256}
257
258long kbd_is_key_clicked(long key) {
259   
260        int i;
261    for (i=0;keymap[i].hackkey;i++) {
262        if (keymap[i].hackkey == key){
263            return ((kbd_prev_state[keymap[i].grp] & keymap[i].canonkey) != 0) &&
264                ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0);
265        }
266    }
267    return 0;
268}
269
270long kbd_get_pressed_key() {
271   
272        int i;
273    for (i=0;keymap[i].hackkey;i++) {
274        if ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0) {
275            return keymap[i].hackkey;
276        }
277    }
278    return 0;
279}
280
281long kbd_get_clicked_key() {
282
283   int i;
284    for (i=0;keymap[i].hackkey;i++) {
285        if (((kbd_prev_state[keymap[i].grp] & keymap[i].canonkey) != 0) && ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0)) {
286            return keymap[i].hackkey;
287        }
288    }
289    return 0;
290}
291
292void kbd_reset_autoclicked_key() {
293
294        last_kbd_key = 0;
295}
296
297long kbd_get_autoclicked_key() {
298   
299        static long last_kbd_time = 0, press_count = 0;
300    register long key, t;
301
302    key=kbd_get_clicked_key();
303    if (key) {
304        last_kbd_key = key;
305        press_count = 0;
306        last_kbd_time = get_tick_count();
307        return key;
308    } else {
309        if (last_kbd_key && kbd_is_key_pressed(last_kbd_key)) {
310            t = get_tick_count();
311            if (t-last_kbd_time>((press_count)?175:500)) {
312                ++press_count;
313                last_kbd_time = t;
314                return last_kbd_key;
315            } else {
316                return 0;
317            }
318        } else {
319            last_kbd_key = 0;
320            return 0;
321        }
322    }
323}
324
325#ifdef CAM_USE_ZOOM_FOR_MF
326    long kbd_use_zoom_as_mf() {
327
328        static long v;
329        static long zoom_key_pressed = 0;
330
331        if (kbd_is_key_pressed(KEY_ZOOM_IN) && (mode_get()&MODE_MASK) == MODE_REC) {
332            get_property_case(PROPCASE_FOCUS_MODE, &v, 4);
333            if (v) {
334                kbd_key_release_all();
335                kbd_key_press(KEY_RIGHT);
336                zoom_key_pressed = KEY_ZOOM_IN;
337                return 1;
338            }
339        } else {
340            if (zoom_key_pressed==KEY_ZOOM_IN) {
341                kbd_key_release(KEY_RIGHT);
342                zoom_key_pressed = 0;
343                return 1;
344            }
345        }
346        if (kbd_is_key_pressed(KEY_ZOOM_OUT) && (mode_get()&MODE_MASK) == MODE_REC) {
347            get_property_case(PROPCASE_FOCUS_MODE, &v, 4);
348            if (v) {
349                kbd_key_release_all();
350                kbd_key_press(KEY_LEFT);
351                zoom_key_pressed = KEY_ZOOM_OUT;
352                return 1;
353            }
354        } else {
355            if (zoom_key_pressed==KEY_ZOOM_OUT) {
356                kbd_key_release(KEY_LEFT);
357                zoom_key_pressed = 0;
358                return 1;
359            }
360        }
361        return 0;
362    }
363#endif
364
365///
366int Get_JogDial(void) {
367        return (*(int*)0xC0240104)>>16;     // 0xC0240000 + 0x104
368}
369
370static int new_jogdial=0, old_jogdial=0;
371
372long get_jogdial_direction(void) {
373        old_jogdial=new_jogdial;
374    new_jogdial=Get_JogDial();
375
376    if (old_jogdial<new_jogdial) {
377        return JOGDIAL_RIGHT;
378    } else if (old_jogdial>new_jogdial) {
379        return JOGDIAL_LEFT;
380    } else {
381        return 0;
382    }
383}
Note: See TracBrowser for help on using the repository browser.