root/platform/g12/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_xoffset
  18. vid_get_viewport_display_xoffset
  19. vid_get_viewport_height
  20. vp_yoffset
  21. vid_get_viewport_yoffset
  22. vid_get_viewport_display_yoffset
  23. vid_get_viewport_display_xoffset_proper
  24. vid_get_viewport_display_yoffset_proper
  25. vid_get_viewport_height_proper
  26. vid_get_viewport_fullscreen_height
  27. vid_get_palette_type
  28. vid_get_palette_size
  29. vid_get_bitmap_active_buffer
  30. vid_get_bitmap_active_palette
  31. 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*3];
  12 }
  13 
  14 char *hook_alt_raw_image_addr()
  15 {
  16     return raw_buffers[(active_raw_buffer^1)*3];
  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 0xC0220138       // Lower Indicator
  56 
  57 void debug_led(int state)
  58 {
  59  *(int*)LED_PR=state ? 0x46 : 0x44;
  60 }
  61 
  62 // G12 has 7 led values
  63 // 0/0 - Upper indicator Green
  64 // 1/1 - Upper indicator Orange
  65 // 2/2 - Lower indicator Yellow
  66 // 3/3 - Power LED Green
  67 // 4/9 - AF Assist Lamp
  68 // 5/14 - ISO LED
  69 // 6/15 - EV LED
  70 void camera_set_led(int led, int state, int bright) {
  71  static char led_table[7]={0,1,2,3,9,14,15};
  72  _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  73 }
  74 
  75 int get_flash_params_count(void){
  76  return 0x9a;   // found in GetParameterData
  77 }
  78 
  79 void JogDial_CW(void){
  80  _PostLogicalEventForNotPowerType(0x86E, 1);  // RotateJogDialRight (table @ FFC0BE90)
  81 }
  82 
  83 void JogDial_CCW(void){
  84  _PostLogicalEventForNotPowerType(0x86F, 1);  // RotateJogDialLeft (table @ FFC0BE90)
  85 }
  86 
  87 // Viewport and Bitmap values that shouldn't change across firmware versions.
  88 // Values that may change are in lib.c for each firmware version.
  89 
  90 // Defined in stubs_min.S
  91 extern char active_viewport_buffer;
  92 extern void* viewport_buffers[];
  93 
  94 void *vid_get_viewport_fb()
  95 {
  96     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
  97     return viewport_buffers[0];
  98 }
  99 
 100 void *vid_get_viewport_live_fb()
 101 {
 102     if (camera_info.state.mode_video)
 103         return viewport_buffers[0];     // Video only seems to use the first viewport buffer.
 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[(active_viewport_buffer-1)&3];
 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;               // G12 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 // viewport width offset table for each image size
 141 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5
 142 static long vp_xo[5] = { 0, 0, 0, 44, 72 };                             // should all be even values for edge overlay
 143 
 144 int vid_get_viewport_xoffset()
 145 {
 146     if (camera_info.state.mode_play)
 147     {
 148         return 0;
 149     }
 150     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16908) // Stitch mode
 151     {
 152         return 0;
 153     }
 154     else
 155     {
 156             return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 157     }
 158 }
 159 
 160 int vid_get_viewport_display_xoffset()
 161 {
 162     if (camera_info.state.mode_play)
 163     {
 164         return 0;
 165     }
 166     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16908) // Stitch mode
 167     {
 168         if (shooting_get_prop(PROPCASE_STITCH_DIRECTION) == 0)      // Direction check
 169             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 170                 return 40;
 171             else
 172                 return 140;
 173         else
 174             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 175                 return 140;
 176             else
 177                 return 40;
 178     }
 179     else
 180     {
 181             return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 182     }
 183 }
 184 
 185 long vid_get_viewport_height()
 186 {
 187     if (camera_info.state.mode_play)
 188     {
 189         return 240;
 190     }
 191     extern int _GetVRAMVPixelsSize();
 192     return _GetVRAMVPixelsSize() >> 1;
 193 }
 194 
 195 static int vp_yoffset(int stitch)
 196 {
 197     // viewport height offset table for each image size
 198     // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5
 199     static long vp_yo[5] = { 0, 30, 13, 0, 0 };
 200 
 201     if (camera_info.state.mode_play)
 202     {
 203         return 0;
 204     }
 205     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16908) // Stitch mode
 206     {
 207         return stitch;
 208     }
 209     else if (camera_info.state.mode_video)
 210     {
 211         return 30;
 212     }
 213     else
 214     {
 215             return vp_yo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 216     }
 217 }
 218 
 219 int vid_get_viewport_yoffset()
 220 {
 221     return vp_yoffset(0);
 222 }
 223 
 224 int vid_get_viewport_display_yoffset()
 225 {
 226     return vp_yoffset(72);
 227 }
 228 
 229 // Functions for PTP Live View system
 230 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() * 2; }
 231 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset() * 2; }
 232 int vid_get_viewport_height_proper()            { return vid_get_viewport_height() * 2; }
 233 int vid_get_viewport_fullscreen_height()        { return 480; }
 234 int vid_get_palette_type()                      { return 3; }
 235 int vid_get_palette_size()                      { return 256 * 4; }
 236 
 237 void *vid_get_bitmap_active_buffer()
 238 {
 239     return bitmap_buffer[active_bitmap_buffer];
 240 }
 241 
 242 void *vid_get_bitmap_active_palette()
 243 {
 244     extern int active_palette_buffer;
 245     extern char* palette_buffer[];
 246     return (palette_buffer[active_palette_buffer]+8);
 247 }
 248 
 249 // Function to load CHDK custom colors into active Canon palette
 250 void load_chdk_palette()
 251 {
 252     extern int active_palette_buffer;
 253     // Only load for the standard record and playback palettes
 254     if ((active_palette_buffer == 0) || (active_palette_buffer == 4) || (active_palette_buffer == 6))
 255     {
 256         int *pal = (int*)vid_get_bitmap_active_palette();
 257         if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
 258         {
 259             pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
 260             pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
 261             pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
 262             pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
 263             pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
 264             pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
 265             pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
 266             pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
 267             pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
 268             pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
 269             pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
 270             pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
 271             pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
 272             pal[CHDK_COLOR_BASE+13] = 0x0090000;  // Transparent dark grey
 273 
 274             extern char palette_control;
 275             palette_control = 1;
 276             vid_bitmap_refresh();
 277         }
 278     }
 279 }

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