Display driver for Sharp's range of SPI-driven memory LCD's, leveraging the power of asynchronous transfers. Currently supports LS013B7DH03, but easily extendable to other models as well.

Dependents:   memLCD-Demo memLCD-Demo memLCD-Demo MemLCD-Temperature-Humidity-Demo ... more

Information

All examples in this repo are considered EXPERIMENTAL QUALITY, meaning this code has been created as one-off proof-of-concept and is suitable as a demonstration for experimental purposes only. This code will not be regularly maintained by Silicon Labs and there is no guarantee that these projects will work across all environments, SDK versions and hardware.

Memory LCD extension board

Caution

This library builds upon the asynchronous SPI interface provided by mbed, but not all platforms currently support this. So, make sure your platform is capable of asynchronous SPI (all Silicon Labs platforms are), otherwise you will get compiler errors!

Usage

The library is purposefully quite simple to use. To set it up, you initialize an SPI object and the required I/O pins, and call the library constructor with those. Make sure the display is powered on, enabled, and the inversion mode is set to external (EXTMODE is high).

setup

#define SCK     PD2
#define MOSI 	PD0

DigitalOut CS(PD3);
DigitalOut EXTCOM(PC4);

SPI displaySPI(MOSI, NC, SCK);
silabs::LS013B7DH03 display(&displaySPI, &CS, &EXTCOM);

You should also swap out the pin names for the relevant names on your platform.

After setup, you usually want to clear any static information left on the screen. To do that, you would call clearImmediate, and optionally provide a callback. The callback will get called when the clearing operation is complete and the display has been cleared. In this example, refreshCallback sets a global boolean 'refreshed' to true when called.

clearing the display

refreshed = false;
int result = display.clearImmediate(refreshCallback);
if(result == LS013B7DH03_OK) {
    while(refreshed == false) sleep();
} else {
    printf("Display error: %d", result);
}

Of course, instead of sleeping while the display is clearing, you could also just continue with the program, and check back whether the callback happened or not.

Then comes the fun part, actually writing stuff on the display! Since the display only supports one-way communication (i.e. you cannot read from it), it uses an internal frame buffer in RAM. So, to actually display something on the LCD, two steps need to happen: writing to the pixel buffer, and at the very end writing the pixel buffer to the LCD.

Pixelbuffer operations

The MemoryLCD library builds upon Simon Ford's TextDisplay library, which means you can use all of that functionality. Even printf is supported!

most important display operations

// Set one pixel at x=10, y=40 to the color White
display.pixel(10,40,White); 

// print "I love mbed" at the character position x=4, y=5
// i.e. starting on row 5, 4 characters from the left border
display.locate(4,5);
display.printf("I love mbed!");

// show a bitmap at a given location
// Constraints: bitmap is 8-bit, MSB first, 1 bit per pixel. Width, height and starting coordinates must be divisible by 8.
// This example: show a bitmap which is 128 pixels wide and high, and start at location 0,0.
display.showBMP(&mbed_logo, 128, 128, 0, 0);

//Draw a line (really a 1px wide rectangle) from (4,10) until (4,15)
display.fill(4, 10, 1, 5, White);

Updating the LCD

Updating the LCD (i.e. moving the framebuffer to the display) happens much the same way as clearing it: asynchronously. To start the update, you call update() on the display, optionally providing a callback to be called after the whole update has happened. In the example below, refreshCallback sets a global boolean 'refreshed' to true when called. Signature: void refreshCallback(void);

updating the display

refreshed = false;
int result = display.update(refreshCallback);
if(result == LS013B7DH03_OK) {
    while(refreshed == false) sleep();
} else {
    printf("Display error: %d", result);
}

Full example

example program

#include "LS013B7DH03.h"
#include "mbed_logo.h"
/******************** Define I/O *****************************/
DigitalOut myled(LED1);

#define SCK     PD2
#define MOSI 	PD0

DigitalOut CS(PD3);
DigitalOut EXTCOM(PC4);
DigitalOut EXTMODE(PD4);
DigitalOut DISP(PD5);

