root/core/usb_sync.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. force_usb_state
  2. get_remote_state
  3. _wait_until_remote_button_is_released

   1 /*===================================================================================================
   2     usb_sync.c
   3     - platform dependent code related to USB remote precision sync / button release
   4 
   5   ===================================================================================================*/
   6 
   7 #include "camera.h"
   8 #include "stdlib.h"
   9 #include "clock.h"
  10 #include "modes.h"
  11 #include "conf.h"
  12 #include "usb_remote.h"
  13 #include "script_api.h"
  14 #include "shooting.h"
  15 
  16 /*===================================================================================================
  17     Variables
  18   ===================================================================================================*/
  19 
  20 extern int usb_sync_wait_flag ;
  21 extern int usb_remote_active;
  22 #ifdef USB_REMOTE_DEBUGGING  
  23 int sync_counter=0;
  24 #endif
  25 
  26 /*---------------------------------------------------------------------------------------------------------
  27 
  28     force_usb_state()
  29         
  30       - causes camera to think the USB port is active ( i.e. 5V on the +V input pin)
  31       - enables the simultaneous use of the USB port for PTP communications and USB remote precision sync
  32 
  33   ---------------------------------------------------------------------------------------------------------*/
  34 
  35 int forced_usb_port = 0 ;
  36 
  37 int force_usb_state(int state)
  38 {
  39     forced_usb_port = state ;
  40 #ifdef CAM_ALLOWS_USB_PORT_FORCING
  41     return 1 ;
  42 #else
  43     return 0 ;
  44 #endif
  45 }
  46 
  47 
  48 /*---------------------------------------------------------------------------------------------------------
  49 
  50     get_remote_state()
  51 
  52     - return state of current remote input
  53   ---------------------------------------------------------------------------------------------------------*/
  54 
  55 int get_remote_state()
  56 {
  57 #ifdef CAM_REMOTE_MULTICHANNEL
  58     switch(conf.remote_input_channel)
  59     {
  60         case REMOTE_INPUT_USB:
  61             return get_usb_bit();
  62 #ifdef CAM_REMOTE_HDMI_HPD
  63         case REMOTE_INPUT_HDMI_HPD:
  64             return get_hdmi_hpd_bit();
  65 #endif
  66 #ifdef CAM_REMOTE_ANALOG_AV
  67         case REMOTE_INPUT_ANALOG_AV:
  68             return get_analog_av_bit();
  69 #endif
  70 #ifdef CAM_REMOTE_AtoD_CHANNEL
  71         case REMOTE_INPUT_AD_CHANNEL:
  72             return (GetAdChValue(CAM_REMOTE_AtoD_CHANNEL) < CAM_REMOTE_AtoD_THRESHOLD) ? 1 : 0;
  73 #endif
  74     }
  75     return 0;
  76 #else // not CAM_REMOTE_MULTICHANNEL
  77     return( get_usb_bit() );
  78 #endif
  79 }
  80 
  81 /*---------------------------------------------------------------------------------------------------------
  82 
  83     wait_until_remote_button_is released()
  84 
  85     - called from capt_seq.c after all focus, exposure and flash things have been setup
  86     - if enabled,  waits for a USB 1->0 transition to allow accurate sync between cameras connected in parrallel
  87 
  88   ---------------------------------------------------------------------------------------------------------*/
  89       
  90 #define GPIO_VSYNC_UPDATE  0xC0F06000
  91 #define GPIO_VSYNC_MAX     0xC0F06014
  92 // note : GPIO_VSYNC_CURRENT is camera dependent and define in platform_camera.h
  93 
  94 void _wait_until_remote_button_is_released(void)
  95 {
  96     int tick;
  97 
  98     // hook for script to block processing just prior to exposure start
  99     libscriptapi->shoot_hook(SCRIPT_SHOOT_HOOK_SHOOT);
 100 
 101     if ( usb_sync_wait_flag )                 // flag set when something wants the current shot to be sync'd
 102     {
 103         usb_remote_status_led(1);             // indicate to user we are waiting for remote button to release - this happens every time the camera takes a picture
 104         tick = get_tick_count();              // timestamp so we don't hang here forever if something goes wrong
 105 
 106     #ifdef CAM_REMOTE_USES_PRECISION_SYNC
 107 
 108         int std_period = EngDrvRead(GPIO_VSYNC_MAX);
 109 
 110         do { }  while( get_remote_state() &&  ((int)get_tick_count()-tick < DELAY_TIMEOUT));
 111 
 112         int cur_cnt = *(volatile int*)(GPIO_VSYNC_CURRENT) & 0xffff; // get the counter state at the time of sync
 113         
 114         int sync_period = std_period * 2 + cur_cnt;                  // schedule the end of extended period at t = t(synch pulse) + sync_time
 115         
 116         if (std_period - cur_cnt < 10)                               // if too close to overflow, wait for the next period
 117         {
 118             sync_period -= (std_period - cur_cnt);
 119             while ((*(volatile int*)(GPIO_VSYNC_CURRENT) & 0xffff) >= cur_cnt) {};
 120         }
 121         
 122         *(volatile int*)(GPIO_VSYNC_MAX) = sync_period; // write the length of the extended period to the register
 123         *(volatile int*)(GPIO_VSYNC_UPDATE) = 1;
 124 
 125         while (*(volatile int*)(GPIO_VSYNC_UPDATE)) {}; // wait until the new value is applied
 126         
 127         //now we are at the beginning of extended period
 128         
 129         *(volatile int*)(GPIO_VSYNC_MAX) = std_period; // back to standard timing on next period
 130         *(volatile int*)(GPIO_VSYNC_UPDATE) = 1;
 131         
 132         /* on s95 the std_period is 0x110
 133            1. if the shooting starts with GPIO_VSYNC_CURRENT value between 0 and 0xe1, it starts immediately
 134            2. if the shooting starts with value between 0xe1 and 0x110 (end of period), it waits for the next period
 135            
 136            now we want to go for the case 2
 137            msleep(40) should get us there, the timing is not critical and with sleep we give the camera a chance
 138            to run the delayed low prio tasks now
 139         */
 140         
 141         msleep(40); 
 142         
 143         // now we are in the second half of the extended period, shooting can start, it will wait for the end of the period
 144 
 145     #else // CAM_REMOTE_USES_PRECISION_SYNC
 146         // delay until USB state goes to "Off" or timeout
 147 
 148         do { }  while( get_remote_state() &&  ((int)get_tick_count()-tick < DELAY_TIMEOUT));
 149 
 150         // add a sync calibration delay if requested
 151 
 152         if ( conf.synch_delay_enable && conf.synch_delay_value>0 ) kbd_synch_delay( conf.synch_delay_value );
 153 
 154     #endif
 155     #ifdef USB_REMOTE_DEBUGGING   
 156         sync_counter++ ;
 157     #endif
 158         usb_sync_wait_flag = 0 ;
 159         usb_remote_status_led(0);       // alert the user that we are all done
 160     }
 161 
 162 }

/* [<][>][^][v][top][bottom][index][help] */