root/platform/sx260hs/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 // SX260 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) {
  57     return 0xA6;                                   //asm1989 @FF1F3FB4, sx230:0xA0 @FF1B94A8 in GetParameterData
  58 }
  59 
  60 void JogDial_CW(void) {
  61     _PostLogicalEventForNotPowerType(0x872, 1);    //asm1989 RotateJogDialRight (in table @ FF58799C)
  62 }
  63 
  64 void JogDial_CCW(void) {
  65     _PostLogicalEventForNotPowerType(0x873, 1);    //asm1989  RotateJogDialLeft (in table @FF5879A8  like SX40 -> FF593E5C,)
  66 }
  67 
  68 extern char active_viewport_buffer;
  69 extern void* viewport_buffers[];
  70 
  71 void *vid_get_viewport_fb() {
  72     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
  73     return viewport_buffers[0];
  74 }
  75 
  76 void *vid_get_viewport_live_fb() {
  77     if (MODE_IS_VIDEO(mode_get()) || is_video_recording())
  78         return viewport_buffers[0];     // Video only seems to use the first viewport buffer.
  79 
  80     // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
  81     return viewport_buffers[(active_viewport_buffer-1)&3];
  82 }
  83 
  84 int vid_get_viewport_width() {
  85     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
  86         return 360;
  87     }
  88     extern int _GetVRAMHPixelsSize();
  89     return _GetVRAMHPixelsSize() >> 1;
  90 }
  91 
  92 long vid_get_viewport_height() {
  93     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
  94         return 240;
  95     }
  96     extern int _GetVRAMVPixelsSize();
  97     return _GetVRAMVPixelsSize() >> 1;
  98 }
  99 
 100 // Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240)
 101 int vid_get_viewport_yscale() {
 102     return 2;
 103 }
 104 
 105 int vid_get_viewport_yoffset() {
 106     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
 107         return 0;
 108     } else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) { // Stitch mode
 109         return 0;
 110     } else {
 111             // viewport height offset table for each image size
 112             // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 113             static long vp_h[4] = { 0, 30, 13, 0 };
 114             return vp_h[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 115     }
 116 }
 117 
 118 int vid_get_viewport_display_xoffset() {
 119     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
 120         return 0;
 121     } else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) { // Stitch mode
 122         if (shooting_get_prop(PROPCASE_STITCH_DIRECTION) == 0)      // Direction check
 123             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 124                 return 40;
 125             else
 126                 return 140;
 127         else
 128             if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
 129                 return 140;
 130             else
 131                 return 40;
 132     } else {
 133             // viewport width offset table for each image size
 134             // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 135             static long vp_w[4] = { 0, 0, 0, 44 };                              // should all be even values for edge overlay
 136             return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 137     }
 138 }
 139 
 140 int vid_get_viewport_display_yoffset() {
 141     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
 142         return 0;
 143     } else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) { // Stitch mode
 144         return 72;
 145     } else {
 146             // viewport width offset table for each image size
 147             // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 148             static long vp_h[4] = { 0, 30, 13, 0 };
 149             return vp_h[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 150     }
 151 }
 152 
 153 extern int active_bitmap_buffer;
 154 extern char* bitmap_buffer[];
 155 
 156 void *vid_get_bitmap_fb() {
 157     // Return first bitmap buffer address
 158     return bitmap_buffer[0];
 159 }
 160 
 161 // Functions for PTP Live View system
 162 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() * 2; }
 163 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset() * 2; }
 164 int vid_get_viewport_height_proper()            { return vid_get_viewport_height() * 2; }
 165 int vid_get_viewport_fullscreen_height()        { return 480; }
 166 int vid_get_palette_type()                      { return 3; }
 167 int vid_get_palette_size()                      { return 256 * 4; }
 168 
 169 void *vid_get_bitmap_active_buffer() {
 170     return bitmap_buffer[active_bitmap_buffer];
 171 }
 172 
 173 void *vid_get_bitmap_active_palette() {
 174     extern int active_palette_buffer;
 175     extern char* palette_buffer[];
 176     return (palette_buffer[active_palette_buffer]+4);
 177 }
 178 
 179 // Function to load CHDK custom colors into active Canon palette
 180 void load_chdk_palette()
 181 {
 182     extern int active_palette_buffer;
 183     // Only load for the standard record and playback palettes
 184     //rec=0, set menu=4, play=5, menu=6
 185     if ((active_palette_buffer == 0) || (active_palette_buffer == 5))
 186     {
 187         int *pal = (int*)vid_get_bitmap_active_palette();
 188         if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
 189         {
 190             pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
 191             pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
 192             pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
 193             pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
 194             pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
 195             pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
 196             pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
 197             pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
 198             pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
 199             pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
 200             pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
 201             pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
 202             pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
 203             pal[CHDK_COLOR_BASE+13] = 0x0090000;  // Transparent dark grey
 204 
 205             extern char palette_control;
 206             palette_control = 1;
 207             vid_bitmap_refresh();
 208         }
 209     }
 210 }

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