root/platform/m3/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_viewport_type
  19. vid_get_bitmap_fb
  20. vid_get_viewport_display_xoffset_proper
  21. vid_get_viewport_display_yoffset_proper
  22. vid_get_viewport_buffer_width_proper
  23. vid_get_viewport_fullscreen_width
  24. vid_get_viewport_byte_width
  25. vid_get_viewport_fullscreen_height
  26. vid_get_aspect_ratio
  27. vid_get_bitmap_active_buffer
  28. vid_get_opacity_active_buffer
  29. vid_get_bitmap_active_palette
  30. 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 void vid_bitmap_refresh() {
   8     // extern int full_screen_refresh;
   9     // extern void _ScreenUnlock();
  10     // extern void _ScreenLock();
  11     // extern void _displaybusyonscreen();
  12     // extern void _undisplaybusyonscreen();
  13 
  14     
  15     // clears perfectly but blinks and is asynchronous
  16     // _displaybusyonscreen();
  17     // _undisplaybusyonscreen();
  18     
  19     // https://chdk.setepontos.com/index.php?topic=12788.msg133958#msg133958
  20     extern void _transfer_src_overlay(int);
  21 // works in most cases but can cause "ghosting" in auto mode when canon UI constantly updates
  22 //  _transfer_src_overlay(active_bitmap_buffer);
  23     _transfer_src_overlay(0);
  24     _transfer_src_overlay(1);
  25 }
  26 
  27 void shutdown() {
  28 //***TODO***
  29 /*
  30     volatile long *p = (void*)0xC022001C;
  31 
  32     asm(
  33         "MRS     R1, CPSR\n"
  34         "AND     R0, R1, #0x80\n"
  35         "ORR     R1, R1, #0x80\n"
  36         "MSR     CPSR_cf, R1\n"
  37         :::"r1","r0"
  38     );
  39 
  40     *p = 0x44;  // power off.
  41 */
  42     while(1)   _SleepTask(500);
  43 }
  44 
  45 #define LED_PR 0xd20b0994 // green LED on the back
  46 
  47 void debug_led(int state) {
  48     volatile long *p = (void*)LED_PR;
  49     *p = ((state) ? 0x4d0002 : 0x4c0003);
  50 }
  51 
  52 // Power Led = first entry in table (led 0)
  53 // AF Assist Lamp = second entry in table (led 1)
  54 void camera_set_led(int led, int state, int bright) {
  55     static char led_table[2]={0,4};
  56     _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  57 }
  58 
  59 void shutdown_soft() {
  60 //      *(int*)0xd20b0810  = 0x4d0002;   // Orange Led = on
  61 
  62         _PostLogicalEventForNotPowerType(0x1005,0);
  63 }
  64 
  65 int get_flash_params_count(void) {
  66     return 0x91;
  67 }
  68 
  69 void JogDial_CW(void) {
  70     _PostLogicalEventToUI(0x872, 1);    //RotateJogDialRight
  71 }
  72 
  73 void JogDial_CCW(void) {
  74     _PostLogicalEventToUI(0x873, 1);    //RotateJogDialLeft
  75 }
  76 
  77 extern  int     active_raw_buffer;
  78 extern  char*   raw_buffers[];
  79 extern char* raw_buffers_canon_raw[];
  80 extern char* raw_buffers_jpeg[];
  81 
  82 char *hook_raw_image_addr()
  83 {
  84 //    return raw_buffers[(active_raw_buffer&3)];
  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) i=0;
  88     return raw_buffers[i];
  89         // TODO most scene modes seem to use different addresse(s)
  90 }
  91 
  92 /* char *hook_alt_raw_image_addr()
  93 {
  94     return raw_buffers[((active_raw_buffer&1)^1)];
  95 } */
  96 
  97 extern char active_viewport_buffer;
  98 extern void* viewport_buffers[];
  99 
 100 void *vid_get_viewport_fb() {
 101     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
 102     //return (void*)0x43115100; // uyvy buffers with signed(?) chroma components
 103     return (void*)0x4367AF00; // 0x43A6F700 0x4b25fc00; uyvy buffers (more than 4), pixel format compatible with earlier DIGIC uyvy
 104 }
 105 
 106 void *vid_get_viewport_fb_d()    {
 107     // based on suggestion from 62ndidiot in https://chdk.setepontos.com/index.php?topic=12532.msg129914#msg129914
 108     extern void *current_fb_d;
 109     return current_fb_d;
 110 } 
 111 
 112 extern void* viewport_buffers[];
 113 extern void *current_viewport_buffer;
 114 
 115 void *vid_get_viewport_live_fb()
 116 {
 117 // current_viewport_buffer doesn't seem to be most recent
 118     int i;
 119     for(i=0;i<4;i++) {
 120         if(current_viewport_buffer == viewport_buffers[i]) {
 121             return viewport_buffers[(i+1)&3];
 122         }
 123     }
 124     return 0;
 125 //      return (void*)0x4367AF00;       
 126 }
 127 
 128 int vid_get_viewport_width() {
 129     extern int _GetVRAMHPixelsSize();
 130     if (camera_info.state.mode_play)
 131     {
 132         return 720;
 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 480;
 144     }
 145         return _GetVRAMVPixelsSize();
 146 }
 147 
 148 int vid_get_viewport_yoffset() {
 149     // this seems to be always 0, buffer always begins with actual display data (widescreen or not)
 150     return 0;
 151 }
 152 
 153 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5
 154 static long vp_xo[5] = { 40, 0, 0, 120, 168 };                          // should all be even values for edge overlay
 155 
 156 int vid_get_viewport_display_xoffset() {
 157     if (camera_info.state.mode_play)
 158     {
 159         return 0;
 160     }
 161     // video, ignore still res propcase
 162     if(camera_info.state.mode_video || is_video_recording()) {
 163         if(shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) {
 164             return 40;// 4:3 video
 165         } else {
 166             return 0; // 16:9 video, no x offset
 167         }
 168     }
 169     return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 170 }
 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 36; // 16:9 video
 183         }
 184     }
 185     if (shooting_get_prop(PROPCASE_ASPECT_RATIO) == 1)
 186     {
 187         return 36;
 188     }
 189     return 0;
 190 }
 191 
 192 extern int active_bitmap_buffer;
 193 extern char* bitmap_buffer[];
 194 
 195 int vid_get_viewport_type() {
 196 //    if (camera_info.state.mode_play)
 197         return LV_FB_YUV8B;
 198 //    return LV_FB_YUV8C;
 199 }
 200 
 201 
 202 void *vid_get_bitmap_fb() {
 203     // Return first bitmap buffer address
 204     return bitmap_buffer[0];
 205 }
 206 
 207 // Functions for PTP Live View system
 208 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() ; }
 209 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset() ; }
 210 int vid_get_viewport_buffer_width_proper()              { return camera_screen.buffer_width ; } //(*(int*)(0x00053CBC) );
 211 int vid_get_viewport_fullscreen_width()                 { return camera_screen.width; }
 212 int vid_get_viewport_byte_width()                               { return (camera_screen.buffer_width * 2); }
 213 
 214 int vid_get_viewport_fullscreen_height()        { return 480; }
 215 int vid_get_aspect_ratio()                      { return LV_ASPECT_3_2; }
 216 
 217 
 218 
 219 // the opacity buffer defines opacity for the bitmap overlay's pixels
 220 //volatile char *opacity_buffer[2] = {(char*)0x41718600, (void*)0x41796f00};
 221 volatile char *opacity_buffer[2] = {(char*)0x41741000, (void*)0x41801000};
 222 
 223 void *vid_get_bitmap_active_buffer() {
 224     return bitmap_buffer[active_bitmap_buffer&1];
 225 }
 226 
 227 void *vid_get_opacity_active_buffer() {
 228     return (void *)opacity_buffer[active_bitmap_buffer&1];
 229 }
 230 
 231 
 232 void *vid_get_bitmap_active_palette() {
 233     return (void*)0x8000; // just to return something valid, no palette needed on this cam
 234 }
 235 
 236 #ifdef CAM_SUPPORT_BITMAP_RES_CHANGE
 237 /*
 238  * needed because bitmap buffer resolutions change when an external display is used
 239  * an extra screen erase doesn't seem to be needed
 240  */
 241 void update_screen_dimensions() {
 242     // see sub_FC177FCA in 101a, sub_FC1780F2 in 120f for the values
 243     extern int displaytype;
 244     static int old_displaytype = -1;
 245 
 246     if (old_displaytype == displaytype) {
 247         return;
 248     }
 249     old_displaytype = displaytype;
 250     
 251     switch(displaytype) {
 252         case 0:
 253         case 3:
 254         case 4:
 255         case 5:
 256             // ?
 257             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 640;
 258             camera_screen.height = camera_screen.buffer_height = 480;
 259             camera_screen.size = camera_screen.buffer_size = 640*480;
 260             break;
 261         case 1:
 262         case 2:
 263         case 8:
 264         case 9:
 265             // tv-out (not implemented in hw)
 266             camera_screen.physical_width = camera_screen.width = 720;
 267             camera_screen.buffer_width = 736;
 268             camera_screen.height = camera_screen.buffer_height = 480;
 269             camera_screen.size = 720*480;
 270             camera_screen.buffer_size = 736*480;
 271             break;
 272         case 6:
 273         case 7:
 274             // hdmi
 275             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 960;
 276             camera_screen.height = camera_screen.buffer_height = 540;
 277             camera_screen.size = camera_screen.buffer_size = 960*540;
 278             break;
 279         case 10:
 280             // lcd
 281             camera_screen.physical_width = camera_screen.width = 720;
 282             camera_screen.buffer_width = 736;
 283             camera_screen.height = camera_screen.buffer_height = 480;
 284             camera_screen.size = 720*480;
 285             camera_screen.buffer_size = 736*480;
 286             break;
 287         case 11:
 288             // evf
 289             camera_screen.width = camera_screen.physical_width = camera_screen.buffer_width = 1024;
 290             camera_screen.height = camera_screen.buffer_height = 768;
 291             camera_screen.size = camera_screen.buffer_size = 1024*768;
 292             break;
 293     }
 294 }
 295 #endif
 296 

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