From: Robin Krens Date: Fri, 20 Sep 2019 09:08:00 +0000 (+0700) Subject: st7735s: documentation, ready for merge X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=477bfb951a2b6c1c14e31cace4363fd14d891308;p=cortex-from-scratch st7735s: documentation, ready for merge --- diff --git a/README.md b/README.md index d891e3c..1463117 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ port this code to any Cortex M0/M3/M4/M7 board. * Temperature sensor: drivers/tsensor.c [COMPLETED] * OLED display [PLANNED] * Joystick: drivers/mk450_joystick.c [COMPLETED] - * TFT Screen: [PLANNED] + * TFT Screen: drivers/st7735s.c, include/libs/fonts/wogfont.h [IN PROGRESS] * Memory Management [IN PROGRESS] -- FILE: lib/pool.c * User Mode [PLANNED] * System Call PendV implementation [PLANNED] @@ -39,9 +39,13 @@ port this code to any Cortex M0/M3/M4/M7 board. * Multiple processes and scheduling [PLANNED] ## SCREENSHOTS -Here is a screenshot that shows the terminal just after booting: +Here are some screenshots that shows the terminal just after booting: -![Screenshot](https://github.com/robinkrens/cortex-from-scratch/raw/master/img/screenshot.png "screenshot") +* Serial (over UART) +![Screenshot](https://github.com/robinkrens/cortex-from-scratch/raw/master/img/serial.png "serial terminal screenshot") + +* TFT screen output (SPI): +![Screenshot](https://github.com/robinkrens/cortex-from-scratch/raw/master/img/tft.png "tft peripheral screenshot") diff --git a/drivers/st7735s.c b/drivers/st7735s.c index c99156f..a3c7117 100644 --- a/drivers/st7735s.c +++ b/drivers/st7735s.c @@ -5,8 +5,19 @@ * Initial version * * $DESCRIPTION$ + * Basic driver for the ST7735s TFT screen. Initializes the screen + * Low-level commands can be called by tft_command. See header (.h) + * file for an overview of all commands. tft_command can accepts + * an unlimited amount of data or parameter commands. * * $USAGE$ + * I added the following functionality: + * a. tft_fill: fills a certain area of the screen + * b. tft_setpixel: sets a single pixel + * c. tft_putc, tft_put: outputs a char/string to the screen, starts + * at the upper top right and tracks the position. If the screen is + * full, it 'scrolls' automatically. So you basically have a mini + * sized terminal. You can link standard output to this function! * * */ @@ -35,6 +46,7 @@ #define YPOS(y) (y * 8) #define BUFFER 352 + static struct { uint16_t cpos; uint8_t * textmemptr; @@ -188,6 +200,7 @@ tft_command(TFT_RAMWR, 2, (uint8_t) (color >> 8), (uint8_t) (color & 0xFF)); } +/* Basic puts function that loops over a string */ int tft_puts(char * str) { for (int i = 0; i < strlen(str); i++) { @@ -197,6 +210,8 @@ int tft_puts(char * str) { } +/* Used by scroll function to overwrite and clear the last + * line on the screen */ void tft_clrln() { tft_puts(" "); @@ -211,26 +226,20 @@ int tft_scroll() { /* Scroll the buffer */ memcpy(tftscreen.textmemptr, tftscreen.textmemptr + 21, BUFFER - 21); - //for (int i = 21; i >= 0; i--) tftscreen.buf[BUFFER - 21] = '\0'; tftscreen.x = 0; tftscreen.y = 0; tftscreen.cpos = 0; - //for (int i = 0; i < 320; i++) { - // uart_putc(tftscreen.buf[i]); - //} - tft_puts(tftscreen.buf); // CHECK: ending - //tftscreen.y = 14; - //tft_puts(" "); tftscreen.y = 14; tftscreen.x = 0; tftscreen.cpos = BUFFER - 21; - // DINOSAUR tft_clrln(); } +/* Fills a line with blank characters, returns to + * the next line */ void tft_nl() { uint8_t blanks = 21 - tftscreen.x; @@ -246,19 +255,11 @@ void tft_nl() { * Should not be used directly */ int tft_putc(uint16_t fg, uint16_t bg, int c) { - int totalpixels = 35; int column = 0; int row = 0; uint8_t current; - - //if ((c == '\n') && (tftscreen.y == 14)) { - // tft_nl(); - // tft_scroll2(); - // return 1; - //} - if (c == '\n') { if (tftscreen.y == 14) { tft_nl(); @@ -270,20 +271,9 @@ int tft_putc(uint16_t fg, uint16_t bg, int c) { return 1; } } - //// else { - //// tft_putc(0xFFFF, 0x0000, 'o'); - //// } - // //else { - // // ENDFLAG = true; - // //} - //} if (tftscreen.y >= 15) { tft_scroll(); - //if (ENDFLAG) { - // ENDFLAG = false; - // return 1; - //} } tft_command(TFT_CASET, 4, 0x00, STARTX + XPOS(tftscreen.x), 0x00, (STARTX + 4) + XPOS(tftscreen.x)); diff --git a/img/screenshot.png b/img/screenshot.png deleted file mode 100644 index d2823f7..0000000 Binary files a/img/screenshot.png and /dev/null differ diff --git a/img/serial.png b/img/serial.png new file mode 100644 index 0000000..d2823f7 Binary files /dev/null and b/img/serial.png differ diff --git a/img/tft.png b/img/tft.png new file mode 100644 index 0000000..cb83eea Binary files /dev/null and b/img/tft.png differ diff --git a/include/lib/fonts/wogfont.h b/include/lib/fonts/wogfont.h index 28cb942..45f13c8 100644 --- a/include/lib/fonts/wogfont.h +++ b/include/lib/fonts/wogfont.h @@ -5,9 +5,30 @@ * Initial version * * $DESCRIPTION$ - * The classic wogfont is back! - * Designed by Robin Krens - * 5 by 7 bit font (lower case) + * A non-standard 5 by 7 bit font (ALL CHARs ARE UPPER CASE) + * Some characters I haven't designed yet, these will display + * a'█' on a VGA or TFT screen. A character is column hex-coded. + * + * An example to make things clear! + * The letter 'S's bitmap is: + * + * WIDTH = 5 + * ##### L + * #___# E + * #____ N + * ##### G + * ____# T + * #___# H + * ##### = 7 + * + * # represents a selected bit, 1 + * _ represents a non selected bit, 0 + * + * For example, the first column is 1111101, the second columm 1001001 + * For hex encoding we start at the MSB, the first LSB is never used + * The first column is 0xF6 and the second column 0x92. The letter 'S' + * equals to: 0xF6, 0x92, 0x92, 0x92, 0xDE, + * * */ const uint8_t ASCII5x7[] = {