* 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!
*
* */
#include <lib/tinyprintf.h>
#include <lib/fonts/wogfont.h>
+#include <drivers/uart.h>
#include <drivers/st7735s.h>
#define TIMEOUT 500
#define YPOS(y) (y * 8)
#define BUFFER 352
+
static struct {
uint16_t cpos;
uint8_t * textmemptr;
}
+/* Basic puts function that loops over a string */
int tft_puts(char * str) {
for (int i = 0; i < strlen(str); i++) {
}
+/* Used by scroll function to overwrite and clear the last
+ * line on the screen */
void tft_clrln() {
tft_puts(" ");
/* Scroll the buffer */
memcpy(tftscreen.textmemptr, tftscreen.textmemptr + 21, BUFFER - 21);
- for (int i = 21; i >= 0; i--)
- tftscreen.buf[BUFFER - 21] = '\0';
+ tftscreen.buf[BUFFER - 21] = '\0';
tftscreen.x = 0;
tftscreen.y = 0;
tftscreen.cpos = 0;
-
+
tft_puts(tftscreen.buf); // CHECK: ending
- tft_clrln();
+ tftscreen.y = 14;
+ tftscreen.x = 0;
+ tftscreen.cpos = BUFFER - 21;
}
-void tft_linefill() {
+/* Fills a line with blank characters, returns to
+ * the next line */
+void tft_nl() {
+
+ uint8_t blanks = 21 - tftscreen.x;
- // TODO
+ // filler with blank spaces
+ for (int i = 0; i < blanks; i++) {
+ tft_putc(0xFFFF, 0x0000, ' ');
+ }
}
* 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') {
+ if (tftscreen.y == 14) {
+ tft_nl();
+ return 1;
+ }
+ else {
+ tft_nl();
+ //if (tftscreen.y < 15)
+ return 1;
+ }
+ }
+
if (tftscreen.y >= 15) {
tft_scroll();
}