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

   1 #include "platform.h"
   2 #include "platform_palette.h"
   3 #include "lolevel.h"
   4 
   5 static char* frame_buffer[2];
   6 
   7 void vid_bitmap_refresh() {
   8     extern int full_screen_refresh;
   9     extern void _ScreenUnlock();
  10     extern void _ScreenLock();
  11 
  12     full_screen_refresh |= 3;
  13     _ScreenLock();
  14     _ScreenUnlock();
  15 }
  16 
  17 void shutdown() {
  18     volatile long *p = (void*)0xC022001C;
  19 
  20     asm(
  21         "MRS     R1, CPSR\n"
  22         "AND     R0, R1, #0x80\n"
  23         "ORR     R1, R1, #0x80\n"
  24         "MSR     CPSR_cf, R1\n"
  25         :::"r1","r0"
  26     );
  27 
  28     *p = 0x44;  // power off.
  29 
  30     while(1);
  31 }
  32 
  33 // see http://chdk.wikia.com/wiki/SX260#LED_addresses
  34 // #define LED_PR 0xC022C30C                       // Power LED (@FF15B178 & @FF15B1CC)
  35 
  36 void debug_led(int state) {
  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 // SX240 has two 'lights' - Power LED, and AF assist lamp
  45 // Power Led = first entry in table (led 0)
  46 // AF Assist Lamp = second entry in table (led 1)
  47 void camera_set_led(int led, int state, int bright) {
  48     static char led_table[2]={0,4};
  49     _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  50 }
  51 
  52 void shutdown_soft() {
  53     _PostLogicalEventForNotPowerType(0x1005,0);
  54 }
  55 
  56 int get_flash_params_count(void) { return 0xa6; }  // Found @0xff1f3f8c sx240hs
  57 
  58 void JogDial_CW(void) {
  59     _PostLogicalEventForNotPowerType(0x872, 1);    //asm1989 RotateJogDialRight (in table @ FF58799C)
  60 }
  61 
  62 void JogDial_CCW(void) {
  63     _PostLogicalEventForNotPowerType(0x873, 1);    //asm1989  RotateJogDialLeft (in table @FF5879A8  like SX40 -> FF593E5C,)
  64 }
  65 
  66 extern char active_viewport_buffer;
  67 extern void* viewport_buffers[];
  68 
  69 void *vid_get_viewport_fb() {
  70     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
  71     return viewport_buffers[0];
  72 }
  73 
  74 void *vid_get_viewport_live_fb() {
  75     if (MODE_IS_VIDEO(mode_get()) || is_video_recording())
  76         return viewport_buffers[0];     // Video only seems to use the first viewport buffer.
  77 
  78     // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
  79     return viewport_buffers[(active_viewport_buffer-1)&3];
  80 }
  81 
  82 int vid_get_viewport_width() {
  83     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
  84         return 360;
  85     }
  86     extern int _GetVRAMHPixelsSize();
  87     return _GetVRAMHPixelsSize() >> 1;
  88 }
  89 
  90 long vid_get_viewport_height() {
  91     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
  92         return 240;
  93     }
  94     extern int _GetVRAMVPixelsSize();
  95     return _GetVRAMVPixelsSize() >> 1;
  96 }
  97 
  98 // Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240)
  99 int vid_get_viewport_yscale() {
 100     return 2;
 101 }
 102 
 103 int vid_get_viewport_yoffset() {
 104     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
 105         return 0;
 106     } else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) { // Stitch mode
 107         return 0;
 108     } else {
 109             // viewport height offset table for each image size
 110             // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 111             static long vp_h[4] = { 0, 30, 13, 0 };
 112             return vp_h[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 113     }
 114 }
 115 
 116 int vid_get_viewport_display_xoffset() {
 117     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
 118         return 0;
 119     } else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) { // Stitch mode
 120         if (shooting_get_prop(PROPCASE_STITCH_DIRECTION) == 0)      // Direction check
 121             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 122                 return 40;
 123             else
 124                 return 140;
 125         else
 126             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 127                 return 140;
 128             else
 129                 return 40;
 130     } else {
 131             // viewport width offset table for each image size
 132             // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 133             static long vp_w[4] = { 0, 0, 0, 44 };                              // should all be even values for edge overlay
 134             return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 135     }
 136 }
 137 
 138 int vid_get_viewport_display_yoffset() {
 139     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
 140         return 0;
 141     } else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) { // Stitch mode
 142         return 72;
 143     } else {
 144             // viewport width offset table for each image size
 145             // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 146             static long vp_h[4] = { 0, 30, 13, 0 };
 147             return vp_h[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 148     }
 149 }
 150 
 151 extern int active_bitmap_buffer;
 152 extern char* bitmap_buffer[];
 153 
 154 void *vid_get_bitmap_fb() {
 155     // Return first bitmap buffer address
 156     return bitmap_buffer[0];
 157 }
 158 
 159 // Functions for PTP Live View system
 160 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() * 2; }
 161 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset() * 2; }
 162 int vid_get_viewport_height_proper()            { return vid_get_viewport_height() * 2; }
 163 int vid_get_viewport_fullscreen_height()        { return 480; }
 164 int vid_get_palette_type()                      { return 3; }
 165 int vid_get_palette_size()                      { return 256 * 4; }
 166 
 167 void *vid_get_bitmap_active_buffer() {
 168     return bitmap_buffer[active_bitmap_buffer];
 169 }
 170 
 171 void *vid_get_bitmap_active_palette() {
 172     extern int active_palette_buffer;
 173     extern char* palette_buffer[];
 174     return (palette_buffer[active_palette_buffer]+4);
 175 }
 176 
 177 // Function to load CHDK custom colors into active Canon palette
 178 void load_chdk_palette()
 179 {
 180     extern int active_palette_buffer;
 181     // Only load for the standard record and playback palettes
 182     //rec=0, set menu=4, play=5, menu=6
 183     if ((active_palette_buffer == 0) || (active_palette_buffer == 5))
 184     {
 185         int *pal = (int*)vid_get_bitmap_active_palette();
 186         if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
 187         {
 188             pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
 189             pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
 190             pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
 191             pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
 192             pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
 193             pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
 194             pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
 195             pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
 196             pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
 197             pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
 198             pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
 199             pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
 200             pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
 201             pal[CHDK_COLOR_BASE+13] = 0x0090000;  // Transparent dark grey
 202 
 203             extern char palette_control;
 204             palette_control = 1;
 205             vid_bitmap_refresh();
 206         }
 207     }
 208 }

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