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

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