source: branches/philmoz/platform/sx40hs/lib.c @ 1401

Revision 1401, 4.9 KB checked in by philmoz, 19 months ago (diff)

Add SX40HS firmware 1.00g to development branch (ALPHA).

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 0xC0220130       // 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// SX40 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) { return 0x9f; }              // Found @0xff205db4
49
50void JogDial_CW(void){
51 _PostLogicalEventForNotPowerType(0x872, 1);  // RotateJogDialRight (in table @ FF593E50, fw 1.00g)
52}
53
54void JogDial_CCW(void){
55 _PostLogicalEventForNotPowerType(0x873, 1);  // RotateJogDialLeft (in table @ FF593E5C, fw 1.00g)
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
61long vid_get_bitmap_screen_width() { return 360; }
62long vid_get_bitmap_screen_height() { return 240; }
63long vid_get_bitmap_buffer_width() { return 960; }
64long vid_get_bitmap_buffer_height() { return 270; }
65
66int vid_get_viewport_width()
67{
68        // viewport width table for each image size
69        // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
70        static long vp_w[5] = { 360, 360, 360, 272 };
71        return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
72}
73
74int vid_get_viewport_xoffset()
75{
76        // viewport width offset table for each image size
77        // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
78        static long vp_w[5] = { 0, 0, 0, 44 };                          // should all be even values for edge overlay
79        return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
80}
81
82long vid_get_viewport_height()
83{
84        // viewport height table for each image size
85        // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
86        static long vp_h[5] = { 240, 180, 214, 240 };
87        return vp_h[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
88}
89
90int vid_get_viewport_yoffset()
91{
92        // viewport height offset table for each image size
93        // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1
94        static long vp_h[5] = { 0, 30, 13, 0 };
95        return vp_h[shooting_get_prop(PROPCASE_ASPECT_RATIO)];
96}
97
98// viewport image offset - used when image size != viewport size (zebra, histogram, motion detect & edge overlay)
99// returns the byte offset into the viewport buffer where the image pixels start (to skip any black borders)
100int vid_get_viewport_image_offset() {
101        return (vid_get_viewport_yoffset() * vid_get_viewport_buffer_width() + vid_get_viewport_xoffset()) * 3;
102}
103
104// Functions for PTP Live View system
105
106int vid_get_viewport_yoffset_proper()           { return vid_get_viewport_yoffset(); }
107int vid_get_viewport_height_proper()            { return vid_get_viewport_height(); }
108int vid_get_palette_type()                      { return 3; }
109int vid_get_palette_size()                      { return 256 * 4; }
110
111void *vid_get_bitmap_active_buffer()
112{
113    extern int active_bitmap_buffer;
114    extern char* bitmap_buffer[];
115    return bitmap_buffer[active_bitmap_buffer];
116}
117
118void *vid_get_bitmap_active_palette()
119{
120    extern int active_palette_buffer;
121    extern char* palette_buffer[];
122    return (palette_buffer[active_palette_buffer]+4);
123}
124
125// Function to load CHDK custom colors into active Canon palette
126void load_chdk_palette()
127{
128    extern int active_palette_buffer;
129    // Only load for the standard record and playback palettes
130    if ((active_palette_buffer == 0) || (active_palette_buffer == 3) || (active_palette_buffer == 6))
131    {
132        int *pal = (int*)vid_get_bitmap_active_palette();
133        if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62)
134        {
135            pal[CHDK_COLOR_BASE+0]  = 0x33ADF62;  // Red
136            pal[CHDK_COLOR_BASE+1]  = 0x326EA40;  // Dark Red
137            pal[CHDK_COLOR_BASE+2]  = 0x34CD57F;  // Light Red
138            pal[CHDK_COLOR_BASE+3]  = 0x373BFAE;  // Green
139            pal[CHDK_COLOR_BASE+4]  = 0x34BD6CA;  // Dark Green
140            pal[CHDK_COLOR_BASE+5]  = 0x395AB95;  // Light Green
141            pal[CHDK_COLOR_BASE+6]  = 0x34766F0;  // Blue
142            pal[CHDK_COLOR_BASE+7]  = 0x31250F3;  // Dark Blue
143            pal[CHDK_COLOR_BASE+8]  = 0x37F408F;  // Cyan
144            pal[CHDK_COLOR_BASE+9]  = 0x3512D5B;  // Magenta
145            pal[CHDK_COLOR_BASE+10] = 0x3A9A917;  // Yellow
146            pal[CHDK_COLOR_BASE+11] = 0x3819137;  // Dark Yellow
147            pal[CHDK_COLOR_BASE+12] = 0x3DED115;  // Light Yellow
148
149            extern char palette_control;
150            palette_control = 1;
151            vid_bitmap_refresh();
152        }
153    }
154}
Note: See TracBrowser for help on using the repository browser.