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

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