root/platform/sx220hs/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_byte_width
  12. vid_get_viewport_yscale
  13. vid_get_viewport_width
  14. vid_get_viewport_display_xoffset
  15. vid_get_viewport_height
  16. vid_get_viewport_height_proper
  17. vid_get_viewport_buffer_width_proper
  18. vid_get_viewport_fullscreen_height
  19. vid_get_palette_type
  20. vid_get_palette_size
  21. vid_get_aspect_ratio
  22. vid_get_bitmap_active_buffer
  23. vid_get_bitmap_active_palette
  24. 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 _LockAndRefresh(); // wrapper function for screen lock
   9         extern void _UnlockAndRefresh(); // wrapper function for screen unlock
  10 
  11         full_screen_refresh |= 3; //found in ScreenUnlock
  12         _LockAndRefresh();      
  13         _UnlockAndRefresh();
  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 0xC0220130
  34 
  35 
  36 void debug_led(int state)
  37 {
  38  *(int*)LED_PR=state ? 0x46 : 0x44;
  39 }
  40 
  41 void camera_set_led(int led, int state, int bright) {
  42  static char led_table[2]={0,9};
  43  _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  44 }
  45 
  46 int get_flash_params_count(void){
  47  return 0xA0;  //@FF1B33A0 in GetParameterData
  48 }
  49 
  50 void JogDial_CW(void){
  51  _PostLogicalEventForNotPowerType(0x86E, 1);  // @FF416880
  52 }
  53 
  54 void JogDial_CCW(void){
  55  _PostLogicalEventForNotPowerType(0x86F, 1);  // @FF41688C
  56 }
  57 
  58 // Viewport and Bitmap values that shouldn't change across firmware versions.
  59 // Values that may change are in lib.c for each firmware version.
  60 
  61 // Defined in stubs_min.S
  62 extern char active_viewport_buffer;
  63 extern void* viewport_buffers[];
  64 
  65 void *vid_get_viewport_fb()
  66 {
  67     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
  68     // Offset the return value because the viewport is left justified instead of centered on this camera
  69     return viewport_buffers[0];
  70 }
  71 
  72 void *vid_get_viewport_live_fb()
  73 {
  74     if (MODE_IS_VIDEO(mode_get()) || (get_movie_status()==VIDEO_RECORD_IN_PROGRESS))
  75         return viewport_buffers[0];     // Video only seems to use the first viewport buffer.
  76 
  77     // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
  78     // Offset the return value because the viewport is left justified instead of centered on this camera
  79     return viewport_buffers[(active_viewport_buffer-1)&3];
  80 }
  81 
  82 // Defined in stubs_min.S
  83 extern int active_bitmap_buffer;
  84 extern char* bitmap_buffer[];
  85 
  86 void *vid_get_bitmap_fb()
  87 {
  88     // Return first bitmap buffer address
  89     return bitmap_buffer[0];
  90 }
  91 
  92 // Physical width of viewport row in bytes
  93 int vid_get_viewport_byte_width() {
  94         return 960 * 6 / 4;     // SX220HS - wide screen LCD is 960 pixels wide, each group of 4 pixels uses 6 bytes (UYVYYY)
  95 }
  96 
  97 // Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240)
  98 int vid_get_viewport_yscale() {
  99         return 2;               // SX220HS viewport is 480 pixels high
 100 }
 101 
 102 
 103 int vid_get_viewport_width()
 104 {
 105         // viewport width table for each image size
 106         // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 107         static long vp_w[4] = { 360, 480, 408, 272 };
 108     if((mode_get()&MODE_MASK) == MODE_PLAY) {
 109         return 480;
 110     }
 111         return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 112 }
 113 
 114 int vid_get_viewport_display_xoffset()
 115 {
 116         // viewport width offset table for each image size
 117         // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
 118         static long vp_w[4] = { 60, 0, 36, 104 };                               // should all be even values for edge overlay
 119     if((mode_get()&MODE_MASK) == MODE_PLAY) {
 120         return 0;
 121     }
 122         return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
 123 }
 124 
 125 long vid_get_viewport_height(){ return 240; }
 126 
 127 // Functions for PTP Live View system
 128 
 129 int vid_get_viewport_height_proper()            { return 480; }
 130 int vid_get_viewport_buffer_width_proper()                { return 960; }
 131 int vid_get_viewport_fullscreen_height()               { return 480; }
 132 int vid_get_palette_type()                      { return 3; }
 133 int vid_get_palette_size()                      { return 256 * 4; }
 134 int vid_get_aspect_ratio()                      { return 1; }
 135 
 136 void *vid_get_bitmap_active_buffer()
 137 {
 138     return bitmap_buffer[active_bitmap_buffer];
 139 }
 140 
 141 void *vid_get_bitmap_active_palette()
 142 {
 143     extern int active_palette_buffer;
 144     extern char* palette_buffer[];
 145     return (palette_buffer[active_palette_buffer]+8);
 146 }
 147 
 148 // Function to load CHDK custom colors into active Canon palette
 149 void load_chdk_palette()
 150 {
 151     extern int active_palette_buffer;
 152     // Only load for the standard record and playback palettes
 153     if ((active_palette_buffer == 0) || (active_palette_buffer == 4))
 154     {
 155         int *pal = (int*)vid_get_bitmap_active_palette();
 156         if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
 157         {
 158             pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
 159             pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
 160             pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
 161             pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
 162             pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
 163             pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
 164             pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
 165             pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
 166             pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
 167             pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
 168             pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
 169             pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
 170             pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
 171             pal[CHDK_COLOR_BASE+13] = 0x0090000;  // Transparent dark grey
 172 
 173             extern char palette_control;
 174             palette_control = 1;
 175             vid_bitmap_refresh();
 176         }
 177     }
 178 }

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