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

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