Versión de Firmware con funciones de RAM incorporadas.

Dependencies:   mbed

Fork of VmRecorderV1dot1 by virtualmech

Committer:
JuanManuelAmador
Date:
Tue Jul 14 08:34:11 2015 +0000
Revision:
2:e818c80e6d5c
Parent:
0:3d456b8ce449
Funciones de memoria RAM introducidas.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JuanManuelAmador 0:3d456b8ce449 1 #include "doggy.h"
JuanManuelAmador 0:3d456b8ce449 2
JuanManuelAmador 0:3d456b8ce449 3 DogMLCD::DogMLCD( SPI& spi, PinName cs, PinName a0 ) : spi_(spi), cs_(cs), a0_(a0)
JuanManuelAmador 0:3d456b8ce449 4 {
JuanManuelAmador 0:3d456b8ce449 5 //b_ = (char*)calloc( 1024, 1 );
JuanManuelAmador 0:3d456b8ce449 6 XFont = xfont_8;
JuanManuelAmador 0:3d456b8ce449 7 b_ = w_;
JuanManuelAmador 0:3d456b8ce449 8 Clear();
JuanManuelAmador 0:3d456b8ce449 9 const unsigned char c[] = {
JuanManuelAmador 0:3d456b8ce449 10 0x40, // display start line + 0-63
JuanManuelAmador 0:3d456b8ce449 11 0xa1, // ADC set 0xA1 + 0 = normal (for reverse view) / +1 = reverse (for normal view)
JuanManuelAmador 0:3d456b8ce449 12 0xc0, // common output mode + 0 = normal / + 0xF reverse
JuanManuelAmador 0:3d456b8ce449 13 0xa6, // dispaly mode 0xA6 + 0 = normal / 1 = reverse
JuanManuelAmador 0:3d456b8ce449 14 0xa2, // set bias 0xa20 + 0 = 1/9 / +1 = 1/7
JuanManuelAmador 0:3d456b8ce449 15 0x2f, // power control: 4 booster on + 2 regulator on + 1 follower on
JuanManuelAmador 0:3d456b8ce449 16 0xf8, 0x00, // set booster ratio , value 0=4x, 1=5x, 2=6x
JuanManuelAmador 0:3d456b8ce449 17 0x27, // set voltage regulator (0x20) to 7
JuanManuelAmador 0:3d456b8ce449 18 0x81, 0x18, // set electronic volume , value
JuanManuelAmador 0:3d456b8ce449 19 0xac, 0x00, // static indicator set 0xAC +0 = off / +1 = on , 0 = flash mode
JuanManuelAmador 0:3d456b8ce449 20 0xaf // display 0xAE +0 = off / +1 = on
JuanManuelAmador 0:3d456b8ce449 21 };
JuanManuelAmador 0:3d456b8ce449 22
JuanManuelAmador 0:3d456b8ce449 23 spi_.format( 8, 0 );
JuanManuelAmador 0:3d456b8ce449 24 spi_.frequency( 1000000 );
JuanManuelAmador 0:3d456b8ce449 25 cs_ = 0;
JuanManuelAmador 0:3d456b8ce449 26 a0_ = 0; wait_us( DOGMLCD_TIME );
JuanManuelAmador 0:3d456b8ce449 27 for( int i = 0 ; i < sizeof( c ); i++ )
JuanManuelAmador 0:3d456b8ce449 28 spi_.write( c[i] );
JuanManuelAmador 0:3d456b8ce449 29 cs_ = 1;
JuanManuelAmador 0:3d456b8ce449 30 }
JuanManuelAmador 0:3d456b8ce449 31
JuanManuelAmador 0:3d456b8ce449 32 void DogMLCD::AttachScreen( char* screen )
JuanManuelAmador 0:3d456b8ce449 33 {
JuanManuelAmador 0:3d456b8ce449 34 b_ = screen;
JuanManuelAmador 0:3d456b8ce449 35 }
JuanManuelAmador 0:3d456b8ce449 36
JuanManuelAmador 0:3d456b8ce449 37 void DogMLCD::DetachScreen()
JuanManuelAmador 0:3d456b8ce449 38 {
JuanManuelAmador 0:3d456b8ce449 39 b_ = w_;
JuanManuelAmador 0:3d456b8ce449 40 }
JuanManuelAmador 0:3d456b8ce449 41
JuanManuelAmador 0:3d456b8ce449 42 #define FASTPOKE( x, y ) b_[ ( ( y & 56 ) << 4 ) + ( x & 127 ) ] |= DOGMLCD_on[ y & 7 ];
JuanManuelAmador 0:3d456b8ce449 43 #define FASTWIPE( x, y ) b_[ ( ( y & 56 ) << 4 ) + ( x & 127 ) ] &= DOGMLCD_off[ y & 7 ];
JuanManuelAmador 0:3d456b8ce449 44 #define FASTINV( x, y ) b_[ ( ( y & 56 ) << 4 ) + ( x & 127 ) ] ^= DOGMLCD_on[ y & 7 ];
JuanManuelAmador 0:3d456b8ce449 45
JuanManuelAmador 0:3d456b8ce449 46
JuanManuelAmador 0:3d456b8ce449 47 void DogMLCD::Poke( int x, int y )
JuanManuelAmador 0:3d456b8ce449 48 {
JuanManuelAmador 0:3d456b8ce449 49 if( ( x & 0xFF80 ) == 0 && ( y & 0xFFC0 ) == 0 )
JuanManuelAmador 0:3d456b8ce449 50 FASTPOKE( x, y )
JuanManuelAmador 0:3d456b8ce449 51 }
JuanManuelAmador 0:3d456b8ce449 52 void DogMLCD::Wipe( int x, int y )
JuanManuelAmador 0:3d456b8ce449 53 {
JuanManuelAmador 0:3d456b8ce449 54 if( ( x & 0xFF80 ) == 0 && ( y & 0xFFC0 ) == 0 )
JuanManuelAmador 0:3d456b8ce449 55 FASTWIPE( x, y )
JuanManuelAmador 0:3d456b8ce449 56 }
JuanManuelAmador 0:3d456b8ce449 57 void DogMLCD::Inv( int x, int y )
JuanManuelAmador 0:3d456b8ce449 58 {
JuanManuelAmador 0:3d456b8ce449 59 if( ( x & 0xFF80 ) == 0 && ( y & 0xFFC0 ) == 0 )
JuanManuelAmador 0:3d456b8ce449 60 FASTINV( x, y )
JuanManuelAmador 0:3d456b8ce449 61 }
JuanManuelAmador 0:3d456b8ce449 62
JuanManuelAmador 0:3d456b8ce449 63 void DogMLCD::InvRect( int x0, int y0, int x1, int y1 )
JuanManuelAmador 0:3d456b8ce449 64 {
JuanManuelAmador 0:3d456b8ce449 65 for(int i = y0; i < y1 + 1; i++){
JuanManuelAmador 0:3d456b8ce449 66 for(int j = x0; j < x1 + 1; j++){
JuanManuelAmador 0:3d456b8ce449 67 Inv(j,i);
JuanManuelAmador 0:3d456b8ce449 68 }
JuanManuelAmador 0:3d456b8ce449 69 }
JuanManuelAmador 0:3d456b8ce449 70 }
JuanManuelAmador 0:3d456b8ce449 71 void DogMLCD::Clear()
JuanManuelAmador 0:3d456b8ce449 72 {
JuanManuelAmador 0:3d456b8ce449 73 int i = 1024;
JuanManuelAmador 0:3d456b8ce449 74 char* p = b_;
JuanManuelAmador 0:3d456b8ce449 75 while( i-- )
JuanManuelAmador 0:3d456b8ce449 76 *p++ = 0;
JuanManuelAmador 0:3d456b8ce449 77 }
JuanManuelAmador 0:3d456b8ce449 78 void DogMLCD::Flush()
JuanManuelAmador 0:3d456b8ce449 79 {
JuanManuelAmador 0:3d456b8ce449 80 char* p = b_;
JuanManuelAmador 0:3d456b8ce449 81 spi_.format( 8, 0 );
JuanManuelAmador 0:3d456b8ce449 82 spi_.frequency( DOGMLCD_MHZ );
JuanManuelAmador 0:3d456b8ce449 83 cs_ = 0;
JuanManuelAmador 0:3d456b8ce449 84 for( int page = 0xB0 ; page < 0xB8 ; page++ )
JuanManuelAmador 0:3d456b8ce449 85 {
JuanManuelAmador 0:3d456b8ce449 86 a0_ = 0; wait_us( DOGMLCD_TIME );
JuanManuelAmador 0:3d456b8ce449 87 spi_.write( page ); spi_.write( 0x10 ); spi_.write( 0x00 );
JuanManuelAmador 0:3d456b8ce449 88
JuanManuelAmador 0:3d456b8ce449 89 a0_ = 1; wait_us( DOGMLCD_TIME );
JuanManuelAmador 0:3d456b8ce449 90 int i = 128;
JuanManuelAmador 0:3d456b8ce449 91 while( i-- )
JuanManuelAmador 0:3d456b8ce449 92 spi_.write( *p++ );
JuanManuelAmador 0:3d456b8ce449 93 }
JuanManuelAmador 0:3d456b8ce449 94 cs_ = 1;
JuanManuelAmador 0:3d456b8ce449 95 }
JuanManuelAmador 0:3d456b8ce449 96 void DogMLCD::Flush( unsigned char page, int x0, int x1 )
JuanManuelAmador 0:3d456b8ce449 97 {
JuanManuelAmador 0:3d456b8ce449 98 page &= 7;
JuanManuelAmador 0:3d456b8ce449 99 BOUND( x0, 0, 127 );
JuanManuelAmador 0:3d456b8ce449 100 BOUND( x1, 0, 127 );
JuanManuelAmador 0:3d456b8ce449 101 ORDER( x0 , x1 )
JuanManuelAmador 0:3d456b8ce449 102 char* p = b_ + ( page << 7 ) + x0;
JuanManuelAmador 0:3d456b8ce449 103 spi_.format( 8, 0 );
JuanManuelAmador 0:3d456b8ce449 104 spi_.frequency( DOGMLCD_MHZ );
JuanManuelAmador 0:3d456b8ce449 105 cs_ = 0;
JuanManuelAmador 0:3d456b8ce449 106 a0_ = 0; wait_us( DOGMLCD_TIME );
JuanManuelAmador 0:3d456b8ce449 107 spi_.write( 0xB0 + page ); spi_.write( 0x10 ); spi_.write( 0x00 );
JuanManuelAmador 0:3d456b8ce449 108
JuanManuelAmador 0:3d456b8ce449 109 a0_ = 1; wait_us( DOGMLCD_TIME );
JuanManuelAmador 0:3d456b8ce449 110 int i = x1 - x0 + 1;
JuanManuelAmador 0:3d456b8ce449 111 while( i-- )
JuanManuelAmador 0:3d456b8ce449 112 spi_.write( *p++ );
JuanManuelAmador 0:3d456b8ce449 113 cs_ = 1;
JuanManuelAmador 0:3d456b8ce449 114 }
JuanManuelAmador 0:3d456b8ce449 115 void DogMLCD::Page( unsigned char page0, unsigned char page1 )
JuanManuelAmador 0:3d456b8ce449 116 {
JuanManuelAmador 0:3d456b8ce449 117 page0 &= 7;
JuanManuelAmador 0:3d456b8ce449 118 if( page1 == 0 ) page1 = page0;
JuanManuelAmador 0:3d456b8ce449 119 else
JuanManuelAmador 0:3d456b8ce449 120 {
JuanManuelAmador 0:3d456b8ce449 121 page1 &= 7;
JuanManuelAmador 0:3d456b8ce449 122 ORDER( page0, page1 );
JuanManuelAmador 0:3d456b8ce449 123 }
JuanManuelAmador 0:3d456b8ce449 124 char* p = b_ + ( page0 << 7 );
JuanManuelAmador 0:3d456b8ce449 125 spi_.format( 8, 0 );
JuanManuelAmador 0:3d456b8ce449 126 spi_.frequency( DOGMLCD_MHZ );
JuanManuelAmador 0:3d456b8ce449 127 cs_ = 0;
JuanManuelAmador 0:3d456b8ce449 128 for( int page = 0xB0 + page0 ; page <= ( 0xB0 + page1 ) ; page++ )
JuanManuelAmador 0:3d456b8ce449 129 {
JuanManuelAmador 0:3d456b8ce449 130 a0_ = 0; wait_us( DOGMLCD_TIME );
JuanManuelAmador 0:3d456b8ce449 131 spi_.write( page ); spi_.write( 0x10 ); spi_.write( 0x00 );
JuanManuelAmador 0:3d456b8ce449 132
JuanManuelAmador 0:3d456b8ce449 133 a0_ = 1; wait_us( DOGMLCD_TIME );
JuanManuelAmador 0:3d456b8ce449 134 int i = 128;
JuanManuelAmador 0:3d456b8ce449 135 while( i-- )
JuanManuelAmador 0:3d456b8ce449 136 spi_.write( *p++ );
JuanManuelAmador 0:3d456b8ce449 137 }
JuanManuelAmador 0:3d456b8ce449 138 cs_ = 1;
JuanManuelAmador 0:3d456b8ce449 139 }
JuanManuelAmador 0:3d456b8ce449 140 void DogMLCD::Paste( char* screen, doggy_op op )
JuanManuelAmador 0:3d456b8ce449 141 {
JuanManuelAmador 0:3d456b8ce449 142 int i = 1024;
JuanManuelAmador 0:3d456b8ce449 143 char* p = b_;
JuanManuelAmador 0:3d456b8ce449 144 char* q = screen;
JuanManuelAmador 0:3d456b8ce449 145
JuanManuelAmador 0:3d456b8ce449 146 if( op == poke ) while( i-- ) *p++ |= *q++;
JuanManuelAmador 0:3d456b8ce449 147 else if( op == wipe ) while( i-- ) *p++ &= ~(*q++);
JuanManuelAmador 0:3d456b8ce449 148 else while( i-- ) *p++ ^= *q++;
JuanManuelAmador 0:3d456b8ce449 149 }
JuanManuelAmador 0:3d456b8ce449 150
JuanManuelAmador 0:3d456b8ce449 151
JuanManuelAmador 0:3d456b8ce449 152