Sample program for Futaba GP1059A01 240x36dot VFD

Dependencies:   mbed SDFileSystem FatFileSystem

Committer:
kanpapa
Date:
Sat Oct 05 22:56:59 2019 +0000
Revision:
0:cd32c44c16f8
Update SDFileSystem

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kanpapa 0:cd32c44c16f8 1 //
kanpapa 0:cd32c44c16f8 2 // VFD BMP file display program
kanpapa 0:cd32c44c16f8 3 // 2011/11/26 by @kanpapa
kanpapa 0:cd32c44c16f8 4 //
kanpapa 0:cd32c44c16f8 5
kanpapa 0:cd32c44c16f8 6 #include "mbed.h"
kanpapa 0:cd32c44c16f8 7 #include "vfd_gp1059.h"
kanpapa 0:cd32c44c16f8 8
kanpapa 0:cd32c44c16f8 9 /*
kanpapa 0:cd32c44c16f8 10 =====================
kanpapa 0:cd32c44c16f8 11 GP1059A01(I/O)
kanpapa 0:cd32c44c16f8 12 ---------------------
kanpapa 0:cd32c44c16f8 13 p9 1 (D0) I/O
kanpapa 0:cd32c44c16f8 14 p10 2 (D1) I/O
kanpapa 0:cd32c44c16f8 15 p11 3 (D2) I/O
kanpapa 0:cd32c44c16f8 16 p12 4 (D3) I/O
kanpapa 0:cd32c44c16f8 17 p13 5 (D4) I/O
kanpapa 0:cd32c44c16f8 18 p14 6 (D5) I/O
kanpapa 0:cd32c44c16f8 19 p15 7 (D6) I/O
kanpapa 0:cd32c44c16f8 20 p16 8 (D7) I/O
kanpapa 0:cd32c44c16f8 21 p21 10 (INT) O
kanpapa 0:cd32c44c16f8 22 p22 11 (WR) I
kanpapa 0:cd32c44c16f8 23 p23 12 (RD) I
kanpapa 0:cd32c44c16f8 24 p24 13 (CS) I
kanpapa 0:cd32c44c16f8 25 p25 14 (C/D) I
kanpapa 0:cd32c44c16f8 26 */
kanpapa 0:cd32c44c16f8 27
kanpapa 0:cd32c44c16f8 28 VFD_GP1059 vfd(p9, p10, p11, p12, p13, p14, p15, p16, p21, p22, p23, p24, p25);
kanpapa 0:cd32c44c16f8 29
kanpapa 0:cd32c44c16f8 30 //
kanpapa 0:cd32c44c16f8 31 // For SD_card
kanpapa 0:cd32c44c16f8 32 //
kanpapa 0:cd32c44c16f8 33 #include "SDFileSystem.h"
kanpapa 0:cd32c44c16f8 34 //SDFileSystem sd(p5, p6, p7, p13, "sd"); // mosi, miso, sclk, cs, name
kanpapa 0:cd32c44c16f8 35 SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs, name (HW modification candidate)
kanpapa 0:cd32c44c16f8 36
kanpapa 0:cd32c44c16f8 37 Serial pc(USBTX, USBRX);
kanpapa 0:cd32c44c16f8 38 LocalFileSystem local("local");
kanpapa 0:cd32c44c16f8 39
kanpapa 0:cd32c44c16f8 40 // LED Status
kanpapa 0:cd32c44c16f8 41 // mbed
kanpapa 0:cd32c44c16f8 42 DigitalOut led1(LED1);
kanpapa 0:cd32c44c16f8 43 // LPCXpresso
kanpapa 0:cd32c44c16f8 44 //DigitalOut led1(P0_22);
kanpapa 0:cd32c44c16f8 45
kanpapa 0:cd32c44c16f8 46 unsigned char reverse_bit(unsigned char x){
kanpapa 0:cd32c44c16f8 47 const unsigned int bit[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
kanpapa 0:cd32c44c16f8 48 unsigned char y = 0;
kanpapa 0:cd32c44c16f8 49 for (int i = 0; i < 8; i++){
kanpapa 0:cd32c44c16f8 50 if ((bit[i] & x) != 0){
kanpapa 0:cd32c44c16f8 51 y |= bit[7-i];
kanpapa 0:cd32c44c16f8 52 }
kanpapa 0:cd32c44c16f8 53 }
kanpapa 0:cd32c44c16f8 54 return(y);
kanpapa 0:cd32c44c16f8 55 }
kanpapa 0:cd32c44c16f8 56
kanpapa 0:cd32c44c16f8 57 void blink_LED() {
kanpapa 0:cd32c44c16f8 58 for (int i = 0 ; i < 5 ; i++) {
kanpapa 0:cd32c44c16f8 59 led1 = 1;
kanpapa 0:cd32c44c16f8 60 wait(0.2);
kanpapa 0:cd32c44c16f8 61 led1 = 0;
kanpapa 0:cd32c44c16f8 62 wait(0.2);
kanpapa 0:cd32c44c16f8 63 }
kanpapa 0:cd32c44c16f8 64 return;
kanpapa 0:cd32c44c16f8 65 }
kanpapa 0:cd32c44c16f8 66
kanpapa 0:cd32c44c16f8 67
kanpapa 0:cd32c44c16f8 68 /*
kanpapa 0:cd32c44c16f8 69 *
kanpapa 0:cd32c44c16f8 70 * BMP file data handler sample
kanpapa 0:cd32c44c16f8 71 *
kanpapa 0:cd32c44c16f8 72 * reference : http://www.umekkii.jp/data/computer/file_format/bitmap.cgi
kanpapa 0:cd32c44c16f8 73 *
kanpapa 0:cd32c44c16f8 74 */
kanpapa 0:cd32c44c16f8 75
kanpapa 0:cd32c44c16f8 76 #include <stdio.h>
kanpapa 0:cd32c44c16f8 77
kanpapa 0:cd32c44c16f8 78
kanpapa 0:cd32c44c16f8 79 // mono color bitmap 1214byte
kanpapa 0:cd32c44c16f8 80 #define BUFFER_SIZE 1280
kanpapa 0:cd32c44c16f8 81
kanpapa 0:cd32c44c16f8 82 typedef struct bmp_header_st {
kanpapa 0:cd32c44c16f8 83 unsigned short bfType __attribute__((packed));
kanpapa 0:cd32c44c16f8 84 unsigned long bfSize __attribute__((packed));
kanpapa 0:cd32c44c16f8 85 unsigned short bfReserved1 __attribute__((packed));
kanpapa 0:cd32c44c16f8 86 unsigned short bfReserved2 __attribute__((packed));
kanpapa 0:cd32c44c16f8 87 unsigned long bfOffBits __attribute__((packed));
kanpapa 0:cd32c44c16f8 88
kanpapa 0:cd32c44c16f8 89 unsigned long biSize __attribute__((packed));
kanpapa 0:cd32c44c16f8 90 long biWidth __attribute__((packed));
kanpapa 0:cd32c44c16f8 91 long biHeight __attribute__((packed));
kanpapa 0:cd32c44c16f8 92 unsigned short biPlanes __attribute__((packed));
kanpapa 0:cd32c44c16f8 93 unsigned short biBitCount __attribute__((packed));
kanpapa 0:cd32c44c16f8 94 unsigned long biCompression __attribute__((packed));
kanpapa 0:cd32c44c16f8 95 unsigned long biSizeImage __attribute__((packed));
kanpapa 0:cd32c44c16f8 96 long biXPixPerMeter __attribute__((packed));
kanpapa 0:cd32c44c16f8 97 long biYPixPerMeter __attribute__((packed));
kanpapa 0:cd32c44c16f8 98 unsigned long biClrUsed __attribute__((packed));
kanpapa 0:cd32c44c16f8 99 unsigned long biCirImportant __attribute__((packed));
kanpapa 0:cd32c44c16f8 100 }
kanpapa 0:cd32c44c16f8 101 bmp_header;
kanpapa 0:cd32c44c16f8 102
kanpapa 0:cd32c44c16f8 103 typedef struct color_palette_st {
kanpapa 0:cd32c44c16f8 104 unsigned char red;
kanpapa 0:cd32c44c16f8 105 unsigned char green;
kanpapa 0:cd32c44c16f8 106 unsigned char blue;
kanpapa 0:cd32c44c16f8 107 unsigned char dummy;
kanpapa 0:cd32c44c16f8 108 }
kanpapa 0:cd32c44c16f8 109 color_palette;
kanpapa 0:cd32c44c16f8 110
kanpapa 0:cd32c44c16f8 111 void print_bit(unsigned char x){
kanpapa 0:cd32c44c16f8 112 const unsigned int bit[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
kanpapa 0:cd32c44c16f8 113 for (int i = 0; i < 8; i++){
kanpapa 0:cd32c44c16f8 114 if ((bit[i] & x) != 0){
kanpapa 0:cd32c44c16f8 115 printf("1");
kanpapa 0:cd32c44c16f8 116 } else {
kanpapa 0:cd32c44c16f8 117 printf(" ");
kanpapa 0:cd32c44c16f8 118 }
kanpapa 0:cd32c44c16f8 119 }
kanpapa 0:cd32c44c16f8 120 return;
kanpapa 0:cd32c44c16f8 121 }
kanpapa 0:cd32c44c16f8 122
kanpapa 0:cd32c44c16f8 123 int read_bmp_mono(const char *file_name, unsigned char *buffer, int buffer_size){
kanpapa 0:cd32c44c16f8 124 FILE *fs;
kanpapa 0:cd32c44c16f8 125 bmp_header bh;
kanpapa 0:cd32c44c16f8 126 color_palette cp[2];
kanpapa 0:cd32c44c16f8 127 printf( "BMP file access sample\r\n");
kanpapa 0:cd32c44c16f8 128
kanpapa 0:cd32c44c16f8 129 if ( NULL == (fs = fopen( file_name, "rb" )) ) {
kanpapa 0:cd32c44c16f8 130 printf( "file open error when opening file \"%s\"\r\n", file_name );
kanpapa 0:cd32c44c16f8 131 return ( 1 );
kanpapa 0:cd32c44c16f8 132 }
kanpapa 0:cd32c44c16f8 133
kanpapa 0:cd32c44c16f8 134 /*
kanpapa 0:cd32c44c16f8 135 * reading header
kanpapa 0:cd32c44c16f8 136 */
kanpapa 0:cd32c44c16f8 137
kanpapa 0:cd32c44c16f8 138 fread( &bh, sizeof( bh ), 1, fs );
kanpapa 0:cd32c44c16f8 139
kanpapa 0:cd32c44c16f8 140 printf( " bfType : 0x%04X\r\n", bh.bfType );
kanpapa 0:cd32c44c16f8 141 printf( " bfSize : %ld\r\n", bh.bfSize );
kanpapa 0:cd32c44c16f8 142 printf( " bfOffBits : %ld\r\n", bh.bfOffBits );
kanpapa 0:cd32c44c16f8 143 printf( " biSize : %lu\r\n", bh.biSize );
kanpapa 0:cd32c44c16f8 144 printf( " biWidth : %ld\r\n", bh.biWidth );
kanpapa 0:cd32c44c16f8 145 printf( " biHeight : %ld\r\n", bh.biHeight );
kanpapa 0:cd32c44c16f8 146 printf( " biPlanes : %d\r\n", bh.biPlanes );
kanpapa 0:cd32c44c16f8 147 printf( " biBitCount : %d\r\n", bh.biBitCount );
kanpapa 0:cd32c44c16f8 148 printf( " biCompression : %lu\r\n", bh.biCompression );
kanpapa 0:cd32c44c16f8 149 printf( " biSizeImage : %lu\r\n", bh.biSizeImage );
kanpapa 0:cd32c44c16f8 150 printf( " biXPixPerMeter : %ld\r\n", bh.biXPixPerMeter );
kanpapa 0:cd32c44c16f8 151 printf( " biYPixPerMeter : %ld\r\n", bh.biYPixPerMeter );
kanpapa 0:cd32c44c16f8 152 printf( " biClrUsed : %lu\r\n", bh.biClrUsed );
kanpapa 0:cd32c44c16f8 153 printf( " biCirImportant : %lu\r\n", bh.biCirImportant );
kanpapa 0:cd32c44c16f8 154
kanpapa 0:cd32c44c16f8 155 /*
kanpapa 0:cd32c44c16f8 156 * checking header (mono color pallet:2)
kanpapa 0:cd32c44c16f8 157 */
kanpapa 0:cd32c44c16f8 158 if ( (bh.bfType != 0x4D42) // "BM"
kanpapa 0:cd32c44c16f8 159 || (bh.bfOffBits != 54 + 2 * sizeof( color_palette ) ) // pallet data 2
kanpapa 0:cd32c44c16f8 160 || (bh.biBitCount != 1) // color 1bit
kanpapa 0:cd32c44c16f8 161 || (bh.biCompression != 0)
kanpapa 0:cd32c44c16f8 162 ) {
kanpapa 0:cd32c44c16f8 163 printf( "unsupported file format\r\n" );
kanpapa 0:cd32c44c16f8 164 fclose( fs );
kanpapa 0:cd32c44c16f8 165 return ( 1 );
kanpapa 0:cd32c44c16f8 166 }
kanpapa 0:cd32c44c16f8 167
kanpapa 0:cd32c44c16f8 168 /*
kanpapa 0:cd32c44c16f8 169 * header information
kanpapa 0:cd32c44c16f8 170 */
kanpapa 0:cd32c44c16f8 171 printf( "header read, the image data size is %lu bytes\r\n", bh.bfSize );
kanpapa 0:cd32c44c16f8 172 printf( " the image data size is %lu bytes\r\n", bh.biSizeImage );
kanpapa 0:cd32c44c16f8 173 printf( " horizontal size %lu pixels\r\n", bh.biWidth );
kanpapa 0:cd32c44c16f8 174 printf( " vertical size %lu pixels\r\n", bh.biHeight );
kanpapa 0:cd32c44c16f8 175
kanpapa 0:cd32c44c16f8 176 /*
kanpapa 0:cd32c44c16f8 177 * read color palette
kanpapa 0:cd32c44c16f8 178 */
kanpapa 0:cd32c44c16f8 179
kanpapa 0:cd32c44c16f8 180 for ( int i = 0; i < 2; i++ ) {
kanpapa 0:cd32c44c16f8 181 fread( &(cp[i]), sizeof( color_palette ), 1, fs );
kanpapa 0:cd32c44c16f8 182 printf( "color pallet No.0x%02X : R:0x%02X - G:0x%02X - B:0x%02X\r\n", i, (cp[i]).red, (cp[i]).green, (cp[i]).blue );
kanpapa 0:cd32c44c16f8 183 }
kanpapa 0:cd32c44c16f8 184
kanpapa 0:cd32c44c16f8 185 /*
kanpapa 0:cd32c44c16f8 186 * read pixel data
kanpapa 0:cd32c44c16f8 187 */
kanpapa 0:cd32c44c16f8 188 unsigned long readsize = fread( buffer, sizeof( unsigned char ) , buffer_size, fs );
kanpapa 0:cd32c44c16f8 189 printf( "Readsize: %d\r\n", readsize);
kanpapa 0:cd32c44c16f8 190
kanpapa 0:cd32c44c16f8 191 fclose( fs );
kanpapa 0:cd32c44c16f8 192 return( 0 );
kanpapa 0:cd32c44c16f8 193 }
kanpapa 0:cd32c44c16f8 194
kanpapa 0:cd32c44c16f8 195 bool CheckExtention( const char* filename, const char* ext )
kanpapa 0:cd32c44c16f8 196 {
kanpapa 0:cd32c44c16f8 197 if ( filename && ext )
kanpapa 0:cd32c44c16f8 198 {
kanpapa 0:cd32c44c16f8 199 return 0 == std::strcmp(std::strrchr(filename, '.'), ext);
kanpapa 0:cd32c44c16f8 200 }
kanpapa 0:cd32c44c16f8 201 return false;
kanpapa 0:cd32c44c16f8 202 }
kanpapa 0:cd32c44c16f8 203
kanpapa 0:cd32c44c16f8 204
kanpapa 0:cd32c44c16f8 205 int display_bmp(char * bmp_file) {
kanpapa 0:cd32c44c16f8 206 unsigned char buffer[ BUFFER_SIZE ];
kanpapa 0:cd32c44c16f8 207
kanpapa 0:cd32c44c16f8 208 printf("bmp_file: %s\n\r",bmp_file);
kanpapa 0:cd32c44c16f8 209 if ( read_bmp_mono(bmp_file, buffer, sizeof( buffer )) != 0) {
kanpapa 0:cd32c44c16f8 210 printf( "file open error when opening file \"%s\"\r\n", bmp_file);
kanpapa 0:cd32c44c16f8 211 return ( 1 );
kanpapa 0:cd32c44c16f8 212 }
kanpapa 0:cd32c44c16f8 213
kanpapa 0:cd32c44c16f8 214 //
kanpapa 0:cd32c44c16f8 215 // SET VRAM
kanpapa 0:cd32c44c16f8 216 //
kanpapa 0:cd32c44c16f8 217 const unsigned int bit[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
kanpapa 0:cd32c44c16f8 218
kanpapa 0:cd32c44c16f8 219 for (int y = 0; y < 5; y++){
kanpapa 0:cd32c44c16f8 220 unsigned int address = y;
kanpapa 0:cd32c44c16f8 221 for (int x = 0 ; x < 30 ; x++) {
kanpapa 0:cd32c44c16f8 222 int bufbit = 0; // buffer bit
kanpapa 0:cd32c44c16f8 223 for ( int z = 0; z < 8 ; z++) {
kanpapa 0:cd32c44c16f8 224 unsigned char d = 0; // vram data
kanpapa 0:cd32c44c16f8 225 int dbit = 0; // vram data bit
kanpapa 0:cd32c44c16f8 226 for ( int i = 0 ; i < 8 ; i++) {
kanpapa 0:cd32c44c16f8 227 //printf("buffer[%d]\r\n", 32 * (35 - (y * 8 + i)) + x );
kanpapa 0:cd32c44c16f8 228 if ((bit[bufbit] & buffer[32 * (35 - (y * 8 + i)) + x]) == 0){
kanpapa 0:cd32c44c16f8 229 d = d | bit[dbit];
kanpapa 0:cd32c44c16f8 230 }
kanpapa 0:cd32c44c16f8 231 dbit++;
kanpapa 0:cd32c44c16f8 232 }
kanpapa 0:cd32c44c16f8 233 bufbit++;
kanpapa 0:cd32c44c16f8 234
kanpapa 0:cd32c44c16f8 235 // write VRAM
kanpapa 0:cd32c44c16f8 236 //printf( "VRAM address: %04x Data: %02x\r\n", address, d);
kanpapa 0:cd32c44c16f8 237 vfd.set_write_read_address(address);
kanpapa 0:cd32c44c16f8 238 vfd.send_data(d);
kanpapa 0:cd32c44c16f8 239
kanpapa 0:cd32c44c16f8 240 address = address + 8;
kanpapa 0:cd32c44c16f8 241 }
kanpapa 0:cd32c44c16f8 242 }
kanpapa 0:cd32c44c16f8 243 }
kanpapa 0:cd32c44c16f8 244 return(0);
kanpapa 0:cd32c44c16f8 245 }
kanpapa 0:cd32c44c16f8 246
kanpapa 0:cd32c44c16f8 247 int main() {
kanpapa 0:cd32c44c16f8 248 const char* ext1 = ".bmp";
kanpapa 0:cd32c44c16f8 249 const char* ext2 = ".BMP";
kanpapa 0:cd32c44c16f8 250
kanpapa 0:cd32c44c16f8 251 // mono color bitmap
kanpapa 0:cd32c44c16f8 252 //const char *bmp_file[] = {"/local/kumamoto.bmp", "/local/narita.bmp"};
kanpapa 0:cd32c44c16f8 253 //const char *bmp_file[] = {"/sd/kumamoto.bmp", "/sd/narita.bmp"};
kanpapa 0:cd32c44c16f8 254
kanpapa 0:cd32c44c16f8 255 printf( "BMP file access sample\r\n");
kanpapa 0:cd32c44c16f8 256
kanpapa 0:cd32c44c16f8 257 vfd.cls();
kanpapa 0:cd32c44c16f8 258
kanpapa 0:cd32c44c16f8 259 vfd.luminance_adjustment(0x0f); // 100%
kanpapa 0:cd32c44c16f8 260
kanpapa 0:cd32c44c16f8 261 while(1) {
kanpapa 0:cd32c44c16f8 262 DIR *dir = opendir("/sd/");
kanpapa 0:cd32c44c16f8 263
kanpapa 0:cd32c44c16f8 264 struct dirent *dent;
kanpapa 0:cd32c44c16f8 265
kanpapa 0:cd32c44c16f8 266 if ( dir ) {
kanpapa 0:cd32c44c16f8 267 while( dent = readdir( dir ) ){
kanpapa 0:cd32c44c16f8 268 printf("%s\r\n", dent->d_name);
kanpapa 0:cd32c44c16f8 269 if (CheckExtention(dent->d_name, ext1) || CheckExtention(dent->d_name, ext2)) {
kanpapa 0:cd32c44c16f8 270 char file_name[256] = "/sd/";
kanpapa 0:cd32c44c16f8 271 strcat(file_name, dent->d_name);
kanpapa 0:cd32c44c16f8 272 int ret = display_bmp(file_name);
kanpapa 0:cd32c44c16f8 273
kanpapa 0:cd32c44c16f8 274 // wait
kanpapa 0:cd32c44c16f8 275 if (ret == 0){
kanpapa 0:cd32c44c16f8 276 wait(5);
kanpapa 0:cd32c44c16f8 277 vfd.cls();
kanpapa 0:cd32c44c16f8 278 wait(1);
kanpapa 0:cd32c44c16f8 279 }
kanpapa 0:cd32c44c16f8 280 }
kanpapa 0:cd32c44c16f8 281 }
kanpapa 0:cd32c44c16f8 282 } else {
kanpapa 0:cd32c44c16f8 283 printf("Filed to open directory\r\n");
kanpapa 0:cd32c44c16f8 284 return(1);
kanpapa 0:cd32c44c16f8 285 }
kanpapa 0:cd32c44c16f8 286 closedir( dir );
kanpapa 0:cd32c44c16f8 287 }
kanpapa 0:cd32c44c16f8 288 }