Commit 8077b27d authored by Matěj Kopecký's avatar Matěj Kopecký
Browse files

Added comments and quit code

parent 9b795d4b
......@@ -7,7 +7,7 @@
# void print_str_on_terminal(char *str)
* Write string to terminal output
# unsigned long myStrLen(const char *str)
* Return length of a string
* Returns length of a string
# void print_coordinates(uint16_t x, uint16_t y)
* Prints out vertical and horizontal coordinate from input
# char *my_int_to_str_convert(int number, char *outStr)
......
//defining all the adressses
#define SERIAL_PORT_BASE 0xffffc000
#define SERP_RX_ST_REG_o 0x00
......@@ -27,33 +28,23 @@
#define LCD_FB_START 0xffe00000
#define LCD_FB_END 0xffe4afff
//display properities
#define LCD_WIDTH 480
#define LCD_HEIGHT 320
#define X_K (480 / 255)
#define Y_K (320 / 255)
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "my_terminal.h"
#include "my_lcd_text.h"
#include "font_types.h"
//getting extern structs
rgb_color_16b_t Gcolor16b;
font_descriptor_t font_winFreeSystem14x16;
/*struct px_t
{
unsigned R : 5;
unsigned G : 6;
unsigned B : 5;
} __attribute((packed)) __;
typedef struct px_t px;*/
//struct for knobs
typedef struct
{
uint8_t R;
......@@ -61,6 +52,7 @@ typedef struct
uint8_t B;
} knobs_t;
//getting knobs values
void loadKnobs(volatile knobs_t *knobs)
{
volatile uint32_t *knobs_ptr = (uint32_t *)(SPILED_REG_BASE + SPILED_REG_KNOBS_8BIT_o);
......@@ -69,18 +61,21 @@ void loadKnobs(volatile knobs_t *knobs)
knobs->R = 0xFF & (*knobs_ptr >> 16);
}
//pointer for drawing
typedef struct
{
uint16_t x;
uint16_t y;
} point_t;
//setting new point
void setPoint(point_t *newPoint, uint16_t x, uint16_t y)
{
newPoint->x = x;
newPoint->y = y;
}
//changes color of leds
void show_color_on_led(uint64_t color)
{
unsigned char *mem_base = (unsigned char *)SPILED_REG_BASE;
......@@ -88,6 +83,7 @@ void show_color_on_led(uint64_t color)
*(volatile uint32_t *)(mem_base + SPILED_REG_LED_RGB2_o) = color;
}
//draws new point
void drawPoint(point_t *oldPoint, point_t *newPoint, volatile uint16_t *lcd, uint16_t color_16b)
{
int ii = newPoint->x > oldPoint->x ? 1 : -1;
......@@ -108,15 +104,23 @@ void drawPoint(point_t *oldPoint, point_t *newPoint, volatile uint16_t *lcd, uin
oldPoint->y += j;
}
void set_draw_color(uint16_t *color16b, uint64_t *color64b, int wait_time)
//changes draw color and led color
int set_draw_color(uint16_t *color16b, uint64_t *color64b, int wait_time)
{
pick_color_trm(color16b, color64b, wait_time);
int ret = 0;
ret = pick_color_trm(color16b, color64b, wait_time);
if (ret == 'q')
{
return 1;
}
show_color_on_led(*color64b);
return 0;
}
//main of the code
int main()
{
{
//inicialization
int small_font = 1;
int wait_time = 100; //number of cycles to wait
int inf_time = -1;
......@@ -132,15 +136,30 @@ int main()
setPoint(&oldPoint, knobs->R, knobs->G);
point_t newPoint;
setPoint(&newPoint, knobs->R, knobs->G);
//LCD draw
init_lcd_message(small_font, Gcolor16b.yellow, &font_winFreeSystem14x16);
set_draw_color(&color16b, &color64b, inf_time);
//the main code cycle
int print_c = 0;
int i_break = 0;
while (1)
{
{
loadKnobs(knobs);
setPoint(&newPoint, knobs->R, knobs->G);
drawPoint(&oldPoint, &newPoint, lcd_t, color16b);
set_draw_color(&color16b, &color64b, wait_time);
i_break = set_draw_color(&color16b, &color64b, wait_time);
//end of code
if(i_break == 1)
{
print_str_on_terminal("YOU QUITED THE GAME\n");
print_str_on_terminal("BYE BYE\n");
break;
}
//print of coordinates and info
if (print_c % 100 == 0)
{
print_coordinates(newPoint.x, newPoint.y);
......
......@@ -3,14 +3,18 @@
#define LCD_FB_START 0xffe00000
#define LCD_FB_END 0xffe4afff
#define GAB 2
//gab between two characters, size two
#define GAB 2
//display properities
#define LCD_WIDTH 480
#define LCD_HEIGHT 320
//border of the draw field
#define DRAW_BORDER 255
//lcd buffer
uint16_t text_field[LCD_WIDTH * LCD_HEIGHT];
//16 bites colors
rgb_color_16b_t Gcolor16b =
{
.red = 0xF800,
......@@ -21,6 +25,7 @@ rgb_color_16b_t Gcolor16b =
.yellow = 0xFF00,
};
//64 bites colors
rgb_color_64b_t Gcolor64b =
{
.red = 0xFF0000,
......@@ -31,6 +36,7 @@ rgb_color_64b_t Gcolor64b =
.yellow = 0xFFFF00,
};
//Function for getting the width of a char from a fond for lcd display
int get_width_of_char(font_descriptor_t *file_des, int ch_char)
{
int ch_width = 0;
......@@ -51,6 +57,7 @@ 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)
......@@ -59,6 +66,7 @@ void erase_text_field(void)
}
}
//Colors pixels in field according to inputs
void color_pixels(uint16_t pix_color, int start_pos, int block_size)
{
for (int m = 0; m < block_size; ++m)
......@@ -70,6 +78,7 @@ void color_pixels(uint16_t pix_color, int start_pos, int block_size)
}
}
//Makes draw frame in field
void make_draw_frame(uint16_t pix_color)
{
int size_of_num = 1;
......@@ -86,6 +95,7 @@ void make_draw_frame(uint16_t pix_color)
{
text_field[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");
draw_line(size_of_num, 127, Gcolor16b.white, &font_winFreeSystem14x16, side_num, "127");
draw_line(size_of_num, lower_line, Gcolor16b.white, &font_winFreeSystem14x16, side_num, "255");
......@@ -93,6 +103,7 @@ void make_draw_frame(uint16_t pix_color)
draw_line(size_of_num, lower_line, Gcolor16b.white, &font_winFreeSystem14x16, 127, "127");
}
//Returns text length according to file descriptor
int get_text_lenght(font_descriptor_t *file_des, int *text_size, char *str_text)
{
int ret = 0;
......@@ -112,6 +123,7 @@ int get_text_lenght(font_descriptor_t *file_des, int *text_size, char *str_text)
return ret;
}
//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)
{
......@@ -141,6 +153,7 @@ void write_character(int ch_size, int start, uint16_t char_color, font_descripto
}
}
//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)
{
......@@ -175,6 +188,7 @@ void draw_line(int size_of_font, int line_number, uint16_t text_color, font_desc
}
}
//Redraws whole text field into the lcd
void draw_to_lcd(void)
{
volatile uint16_t *lcd_t = (typeof(lcd_t))LCD_FB_START;
......@@ -184,29 +198,35 @@ void draw_to_lcd(void)
}
}
//Draws initialization message to lcd display
void init_lcd_message(int size_of_font, uint16_t text_color, font_descriptor_t *file_des)
{
int bigger_font = 2;
int left_side = DRAW_BORDER + 40;
int middle = -1;
//first messages
print_str_on_terminal("HELLO!\n");
print_str_on_terminal("WAIT FOR LCD TO LOAD!\n");
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");
draw_line(size_of_font, 36, text_color, &font_winFreeSystem14x16, left_side, " <-- DRAW SCREEN");
draw_line(size_of_font, 56, text_color, &font_winFreeSystem14x16, left_side, " PICK COLOR");
pick_color(size_of_font, text_color, file_des);
draw_line(size_of_font, 176, text_color, &font_winFreeSystem14x16, left_side, " TYPE 'P' TO ERASE");
//tady to nekompiluje
draw_line(size_of_font, 196, text_color, &font_winFreeSystem14x16, left_side, " TYPE 'Q' TO QUIT");
draw_line(size_of_font, 290, Gcolor16b.green, &font_winFreeSystem14x16, middle, "BY: MATEJ KOPECKY AND VIT RAMBA");
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)
{
{
//draws colors options
int left_side = DRAW_BORDER + 40;
draw_line(size_of_font, 76, Gcolor16b.red, &font_winFreeSystem14x16, left_side, " 'R' - RED");
draw_line(size_of_font, 96, Gcolor16b.green, &font_winFreeSystem14x16, left_side, " 'G' - GREEN");
......@@ -215,6 +235,7 @@ void pick_color(int size_of_font, uint16_t text_color, font_descriptor_t *file_d
draw_line(size_of_font, 156, Gcolor16b.white, &font_winFreeSystem14x16, left_side, " 'W' - WHITE");
}
//Erases the whole lcd display
void black_the_lcd(void)
{
print_str_on_terminal("WAIT FOR BLACK SCREEN!\n");
......@@ -226,6 +247,7 @@ void black_the_lcd(void)
print_str_on_terminal("READY TO DRAW!\n");
}
//Erases just the draw frame for new drawing
void black_the_draw_frame(void)
{
int block_size = DRAW_BORDER;
......
//defining all the adresses
#define SERIAL_PORT_BASE 0xffffc000
#define SERP_RX_ST_REG_o 0x00
......@@ -16,6 +17,7 @@
#include "my_terminal.h"
#include "my_lcd_text.h"
//Gets one character from terminal input
volatile int terminalIn()
{
volatile int *state = (int *)(SERIAL_PORT_BASE + SERP_RX_ST_REG_o);
......@@ -25,7 +27,8 @@ volatile int terminalIn()
return *data;
}
volatile int my_terminalIn(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;
......@@ -40,6 +43,7 @@ volatile int my_terminalIn(int wait_time)
return 0;
}
//Writes data to terminal output
void terminalOut(volatile int print)
{
volatile int *state = (int *)(SERIAL_PORT_BASE + SERP_TX_ST_REG_o);
......@@ -49,6 +53,7 @@ void terminalOut(volatile int print)
*data = print;
}
//Write string to terminal output
void print_str_on_terminal(char *str)
{
for (int i = 0; i < myStrLen(str); ++i)
......@@ -57,6 +62,7 @@ void print_str_on_terminal(char *str)
}
}
//Returns length of a string
unsigned long myStrLen(const char *str)
{
unsigned long ret = 0;
......@@ -67,6 +73,7 @@ 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)
{
print_str_on_terminal("Coord are: ");
......@@ -84,6 +91,7 @@ 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)
{
int str_len = 12;
......@@ -117,6 +125,7 @@ char *my_int_to_str_convert(int number, char *outStr)
return outStr;
}
//Prints number into terminal
void print_num_terminal(int num)
{
char str_x[12];
......@@ -126,6 +135,7 @@ 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)
{
int start_wait = -1;
......@@ -136,7 +146,7 @@ volatile int pick_color_trm(uint16_t *color16b, uint64_t *color64b, int wait_tim
}
else
{
ret = my_terminalIn(wait_time);
ret = terminal_in_timeout(wait_time);
}
switch (ret)
{
......@@ -179,12 +189,13 @@ volatile int pick_color_trm(uint16_t *color16b, uint64_t *color64b, int wait_tim
}
break;
case 'q':
print_str_on_terminal("STOP THE CODE TO QUIT\n");
//quiting the code
break;
default:
print_str_on_terminal("TRY STARTING LETTER OF SOME COLOR\n");
if (wait_time == -1)
{
{
//chosing color at the start
ret = pick_color_trm(color16b, color64b, start_wait);
}
break;
......
#ifndef __MY_TERMINAL__
#define __MY_TERMINAL__
//Gets one character from terminal input
volatile int terminalIn();
volatile int my_terminalIn(int wait_time);
//Gets one character from terminal input but with a timeout
volatile int terminal_in_timeout(int wait_time);
//Writes data to terminal output
void terminalOut(volatile int print);
//Write string to terminal output
void print_str_on_terminal(char *str);
//Returns length of a string
unsigned long myStrLen(const char *str);
//Prints out vertical and horizontal coordinate from input
void print_coordinates(uint16_t x, uint16_t y);
//Converts number into string
char *my_int_to_str_convert(int number, char *outStr);
//Prints number into terminal
void print_num_terminal(int num);
//Gets color choice from terminal input with and without timeout
volatile int pick_color_trm(uint16_t *color16b, uint64_t *color64b, int wait_time);
#endif
\ No newline at end of file
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