root/platform/sx40hs/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_width
  16. vid_get_viewport_xoffset
  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_height_proper
  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 
   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 (@FF15B178 & @FF15B1CC)
  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 // SX40 has two 'lights' - Power LED, and AF assist lamp
  67 // Power Led = first entry in table (led 0)
  68 // AF Assist Lamp = second entry in table (led 1)
  69 void camera_set_led(int led, int state, int bright) {
  70  static char led_table[2]={3,9};
  71  _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  72 }
  73 
  74 int get_flash_params_count(void) { return 0x9f; }              // Found @0xff205db4
  75 
  76 void JogDial_CW(void){
  77  _PostLogicalEventToUI(0x872, 1);  // RotateJogDialRight (in table @ FF593E50, fw 1.00g)
  78 }
  79 
  80 void JogDial_CCW(void){
  81  _PostLogicalEventToUI(0x873, 1);  // RotateJogDialLeft (in table @ FF593E5C, fw 1.00g)
  82 }
  83 
  84 // Viewport and Bitmap values that shouldn't change across firmware versions.
  85 // Values that may change are in lib.c for each firmware version.
  86 
  87 // Defined in stubs_min.S
  88 extern char active_viewport_buffer;
  89 extern void* viewport_buffers[];
  90 
  91 void *vid_get_viewport_fb()
  92 {
  93     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
  94     return viewport_buffers[0];
  95 }
  96 
  97 void *vid_get_viewport_live_fb()
  98 {
  99     if (camera_info.state.mode_video || (get_movie_status()==VIDEO_RECORD_IN_PROGRESS))
 100         return viewport_buffers[0];     // Video only seems to use the first viewport buffer.
 101 
 102     // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
 103     return viewport_buffers[(active_viewport_buffer-1)&3];
 104 }
 105 
 106 void *vid_get_viewport_fb_d()
 107 {
 108     extern char *viewport_fb_d;
 109         return viewport_fb_d;
 110 }
 111 
 112 // Defined in stubs_min.S
 113 extern int active_bitmap_buffer;
 114 extern char* bitmap_buffer[];
 115 
 116 void *vid_get_bitmap_fb()
 117 {
 118     // Return first bitmap buffer address
 119     return bitmap_buffer[0];
 120 }
 121 
 122 int vid_get_viewport_width()
 123 {
 124     if (camera_info.state.mode_play)
 125     {
 126         return 360;
 127     }
 128     extern int _GetVRAMHPixelsSize();
 129     return _GetVRAMHPixelsSize() >> 1;
 130 }
 131 
 132 // viewport width offset table for each image size
 133 // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 134 static long vp_xo[5] = { 0, 0, 0, 44 };                         // should all be even values for edge overlay
 135 
 136 int vid_get_viewport_xoffset()
 137 {
 138     if (camera_info.state.mode_play)
 139     {
 140         return 0;
 141     }
 142     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode
 143     {
 144         return 0;
 145     }
 146     else
 147     {
 148             return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 149     }
 150 }
 151 
 152 int vid_get_viewport_display_xoffset()
 153 {
 154     if (camera_info.state.mode_play)
 155     {
 156         return 0;
 157     }
 158     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode
 159     {
 160         if (shooting_get_prop(PROPCASE_STITCH_DIRECTION) == 0)      // Direction check
 161             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 162                 return 40;
 163             else
 164                 return 140;
 165         else
 166             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 167                 return 140;
 168             else
 169                 return 40;
 170     }
 171     else
 172     {
 173             return vp_xo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 174     }
 175 }
 176 
 177 long vid_get_viewport_height()
 178 {
 179     if (camera_info.state.mode_play)
 180     {
 181         return 240;
 182     }
 183     extern int _GetVRAMVPixelsSize();
 184     return _GetVRAMVPixelsSize();
 185 }
 186 
 187 static int vp_yoffset(int stitch)
 188 {
 189     // viewport height offset table for each image size
 190     // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 191     static long vp_yo[5] = { 0, 30, 13, 0 };
 192 
 193     if (camera_info.state.mode_play)
 194     {
 195         return 0;
 196     }
 197     else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16908) // Stitch mode
 198     {
 199         return stitch;
 200     }
 201     else if (camera_info.state.mode_video)
 202     {
 203         return 30;
 204     }
 205     else
 206     {
 207             return vp_yo[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 208     }
 209 }
 210 
 211 int vid_get_viewport_yoffset()
 212 {
 213     return vp_yoffset(0);
 214 }
 215 
 216 int vid_get_viewport_display_yoffset()
 217 {
 218     return vp_yoffset(72);
 219 }
 220 
 221 // Functions for PTP Live View system
 222 
 223 int vid_get_viewport_height_proper()            { return vid_get_viewport_height(); }
 224 int vid_get_palette_type()                      { return 3; }
 225 int vid_get_palette_size()                      { return 256 * 4; }
 226 
 227 void *vid_get_bitmap_active_buffer()
 228 {
 229     return bitmap_buffer[active_bitmap_buffer];
 230 }
 231 
 232 void *vid_get_bitmap_active_palette()
 233 {
 234     extern int active_palette_buffer;
 235     extern char* palette_buffer[];
 236     return (palette_buffer[active_palette_buffer]+4);
 237 }
 238 
 239 // Function to load CHDK custom colors into active Canon palette
 240 void load_chdk_palette()
 241 {
 242     extern int active_palette_buffer;
 243     // Only load for the standard record and playback palettes
 244     if ((active_palette_buffer == 0) || (active_palette_buffer == 3) || (active_palette_buffer == 6))
 245     {
 246         int *pal = (int*)vid_get_bitmap_active_palette();
 247         if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
 248         {
 249             pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
 250             pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
 251             pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
 252             pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
 253             pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
 254             pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
 255             pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
 256             pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
 257             pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
 258             pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
 259             pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
 260             pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
 261             pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
 262             pal[CHDK_COLOR_BASE+13] = 0x0090000;  // Transparent dark grey
 263 
 264             extern char palette_control;
 265             palette_control = 1;
 266             vid_bitmap_refresh();
 267         }
 268     }
 269 }

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