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

Changes to main.c

parent 55364ae8
......@@ -40,86 +40,34 @@
#include "my_lcd_text.h"
#include "font_types.h"
//getting extern structs
/* Getting extern structs */
rgb_color_16b_t Gcolor16b;
font_descriptor_t font_winFreeSystem14x16;
//struct for knobs
typedef struct
{
/* Struct for knobs */
typedef struct {
uint8_t R;
uint8_t G;
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);
knobs->B = 0xFF & *knobs_ptr;
knobs->G = 0xFF & (*knobs_ptr >> 8);
knobs->R = 0xFF & (*knobs_ptr >> 16);
}
//pointer for drawing
typedef struct
{
/* 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;
*(volatile uint32_t *)(mem_base + SPILED_REG_LED_RGB1_o) = 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;
int ji = newPoint->y > oldPoint->y ? 1 : -1;
int i = 0;
int j = 0;
if (oldPoint->x + i != newPoint->x)
{
i += ii;
}
if (oldPoint->y + j != newPoint->y)
{
j += ji;
}
lcd[(oldPoint->y + j) * LCD_WIDTH + (oldPoint->x + i)] = color_16b;
oldPoint->x += i;
oldPoint->y += j;
}
//changes draw color and led color
int set_draw_color(uint16_t *color16b, uint64_t *color64b, int 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()
{
/* My functions */
void loadKnobs(volatile knobs_t *knobs);
void setPoint(point_t *newPoint, uint16_t x, uint16_t y);
void show_color_on_led(uint64_t color);
void drawPoint(point_t *oldPoint, point_t *newPoint,
volatile uint16_t *lcd, uint16_t color_16b);
int setDrawColor(uint16_t *color16b, uint64_t *color64b, int wait_time);
/* The main function */
int main(void) {
//inicialization
int small_font = 1;
int wait_time = 100; //number of cycles to wait
......@@ -139,7 +87,7 @@ int main()
//LCD draw
init_lcd_message(small_font, Gcolor16b.yellow, &font_winFreeSystem14x16);
set_draw_color(&color16b, &color64b, inf_time);
setDrawColor(&color16b, &color64b, inf_time);
//the main code cycle
int print_c = 0;
......@@ -149,7 +97,7 @@ int main()
loadKnobs(knobs);
setPoint(&newPoint, knobs->R, knobs->G);
drawPoint(&oldPoint, &newPoint, lcd_t, color16b);
i_break = set_draw_color(&color16b, &color64b, wait_time);
i_break = setDrawColor(&color16b, &color64b, wait_time);
//end of code
if(i_break == 1)
......@@ -170,3 +118,64 @@ int main()
}
return 0;
}
/* Getting knobs values */
void loadKnobs(volatile knobs_t *knobs) {
volatile uint32_t *knobs_ptr = (uint32_t *)(SPILED_REG_BASE
+ SPILED_REG_KNOBS_8BIT_o);
knobs->B = 0xFF & *knobs_ptr;
knobs->G = 0xFF & (*knobs_ptr >> 8);
knobs->R = 0xFF & (*knobs_ptr >> 16);
}
/* 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;
*(volatile uint32_t *)(mem_base + SPILED_REG_LED_RGB1_o) = 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;
int ji = newPoint->y > oldPoint->y ? 1 : -1;
int i = 0;
int j = 0;
if (oldPoint->x + i != newPoint->x)
{
i += ii;
}
if (oldPoint->y + j != newPoint->y)
{
j += ji;
}
lcd[(oldPoint->y + j) * LCD_WIDTH + (oldPoint->x + i)] = color_16b;
oldPoint->x += i;
oldPoint->y += j;
}
/* Changes draw color and led color */
int setDrawColor(uint16_t *color16b, uint64_t *color64b, int 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;
}
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