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