root/platform/sx710hs/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_bitmap_active_buffer
  27. vid_get_opacity_active_buffer
  28. update_screen_dimensions
  29. 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     // https://chdk.setepontos.com/index.php?topic=12788.msg133958#msg133958
   9     extern void _transfer_src_overlay(int);
  10 // works in most cases but can cause "ghosting" in auto mode when canon UI constantly updates
  11 //  _transfer_src_overlay(active_bitmap_buffer);
  12     _transfer_src_overlay(0);
  13     _transfer_src_overlay(1);
  14 }
  15 
  16 void shutdown() {
  17 //***TODO***
  18 /*
  19     volatile long *p = (void*)0xC022001C;
  20 
  21     asm(
  22         "MRS     R1, CPSR\n"
  23         "AND     R0, R1, #0x80\n"
  24         "ORR     R1, R1, #0x80\n"
  25         "MSR     CPSR_cf, R1\n"
  26         :::"r1","r0"
  27     );
  28 
  29     *p = 0x44;  // power off.
  30 */
  31     while(1);
  32 }
  33 
  34 #define LED_PR 0xd20b0994 // green LED on the back
  35 
  36 void debug_led(int state) {
  37     volatile long *p = (void*)LED_PR;
  38     *p = ((state) ? 0x4d0002 : 0x4c0003);
  39 }
  40 
  41 // Power Led = first entry in table (led 0)
  42 // AF Assist Lamp = second entry in table (led 1)
  43 void camera_set_led(int led, int state, __attribute__ ((unused))int bright) {
  44     static char led_table[2]={0,4};
  45     _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  46 }
  47 
  48 void shutdown_soft() {
  49     _PostLogicalEventForNotPowerType(0x1005,0); // PressOffButton
  50 }
  51 
  52 int get_flash_params_count(void) {
  53     return 0xe5; // @fc066f98 GetParameterData
  54 }
  55 
  56 void JogDial_CW(void) {
  57     _PostLogicalEventToUI(0x872, 1);    //RotateJogDialRight
  58 }
  59 
  60 void JogDial_CCW(void) {
  61     _PostLogicalEventToUI(0x873, 1);    //RotateJogDialLeft
  62 }
  63 
  64 // updated by using function in capt_seq, valid between shot start and raw hook end
  65 extern  char*   current_raw_addr;
  66 char *hook_raw_image_addr()
  67 {
  68     if(current_raw_addr) {
  69         return current_raw_addr;
  70     }
  71     // TODO fallback if current_raw_addr not set. Would be better to fail, but calling code doesn't check
  72     return  (char *)0x41574352; // CRAW BUF = *fc56898c
  73 }
  74 
  75 // TODO - camera has at least 3 raw buffers
  76 /*
  77 0x42f69e00
  78 0x44da0100
  79 0x46bd6400
  80 */
  81 /*
  82 char *hook_alt_raw_image_addr()
  83 {
  84     return raw_buffers[((active_raw_buffer&1)^1)];
  85 }
  86 */
  87 
  88 void *vid_get_viewport_fb() {
  89     return (void*)0x42cafe00; // "first" viewport adr, "VRAM Address  : %p", contains d6 uyvy
  90 }
  91 /*
  92 playback viewport
  93 */
  94 void *vid_get_viewport_fb_d()    {
  95     // based on suggestion from 62ndidiot in https://chdk.setepontos.com/index.php?topic=12532.msg129914#msg129914
  96     extern void *current_fb_d;
  97     return current_fb_d;
  98 }
  99 
 100 extern void* viewport_buffers[];
 101 /*
 102 four viewport buffers @0xfc5befd8
 103 0x42cafe00
 104 0x42d5e600
 105 0x42e0ce00
 106 0x42ebb600
 107 */
 108 
 109 extern void *current_viewport_buffer;
 110 void *vid_get_viewport_live_fb()
 111 {
 112 // current_viewport_buffer assummed not most recent, like g7x
 113     int i;
 114     for(i=0;i<4;i++) {
 115         if(current_viewport_buffer == viewport_buffers[i]) {
 116             return viewport_buffers[(i+1)&3];
 117         }
 118     }
 119     return 0;
 120 }
 121 
 122 // track viewport size changes with display type
 123 // only different from bitmap for HDMI out, playback only, probably pointless
 124 static int vp_full_width = 640;
 125 static int vp_full_buf_width = 640;
 126 static int vp_full_height = 480;
 127 
 128 int vid_get_viewport_width() {
 129     extern int _GetVRAMHPixelsSize();
 130     if (camera_info.state.mode_play)
 131     {
 132         return vp_full_width;
 133     }
 134 // TODO: currently using actual width rather than half width used on pre d6
 135 // pixel format is uyvy (16bpp)
 136     return _GetVRAMHPixelsSize();
 137 }
 138 
 139 long vid_get_viewport_height() {
 140     extern int _GetVRAMVPixelsSize();
 141     if (camera_info.state.mode_play)
 142     {
 143         return vp_full_height;
 144     }
 145 // TODO: currently using actual height rather than 240 used on pre d6
 146     return _GetVRAMVPixelsSize();
 147 }
 148 
 149 int vid_get_viewport_yoffset() {
 150     // this seems to be always 0, buffer always begins with actual display data (widescreen or not)
 151     return 0;
 152 }
 153 // TODO
 154 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 155 static long vp_xo[4] = { 0, 0, 0, 80 };                         // should all be even values for edge overlay
 156 
 157 int vid_get_viewport_display_xoffset() {
 158     if (camera_info.state.mode_play)
 159     {
 160         return 0;
 161     }
 162     // video, ignore still res propcase
 163     if(camera_info.state.mode_video || is_video_recording()) {
 164         return 0; //neither 4:3 nor 16:9 video have x offset
 165     }
 166     return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 167 }
 168 
 169 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 170 static long vp_yo[4] = { 0, 60, 28, 0 };
 171 
 172 int vid_get_viewport_display_yoffset() {
 173     if (camera_info.state.mode_play)
 174     {
 175         return 0;
 176     }
 177     // video, ignore still res propcase
 178     if(camera_info.state.mode_video || is_video_recording()) {
 179         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) {
 180             return 0; // 4:3 video, no Y offset
 181         } else {
 182             return 60; // 16:9 video
 183         }
 184     }
 185     return vp_yo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 186 }
 187 
 188 extern char* bitmap_buffer[];
 189 
 190 void *vid_get_bitmap_fb() {
 191     return (void *)0x5ff02e00; // from sub_fc1632ba, alt 5fe05c00, based on searching for "BmpDDev.c" similar to g7x
 192 }
 193 
 194 int vid_get_viewport_byte_width() {
 195     return vp_full_buf_width*2;
 196 }
 197 
 198 // Functions for PTP Live View system
 199 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset(); }
 200 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset(); }
 201 int vid_get_viewport_fullscreen_width()         { return vp_full_width; }
 202 int vid_get_viewport_fullscreen_height()        { return vp_full_height; }
 203 int vid_get_viewport_buffer_width_proper()      { return vp_full_buf_width; }
 204 int vid_get_viewport_type()                     { return LV_FB_YUV8B; }
 205 
 206 void *vid_get_bitmap_active_buffer() {
 207     return bitmap_buffer[active_bitmap_buffer&1];
 208 }
 209 
 210 // the opacity buffer defines opacity for the bitmap overlay's pixels
 211 // fc1631ee, similar to g7x fc0f7b52, BmpDDev.c assert + switch
 212 volatile char *opacity_buffer[2] = {(char*)0x5fd87300, (void*)0x5fd08a00};
 213 
 214 // 0x10108 also appears to contain the active buffer
 215 void *vid_get_opacity_active_buffer() {
 216     return (void *)opacity_buffer[active_bitmap_buffer&1];
 217 }
 218 
 219 #ifdef CAM_SUPPORT_BITMAP_RES_CHANGE
 220 /*
 221  * needed because bitmap buffer resolutions change when an external display is used
 222  * an extra screen erase doesn't seem to be needed
 223  */
 224 void update_screen_dimensions() {
 225     // see sub_fc163142 in 101a for values
 226     extern int displaytype;
 227     static int old_displaytype = -1;
 228 
 229     if (old_displaytype == displaytype) {
 230         return;
 231     }
 232     old_displaytype = displaytype;
 233 
 234     switch(displaytype) {
 235         case 0:
 236         case 3:
 237         case 4: // normal screen
 238         case 5:
 239             // lcd
 240             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 640;
 241             camera_screen.height = camera_screen.buffer_height = 480;
 242             camera_screen.size = camera_screen.buffer_size = 640*480;
 243             break;
 244             // tv-out
 245         case 1: // NTSC
 246         case 2: // PAL
 247         case 8: // HDMI to non-HD display, (both NTSC and PAL)
 248         case 9:
 249         case 10:
 250             camera_screen.physical_width = camera_screen.width = 720;
 251             camera_screen.buffer_width = 736;
 252             camera_screen.height = camera_screen.buffer_height = 480;
 253             camera_screen.size = 720*480;
 254             camera_screen.buffer_size = 736*480;
 255             break;
 256             // hdmi, playback only
 257         case 6: // NTSC
 258         case 7: // PAL
 259             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 960;
 260             camera_screen.height = camera_screen.buffer_height = 540;
 261             camera_screen.size = camera_screen.buffer_size = 960*540;
 262             break;
 263 // unknown / invalid, but in canon code. Can be set with sub_fc0f0dfa but display is garbled, unstable
 264         case 11:// O_o
 265             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 1024;
 266             camera_screen.height = camera_screen.buffer_height = 768;
 267             camera_screen.size = 1024*768;
 268             camera_screen.buffer_size = 1024*768;
 269             break;
 270         case 12:// O_o
 271             camera_screen.width = 900;
 272             camera_screen.physical_width = camera_screen.buffer_width = 928;
 273             camera_screen.height = camera_screen.buffer_height = 600;
 274             camera_screen.size = 900*600;
 275             camera_screen.buffer_size = 928*600;
 276             break;
 277 
 278     }
 279     if(displaytype == 6 || displaytype == 7) {
 280         vp_full_width = 1920;
 281         vp_full_buf_width = 1920;
 282         vp_full_height = 1080;
 283     } else {
 284         // others are unclear, but unlikely to come up in practice
 285         vp_full_width = camera_screen.width;
 286         vp_full_buf_width = camera_screen.buffer_width;
 287         vp_full_height = camera_screen.height;
 288     }
 289 }
 290 #endif
 291 
 292 char *camera_jpeg_count_str()
 293 {
 294     extern char jpeg_count_str[];
 295         return jpeg_count_str;
 296 }

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