root/platform/d20/lib.c

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

DEFINITIONS

This source file includes following definitions.
  1. hook_raw_image_addr
  2. hook_alt_raw_image_addr
  3. vid_bitmap_refresh
  4. shutdown
  5. debug_led
  6. camera_set_led
  7. get_flash_params_count
  8. vid_get_viewport_fb
  9. vid_get_viewport_live_fb
  10. vid_get_viewport_width
  11. vid_get_viewport_height
  12. vid_get_bitmap_fb
  13. vid_get_viewport_display_xoffset_proper
  14. vid_get_viewport_display_yoffset_proper
  15. vid_get_viewport_height_proper
  16. vid_get_viewport_fullscreen_height
  17. vid_get_palette_type
  18. vid_get_palette_size
  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 extern  int     active_raw_buffer;
   6 extern  char*   raw_buffers[];
   7 
   8 char *hook_raw_image_addr() 
   9 {
  10     return raw_buffers[active_raw_buffer];
  11 }
  12 
  13 char *hook_alt_raw_image_addr()
  14 {
  15     return raw_buffers[active_raw_buffer^1];
  16 }
  17 
  18 void vid_bitmap_refresh() {
  19     extern int full_screen_refresh;
  20     extern void _ScreenUnlock();
  21     extern void _ScreenLock();
  22 
  23     _ScreenLock();
  24     full_screen_refresh |= 3;
  25     _ScreenUnlock();
  26 }
  27 
  28 #define GREEN_LED 0xC0220130
  29 #define AF_LED    0xC0223030
  30 
  31 void shutdown() {
  32     volatile long *p = (void*)GREEN_LED;
  33 
  34     asm(
  35         "MRS     R1, CPSR\n"
  36         "AND     R0, R1, #0x80\n"
  37         "ORR     R1, R1, #0x80\n"
  38         "MSR     CPSR_cf, R1\n"
  39         :::"r1","r0"
  40     );
  41 
  42     *p = 0x44;  // power off.
  43 
  44     while(1);
  45 }
  46 
  47 
  48 void debug_led(int state) {
  49     // using power LED, which defaults to on
  50     // for debugging turn LED off if state is 1 and on for state = 0
  51     // leaves LED on at end of debugging
  52      *(int*)GREEN_LED=state ? 0x46 : 0x44;
  53 }
  54 
  55 // D20 has two 'lights' - Power LED, and AF assist lamp
  56 // Power Led = first entry in table (led ??)
  57 // AF Assist Lamp = second entry in table (led ??)
  58 void camera_set_led(int led, int state, __attribute__ ((unused))int bright) {
  59     static char led_table[2]={0,4};
  60     if(state<=1) _LEDDrive(led_table[led%sizeof(led_table)], (!state)&1);
  61 }
  62 
  63 int get_flash_params_count(void) {
  64     return 0xA6;   // Found @0xff1ab268 - found by finsig
  65 }
  66 
  67 // Viewport and Bitmap values that shouldn't change across firmware versions.
  68 // Values that may change are in lib.c for each firmware version.
  69 
  70 // Defined in stubs_entry.S
  71 extern char active_viewport_buffer;
  72 extern void* viewport_buffers[];
  73 
  74 void *vid_get_viewport_fb()
  75 {
  76     // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
  77     return viewport_buffers[0];
  78 }
  79 
  80 //To do:
  81 void *vid_get_viewport_live_fb()
  82 {
  83     if (MODE_IS_VIDEO(mode_get()))
  84         return viewport_buffers[0];     // Video only seems to use the first viewport buffer.
  85 
  86     // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
  87     return viewport_buffers[(active_viewport_buffer-1)&3];
  88 }
  89 
  90 //To do:
  91 int vid_get_viewport_width() {
  92     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
  93         return 360;
  94     }
  95     extern int _GetVRAMHPixelsSize();
  96     return _GetVRAMHPixelsSize() >> 1;
  97 }
  98 
  99 //To do:
 100 long vid_get_viewport_height() {
 101     if ((mode_get() & MODE_MASK) == MODE_PLAY) {
 102         return 240;
 103     }
 104     extern int _GetVRAMVPixelsSize();
 105     return _GetVRAMVPixelsSize() >> 1;
 106 }
 107 
 108 extern int active_bitmap_buffer;
 109 extern char* bitmap_buffer[];
 110 
 111 void *vid_get_bitmap_fb() {
 112     // Return first bitmap buffer address
 113     return bitmap_buffer[0];
 114 }
 115 
 116 // Functions for PTP Live View system
 117 int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() * 2; }
 118 int vid_get_viewport_display_yoffset_proper()   { return vid_get_viewport_display_yoffset() * 2; }
 119 int vid_get_viewport_height_proper()            { return vid_get_viewport_height() * 2; }
 120 int vid_get_viewport_fullscreen_height()        { return 480; }
 121 int vid_get_palette_type()                      { return 3; }
 122 int vid_get_palette_size()                      { return 256 * 4; }
 123 
 124 void *vid_get_bitmap_active_buffer() {
 125     return bitmap_buffer[active_bitmap_buffer];
 126 }
 127 
 128 void *vid_get_bitmap_active_palette() {
 129     extern int active_palette_buffer;
 130     extern char* palette_buffer[];
 131     void* p = palette_buffer[active_palette_buffer];
 132     // Don't add offset if value is 0
 133     if (p) p += 4;
 134     return p;
 135 }
 136 
 137 #ifdef CAM_LOAD_CUSTOM_COLORS
 138 // Function to load CHDK custom colors into active Canon palette
 139 void load_chdk_palette()
 140 {
 141     extern int active_palette_buffer;
 142     // Only load for the standard record and playback palettes
 143     //rec=0, set menu=, play=, menu=
 144     if ((active_palette_buffer == 0) || (active_palette_buffer == 5))
 145     {
 146         int *pal = (int*)vid_get_bitmap_active_palette();
 147         if (pal && pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
 148         {
 149             pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
 150             pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
 151             pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
 152             pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
 153             pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
 154             pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
 155             pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
 156             pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
 157             pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
 158             pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
 159             pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
 160             pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
 161             pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
 162 
 163             extern char palette_control;
 164             palette_control = 1;
 165             vid_bitmap_refresh();
 166         }
 167     }
 168 }
 169 #endif

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