SPI displaySPI(MOSI, NC, SCK);
silabs::LS013B7DH03 display(&displaySPI, &CS, &EXTCOM);

/******************** Define Timers *****************************/

LowPowerTicker timeKeeping;

/***************** Define global variables **********************/
#define INIT_SECONDS		17600

volatile uint32_t prevSeconds = INIT_SECONDS, seconds = INIT_SECONDS;
volatile bool refreshed = false;

/***************** Define callback handlers *********************/
void secondsCallback(void);
void refreshCallback(void);

void secondsCallback(void) {
	seconds++;
}

/**
 * Callback for refresh completion
 */
void refreshCallback(void) {
	refreshed = true;
}

/*************************** MAIN *******************************/
int main() {
    // Enable the LCD
	EXTMODE = 1;
	DISP = 1;

	// Start generating the 1Hz call for keeping time
	timeKeeping.attach(&secondsCallback, 1.0f);

	// Reset the LCD to a blank state. (All white)
	refreshed = false;
	display.clearImmediate(refreshCallback);
	while(refreshed == false) sleep();

	printf("Initialization done! \n");

	// Apply mbed logo bitmap to the pixel buffer
	display.showBMP((uint8_t*)mbed_enabled_logo, 128, 128, 0, 0);
	display.printf("I like MBED!");

	// Push update to the display
	refreshed = false;
	display.update(refreshCallback);

	// Sleep while doing the transmit
	while(refreshed == false) sleep();

	// Go into clock mode
	while(1) {
		sleep();

		// In clock mode, only update once per second
		if(prevSeconds != seconds) {
			display.locate(4,15);
			display.printf("%02d:%02d:%02d", (seconds / 1200) % 24, (seconds / 60) % 60, seconds % 60);
			if(refreshed == true) {
				prevSeconds = seconds;
				refreshed = false;
				display.update(refreshCallback);
			}
		}
	}
}

Datasheet

Datasheet for the LCD (hosted by Mouser)

