source: trunk/platform/ixus310_elph500hs/lib.c @ 1527

Revision 1527, 5.1 KB checked in by philmoz, 18 months ago (diff)

Merge latest code from reyalp-flt branch to main trunk.

  • Property svn:eol-style set to native
Line 
1#include "platform.h"
2#include "lolevel.h"
3
4void vid_bitmap_refresh()
5{
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
16void shutdown()
17{
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        *p = 0x44;  // power off.
28       
29        while(1);
30}
31
32#define LED_PR 0xC0220110       // Power Indicator
33
34void debug_led(int state)
35{
36 *(int*)LED_PR=state ? 0x46 : 0x44;
37}
38
39// IXUS 310 has 2 led values
40// 0/7 - Power LED (Green)
41// 1/11 - AF Assist Lamp
42void camera_set_led(int led, int state, int bright) {
43 static char led_table[2]={7,11};
44 _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
45}
46
47int get_flash_params_count(void){
48 return 0xA0;   // found in GetParameterData
49}
50
51// Viewport and Bitmap values that shouldn't change across firmware versions.
52// Values that may change are in lib.c for each firmware version.
53
54// Defined in stubs_min.S
55extern char active_viewport_buffer;
56extern void* viewport_buffers[];
57
58void *vid_get_viewport_fb()
59{
60    // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
61    // Offset the return value because the viewport is left justified instead of centered on this camera
62    return viewport_buffers[0] - vid_get_viewport_xoffset()*3;
63}
64
65void *vid_get_viewport_live_fb()
66{
67    // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
68    // Offset the return value because the viewport is left justified instead of centered on this camera
69    return viewport_buffers[(active_viewport_buffer-1)&3] - vid_get_viewport_xoffset()*3;
70}
71
72// Defined in stubs_min.S
73extern int active_bitmap_buffer;
74extern char* bitmap_buffer[];
75
76void *vid_get_bitmap_fb()
77{
78    // Return first bitmap buffer address
79    return bitmap_buffer[0];
80}
81
82// Physical width of viewport row in bytes
83int vid_get_viewport_byte_width() {
84        return 960 * 6 / 4;     // IXUS 310 - wide screen LCD is 960 pixels wide, each group of 4 pixels uses 6 bytes (UYVYYY)
85}
86
87// Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240)
88int vid_get_viewport_yscale() {
89        return 2;               // IXUS 310 viewport is 480 pixels high
90}
91
92int vid_get_viewport_width()
93{
94        // viewport width table for each image size
95        // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
96        static long vp_w[5] = { 360, 480, 408, 272 };
97        return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
98}
99
100int vid_get_viewport_xoffset()
101{
102        // viewport width offset table for each image size
103        // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
104        static long vp_w[5] = { 60, 0, 36, 104 };                               // should all be even values for edge overlay
105        return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
106}
107
108long vid_get_viewport_height(){ return 240; }
109
110// Functions for PTP Live View system
111
112int vid_get_viewport_xoffset_proper()           { return vid_get_viewport_xoffset() * 2; }
113int vid_get_viewport_yoffset_proper()           { return 480; }
114int vid_get_viewport_width_proper()             { return vid_get_viewport_width() * 2; }
115int vid_get_viewport_height_proper()            { return 480; }
116int vid_get_viewport_max_width()                { return 960; }
117int vid_get_viewport_max_height()               { return 480; }
118int vid_get_palette_type()                      { return 3; }
119int vid_get_palette_size()                      { return 256 * 4; }
120int vid_get_aspect_ratio()                      { return 1; }
121
122void *vid_get_bitmap_active_buffer()
123{
124    return bitmap_buffer[active_bitmap_buffer];
125}
126
127void *vid_get_bitmap_active_palette()
128{
129    extern int active_palette_buffer;
130    extern char* palette_buffer[];
131    return (palette_buffer[active_palette_buffer]+8);
132}
133
134// Function to load CHDK custom colors into active Canon palette
135void load_chdk_palette()
136{
137    extern int active_palette_buffer;
138    // Only load for the standard record and playback palettes
139    if ((active_palette_buffer == 0) || (active_palette_buffer == 16))
140    {
141        int *pal = (int*)vid_get_bitmap_active_palette();
142        if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
143        {
144            pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
145            pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
146            pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
147            pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
148            pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
149            pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
150            pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
151            pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
152            pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
153            pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
154            pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
155            pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
156            pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
157
158            extern char palette_control;
159            palette_control = 1;
160            vid_bitmap_refresh();
161        }
162    }
163}
Note: See TracBrowser for help on using the repository browser.