root/platform/g7x/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_byte_width
  20. vid_get_viewport_display_xoffset_proper
  21. vid_get_viewport_display_yoffset_proper
  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_aspect_ratio
  27. vid_get_bitmap_active_buffer
  28. vid_get_opacity_active_buffer
  29. update_screen_dimensions
  30. camera_jpeg_count_str

   1 #include "platform.h"
   2 #include "lolevel.h"
   3 #include "live_view.h"
   4 
   5 extern int active_bitmap_buffer;
   6 
   7 void vid_bitmap_refresh() {
   8     // clears perfectly but blinks and is asynchronous
   9 //    extern void _displaybusyonscreen();
  10 //    extern void _undisplaybusyonscreen();
  11 //    _displaybusyonscreen();
  12 //    _undisplaybusyonscreen();
  13 
  14     // https://chdk.setepontos.com/index.php?topic=12788.msg133958#msg133958
  15     extern void _transfer_src_overlay(int);
  16 // works in most cases but can cause "ghosting" in auto mode when canon UI constantly updates
  17 //  _transfer_src_overlay(active_bitmap_buffer);
  18     _transfer_src_overlay(0);
  19     _transfer_src_overlay(1);
  20 }
  21 
  22 void shutdown() {
  23 //***TODO***
  24 /*
  25     volatile long *p = (void*)0xC022001C;
  26 
  27     asm(
  28         "MRS     R1, CPSR\n"
  29         "AND     R0, R1, #0x80\n"
  30         "ORR     R1, R1, #0x80\n"
  31         "MSR     CPSR_cf, R1\n"
  32         :::"r1","r0"
  33     );
  34 
  35     *p = 0x44;  // power off.
  36 */
  37     while(1);
  38 }
  39 
  40 #define LED_PR 0xd20b0994 // green LED on the back
  41 
  42 void debug_led(int state) {
  43     volatile long *p = (void*)LED_PR;
  44     *p = ((state) ? 0x4d0002 : 0x4c0003);
  45 }
  46 
  47 // Power Led = first entry in table (led 0)
  48 // AF Assist Lamp = second entry in table (led 1)
  49 void camera_set_led(int led, int state, int bright) {
  50     static char led_table[2]={0,4};
  51     _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  52 }
  53 
  54 void shutdown_soft() {
  55     _PostLogicalEventForNotPowerType(0x1005,0); // PressOffButton
  56 }
  57 
  58 int get_flash_params_count(void) {
  59     return 0xde; // @0xfc0afeb8
  60 }
  61 
  62 void JogDial_CW(void) {
  63     _PostLogicalEventToUI(0x872, 1);    //RotateJogDialRight
  64 }
  65 
  66 void JogDial_CCW(void) {
  67     _PostLogicalEventToUI(0x873, 1);    //RotateJogDialLeft
  68 }
  69 
  70 // old method, incorrect in many cases
  71 extern  int     active_raw_buffer;
  72 extern  char*   raw_buffers_canon_raw[];
  73 extern  char*   raw_buffers_jpeg[];
  74 
  75 // updated by using function in capt_seq, valid between shot start and raw hook end
  76 extern  char*   current_raw_addr;
  77 
  78 char *hook_raw_image_addr()
  79 {
  80     if(current_raw_addr) {
  81         return current_raw_addr;
  82     }
  83     // TODO... fall back to old code.
  84     // Wron in many cases, but some code like benchmark assumes it get a raw buffer outside of shooting
  85     // observed values 0-2, 3 would index something that doesn't look like a raw fb in the jpeg case
  86     int i=active_raw_buffer&3;
  87     if(i>2) {
  88         i=0;
  89     }
  90     if( camera_info.state.mode_shooting == MODE_AUTO) {
  91         // AUTO mode (canon raw can't be enabled in AUTO)
  92         return (char *)0x46f04300; // TODO continuous shooting uses different buffers
  93     }else if(shooting_get_prop(PROPCASE_IMAGE_FORMAT) == 1) {
  94     // canon raw disabled - uses up to 3 raw buffers
  95         return raw_buffers_jpeg[i];
  96     } else {
  97         // canon raw enabled - different address, not clear if it ever uses multiple buffers
  98         return raw_buffers_canon_raw[i];
  99     }
 100     // TODO most scene modes seem to use different addresse(s)
 101 }
 102 
 103 // TODO
 104 /*
 105 char *hook_alt_raw_image_addr()
 106 {
 107     return raw_buffers[((active_raw_buffer&1)^1)];
 108 }
 109 */
 110 
 111 void *vid_get_viewport_fb() {
 112     return (void*)0x43334300; // "first" viewport adr, "VRAM Address  : %p", contains d6 uyvy
 113 // TODO sx280 values
 114     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
 115     //return (void*)0x43115100; // uyvy buffers with signed(?) chroma components
 116     // return (void*)0x4b25fc00; // uyvy buffers (more than 4), pixel format compatible with earlier DIGIC uyvy
 117 }
 118 /*
 119 playback viewport
 120 binview uyvy_d6 format
 121 TODO - 3 buffers 0x5e608000 0x5ea08000 0x5ee08000
 122 also 0x5e208000
 123 initially found by RAM dumping
 124 0x5e608000 ref sub_fc1ba3f0 "ImgDDev.c" 
 125 0x5ee08000 ref DispCon_ShowColorBar and other DispCon_* functions
 126 */
 127 void *vid_get_viewport_fb_d()    {
 128     // alternates between the 5e* buffers, but isn't correct when video selected
 129     // and doesn't do animated transitions
 130     /*
 131     void *p=*(void **)(0xa804);
 132     if(p) {
 133         return p;
 134     }
 135     return (void*)0x5e608000;
 136     */
 137     // based on suggestion from 62ndidiot in https://chdk.setepontos.com/index.php?topic=12532.msg129914#msg129914
 138     extern void *current_fb_d;
 139     return current_fb_d;
 140 } 
 141 
 142 /*
 143 live buffers
 144 binview uyvy_d6 format
 145 0x43334300 (from VRAM Address above)
 146 found by RAM dumping
 147 0x433e2b00 first plus 0xAE800, or 736*480*2=0xAC800 + 0x2000
 148 0x43491300
 149 0x4353fb00
 150 buffer list pointer at 0x398b4 (0x00039878 + 0x3c)->fc612b8, via sub fc13b7f2
 151 active index not found
 152 
 153 lower res uyvy_old format
 154 360x240
 155 0x5a3adc00
 156 0x5a3ed080
 157 0x5a42c500
 158 0x5a46b980
 159 0x5a4aae00
 160 0x5a4ea280
 161 0x5a529700
 162 0x5a568b80
 163 
 164 640x426
 165 0x5a5a8000
 166 0x5a63e000
 167 0x5a6d4000
 168 0x5a76a000
 169 0x5a800000
 170 0x5a896000
 171 0x5a92c000
 172 0x5a9c2000
 173 
 174 */
 175 extern void* viewport_buffers[];
 176 extern void *current_viewport_buffer;
 177 
 178 void *vid_get_viewport_live_fb()
 179 {
 180 // current_viewport_buffer doesn't seem to be most recent
 181     int i;
 182     for(i=0;i<4;i++) {
 183         if(current_viewport_buffer == viewport_buffers[i]) {
 184             return viewport_buffers[(i+1)&3];
 185         }
 186     }
 187     return 0;
 188 }
 189 
 190 // track viewport size changes with display type
 191 // only different for HDMI out, playback only, probably pointless
 192 static int vp_full_width = 720;
 193 static int vp_full_buf_width = 736;
 194 static int vp_full_height = 480;
 195 
 196 int vid_get_viewport_width() {
 197     extern int _GetVRAMHPixelsSize();
 198     if (camera_info.state.mode_play)
 199     {
 200         return vp_full_width;
 201     }
 202 // TODO: currently using actual width rather than half width used on pre d6
 203 // pixel format is uyvy (16bpp)
 204     return _GetVRAMHPixelsSize();
 205 }
 206 
 207 long vid_get_viewport_height() {
 208     extern int _GetVRAMVPixelsSize();
 209     if (camera_info.state.mode_play)
 210     {
 211         return vp_full_height;
 212     }
 213 // TODO: currently using actual height rather than 240 used on pre d6
 214     return _GetVRAMVPixelsSize();
 215 }
 216 
 217 int vid_get_viewport_yoffset() {
 218     // this seems to be always 0, buffer always begins with actual display data (widescreen or not)
 219     return 0;
 220 }
 221 //
 222 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5
 223 static long vp_xo[5] = { 40, 0, 0, 120, 168 };                          // should all be even values for edge overlay
 224 
 225 int vid_get_viewport_display_xoffset() {
 226     if (camera_info.state.mode_play)
 227     {
 228         return 0;
 229     }
 230     // video, ignore still res propcase
 231     if(camera_info.state.mode_video || is_video_recording()) {
 232         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) {
 233             return 40;// 4:3 video
 234         } else {
 235             return 0; // 16:9 video, no x offset
 236         }
 237     }
 238     return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 239 }
 240 
 241 int vid_get_viewport_display_yoffset() {
 242     if (camera_info.state.mode_play)
 243     {
 244         return 0;
 245     }
 246     // video, ignore still res propcase
 247     if(camera_info.state.mode_video || is_video_recording()) {
 248         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) {
 249             return 0; // 4:3 video, no Y offset
 250         } else {
 251             return 36; // 16:9 video
 252         }
 253     }
 254     if (shooting_get_prop(PROPCASE_ASPECT_RATIO) == 1)
 255     {
 256         return 36;
 257     }
 258     return 0;
 259 }
 260 
 261 extern char* bitmap_buffer[];
 262 
 263 void *vid_get_bitmap_fb() {
 264     return (void *)0x41441000; // from sub_fc0f7c21, alt 4153e200
 265 }
 266 
 267 int vid_get_viewport_byte_width() {
 268     return (vp_full_width * 2);
 269 }
 270 
 271 // Functions for PTP Live View system
 272 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset(); }
 273 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset(); }
 274 int vid_get_viewport_fullscreen_width()         { return vp_full_width; }
 275 int vid_get_viewport_fullscreen_height()        { return vp_full_height; }
 276 int vid_get_viewport_buffer_width_proper()      { return vp_full_buf_width; }
 277 int vid_get_viewport_type()                     { return LV_FB_YUV8B; }
 278 int vid_get_aspect_ratio()                      { return LV_ASPECT_3_2; }
 279 void *vid_get_bitmap_active_buffer() {
 280     return bitmap_buffer[active_bitmap_buffer&1];
 281 }
 282 /*
 283 note RGBA bitmap buffer, 640x480 on 960x480 buffer
 284 0x42541000
 285 0x42703000
 286 doesn't seem to be a simple double buffer, UI shows up in first focus box shows up in second
 287 */
 288 
 289 // the opacity buffer defines opacity for the bitmap overlay's pixels
 290 // found near BmpDDev.c line 215 assert fc0f7b58
 291 volatile char *opacity_buffer[2] = {(char*)0x4163b400, (void*)0x416b9d00};
 292 
 293 // 0x10108 also appears to contain the active buffer
 294 void *vid_get_opacity_active_buffer() {
 295     return (void *)opacity_buffer[active_bitmap_buffer&1];
 296 }
 297 
 298 #ifdef CAM_SUPPORT_BITMAP_RES_CHANGE
 299 /*
 300  * needed because bitmap buffer resolutions change when an external display is used
 301  * an extra screen erase doesn't seem to be needed
 302  */
 303 void update_screen_dimensions() {
 304     // see sub_fc0f7aae
 305     extern int displaytype;
 306     static int old_displaytype = -1;
 307 
 308     if (old_displaytype == displaytype) {
 309         return;
 310     }
 311     old_displaytype = displaytype;
 312 
 313     switch(displaytype) {
 314         case 0:
 315         case 3:
 316         case 4:
 317         case 5:
 318             // 640, ? not used
 319             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 640;
 320             camera_screen.height = camera_screen.buffer_height = 480;
 321             camera_screen.size = camera_screen.buffer_size = 640*480;
 322             break;
 323         case 1: // TV out NTSC
 324         case 2: // TV out PAL
 325         case 8:
 326         case 9: 
 327         case 10:// LCD
 328             camera_screen.width = camera_screen.physical_width = 720;
 329             camera_screen.buffer_width = 736;
 330             camera_screen.height = camera_screen.buffer_height = 480;
 331             camera_screen.size = 720*480;
 332             camera_screen.buffer_size = 736*480;
 333             break;
 334         case 6: // HDMI (playback only) (video standard NTSC)
 335         case 7: // " (video standard PAL)
 336             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 960;
 337             camera_screen.height = camera_screen.buffer_height = 540;
 338             camera_screen.size = camera_screen.buffer_size = 960*540;
 339             break;
 340         case 11:// O_o
 341             camera_screen.width = 1024;
 342             camera_screen.physical_width = camera_screen.buffer_width = 1024;
 343             camera_screen.height = camera_screen.buffer_height = 768;
 344             camera_screen.size = 1024*768;
 345             camera_screen.buffer_size = 1024*768;
 346             break;
 347     }
 348     if(displaytype == 6 || displaytype == 7) {
 349         vp_full_width = 1920;
 350         vp_full_buf_width = 1920;
 351         vp_full_height = 1080;
 352     } else {
 353         // others are unclear, but unlikely to come up in practice
 354         vp_full_width = 720;
 355         vp_full_buf_width = 736;
 356         vp_full_height = 480;
 357     }
 358 }
 359 #endif
 360 
 361 char *camera_jpeg_count_str()
 362 {
 363     extern char jpeg_count_str[];
 364         return jpeg_count_str;
 365 }

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