source: trunk/platform/g12/kbd.c @ 711

Revision 711, 10.4 KB checked in by msl, 22 months ago (diff)

Neuer Tastatur-Befehl

  • Betrifft alle

+ neuer Befehl zur Tastatursteuerung: "shoot_full_only", nutzbar mit click, press und release
+ Mit diesem Befehl sind deutlich verbesserte Intervallaufnahmen mit kurzen Zeitabstaenden moeglich.
+ siehe http://chdk.setepontos.com/index.php?topic=1444.msg70223#msg70223
+ Danke fudgey

  • Betrifft A1100

+ Fehlerhafte Palettenangabe in rev705 in platform_camera.h korrigiert.

  • Veralteten Ordner "script" aus Repository entfernt.
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
13static long kbd_new_state[3];
14static long kbd_prev_state[3];
15static long kbd_mod_state[3];
16
17static long last_kbd_key = 0;
18static long alt_mode_key_mask = 0x00000400;
19static int alt_mode_led=0;
20static int usb_power=0;
21static int remote_key, remote_count;
22static int shoot_counter=0;
23extern void _GetKbdState(long*);
24
25#define DELAY_TIMEOUT 10000
26
27//void my_blinkk(void) {
28//      int i;
29////    while(1) {
30//              *((volatile int *) 0xC0220134) = 0x46; // Turn on LED
31//              for (i=0; i<0x200000; i++) { asm volatile ( "nop\n" ); }
32//
33//              *((volatile int *) 0xC0220134) = 0x44; // Turn off LED
34//              for (i=0; i<0x200000; i++) { asm volatile ( "nop\n" ); }
35//
36//              *((volatile int *) 0xC0220134) = 0x46; // Turn on LED
37//              for (i=0; i<0x200000; i++) { asm volatile ( "nop\n" ); }
38//
39//              *((volatile int *) 0xC0220134) = 0x44; // Turn off LED
40//              for (i=0; i<0x900000; i++) { asm volatile ( "nop\n" ); }
41////    }
42//}
43
44#define KEYS_MASK0 (0x007DFC20)
45#define KEYS_MASK1 (0x00000000)
46#define KEYS_MASK2 (0x00000003)
47
48#define SD_READONLY_FLAG (0x20000)
49#define USB_MASK (0x4000000)
50#define USB_REG 2
51
52static KeyMap keymap[] = {
53
54        { 0, KEY_ZOOM_IN        , 0x00000020 },
55        { 0, KEY_PRINT          , 0x00000400 },
56        { 0, KEY_ZOOM_OUT   , 0x00000800 },
57        { 0, KEY_LEFT           , 0x00001000 },
58        { 0, KEY_SET            , 0x00002000 },
59        { 0, KEY_RIGHT          , 0x00004000 },
60        { 0, KEY_DOWN           , 0x00008000 },
61        { 0, KEY_UP                     , 0x00010000 },
62        { 0, KEY_METERING       , 0x00040000 },
63        { 0, KEY_ERASE          , 0x00080000 },
64        { 0, KEY_DISPLAY        , 0x00100000 },
65        { 0, KEY_MENU           , 0x00200000 },
66        { 0, KEY_AE_LOCK        , 0x00400000 },
67
68        { 2, KEY_SHOOT_HALF     , 0x00000001 },
69        { 2, KEY_SHOOT_FULL_ONLY, 0x00000002 },
70        { 2, KEY_SHOOT_FULL     , 0x00000003 },
71
72        { 0, 0, 0 }
73};
74
75
76long __attribute__((naked)) wrap_kbd_p1_f() ;
77
78void wait_until_remote_button_is_released(void)
79{
80
81long x[3];
82int count1;
83int count2;
84int tick,tick2,tick3;
85int nSW;
86int prev_usb_power,cur_usb_power;
87 // ------ add by Masuji SUTO (start) --------------
88    static int nMode;
89 // ------ add by Masuji SUTO (end)   --------------
90
91asm volatile ("STMFD SP!, {R0-R11,LR}\n"); // store R0-R11 and LR in stack
92debug_led(1);
93tick = get_tick_count();
94tick2 = tick;
95static long usb_physw[3];
96if (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
97  {
98// ------ add by Masuji SUTO (start) --------------
99        nMode=0;
100        usb_physw[2] = 0;                                             // makes sure USB bit is cleared.
101        _kbd_read_keys_r2(usb_physw);
102        if((usb_physw[2] & USB_MASK)==USB_MASK) nMode=1;
103// ------ add by Masuji SUTO (end)   --------------
104     if(conf.ricoh_ca1_mode && conf.remote_enable)
105     {
106        if(shooting_get_drive_mode()==1 && state_shooting_progress == SHOOTING_PROGRESS_PROCESSING){                    //continuous-shooting mode
107                if(conf.bracket_type>2){
108                        if(shoot_counter<2) shutter_int=3;
109                        shoot_counter--;
110                        }
111                else{
112                        prev_usb_power=0;
113                        nSW = 0;
114                        do
115                                {
116                                usb_physw[2] = 0;                                             // makes sure USB bit is cleared.
117                                _kbd_read_keys_r2(usb_physw);
118                                cur_usb_power = (usb_physw[2] & USB_MASK)==USB_MASK;
119                                if(cur_usb_power){
120                                        if(!prev_usb_power){
121                                                tick2 = get_tick_count();
122                                                prev_usb_power=cur_usb_power;
123                                                }
124                                        else{
125                                                if((int)get_tick_count()-tick2>1000) {debug_led(0);}
126                                                }
127                                        }
128                                else{
129                                        if(prev_usb_power){
130                                                tick3 = (int)get_tick_count()-tick2;
131                                                if(nSW==10) {
132                                                        if(tick3>50) shutter_int=1;
133                                                        nSW=20;
134                                                        }
135                                                if(nSW==0 && tick3>0) {
136                                                        if(tick3<50) {
137                                                        nSW=10;
138                                                        }
139                                                else{
140                                                        if(tick3>1000) shutter_int=1;
141                                                                nSW=20;
142                                                        }
143                                                }
144                                                prev_usb_power=cur_usb_power;
145                                                }
146                                        }
147                                if((int)get_tick_count()-tick >= DELAY_TIMEOUT) {nSW=20;shutter_int=2;}
148                                }
149                         while(nSW<20);
150                         }
151                }               //continuous-shooting mode
152                else{           //nomal mode
153                        shoot_counter=0;
154                        if(conf.bracket_type>2){
155                                shoot_counter=(conf.bracket_type-2)*2;
156                                }
157        do
158           {
159         //  _platformsub_kbd_fetch_data(x);
160           usb_physw[2] = 0;
161          _kbd_read_keys_r2(usb_physw);
162           }
163
164// ------ modif by Masuji SUTO (start) --------------
165    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));
166// ------ modif by Masuji SUTO (end)   --------------
167        }
168       } // ricoh ca-1 mode
169
170else
171
172       {
173         do
174          {
175         //  _platformsub_kbd_fetch_data(x);
176           usb_physw[2] = 0;
177          _kbd_read_keys_r2(usb_physw);
178           }
179        while((usb_physw[2]&USB_MASK) &&  ((int)get_tick_count()-tick < DELAY_TIMEOUT));
180
181        }
182
183  } // synch enable
184
185
186if (conf.synch_delay_enable && conf.synch_delay_value>0)       // if delay is switched on and greater than 0
187  {
188    for (count1=0;count1<conf.synch_delay_value+(conf.synch_delay_coarse_value*1000);count1++) // wait delay_value * 0.1ms
189    {
190      for (count2=0;count2<1400;count2++)            // delay approx. 0.1ms
191        {
192        }
193     }
194  }
195
196debug_led(0);
197asm volatile ("LDMFD SP!, {R0-R11,LR}\n"); // restore R0-R11 and LR from stack
198}
199
200static void __attribute__((noinline)) mykbd_task_proceed()
201{
202        while (physw_run){
203                _SleepTask(*((int*)(0x1c30+0x14)));//10);
204
205                if (wrap_kbd_p1_f() == 1){ // autorepeat ?
206                        _kbd_p2_f();
207                }
208        }
209}
210
211// no stack manipulation needed here, since we create the task directly
212void __attribute__((naked,noinline))
213mykbd_task()
214{
215    mykbd_task_proceed();
216
217    _ExitTask();
218}
219
220long __attribute__((naked,noinline)) wrap_kbd_p1_f()
221{
222        asm volatile(
223                "STMFD   SP!, {R1-R5,LR}\n"
224                "MOV     R4, #0\n"
225                //"BL      _kbd_read_keys \n"
226                "BL             my_kbd_read_keys\n"
227                "B       _kbd_p1_f_cont\n"
228        );
229        return 0; // shut up the compiler
230}
231
232volatile int jogdial_stopped=0;
233
234void my_kbd_read_keys()
235{
236        kbd_prev_state[0] = kbd_new_state[0];
237        kbd_prev_state[1] = kbd_new_state[1];
238        kbd_prev_state[2] = kbd_new_state[2];
239
240        _GetKbdState(kbd_new_state);
241        _kbd_read_keys_r2(kbd_new_state);
242
243        if (kbd_process() == 0){
244                // leave it alone...
245          physw_status[0] = kbd_new_state[0];
246          physw_status[1] = kbd_new_state[1];
247          physw_status[2] = kbd_new_state[2];
248          jogdial_stopped=0;
249
250        } else {
251                // override keys
252                physw_status[0] = (kbd_new_state[0] & (~KEYS_MASK0)) | (kbd_mod_state[0] & KEYS_MASK0);
253                physw_status[1] = (kbd_new_state[1] & (~KEYS_MASK1)) | (kbd_mod_state[1] & KEYS_MASK1);
254                physw_status[2] = (kbd_new_state[2] & (~KEYS_MASK2)) | (kbd_mod_state[2] & KEYS_MASK2);
255
256                if ((jogdial_stopped==0) && !state_kbd_script_run)
257                {
258                        jogdial_stopped=1;
259                        get_jogdial_direction();
260                }
261                else if (jogdial_stopped && state_kbd_script_run) jogdial_stopped=0;
262        }
263
264        //_kbd_read_keys_r2(physw_status);      // re-reads physw_status[0] from 0x2DE4 at start (so above doesn't work properly) !!!!!
265
266        remote_key = (physw_status[2] & USB_MASK)==USB_MASK;
267                if (remote_key)
268                        remote_count += 1;
269                else if (remote_count) {
270                        usb_power = remote_count;
271                        remote_count = 0;
272                }
273        if (conf.remote_enable) {
274                physw_status[2] = physw_status[2] & ~(SD_READONLY_FLAG | USB_MASK);
275        } else {
276                physw_status[2] = physw_status[2] & ~SD_READONLY_FLAG;
277        }
278}
279
280
281/****************/
282
283void kbd_set_alt_mode_key_mask(long key)
284{
285        int i;
286        for (i=0; keymap[i].hackkey; ++i) {
287                if (keymap[i].hackkey == key) {
288                        alt_mode_key_mask = keymap[i].canonkey;
289                        return;
290                }
291        }
292}
293
294
295void kbd_key_press(long key)
296{
297        int i;
298
299        for (i=0;keymap[i].hackkey;i++){
300                if (keymap[i].hackkey == key)
301                {
302                        kbd_mod_state[keymap[i].grp] &= ~keymap[i].canonkey;
303                        return;
304                }
305        }
306}
307
308void kbd_key_release(long key)
309{
310        int i;
311        for (i=0;keymap[i].hackkey;i++){
312                if (keymap[i].hackkey == key){
313                        kbd_mod_state[keymap[i].grp] |= keymap[i].canonkey;
314                        return;
315                }
316        }
317}
318
319void kbd_key_release_all()
320{
321        kbd_mod_state[0] |= KEYS_MASK0;
322        kbd_mod_state[1] |= KEYS_MASK1;
323        kbd_mod_state[2] |= KEYS_MASK2;
324}
325
326long kbd_is_key_pressed(long key)
327{
328        int i;
329        for (i=0;keymap[i].hackkey;i++){
330                if (keymap[i].hackkey == key){
331                        return ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0) ? 1:0;
332                }
333        }
334        return 0;
335}
336
337long kbd_is_key_clicked(long key)
338{
339        int i;
340        for (i=0;keymap[i].hackkey;i++){
341                if (keymap[i].hackkey == key){
342                        return ((kbd_prev_state[keymap[i].grp] & keymap[i].canonkey) != 0) &&
343                               ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0);
344                }
345        }
346        return 0;
347}
348
349long kbd_get_pressed_key()
350{
351        int i;
352        for (i=0;keymap[i].hackkey;i++){
353                if ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0){
354                        return keymap[i].hackkey;
355                }
356        }
357        return 0;
358}
359
360long kbd_get_clicked_key()
361{
362        int i;
363        for (i=0;keymap[i].hackkey;i++){
364                if (((kbd_prev_state[keymap[i].grp] & keymap[i].canonkey) != 0) &&
365                    ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0)) {
366                        return keymap[i].hackkey;
367                }
368        }
369        return 0;
370}
371
372void kbd_reset_autoclicked_key() {
373        last_kbd_key = 0;
374}
375
376long kbd_get_autoclicked_key() {
377        static long last_kbd_time = 0, press_count = 0;
378        register long key, t;
379
380        key=kbd_get_clicked_key();
381        if (key) {
382                last_kbd_key = key;
383                press_count = 0;
384                last_kbd_time = get_tick_count();
385                return key;
386        } else {
387                if (last_kbd_key && kbd_is_key_pressed(last_kbd_key)) {
388                        t = get_tick_count();
389                        if (t-last_kbd_time>((press_count)?175:500)) {
390                                ++press_count;
391                                last_kbd_time = t;
392                                return last_kbd_key;
393                        } else {
394                                return 0;
395                        }
396                } else {
397                        last_kbd_key = 0;
398                        return 0;
399                }
400        }
401}
402
403int get_usb_power(int edge)
404{
405        int x;
406
407        if (edge) return remote_key;
408        x = usb_power;
409        usb_power = 0;
410        return x;
411}
412
413// ?? Not used ??
414//long kbd_use_zoom_as_mf() {
415// return 0;
416//}
417
418static int new_jogdial=0, old_jogdial=0;
419
420int Get_JogDial(void){
421 return (*(int*)0xC0240104)>>16;
422}
423
424long get_jogdial_direction(void) {
425 old_jogdial=new_jogdial;
426 new_jogdial=Get_JogDial();
427 if (old_jogdial>new_jogdial) return JOGDIAL_LEFT;
428 else if (old_jogdial<new_jogdial) return JOGDIAL_RIGHT;
429 else return 0;
430}
Note: See TracBrowser for help on using the repository browser.