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

Revision 1031, 9.1 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];
17
18static long last_kbd_key = 0;
19static int usb_power=0;
20static int remote_key, remote_count;
21static int shoot_counter=0;
22extern void _platformsub_kbd_fetch_data(long*);
23
24#define DELAY_TIMEOUT 10000
25
26
27#define KEYS_MASK0 (0x00020000)
28#define KEYS_MASK1 (0x00000000)
29#define KEYS_MASK2 (0x00000DFF)
30
31#define NEW_SS (0x2000)
32#define SD_READONLY_FLAG (0x40000)
33#define USB_MASK (0x80000)
34#define USB_REG 2
35
36
37#ifndef MALLOCD_STACK
38static char kbd_stack[NEW_SS];
39#endif
40
41
42static KeyMap keymap[] = {
43        /* tiny bug: key order matters. see kbd_get_pressed_key()
44         * for example
45         */
46
47        { 0, KEY_DISPLAY        , 0x00020000 },   // playback key
48
49        { 2, KEY_SHOOT_FULL     , 0x00000030 },
50        { 2, KEY_SHOOT_HALF     , 0x00000010 },
51        { 2, KEY_UP             , 0x00000001 },
52        { 2, KEY_DOWN           , 0x00000002 },
53        { 2, KEY_LEFT           , 0x00000008 },
54        { 2, KEY_RIGHT          , 0x00000004 },
55        { 2, KEY_SET            , 0x00000100 },
56        { 2, KEY_ZOOM_IN        , 0x00000080 },
57        { 2, KEY_ZOOM_OUT       , 0x00000040 },
58        { 2, KEY_MENU           , 0x00000400 },
59        { 2, KEY_PRINT          , 0x00000800 },   // mode key
60        { 0, 0, 0 }
61};
62
63
64long __attribute__((naked)) wrap_kbd_p1_f() ;
65
66void wait_until_remote_button_is_released(void)
67{
68
69long x[3];
70int count1;
71int count2;
72int tick,tick2,tick3;
73int nSW;
74int prev_usb_power,cur_usb_power;
75 // ------ add by Masuji SUTO (start) --------------
76    static int nMode;
77 // ------ add by Masuji SUTO (end)   --------------
78
79asm volatile ("STMFD SP!, {R0-R11,LR}\n"); // store R0-R11 and LR in stack
80debug_led(1);
81tick = get_tick_count();
82tick2 = tick;
83static long usb_physw[3];
84if (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
85  {
86// ------ add by Masuji SUTO (start) --------------
87        nMode=0;
88        usb_physw[2] = 0;                                             // makes sure USB bit is cleared.
89        _kbd_read_keys_r2(usb_physw);
90        if((usb_physw[2] & USB_MASK)==USB_MASK) nMode=1;
91// ------ add by Masuji SUTO (end)   --------------
92     if(conf.ricoh_ca1_mode && conf.remote_enable)
93     {
94        if(shooting_get_drive_mode()==1 && state_shooting_progress == SHOOTING_PROGRESS_PROCESSING){                    //continuous-shooting mode
95                if(conf.bracket_type>2){
96                        if(shoot_counter<2) shutter_int=3;
97                        shoot_counter--;
98                        }
99                else{
100                        prev_usb_power=0;
101                        nSW = 0;
102                        do
103                                {     
104                                usb_physw[2] = 0;                                             // makes sure USB bit is cleared.
105                                _kbd_read_keys_r2(usb_physw);
106                                cur_usb_power = (usb_physw[2] & USB_MASK)==USB_MASK;
107                                if(cur_usb_power){
108                                        if(!prev_usb_power){
109                                                tick2 = get_tick_count();
110                                                prev_usb_power=cur_usb_power;
111                                                }
112                                        else{
113                                                if((int)get_tick_count()-tick2>1000) {debug_led(0);}
114                                                }
115                                        }
116                                else{
117                                        if(prev_usb_power){
118                                                tick3 = (int)get_tick_count()-tick2;
119                                                if(nSW==10) {
120                                                        if(tick3>50) shutter_int=1;
121                                                        nSW=20;
122                                                        }
123                                                if(nSW==0 && tick3>0) {
124                                                        if(tick3<50) {
125                                                        nSW=10;
126                                                        }
127                                                else{
128                                                        if(tick3>1000) shutter_int=1;
129                                                                nSW=20;
130                                                        }
131                                                }
132                                                prev_usb_power=cur_usb_power;
133                                                }
134                                        }
135                                if((int)get_tick_count()-tick >= DELAY_TIMEOUT) {nSW=20;shutter_int=2;}
136                                }
137                         while(nSW<20);
138                         }
139                }               //continuous-shooting mode
140                else{           // normal mode
141                        shoot_counter=0;
142                        if(conf.bracket_type>2){
143                                shoot_counter=(conf.bracket_type-2)*2;
144                                }
145        do
146           {
147           _platformsub_kbd_fetch_data(x);
148           usb_physw[2] = 0;
149          _kbd_read_keys_r2(usb_physw);           
150           }
151
152// ------ modif by Masuji SUTO (start) --------------
153    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));
154// ------ modif by Masuji SUTO (end)   --------------
155        }
156       } // ricoh ca-1 mode
157
158else
159
160       {
161         do
162          {
163           _platformsub_kbd_fetch_data(x);
164           usb_physw[2] = 0;
165          _kbd_read_keys_r2(usb_physw);           
166           }
167        while((usb_physw[2]&USB_MASK) &&  ((int)get_tick_count()-tick < DELAY_TIMEOUT));
168
169        }
170
171  } // synch enable
172
173
174if (conf.synch_delay_enable && conf.synch_delay_value>0)       // if delay is switched on and greater than 0
175  {
176    for (count1=0;count1<conf.synch_delay_value+(conf.synch_delay_coarse_value*1000);count1++) // wait delay_value * 0.1ms
177    {
178      for (count2=0;count2<1400;count2++)            // delay approx. 0.1ms
179        {
180        }
181     }
182  }
183
184debug_led(0);
185
186asm volatile ("LDMFD SP!, {R0-R11,LR}\n"); // restore R0-R11 and LR from stack
187}
188
189
190
191
192static void __attribute__((noinline)) mykbd_task_proceed()
193{
194        while (physw_run){
195                _SleepTask(10);
196               
197                if (wrap_kbd_p1_f() == 1){ // autorepeat ?
198                        _kbd_p2_f();
199                }
200        }
201}
202
203void __attribute__((naked,noinline)) mykbd_task()
204{
205    /* WARNING
206     * Stack pointer manipulation performed here!
207     * This means (but not limited to):
208     *  function arguments destroyed;
209     *  function CAN NOT return properly;
210     *  MUST NOT call or use stack variables before stack
211     *  is setup properly;
212     *
213     */
214
215        register int i;
216        register long *newstack;
217
218#ifndef MALLOCD_STACK
219        newstack = (void*)kbd_stack;
220#else
221        newstack = malloc(NEW_SS);
222#endif
223
224        for (i=0;i<NEW_SS/4;i++)
225                newstack[i]=0xdededede;
226
227        asm volatile (
228                "MOV    SP, %0"
229                :: "r"(((char*)newstack)+NEW_SS)
230                : "memory"
231        );
232
233        mykbd_task_proceed();
234
235        /* function can be modified to restore SP here...
236         */
237
238        _ExitTask();
239}
240
241
242long __attribute__((naked,noinline)) wrap_kbd_p1_f()
243{
244
245        asm volatile(
246                "STMFD   SP!, {R1-R5,LR}\n"
247                "MOV     R4, #0\n"
248                "BL      my_kbd_read_keys\n"
249                "B       _kbd_p1_f_cont\n"
250        );
251        return 0; // shut up the compiler
252}
253
254
255void my_kbd_read_keys()
256{
257        kbd_prev_state[0] = kbd_new_state[0];
258        kbd_prev_state[1] = kbd_new_state[1];
259        kbd_prev_state[2] = kbd_new_state[2];
260       
261        _platformsub_kbd_fetch_data(kbd_new_state);
262
263        if (kbd_process() == 0){
264                // leave it alone...
265          physw_status[0] = kbd_new_state[0];
266          physw_status[1] = kbd_new_state[1];
267          physw_status[2] = kbd_new_state[2];
268
269        } else {
270                // override keys
271        physw_status[0] = (kbd_new_state[0] & (~KEYS_MASK0)) |
272                          (kbd_mod_state[0] & KEYS_MASK0);
273
274        physw_status[1] = (kbd_new_state[1] & (~KEYS_MASK1)) |
275                          (kbd_mod_state[1] & KEYS_MASK1);
276
277        physw_status[2] = (kbd_new_state[2] & (~KEYS_MASK2)) |
278                          (kbd_mod_state[2] & KEYS_MASK2);
279
280        }
281       
282        _kbd_read_keys_r2(physw_status);
283
284        remote_key = (physw_status[2] & USB_MASK)==USB_MASK;
285                if (remote_key)
286                        remote_count += 1;
287                else if (remote_count) {
288                        usb_power = remote_count;
289                        remote_count = 0;
290                }
291        if (conf.remote_enable) {
292                physw_status[2] = physw_status[2] & ~(SD_READONLY_FLAG | USB_MASK);
293        } else {
294                physw_status[2] = physw_status[2] & ~SD_READONLY_FLAG;
295        }
296
297}
298
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
378
379void kbd_reset_autoclicked_key() {
380        last_kbd_key = 0;
381}
382
383long kbd_get_autoclicked_key() {
384        static long last_kbd_time = 0, press_count = 0;
385        register long key, t;
386       
387        key=kbd_get_clicked_key();
388        if (key) {
389                last_kbd_key = key;
390                press_count = 0;
391                last_kbd_time = get_tick_count();
392                return key;
393        } else {
394                if (last_kbd_key && kbd_is_key_pressed(last_kbd_key)) {
395                        t = get_tick_count();
396                        if (t-last_kbd_time>((press_count)?175:500)) {
397                                ++press_count;
398                                last_kbd_time = t;
399                                return last_kbd_key;
400                        } else {
401                                return 0;
402                        }
403                } else {
404                        last_kbd_key = 0;
405                        return 0;
406                }
407        }
408}
409
410
411int get_usb_power(int edge)
412{
413        int x;
414
415        if (edge) return remote_key;
416        x = usb_power;
417        usb_power = 0;
418        return x;
419}
420
421long kbd_use_zoom_as_mf() {
422 return 0;
423}
Note: See TracBrowser for help on using the repository browser.