source: trunk/platform/g7/kbd.c @ 1031

Revision 1031, 12.2 KB checked in by pixeldoc2000, 2 years ago (diff)

typo fixed in kbd.c (nomal -> normal)

  • Property svn:eol-style set to native
Line 
1#include "lolevel.h"
2#include "platform.h"
3#include "core.h"
4#include "conf.h"
5#include "keyboard.h"
6
7typedef struct {
8        short grp;
9        short hackkey;
10        long canonkey;
11} KeyMap;
12
13
14static long kbd_new_state[3];
15static long kbd_prev_state[3];
16static long kbd_mod_state[3];
17static KeyMap keymap[];
18static long last_kbd_key = 0;
19static long alt_mode_key_mask = 0x1000;
20static int usb_power=0;
21static int remote_key, remote_count;
22static int shoot_counter=0;
23static int new_jogdial=0, old_jogdial=0;
24#define DELAY_TIMEOUT 10000
25#define KEYS_MASK0 (0xC0000000)
26#define KEYS_MASK1 (0x3F1F1418)
27#define KEYS_MASK2 (0x00000000)
28
29#define NEW_SS (0x2000)
30#define SD_READONLY_FLAG (0x20000)
31
32#define USB_MASK (0x40000)
33
34#ifndef MALLOCD_STACK
35static char kbd_stack[NEW_SS];
36#endif
37
38extern void _platformsub_kbd_fetch_data(long*);
39long __attribute__((naked)) wrap_kbd_p1_f() ;
40
41void wait_until_remote_button_is_released(void)
42{
43int count1;
44int count2;
45int tick,tick2,tick3;
46int nSW;
47int prev_usb_power,cur_usb_power;
48 // ------ add by Masuji SUTO (start) --------------
49    static int nMode;
50 // ------ add by Masuji SUTO (end)   --------------
51
52asm volatile ("STMFD SP!, {R0-R11,LR}\n"); // store R0-R11 and LR in stack
53
54debug_led(1);
55tick = get_tick_count();
56tick2 = tick;
57static long usb_physw[3];
58   if (conf.synch_enable && conf.ricoh_ca1_mode && conf.remote_enable && (!shooting_get_drive_mode()|| (shooting_get_drive_mode()==1) || ((shooting_get_drive_mode()==2) && state_shooting_progress != SHOOTING_PROGRESS_PROCESSING)))                                     
59// if (conf.synch_enable && conf.ricoh_ca1_mode && conf.remote_enable && (!shooting_get_drive_mode()|| ((shooting_get_drive_mode()==2) && state_shooting_progress != SHOOTING_PROGRESS_PROCESSING)))   // synch mode enable so wait for USB to disconnect
60  {
61// ------ add by Masuji SUTO (start) --------------
62        nMode=0;
63        usb_physw[2] = 0;                                             // makes sure USB bit is cleared.
64        _kbd_read_keys_r2(usb_physw);
65        if((usb_physw[2] & USB_MASK)==USB_MASK) nMode=1;
66// ------ add by Masuji SUTO (end)   --------------
67
68if(conf.ricoh_ca1_mode && conf.remote_enable)
69{
70        if(shooting_get_drive_mode()==1 && state_shooting_progress == SHOOTING_PROGRESS_PROCESSING){                    //continuous-shooting mode
71                if(conf.bracket_type>2){
72                        if(shoot_counter<2) shutter_int=3;
73                        shoot_counter--;
74                        }
75                else{
76                        prev_usb_power=0;
77                        nSW = 0;
78                        do
79                                {     
80                                usb_physw[2] = 0;                                             // makes sure USB bit is cleared.
81                                _kbd_read_keys_r2(usb_physw);
82                                cur_usb_power = (usb_physw[2] & USB_MASK)==USB_MASK;
83                                if(cur_usb_power){
84                                        if(!prev_usb_power){
85                                                tick2 = get_tick_count();
86                                                prev_usb_power=cur_usb_power;
87                                                }
88                                        else{
89                                                if((int)get_tick_count()-tick2>1000) {debug_led(0);}
90                                                }
91                                        }
92                                else{
93                                        if(prev_usb_power){
94                                                tick3 = (int)get_tick_count()-tick2;
95                                                if(nSW==10) {
96                                                        if(tick3>50) shutter_int=1;
97                                                        nSW=20;
98                                                        }
99                                                if(nSW==0 && tick3>0) {
100                                                        if(tick3<50) {
101                                                        nSW=10;
102                                                        }
103                                                else{
104                                                        if(tick3>1000) shutter_int=1;
105                                                                nSW=20;
106                                                        }
107                                                }
108                                                prev_usb_power=cur_usb_power;
109                                                }
110                                        }
111                                if((int)get_tick_count()-tick >= DELAY_TIMEOUT) {nSW=20;shutter_int=2;}
112                                }
113                         while(nSW<20);
114                         }
115                }               //continuous-shooting mode
116                else{           // normal mode
117                        shoot_counter=0;
118                        if(conf.bracket_type>2){
119                                shoot_counter=(conf.bracket_type-2)*2;
120                                }
121   do
122         {     
123            usb_physw[2] = 0;                                             // makes sure USB bit is cleared.
124           _kbd_read_keys_r2(usb_physw);
125           }
126//   while(((usb_physw[2] & USB_MASK)==USB_MASK) && ((int)get_tick_count()-tick < DELAY_TIMEOUT));
127// ------ modif by Masuji SUTO (start) --------------
128        while(((((usb_physw[2] & USB_MASK)!=USB_MASK) && (nMode==0)) || (((usb_physw[2] & USB_MASK)==USB_MASK) && (nMode==1))) && ((int)get_tick_count()-tick < DELAY_TIMEOUT));
129// ------ modif by Masuji SUTO (end)   --------------
130        }
131 }
132
133else
134   {
135
136      do
137          {
138            usb_physw[2] = 0;                                             // makes sure USB bit is cleared.
139           _kbd_read_keys_r2(usb_physw);
140             
141           }
142        while((usb_physw[2]&USB_MASK) &&  ((int)get_tick_count()-tick < DELAY_TIMEOUT));
143    }
144  }
145
146if (conf.synch_delay_enable && conf.synch_delay_value>0)                                // if delay is switched on and greater than 0
147  {
148    for (count1=0;count1<conf.synch_delay_value+(conf.synch_delay_coarse_value*1000);count1++) // wait delay_value * 0.1ms
149    {
150      for (count2=0;count2<1400;count2++)            // delay approx. 0.1ms
151        {
152        }
153     }
154  }
155
156debug_led(0);
157asm volatile ("LDMFD SP!, {R0-R11,LR}\n"); // restore R0-R11 and LR from stack
158}
159
160static void __attribute__((noinline)) mykbd_task_proceed()
161{
162    while (physw_run){
163        _SleepTask(10);
164
165        if (wrap_kbd_p1_f() == 1){ // autorepeat ?
166            _kbd_p2_f();
167        }
168    }
169}
170
171void __attribute__((naked,noinline))
172mykbd_task(long ua, long ub, long uc, long ud, long ue, long uf)
173{
174    /* WARNING
175     * Stack pointer manipulation performed here!
176     * This means (but not limited to):
177     *  function arguments destroyed;
178     *  function CAN NOT return properly;
179     *  MUST NOT call or use stack variables before stack
180     *  is setup properly;
181     *
182     */
183
184    register int i;
185    register long *newstack;
186
187#ifndef MALLOCD_STACK
188    newstack = (void*)kbd_stack;
189#else
190    newstack = malloc(NEW_SS);
191#endif
192
193    for (i=0;i<NEW_SS/4;i++)
194        newstack[i]=0xdededede;
195
196    asm volatile (
197        "MOV    SP, %0"
198        :: "r"(((char*)newstack)+NEW_SS)
199        : "memory"
200    );
201
202    mykbd_task_proceed();
203
204    /* function can be modified to restore SP here...
205     */
206
207    _ExitTask();
208}
209
210
211long __attribute__((naked,noinline)) wrap_kbd_p1_f()
212{
213
214    asm volatile(
215                "STMFD   SP!, {R4-R7,LR}\n"
216                "SUB     SP, SP, #0xC\n"
217                "BL      my_kbd_read_keys\n"
218                "B       _kbd_p1_f_cont\n"
219    );
220    return 0; // shut up the compiler
221}
222
223
224void my_kbd_read_keys()
225{
226    static int handle_taskTouchW = 0, isRunning_taskTouchW = 1;
227
228    kbd_prev_state[0] = kbd_new_state[0];
229    kbd_prev_state[1] = kbd_new_state[1];
230    kbd_prev_state[2] = kbd_new_state[2];
231
232    _platformsub_kbd_fetch_data(kbd_new_state);
233
234    if (handle_taskTouchW == 0) { handle_taskTouchW = _taskNameToId("tJogDial"); }
235
236    if (kbd_process() == 0){
237        // leave it alone...
238        physw_status[0] = kbd_new_state[0];
239        physw_status[1] = kbd_new_state[1];
240        physw_status[2] = kbd_new_state[2];
241        physw_status[1] |= alt_mode_key_mask;
242        if (!isRunning_taskTouchW) { _taskResume(handle_taskTouchW); isRunning_taskTouchW = 1; }
243    } else {
244        // override keys
245        physw_status[0] = (kbd_new_state[0] & (~KEYS_MASK0)) |
246                          (kbd_mod_state[0] & KEYS_MASK0);
247
248        physw_status[1] = (kbd_new_state[1] & (~KEYS_MASK1)) |
249                          (kbd_mod_state[1] & KEYS_MASK1);
250
251        physw_status[2] = (kbd_new_state[2] & (~KEYS_MASK2)) |
252                          (kbd_mod_state[2] & KEYS_MASK2);
253
254        if (isRunning_taskTouchW && !state_kbd_script_run)
255                { _taskSuspend(handle_taskTouchW); isRunning_taskTouchW = 0; get_jogdial_direction(); }
256        else if (!isRunning_taskTouchW && state_kbd_script_run)
257                { _taskResume(handle_taskTouchW); isRunning_taskTouchW = 1; }
258
259    }
260
261    _kbd_read_keys_r2(physw_status);
262
263                remote_key = (physw_status[2] & USB_MASK)==USB_MASK;
264                if (remote_key)
265                        remote_count += 1;
266                else if (remote_count) {
267                        usb_power = remote_count;
268                        remote_count = 0;
269                }
270       
271        if (conf.remote_enable) {
272                physw_status[2] = physw_status[2] & ~(SD_READONLY_FLAG | USB_MASK);
273        }
274        else
275                physw_status[2] = physw_status[2] & ~SD_READONLY_FLAG;
276
277    _kbd_pwr_off();
278   
279}
280
281int get_usb_power(int edge)
282{
283        int x;
284
285        if (edge) return remote_key;
286        x = usb_power;
287        usb_power = 0;
288        return x;
289}
290/****************/
291
292void kbd_set_alt_mode_key_mask(long key)
293{
294    int i;
295    for (i=0; keymap[i].hackkey; ++i) {
296        if (keymap[i].hackkey == key) {
297            alt_mode_key_mask = keymap[i].canonkey;
298            return;
299        }
300    }
301}
302
303void kbd_key_press(long key)
304{
305    int i;
306    for (i=0;keymap[i].hackkey;i++){
307        if (keymap[i].hackkey == key){
308            kbd_mod_state[keymap[i].grp] &= ~keymap[i].canonkey;
309            return;
310        }
311    }
312}
313
314void kbd_key_release(long key)
315{
316    int i;
317    for (i=0;keymap[i].hackkey;i++){
318        if (keymap[i].hackkey == key){
319            kbd_mod_state[keymap[i].grp] |= keymap[i].canonkey;
320            return;
321        }
322    }
323}
324
325void kbd_key_release_all()
326{
327  kbd_mod_state[0] |= KEYS_MASK0;
328  kbd_mod_state[1] |= KEYS_MASK1;
329  kbd_mod_state[2] |= KEYS_MASK2;
330}
331
332long kbd_is_key_pressed(long key)
333{
334    int i;
335    for (i=0;keymap[i].hackkey;i++){
336        if (keymap[i].hackkey == key){
337            return ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0) ? 1:0;
338        }
339    }
340    return 0;
341}
342
343long kbd_is_key_clicked(long key)
344{
345    int i;
346    for (i=0;keymap[i].hackkey;i++){
347        if (keymap[i].hackkey == key){
348            return ((kbd_prev_state[keymap[i].grp] & keymap[i].canonkey) != 0) &&
349                    ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0);
350        }
351    }
352    return 0;
353}
354
355long kbd_get_pressed_key()
356{
357    int i;
358    for (i=0;keymap[i].hackkey;i++){
359        if ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0){
360            return keymap[i].hackkey;
361        }
362    }
363    return 0;
364}
365
366long kbd_get_clicked_key()
367{
368    int i;
369    for (i=0;keymap[i].hackkey;i++){
370        if (((kbd_prev_state[keymap[i].grp] & keymap[i].canonkey) != 0) &&
371            ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0)){
372            return keymap[i].hackkey;
373        }
374    }
375    return 0;
376}
377
378void kbd_reset_autoclicked_key() {
379    last_kbd_key = 0;
380}
381
382long kbd_get_autoclicked_key() {
383    static long last_kbd_time = 0, press_count = 0;
384    register long key, t;
385
386    key=kbd_get_clicked_key();
387    if (key) {
388        last_kbd_key = key;
389        press_count = 0;
390        last_kbd_time = get_tick_count();
391        return key;
392    } else {
393        if (last_kbd_key && kbd_is_key_pressed(last_kbd_key)) {
394            t = get_tick_count();
395            if (t-last_kbd_time>((press_count)?175:500)) {
396                ++press_count;
397                last_kbd_time = t;
398                return last_kbd_key;
399            } else {
400                return 0;
401            }
402        } else {
403            last_kbd_key = 0;
404            return 0;
405        }
406    }
407}
408
409
410int Get_JogDial(void){
411 return (*(int*)0xC0240304)>>16;
412}
413
414long get_jogdial_direction(void) {
415 old_jogdial=new_jogdial;
416 new_jogdial=Get_JogDial();
417 if (old_jogdial<new_jogdial) return JOGDIAL_LEFT;
418 else if (old_jogdial>new_jogdial) return JOGDIAL_RIGHT;
419 else return 0;
420}
421
422
423long kbd_use_zoom_as_mf() {/*  Íåçà÷åì, â G7 åñòü êîëåñî äëÿ ýòîãî
424    static long v;
425    static long zoom_key_pressed = 0;
426
427    if (kbd_is_key_pressed(KEY_ZOOM_IN) && kbd_is_key_pressed(KEY_MF) && (mode_get()&MODE_MASK) == MODE_REC) {
428        get_property_case(12, &v, 4);
429        if (v) {
430            kbd_key_release_all();
431            kbd_key_press(KEY_MF);
432            kbd_key_press(KEY_UP);
433            zoom_key_pressed = KEY_ZOOM_IN;
434            return 1;
435        }
436    } else {
437        if (zoom_key_pressed==KEY_ZOOM_IN) {
438            kbd_key_release(KEY_UP);
439            zoom_key_pressed = 0;
440            return 1;
441        }
442    }
443    if (kbd_is_key_pressed(KEY_ZOOM_OUT) && kbd_is_key_pressed(KEY_MF) && (mode_get()&MODE_MASK) == MODE_REC) {
444        get_property_case(12, &v, 4);
445        if (v) {
446            kbd_key_release_all();
447            kbd_key_press(KEY_MF);
448            kbd_key_press(KEY_DOWN);
449            zoom_key_pressed = KEY_ZOOM_OUT;
450            return 1;
451        }
452    } else {
453        if (zoom_key_pressed==KEY_ZOOM_OUT) {
454            kbd_key_release(KEY_DOWN);
455            zoom_key_pressed = 0;
456            return 1;
457        }
458    }*/
459    return 0;
460}
461
462static KeyMap keymap[] = {
463    /* tiny bug: key order matters. see kbd_get_pressed_key()
464     * for example
465     */
466        { 1, KEY_UP             , 0x00100000 },
467        { 1, KEY_DOWN           , 0x00080000 },
468        { 1, KEY_LEFT           , 0x00010000 },
469        { 1, KEY_RIGHT          , 0x00040000 },
470        { 1, KEY_SET            , 0x00020000 },
471        { 0, KEY_SHOOT_FULL     , 0xC0000000 },
472        { 0, KEY_SHOOT_HALF     , 0x40000000 },
473        { 1, KEY_ZOOM_IN        , 0x00000010 },
474        { 1, KEY_ZOOM_OUT       , 0x00000008 },
475        { 1, KEY_MENU           , 0x08000000 },
476        { 1, KEY_DISPLAY        , 0x04000000 },
477        { 1, KEY_PRINT          , 0x00001000 },
478        { 1, KEY_ERASE          , 0x01000000 },
479        { 1, KEY_EXPO_CORR      , 0x02000000 },
480        { 1, KEY_MICROPHONE     , 0x10000000 },
481//        { 1, KEY_DUMMY        , 0x00000000 },
482        { 0, 0, 0 }
483};
484
Note: See TracBrowser for help on using the repository browser.