root/platform/g5x/lib.c

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

DEFINITIONS

This source file includes following definitions.
  1. vid_bitmap_refresh
  2. vid_get_bitmap_fb
  3. vid_get_bitmap_active_buffer
  4. vid_get_opacity_active_buffer
  5. camera_jpeg_count_str
  6. shutdown
  7. _Restart
  8. debug_led
  9. camera_set_led
  10. shutdown_soft
  11. get_flash_params_count
  12. JogDial_CW
  13. JogDial_CCW
  14. hook_raw_image_addr
  15. vid_get_viewport_fb_d
  16. vid_get_viewport_fb
  17. vid_get_viewport_live_fb
  18. vid_get_viewport_width
  19. vid_get_viewport_height
  20. vid_get_viewport_byte_width
  21. vid_get_viewport_display_xoffset
  22. vid_get_viewport_display_yoffset
  23. vid_get_viewport_display_xoffset_proper
  24. vid_get_viewport_display_yoffset_proper
  25. vid_get_viewport_fullscreen_width
  26. vid_get_viewport_fullscreen_height
  27. vid_get_viewport_buffer_width_proper
  28. vid_get_viewport_type
  29. vid_get_aspect_ratio
  30. update_ui

   1 
   2 #include "platform.h"
   3 #include "lolevel.h"
   4 #include "live_view.h"
   5 #include "levent.h"
   6 
   7 // Dummy variable - actual zoom_status not found
   8 int zoom_status;
   9 
  10 extern int active_bitmap_buffer;
  11 extern char* bitmap_buffer[];
  12 
  13 void vid_bitmap_refresh()
  14 {
  15     extern void _transfer_src_overlay(int);
  16     extern void _VTMLock();
  17     extern void _VTMUnlock();
  18     _VTMLock();
  19     int n = active_bitmap_buffer;
  20     _transfer_src_overlay(n^1);
  21     _transfer_src_overlay(n);
  22     _VTMUnlock();
  23 }
  24 
  25 void *vid_get_bitmap_fb()
  26 {
  27     // For live view send YUV instead of RGBA
  28     return bitmap_buffer[0];
  29 }
  30 
  31 void *vid_get_bitmap_active_buffer()
  32 {
  33     // For live view send YUV instead of RGBA
  34     return bitmap_buffer[active_bitmap_buffer];
  35 }
  36 
  37 // the opacity buffer defines opacity for the bitmap overlay's pixels
  38 extern void *opacity_buffer[];
  39 
  40 void *vid_get_opacity_active_buffer()
  41 {
  42     return opacity_buffer[active_bitmap_buffer];
  43 }
  44 
  45 char *camera_jpeg_count_str()
  46 {
  47     extern char jpeg_count_str[];
  48     return jpeg_count_str;
  49 }
  50 
  51 void shutdown()
  52 {
  53     debug_led(1);
  54     PostLogicalEventForNotPowerType(levent_id_for_name("PressPowerButton"),0);
  55     while(1) msleep(100);
  56 }
  57 
  58 void _Restart(__attribute__ ((unused))unsigned option)
  59 {
  60     // Firmware _Restart() function does not work; but forcing camera to 'boot' our PS.FI2 seems to work, although it takes around 10 seconds to restart.
  61     _reboot_fw_update("A/PS.FI2");
  62 }
  63 
  64 #define LED_PR 0xd20b0994 // green LED on the back
  65 
  66 void debug_led(int state) {
  67     volatile long *p = (void*) LED_PR;
  68     *p = ((state) ? 0x4d0002 : 0x4c0003);
  69 }
  70 
  71 // Power Led = first entry in table (led 0)
  72 // AF Assist Lamp = second entry in table (led 1)
  73 void camera_set_led(int led, int state, __attribute__ ((unused))int bright) {
  74     static char led_table[2] = { 0, 4 };
  75     _LEDDrive(led_table[led % sizeof(led_table)], state <= 1 ? !state : state);
  76 }
  77 
  78 //TODO:
  79 void shutdown_soft()
  80 {
  81     _PostLogicalEventForNotPowerType(0x1005, 0);
  82 }
  83 
  84 //TODO:
  85 int get_flash_params_count(void)
  86 {
  87     return 241;
  88 }
  89 
  90 //TODO:
  91 void JogDial_CW(void)
  92 {
  93     _PostLogicalEventToUI(0x872, 1);    //RotateJogDialRight
  94 }
  95 
  96 //TODO:
  97 void JogDial_CCW(void)
  98 {
  99     _PostLogicalEventToUI(0x873, 1);    //RotateJogDialLeft
 100 }
 101 
 102 // updated by using function in capt_seq, valid between shot start and raw hook end
 103 extern  char*   current_raw_addr;
 104 
 105 char *hook_raw_image_addr()
 106 {
 107     /*
 108      43dbfca0   - RAW & RAW + JPEG
 109      43e4a000   - JPEG only
 110      */
 111     return current_raw_addr;
 112 }
 113 
 114 // TODO:
 115 //char *hook_alt_raw_image_addr()
 116 //{
 117 //}
 118 
 119 extern void* _GetActiveViewportBuffer();
 120 
 121 void *vid_get_viewport_fb_d()
 122 {
 123     return _GetActiveViewportBuffer();
 124 }
 125 
 126 void *vid_get_viewport_fb()
 127 {
 128     return _GetActiveViewportBuffer();
 129 }
 130 
 131 void *vid_get_viewport_live_fb()
 132 {
 133     return _GetActiveViewportBuffer();
 134 }
 135 
 136 extern int displaytype;
 137 #define evf_out     (displaytype == 11)
 138 #define hdmi_out    ((displaytype == 6) || (displaytype == 7))
 139 
 140 int vid_get_viewport_width()
 141 {
 142     if (camera_info.state.mode_play)
 143     {
 144         if (hdmi_out) return 1920;
 145         if (evf_out) return 1024;
 146         return 720;
 147     }
 148     extern int _GetVRAMHPixelsSize();
 149     return _GetVRAMHPixelsSize();
 150 }
 151 
 152 long vid_get_viewport_height()
 153 {
 154     if (camera_info.state.mode_play)
 155     {
 156         if (hdmi_out) return 1080;
 157         if (evf_out) return 768;
 158         return 480;
 159     }
 160     extern int _GetVRAMVPixelsSize();
 161     return _GetVRAMVPixelsSize();
 162 }
 163 
 164 int vid_get_viewport_byte_width()
 165 {
 166     return vid_get_viewport_buffer_width_proper()*2;
 167 }
 168 
 169 int vid_get_viewport_display_xoffset()
 170 {
 171     // viewport width offset table for each image size
 172     // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 173     static long vp_xo[5] = { 40, 0, 0, 120};    // should all be even values for edge overlay
 174     static long vp_xo_hdmi[5] = { 240, 0, 150, 420};   // should all be even values for edge overlay
 175 
 176     if (camera_info.state.mode_play)
 177     {
 178         return 0;
 179     }
 180     else if (camera_info.state.mode_video)
 181     {
 182         if (shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2)  // VGA
 183             return 40;
 184         return 0;
 185     }
 186     else
 187     {
 188         if (hdmi_out)
 189             return vp_xo_hdmi[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 190         return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 191     }
 192 }
 193 
 194 int vid_get_viewport_display_yoffset()
 195 {
 196     // viewport height offset table for each image size
 197     // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 198     static long vp_yo[5] = { 0, 38, 0, 0 };
 199 
 200     if (camera_info.state.mode_play)
 201     {
 202         return 0;
 203     }
 204     else if (camera_info.state.mode_video)
 205     {
 206         if (shooting_get_prop(PROPCASE_VIDEO_RESOLUTION) == 2) // VGA
 207             return 0;
 208         return 38;
 209     }
 210     else
 211     {
 212         if (hdmi_out)
 213             return 0;
 214         return vp_yo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 215     }
 216 }
 217 
 218 // Functions for PTP Live View system
 219 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset(); }
 220 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset(); }
 221 int vid_get_viewport_fullscreen_width()
 222 {
 223     if (hdmi_out) return 1920;
 224     if (evf_out) return 1024;
 225     return 720;
 226 }
 227 int vid_get_viewport_fullscreen_height()
 228 {
 229     if (hdmi_out) return 1080;
 230     if (evf_out) return 768;
 231     return 480;
 232 }
 233 int vid_get_viewport_buffer_width_proper()
 234 {
 235     if (hdmi_out) return 1920;
 236     if (evf_out) return 1024;
 237     return 736;
 238 }
 239 int vid_get_viewport_type()                     { return LV_FB_YUV8B; }
 240 int vid_get_aspect_ratio()
 241 {
 242     if (hdmi_out) return LV_ASPECT_16_9;
 243     if (evf_out) return LV_ASPECT_4_3;
 244     return LV_ASPECT_3_2;
 245 }
 246 
 247 int display_needs_refresh = 0;
 248 
 249 // Ximr layer
 250 typedef struct {
 251     unsigned short  unk1[6];
 252     unsigned short  color_type;
 253     unsigned short  visibility;
 254     unsigned short  unk2;
 255     unsigned short  src_y;
 256     unsigned short  src_x;
 257     unsigned short  src_h;
 258     unsigned short  src_w;
 259     unsigned short  dst_y;
 260     unsigned short  dst_x;
 261     unsigned short  enabled;
 262     unsigned int    marv_sig;
 263     unsigned int    bitmap;
 264     unsigned int    opacity;
 265     unsigned int    color;
 266     unsigned int    width;
 267     unsigned int    height;
 268     unsigned int    unk3;
 269 } ximr_layer;
 270 
 271 // Ximr context
 272 typedef struct {
 273     unsigned int    unk1[14];
 274     int             buffer_width;
 275     int             buffer_height;
 276     unsigned int    unk2[2];
 277     ximr_layer      layers[8];
 278     unsigned int    unk3[26];
 279     short           width;
 280     short           height;
 281     unsigned int    unk4[27];
 282 } ximr_context;
 283 
 284 /*
 285  * Called when Canon is updating UI, via dry_memcpy patch.
 286  * Sets flag for CHDK to update it's UI.
 287  * Also needed because bitmap buffer resolution changes when using the EVF or HDMI
 288  * LCD = 720 x 480
 289  * EVF = 1024 x 768
 290  * HDMI = 960 x 540
 291  * TODO: This does not reset the OSD positions of things on screen
 292  *       If user has customised OSD layout how should this be handled?
 293  */
 294 void update_ui(ximr_context* ximr)
 295 {
 296     // Make sure we are updating the correct layer - skip redundant updates for HDMI out
 297     extern unsigned char* hdmi_buffer_check_adr;
 298     if ((ximr->layers[0].color_type == 0x0500) || (ximr->layers[0].bitmap == (unsigned int)&hdmi_buffer_check_adr))
 299     {
 300         // Update screen dimensions
 301         if (camera_screen.buffer_width != ximr->buffer_width)
 302         {
 303             camera_screen.width = ximr->width;
 304             camera_screen.height = ximr->height;
 305             camera_screen.buffer_width = ximr->buffer_width;
 306             camera_screen.buffer_height = ximr->buffer_height;
 307 
 308             // Reset OSD offset and width
 309             camera_screen.disp_right = camera_screen.width - 1;
 310             camera_screen.disp_width = camera_screen.width;
 311 
 312             // Update other values
 313             camera_screen.physical_width = camera_screen.width;
 314             camera_screen.size = camera_screen.width * camera_screen.height;
 315             camera_screen.buffer_size = camera_screen.buffer_width * camera_screen.buffer_height;
 316         }
 317 
 318         // Tell CHDK UI that display needs update
 319         display_needs_refresh = 1;
 320     }
 321 }

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