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 int vid_get_viewport_width() {
 191     extern int _GetVRAMHPixelsSize();
 192     if (camera_info.state.mode_play)
 193     {
 194         return 720;
 195     }
 196 // TODO: currently using actual width rather than half width used on pre d6
 197 // pixel format is uyvy (16bpp)
 198     return _GetVRAMHPixelsSize();
 199 }
 200 
 201 long vid_get_viewport_height() {
 202     extern int _GetVRAMVPixelsSize();
 203     if (camera_info.state.mode_play)
 204     {
 205         return 480;
 206     }
 207 // TODO: currently using actual height rather than 240 used on pre d6
 208     return _GetVRAMVPixelsSize();
 209 }
 210 
 211 int vid_get_viewport_yoffset() {
 212     // this seems to be always 0, buffer always begins with actual display data (widescreen or not)
 213     return 0;
 214 }
 215 //
 216 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5
 217 static long vp_xo[5] = { 40, 0, 0, 120, 168 };                          // should all be even values for edge overlay
 218 
 219 int vid_get_viewport_display_xoffset() {
 220     if (camera_info.state.mode_play)
 221     {
 222         return 0;
 223     }
 224     // video, ignore still res propcase
 225     if(camera_info.state.mode_video || is_video_recording()) {
 226         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) {
 227             return 40;// 4:3 video
 228         } else {
 229             return 0; // 16:9 video, no x offset
 230         }
 231     }
 232     return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 233 }
 234 
 235 int vid_get_viewport_display_yoffset() {
 236     if (camera_info.state.mode_play)
 237     {
 238         return 0;
 239     }
 240     // video, ignore still res propcase
 241     if(camera_info.state.mode_video || is_video_recording()) {
 242         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) {
 243             return 0; // 4:3 video, no Y offset
 244         } else {
 245             return 36; // 16:9 video
 246         }
 247     }
 248     if (shooting_get_prop(PROPCASE_ASPECT_RATIO) == 1)
 249     {
 250         return 36;
 251     }
 252     return 0;
 253 }
 254 
 255 extern char* bitmap_buffer[];
 256 
 257 void *vid_get_bitmap_fb() {
 258     return (void *)0x41441000; // from sub_fc0f7c21, alt 4153e200
 259 }
 260 
 261 int vid_get_viewport_byte_width() {
 262     return 736*2;     // buffer is 736 wide (720 image pixels) UYVY
 263 }
 264 
 265 // Functions for PTP Live View system
 266 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset(); }
 267 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset(); }
 268 int vid_get_viewport_fullscreen_width()         { return 720; }
 269 int vid_get_viewport_fullscreen_height()        { return 480; }
 270 int vid_get_viewport_buffer_width_proper()      { return 736; }
 271 int vid_get_viewport_type()                     { return LV_FB_YUV8B; }
 272 int vid_get_aspect_ratio()                      { return LV_ASPECT_3_2; }
 273 void *vid_get_bitmap_active_buffer() {
 274     return bitmap_buffer[active_bitmap_buffer&1];
 275 }
 276 /*
 277 note RGBA bitmap buffer, 640x480 on 960x480 buffer
 278 0x42541000
 279 0x42703000
 280 doesn't seem to be a simple double buffer, UI shows up in first focus box shows up in second
 281 */
 282 
 283 // the opacity buffer defines opacity for the bitmap overlay's pixels
 284 // found near BmpDDev.c line 215 assert fc0f7b58
 285 volatile char *opacity_buffer[2] = {(char*)0x4163b400, (void*)0x416b9d00};
 286 
 287 // 0x10108 also appears to contain the active buffer
 288 void *vid_get_opacity_active_buffer() {
 289     return (void *)opacity_buffer[active_bitmap_buffer&1];
 290 }
 291 
 292 #if 0
 293 #ifdef CAM_SUPPORT_BITMAP_RES_CHANGE
 294 /*
 295  * needed because bitmap buffer resolutions change when an external display is used
 296  * an extra screen erase doesn't seem to be needed
 297  */
 298 void update_screen_dimensions() {
 299     // see sub_fc18618a in 102b and 102c for the values
 300     extern int displaytype;
 301     static int old_displaytype = -1;
 302 
 303     if (old_displaytype == displaytype) {
 304         return;
 305     }
 306     old_displaytype = displaytype;
 307 
 308     switch(displaytype) {
 309         case 0:
 310         case 3:
 311         case 4:
 312         case 5:
 313             // lcd
 314             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 640;
 315             camera_screen.height = camera_screen.buffer_height = 480;
 316             camera_screen.size = camera_screen.buffer_size = 640*480;
 317             break;
 318         case 1:
 319         case 2:
 320         case 8:
 321         case 9:
 322             // tv-out
 323             camera_screen.width = 720;
 324             camera_screen.physical_width = camera_screen.buffer_width = 736;
 325             camera_screen.height = camera_screen.buffer_height = 480;
 326             camera_screen.size = 720*480;
 327             camera_screen.buffer_size = 736*480;
 328             break;
 329         case 6:
 330         case 7:
 331             // hdmi
 332             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 960;
 333             camera_screen.height = camera_screen.buffer_height = 540;
 334             camera_screen.size = camera_screen.buffer_size = 960*540;
 335             break;
 336     }
 337 }
 338 #endif
 339 #endif
 340 
 341 char *camera_jpeg_count_str()
 342 {
 343     extern char jpeg_count_str[];
 344         return jpeg_count_str;
 345 }

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