Committer:
Steven Cooreman
Date:
Wed Mar 18 10:57:16 2015 -0500
Revision:
0:a0faa86660d4
Child:
5:26851f9655cf
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Steven Cooreman 0:a0faa86660d4 1 /* mbed GraphicsDisplay Display Library Base Class
Steven Cooreman 0:a0faa86660d4 2 * Copyright (c) 2007-2009 sford
Steven Cooreman 0:a0faa86660d4 3 * Released under the MIT License: http://mbed.org/license/mit
Steven Cooreman 0:a0faa86660d4 4 */
Steven Cooreman 0:a0faa86660d4 5
Steven Cooreman 0:a0faa86660d4 6 #include "GraphicsDisplay.h"
Steven Cooreman 0:a0faa86660d4 7
Steven Cooreman 0:a0faa86660d4 8 const unsigned char FONT8x8[97][8] = {
Steven Cooreman 0:a0faa86660d4 9 {0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00}, // columns, rows, num_bytes_per_char
Steven Cooreman 0:a0faa86660d4 10 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // space 0x20
Steven Cooreman 0:a0faa86660d4 11 {0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00}, // !
Steven Cooreman 0:a0faa86660d4 12 {0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00}, // "
Steven Cooreman 0:a0faa86660d4 13 {0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00}, // #
Steven Cooreman 0:a0faa86660d4 14 {0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00}, // $
Steven Cooreman 0:a0faa86660d4 15 {0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00}, // %
Steven Cooreman 0:a0faa86660d4 16 {0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00}, // &
Steven Cooreman 0:a0faa86660d4 17 {0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00}, // '
Steven Cooreman 0:a0faa86660d4 18 {0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00}, // (
Steven Cooreman 0:a0faa86660d4 19 {0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00}, // )
Steven Cooreman 0:a0faa86660d4 20 {0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00}, // *
Steven Cooreman 0:a0faa86660d4 21 {0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00}, // +
Steven Cooreman 0:a0faa86660d4 22 {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30}, // ,
Steven Cooreman 0:a0faa86660d4 23 {0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00}, // -
Steven Cooreman 0:a0faa86660d4 24 {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00}, // .
Steven Cooreman 0:a0faa86660d4 25 {0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00}, // / (forward slash)
Steven Cooreman 0:a0faa86660d4 26 {0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00}, // 0 0x30
Steven Cooreman 0:a0faa86660d4 27 {0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00}, // 1
Steven Cooreman 0:a0faa86660d4 28 {0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00}, // 2
Steven Cooreman 0:a0faa86660d4 29 {0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00}, // 3
Steven Cooreman 0:a0faa86660d4 30 {0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00}, // 4
Steven Cooreman 0:a0faa86660d4 31 {0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00}, // 5
Steven Cooreman 0:a0faa86660d4 32 {0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00}, // 6
Steven Cooreman 0:a0faa86660d4 33 {0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00}, // 7
Steven Cooreman 0:a0faa86660d4 34 {0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00}, // 8
Steven Cooreman 0:a0faa86660d4 35 {0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00}, // 9
Steven Cooreman 0:a0faa86660d4 36 {0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00}, // :
Steven Cooreman 0:a0faa86660d4 37 {0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30}, // ;
Steven Cooreman 0:a0faa86660d4 38 {0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00}, // <
Steven Cooreman 0:a0faa86660d4 39 {0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00}, // =
Steven Cooreman 0:a0faa86660d4 40 {0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00}, // >
Steven Cooreman 0:a0faa86660d4 41 {0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00}, // ?
Steven Cooreman 0:a0faa86660d4 42 {0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00}, // @ 0x40
Steven Cooreman 0:a0faa86660d4 43 {0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00}, // A
Steven Cooreman 0:a0faa86660d4 44 {0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00}, // B
Steven Cooreman 0:a0faa86660d4 45 {0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00}, // C
Steven Cooreman 0:a0faa86660d4 46 {0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00}, // D
Steven Cooreman 0:a0faa86660d4 47 {0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00}, // E
Steven Cooreman 0:a0faa86660d4 48 {0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00}, // F
Steven Cooreman 0:a0faa86660d4 49 {0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00}, // G
Steven Cooreman 0:a0faa86660d4 50 {0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00}, // H
Steven Cooreman 0:a0faa86660d4 51 {0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00}, // I
Steven Cooreman 0:a0faa86660d4 52 {0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00}, // J
Steven Cooreman 0:a0faa86660d4 53 {0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00}, // K
Steven Cooreman 0:a0faa86660d4 54 {0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00}, // L
Steven Cooreman 0:a0faa86660d4 55 {0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00}, // M
Steven Cooreman 0:a0faa86660d4 56 {0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00}, // N
Steven Cooreman 0:a0faa86660d4 57 {0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00}, // O
Steven Cooreman 0:a0faa86660d4 58 {0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00}, // P 0x50
Steven Cooreman 0:a0faa86660d4 59 {0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00}, // Q
Steven Cooreman 0:a0faa86660d4 60 {0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00}, // R
Steven Cooreman 0:a0faa86660d4 61 {0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00}, // S
Steven Cooreman 0:a0faa86660d4 62 {0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00}, // T
Steven Cooreman 0:a0faa86660d4 63 {0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00}, // U
Steven Cooreman 0:a0faa86660d4 64 {0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00}, // V
Steven Cooreman 0:a0faa86660d4 65 {0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00}, // W
Steven Cooreman 0:a0faa86660d4 66 {0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00}, // X
Steven Cooreman 0:a0faa86660d4 67 {0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00}, // Y
Steven Cooreman 0:a0faa86660d4 68 {0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00}, // Z
Steven Cooreman 0:a0faa86660d4 69 {0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00}, // [
Steven Cooreman 0:a0faa86660d4 70 {0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00}, // \ (back slash)
Steven Cooreman 0:a0faa86660d4 71 {0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00}, // ]
Steven Cooreman 0:a0faa86660d4 72 {0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00}, // ^
Steven Cooreman 0:a0faa86660d4 73 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF}, // _
Steven Cooreman 0:a0faa86660d4 74 {0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00}, // ` 0x60
Steven Cooreman 0:a0faa86660d4 75 {0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00}, // a
Steven Cooreman 0:a0faa86660d4 76 {0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00}, // b
Steven Cooreman 0:a0faa86660d4 77 {0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00}, // c
Steven Cooreman 0:a0faa86660d4 78 {0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00}, // d
Steven Cooreman 0:a0faa86660d4 79 {0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00}, // e
Steven Cooreman 0:a0faa86660d4 80 {0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00}, // f
Steven Cooreman 0:a0faa86660d4 81 {0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C}, // g
Steven Cooreman 0:a0faa86660d4 82 {0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00}, // h
Steven Cooreman 0:a0faa86660d4 83 {0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00}, // i
Steven Cooreman 0:a0faa86660d4 84 {0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C}, // j
Steven Cooreman 0:a0faa86660d4 85 {0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00}, // k
Steven Cooreman 0:a0faa86660d4 86 {0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00}, // l
Steven Cooreman 0:a0faa86660d4 87 {0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00}, // m
Steven Cooreman 0:a0faa86660d4 88 {0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00}, // n
Steven Cooreman 0:a0faa86660d4 89 {0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00}, // o
Steven Cooreman 0:a0faa86660d4 90 {0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78}, // p
Steven Cooreman 0:a0faa86660d4 91 {0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F}, // q
Steven Cooreman 0:a0faa86660d4 92 {0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00}, // r
Steven Cooreman 0:a0faa86660d4 93 {0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00}, // s
Steven Cooreman 0:a0faa86660d4 94 {0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00}, // t
Steven Cooreman 0:a0faa86660d4 95 {0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00}, // u
Steven Cooreman 0:a0faa86660d4 96 {0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00}, // v
Steven Cooreman 0:a0faa86660d4 97 {0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00}, // w
Steven Cooreman 0:a0faa86660d4 98 {0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00}, // x
Steven Cooreman 0:a0faa86660d4 99 {0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C}, // y
Steven Cooreman 0:a0faa86660d4 100 {0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00}, // z
Steven Cooreman 0:a0faa86660d4 101 {0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00}, // {
Steven Cooreman 0:a0faa86660d4 102 {0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00}, // |
Steven Cooreman 0:a0faa86660d4 103 {0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00}, // }
Steven Cooreman 0:a0faa86660d4 104 {0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00}, // ~
Steven Cooreman 0:a0faa86660d4 105 {0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}}; // DEL
Steven Cooreman 0:a0faa86660d4 106
Steven Cooreman 0:a0faa86660d4 107 GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) {
Steven Cooreman 0:a0faa86660d4 108 foreground((uint16_t)Black);
Steven Cooreman 0:a0faa86660d4 109 background((uint16_t)White);
Steven Cooreman 0:a0faa86660d4 110 // current pixel location
Steven Cooreman 0:a0faa86660d4 111 _x = 0;
Steven Cooreman 0:a0faa86660d4 112 _y = 0;
Steven Cooreman 0:a0faa86660d4 113 // window settings
Steven Cooreman 0:a0faa86660d4 114 _x1 = 0;
Steven Cooreman 0:a0faa86660d4 115 _x2 = 0;
Steven Cooreman 0:a0faa86660d4 116 _y1 = 0;
Steven Cooreman 0:a0faa86660d4 117 _y2 = 0;
Steven Cooreman 0:a0faa86660d4 118 }
Steven Cooreman 0:a0faa86660d4 119
Steven Cooreman 0:a0faa86660d4 120 void GraphicsDisplay::character(int column, int row, int value) {
Steven Cooreman 0:a0faa86660d4 121 blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
Steven Cooreman 0:a0faa86660d4 122 }
Steven Cooreman 0:a0faa86660d4 123
Steven Cooreman 0:a0faa86660d4 124 void GraphicsDisplay::window(int x, int y, int w, int h) {
Steven Cooreman 0:a0faa86660d4 125 // current pixel location
Steven Cooreman 0:a0faa86660d4 126 _x = x;
Steven Cooreman 0:a0faa86660d4 127 _y = y;
Steven Cooreman 0:a0faa86660d4 128 // window settings
Steven Cooreman 0:a0faa86660d4 129 _x1 = x;
Steven Cooreman 0:a0faa86660d4 130 _x2 = x + w - 1;
Steven Cooreman 0:a0faa86660d4 131 _y1 = y;
Steven Cooreman 0:a0faa86660d4 132 _y2 = y + h - 1;
Steven Cooreman 0:a0faa86660d4 133 }
Steven Cooreman 0:a0faa86660d4 134
Steven Cooreman 0:a0faa86660d4 135 void GraphicsDisplay::putp(int colour) {
Steven Cooreman 0:a0faa86660d4 136 // put pixel at current pixel location
Steven Cooreman 0:a0faa86660d4 137 pixel(_x, _y, colour);
Steven Cooreman 0:a0faa86660d4 138 // update pixel location based on window settings
Steven Cooreman 0:a0faa86660d4 139 _x++;
Steven Cooreman 0:a0faa86660d4 140 if(_x > _x2) {
Steven Cooreman 0:a0faa86660d4 141 _x = _x1;
Steven Cooreman 0:a0faa86660d4 142 _y++;
Steven Cooreman 0:a0faa86660d4 143 if(_y > _y2) {
Steven Cooreman 0:a0faa86660d4 144 _y = _y1;
Steven Cooreman 0:a0faa86660d4 145 }
Steven Cooreman 0:a0faa86660d4 146 }
Steven Cooreman 0:a0faa86660d4 147 }
Steven Cooreman 0:a0faa86660d4 148
Steven Cooreman 0:a0faa86660d4 149 void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) {
Steven Cooreman 0:a0faa86660d4 150 window(x, y, w, h);
Steven Cooreman 0:a0faa86660d4 151 for(int i=0; i<w*h; i++) {
Steven Cooreman 0:a0faa86660d4 152 putp(colour);
Steven Cooreman 0:a0faa86660d4 153 }
Steven Cooreman 0:a0faa86660d4 154 }
Steven Cooreman 0:a0faa86660d4 155
Steven Cooreman 0:a0faa86660d4 156 void GraphicsDisplay::cls() {
Steven Cooreman 0:a0faa86660d4 157 fill(0, 0, width(), height(), _background);
Steven Cooreman 0:a0faa86660d4 158 }
Steven Cooreman 0:a0faa86660d4 159
Steven Cooreman 0:a0faa86660d4 160 void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) {
Steven Cooreman 0:a0faa86660d4 161 window(x, y, w, h);
Steven Cooreman 0:a0faa86660d4 162 for(int i=0; i<w*h; i++) {
Steven Cooreman 0:a0faa86660d4 163 putp(colour[i]);
Steven Cooreman 0:a0faa86660d4 164 }
Steven Cooreman 0:a0faa86660d4 165 }
Steven Cooreman 0:a0faa86660d4 166
Steven Cooreman 0:a0faa86660d4 167 void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) {
Steven Cooreman 0:a0faa86660d4 168 window(x, y, w, h);
Steven Cooreman 0:a0faa86660d4 169 for(int i = 0; i < w*h; i++) {
Steven Cooreman 0:a0faa86660d4 170 char byte = colour[i >> 3];
Steven Cooreman 0:a0faa86660d4 171 int offset = i & 0x7;
Steven Cooreman 0:a0faa86660d4 172 int c = ((byte << (offset)) & 0x80) ? _foreground : _background;
Steven Cooreman 0:a0faa86660d4 173 putp(c);
Steven Cooreman 0:a0faa86660d4 174 }
Steven Cooreman 0:a0faa86660d4 175 }
Steven Cooreman 0:a0faa86660d4 176
Steven Cooreman 0:a0faa86660d4 177 int GraphicsDisplay::columns() {
Steven Cooreman 0:a0faa86660d4 178 return width() / 8;
Steven Cooreman 0:a0faa86660d4 179 }
Steven Cooreman 0:a0faa86660d4 180
Steven Cooreman 0:a0faa86660d4 181 int GraphicsDisplay::rows() {
Steven Cooreman 0:a0faa86660d4 182 return height() / 8;
Steven Cooreman 0:a0faa86660d4 183 }
Steven Cooreman 0:a0faa86660d4 184