source: branches/reyalp-ptp-live/platform/sx30/lib.c @ 1911

Revision 1911, 6.2 KB checked in by reyalp, 12 months ago (diff)

update live view branch to trunk 1910

  • 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 0xC0220134       // Power LED
33
34// TODO = this uses power LED, need to disable later (so power LED doesn't flicker)
35void debug_led(int state)
36{
37 //*(int*)LED_PR=state ? 0x46 : 0x44;
38}
39
40// SX30 has two 'lights' - Power LED, and AF assist lamp
41// Power Led = first entry in table (led 0)
42// AF Assist Lamp = second entry in table (led 1)
43void camera_set_led(int led, int state, int bright) {
44 static char led_table[2]={3,9};
45 _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state);
46}
47
48int get_flash_params_count(void){
49 return 0x9a;   // found in GetParameterData ???
50}
51
52void JogDial_CW(void){
53 _PostLogicalEventForNotPowerType(0x86E, 1);  // RotateJogDialRight (in table @ FFC0E88C, fw 1.00h)
54}
55
56void JogDial_CCW(void){
57 _PostLogicalEventForNotPowerType(0x86F, 1);  // RotateJogDialLeft (in table @ FFC0E88C, fw 1.00h)
58}
59
60// Viewport and Bitmap values that shouldn't change across firmware versions.
61// Values that may change are in lib.c for each firmware version.
62
63// Defined in stubs_min.S
64extern char active_viewport_buffer;
65extern void* viewport_buffers[];
66
67void *vid_get_viewport_fb()
68{
69    // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined
70    return viewport_buffers[0];
71}
72
73void *vid_get_viewport_live_fb()
74{
75    if (MODE_IS_VIDEO(mode_get()) || (movie_status==VIDEO_RECORD_IN_PROGRESS))
76        return viewport_buffers[0];     // Video only seems to use the first viewport buffer.
77
78    // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data
79    return viewport_buffers[(active_viewport_buffer-1)&3];
80}
81
82// Defined in stubs_min.S
83extern int active_bitmap_buffer;
84extern char* bitmap_buffer[];
85
86void *vid_get_bitmap_fb()
87{
88    // Return first bitmap buffer address
89    return bitmap_buffer[0];
90}
91
92int vid_get_viewport_width()
93{
94    if ((mode_get() & MODE_MASK) == MODE_PLAY)
95    {
96        return 360;
97    }
98    else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16908) // Stitch mode
99    {
100        return 180;
101    }
102    else
103    {
104        return 360;
105    }
106}
107
108int vid_get_viewport_display_xoffset()
109{
110    if ((mode_get() & MODE_MASK) == MODE_PLAY)
111    {
112        return 0;
113    }
114    else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16908) // Stitch mode
115    {
116        if (shooting_get_prop(PROPCASE_STITCH_DIRECTION) == 0)      // Direction check
117            if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
118                return 40;
119            else
120                return 140;
121        else
122            if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0)   // Shot already taken?
123                return 140;
124            else
125                return 40;
126    }
127    else
128    {
129        return 0;
130    }
131}
132
133long vid_get_viewport_height()
134{
135    if ((mode_get() & MODE_MASK) == MODE_PLAY)
136    {
137        return 240;
138    }
139    else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16908) // Stitch mode
140    {
141        return 120;
142    }
143    else if (shooting_get_prop(PROPCASE_ASPECT_RATIO) == 1)     // Wide screen top & bottom 30 pixels not used in viewport
144                return 180;
145        return 240;
146}
147
148int vid_get_viewport_yoffset()
149{
150    if ((mode_get() & MODE_MASK) == MODE_PLAY)
151    {
152        return 0;
153    }
154    else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16908) // Stitch mode
155    {
156        return 0;
157    }
158    else if (shooting_get_prop(PROPCASE_ASPECT_RATIO) == 1)     // Wide screen top & bottom 30 pixels not used in viewport
159                return 30;
160        return 0;
161}
162
163int vid_get_viewport_display_yoffset()
164{
165    if ((mode_get() & MODE_MASK) == MODE_PLAY)
166    {
167        return 0;
168    }
169    else if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16908) // Stitch mode
170    {
171        return 72;
172    }
173    else if (shooting_get_prop(PROPCASE_ASPECT_RATIO) == 1)     // Wide screen top & bottom 30 pixels not used in viewport
174                return 30;
175        return 0;
176}
177
178// Functions for PTP Live View system
179
180int vid_get_viewport_display_xoffset_proper()   { return vid_get_viewport_display_xoffset() * 2; }
181int vid_get_viewport_height_proper()            { return vid_get_viewport_height(); }
182int vid_get_palette_type()                      { return 3; }
183int vid_get_palette_size()                      { return 256 * 4; }
184
185void *vid_get_bitmap_active_buffer()
186{
187    return bitmap_buffer[active_bitmap_buffer];
188}
189
190void *vid_get_bitmap_active_palette()
191{
192    extern int active_palette_buffer;
193    extern char* palette_buffer[];
194    return (palette_buffer[active_palette_buffer]+8);
195}
196
197// Function to load CHDK custom colors into active Canon palette
198void load_chdk_palette()
199{
200    extern int active_palette_buffer;
201    // Only load for the standard record and playback palettes
202    if ((active_palette_buffer == 0) || (active_palette_buffer == 4) || (active_palette_buffer == 6))
203    {
204        int *pal = (int*)vid_get_bitmap_active_palette();
205        if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
206        {
207            pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
208            pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
209            pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
210            pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
211            pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
212            pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
213            pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
214            pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
215            pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
216            pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
217            pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
218            pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
219            pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
220
221            extern char palette_control;
222            palette_control = 1;
223            vid_bitmap_refresh();
224        }
225    }
226}
Note: See TracBrowser for help on using the repository browser.