File content as of revision 0:601fd83c75e0:
#include "doggy.h"
DogMLCD::DogMLCD( SPI& spi, PinName cs, PinName a0 ) : spi_(spi), cs_(cs), a0_(a0)
{
b_ = (char*)calloc( 1024, 1 );
XFont = xfont_8;
const unsigned char c[] = {
0x40, // display start line + 0-63
0xa1, // ADC set 0xA1 + 0 = normal (for reverse view) / +1 = reverse (for normal view)
0xc0, // common output mode + 0 = normal / + 0xF reverse
0xa6, // dispaly mode 0xA6 + 0 = normal / 1 = reverse
0xa2, // set bias 0xa20 + 0 = 1/9 / +1 = 1/7
0x2f, // power control: 4 booster on + 2 regulator on + 1 follower on
0xf8, 0x00, // set booster ratio , value 0=4x, 1=5x, 2=6x
0x27, // set voltage regulator (0x20) to 7
0x81, 0x14, // set electronic volume , value
0xac, 0x00, // static indicator set 0xAC +0 = off / +1 = on , 0 = flash mode
0xaf // display 0xAE +0 = off / +1 = on
};
spi_.format( 8, 0 );
spi_.frequency( 1000000 );
cs_ = 0;
a0_ = 0;
for( int i = 0 ; i < sizeof( c ); i++ )
spi_.write( c[i] );
cs_ = 1;
}
DogMLCD::~DogMLCD()
{
free( b_ );
}
#define FASTPOKE( x, y ) b_[ ( ( y & 56 ) << 4 ) + ( x & 127 ) ] |= DOGMLCD_on[ y & 7 ];
#define FASTWIPE( x, y ) b_[ ( ( y & 56 ) << 4 ) + ( x & 127 ) ] |= DOGMLCD_off[ y & 7 ];
#define FASTINV( x, y ) b_[ ( ( y & 56 ) << 4 ) + ( x & 127 ) ] ^= DOGMLCD_on[ y & 7 ];
void DogMLCD::Poke( int x, int y )
{
if( ( x & 0xFF80 ) == 0 && ( y & 0xFFC0 ) == 0 )
FASTPOKE( x, y )
}
void DogMLCD::Wipe( int x, int y )
{
if( ( x & 0xFF80 ) == 0 && ( y & 0xFFC0 ) == 0 )
FASTWIPE( x, y )
}
void DogMLCD::Inv( int x, int y )
{
if( ( x & 0xFF80 ) == 0 && ( y & 0xFFC0 ) == 0 )
FASTINV( x, y )
}
void DogMLCD::Clear()
{
int i = 1024;
char* p = b_;
while( i-- )
*p++ = 0;
}
void DogMLCD::Flush()
{
char* p = b_;
spi_.format( 8, 0 );
spi_.frequency( DOGMLCD_MHZ );
for( int page = 0xB0 ; page < 0xB8 ; page++ )
{
cs_ = 0;
a0_ = 0;
spi_.write( page ); spi_.write( 0x10 ); spi_.write( 0x00 );
a0_ = 1;
int i = 128;
while( i-- )
spi_.write( *p++ );
a0_ = 0;
}
cs_ = 1;
}