source: trunk/platform/generic/wrappers.c @ 514

Revision 514, 13.7 KB checked in by reyalp, 5 years ago (diff)

merged old-trunk 491:502. russian.lng not updated, since it is very out of date in this tree already.

Line 
1#include "camera.h"
2#include "lolevel.h"
3#include "platform.h"
4#include "conf.h"
5
6#if CAM_DRYOS
7#define _U      0x01    /* upper */
8#define _L      0x02    /* lower */
9#define _D      0x04    /* digit */
10#define _C      0x08    /* cntrl */
11#define _P      0x10    /* punct */
12#define _S      0x20    /* white space (space/lf/tab) */
13#define _X      0x40    /* hex digit */
14#define _SP     0x80    /* hard space (0x20) */
15unsigned char _ctype[] = {
16_C,_C,_C,_C,_C,_C,_C,_C,                        /* 0-7 */
17_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C,         /* 8-15 */
18_C,_C,_C,_C,_C,_C,_C,_C,                        /* 16-23 */
19_C,_C,_C,_C,_C,_C,_C,_C,                        /* 24-31 */
20_S|_SP,_P,_P,_P,_P,_P,_P,_P,                    /* 32-39 */
21_P,_P,_P,_P,_P,_P,_P,_P,                        /* 40-47 */
22_D,_D,_D,_D,_D,_D,_D,_D,                        /* 48-55 */
23_D,_D,_P,_P,_P,_P,_P,_P,                        /* 56-63 */
24_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U,      /* 64-71 */
25_U,_U,_U,_U,_U,_U,_U,_U,                        /* 72-79 */
26_U,_U,_U,_U,_U,_U,_U,_U,                        /* 80-87 */
27_U,_U,_U,_P,_P,_P,_P,_P,                        /* 88-95 */
28_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L,      /* 96-103 */
29_L,_L,_L,_L,_L,_L,_L,_L,                        /* 104-111 */
30_L,_L,_L,_L,_L,_L,_L,_L,                        /* 112-119 */
31_L,_L,_L,_P,_P,_P,_P,_C,                        /* 120-127 */
320,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 128-143 */
330,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 144-159 */
340,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 160-175 */
350,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 176-191 */
360,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 192-207 */
370,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 208-223 */
380,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 224-239 */
390,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};               /* 240-255 */
40#endif
41
42void msleep(long msec)
43{
44    _SleepTask(msec);
45}
46
47void task_lock()
48{
49    _taskLock();
50}
51
52void task_unlock()
53{
54    _taskUnlock();
55}
56
57#ifndef CAM_DRYOS
58const char *task_name(int id)
59{
60    return _taskName(id);
61}
62
63int task_id_list_get(int *idlist,int size)
64{
65    return _taskIdListGet(idlist,size);
66}
67#endif
68
69long get_property_case(long id, void *buf, long bufsize)
70{
71    return _GetPropertyCase(id, buf, bufsize);
72}
73
74long set_property_case(long id, void *buf, long bufsize)
75{
76    return _SetPropertyCase(id, buf, bufsize);
77}
78
79void remount_filesystem()
80{
81    _Unmount_FileSystem();
82    _Mount_FileSystem();
83}
84
85
86void mark_filesystem_bootable()
87{
88    _UpdateMBROnFlash(0, 0x40, "BOOTDISK");
89}
90
91void vid_bitmap_refresh()
92{
93    _RefreshPhysicalScreen(1);
94}
95
96
97long get_parameter_data(long id, void *buf, long bufsize)
98{
99    return _GetParameterData(id|0x4000, buf, bufsize);
100}
101
102long set_parameter_data(long id, void *buf, long bufsize)
103{
104    return _SetParameterData(id|0x4000, buf, bufsize);
105}
106
107long lens_get_zoom_pos()
108{
109    return _GetZoomLensCurrentPosition();
110}
111
112void lens_set_zoom_pos(long newpos)
113{
114}
115
116long lens_get_zoom_point()
117{
118    return _GetZoomLensCurrentPoint();
119}
120
121void lens_set_zoom_point(long newpt)
122{
123    if (newpt < 0) {
124        newpt = 0;
125    } else if (newpt >= zoom_points) {
126        newpt = zoom_points-1;
127    }
128    _MoveZoomLensWithPoint((short*)&newpt);
129    while (zoom_busy);
130}
131
132void lens_set_zoom_speed(long newspd)
133{
134    if (newspd < 5) {
135        newspd = 5;
136    } else if (newspd > 100) {
137        newspd = 100;
138    }
139    _SetZoomActuatorSpeedPercent((short*)&newspd);
140}
141
142void lens_set_focus_pos(long newpos)
143{
144    _MoveFocusLensToDistance((short*)&newpos);
145    //while (focus_busy);
146    while ((shooting_is_flash_ready()!=1) || (focus_busy));
147    newpos = _GetFocusLensSubjectDistance();
148    _SetPropertyCase(PROPCASE_SUBJECT_DIST1, &newpos, sizeof(newpos));
149    _SetPropertyCase(PROPCASE_SUBJECT_DIST2, &newpos, sizeof(newpos));
150}
151
152void play_sound(unsigned sound)
153{
154        static const int sounds[]={ 0x2001, //startup sound
155                                0x2002, //shutter sound
156                                0x2003, //button press sound
157                                0x2004, //self-timer sound
158                                0xC211, //short beep
159                                50000,  // AF confirmation
160                                0xC507, // error beep imo
161                                0x400D, // LONG ERROR BEEP CONTINIUOUS- warning, cannot be stopped (yet)
162                            };
163    if(sound >= sizeof(sounds)/sizeof(sounds[0]))
164        return;
165
166    _PT_PlaySound(sounds[sound], 0);
167}
168
169long stat_get_vbatt()
170{
171    return _VbattGet();
172}
173
174int get_battery_temp()
175{
176    return _GetBatteryTemperature();
177}
178
179int get_ccd_temp()
180{
181    return _GetCCDTemperature();
182}
183
184int get_optical_temp()
185{
186    return _GetOpticalTemperature();
187}
188
189long get_tick_count()
190{
191long t;
192#if !CAM_DRYOS
193    _GetSystemTime(&t);
194    return t;
195#else
196    return (int)_GetSystemTime(&t);
197#endif
198}
199
200/*int creat (const char *name, int flags)
201{
202    return _creat(name, flags);
203}*/
204int open (const char *name, int flags, int mode )
205{
206    return _Open(name, flags, mode);
207}
208int close (int fd)
209{
210    return _Close(fd);
211}
212int write (int fd, void *buffer, long nbytes)
213{
214    return _Write(fd, buffer, nbytes);
215}
216int read (int fd, void *buffer, long nbytes)
217{
218    return _Read(fd, buffer, nbytes);
219}
220int lseek (int fd, long offset, int whence)
221{
222    return _lseek(fd, offset, whence); /* yes, it's lower-case lseek here since Lseek calls just lseek (A610) */
223}
224long mkdir(const char *dirname)
225{
226    return _mkdir(dirname);
227}
228
229int remove(const char *name) {
230    return _Remove(name);
231}
232
233int isdigit(int c) {
234#if !CAM_DRYOS
235    return _isdigit(c);
236#else
237    return _ctype[c]&_D;
238#endif
239}
240
241int isspace(int c) {
242#if !CAM_DRYOS
243    return _isspace(c);
244#else
245    return _ctype[c]&_S;
246#endif
247
248}
249
250int isalpha(int c) {
251#if !CAM_DRYOS
252    return _isalpha(c);
253#else
254    return _ctype[c]&(_U|_L);
255#endif
256}
257
258int isupper(int c) {
259#if !CAM_DRYOS
260    return _isupper(c);
261#else
262    return _ctype[c]&_U;
263#endif
264
265}
266
267long strlen(const char *s) {
268    return _strlen(s);
269}
270
271int strcmp(const char *s1, const char *s2) {
272    return _strcmp(s1, s2);
273}
274
275int strncmp(const char *s1, const char *s2, long n) {
276    return _strncmp(s1, s2, n);
277}
278
279char *strchr(const char *s, int c) {
280    return _strchr(s, c);
281}
282
283char *strcpy(char *dest, const char *src) {
284    return _strcpy(dest, src);
285}
286
287char *strncpy(char *dest, const char *src, long n) {
288    return _strncpy(dest, src, n);
289}
290
291char *strcat(char *dest, const char *app) {
292    return _strcat(dest, app);
293}
294
295char *strrchr(const char *s, int c) {
296    return _strrchr(s, c);
297}
298
299long strtol(const char *nptr, char **endptr, int base) {
300    return _strtol(nptr, endptr, base);
301}
302
303char *strpbrk(const char *s, const char *accept) {
304#if !CAM_DRYOS
305    return _strpbrk(s, accept);
306#else
307    const char *sc1,*sc2;
308
309    for( sc1 = s; *sc1 != '\0'; ++sc1) {
310     for( sc2 = accept; *sc2 != '\0'; ++sc2) {
311      if (*sc1 == *sc2) return (char *) sc1;
312     }
313    }
314return (void*)0;
315#endif
316}
317
318long sprintf(char *s, const char *st, ...)
319{
320    long res;
321    __builtin_va_list va;
322    __builtin_va_start(va, st);
323    res = _vsprintf(s, st, va);
324    __builtin_va_end(va);
325    return res;
326}
327
328unsigned long time(unsigned long *timer) {
329    return _time(timer);
330}
331
332int utime(char *file, void *newTimes) {
333    return _utime(file, newTimes);
334}
335
336void *localtime(const unsigned long *_tod) {
337#if !CAM_DRYOS
338    return _localtime(_tod);
339#else
340// for DRYOS cameras do something with this!  - sizeof(x[]) must be >= sizeof(struct tm) :  'static int x[9];'
341  static int x[9];
342  return _LocalTime(_tod, &x);   
343#endif
344}
345
346double _log(double x) {
347    return __log(x);
348}
349
350double _log10(double x) {
351    return __log10(x);
352}
353
354double _pow(double x, double y) {
355    return __pow(x, y);
356}
357
358double _sqrt(double x) {
359    return __sqrt(x);
360}
361
362void *malloc(long size) {
363    return _malloc(size);
364}
365
366void free(void *p) {
367    return _free(p);
368}
369
370void *memcpy(void *dest, const void *src, long n) {
371    return _memcpy(dest, src, n);
372}
373
374void *memset(void *s, int c, int n) {
375    return _memset(s, c, n);
376}
377
378int memcmp(const void *s1, const void *s2, long n) {
379    return _memcmp(s1, s2, n);
380}
381
382int rand(void) {
383    return _rand();
384}
385
386void *srand(unsigned int seed) {
387    return _srand(seed);
388}
389
390void qsort(void *__base, int __nelem, int __size, int (*__cmp)(const void *__e1, const void *__e2)) {
391    _qsort(__base, __nelem, __size, __cmp);
392}
393
394void *opendir(const char* name) {
395    return _opendir(name);
396}
397
398void* readdir(void *d) {
399# if !CAM_DRYOS
400    return _readdir(d);
401#else
402// for DRYOS cameras  A650, A720  do something with this!  - sizeof(de[]) must be >= sizeof(struct dirent): 'static char de[40];'
403  static char de[40];
404  _ReadFastDir(d, &de);
405  return de[0]? &de : (void*)0;
406#endif
407}
408
409int closedir(void *d) {
410    return _closedir(d);
411}
412
413void rewinddir(void *d) {
414    return _rewinddir(d);
415}
416
417int stat(char *name, void *pStat) {
418    return _stat(name, pStat);
419}
420
421void *umalloc(long size) {
422    return _AllocateUncacheableMemory(size);
423}
424
425void ufree(void *p) {
426    return _FreeUncacheableMemory(p);
427}
428
429static int shutdown_disabled = 0;
430void disable_shutdown() {
431    if (!shutdown_disabled) {
432        _LockMainPower();
433        shutdown_disabled = 1;
434    }
435}
436
437void enable_shutdown() {
438    if (shutdown_disabled) {
439        _UnlockMainPower();
440        shutdown_disabled = 0;
441    }
442}
443void camera_shutdown_in_a_second(void){
444int i;
445//#if CAM_DRYOS
446//#else
447_SetAutoShutdownTime(1); // 1 sec
448for (i=0;i<200;i++) _UnlockMainPower(); // set power unlock counter to 200 or more, because every keyboard function call try to lock power again ( if "Disable LCD off" menu is "alt" or "script").
449//#endif
450}
451long Fopen_Fut(const char *filename, const char *mode){
452 return _Fopen_Fut(filename,mode);
453}
454
455void Fclose_Fut(long file){
456 _Fclose_Fut(file);
457}
458
459long Fread_Fut(void *buf, long elsize, long count, long f){
460 return _Fread_Fut(buf,  elsize,  count, f);
461}
462
463long Fwrite_Fut(const void *buf, long elsize, long count, long f){
464  return _Fwrite_Fut(buf, elsize, count, f);
465}
466
467long Fseek_Fut(long file, long offset, long whence){
468 return  _Fseek_Fut(file, offset, whence);
469}
470
471int rename(const char *oldname, const char *newname){
472 return _rename(oldname, newname);
473}
474
475unsigned int GetFreeCardSpaceKb(void){
476 return (_GetDrive_FreeClusters(0)*(_GetDrive_ClusterSize(0)>>9))>>1;
477}
478
479unsigned int GetTotalCardSpaceKb(void){
480 return (_GetDrive_TotalClusters(0)*(_GetDrive_ClusterSize(0)>>9))>>1;
481}
482
483
484unsigned int GetJpgCount(void){
485
486 return strtol(camera_jpeg_count_str(),((void*)0),0);
487}
488
489unsigned int GetRawCount(void){
490 return GetFreeCardSpaceKb()/((hook_raw_size() / 1024)+GetFreeCardSpaceKb()/GetJpgCount());
491
492}
493
494void EnterToCompensationEVF(void)
495{
496  _EnterToCompensationEVF();
497}
498
499void ExitFromCompensationEVF()
500{
501  _ExitFromCompensationEVF();
502}
503
504#if CAM_MULTIPART
505
506#define SECTOR_SIZE 512
507char *mbr_buf;
508static unsigned long drive_sectors;
509
510int mbr_read(char* mbr_sector, unsigned long drive_total_sectors, unsigned long *part_start_sector,  unsigned long *part_length){
511// return value: 1 - success, 0 - fail
512 
513 int offset=0x10; // points to partition #2
514 int valid;
515 
516 if ((mbr_sector[0x1FE]!=0x55) || (mbr_sector[0x1FF]!=0xAA)) return 0; // signature check
517
518 mbr_buf=_AllocateUncacheableMemory(SECTOR_SIZE);
519 _memcpy(mbr_buf,mbr_sector,SECTOR_SIZE);
520 drive_sectors=drive_total_sectors;
521
522 while(offset>=0) {
523 
524  *part_start_sector=(*(unsigned short*)(mbr_sector+offset+0x1C8)<<16) | *(unsigned short*)(mbr_sector+offset+0x1C6);
525  *part_length=(*(unsigned short*)(mbr_sector+offset+0x1CC)<<16) | *(unsigned short*)(mbr_sector+offset+0x1CA);
526
527  valid= (*part_start_sector) && (*part_length) &&
528         (*part_start_sector<=drive_total_sectors) &&
529         (*part_start_sector+*part_length<=drive_total_sectors) &&
530         ((mbr_sector[offset+0x1BE]==0) || (mbr_sector[offset+0x1BE]==0x80)); // status: 0x80 (active) or 0 (non-active)
531
532  if (valid && ((mbr_sector[0x1C2+offset]==0x0B) || (mbr_sector[0x1C2+offset]==0x0C))) break;   // FAT32 secondary partition
533
534  offset-=0x10;
535
536 }
537
538 return valid;
539}
540
541
542
543
544
545
546
547int get_part_count(void){
548 unsigned long part_start_sector, part_length;
549 char part_status, part_type;
550 int i;
551 int count=0;
552 for (i=0; i<=1;i++){
553  part_start_sector=(*(unsigned short*)(mbr_buf+i*16+0x1C8)<<16) | *(unsigned short*)(mbr_buf+i*16+0x1C6);
554  part_length=(*(unsigned short*)(mbr_buf+i*16+0x1CC)<<16) | *(unsigned short*)(mbr_buf+i*16+0x1CA);
555  part_status=mbr_buf[i*16+0x1BE];
556  part_type=mbr_buf[0x1C2+i*16];
557  if ( part_start_sector && part_length && part_type && ((part_status==0) || (part_status==0x80)) ) count++;
558 }
559 return count;
560}
561
562void swap_partitions(void){
563 int i;
564 char c;
565 for(i=0;i<16;i++){
566  c=mbr_buf[i+0x1BE];
567  mbr_buf[i+0x1BE]=mbr_buf[i+0x1CE];
568  mbr_buf[i+0x1CE]=c;
569 }
570 _WriteSDCard(0,0,1,mbr_buf);
571}
572
573void create_partitions(void){
574 unsigned long start, length;
575 char type;
576
577 _memset(mbr_buf,0,SECTOR_SIZE);
578 
579 start=1; length=2*1024*1024/SECTOR_SIZE; //2 Mb
580 type=1; // FAT primary
581 mbr_buf[0x1BE + 4]=type;
582 mbr_buf[0x1BE + 8]=start;   mbr_buf[0x1BE + 9]=start>>8;   mbr_buf[0x1BE + 10]=start>>16;  mbr_buf[0x1BE + 11]=start>>24;
583 mbr_buf[0x1BE + 12]=length; mbr_buf[0x1BE + 13]=length>>8; mbr_buf[0x1BE + 14]=length>>16; mbr_buf[0x1BE + 15]=length>>24;
584
585 start=start+length; length=drive_sectors-start-1;
586 type=0x0B;  //FAT32 primary;
587 mbr_buf[0x1CE + 4]=type;
588 mbr_buf[0x1CE + 8]=start;   mbr_buf[0x1CE + 9]=start>>8;   mbr_buf[0x1CE + 10]=start>>16;  mbr_buf[0x1CE + 11]=start>>24;
589 mbr_buf[0x1CE + 12]=length; mbr_buf[0x1CE + 13]=length>>8; mbr_buf[0x1CE + 14]=length>>16; mbr_buf[0x1CE + 15]=length>>24;
590
591 mbr_buf[0x1FE]=0x55; mbr_buf[0x1FF]=0xAA; // signature;
592
593 _WriteSDCard(0,0,1,mbr_buf);
594}
595
596#endif
597
598int mute_on_zoom(int x){
599 static int old_busy=0;
600 int busy=zoom_busy||focus_busy;
601 if (old_busy!=busy) {
602  if (busy) {
603#if CAM_CAN_MUTE_MICROPHONE
604   if (conf.mute_on_zoom) _TurnOffMic();
605#endif
606   }
607   else {
608#if CAM_CAN_MUTE_MICROPHONE
609  if (conf.mute_on_zoom) _TurnOnMic();
610#endif
611#if CAM_EV_IN_VIDEO
612  if (get_ev_video_avail()) set_ev_video_avail(0);
613#endif
614  }
615  old_busy=busy;
616 }
617 return x; // preserve R0 if called from assembler
618}
619
620
621#if CAM_AF_SCAN_DURING_VIDEO_RECORD
622void MakeAFScan(void){
623 int a=0, save;
624 if (zoom_busy || focus_busy) return;
625 save=some_flag_for_af_scan;
626 some_flag_for_af_scan=0;
627#if CAM_AF_SCAN_DURING_VIDEO_RECORD == 2
628 parameter_for_af_scan=3;
629#endif
630 _MakeAFScan(&a, 3);
631 some_flag_for_af_scan=save;
632 _ExpCtrlTool_StartContiAE(0,0);
633}
634#endif
635
Note: See TracBrowser for help on using the repository browser.