| 1 | #include "platform.h" |
|---|
| 2 | #include "lolevel.h" |
|---|
| 3 | |
|---|
| 4 | void 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 | |
|---|
| 16 | void 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 0xC022C30C // Power LED (@FF15B178 & @FF15B1CC) |
|---|
| 33 | |
|---|
| 34 | void debug_led(int state) |
|---|
| 35 | { |
|---|
| 36 | // using power LED, which defaults to on |
|---|
| 37 | // for debugging turn LED off if state is 1 and on for state = 0 |
|---|
| 38 | // leaves LED on at end of debugging |
|---|
| 39 | volatile long *p = (void*)LED_PR; |
|---|
| 40 | *p = (*p & 0xFFFFFFCF) | ((state) ? 0x00 : 0x20); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | // G1X has 4 led values |
|---|
| 44 | // 0/0 - Upper indicator Green |
|---|
| 45 | // 1/1 - Lower indicator Orange |
|---|
| 46 | // 2/3 - Power LED Green |
|---|
| 47 | // 3/9 - AF Assist Lamp |
|---|
| 48 | void camera_set_led(int led, int state, int bright) { |
|---|
| 49 | static char led_table[5]={0,1,3,9}; |
|---|
| 50 | _LEDDrive(led_table[led%sizeof(led_table)], state<=1 ? !state : state); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | int get_flash_params_count(void) { return 0x9f; } // Found @0xff206724 |
|---|
| 54 | |
|---|
| 55 | void JogDial_CW(void){ |
|---|
| 56 | _PostLogicalEventForNotPowerType(0x872, 1); // RotateJogDialRight (in table @ FF593A0C, fw 1.00f) |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | void JogDial_CCW(void){ |
|---|
| 60 | _PostLogicalEventForNotPowerType(0x873, 1); // RotateJogDialLeft (in table @ FF593A0C, fw 1.00f) |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | // Viewport and Bitmap values that shouldn't change across firmware versions. |
|---|
| 64 | // Values that may change are in lib.c for each firmware version. |
|---|
| 65 | |
|---|
| 66 | // Defined in stubs_min.S |
|---|
| 67 | extern char active_viewport_buffer; |
|---|
| 68 | extern void* viewport_buffers[]; |
|---|
| 69 | |
|---|
| 70 | void *vid_get_viewport_fb() |
|---|
| 71 | { |
|---|
| 72 | // Return first viewport buffer - for case when vid_get_viewport_live_fb not defined |
|---|
| 73 | return viewport_buffers[0]; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | void *vid_get_viewport_live_fb() |
|---|
| 77 | { |
|---|
| 78 | if (MODE_IS_VIDEO(mode_get()) || (movie_status==VIDEO_RECORD_IN_PROGRESS)) |
|---|
| 79 | return viewport_buffers[0]; // Video only seems to use the first viewport buffer. |
|---|
| 80 | |
|---|
| 81 | // Hopefully return the most recently used viewport buffer so that motion detect, histogram, zebra and edge overly are using current image data |
|---|
| 82 | return viewport_buffers[(active_viewport_buffer-1)&3]; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | // Defined in stubs_min.S |
|---|
| 86 | extern int active_bitmap_buffer; |
|---|
| 87 | extern char* bitmap_buffer[]; |
|---|
| 88 | |
|---|
| 89 | void *vid_get_bitmap_fb() |
|---|
| 90 | { |
|---|
| 91 | // Return first bitmap buffer address |
|---|
| 92 | return bitmap_buffer[0]; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | // Y multiplier for cameras with 480 pixel high viewports (CHDK code assumes 240) |
|---|
| 96 | int vid_get_viewport_yscale() { |
|---|
| 97 | return 2; // G1X viewport is 480 pixels high |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | int vid_get_viewport_width() |
|---|
| 101 | { |
|---|
| 102 | if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode |
|---|
| 103 | { |
|---|
| 104 | return 180; |
|---|
| 105 | } |
|---|
| 106 | else |
|---|
| 107 | { |
|---|
| 108 | // viewport width table for each image size |
|---|
| 109 | // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5 |
|---|
| 110 | static long vp_w[5] = { 360, 360, 360, 272, 216 }; |
|---|
| 111 | return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)]; |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | int vid_get_viewport_display_xoffset() |
|---|
| 116 | { |
|---|
| 117 | if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode |
|---|
| 118 | { |
|---|
| 119 | if (shooting_get_prop(PROPCASE_STITCH_DIRECTION) == 0) // Direction check |
|---|
| 120 | if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0) // Shot already taken? |
|---|
| 121 | return 40; |
|---|
| 122 | else |
|---|
| 123 | return 140; |
|---|
| 124 | else |
|---|
| 125 | if (shooting_get_prop(PROPCASE_STITCH_SEQUENCE) == 0) // Shot already taken? |
|---|
| 126 | return 140; |
|---|
| 127 | else |
|---|
| 128 | return 40; |
|---|
| 129 | } |
|---|
| 130 | else |
|---|
| 131 | { |
|---|
| 132 | // viewport width offset table for each image size |
|---|
| 133 | // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5 |
|---|
| 134 | static long vp_w[5] = { 0, 0, 0, 44, 72 }; // should all be even values for edge overlay |
|---|
| 135 | return vp_w[shooting_get_prop(PROPCASE_ASPECT_RATIO)]; |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | long vid_get_viewport_height() |
|---|
| 140 | { |
|---|
| 141 | if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode |
|---|
| 142 | { |
|---|
| 143 | return 120; |
|---|
| 144 | } |
|---|
| 145 | else |
|---|
| 146 | { |
|---|
| 147 | // viewport height table for each image size |
|---|
| 148 | // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5 |
|---|
| 149 | static long vp_h[5] = { 240, 180, 214, 240, 240 }; |
|---|
| 150 | return vp_h[shooting_get_prop(PROPCASE_ASPECT_RATIO)]; |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | int vid_get_viewport_yoffset() |
|---|
| 155 | { |
|---|
| 156 | if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode |
|---|
| 157 | { |
|---|
| 158 | return 0; |
|---|
| 159 | } |
|---|
| 160 | else |
|---|
| 161 | { |
|---|
| 162 | // viewport height offset table for each image size |
|---|
| 163 | // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5 |
|---|
| 164 | static long vp_h[5] = { 0, 30, 13, 0, 0 }; |
|---|
| 165 | return vp_h[shooting_get_prop(PROPCASE_ASPECT_RATIO)]; |
|---|
| 166 | } |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | int vid_get_viewport_display_yoffset() |
|---|
| 170 | { |
|---|
| 171 | if (shooting_get_prop(PROPCASE_SHOOTING_MODE) == 16909) // Stitch mode |
|---|
| 172 | { |
|---|
| 173 | return 72; |
|---|
| 174 | } |
|---|
| 175 | else |
|---|
| 176 | { |
|---|
| 177 | // viewport width offset table for each image size |
|---|
| 178 | // 0 = 4:3, 1 = 16:9, 2 = 3:2, 3 = 1:1, 4 = 4:5 |
|---|
| 179 | static long vp_h[5] = { 0, 30, 13, 0, 0 }; |
|---|
| 180 | return vp_h[shooting_get_prop(PROPCASE_ASPECT_RATIO)]; |
|---|
| 181 | } |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | // Functions for PTP Live View system |
|---|
| 185 | |
|---|
| 186 | int vid_get_viewport_yoffset_proper() { return vid_get_viewport_yoffset() * 2; } |
|---|
| 187 | int vid_get_viewport_display_xoffset_proper() { return vid_get_viewport_display_xoffset() * 2; } |
|---|
| 188 | int vid_get_viewport_display_yoffset_proper() { return vid_get_viewport_display_yoffset() * 2; } |
|---|
| 189 | int vid_get_viewport_width_proper() { return vid_get_viewport_width() * 2; } |
|---|
| 190 | int vid_get_viewport_height_proper() { return vid_get_viewport_height() * 2; } |
|---|
| 191 | int vid_get_viewport_max_height() { return 480; } |
|---|
| 192 | int vid_get_palette_type() { return 3; } |
|---|
| 193 | int vid_get_palette_size() { return 256 * 4; } |
|---|
| 194 | |
|---|
| 195 | void *vid_get_bitmap_active_buffer() |
|---|
| 196 | { |
|---|
| 197 | return bitmap_buffer[active_bitmap_buffer]; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | void *vid_get_bitmap_active_palette() |
|---|
| 201 | { |
|---|
| 202 | extern int active_palette_buffer; |
|---|
| 203 | extern char* palette_buffer[]; |
|---|
| 204 | return (palette_buffer[active_palette_buffer]+4); |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | // Function to load CHDK custom colors into active Canon palette |
|---|
| 208 | void load_chdk_palette() |
|---|
| 209 | { |
|---|
| 210 | extern int active_palette_buffer; |
|---|
| 211 | // Only load for the standard record and playback palettes |
|---|
| 212 | if ((active_palette_buffer == 0) || (active_palette_buffer == 3) || (active_palette_buffer == 6)) |
|---|
| 213 | { |
|---|
| 214 | int *pal = (int*)vid_get_bitmap_active_palette(); |
|---|
| 215 | if (pal[CHDK_COLOR_BASE+0] != 0x33ADF62) |
|---|
| 216 | { |
|---|
| 217 | pal[CHDK_COLOR_BASE+0] = 0x33ADF62; // Red |
|---|
| 218 | pal[CHDK_COLOR_BASE+1] = 0x326EA40; // Dark Red |
|---|
| 219 | pal[CHDK_COLOR_BASE+2] = 0x34CD57F; // Light Red |
|---|
| 220 | pal[CHDK_COLOR_BASE+3] = 0x373BFAE; // Green |
|---|
| 221 | pal[CHDK_COLOR_BASE+4] = 0x34BD6CA; // Dark Green |
|---|
| 222 | pal[CHDK_COLOR_BASE+5] = 0x395AB95; // Light Green |
|---|
| 223 | pal[CHDK_COLOR_BASE+6] = 0x34766F0; // Blue |
|---|
| 224 | pal[CHDK_COLOR_BASE+7] = 0x31250F3; // Dark Blue |
|---|
| 225 | pal[CHDK_COLOR_BASE+8] = 0x37F408F; // Cyan |
|---|
| 226 | pal[CHDK_COLOR_BASE+9] = 0x3512D5B; // Magenta |
|---|
| 227 | pal[CHDK_COLOR_BASE+10] = 0x3A9A917; // Yellow |
|---|
| 228 | pal[CHDK_COLOR_BASE+11] = 0x3819137; // Dark Yellow |
|---|
| 229 | pal[CHDK_COLOR_BASE+12] = 0x3DED115; // Light Yellow |
|---|
| 230 | |
|---|
| 231 | extern char palette_control; |
|---|
| 232 | palette_control = 1; |
|---|
| 233 | vid_bitmap_refresh(); |
|---|
| 234 | } |
|---|
| 235 | } |
|---|
| 236 | } |
|---|