Description
DISCLAMER: I am so sorry for asking, I looked high and low for information in last 3 days to understand, but came up empty handed.
I am a lowly mechanical engineer and i am struggling to understand how to go from my “count” variable to display it on the screen. I need help since i am not getting anywhere. My last UI i made before i switched to stm32 was hard coded and i had easy control of everything but its tedious to code. I need help to understand how to integrate my inputs to the UI (assume I am a coding noob). I know i am supposed to add events to UI elements, but there are a lot of options and i am overwhelmed.
What MCU/Processor/Board and compiler are you using?
i am using a stm32h723vt6 with a parallel interface ssd1963 with FMC. I am using cubeIDE and eez studio. Currently using LVGL version 9.xx.
What do you want to achieve?
Understand how to integrate physical inputs to display elements. For now just to get a box on the display to display the rotary encoder count.
What have you tried so far?
I have read the documentation (lv_indev) and i did the initialization of with the 3 lines of code and wrote a separate function for the encoder (encoder code was running inside a encoder timer call back). Currently stuck here.
Code to reproduce
Add the relevant code snippets here.
The code block(s) should be between ```c
and ```
tags:
//basic testing code before using LVGL
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
/* Prevent unused argument(s) compilation warning */
count=(TIM2->CNT)/2;
LCD_Rect_Fill(0, 0, 800, 480, BLACK);
LCD_Rect_Fill(0, 0, count, 480, 0xff900c3e);
char temp[5];
sprintf(temp,"%d",count);
LCD_Font(5, 100,temp , _16_Segment_16_Full, 2, YELLOW);
if(count>60)
{
LCD_Font(100, 120, "what now?", _9_Serif_Bold, 4, YELLOW);
}
}
// LVGL setup.
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
count=(TIM2->CNT)/2;
}
void encoder_read(lv_indev_t * indev, lv_indev_data_t * data){
data->enc_diff = count;
if(enc_pressed()) data->state = LV_INDEV_STATE_PRESSED;
else data->state = LV_INDEV_STATE_RELEASED;
}
void my_flush_cb(lv_display_t * display, const lv_area_t * area, uint8_t * px_map)
{
/* The most simple case (also the slowest) to send all rendered pixels to the
* screen one-by-one. `put_px` is just an example. It needs to be implemented by you. */
LCD_Window(area->y1, area->x1, area->y2, area->x2);
uint16_t * buf16 = (uint16_t *)px_map; /* Let's say it's a 16 bit (RGB565) display */
int32_t x, y;
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
LCD_Send_Dat(*buf16);
buf16++;
}
}
/* IMPORTANT!!!
* Inform LVGL that flushing is complete so buffer can be modified again. */
lv_display_flush_ready(display);
}
int main(void)
{
MPU_Config();
SCB_EnableICache();
SCB_EnableDCache();
HAL_Init();
SystemClock_Config();
PeriphCommonClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_FMC_Init();
MX_OCTOSPI1_Init();
MX_SPI1_Init();
MX_CORDIC_Init();
MX_FMAC_Init();
MX_DMA2D_Init();
MX_TIM2_Init();
/* Initialize interrupts */
MX_NVIC_Init();
LCD_Init();
lv_init();
lv_tick_set_cb(HAL_GetTick);
lv_display_t * display1 = lv_display_create(800, 480);
lv_display_set_buffers(display1, buf1, NULL, sizeof(buf1),
LV_DISPLAY_RENDER_MODE_PARTIAL);
lv_display_set_flush_cb(display1, my_flush_cb);
ui_init();
lv_indev_t * indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_ENCODER);
lv_indev_set_read_cb(indev, my_input_read);
HAL_TIM_Encoder_Start_IT(&htim2, TIM_CHANNEL_ALL);
while (1)
{
uint32_t time_till_next = lv_timer_handler();
HAL_Delay(time_till_next);
}
}
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.