root/platform/ixus30_sd200/lib.c

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

DEFINITIONS

This source file includes following definitions.
  1. _time
  2. set_shooting_status
  3. _GetPropertyCase
  4. _SetPropertyCase
  5. shutdown
  6. dummy_nop
  7. led_on
  8. led_off
  9. debug_led
  10. get_flash_params_count
  11. set_led
  12. camera_set_led
  13. get_uiprop_value

   1 #include "platform.h"
   2 #include "lolevel.h"
   3 #include "levent.h"
   4 #define PARAM_FILE_COUNTER      0x2A
   5 
   6 extern void _sub_FF821D04(long mem, long *data);
   7 extern long _GetPropertyCase_orig(long opt_id, void *buf, long bufsize);
   8 extern long _SetPropertyCase_orig(long opt_id, void *buf, long bufsize);
   9 extern void _SetAFBeamBrightness(long val);
  10 extern void _SetAFBeamOff();
  11 extern unsigned long _time_orig(unsigned long *timer);
  12 
  13 static unsigned long bootuptime = 0;
  14 
  15 unsigned long _time(__attribute__ ((unused))unsigned long *timer) {
  16 /*
  17 the original "time" function doesn't seem to work correctly
  18 chdk's clock display runs at around 1/7 speed with it (the display is only correct right after bootup)
  19 this hack provides a replacement using GetSystemTime (which incements every 1ms, I guess),
  20 but it will be off by a few seconds.
  21 There might be a fault in this chdk port somewhere...
  22 */
  23 unsigned long timer2; //unsigned long *timer will be NULL when called from chdk
  24     _GetSystemTime((long*)&timer2);
  25     if (bootuptime == 0) {
  26         bootuptime = _time_orig((unsigned long*)0)-(timer2)/1000;
  27     }
  28     return bootuptime+(timer2)/1000;
  29 }
  30 
  31 //workaround
  32 //strange, on my cam the propcase_shooting (205)
  33 //has always a strange value... is this on every sd300 ?
  34 //(mine was once damaged by water on the circuit board)
  35 //or is it just at a different location ?! fixme
  36 
  37 
  38 //data handler for propcase_shooting workaround:
  39 //i think this should be done with a semaphore... for now it should work
  40 volatile long shooting_status_=0;
  41 
  42 // volatile long shbuf[100];
  43 // volatile long shbufi=0;
  44 
  45 void set_shooting_status(long l){
  46 //     if (shbufi<100){
  47 //         if (shbuf[shbufi] != l){
  48 //             shbufi++;
  49 //             shbuf[shbufi] = l;
  50 //         }
  51 //     }
  52     
  53     //shooting_status_=l;
  54     //return;
  55      switch(l){
  56          case(0x0): 
  57              //picture mode: focussing
  58              shooting_status_=1;
  59              break;
  60          case(0x1): 
  61              //picture mode: charge flash & do snapshot
  62              shooting_status_=1;
  63              break;
  64          case(0x2): 
  65              //picture mode: maybe stitch assist related
  66              shooting_status_=0;
  67              break;
  68          case(0x3): 
  69              //picture mode: idle
  70              shooting_status_=0;
  71              break;
  72          case(0x6): 
  73              //video mode: focus & rec
  74              shooting_status_=1;
  75              break;
  76          case(0x7): 
  77              //video mode: idle
  78              shooting_status_=0;
  79              break;
  80          case (0xb):
  81              //idle in play mode ?!
  82              shooting_status_=0;
  83              break;
  84              
  85          default:
  86              shooting_status_=0;
  87              break;
  88      }
  89 }
  90 
  91 
  92 long _GetPropertyCase(long cse, void *ptr, long len){
  93     if (cse == PROPCASE_SHOOTING){
  94         if (len==sizeof(long)){
  95             *(long*)ptr = shooting_status_;
  96         }else if (len==sizeof(short)){
  97             *(short*)ptr = shooting_status_;
  98         }else{
  99             //??? FIXME
 100         }
 101     }else{
 102         return _GetPropertyCase_orig(cse, ptr, len);
 103     }
 104     return 0;
 105 }
 106 
 107 long _SetPropertyCase(long cse, void *ptr, long len){
 108 /*
 109 PROPCASE_SV_MARKET, PROPCASE_SV, PROPCASE_DELTA_SV -> lower ISO values cause crash
 110 */
 111     if (cse == PROPCASE_SHOOTING){
 112         //do nothing
 113         return 0;
 114     }else{
 115         return _SetPropertyCase_orig(cse, ptr, len);
 116     }
 117 }
 118 
 119 void shutdown()
 120 {
 121     volatile long *p = (void*)0xc022002c;
 122         
 123     asm(
 124          "MRS     R1, CPSR\n"
 125          "AND     R0, R1, #0x80\n"
 126          "ORR     R1, R1, #0x80\n"
 127          "MSR     CPSR_cf, R1\n"
 128          :::"r1","r0");
 129         
 130     *p = 0x46;
 131 
 132     while(1);
 133 }
 134 
 135 // typedef unsigned short  color;
 136 // void mydebug(long l){
 137 //     //"ldr r0, =3\nbl mydebug\nLDMFD   SP!, {R0}\n"
 138 //     char buf[100];
 139 //     sprintf(buf,"dbg=%ld",l);
 140 // 
 141 // #define MAKE_COLOR(bg, fg)        ((color)((((char)(bg))<<8)|((char)(fg))))
 142 // 
 143 //     draw_txt_string(2, 2, buf, MAKE_COLOR(0xD4, 10));
 144 //     msleep(100);
 145 // }
 146 
 147 void dummy_nop(){
 148 }
 149 
 150 
 151 #define LED_PR 0xc0220088 //?
 152 #define LED_BRIGHTNESS  200
 153 #define LED_GREEN       4
 154 #define LED_YELLOW      5
 155 #define LED_ORANGE      7
 156 #define LED_BLUE        8
 157 #define LED_AF_BEAM     9
 158 #define LED_TIMER       10
 159 
 160 //sd300:
 161 //0xBC24 --> 0x00000000
 162 //0xBC28 --> 0xC02200D8 = green  (pair)
 163 //0xBC2C --> 0xC02200DC = orange (pair)
 164 //0xBC30 --> 0xC02200E0 = yellow
 165 //0xBC34 --> 0xC02200E8 = green power led
 166 //0xBC38 --> 0x00000000
 167 //0xBC3C --> 0x00000000
 168 //0xBC40 --> 0x00000000
 169 //0xBC44 --> 0x00000000
 170 //0xBC48 --> 0xC02200E4 = blue
 171 //0xBC4C --> 0xC02200EC = af beam 
 172 //0xBC50 --> 0x00000000
 173     
 174 //LED stuff verified as working: 30.07.2008
 175 static void led_on(const int led, const int brightness)
 176 {
 177     if (led < 4 || led > 10 || led == 6) return;
 178     //on sd400 the led stuff works like this: 
 179     //led_addr = led_table + (led * 0x40)
 180     //
 181     //if (mem(led_addr) == 0){
 182     //  mem(led_addr + 4) = 0x46; //=ON
 183     //}else if (mem(led_addr) == 1){
 184     //  af_led_sub(led_addr)
 185     //}
 186     //
 187     //ok on sd300 something like ledUniqueOn doesnt seem
 188     //to exist. so build our own lib:
 189     
 190     volatile long *p; 
 191     switch(led){
 192         case (LED_GREEN) : p=(void*)0xc02200D8; break;
 193         case (LED_ORANGE): p=(void*)0xc02200DC; break;
 194         case (LED_YELLOW): p=(void*)0xc02200E0; break;
 195         case (LED_BLUE)  : p=(void*)0xc02200E4; break;
 196         case (LED_AF_BEAM): p=(void*)0xc02200EC; break;
 197         default: return;
 198     }
 199     
 200     if (led == LED_AF_BEAM){
 201         _SetAFBeamBrightness(brightness);
 202     }else{
 203         *p=0x46;
 204     }
 205 }
 206 
 207 //LED stuff verified as working: 30.07.2008
 208 static void led_off(const int led)
 209 {
 210    if (led < 4 || led > 10 || led == 6) return;
 211        
 212     volatile long *p; 
 213     switch(led){
 214         case (LED_GREEN) : p=(void*)0xc02200D8; break;
 215         case (LED_ORANGE): p=(void*)0xc02200DC; break;
 216         case (LED_YELLOW): p=(void*)0xc02200E0; break;
 217         case (LED_BLUE)  : p=(void*)0xc02200E4; break;
 218         case (LED_AF_BEAM): p=(void*)0xc02200EC; break;
 219         default: return;
 220     }
 221     
 222     if (led == LED_AF_BEAM){
 223         _SetAFBeamOff();
 224     }else{
 225         *p=0x44;
 226     }
 227  
 228 }
 229 
 230 void debug_led(int state)
 231 {
 232     if (state)
 233         led_on(LED_BLUE, LED_BRIGHTNESS);
 234     else
 235         led_off(LED_BLUE);
 236 }
 237 
 238 int get_flash_params_count(void){
 239  return 70;
 240 }
 241 
 242 void set_led(int led, int state)
 243 {
 244     if (state)
 245         led_on(led, LED_BRIGHTNESS);
 246     else
 247         led_off(led);
 248 }
 249 void camera_set_led(int led, int state, int bright)
 250 {
 251         if (state) {
 252                 if (bright > LED_BRIGHTNESS) bright = LED_BRIGHTNESS;
 253                 if (led == 6) {
 254                 led_on(4, bright);
 255                     led_on(5, bright);
 256                 } else
 257                         led_on(led, bright);
 258         }
 259     else
 260                 if (led == 6) {
 261                 led_off(4);
 262                     led_off(5);
 263                 } else
 264         led_off(led);
 265 }
 266 
 267 short get_uiprop_value(unsigned long id)
 268 {
 269     // avoid asserts: return 0 if id is above limit
 270     if (id >= (unsigned)uiprop_count)
 271         return 0;
 272     return _PTM_GetCurrentItem(id);
 273 }
 274 
 275 /*
 276 int switch_mode_usb(int mode)
 277 {
 278     if ( mode == 0 ) {
 279         //extern void _EnterToPlayFromRec();
 280         //_EnterToPlayFromRec();
 281         //levent_post_to_ui_by_name("ModeLeverPlay");
 282         levent_post_to_ui_by_name("ConnectUSBCable");
 283     } else if ( mode == 1 ) {
 284         //extern void _EnterToRecFromPlay();
 285         //_EnterToRecFromPlay(); ineffective
 286         //levent_post_to_ui_by_name("ModeLeverStillRec"); mode switch but bad state, no USB
 287         levent_post_to_ui_by_name("DisconnectUSBCable"); crash
 288     } else return 0;
 289     return 1;
 290 }
 291 */

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