root/platform/sx60hs/lib.c

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

DEFINITIONS

This source file includes following definitions.
  1. vid_bitmap_refresh
  2. shutdown
  3. debug_led
  4. camera_set_led
  5. shutdown_soft
  6. get_flash_params_count
  7. JogDial_CW
  8. JogDial_CCW
  9. hook_raw_image_addr
  10. vid_get_viewport_fb
  11. vid_get_viewport_fb_d
  12. vid_get_viewport_live_fb
  13. vid_get_viewport_width
  14. vid_get_viewport_height
  15. vid_get_viewport_yoffset
  16. vid_get_viewport_display_xoffset
  17. vid_get_viewport_display_yoffset
  18. vid_get_bitmap_fb
  19. vid_get_viewport_display_xoffset_proper
  20. vid_get_viewport_display_yoffset_proper
  21. vid_get_viewport_byte_width
  22. vid_get_viewport_fullscreen_width
  23. vid_get_viewport_fullscreen_height
  24. vid_get_viewport_buffer_width_proper
  25. vid_get_viewport_type
  26. vid_get_bitmap_active_buffer
  27. vid_get_opacity_active_buffer
  28. camera_jpeg_count_str
  29. update_screen_dimensions

   1 #include "platform.h"
   2 #include "lolevel.h"
   3 #include "live_view.h"
   4 
   5 static char* frame_buffer[2];
   6 
   7 extern int displaytype;
   8 extern void _LogCameraEvent(int id, const char *fmt,...);
   9 extern int active_bitmap_buffer;
  10 extern void* bitmap_buffer[];
  11 extern char* raw_buffers_canon_raw[];
  12 extern char* raw_buffers_jpeg[];
  13 
  14 void vid_bitmap_refresh() {
  15 
  16     extern int active_bitmap_buffer;
  17     extern void _transfer_src_overlay(int);
  18     _transfer_src_overlay(0);
  19     _transfer_src_overlay(1);
  20 }
  21 
  22 void shutdown() {
  23 /*
  24     volatile long *p = (void*)0xC022001C;
  25 
  26     asm(
  27         "MRS     R1, CPSR\n"
  28         "AND     R0, R1, #0x80\n"
  29         "ORR     R1, R1, #0x80\n"
  30         "MSR     CPSR_cf, R1\n"
  31         :::"r1","r0"
  32     );
  33 
  34     *p = 0x44;  // power off.
  35 */
  36     while(1);
  37 }
  38 
  39 #define LED_PR 0xd20b0994 // green LED on the back
  40 
  41 void debug_led(int state) {
  42     volatile long *p = (void*)LED_PR;
  43     *p = ((state) ? 0x4d0002 : 0x4c0003);
  44 }
  45 
  46 // Power Led = first entry in table (led 0)
  47 // AF Assist Lamp = second entry in table (led 1)
  48 void camera_set_led(int led, int state, int bright) {
  49     static char led_table[2]={0,4};
  50     _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  51 }
  52 
  53 void shutdown_soft() {
  54     _PostLogicalEventForNotPowerType(0x1005,0); // PressOffButton
  55 }
  56 
  57 int get_flash_params_count(void) {
  58     return 0xde; // @0xfc0afeb8
  59 }
  60 
  61 void JogDial_CW(void) {
  62     _PostLogicalEventToUI(0x8ad, 1);    //RotateJogDialRight 
  63 }
  64 
  65 void JogDial_CCW(void) {
  66     _PostLogicalEventToUI(0x8ae, 1);    //RotateJogDialLeft
  67 }
  68 
  69 extern  int     active_raw_buffer;
  70 extern  char*   current_raw_addr;
  71 //extern  char*   raw_buffers[];
  72 char *hook_raw_image_addr()
  73 {
  74     if (current_raw_addr) {
  75          return current_raw_addr;
  76     }
  77 // fall back to old code which will be wrong in many cases.....
  78     // observed values 0-2, 3 would index something that doesn't look like a raw fb in the jpeg case
  79     int i=active_raw_buffer&3;
  80 /*
  81     _LogCameraEvent(0x20,"lc: hria: %i %i %08x %i",i, camera_info.state.mode_shooting,
  82                                               camera_info.state.mode_shooting,
  83                                               shooting_get_prop(PROPCASE_IMAGE_FORMAT));
  84 */ 
  85     if(i>2) {
  86         i=0;
  87     }
  88     if( camera_info.state.mode_shooting == MODE_AUTO) {
  89         // AUTO mode (canon raw can't be enabled in AUTO)
  90         return (char *)0x435ee300; // TODO unclear if this is only buffer, or if used in all AUTO sub modes
  91     }else if(shooting_get_prop(PROPCASE_IMAGE_FORMAT) == 1) {
  92     // canon raw disabled - uses up to 3 raw buffers
  93         return raw_buffers_jpeg[i];
  94     } else {
  95         // canon raw enabled - different address, not clear if it ever uses multiple buffers
  96         return raw_buffers_canon_raw[i];
  97     }
  98     // TODO most scene modes seem to use different addresse(s)
  99 }
 100 
 101 /* 
 102 char *hook_raw_image_addr()
 103 {
 104       return raw_buffers_jpeg[(active_raw_buffer&1)];
 105 }
 106 
 107 char *hook_alt_raw_image_addr()
 108 {
 109     return raw_buffers_jpeg[((active_raw_buffer&1)^1)];
 110 }
 111 */
 112 
 113 
 114 
 115 
 116 
 117 void *vid_get_viewport_fb() {
 118     return (void*)0x43334300; // same as g7x "first" viewport adr, "VRAM Address  : %p", contains d6 uyvy
 119 // TODO sx280 values
 120     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
 121     //return (void*)0x43115100; // uyvy buffers with signed(?) chroma components
 122     // return (void*)0x4b25fc00; // uyvy buffers (more than 4), pixel format compatible with earlier DIGIC uyvy
 123 }
 124 
 125 //void *vid_get_viewport_fb_d()    { return (void*)0x5e878000; } //by comparison with g7x
 126 void *vid_get_viewport_fb_d()    { 
 127   extern void *current_fb_d;
 128   return current_fb_d;
 129  } 
 130 //void *vid_get_viewport_fb_d()    { return (void*)0x43334300; } 
 131 //void *vid_get_viewport_fb_d()    { return (void*)0x465ebb40; } 
 132 /* live buffers the list is found at 0xfc5cf054 on 100f and at 0xfc5cf040 on 100b
 133   first at 0x43334000 
 134 strangely these increment like the g7x (by 0xae800)  case which has higher rez
 135   640*2*480 = 0x96000 + 0x18800 ae800
 136  0x43334300
 137  0x433e2b00
 138  0x43491300
 139  0x4353fb00
 140 */
 141 extern void* viewport_buffers[];
 142 extern void *current_viewport_buffer;
 143 
 144 void *vid_get_viewport_live_fb()
 145 {
 146 // current_viewport_buffer doesn't seem to be most recent
 147     int i;
 148     for(i=0;i<4;i++) {
 149         if(current_viewport_buffer == viewport_buffers[i]) {
 150             return viewport_buffers[(i+1)&3];
 151         }
 152     }
 153     return 0;
 154 }
 155 
 156 
 157 int vid_get_viewport_width() {
 158 /*
 159 loc_fc134980: ; 4 refs (GetVRAMHPixelsSize)
 160 fc134980:   487d        ldr r0, [pc, #500]  ; 0xfc134b78: (0002ca18) 
 161 fc134982:   f8d0 00ac   ldr.w   r0, [r0, #172]  ; 0xac
 162 fc134986:   4770        bx  lr
 163 */
 164    if (camera_info.state.mode_play)
 165    { 
 166        return camera_screen.physical_width; 
 167 //     return 360; //todo
 168    }
 169     extern int _GetVRAMHPixelsSize();
 170     return _GetVRAMHPixelsSize();
 171 }
 172 
 173 long vid_get_viewport_height() {
 174 /*
 175 loc_fc134988: ; 3 refs (GetVRAMVPixelsSize)
 176 fc134988:   487b        ldr r0, [pc, #492]  ; 0xfc134b78: (0002ca18) 
 177 fc13498a:   f8d0 00b0   ldr.w   r0, [r0, #176]  ; 0xb0
 178 fc13498e:   4770        bx  lr
 179 */
 180 /*
 181     int m = mode_get();
 182     int aspect_ratio=shooting_get_prop(PROPCASE_ASPECT_RATIO);
 183 
 184     if (MODE_IS_VIDEO(m) || is_video_recording())
 185         return 480;
 186 
 187     if ((m & MODE_MASK) != MODE_PLAY)
 188     {
 189         // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 190         if (aspect_ratio==1 || aspect_ratio==2)
 191             return 480;
 192     }
 193     
 194     extern int _GetVRAMVPixelsSize();
 195     return ((m & MODE_MASK) == MODE_PLAY)?480:_GetVRAMVPixelsSize();
 196 */
 197        extern int _GetVRAMVPixelsSize();
 198 // return half height
 199     if (camera_info.state.mode_play)
 200         return camera_screen.buffer_height;
 201     return _GetVRAMVPixelsSize();
 202 }
 203 
 204 // viewport width offset table for each aspect ratio
 205 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1 4 = 4:5
 206 static long vp_xo[5] = { 0, 0, 0, 80, 128 };// should all be even values for edge overlay
 207 static long vp_yo[5] = {0, 60, 28, 0, 0};
 208 
 209 int vid_get_viewport_yoffset() {
 210     int aspect_ratio=shooting_get_prop(PROPCASE_ASPECT_RATIO);
 211 
 212         return 0;
 213 }
 214 
 215 
 216 int vid_get_viewport_display_xoffset() {
 217 
 218     if (camera_info.state.mode_play) {
 219         return 0;
 220     }
 221     // video, ignore still res propcase
 222     if(camera_info.state.mode_video || is_video_recording()) {
 223             return 0; //all video modes for now
 224     }
 225     return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 226 
 227 }
 228 
 229 int vid_get_viewport_display_yoffset() {
 230     if (camera_info.state.mode_play) {
 231         return 0;
 232     }
 233     else {
 234         if(camera_info.state.mode_video || is_video_recording()) {
 235                 return 0; //all video modes
 236         }
 237     } 
 238     return (vp_yo[shooting_get_prop(PROPCASE_ASPECT_RATIO)]);
 239 
 240 }
 241 
 242 
 243 //extern int active_bitmap_buffer;
 244 //int active_bitmap_buffer = 0;
 245 //extern char* bitmap_buffer[];
 246 
 247 void *vid_get_bitmap_fb() {
 248 //    return (void *)0x41441000; //  from sub_fc0f8804, alt 4153e200
 249       return bitmap_buffer[0];
 250 }
 251 
 252 // TODO
 253 // Functions for PTP Live View system
 254 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() ; }
 255 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset() ; }
 256 int vid_get_viewport_byte_width() {
 257 // digic 6 uYvY    2 pixels per 4 bytes
 258   return (640 * 2);
 259 }
 260 int vid_get_viewport_fullscreen_width()         { return camera_screen.width; }
 261 int vid_get_viewport_fullscreen_height()        { return camera_screen.height; }
 262 int vid_get_viewport_buffer_width_proper()      { return camera_screen.buffer_width; } // may not be always ok
 263 int vid_get_viewport_type()                     { return LV_FB_YUV8B; }
 264 
 265 void *vid_get_bitmap_active_buffer() {
 266     return bitmap_buffer[active_bitmap_buffer&1];
 267 }
 268 
 269 // the opacity buffer defines opacity for the bitmap overlay's pixels
 270 // found near BmpDDev.c line 215 assert fc0f873c
 271 volatile char *opacity_buffer[2] = {(char*)0x4163b400, (void*)0x416b9d00};
 272 void *vid_get_opacity_active_buffer() {
 273     return (void *)opacity_buffer[active_bitmap_buffer&1];
 274 }
 275 // now in platform_palette.c
 276 //void *vid_get_bitmap_active_palette() {
 277 //    return (void*)0x8000; // just to return something valid, no palette needed on this cam
 278 //}
 279 char *camera_jpeg_count_str()
 280 {
 281     extern char jpeg_count_str[];
 282         return jpeg_count_str;
 283 }
 284 #ifdef CAM_SUPPORT_BITMAP_RES_CHANGE
 285 /*
 286  * needed because bitmap buffer resolutions change when an external display is used
 287  * an extra screen erase doesn't seem to be needed
 288  */
 289 void update_screen_dimensions() {
 290     extern int displaytype;
 291     static int old_displaytype = -1;
 292 
 293     if (old_displaytype == displaytype) {
 294         return;
 295     }
 296  
 297     _LogCameraEvent(0x60,"lc: odt: %d dt: %d csw: %d csh: %d css: %d",
 298                 old_displaytype, displaytype, camera_screen.width,
 299                  camera_screen.height, camera_screen.size);
 300     camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 640;
 301     camera_screen.height = camera_screen.buffer_height = 480;
 302     camera_screen.size = camera_screen.buffer_size = 640*480;
 303     old_displaytype = displaytype;
 304     switch(displaytype) {
 305         case 0:
 306         case 3:
 307         case 4:
 308             // lcd
 309             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 640;
 310             camera_screen.height = camera_screen.buffer_height = 480;
 311             camera_screen.size = camera_screen.buffer_size = 640*480;
 312             break;
 313         case 5:
 314         case 1:
 315         case 2:
 316         case 8:
 317         case 9:
 318             // tv-out
 319             camera_screen.width = 720;
 320             camera_screen.physical_width = camera_screen.buffer_width = 736;
 321             camera_screen.height = camera_screen.buffer_height = 480;
 322             camera_screen.size = 720*480;
 323             camera_screen.buffer_size = 736*480;
 324             break;
 325         case 6:
 326             // hdmi
 327             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 960;
 328             camera_screen.height = camera_screen.buffer_height = 540;
 329             camera_screen.size = camera_screen.buffer_size = 960*540;
 330             break;
 331     }
 332 }
 333 #endif
 334 

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