root/platform/sx230hs/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_byte_width
  9. vid_get_viewport_yscale
  10. vid_get_viewport_width
  11. vid_get_viewport_display_xoffset
  12. vid_get_viewport_height
  13. vid_get_viewport_height_proper
  14. vid_get_viewport_buffer_width_proper
  15. vid_get_viewport_fullscreen_height
  16. vid_get_palette_type
  17. vid_get_palette_size
  18. vid_get_aspect_ratio
  19. vid_get_bitmap_active_buffer
  20. vid_get_bitmap_active_palette
  21. load_chdk_palette

   1 #include "platform.h"
   2 #include "platform_palette.h"
   3 #include "lolevel.h"
   4 
   5 
   6 void vid_bitmap_refresh()
   7 {
   8         extern int full_screen_refresh;
   9 
  10         extern void _LockAndRefresh(); // wrapper function for screen lock
  11         extern void _UnlockAndRefresh(); // wrapper function for screen unlock
  12 
  13         full_screen_refresh |= 3; //found in ScreenUnlock
  14         _LockAndRefresh();      
  15         _UnlockAndRefresh();
  16 }
  17 
  18 
  19 void shutdown()
  20 {
  21         volatile long *p = (void*)0xC022001C;
  22 
  23         asm(
  24                 "MRS     R1, CPSR\n"
  25                 "AND     R0, R1, #0x80\n"
  26                 "ORR     R1, R1, #0x80\n"
  27                 "MSR     CPSR_cf, R1\n"
  28                 :::"r1","r0");
  29 
  30         *p = 0x44;  // power off.
  31 
  32         while(1);
  33 }
  34 
  35 #define LED_PR 0xC0220130
  36 
  37 
  38 void debug_led(int state)
  39 {
  40  *(int*)LED_PR=state ? 0x46 : 0x44;
  41 }
  42 
  43 void camera_set_led(int led, int state, __attribute__ ((unused))int bright) {
  44  static char led_table[2]={0,9};
  45  _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
  46 }
  47 
  48 int get_flash_params_count(void){
  49  return 0xA0;   //@FF1B94A8 in GetParameterData 
  50 }
  51 
  52 void JogDial_CW(void){
  53         _PostLogicalEventToUI(0x86E, 1);  // RotateJogDialRight
  54 }
  55 
  56 void JogDial_CCW(void){
  57         _PostLogicalEventToUI(0x86F, 1);  // RotateJogDialLeft
  58 }
  59 
  60 
  61 // Viewport and Bitmap values that shouldn't change across firmware versions.
  62 // Values that may change are in lib.c for each firmware version.
  63 
  64 // Defined in stubs_min.S
  65 extern int active_bitmap_buffer;
  66 extern char* bitmap_buffer[];
  67 
  68 // Physical width of viewport row in bytes
  69 int vid_get_viewport_byte_width() {
  70         return 960 * 6 / 4;     // SX230HS - wide screen LCD is 960 pixels wide, each group of 4 pixels uses 6 bytes (UYVYYY)
  71 }
  72 
  73 // Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240)
  74 int vid_get_viewport_yscale() {
  75         return 2;               // SX230HS viewport is 480 pixels high
  76 }
  77 
  78 
  79 int vid_get_viewport_width()
  80 {
  81         // viewport width table for each image size
  82         // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
  83         static long vp_w[4] = { 360, 480, 408, 272 };
  84         return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
  85 }
  86 
  87 int vid_get_viewport_display_xoffset()
  88 {
  89         // viewport width offset table for each image size
  90         // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
  91         static long vp_w[4] = { 60, 0, 36, 104 };                               // should all be even values for edge overlay
  92         return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
  93 }
  94 
  95 long vid_get_viewport_height(){ return 240; }
  96 
  97 // Functions for PTP Live View system
  98 int vid_get_viewport_height_proper()            { return 480; }
  99 int vid_get_viewport_buffer_width_proper()                { return 960; }
 100 int vid_get_viewport_fullscreen_height()               { return 480; }
 101 int vid_get_palette_type()                      { return 3; }
 102 int vid_get_palette_size()                      { return 256 * 4; }
 103 int vid_get_aspect_ratio()                      { return 1; }
 104 
 105 void *vid_get_bitmap_active_buffer()
 106 {
 107     return bitmap_buffer[active_bitmap_buffer];
 108 }
 109 
 110 void *vid_get_bitmap_active_palette()
 111 {
 112     extern int active_palette_buffer;
 113     extern char* palette_buffer[];
 114     void* p = palette_buffer[active_palette_buffer];
 115     // Don't add offset if value is 0
 116     if (p) p += 8;
 117     return p;
 118 }
 119 
 120 // Function to load CHDK custom colors into active Canon palette
 121 void load_chdk_palette()
 122 {
 123     extern int active_palette_buffer;
 124     // Only load for the standard record and playback palettes
 125     if ((active_palette_buffer == 0) || (active_palette_buffer == 4))
 126     {
 127         int *pal = (int*)vid_get_bitmap_active_palette();
 128         if (pal && pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
 129         {
 130             pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
 131             pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
 132             pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
 133             pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
 134             pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
 135             pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
 136             pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
 137             pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
 138             pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
 139             pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
 140             pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
 141             pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
 142             pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
 143             pal[CHDK_COLOR_BASE+13] = 0x0090000;  // Transparent dark grey
 144 
 145             extern char palette_control;
 146             palette_control = 1;
 147             vid_bitmap_refresh();
 148         }
 149     }
 150 }

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