Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SPI_TFT by
Diff: SPI_TFT.cpp
- Revision:
- 6:fc33e4a5713e
- Parent:
- 5:2db1b8070d94
- Child:
- 7:4781bb8eed45
--- a/SPI_TFT.cpp Sat Jul 30 22:15:35 2011 +0000
+++ b/SPI_TFT.cpp Wed Aug 31 20:51:14 2011 +0000
@@ -9,6 +9,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+
+
+// fix bmp padding for Bitmap function
+
#include "SPI_TFT.h"
#include "mbed.h"
@@ -534,10 +538,9 @@
-void SPI_TFT::locate(int column, int row) {
- _column = column;
- char_x = font[1] * column; // get the horz. size of the actual font
- _row = row;
+void SPI_TFT::locate(int x, int y) {
+ char_x = x;
+ char_y = y;
}
@@ -555,24 +558,22 @@
int SPI_TFT::_putc(int value) {
- if (value == '\n') {
- _column = 0;
+ if (value == '\n') { // new line
char_x = 0;
- _row++;
- if (_row >= rows()) {
- _row = 0;
+ char_y = char_y + font[2];
+ if (char_y >= height() - font[2]) {
+ char_y = 0;
}
} else {
- character(_column, _row, value);
- _column++;
- }
+ character(char_x, char_y, value);
+ }
return value;
}
-void SPI_TFT::character(int col, int row, int c) {
+void SPI_TFT::character(int x, int y, int c) {
unsigned int hor,vert,offset,bpl,j,i,b;
unsigned char* zeichen;
unsigned char z,w;
@@ -587,16 +588,13 @@
if (char_x + hor > width()) {
char_x = 0;
- _column = 0;
- _row ++;
- row++;
- if (_row >= rows()) {
- _row = 0;
- row=0;
+ char_y = char_y + vert;
+ if (char_y >= height() - font[2]) {
+ char_y = 0;
}
}
- window(char_x, row * vert,hor,vert); // char box
+ window(char_x, char_y,hor,vert); // char box
wr_cmd(0x22);
wr_dat_start();
zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
@@ -632,19 +630,26 @@
void SPI_TFT::Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap) {
- unsigned int i,j;
+ unsigned int i,j,padd;
unsigned short *bitmap_ptr = (unsigned short *)bitmap;
+ // the lines are padded to multiple of 4 bytes in a bitmap
+ padd = -1;
+ do {
+ padd ++;
+ } while (2*(w + padd)%4 != 0);
window(x, y, w, h);
wr_cmd(0x22);
wr_dat_start();
_spi.format(16,3);
- bitmap_ptr += ((h - 1)*w);
+ bitmap_ptr += ((h - 1)* (w + padd));
+ //bitmap_ptr -= padd;
for (j = 0; j < h; j++) { //Lines
for (i = 0; i < w; i++) { // copy pixel data to TFT
_spi.write(*bitmap_ptr); // one line
bitmap_ptr++;
}
bitmap_ptr -= 2*w;
+ bitmap_ptr -= padd;
}
_spi.format(8,3);
wr_dat_stop();
