root/platform/g1x/lib.c

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

DEFINITIONS

This source file includes following definitions.
  1. hook_raw_image_addr
  2. hook_alt_raw_image_addr
  3. camera_jpeg_count_str
  4. vid_bitmap_refresh
  5. shutdown
  6. debug_led
  7. camera_set_led
  8. get_flash_params_count
  9. JogDial_CW
  10. JogDial_CCW
  11. vid_get_viewport_fb
  12. vid_get_viewport_live_fb
  13. vid_get_viewport_fb_d
  14. vid_get_bitmap_fb
  15. vid_get_viewport_yscale
  16. vid_get_viewport_width
  17. vid_get_viewport_display_xoffset
  18. vid_get_viewport_height
  19. vp_yoffset
  20. vid_get_viewport_yoffset
  21. vid_get_viewport_display_yoffset
  22. vid_get_viewport_display_xoffset_proper
  23. vid_get_viewport_display_yoffset_proper
  24. vid_get_viewport_height_proper
  25. vid_get_viewport_fullscreen_height
  26. vid_get_palette_type
  27. vid_get_palette_size
  28. vid_get_bitmap_active_buffer
  29. vid_get_bitmap_active_palette
  30. load_chdk_palette

   1 #include "platform.h"
   2 #include "platform_palette.h"
   3 #include "lolevel.h"
   4 
   5 
   6 extern  int     active_raw_buffer;
   7 extern  char*   raw_buffers[];
   8 
   9 char *hook_raw_image_addr()
  10 {
  11     return raw_buffers[active_raw_buffer];
  12 }
  13 
  14 char *hook_alt_raw_image_addr()
  15 {
  16     return raw_buffers[active_raw_buffer^1];
  17 }
  18 
  19 
  20 char *camera_jpeg_count_str()
  21 {
  22     extern char jpeg_count_str[];
  23         return jpeg_count_str;
  24 }
  25 
  26 
  27 void vid_bitmap_refresh()
  28 {
  29         extern int full_screen_refresh;
  30         extern void _ScreenUnlock();
  31         extern void _ScreenLock();
  32 
  33         full_screen_refresh |= 3;
  34         _ScreenLock();
  35         _ScreenUnlock();
  36 }
  37 
  38 
  39 void shutdown()
  40 {
  41         volatile long *p = (void*)0xC022001C;
  42 
  43         asm(
  44                 "MRS     R1, CPSR\n"
  45                 "AND     R0, R1, #0x80\n"
  46                 "ORR     R1, R1, #0x80\n"
  47                 "MSR     CPSR_cf, R1\n"
  48                 :::"r1","r0");
  49 
  50         *p = 0x44;  // power off.
  51 
  52         while(1);
  53 }
  54 
  55 #define LED_PR 0xC022C30C       // Power LED (@FF15D0D0 & @FF15D124 G1X 1.00f)
  56 
  57 void debug_led(int state)
  58 {
  59         // using power LED, which defaults to on
  60         // for debugging turn LED off if state is 1 and on for state = 0
  61         // leaves LED on at end of debugging
  62     volatile long *p = (void*)LED_PR;
  63     *p = (*p & 0xFFFFFFCF) | ((state) ? 0x00 : 0x20);
  64 }
  65 
  66 // G1X has 4 led values
  67 // 0/0 - Upper indicator Green
  68 // 1/1 - Lower indicator Orange
  69 // 2/3 - Power LED Green
  70 // 3/9 - AF Assist Lamp
  71 void camera_set_led(int led, int state, int bright) {
  72  static char led_table[5]={0,1,3,9};
  73  _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  74 }
  75 
  76 int get_flash_params_count(void) { return 0x9f; }              // Found @0xff206724
  77 
  78 void JogDial_CW(void){
  79  _PostLogicalEventToUI(0x872, 1);  // RotateJogDialRight (in levent_table)
  80 }
  81 
  82 void JogDial_CCW(void){
  83  _PostLogicalEventToUI(0x873, 1);  // RotateJogDialLeft (in levent_table)
  84 }
  85 
  86 // Viewport and Bitmap values that shouldn't change across firmware versions.
  87 // Values that may change are in lib.c for each firmware version.
  88 
  89 // Defined in stubs_min.S
  90 extern char active_viewport_buffer;
  91 extern void* viewport_buffers[];
  92 
  93 void *vid_get_viewport_fb()
  94 {
  95     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
  96     return viewport_buffers[0];
  97 }
  98 
  99 void *vid_get_viewport_live_fb()
 100 {
 101     int b = (active_viewport_buffer-1)&3;
 102     if ((b == 3) && (camera_info.state.mode_video || ((camera_info.state.mode & MODE_SHOOTING_MASK) == MODE_VIDEO_MOVIE_DIGEST) || is_video_recording()))
 103         b = 2;  // Video only seems to use the first 3 viewport buffers.
 104 
 105     // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
 106     return viewport_buffers[b];
 107 }
 108 
 109 void *vid_get_viewport_fb_d()
 110 {
 111     extern char *viewport_fb_d;
 112         return viewport_fb_d;
 113 }
 114 
 115 // Defined in stubs_min.S
 116 extern int active_bitmap_buffer;
 117 extern char* bitmap_buffer[];
 118 
 119 void *vid_get_bitmap_fb()
 120 {
 121     // Return first bitmap buffer address
 122     return bitmap_buffer[0];
 123 }
 124 
 125 // Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240)
 126 int vid_get_viewport_yscale() {
 127         return 2;               // G1X viewport is 480 pixels high
 128 }
 129 
 130 int vid_get_viewport_width()
 131 {
 132     if (camera_info.state.mode_play)
 133     {
 134         return 360;
 135     }
 136     extern int _GetVRAMHPixelsSize();
 137     return _GetVRAMHPixelsSize() >> 1;
 138 }
 139 
 140 int vid_get_viewport_display_xoffset()
 141 {
 142     if (camera_info.state.mode_play)
 143     {
 144         return 0;
 145     }
 146     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode
 147     {
 148         if (shooting_get_prop(PROPCASE_STITCH_DIRECTION) == 0)      // Direction check
 149             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 150                 return 40;
 151             else
 152                 return 140;
 153         else
 154             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 155                 return 140;
 156             else
 157                 return 40;
 158     }
 159     else
 160     {
 161             // viewport width offset table for each image size
 162             // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5
 163             static long vp_w[5] = { 0, 0, 0, 44, 72 };                          // should all be even values for edge overlay
 164             return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 165     }
 166 }
 167 
 168 long vid_get_viewport_height()
 169 {
 170     if (camera_info.state.mode_play)
 171     {
 172         return 240;
 173     }
 174     extern int _GetVRAMVPixelsSize();
 175     return _GetVRAMVPixelsSize() >> 1;
 176 }
 177 
 178 static int vp_yoffset(int stitch)
 179 {
 180     // viewport height offset table for each image size
 181     // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5
 182     static long vp_yo[5] = { 0, 30, 13, 0, 0 };
 183 
 184     if (camera_info.state.mode_play)
 185     {
 186         return 0;
 187     }
 188     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode
 189     {
 190         return stitch;
 191     }
 192     else if (camera_info.state.mode_video)
 193     {
 194         return 30;
 195     }
 196     else
 197     {
 198             return vp_yo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 199     }
 200 }
 201 
 202 int vid_get_viewport_yoffset()
 203 {
 204     return vp_yoffset(0);
 205 }
 206 
 207 int vid_get_viewport_display_yoffset()
 208 {
 209     return vp_yoffset(72);
 210 }
 211 
 212 // Functions for PTP Live View system
 213 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() * 2; }
 214 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset() * 2; }
 215 int vid_get_viewport_height_proper()            { return vid_get_viewport_height() * 2; }
 216 int vid_get_viewport_fullscreen_height()        { return 480; }
 217 int vid_get_palette_type()                      { return 3; }
 218 int vid_get_palette_size()                      { return 256 * 4; }
 219 
 220 void *vid_get_bitmap_active_buffer()
 221 {
 222     return bitmap_buffer[active_bitmap_buffer];
 223 }
 224 
 225 void *vid_get_bitmap_active_palette()
 226 {
 227     extern int active_palette_buffer;
 228     extern char* palette_buffer[];
 229     return (palette_buffer[active_palette_buffer]+4);
 230 }
 231 
 232 // Function to load CHDK custom colors into active Canon palette
 233 void load_chdk_palette()
 234 {
 235     extern int active_palette_buffer;
 236     // Only load for the standard record and playback palettes
 237     if ((active_palette_buffer == 0) || (active_palette_buffer == 3) || (active_palette_buffer == 6))
 238     {
 239         int *pal = (int*)vid_get_bitmap_active_palette();
 240         if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
 241         {
 242             pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
 243             pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
 244             pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
 245             pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
 246             pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
 247             pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
 248             pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
 249             pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
 250             pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
 251             pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
 252             pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
 253             pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
 254             pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
 255             pal[CHDK_COLOR_BASE+13] = 0x0090000;  // Transparent dark grey
 256 
 257             extern char palette_control;
 258             palette_control = 1;
 259             vid_bitmap_refresh();
 260         }
 261     }
 262 }

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