Commit fd073d2a authored by Vít Ramba's avatar Vít Ramba
Browse files

Changes to code, program now writes directly to LCD instead of buffer, CS

parent 003d8a47
......@@ -77,7 +77,8 @@ int main(void) {
setPoint(&newPoint, knobs.R, knobs.G);
// LCD draw
init_lcd_message(small_font, Gcolor16b.yellow, &font_winFreeSystem14x16);
init_lcd_message(small_font, Gcolor16b.yellow,
&font_winFreeSystem14x16, lcd_t);
setDrawColor(&color16b, &color64b, inf_time);
// The main code cycle
......
......@@ -8,8 +8,6 @@
#define LCD_HEIGHT 320 // Display height
#define DRAW_BORDER 255 // Border of the canvas
uint16_t text_field[LCD_WIDTH * LCD_HEIGHT]; // LCD buffer
/* 16 bit colors */
rgb_color_16b_t Gcolor16b =
{
......@@ -53,29 +51,21 @@ int get_width_of_char(font_descriptor_t *file_des, int ch_char) {
return ch_width;
}
/* Erase whole text field (buffer) to black (zero) */
void erase_text_field(void) {
for (int i = 0; i < LCD_WIDTH * LCD_HEIGHT; ++i)
{
text_field[i] = 0;
}
}
/* Colors pixels in field according to inputs */
void color_pixels(uint16_t pix_color, int start_pos, int block_size) {
void color_pixels(uint16_t pix_color, int start_pos, int block_size,
volatile uint16_t *lcd) {
for (int m = 0; m < block_size; ++m)
{
for (int k = 0; k < block_size; ++k)
{
text_field[start_pos + m * LCD_WIDTH + k] = pix_color;
lcd[start_pos + m * LCD_WIDTH + k] = pix_color;
}
}
}
/* Makes draw frame in field */
void make_draw_frame(uint16_t pix_color) {
void make_draw_frame(uint16_t pix_color, volatile uint16_t *lcd) {
int size_of_num = 1;
int side_num = DRAW_BORDER + 10;
......@@ -84,28 +74,29 @@ void make_draw_frame(uint16_t pix_color) {
int lower_line = x + 2;
for (int y = 0; y < x; ++y)
{
text_field[x + y * LCD_WIDTH] = pix_color;
lcd[x + y * LCD_WIDTH] = pix_color;
}
//horizontal line
for (int y = 0; y < x; ++y)
{
text_field[y + x * LCD_WIDTH] = pix_color;
lcd[y + x * LCD_WIDTH] = pix_color;
}
//draws numbers to the draw field
draw_line(size_of_num, 1, Gcolor16b.white, &font_winFreeSystem14x16,
side_num, "0");
side_num, "0", lcd);
draw_line(size_of_num, 127, Gcolor16b.white, &font_winFreeSystem14x16,
side_num, "127");
side_num, "127", lcd);
draw_line(size_of_num, lower_line, Gcolor16b.white,
&font_winFreeSystem14x16, side_num, "255");
&font_winFreeSystem14x16, side_num, "255", lcd);
draw_line(size_of_num, lower_line, Gcolor16b.white,
&font_winFreeSystem14x16, 2, "0");
&font_winFreeSystem14x16, 2, "0", lcd);
draw_line(size_of_num, lower_line, Gcolor16b.white,
&font_winFreeSystem14x16, 127, "127");
&font_winFreeSystem14x16, 127, "127", lcd);
}
/* Returns text length according to file descriptor */
int get_text_lenght(font_descriptor_t *file_des, int *text_size, char *str_text) {
int get_text_lenght(font_descriptor_t *file_des, int *text_size,
char *str_text) {
int ret = 0;
int lenght = 0;
......@@ -127,7 +118,7 @@ int get_text_lenght(font_descriptor_t *file_des, int *text_size, char *str_text)
/* Writes one character into the text field */
void write_character(int ch_size, int start, uint16_t char_color,
font_descriptor_t *file_des, char character,
int line_number) {
int line_number, volatile uint16_t *lcd) {
int char_width = get_width_of_char(file_des, character);
for (int i = 0; i < file_des->height; ++i)
......@@ -142,13 +133,15 @@ void write_character(int ch_size, int start, uint16_t char_color,
int start_idx = 0;
if (cond)
{
start_idx = start + (line_number + i * ch_size) * LCD_WIDTH + j * ch_size;
color_pixels(char_color, start_idx, ch_size);
start_idx = start + (line_number + i * ch_size) * LCD_WIDTH +
j * ch_size;
color_pixels(char_color, start_idx, ch_size, lcd);
}
else
{
start_idx = start + (line_number + i * ch_size) * LCD_WIDTH + j * ch_size;
color_pixels(0x0, start_idx, ch_size);
start_idx = start + (line_number + i * ch_size) * LCD_WIDTH +
j * ch_size;
color_pixels(0x0, start_idx, ch_size, lcd);
}
bit_mask = bit_mask >> 1;
}
......@@ -157,7 +150,8 @@ void write_character(int ch_size, int start, uint16_t char_color,
/* Writes one line of a string according to inputs */
void draw_line(int size_of_font, int line_number, uint16_t text_color,
font_descriptor_t *file_des, int idx, char *str_text) {
font_descriptor_t *file_des, int idx, char *str_text,
volatile uint16_t *lcd) {
int text_size = 0;
int str_lenght = get_text_lenght(file_des, &text_size, str_text);
......@@ -186,26 +180,16 @@ void draw_line(int size_of_font, int line_number, uint16_t text_color,
for (int j = 0; j < str_lenght; ++j)
{
write_character(size_of_font, index, text_color, file_des,
str_text[j], line_number);
str_text[j], line_number, lcd);
index = index + (get_width_of_char(file_des, str_text[j]) +
GAB) * size_of_font;
}
}
}
/* Redraws whole text field into the lcd */
void draw_to_lcd(void) {
volatile uint16_t *lcd_t = (typeof(lcd_t))LCD_FB_START;
for (int e = 0; e < LCD_WIDTH * LCD_HEIGHT; ++e)
{
lcd_t[e] = text_field[e];
}
}
/* Draws initialization message to lcd display */
void init_lcd_message(int size_of_font, uint16_t text_color,
font_descriptor_t *file_des) {
font_descriptor_t *file_des, volatile uint16_t *lcd) {
int bigger_font = 2;
int left_side = DRAW_BORDER + 40;
......@@ -217,39 +201,39 @@ void init_lcd_message(int size_of_font, uint16_t text_color,
print_str_on_terminal("I AM SLOW!\n");
//whole drawing of lcd screen
make_draw_frame(Gcolor16b.white);
draw_line(bigger_font, 1, text_color, file_des, left_side, " GRAFO");
make_draw_frame(Gcolor16b.white, lcd);
draw_line(bigger_font, 1, text_color, file_des, left_side, " GRAFO", lcd);
draw_line(size_of_font, 36, text_color, &font_winFreeSystem14x16,
left_side, " <-- DRAW SCREEN");
left_side, " <-- DRAW SCREEN", lcd);
draw_line(size_of_font, 56, text_color, &font_winFreeSystem14x16,
left_side, " PICK COLOR");
pick_color(size_of_font, text_color, file_des);
left_side, " PICK COLOR", lcd);
pick_color(size_of_font, text_color, file_des, lcd);
draw_line(size_of_font, 176, text_color, &font_winFreeSystem14x16,
left_side, " TYPE 'P' TO ERASE");
left_side, " TYPE 'P' TO ERASE", lcd);
draw_line(size_of_font, 196, text_color, &font_winFreeSystem14x16,
left_side, " TYPE 'Q' TO QUIT");
left_side, " TYPE 'Q' TO QUIT", lcd);
draw_line(size_of_font, 290, Gcolor16b.green, &font_winFreeSystem14x16,
middle, "BY: MATEJ KOPECKY AND VIT RAMBA");
draw_to_lcd();
middle, "BY: MATEJ KOPECKY AND VIT RAMBA", lcd);
//draw_to_lcd();
print_str_on_terminal("TYPE TO INPUT TO PICK COLOR!\n");
}
/* Draw color options to lcd */
void pick_color(int size_of_font, uint16_t text_color,
font_descriptor_t *file_des) {
font_descriptor_t *file_des, volatile uint16_t *lcd) {
//draws colors options
int left_side = DRAW_BORDER + 40;
draw_line(size_of_font, 76, Gcolor16b.red, &font_winFreeSystem14x16,
left_side, " 'R' - RED");
left_side, " 'R' - RED", lcd);
draw_line(size_of_font, 96, Gcolor16b.green, &font_winFreeSystem14x16,
left_side, " 'G' - GREEN");
left_side, " 'G' - GREEN", lcd);
draw_line(size_of_font, 116, Gcolor16b.blue, &font_winFreeSystem14x16,
left_side, " 'B' - BLUE");
left_side, " 'B' - BLUE", lcd);
draw_line(size_of_font, 136, Gcolor16b.yellow, &font_winFreeSystem14x16,
left_side, " 'Y' - YELLOW");
left_side, " 'Y' - YELLOW", lcd);
draw_line(size_of_font, 156, Gcolor16b.white, &font_winFreeSystem14x16,
left_side, " 'W' - WHITE");
left_side, " 'W' - WHITE", lcd);
}
/* Erases the whole lcd display */
......
......@@ -38,34 +38,26 @@ int get_width_of_char(font_descriptor_t *file_des, int ch_char);
//puts string into text field
void fill_line(int line_num, font_descriptor_t *fdes, char *text, uint16_t color, int font_size);
//erases whole test field
void erase_text_field(void);
//colors pixels by start and block size
void color_pixels(uint16_t pix_color, int start_pos, int block_size);
void color_pixels(uint16_t pix_color, int start_pos, int block_size, volatile uint16_t *lcd);
//get text lenght with file descriptor
int get_text_lenght(font_descriptor_t *file_des, int *size, char *text);
//write character to text field by given color and size
void write_character(int ch_size, int start, uint16_t char_color, font_descriptor_t *file_des, char character,
int line_number);
void write_character(int ch_size, int start, uint16_t char_color, font_descriptor_t *file_des, char character, int line_number, volatile uint16_t *lcd);
//draw whole line of characters
void draw_line(int size_of_font, int line_number, uint16_t text_color, font_descriptor_t *file_des, int idx,
char *str_text);
//draw whole text field to lcd display
void draw_to_lcd(void);
void draw_line(int size_of_font, int line_number, uint16_t text_color, font_descriptor_t *file_des, int idx, char *str_text, volatile uint16_t *lcd);
//input string and properites and write to lcd
void final_to_lcd(int size_of_font, int line_number, uint16_t text_color, font_descriptor_t *file_des, char *str_text);
//hello message at the start
void init_lcd_message(int size_of_font, uint16_t text_color, font_descriptor_t *file_des);
void init_lcd_message(int size_of_font, uint16_t text_color, font_descriptor_t *file_des, volatile uint16_t *lcd);
//pick color message
void pick_color(int size_of_font, uint16_t text_color, font_descriptor_t *file_des);
void pick_color(int size_of_font, uint16_t text_color, font_descriptor_t *file_des, volatile uint16_t *lcd);
//blacken the lcd
void black_the_lcd(void);
......@@ -74,6 +66,6 @@ void black_the_lcd(void);
void black_the_draw_frame(void);
//fcn to make the draw frame
void make_draw_frame(uint16_t pix_color);
void make_draw_frame(uint16_t pix_color, volatile uint16_t *lcd);
#endif
......@@ -15,9 +15,9 @@
#include "my_terminal.h"
#include "my_lcd_text.h"
//Gets one character from terminal input
volatile int terminalIn()
{
/* Gets one character from terminal input */
volatile int terminalIn() {
volatile int *state = (int *)(SERIAL_PORT_BASE + SERP_RX_ST_REG_o);
volatile int *data = (int *)(SERIAL_PORT_BASE + SERP_RX_DATA_REG_o);
while (*state != SERP_RX_ST_REG_READY_m)
......@@ -25,9 +25,9 @@ volatile int terminalIn()
return *data;
}
//Gets one character from terminal input but with a timeout
volatile int terminal_in_timeout(int wait_time)
{
/* Gets one character from terminal input but with a timeout */
volatile int terminal_in_timeout(int wait_time) {
volatile int *data = (int *)(SERIAL_PORT_BASE + SERP_RX_DATA_REG_o);
int i = 0;
while (i != wait_time)
......@@ -41,9 +41,9 @@ volatile int terminal_in_timeout(int wait_time)
return 0;
}
//Writes data to terminal output
void terminalOut(volatile int print)
{
/* Writes data to terminal output */
void terminalOut(volatile int print) {
volatile int *state = (int *)(SERIAL_PORT_BASE + SERP_TX_ST_REG_o);
volatile int *data = (int *)(SERIAL_PORT_BASE + SERP_TX_DATA_REG_o);
while (*state != SERP_TX_ST_REG_READY_m)
......@@ -51,18 +51,18 @@ void terminalOut(volatile int print)
*data = print;
}
//Write string to terminal output
void print_str_on_terminal(char *str)
{
/* Write string to terminal output */
void print_str_on_terminal(char *str) {
for (int i = 0; i < myStrLen(str); ++i)
{
terminalOut(str[i]);
}
}
//Returns length of a string
unsigned long myStrLen(const char *str)
{
/* Returns length of a string */
unsigned long myStrLen(const char *str) {
unsigned long ret = 0;
while (str && str[ret] != '\0')
{
......@@ -71,9 +71,9 @@ unsigned long myStrLen(const char *str)
return ret;
}
//Prints out vertical and horizontal coordinate from input
void print_coordinates(uint16_t x, uint16_t y)
{
/* Prints out vertical and horizontal coordinate from input */
void print_coordinates(uint16_t x, uint16_t y) {
print_str_on_terminal("Coord are: ");
char str_x[12];
char str_y[12];
......@@ -89,9 +89,9 @@ void print_coordinates(uint16_t x, uint16_t y)
print_str_on_terminal("\n");
}
//Converts number into string
char *my_int_to_str_convert(int number, char *outStr)
{
/* Converts number into string */
char *my_int_to_str_convert(int number, char *outStr) {
int str_len = 12;
char rev_str[12];
int num_len = 0;
......@@ -123,9 +123,9 @@ char *my_int_to_str_convert(int number, char *outStr)
return outStr;
}
//Prints number into terminal
void print_num_terminal(int num)
{
/* Prints number into terminal */
void print_num_terminal(int num) {
char str_x[12];
char *str_x_ptr = str_x;
str_x_ptr = my_int_to_str_convert(num, str_x_ptr);
......@@ -133,9 +133,9 @@ void print_num_terminal(int num)
print_str_on_terminal("\n");
}
//Gets color choice from terminal input with and without timeout
volatile int pick_color_trm(uint16_t *color16b, uint64_t *color64b, int wait_time)
{
/* Gets color choice from terminal input with and without timeout */
volatile int pick_color_trm(uint16_t *color16b, uint64_t *color64b, int wait_time) {
int start_wait = -1;
volatile int ret = -1;
if (wait_time == -1)
......@@ -200,3 +200,4 @@ volatile int pick_color_trm(uint16_t *color16b, uint64_t *color64b, int wait_tim
}
return ret;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment