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, __attribute__ ((unused))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 static int vp_full_width = 720;
 192 static int vp_full_buf_width = 736;
 193 static int vp_full_height = 480;
 194 static int lv_aspect = LV_ASPECT_3_2; // expected physical aspect ratio depends on output type
 195 
 196 // NOTE: digic 6 currently using actual width rather than half width used on pre d6
 197 // pixel format is uyvy (16bpp)
 198 int vid_get_viewport_width() {
 199     extern int _GetVRAMHPixelsSize();
 200     if (camera_info.state.mode_play)
 201     {
 202         return vp_full_width;
 203     }
 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     return _GetVRAMVPixelsSize();
 214 }
 215 
 216 int vid_get_viewport_yoffset() {
 217     // this seems to be always 0, buffer always begins with actual display data (widescreen or not)
 218     return 0;
 219 }
 220 
 221 // should all be even values for edge overlay
 222 static long vp_xo[3][5] = {
 223 // 0=4:3, 1=16:9, 2=3:2, 3=1:1, 4=4:5
 224     {  0,     0,     0,    90,   144 }, // analog out 4:3
 225     {  0,     0,     0,     0,     0 }, // 16:9 dummy, only applies to playback
 226     { 40,     0,     0,   120,   168 }, // LCD 3x2
 227 };
 228 
 229 int vid_get_viewport_display_xoffset() {
 230     if (camera_info.state.mode_play)
 231     {
 232         return 0;
 233     }
 234     // video, ignore still res propcase
 235     if(camera_info.state.mode_video || is_video_recording()) {
 236         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) {
 237             return vp_xo[lv_aspect][0];// 4:3 video
 238         } else {
 239             return 0; // 16:9 video, no x offset
 240         }
 241     }
 242     return vp_xo[lv_aspect][shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 243 }
 244 
 245 static long vp_yo[3][5] = {
 246 // 0=4:3, 1=16:9, 2=3:2, 3=1:1, 4=4:5
 247     {  0,     60,    27,     0,     0 }, // analog out 4:3
 248     {  0,      0,     0,     0,     0 }, // 16:9 dummy, only applies to playback
 249     {  0,     36,     0,     0,     0 }, // LCD 3x2 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5
 250 };
 251 
 252 int vid_get_viewport_display_yoffset() {
 253     if (camera_info.state.mode_play)
 254     {
 255         return 0;
 256     }
 257     // video, ignore still res propcase
 258     if(camera_info.state.mode_video || is_video_recording()) {
 259         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) {
 260             return 0; // 4:3 video, no Y offset
 261         } else {
 262             return vp_yo[lv_aspect][1];// 16:9 video
 263         }
 264     }
 265     return vp_yo[lv_aspect][shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 266 }
 267 
 268 extern char* bitmap_buffer[];
 269 
 270 void *vid_get_bitmap_fb() {
 271     return (void *)0x41441000; // from sub_fc0f7c21, alt 4153e200
 272 }
 273 
 274 int vid_get_viewport_byte_width() {
 275     return (vp_full_buf_width * 2);
 276 }
 277 
 278 // Functions for PTP Live View system
 279 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset(); }
 280 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset(); }
 281 int vid_get_viewport_fullscreen_width()         { return vp_full_width; }
 282 int vid_get_viewport_fullscreen_height()        { return vp_full_height; }
 283 int vid_get_viewport_buffer_width_proper()      { return vp_full_buf_width; }
 284 int vid_get_viewport_type()                     { return LV_FB_YUV8B; }
 285 int vid_get_aspect_ratio()                      { return lv_aspect; }
 286 void *vid_get_bitmap_active_buffer() {
 287     return bitmap_buffer[active_bitmap_buffer&1];
 288 }
 289 /*
 290 note RGBA bitmap buffer, 640x480 on 960x480 buffer
 291 0x42541000
 292 0x42703000
 293 doesn't seem to be a simple double buffer, UI shows up in first focus box shows up in second
 294 */
 295 
 296 // the opacity buffer defines opacity for the bitmap overlay's pixels
 297 // found near BmpDDev.c line 215 assert fc0f7b58
 298 volatile char *opacity_buffer[2] = {(char*)0x4163b400, (void*)0x416b9d00};
 299 
 300 // 0x10108 also appears to contain the active buffer
 301 void *vid_get_opacity_active_buffer() {
 302     return (void *)opacity_buffer[active_bitmap_buffer&1];
 303 }
 304 
 305 #ifdef CAM_SUPPORT_BITMAP_RES_CHANGE
 306 /*
 307  * needed because bitmap buffer resolutions change when an external display is used
 308  * an extra screen erase doesn't seem to be needed
 309  */
 310 void update_screen_dimensions() {
 311     // see sub_fc0f7aae
 312     extern int displaytype;
 313     static int old_displaytype = -1;
 314 
 315     if (old_displaytype == displaytype) {
 316         return;
 317     }
 318     old_displaytype = displaytype;
 319 
 320     switch(displaytype) {
 321         case 0:
 322         case 3:
 323         case 4:
 324         case 5:
 325             // 640, ? not used
 326             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 640;
 327             camera_screen.height = camera_screen.buffer_height = 480;
 328             camera_screen.size = camera_screen.buffer_size = 640*480;
 329             break;
 330         case 1: // TV out NTSC
 331         case 2: // TV out PAL
 332         case 8: // HDMI on displays not capable of 1080i, 720x480, expected physical aspect ratio unclear
 333         case 9:
 334         case 10:// LCD
 335             camera_screen.width = camera_screen.physical_width = 720;
 336             camera_screen.buffer_width = 736;
 337             camera_screen.height = camera_screen.buffer_height = 480;
 338             camera_screen.size = 720*480;
 339             camera_screen.buffer_size = 736*480;
 340             break;
 341         case 6: // HDMI (playback only) (video standard NTSC)
 342         case 7: // " (video standard PAL)
 343             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 960;
 344             camera_screen.height = camera_screen.buffer_height = 540;
 345             camera_screen.size = camera_screen.buffer_size = 960*540;
 346             break;
 347         case 11:// O_o
 348             camera_screen.width = 1024;
 349             camera_screen.physical_width = camera_screen.buffer_width = 1024;
 350             camera_screen.height = camera_screen.buffer_height = 768;
 351             camera_screen.size = 1024*768;
 352             camera_screen.buffer_size = 1024*768;
 353             break;
 354     }
 355     if(displaytype == 6 || displaytype == 7) {
 356         vp_full_width = 1920;
 357         vp_full_buf_width = 1920;
 358         vp_full_height = 1080;
 359         lv_aspect = LV_ASPECT_16_9;
 360     } else {
 361         // others are unclear, but unlikely to come up in practice
 362         vp_full_width = 720;
 363         vp_full_buf_width = 736;
 364         vp_full_height = 480;
 365         if(displaytype == 10) { // LCD is 3:2
 366             lv_aspect = LV_ASPECT_3_2;
 367         } else { // TV out is 4:3, low res HDMI looks correct at 4:3
 368             lv_aspect = LV_ASPECT_4_3;
 369         }
 370     }
 371 }
 372 #endif
 373 
 374 char *camera_jpeg_count_str()
 375 {
 376     extern char jpeg_count_str[];
 377         return jpeg_count_str;
 378 }

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