[644] | 1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // file : display.c |
---|
| 3 | // date : may 2014 |
---|
| 4 | // author : Alain Greiner |
---|
| 5 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 6 | // This file describes the single thread "display" application. |
---|
| 7 | // It uses the external chained buffer DMA to display a stream |
---|
| 8 | // of images on the frame buffer. |
---|
| 9 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 10 | |
---|
| 11 | #include <stdio.h> |
---|
| 12 | #include <stdlib.h> |
---|
| 13 | #include <fcntl.h> |
---|
| 14 | #include <unistd.h> |
---|
| 15 | #include <almosmkh.h> |
---|
| 16 | |
---|
[657] | 17 | #define PATH_MAX_LENGHT 128 |
---|
| 18 | |
---|
[644] | 19 | #define FBF_TYPE 420 |
---|
| 20 | #define NPIXELS 128 |
---|
| 21 | #define NLINES 128 |
---|
| 22 | |
---|
| 23 | /////////// Global variables /////////////////////////////////////// |
---|
| 24 | |
---|
| 25 | char buffer[NPIXELS * NLINES] __attribute__((aligned(512))); |
---|
| 26 | |
---|
| 27 | ///////////////////////// |
---|
| 28 | void build( char * base ) |
---|
| 29 | { |
---|
| 30 | int line; |
---|
| 31 | int pixel; |
---|
| 32 | char * buf; |
---|
| 33 | |
---|
| 34 | for( line = 0 ; line < NLINES ; line++ ) |
---|
| 35 | { |
---|
| 36 | for( pixel = 0 ; pixel < NPIXELS ; pixel++ ) |
---|
| 37 | { |
---|
| 38 | buf = base + (line * NPIXELS) + pixel; |
---|
| 39 | |
---|
| 40 | *buf = ( ((pixel < (NPIXELS>>1)) && (line < (NLINES>>1))) || |
---|
| 41 | ((pixel >= (NPIXELS>>1)) && (line >= (NLINES>>1))) ) ? 0xFF : 0; |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | ////////////////////////////////////// |
---|
| 47 | void print_block( unsigned int * buf ) |
---|
| 48 | { |
---|
| 49 | int offset; // word index in array of words |
---|
| 50 | |
---|
| 51 | printf("\n***** content of buffer %x *****\n", buf ); |
---|
| 52 | for( offset = 0 ; offset < 128 ; offset += 8 ) |
---|
| 53 | { |
---|
| 54 | printf(" - %d\t: %x | %x | %x | %x | %x | %x | %x | %x\n", |
---|
| 55 | offset<<2, buf[offset+0], buf[offset+1], buf[offset+2], buf[offset+3], |
---|
| 56 | buf[offset+4], buf[offset+5], buf[offset+6], buf[offset+7] ); |
---|
| 57 | } |
---|
| 58 | } |
---|
[657] | 59 | |
---|
[656] | 60 | //////////////// |
---|
| 61 | int main( void ) |
---|
[644] | 62 | { |
---|
| 63 | |
---|
| 64 | unsigned int fbf_width; |
---|
| 65 | unsigned int fbf_height; |
---|
| 66 | unsigned int fbf_type; |
---|
| 67 | unsigned int nbytes; |
---|
| 68 | int val; |
---|
| 69 | int error; |
---|
[657] | 70 | char pathname[PATH_MAX_LENGHT]; |
---|
[644] | 71 | |
---|
| 72 | // check frame buffer size |
---|
| 73 | fbf_get_config( &fbf_width , &fbf_height , &fbf_type ); |
---|
| 74 | |
---|
| 75 | if( (NPIXELS != fbf_width) || (NLINES != fbf_height) ) |
---|
| 76 | { |
---|
| 77 | printf("\n[display error] FBF size [%d,%d] does not fit image size[%d,%d]\n", |
---|
| 78 | fbf_width, fbf_height, NPIXELS, NLINES ); |
---|
| 79 | exit( 0 ); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if( fbf_type != FBF_TYPE ) |
---|
| 83 | { |
---|
| 84 | printf("\n[display error] FBF type [%d] does not fit image type [%d]\n", |
---|
| 85 | fbf_type, FBF_TYPE); |
---|
| 86 | exit( 0 ); |
---|
| 87 | } |
---|
| 88 | |
---|
[657] | 89 | // get pathname for input file |
---|
| 90 | while( 1 ) |
---|
| 91 | { |
---|
| 92 | printf("\n[display] path = "); |
---|
| 93 | |
---|
| 94 | error = get_string( pathname , PATH_MAX_LENGHT ); |
---|
| 95 | |
---|
| 96 | if ( error ) printf("\n[display error] cannot get path for input file\n" ); |
---|
| 97 | else break; |
---|
| 98 | } |
---|
| 99 | |
---|
[644] | 100 | // open file |
---|
[657] | 101 | int fd = open( pathname , O_RDONLY , 0 ); |
---|
[644] | 102 | |
---|
[657] | 103 | if( fd < 0 ) |
---|
[644] | 104 | { |
---|
[657] | 105 | printf("\n[display error] Cannot open file <%s>\n", pathname ); |
---|
[644] | 106 | exit( 0 ); |
---|
| 107 | } |
---|
| 108 | |
---|
[657] | 109 | printf("\n[display] open file <%s>\n", pathname ); |
---|
[644] | 110 | |
---|
[657] | 111 | // load buffer from file |
---|
| 112 | nbytes = read( fd , buffer , NPIXELS * NLINES ); |
---|
| 113 | |
---|
| 114 | if( nbytes != NPIXELS * NLINES ) |
---|
[644] | 115 | { |
---|
[657] | 116 | printf("\n[display error] Cannot load image \n" ); |
---|
| 117 | exit( 0 ); |
---|
| 118 | } |
---|
[644] | 119 | |
---|
[657] | 120 | printf("\n[display] load image in buffer %x\n", buffer ); |
---|
[644] | 121 | |
---|
[657] | 122 | // display image |
---|
| 123 | error = fbf_write( buffer , NPIXELS * NLINES , 0 ); |
---|
[644] | 124 | |
---|
[657] | 125 | if( error ) |
---|
| 126 | { |
---|
| 127 | printf("\n[display error] Cannot access frame buffer\n"); |
---|
| 128 | exit( 0 ); |
---|
| 129 | } |
---|
[644] | 130 | |
---|
[657] | 131 | printf("\n[display] display image\n"); |
---|
[644] | 132 | |
---|
| 133 | // close file |
---|
[657] | 134 | close( fd ); |
---|
[644] | 135 | |
---|
| 136 | exit(0); |
---|
[656] | 137 | |
---|
| 138 | return 0; |
---|
[644] | 139 | } |
---|