static void disp_flush(lv_display_t * disp_drv, const lv_area_t * area, uint8_t * px_map)
{
int i = 0;
if(disp_flush_enabled)
{
uint16_t x , y;
for(y = area->y1; y <= area->y2; y++)
{
for(x = area->x1; x <= area->x2; x++)
{
//*(px_map) = 0xff - *(px_map);
lcd_current_working_buffer[(y * MY_DISP_HOR_RES) + x] = (*(px_map) << 8) | *(px_map + 1);
px_map += 2;
}
}
// printf("area = %d.\n" , (area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1));
// LVGL_Draw_G2d(area->x1 , area->y1 , area->x2 , area->y2 , px_map);
}
lv_display_flush_ready(disp_drv);
}
void lv_port_disp_init(void)
{
/*-------------------------
* Initialize your display
* -----------------------*/
disp_init();
/*------------------------------------
* Create a display and set a flush_cb
* -----------------------------------*/
lv_display_t * disp = lv_display_create(MY_DISP_HOR_RES, MY_DISP_VER_RES);
lv_display_set_flush_cb(disp, disp_flush);
/* Example 1
* One buffer for partial rendering*/
static lv_color_t buf_1_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/
lv_display_set_buffers(disp, buf_1_1, NULL, sizeof(buf_1_1), LV_DISPLAY_RENDER_MODE_PARTIAL);
// /* Example 2
// * Two buffers for partial rendering
// * In flush_cb DMA or similar hardware should be used to update the display in the background.*/
// static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10];
// static lv_color_t buf_2_2[MY_DISP_HOR_RES * 10];
// lv_display_set_buffers(disp, buf_2_1, buf_2_2, sizeof(buf_2_1), LV_DISPLAY_RENDER_MODE_PARTIAL);
// /* Example 3
// * Two buffers screen sized buffer for double buffering.
// * Both LV_DISPLAY_RENDER_MODE_DIRECT and LV_DISPLAY_RENDER_MODE_FULL works, see their comments*/
// static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES];
// static lv_color_t buf_3_2[MY_DISP_HOR_RES * MY_DISP_VER_RES];
// lv_display_set_buffers(disp, buf_3_1, buf_3_2, sizeof(buf_3_1), LV_DISPLAY_RENDER_MODE_DIRECT);
}
添加4个按钮:
void lv_example_button_1(void)
{
lv_obj_t *label;
dropdown_font = &lv_font_montserrat_22;
dropdown_width = 150;
btn1 = lv_button_create(lv_screen_active());
lv_obj_set_size(btn1, 200 , 50);
lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);
lv_obj_remove_flag(btn1, LV_OBJ_FLAG_PRESS_LOCK);
label = lv_label_create(btn1);
lv_label_set_text(label, "Button");
lv_obj_set_style_text_font(label, dropdown_font, LV_PART_MAIN);
lv_obj_set_width(label, dropdown_width);
lv_obj_center(label);
btn2 = lv_button_create(lv_screen_active());
lv_obj_set_size(btn2 , 200 , 50);
lv_obj_add_event_cb(btn2, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 40);
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_height(btn2, LV_SIZE_CONTENT);
label = lv_label_create(btn2);
lv_label_set_text(label, "Toggle");
lv_obj_set_style_text_font(label, dropdown_font, LV_PART_MAIN);
lv_obj_set_width(label, dropdown_width);
lv_obj_center(label);
btn3 = lv_button_create(lv_screen_active());
lv_obj_set_size(btn3, 200 , 50);
lv_obj_add_event_cb(btn3, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn3, LV_ALIGN_CENTER, 300, -40);
lv_obj_remove_flag(btn3, LV_OBJ_FLAG_PRESS_LOCK);
label = lv_label_create(btn3);
lv_label_set_text(label, "Button");
lv_obj_set_style_text_font(label, dropdown_font, LV_PART_MAIN);
lv_obj_set_width(label, dropdown_width);
lv_obj_center(label);
btn4 = lv_button_create(lv_screen_active());
lv_obj_set_size(btn4 , 200 , 50);
lv_obj_add_event_cb(btn4, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn4, LV_ALIGN_CENTER, 300 , 40);
lv_obj_add_flag(btn4, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_height(btn4, LV_SIZE_CONTENT);
label = lv_label_create(btn4);
lv_label_set_text(label, "Toggle");
lv_obj_set_style_text_font(label, dropdown_font, LV_PART_MAIN);
lv_obj_set_width(label, dropdown_width);
lv_obj_center(label);
}
extern uint8_t FT5426_Scan();
static void touchpad_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
{
static int32_t last_x = 0;
static int32_t last_y = 0;
FT5426_Scan();
if(touchpad_is_pressed())
{
touchpad_get_xy(&last_x, &last_y);
data->state = LV_INDEV_STATE_PR;
}
else {
data->state = LV_INDEV_STATE_REL;
}
/*Set the last pressed coordinates*/
data->point.x = last_x;
data->point.y = last_y;
}
extern uint16_t touch_x[5];
extern uint16_t touch_y[5];
extern uint16_t touch_sta;
#define TP_PRES_DOWN 0x8000
static bool touchpad_is_pressed(void)
{
if (touch_sta == 0xc001)
{
return true;
}
return false;
}
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
{
(*x) = touch_x[0];
(*y) = touch_y[0];
}
更多回帖