root/platform/ixus100_sd780/main.c

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

DEFINITIONS

This source file includes following definitions.
  1. startup
  2. get_effective_focal_length
  3. get_focal_length
  4. get_zoom_x
  5. get_vbatt_min
  6. get_vbatt_max
  7. hook_tyWriteOrig
  8. cam_console_init

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 #include "core.h"
   4 #include "keyboard.h"
   5 
   6 
   7 extern long link_bss_start;
   8 extern long link_bss_end;
   9 extern void boot();
  10 
  11 
  12 void startup()
  13 {
  14     long *bss = &link_bss_start;
  15 
  16    // sanity check (pointless with automemiso)
  17     if ((long)&link_bss_end > (MEMISOSTART + MEMISOSIZE)){
  18         started();
  19         shutdown();
  20     }
  21 
  22     // initialize .bss senment
  23     while (bss<&link_bss_end)
  24         *bss++ = 0;
  25 
  26     boot();
  27 }
  28 
  29 
  30 //// TODO setting the DP button as a shortcut to movie in canon menu
  31 //// gives a value of (current mode)+1024 while movie is recording, unless
  32 //// already in movie mode
  33 //static struct {
  34 //      int hackmode;
  35 //      int canonmode;
  36 //} modemap[] = {
  37 //    { MODE_AUTO,               32768 },
  38 //    { MODE_M,                  32769 },
  39 //    { MODE_P,                  32772 },
  40 //    { MODE_PORTRAIT,           0x800D },
  41 //    { MODE_NIGHT_SNAPSHOT,     0x800B },
  42 //    { MODE_KIDS_PETS,          0x8010 },
  43 //    { MODE_INDOOR,             0x8011 },
  44 //    { MODE_SUNSET,             0x4012 },
  45 //    { MODE_FOLIAGE,            0x4013 },
  46 //    { MODE_SNOW,               0x4014 },
  47 //    { MODE_BEACH,              0x4015 },
  48 //    { MODE_FIREWORK,           0x4016 },
  49 //    { MODE_NIGHT_SCENE,        0x4006 }, //AKA Long Shutter --- unclear, 13-Mar-2010/fe50
  50 //    { MODE_UNDERWATER,         0x4017 },
  51 //    { MODE_AQUARIUM,           0x4018 },
  52 //    { MODE_ISO_3200,           0x401D },
  53 //    { MODE_DIGITAL_MACRO,      0x4208 },
  54 //    { MODE_COLOR_ACCENT,       0x421B },
  55 //    { MODE_COLOR_SWAP,         0x421C },
  56 //    { MODE_STITCH,             0x420A },
  57 ////    { MODE_QUICK,              33312 },
  58 //
  59 //    { MODE_VIDEO_STD,          0xA29  },
  60 //    { MODE_VIDEO_COLOR_ACCENT, 0xA27  },
  61 //    { MODE_VIDEO_COLOR_SWAP,   0xA28  },
  62 //};
  63 //
  64 //#define MODESCNT (sizeof(modemap)/sizeof(modemap[0]))
  65 
  66 
  67 // Focus length table in firmware @0xfffe2a8c
  68 #define NUM_FL      7   // 0 - 6, entries in firmware
  69 #define NUM_DATA    3   // 3 words each entry, first is FL
  70 extern int focus_len_table[NUM_FL*NUM_DATA];
  71 
  72 // Conversion factor lens FL --> 35mm equiv
  73 // lens      35mm     CF
  74 // ----      ----     --
  75 // 5.9       33       ( 33/ 5.9) * 59 = 330  (min FL)
  76 // 17.9      100      (100/17.9) * 59 = 329.6  (max FL)
  77 #define CF_EFL      330
  78 #define CF_EFL_DIV  59
  79 
  80 const int zoom_points = NUM_FL;
  81 
  82 int get_effective_focal_length(int zp) {
  83     return (CF_EFL*get_focal_length(zp))/CF_EFL_DIV;
  84 }
  85 
  86 int get_focal_length(int zp) {
  87     if (zp < 0) zp = 0;
  88     else if (zp >= NUM_FL) zp = NUM_FL-1;
  89     return focus_len_table[zp*NUM_DATA];
  90 }
  91 
  92 int get_zoom_x(int zp) {
  93     return get_focal_length(zp)*10/focus_len_table[0];
  94 }
  95 
  96 ///*
  97 //physw_ bit OK
  98 //*/
  99 ////VERIFY_SD780 this was mode_get() previously
 100 //int mode_get2() {
 101 //    int mode, i, t=0xFF;
 102 //    mode  = (physw_status[1] & 0x00000001)?MODE_REC:MODE_PLAY;
 103 //
 104 //    _GetPropertyCase(PROPCASE_SHOOTING_MODE, &t, 4);
 105 //    for (i=0; i<MODESCNT; ++i) {
 106 //      if (modemap[i].canonmode == t) {
 107 //          return (mode | (modemap[i].hackmode & MODE_SHOOTING_MASK));
 108 //      }
 109 //    }
 110 //    return (mode);
 111 //}
 112 
 113 //VERIFY_SD780 min observed
 114 long get_vbatt_min()
 115 {
 116     return 3375; // hnikesch on forum
 117 }
 118 
 119 //VERIFY_SD780 max observed
 120 long get_vbatt_max()
 121 {
 122     return 4125; // fresh off charger slightly greater
 123 }
 124 
 125 #if CAM_CONSOLE_LOG_ENABLED
 126 
 127 #define DEV_HDR_WRITE_OFFSET (0x14C/4)
 128 
 129 typedef int DEV_HDR;
 130 
 131 int (*_tyWriteOrig)(DEV_HDR *hdr, char *buf, int len);
 132 
 133 
 134 int hook_tyWriteOrig(DEV_HDR *hdr, char *buf, int len)
 135 {
 136         // Slow, but stable writes
 137         FILE *fd = fopen("A/stdout.txt", "a");
 138         if (fd) {
 139             fwrite(buf, 1, len, fd);
 140             fclose(fd);
 141         }
 142 
 143     return _tyWriteOrig(hdr, buf, len);
 144 
 145 }
 146 
 147 void cam_console_init()
 148 {
 149     DEV_HDR *DRV_struct;
 150 
 151     DRV_struct = _iosDevFind("/tyCo/0", 0);
 152 
 153     _tyWriteOrig = (void*)DRV_struct[DEV_HDR_WRITE_OFFSET];
 154 
 155         FILE *fd = fopen("A/chdklog.txt", "a");
 156         if (fd) {
 157             // can't be used with "Fut" API
 158             //fprintf(fd, "DRV_struct: %x, _tyWriteOrig: %x\n", DRV_struct, _tyWriteOrig);
 159             char buf[256];
 160             int buflen = sprintf(buf, "DRV_struct: %x, _tyWriteOrig: %x\n", DRV_struct, _tyWriteOrig);
 161             fwrite(buf, 1, buflen, fd);
 162         }
 163 
 164         FILE *fdout = fopen("A/stdout.txt", "r");
 165         if (fdout)
 166         {
 167         DRV_struct[DEV_HDR_WRITE_OFFSET] = (int)hook_tyWriteOrig;
 168         fclose(fdout);
 169             // fprintf(fd, "tyWrite replaced, camera log enabled\n");
 170             fwrite("tyWrite replaced, camera log enabled\n", 1, sizeof("tyWrite replaced, camera log enabled\n"), fd);
 171     }
 172 
 173         if (fd)
 174         {
 175             fclose(fd);
 176         }
 177 
 178 }
 179 
 180 #endif

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