root/platform/sx50hs/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. get_flash_params_count
  6. JogDial_CW
  7. JogDial_CCW
  8. vid_get_viewport_fb
  9. vid_get_viewport_live_fb
  10. vid_get_bitmap_fb
  11. vid_get_viewport_yscale
  12. vid_get_viewport_width
  13. vid_get_viewport_xoffset
  14. vid_get_viewport_display_xoffset
  15. vid_get_viewport_height
  16. vp_yoffset
  17. vid_get_viewport_yoffset
  18. vid_get_viewport_display_yoffset
  19. vid_get_viewport_display_xoffset_proper
  20. vid_get_viewport_display_yoffset_proper
  21. vid_get_viewport_height_proper
  22. vid_get_viewport_fullscreen_height
  23. vid_get_palette_type
  24. vid_get_palette_size
  25. vid_get_bitmap_active_buffer
  26. vid_get_bitmap_active_palette
  27. load_chdk_palette

   1 #include "platform.h"
   2 #include "platform_palette.h"
   3 #include "lolevel.h"
   4 
   5 void vid_bitmap_refresh()
   6 {
   7         extern int full_screen_refresh;
   8         extern void _ScreenUnlock();
   9         extern void _ScreenLock();
  10 
  11         full_screen_refresh |= 3;
  12         _ScreenLock();
  13         _ScreenUnlock();
  14 }
  15 
  16 
  17 void shutdown()
  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         *p = 0x44;  // power off.
  29 
  30         while(1);
  31 }
  32 
  33 #define LED_PR 0xC022C200   
  34 
  35 void debug_led(int state)
  36 {
  37         // using power LED, which defaults to on
  38         // for debugging turn LED off if state is 1 and on for state = 0
  39         // leaves LED on at end of debugging
  40     volatile long *p = (void*)LED_PR;
  41     *p = (*p & 0xFFFFFFCF) | ((state) ? 0x00 : 0x20);
  42 }
  43 
  44 
  45 
  46 
  47 // Power Led = first entry in table (led 0)
  48 // AF Assist Lamp = second entry in table (led 1)
  49 void camera_set_led(int led, int state, __attribute__ ((unused))int bright) {
  50  static char led_table[2]={0,5};
  51  _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  52 }
  53 
  54 int get_flash_params_count(void) { return 0xa6; }                          // Found @0xff205ce4
  55 
  56 void JogDial_CW(void){
  57  _PostLogicalEventForNotPowerType(0x872, 1);  // RotateJogDialRight (in table @ ff62f34c, fw 1.00b)
  58 }
  59 
  60 void JogDial_CCW(void){
  61  _PostLogicalEventForNotPowerType(0x873, 1);  // RotateJogDialLeft (in table @ ff62f358, fw 1.00b)
  62 }
  63 
  64 // Viewport and Bitmap values that shouldn't change across firmware versions.
  65 // Values that may change are in lib.c for each firmware version.
  66 
  67 // Defined in stubs_min.S
  68 extern char active_viewport_buffer;
  69 extern void* viewport_buffers[];
  70 
  71 void *vid_get_viewport_fb()
  72 {
  73     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
  74     return viewport_buffers[0];
  75 }
  76 
  77 void *vid_get_viewport_live_fb()
  78 {
  79     if (MODE_IS_VIDEO(mode_get()) || is_video_recording())
  80         return viewport_buffers[0];     // Video only seems to use the first viewport buffer.
  81 
  82     // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
  83     return viewport_buffers[(active_viewport_buffer-1)&7];
  84 }
  85 
  86 // Defined in stubs_min.S
  87 extern int active_bitmap_buffer;
  88 extern char* bitmap_buffer[];
  89 
  90 // SX50 Values below go in 'lib.c':
  91 void *vid_get_bitmap_fb()        { return (void*)0x406c5000; }             // Found @0xff056b6c
  92 
  93 
  94 // Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240)
  95 int vid_get_viewport_yscale() {
  96         return 2;
  97 }
  98 
  99 int vid_get_viewport_width()
 100 {
 101     if ((mode_get() & MODE_MASK) == MODE_PLAY)
 102     {
 103         return 360;
 104     }
 105     extern int _GetVRAMHPixelsSize();
 106     return _GetVRAMHPixelsSize() >> 1;
 107 }
 108 
 109 // viewport width offset table for each image size
 110 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5
 111 static long vp_xo[5] = { 0, 0, 0, 44, 72 };                             // should all be even values for edge overlay
 112 
 113 int vid_get_viewport_xoffset()
 114 {
 115     if ((mode_get() & MODE_MASK) == MODE_PLAY)
 116     {
 117         return 0;
 118     }
 119     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode
 120     {
 121         return 0;
 122     }
 123     else
 124     {
 125         return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 126     }
 127 }
 128 
 129 int vid_get_viewport_display_xoffset()
 130 {
 131     if ((mode_get() & MODE_MASK) == MODE_PLAY)
 132     {
 133         return 0;
 134     }
 135     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode
 136     {
 137         if (shooting_get_prop(PROPCASE_STITCH_DIRECTION) == 0)      // Direction check
 138             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 139                 return 40;
 140             else
 141                 return 140;
 142         else
 143             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 144                 return 140;
 145             else
 146                 return 40;
 147     }
 148     else
 149     {
 150         return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 151     }
 152 }
 153 
 154 long vid_get_viewport_height()
 155 {
 156     if ((mode_get() & MODE_MASK) == MODE_PLAY)
 157     {
 158         return 240;
 159     }
 160     extern int _GetVRAMVPixelsSize();
 161     return _GetVRAMVPixelsSize() >> 1;
 162 }
 163 
 164 static int vp_yoffset(int stitch)
 165 {
 166     // viewport height offset table for each image size
 167     // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5
 168     static long vp_yo[5] = { 0, 30, 13, 0, 0 };
 169 
 170     int m = mode_get();
 171     if ((m & MODE_MASK) == MODE_PLAY)
 172     {
 173         return 0;
 174     }
 175     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16908) // Stitch mode
 176     {
 177         return stitch;
 178     }
 179     else if (mode_is_video(m))
 180     {
 181         return 30;
 182     }
 183     else
 184     {
 185             return vp_yo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 186     }
 187 }
 188 
 189 int vid_get_viewport_yoffset()
 190 {
 191     return vp_yoffset(0);
 192 }
 193 
 194 int vid_get_viewport_display_yoffset()
 195 {
 196     return vp_yoffset(72);
 197 }
 198 
 199 // Functions for PTP Live View system
 200 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() * 2; }
 201 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset() * 2; }
 202 int vid_get_viewport_height_proper()            { return vid_get_viewport_height() * 2; }
 203 int vid_get_viewport_fullscreen_height()        { return 480; }
 204 int vid_get_palette_type()                      { return 5; }
 205 int vid_get_palette_size()                      { return 256 * 4; }
 206 
 207 void *vid_get_bitmap_active_buffer()
 208 {
 209     return bitmap_buffer[active_bitmap_buffer];
 210 }
 211 
 212 void *vid_get_bitmap_active_palette()
 213 {
 214     extern int active_palette_buffer;
 215     extern char* palette_buffer[];
 216     void* p = palette_buffer[active_palette_buffer];
 217     // Don't add offset if value is 0
 218     if (p) p += 4;
 219     return p;
 220 }
 221 
 222 // Function to load CHDK custom colors into active Canon palette
 223 void load_chdk_palette()
 224 {
 225     extern int active_palette_buffer;
 226     // Only load for the standard record and playback palettes
 227     if ((active_palette_buffer == 0) || (active_palette_buffer == 5) || (active_palette_buffer == 6))
 228     {
 229         int *pal = (int*)vid_get_bitmap_active_palette();
 230         if (pal && pal[CHDK_COLOR_BASE+0] != 0x3F3ADF62)
 231         {
 232             pal[CHDK_COLOR_BASE+0]  = 0x3F3ADF62;  // Red
 233             pal[CHDK_COLOR_BASE+1]  = 0x3F26EA40;  // Dark Red
 234             pal[CHDK_COLOR_BASE+2]  = 0x3F4CD57F;  // Light Red
 235             pal[CHDK_COLOR_BASE+3]  = 0x3F73BFAE;  // Green
 236             pal[CHDK_COLOR_BASE+4]  = 0x3F4BD6CA;  // Dark Green
 237             pal[CHDK_COLOR_BASE+5]  = 0x3F95AB95;  // Light Green
 238             pal[CHDK_COLOR_BASE+6]  = 0x3F4766F0;  // Blue
 239             pal[CHDK_COLOR_BASE+7]  = 0x3F1250F3;  // Dark Blue
 240             pal[CHDK_COLOR_BASE+8]  = 0x3F7F408F;  // Cyan
 241             pal[CHDK_COLOR_BASE+9]  = 0x3F512D5B;  // Magenta
 242             pal[CHDK_COLOR_BASE+10] = 0x3FA9A917;  // Yellow
 243             pal[CHDK_COLOR_BASE+11] = 0x3F819137;  // Dark Yellow
 244             pal[CHDK_COLOR_BASE+12] = 0x3FDED115;  // Light Yellow
 245             pal[CHDK_COLOR_BASE+13] = 0x1F0A0000;  // Transparent dark grey               
 246 
 247             extern char palette_control;
 248             palette_control = 1;
 249             vid_bitmap_refresh();
 250         }
 251     }
 252 }

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