سلام وقت بخیر
تشکر از سایت سیسوگ و دوستان فعال
کدی رو برای برد sinux f1 نوشتم با lcd و touch هم پورتش کردم و راه اندازی میشه الان میخوام با استفاده از کتابخونه های اموزش bare metal پورت uart رو راه اندازی کنم روی برد چند تا سوال دارم
یک : کتابخونه رو ایمپورت میکنم ولی در قسمت کامپایل کتابخونه ها با دستور make کامپایل نمیشن و خطای undifined میگیرم (احتمالا از فایل make) باید باشه که دوستان اگر میشه راهنمایی کنند.
دو : شدنی هست آیا یا خیر باید به صورت bare metal بنویسم از اول؟
کد main هم به این شکله:
#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "lvgl/src/misc/lv_style.h"
#include "lvgl/examples/lv_examples.h"
#include "f1c100s_uart.h"
#include "f1c100s_clock.h"
#include "f1c100s_periph.h"
#define DISP_BUF_SIZE (128 * 1024)
// Array to hold text options
const char* status[] = {"PLAY", "PAUSE"};
const char* status1[] = {"NEXT", "NEXT"};
// Counter variable made global
uint8_t cnt = 1;
static void hal_init(void);
static int tick_thread(void *data);
static lv_obj_t * label2;
static void btn_event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * btn = lv_event_get_target(e);
if(code == LV_EVENT_CLICKED) {
static uint8_t cnt = 0;
cnt++;
/*Get the first child of the button which is the label and change its text*/
lv_obj_t * label = lv_obj_get_child(btn, 0);
lv_label_set_text_fmt(label, "Button: %d", cnt);
}
}
static void btn_event_cb1(lv_event_t * e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * btn1 = lv_event_get_target(e);
if(code == LV_EVENT_CLICKED) {
// Get label
lv_obj_t * label1 = lv_obj_get_child(btn1, 0);
lv_label_set_text(label1, status[cnt]);
cnt++;
// Wrap around cnt to stay in range
if(cnt > 1) {
cnt = 0;
}
}
}
static void btn_event_cb2(lv_event_t * e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * btn1 = lv_event_get_target(e);
if(code == LV_EVENT_CLICKED) {
// Get label
lv_obj_t * label1 = lv_obj_get_child(btn1, 0);
lv_label_set_text(label1, status1[cnt]);
// Increment cnt
cnt++;
// Wrap around cnt to stay in range
if(cnt > 1) {
cnt = 0;
}
}
}
static lv_indev_drv_t indev_drv;
int main(void)
{
/*LittlevGL init*/
lv_init();
/*Linux frame buffer device init*/
fbdev_init();
/*A small buffer for LittlevGL to draw the screen's content*/
static lv_color_t buf[DISP_BUF_SIZE];
/*Initialize a descriptor for the buffer*/
static lv_disp_draw_buf_t disp_buf;
lv_disp_draw_buf_init(&disp_buf, buf, NULL, DISP_BUF_SIZE);
/*Initialize and register a display driver*/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &disp_buf;
disp_drv.flush_cb = fbdev_flush;
disp_drv.hor_res = 480;
disp_drv.ver_res = 272;
lv_disp_drv_register(&disp_drv);
/* Linux input device init */
evdev_init();
// Register input device driver
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = evdev_read;
lv_indev_t * indev_touch = lv_indev_drv_register(&indev_drv);
lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/
lv_obj_set_pos(btn, 110,150); /*Set its position*/
lv_obj_set_size(btn, 80, 50); /*Set its size*/
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/
lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/
lv_label_set_text(label, "PREVIOUS"); /*Set the labels text*/
lv_obj_center(label);
lv_obj_t * btn1= lv_btn_create(lv_scr_act()); /*Add a button the current screen*/
lv_obj_set_pos(btn1,210,150); /*Set its position*/
lv_obj_set_size(btn1,80,50); /*Set its size*/
lv_obj_add_event_cb(btn1,btn_event_cb1, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/
lv_obj_t * label1= lv_label_create(btn1); /*Add a label to the button*/
lv_label_set_text(label1, "PLAY"); /*Set the labels text*/
lv_obj_center(label1);
// Link the input device to the button
lv_indev_set_button_points(indev_touch, &btn1->coords);
lv_obj_t * btn2= lv_btn_create(lv_scr_act()); /*Add a button the current screen*/
lv_obj_set_pos(btn2,310,150); /*Set its position*/
lv_obj_set_size(btn2,80,50); /*Set its size*/
lv_obj_add_event_cb(btn2,btn_event_cb2, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/
lv_obj_t * label2= lv_label_create(btn2); /*Add a label to the button*/
lv_label_set_text(label2, "NEXT"); /*Set the labels text*/
lv_obj_center(label2);
lv_obj_t *label_2 = lv_label_create(lv_scr_act());
lv_label_set_long_mode(label_2, LV_LABEL_LONG_SCROLL_CIRCULAR); /*Circular scroll*/
lv_obj_set_width(label_2, 300);
lv_label_set_recolor(label_2, true);
lv_label_set_text(label_2, "#000000 THIS IS A TEST FOR THE FUTURE#");
lv_obj_align(label_2, LV_ALIGN_CENTER, 0, 120);
while (1)
{
lv_tick_inc(5);
lv_task_handler();
usleep(5000);
}
return 0;
}