Changeset 1240 for trunk/platform/a410/kbd.c
- Timestamp:
- 07/18/11 08:08:23 (2 years ago)
- File:
-
- 1 edited
-
trunk/platform/a410/kbd.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/platform/a410/kbd.c
r1226 r1240 1 #include "lolevel.h" 2 #include "platform.h" 3 #include "conf.h" 4 #include "core.h" 5 #include "keyboard.h" 6 7 typedef struct { 8 long hackkey; 9 long canonkey; 10 } KeyMap; 1 #include "../generic/kbd.c" 11 2 12 3 13 static long kbd_new_state[3];14 static long kbd_prev_state[3];15 static long kbd_mod_state;16 static KeyMap keymap[];17 static long last_kbd_key = 0;18 static int usb_power=0;19 static int remote_key, remote_count;20 static int shoot_counter=0;21 #define DELAY_TIMEOUT 1000022 23 #define NEW_SS (0x2000)24 #define SD_READONLY_FLAG (0x20000)25 26 #define USB_MASK 0x4000027 #define USB_REG 228 29 #ifndef MALLOCD_STACK30 static char kbd_stack[NEW_SS];31 #endif32 33 long __attribute__((naked)) wrap_kbd_p1_f() ;34 35 void wait_until_remote_button_is_released(void)36 {37 38 long x[3];39 int count1;40 int count2;41 int tick,tick2,tick3;42 int nSW;43 int prev_usb_power,cur_usb_power;44 // ------ add by Masuji SUTO (start) --------------45 static int nMode;46 // ------ add by Masuji SUTO (end) --------------47 48 asm volatile ("STMFD SP!, {R0-R11,LR}\n"); // store R0-R11 and LR in stack49 debug_led(1);50 tick = get_tick_count();51 tick2 = tick;52 static long usb_physw[3];53 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)))54 // 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 disconnect55 {56 // ------ add by Masuji SUTO (start) --------------57 nMode=0;58 usb_physw[2] = 0; // makes sure USB bit is cleared.59 _kbd_read_keys_r2(usb_physw);60 if((usb_physw[2] & USB_MASK)==USB_MASK) nMode=1;61 // ------ add by Masuji SUTO (end) --------------62 if(conf.ricoh_ca1_mode && conf.remote_enable)63 {64 if(shooting_get_drive_mode()==1 && state_shooting_progress == SHOOTING_PROGRESS_PROCESSING){ //continuous-shooting mode65 if(conf.bracket_type>2){66 if(shoot_counter<2) shutter_int=3;67 shoot_counter--;68 }69 else{70 prev_usb_power=0;71 nSW = 0;72 do73 {74 usb_physw[2] = 0; // makes sure USB bit is cleared.75 _kbd_read_keys_r2(usb_physw);76 cur_usb_power = (usb_physw[2] & USB_MASK)==USB_MASK;77 if(cur_usb_power){78 if(!prev_usb_power){79 tick2 = get_tick_count();80 prev_usb_power=cur_usb_power;81 }82 else{83 if((int)get_tick_count()-tick2>1000) {debug_led(0);}84 }85 }86 else{87 if(prev_usb_power){88 tick3 = (int)get_tick_count()-tick2;89 if(nSW==10) {90 if(tick3>50) shutter_int=1;91 nSW=20;92 }93 if(nSW==0 && tick3>0) {94 if(tick3<50) {95 nSW=10;96 }97 else{98 if(tick3>1000) shutter_int=1;99 nSW=20;100 }101 }102 prev_usb_power=cur_usb_power;103 }104 }105 if((int)get_tick_count()-tick >= DELAY_TIMEOUT) {nSW=20;shutter_int=2;}106 }107 while(nSW<20);108 }109 } //continuous-shooting mode110 else{ // normal mode111 shoot_counter=0;112 if(conf.bracket_type>2){113 shoot_counter=(conf.bracket_type-2)*2;114 }115 do116 {117 usb_physw[2] = 0; // makes sure USB bit is cleared.118 _kbd_read_keys_r2(usb_physw);119 120 }121 122 // ------ modif by Masuji SUTO (start) --------------123 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));124 // ------ modif by Masuji SUTO (end) --------------125 }126 }127 128 else129 {130 131 do132 {133 usb_physw[2] = 0; // makes sure USB bit is cleared.134 _kbd_read_keys_r2(usb_physw);135 136 }137 while((usb_physw[2]&USB_MASK) && ((int)get_tick_count()-tick < DELAY_TIMEOUT));138 }139 } // synch enable140 141 142 if (conf.synch_delay_enable && conf.synch_delay_value>0) // if delay is switched on and greater than 0143 {144 for (count1=0;count1<conf.synch_delay_value+(conf.synch_delay_coarse_value*1000);count1++) // wait delay_value * 0.1ms145 {146 for (count2=0;count2<1400;count2++) // delay approx. 0.1ms147 {148 }149 }150 }151 152 debug_led(0);153 154 asm volatile ("LDMFD SP!, {R0-R11,LR}\n"); // restore R0-R11 and LR from stack155 }156 157 static void __attribute__((noinline)) mykbd_task_proceed()158 {159 while (physw_run){160 _SleepTask(10);161 162 if (wrap_kbd_p1_f() == 1){ // autorepeat ?163 _kbd_p2_f();164 }165 }166 }167 168 void __attribute__((naked,noinline)) mykbd_task()169 {170 /* WARNING171 * Stack pointer manipulation performed here!172 * This means (but not limited to):173 * function arguments destroyed;174 * function CAN NOT return properly;175 * MUST NOT call or use stack variables before stack176 * is setup properly;177 *178 */179 180 register int i;181 register long *newstack;182 183 #ifndef MALLOCD_STACK184 newstack = (void*)kbd_stack;185 #else186 newstack = malloc(NEW_SS);187 #endif188 189 for (i=0;i<NEW_SS/4;i++)190 newstack[i]=0xdededede;191 192 asm volatile (193 "MOV SP, %0"194 :: "r"(((char*)newstack)+NEW_SS)195 : "memory"196 );197 198 mykbd_task_proceed();199 200 /* function can be modified to restore SP here...201 */202 203 _ExitTask();204 }205 206 207 long __attribute__((naked,noinline)) wrap_kbd_p1_f()208 {209 210 asm volatile(211 "STMFD SP!, {R4-R7,LR}\n"212 "SUB SP, SP, #0xC\n"213 "BL my_kbd_read_keys\n"214 "B _kbd_p1_f_cont\n"215 );216 return 0; // shut up the compiler217 }218 219 220 void my_kbd_read_keys()221 {222 kbd_prev_state[0] = kbd_new_state[0];223 kbd_prev_state[1] = kbd_new_state[1];224 kbd_prev_state[2] = kbd_new_state[2];225 226 // _kbd_pwr_on();227 228 kbd_fetch_data(kbd_new_state);229 230 #if 0231 if ((new_state[2] & 0x00001000 /* print button */) == 0 )232 started();233 else234 finished();235 #endif236 237 238 if (kbd_process() == 0){239 // leave it alone...240 physw_status[0] = kbd_new_state[0];241 physw_status[1] = kbd_new_state[1];242 physw_status[2] = kbd_new_state[2];243 #if 0244 kbd_mod_state = kbd_new_state[2];245 #endif246 } else {247 // override keys248 #if 0249 physw_status[2] = kbd_mod_state;250 #else251 physw_status[0] = kbd_new_state[0];252 physw_status[1] = kbd_new_state[1];253 physw_status[2] = (kbd_new_state[2] & (~0x1fff)) |254 (kbd_mod_state & 0x1fff);255 #endif256 }257 258 _kbd_read_keys_r2(physw_status);259 remote_key = (physw_status[2] & USB_MASK)==USB_MASK;260 261 if (remote_key)262 remote_count += 1;263 else if (remote_count) {264 usb_power = remote_count;265 remote_count = 0;266 }267 268 if (conf.remote_enable) {269 270 physw_status[2] = physw_status[2] & ~(SD_READONLY_FLAG | USB_MASK);271 }272 else273 physw_status[2] = physw_status[2] & ~SD_READONLY_FLAG;274 275 // _kbd_pwr_off();276 277 }278 int get_usb_power(int edge)279 {280 int x;281 282 if (edge) return remote_key;283 x = usb_power;284 usb_power = 0;285 return x;286 }287 /****************/288 289 290 void kbd_key_press(long key)291 {292 int i;293 for (i=0;keymap[i].hackkey;i++){294 if (keymap[i].hackkey == key){295 kbd_mod_state &= ~keymap[i].canonkey;296 return;297 }298 }299 }300 301 void kbd_key_release(long key)302 {303 int i;304 for (i=0;keymap[i].hackkey;i++){305 if (keymap[i].hackkey == key){306 kbd_mod_state |= keymap[i].canonkey;307 return;308 }309 }310 }311 312 void kbd_key_release_all()313 {314 kbd_mod_state |= 0x1fff;315 }316 317 long kbd_is_key_pressed(long key)318 {319 int i;320 for (i=0;keymap[i].hackkey;i++){321 if (keymap[i].hackkey == key){322 return ((kbd_new_state[2] & keymap[i].canonkey) == 0) ? 1:0;323 }324 }325 return 0;326 }327 328 long kbd_is_key_clicked(long key)329 {330 int i;331 for (i=0;keymap[i].hackkey;i++){332 if (keymap[i].hackkey == key){333 return ((kbd_prev_state[2] & keymap[i].canonkey) != 0) &&334 ((kbd_new_state[2] & keymap[i].canonkey) == 0);335 }336 }337 return 0;338 }339 340 long kbd_get_pressed_key()341 {342 int i;343 for (i=0;keymap[i].hackkey;i++){344 if ((kbd_new_state[2] & keymap[i].canonkey) == 0){345 return keymap[i].hackkey;346 }347 }348 return 0;349 }350 351 long kbd_get_clicked_key()352 {353 int i;354 for (i=0;keymap[i].hackkey;i++){355 if (((kbd_prev_state[2] & keymap[i].canonkey) != 0) &&356 ((kbd_new_state[2] & keymap[i].canonkey) == 0)){357 return keymap[i].hackkey;358 }359 }360 return 0;361 }362 363 void kbd_reset_autoclicked_key() {364 last_kbd_key = 0;365 }366 367 long kbd_get_autoclicked_key() {368 static long last_kbd_time = 0, press_count = 0;369 register long key, t;370 371 key=kbd_get_clicked_key();372 if (key) {373 last_kbd_key = key;374 press_count = 0;375 last_kbd_time = get_tick_count();376 return key;377 } else {378 if (last_kbd_key && kbd_is_key_pressed(last_kbd_key)) {379 t = get_tick_count();380 if (t-last_kbd_time>((press_count)?175:500)) {381 ++press_count;382 last_kbd_time = t;383 return last_kbd_key;384 } else {385 return 0;386 }387 } else {388 last_kbd_key = 0;389 return 0;390 }391 }392 }393 394 long kbd_use_zoom_as_mf() {395 return 0;396 }397 4 static KeyMap keymap[] = { 398 5 /* tiny bug: key order matters. see kbd_get_pressed_key()
Note: See TracChangeset
for help on using the changeset viewer.