/* rdcam.c contient les fonctions qui enregistre l'image */ #include "rdcam.h" #include #include #include #define CAM_PCLK BITN(1) #define CAM_HREF BITN(2) #define CAM_VSYNC BITN(3) void cam_init(void) { // configuration des lignes en entrée; //_io_ports[M6811_DDRA] &= ~0x07 ; _io_ports[M6811_DDRG] = 0; } unsigned char test_portcam(unsigned char bit) { if ((_io_ports[M6811_PORTA] & bit) !=0) return 1; else return 0; } /* 352*288 = 101376 octect * le 68 hc ne dispose que de 64ko de RAM !!! PB --> on segmente en 4 * parties : * 288 /4 = 72 * * 352 * 72 */ void cam_get(unsigned char * tab, unsigned char part) { unsigned char ligne; unsigned char *p; // attend que CAM_VSYNC passe à 1 while (!(_io_ports[M6811_PORTA] & 0x04)) ; for (ligne=0;ligne < 72 * part;ligne++) { // attend que CAM_HREF passe à 1 while(!(_io_ports[M6811_PORTA] & 0x02)) ; // attend que CAM_HREF passe à 0 while((_io_ports[M6811_PORTA] & 0x02)) ; } for (ligne=0;ligne<72;ligne++) { p = tab; // attend que CAM_HREF passe à 1 while(!(_io_ports[M6811_PORTA] & 0x02)) ; // tant que CAM_HREF est à 1 while(_io_ports[M6811_PORTA] & 0x02) { // si CAM_PCLK passe à 1 if(_io_ports[M6811_PORTA] & 0x01) { *p++ = _io_ports[M6811_PORTG]; // attend que CAM_PCK passe à 0 while(_io_ports[M6811_PORTA] & 0x01) ; } } tab += 352; } } void cam_count_href_pclk(int *tab) { int i = 0; int c; // attend que CAM_VSYNC passe à 1 while (!(_io_ports[M6811_PORTA] & 0x04)) ; // attend que CAM_HREF passe à 1 while(!(_io_ports[M6811_PORTA] & 0x02)) ; // attend que CAM_HREF passe à 0 while(_io_ports[M6811_PORTA] & 0x02) ; // attend que CAM_HREF passe à 1 while(!(_io_ports[M6811_PORTA] & 0x02)) ; for (i = 0; i < 288; i++) { c = 0; // tant que CAM_HREF est à 1 while(_io_ports[M6811_PORTA] & 0x02) { // attend que PCLK passe à 1 while(!(_io_ports[M6811_PORTA] & 0x01)) ; // attend que PCLK passe à 0 while(_io_ports[M6811_PORTA] & 0x01) ; c++; } *tab++ = c; } } void cam_skip_frames(int n) { int i; for (i = 0; i < n; i++) { // attend que CAM_VSYNC passe à 1 puis 0 while (!(_io_ports[M6811_PORTA] & 0x04)) ; while ((_io_ports[M6811_PORTA] & 0x04)) ; } }