pkarashchenko commented on code in PR #1341: URL: https://github.com/apache/incubator-nuttx-apps/pull/1341#discussion_r992691070
########## graphics/lvgl/port/lv_port_button.c: ########## @@ -0,0 +1,237 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_button.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <nuttx/input/buttons.h> +#include "lv_port_button.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BUTTON_0_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_0_MAP_X +#define BUTTON_0_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_0_MAP_Y +#define BUTTON_1_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_1_MAP_X +#define BUTTON_1_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_1_MAP_Y +#define BUTTON_2_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_2_MAP_X +#define BUTTON_2_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_2_MAP_Y +#define BUTTON_3_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_3_MAP_X +#define BUTTON_3_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_3_MAP_Y +#define BUTTON_4_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_4_MAP_X +#define BUTTON_4_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_4_MAP_Y +#define BUTTON_5_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_5_MAP_X +#define BUTTON_5_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_5_MAP_Y + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct button_obj_s +{ + int fd; + uint8_t last_btn; + lv_indev_drv_t indev_drv; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Assign buttons to points on the screen */ + +static const lv_point_t g_button_points_map[6] = +{ + {BUTTON_0_MAP_X, BUTTON_0_MAP_Y}, + {BUTTON_1_MAP_X, BUTTON_1_MAP_Y}, + {BUTTON_2_MAP_X, BUTTON_2_MAP_Y}, + {BUTTON_3_MAP_X, BUTTON_3_MAP_Y}, + {BUTTON_4_MAP_X, BUTTON_4_MAP_Y}, + {BUTTON_5_MAP_X, BUTTON_5_MAP_Y} +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: button_get_pressed_id + ****************************************************************************/ + +static int button_get_pressed_id(int fd) +{ + int btn_act = -1; + btn_buttonset_t buttonset; + const int buttonset_bits = sizeof(btn_buttonset_t) * 8; + int bit; + + int ret = read(fd, &buttonset, sizeof(btn_buttonset_t)); + if (ret < 0) + { + return -1; + } + + for (bit = 0; bit < buttonset_bits; bit++) + { + btn_buttonset_t mask = 1 << bit; + + if (buttonset & mask) Review Comment: ```suggestion if (buttonset & mask != 0) ``` ########## graphics/lvgl/Makefile: ########## @@ -25,32 +25,67 @@ include $(APPDIR)/Make.defs LVGL_DIR = . LVGL_DIR_NAME = lvgl -# Relax format check for LVGL to avoid errors on prinf() use +# Relax LVGL's format checking and unused variable checking to avoid errors -CFLAGS += -Wno-format +CFLAGS += -Wno-format -Wno-unused-variable -# LVGL Libraries +-include ./lvgl/lvgl.mk --include ./lvgl/src/lv_core/lv_core.mk --include ./lvgl/src/lv_hal/lv_hal.mk --include ./lvgl/src/lv_widgets/lv_widgets.mk --include ./lvgl/src/lv_font/lv_font.mk --include ./lvgl/src/lv_misc/lv_misc.mk --include ./lvgl/src/lv_themes/lv_themes.mk --include ./lvgl/src/lv_draw/lv_draw.mk --include ./lvgl/src/lv_gpu/lv_gpu.mk +CSRCS += port/lv_port.c +CSRCS += port/lv_port_tick.c -CSRCS += lv_tick_interface.c -ifneq ($(CONFIG_USE_LV_FILESYSTEM),) -CSRCS += lv_fs_interface.c +ifneq ($(CONFIG_LV_PORT_USE_LCDDEV),) Review Comment: why not `ifeq ($(CONFIG_LV_PORT_USE_LCDDEV),y)`? and the same for other similar places here ########## graphics/lvgl/port/lv_port_button.c: ########## @@ -0,0 +1,237 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_button.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <nuttx/input/buttons.h> +#include "lv_port_button.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BUTTON_0_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_0_MAP_X +#define BUTTON_0_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_0_MAP_Y +#define BUTTON_1_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_1_MAP_X +#define BUTTON_1_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_1_MAP_Y +#define BUTTON_2_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_2_MAP_X +#define BUTTON_2_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_2_MAP_Y +#define BUTTON_3_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_3_MAP_X +#define BUTTON_3_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_3_MAP_Y +#define BUTTON_4_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_4_MAP_X +#define BUTTON_4_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_4_MAP_Y +#define BUTTON_5_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_5_MAP_X +#define BUTTON_5_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_5_MAP_Y + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct button_obj_s +{ + int fd; + uint8_t last_btn; + lv_indev_drv_t indev_drv; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Assign buttons to points on the screen */ + +static const lv_point_t g_button_points_map[6] = +{ + {BUTTON_0_MAP_X, BUTTON_0_MAP_Y}, + {BUTTON_1_MAP_X, BUTTON_1_MAP_Y}, + {BUTTON_2_MAP_X, BUTTON_2_MAP_Y}, + {BUTTON_3_MAP_X, BUTTON_3_MAP_Y}, + {BUTTON_4_MAP_X, BUTTON_4_MAP_Y}, + {BUTTON_5_MAP_X, BUTTON_5_MAP_Y} +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: button_get_pressed_id + ****************************************************************************/ + +static int button_get_pressed_id(int fd) +{ + int btn_act = -1; + btn_buttonset_t buttonset; + const int buttonset_bits = sizeof(btn_buttonset_t) * 8; + int bit; + + int ret = read(fd, &buttonset, sizeof(btn_buttonset_t)); + if (ret < 0) + { + return -1; + } + + for (bit = 0; bit < buttonset_bits; bit++) + { + btn_buttonset_t mask = 1 << bit; + + if (buttonset & mask) + { + btn_act = bit; + break; + } + } + + return btn_act; +} + +/**************************************************************************** + * Name: button_read + ****************************************************************************/ + +static void button_read(FAR lv_indev_drv_t *drv, FAR lv_indev_data_t *data) +{ + struct button_obj_s *button_obj = drv->user_data; + + /* Get the pressed button's ID */ + + int btn_act = button_get_pressed_id(button_obj->fd); + + if (btn_act >= 0) + { + data->state = LV_INDEV_STATE_PR; + button_obj->last_btn = btn_act; + } + else + { + data->state = LV_INDEV_STATE_REL; + } + + /* Save the last pressed button's ID */ + + data->btn_id = button_obj->last_btn; +} + +/**************************************************************************** + * Name: button_init + ****************************************************************************/ + +static FAR lv_indev_t *button_init(int fd) +{ + FAR struct button_obj_s *button_obj; + button_obj = malloc(sizeof(struct button_obj_s)); + FAR lv_indev_t *indev_button; Review Comment: ```suggestion FAR struct button_obj_s *button_obj; FAR lv_indev_t *indev_button; button_obj = malloc(sizeof(struct button_obj_s)); ``` ########## graphics/lvgl/port/lv_port_fbdev.c: ########## @@ -0,0 +1,755 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_fbdev.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/video/fb.h> +#include <nuttx/video/rgbcolors.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <unistd.h> +#include <stdlib.h> +#include <fcntl.h> +#include <errno.h> +#include "lv_port_fbdev.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if defined(CONFIG_FB_UPDATE) +#define FBDEV_UPDATE_AREA(obj, area) fbdev_update_area(obj, area) Review Comment: ```suggestion # define FBDEV_UPDATE_AREA(obj, area) fbdev_update_area(obj, area) ``` ########## graphics/lvgl/port/lv_port_mem.h: ########## @@ -0,0 +1,92 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_mem.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_LVGL_PORT_LV_PORT_MEM_H +#define __APPS_GRAPHICS_LVGL_PORT_LV_PORT_MEM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <lvgl/lvgl.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_LV_PORT_MEM_CUSTOM_SIZE +#define CONFIG_LV_PORT_MEM_CUSTOM_SIZE 0 Review Comment: ```suggestion # define CONFIG_LV_PORT_MEM_CUSTOM_SIZE 0 ``` ########## graphics/lvgl/port/lv_port_button.c: ########## @@ -0,0 +1,237 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_button.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <nuttx/input/buttons.h> +#include "lv_port_button.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BUTTON_0_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_0_MAP_X +#define BUTTON_0_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_0_MAP_Y +#define BUTTON_1_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_1_MAP_X +#define BUTTON_1_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_1_MAP_Y +#define BUTTON_2_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_2_MAP_X +#define BUTTON_2_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_2_MAP_Y +#define BUTTON_3_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_3_MAP_X +#define BUTTON_3_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_3_MAP_Y +#define BUTTON_4_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_4_MAP_X +#define BUTTON_4_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_4_MAP_Y +#define BUTTON_5_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_5_MAP_X +#define BUTTON_5_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_5_MAP_Y + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct button_obj_s +{ + int fd; + uint8_t last_btn; + lv_indev_drv_t indev_drv; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Assign buttons to points on the screen */ + +static const lv_point_t g_button_points_map[6] = +{ + {BUTTON_0_MAP_X, BUTTON_0_MAP_Y}, + {BUTTON_1_MAP_X, BUTTON_1_MAP_Y}, + {BUTTON_2_MAP_X, BUTTON_2_MAP_Y}, + {BUTTON_3_MAP_X, BUTTON_3_MAP_Y}, + {BUTTON_4_MAP_X, BUTTON_4_MAP_Y}, + {BUTTON_5_MAP_X, BUTTON_5_MAP_Y} +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: button_get_pressed_id + ****************************************************************************/ + +static int button_get_pressed_id(int fd) +{ + int btn_act = -1; + btn_buttonset_t buttonset; + const int buttonset_bits = sizeof(btn_buttonset_t) * 8; + int bit; + + int ret = read(fd, &buttonset, sizeof(btn_buttonset_t)); + if (ret < 0) + { + return -1; + } + + for (bit = 0; bit < buttonset_bits; bit++) + { + btn_buttonset_t mask = 1 << bit; Review Comment: ```suggestion btn_buttonset_t mask = (btn_buttonset_t)1 << bit; ``` ########## graphics/lvgl/port/lv_port_keypad.c: ########## @@ -0,0 +1,250 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_keypad.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> +#include <nuttx/input/buttons.h> +#include "lv_port_keypad.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define LV_KEY_UP_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_UP_MAP_BIT +#define LV_KEY_DOWN_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_DOWN_MAP_BIT +#define LV_KEY_RIGHT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_RIGHT_MAP_BIT +#define LV_KEY_LEFT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_LEFT_MAP_BIT + +#define LV_KEY_ESC_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_ESC_MAP_BIT +#define LV_KEY_DEL_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_DEL_MAP_BIT +#define LV_KEY_BACKSPACE_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_BACKSPACE_MAP_BIT +#define LV_KEY_ENTER_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_ENTER_MAP_BIT + +#define LV_KEY_NEXT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_NEXT_MAP_BIT +#define LV_KEY_PREV_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_PREV_MAP_BIT +#define LV_KEY_HOME_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_HOME_MAP_BIT +#define LV_KEY_END_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_END_MAP_BIT + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct keypad_map_s +{ + const lv_key_t key; + int bit; +}; + +struct keypad_obj_s +{ + int fd; + uint32_t last_key; + lv_indev_drv_t indev_drv; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct keypad_map_s g_keypad_map[] = +{ + {.key = LV_KEY_UP, .bit = LV_KEY_UP_MAP_BIT}, Review Comment: let not use designated initializer here ########## graphics/lvgl/port/lv_port_keypad.c: ########## @@ -0,0 +1,250 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_keypad.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> +#include <nuttx/input/buttons.h> +#include "lv_port_keypad.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define LV_KEY_UP_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_UP_MAP_BIT +#define LV_KEY_DOWN_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_DOWN_MAP_BIT +#define LV_KEY_RIGHT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_RIGHT_MAP_BIT +#define LV_KEY_LEFT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_LEFT_MAP_BIT + +#define LV_KEY_ESC_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_ESC_MAP_BIT +#define LV_KEY_DEL_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_DEL_MAP_BIT +#define LV_KEY_BACKSPACE_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_BACKSPACE_MAP_BIT +#define LV_KEY_ENTER_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_ENTER_MAP_BIT + +#define LV_KEY_NEXT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_NEXT_MAP_BIT +#define LV_KEY_PREV_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_PREV_MAP_BIT +#define LV_KEY_HOME_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_HOME_MAP_BIT +#define LV_KEY_END_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_END_MAP_BIT + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct keypad_map_s +{ + const lv_key_t key; + int bit; +}; + +struct keypad_obj_s +{ + int fd; + uint32_t last_key; + lv_indev_drv_t indev_drv; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct keypad_map_s g_keypad_map[] = +{ + {.key = LV_KEY_UP, .bit = LV_KEY_UP_MAP_BIT}, + {.key = LV_KEY_DOWN, .bit = LV_KEY_DOWN_MAP_BIT}, + {.key = LV_KEY_RIGHT, .bit = LV_KEY_RIGHT_MAP_BIT}, + {.key = LV_KEY_LEFT, .bit = LV_KEY_LEFT_MAP_BIT}, + {.key = LV_KEY_ESC, .bit = LV_KEY_ESC_MAP_BIT}, + {.key = LV_KEY_DEL, .bit = LV_KEY_DEL_MAP_BIT}, + {.key = LV_KEY_BACKSPACE, .bit = LV_KEY_BACKSPACE_MAP_BIT}, + {.key = LV_KEY_ENTER, .bit = LV_KEY_ENTER_MAP_BIT}, + {.key = LV_KEY_NEXT, .bit = LV_KEY_NEXT_MAP_BIT}, + {.key = LV_KEY_PREV, .bit = LV_KEY_PREV_MAP_BIT}, + {.key = LV_KEY_HOME, .bit = LV_KEY_HOME_MAP_BIT}, + {.key = LV_KEY_END, .bit = LV_KEY_END_MAP_BIT} +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: keypad_get_key + ****************************************************************************/ + +static uint32_t keypad_get_key(int fd) +{ + uint32_t act_key = 0; + btn_buttonset_t buttonset; + const int buttonset_bits = sizeof(btn_buttonset_t) * 8; + int i; + + int ret = read(fd, &buttonset, sizeof(btn_buttonset_t)); + if (ret < 0) + { + return 0; + } + + for (i = 0; i < sizeof(g_keypad_map) / sizeof(struct keypad_map_s); i++) + { + int bit = g_keypad_map[i].bit; + + if (bit >= 0 && bit < buttonset_bits) + { + btn_buttonset_t mask = 1 << bit; + if (buttonset & mask) Review Comment: ```suggestion btn_buttonset_t mask = (btn_buttonset_t)1 << bit; if (buttonset & mask != 0) ``` ########## graphics/lvgl/port/lv_port_encoder.c: ########## @@ -0,0 +1,162 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_encoder.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> +#include <nuttx/input/mouse.h> +#include "lv_port_encoder.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct encoder_obj_s +{ + int fd; + lv_indev_state_t last_state; + lv_indev_drv_t indev_drv; +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: encoder_read + ****************************************************************************/ + +static void encoder_read(FAR lv_indev_drv_t *drv, FAR lv_indev_data_t *data) +{ + FAR struct encoder_obj_s *encoder_obj = drv->user_data; + + /* Read one sample */ + + struct mouse_report_s sample; + int16_t wheel = 0; + + int nbytes = read(encoder_obj->fd, &sample, + sizeof(struct mouse_report_s)); + + /* Handle unexpected return values */ + + if (nbytes == sizeof(struct mouse_report_s)) + { + wheel = sample.wheel; + encoder_obj->last_state = (sample.buttons & MOUSE_BUTTON_3) ? + LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED; + } + + /* Update encoder data */ + + data->enc_diff = wheel; + data->state = encoder_obj->last_state; +} + +/**************************************************************************** + * Name: encoder_init + ****************************************************************************/ + +static FAR lv_indev_t *encoder_init(int fd) +{ + FAR struct encoder_obj_s *encoder_obj; + encoder_obj = malloc(sizeof(struct encoder_obj_s)); + + if (encoder_obj == NULL) + { + LV_LOG_ERROR("encoder_obj_s malloc failed"); + return NULL; + } + + encoder_obj->fd = fd; + encoder_obj->last_state = LV_INDEV_STATE_RELEASED; + + lv_indev_drv_init(&(encoder_obj->indev_drv)); + encoder_obj->indev_drv.type = LV_INDEV_TYPE_ENCODER; + encoder_obj->indev_drv.read_cb = encoder_read; +#if ( LV_USE_USER_DATA != 0 ) + encoder_obj->indev_drv.user_data = encoder_obj; +#else +#error LV_USE_USER_DATA must be enabled +#endif + return lv_indev_drv_register(&(encoder_obj->indev_drv)); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lv_port_encoder_init + * + * Description: + * Encoder interface initialization. + * + * Input Parameters: + * dev_path - input device path, set to NULL to use the default path. + * + * Returned Value: + * lv_indev object address on success; NULL on failure. + * + ****************************************************************************/ + +FAR lv_indev_t *lv_port_encoder_init(FAR const char *dev_path) +{ + const char *device_path = dev_path; + lv_indev_t *indev; Review Comment: ```suggestion FAR const char *device_path = dev_path; FAR lv_indev_t *indev; ``` ########## graphics/lvgl/port/lv_port_lcddev.c: ########## @@ -0,0 +1,302 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_lcddev.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/lcd/lcd_dev.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <pthread.h> +#include <semaphore.h> +#include "lv_port_lcddev.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct lcddev_obj_s +{ + int fd; + lv_disp_draw_buf_t disp_draw_buf; + lv_disp_drv_t disp_drv; + struct lcddev_area_s area; + + pthread_t write_thread; + sem_t flush_sem; + sem_t wait_sem; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lcddev_wait + ****************************************************************************/ + +static void lcddev_wait(FAR lv_disp_drv_t *disp_drv) +{ + FAR struct lcddev_obj_s *lcddev_obj = disp_drv->user_data; + + sem_wait(&(lcddev_obj->wait_sem)); + + /* Tell the flushing is ready */ + + lv_disp_flush_ready(disp_drv); +} + +/**************************************************************************** + * Name: lcddev_update_thread + ****************************************************************************/ + +static FAR void *lcddev_update_thread(FAR void *arg) +{ + int ret = OK; + int errcode = 0; + FAR struct lcddev_obj_s *lcddev_obj = arg; + + while (ret == OK) + { + sem_wait(&(lcddev_obj->flush_sem)); + + ret = ioctl(lcddev_obj->fd, LCDDEVIO_PUTAREA, + (unsigned long)&(lcddev_obj->area)); + if (ret < 0) + { + errcode = errno; + } + + sem_post(&(lcddev_obj->wait_sem)); + } + + LV_LOG_ERROR("ioctl(LCDDEVIO_PUTAREA) failed: %d", errcode); + close(lcddev_obj->fd); + lcddev_obj->fd = -1; + + return NULL; +} + +/**************************************************************************** + * Name: lcddev_flush + ****************************************************************************/ + +static void lcddev_flush(FAR lv_disp_drv_t *disp_drv, + FAR const lv_area_t *area_p, + FAR lv_color_t *color_p) +{ + struct lcddev_obj_s *lcddev_obj = disp_drv->user_data; Review Comment: ```suggestion FAR struct lcddev_obj_s *lcddev_obj = disp_drv->user_data; ``` ########## graphics/lvgl/port/lv_port_keypad.c: ########## @@ -0,0 +1,250 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_keypad.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> +#include <nuttx/input/buttons.h> +#include "lv_port_keypad.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define LV_KEY_UP_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_UP_MAP_BIT +#define LV_KEY_DOWN_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_DOWN_MAP_BIT +#define LV_KEY_RIGHT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_RIGHT_MAP_BIT +#define LV_KEY_LEFT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_LEFT_MAP_BIT + +#define LV_KEY_ESC_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_ESC_MAP_BIT +#define LV_KEY_DEL_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_DEL_MAP_BIT +#define LV_KEY_BACKSPACE_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_BACKSPACE_MAP_BIT +#define LV_KEY_ENTER_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_ENTER_MAP_BIT + +#define LV_KEY_NEXT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_NEXT_MAP_BIT +#define LV_KEY_PREV_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_PREV_MAP_BIT +#define LV_KEY_HOME_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_HOME_MAP_BIT +#define LV_KEY_END_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_END_MAP_BIT + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct keypad_map_s +{ + const lv_key_t key; + int bit; +}; + +struct keypad_obj_s +{ + int fd; + uint32_t last_key; + lv_indev_drv_t indev_drv; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct keypad_map_s g_keypad_map[] = +{ + {.key = LV_KEY_UP, .bit = LV_KEY_UP_MAP_BIT}, + {.key = LV_KEY_DOWN, .bit = LV_KEY_DOWN_MAP_BIT}, + {.key = LV_KEY_RIGHT, .bit = LV_KEY_RIGHT_MAP_BIT}, + {.key = LV_KEY_LEFT, .bit = LV_KEY_LEFT_MAP_BIT}, + {.key = LV_KEY_ESC, .bit = LV_KEY_ESC_MAP_BIT}, + {.key = LV_KEY_DEL, .bit = LV_KEY_DEL_MAP_BIT}, + {.key = LV_KEY_BACKSPACE, .bit = LV_KEY_BACKSPACE_MAP_BIT}, + {.key = LV_KEY_ENTER, .bit = LV_KEY_ENTER_MAP_BIT}, + {.key = LV_KEY_NEXT, .bit = LV_KEY_NEXT_MAP_BIT}, + {.key = LV_KEY_PREV, .bit = LV_KEY_PREV_MAP_BIT}, + {.key = LV_KEY_HOME, .bit = LV_KEY_HOME_MAP_BIT}, + {.key = LV_KEY_END, .bit = LV_KEY_END_MAP_BIT} +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: keypad_get_key + ****************************************************************************/ + +static uint32_t keypad_get_key(int fd) +{ + uint32_t act_key = 0; + btn_buttonset_t buttonset; + const int buttonset_bits = sizeof(btn_buttonset_t) * 8; + int i; + + int ret = read(fd, &buttonset, sizeof(btn_buttonset_t)); + if (ret < 0) + { + return 0; + } + + for (i = 0; i < sizeof(g_keypad_map) / sizeof(struct keypad_map_s); i++) + { + int bit = g_keypad_map[i].bit; + + if (bit >= 0 && bit < buttonset_bits) + { + btn_buttonset_t mask = 1 << bit; + if (buttonset & mask) + { + act_key = g_keypad_map[i].key; + break; + } + } + } + + return act_key; +} + +/**************************************************************************** + * Name: keypad_read + ****************************************************************************/ + +static void keypad_read(FAR lv_indev_drv_t *drv, FAR lv_indev_data_t *data) +{ + struct keypad_obj_s *keypad_obj = drv->user_data; Review Comment: ```suggestion FAR struct keypad_obj_s *keypad_obj = drv->user_data; ``` ########## graphics/lvgl/port/lv_port_fbdev.c: ########## @@ -0,0 +1,755 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_fbdev.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/video/fb.h> +#include <nuttx/video/rgbcolors.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <unistd.h> +#include <stdlib.h> +#include <fcntl.h> +#include <errno.h> +#include "lv_port_fbdev.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if defined(CONFIG_FB_UPDATE) +#define FBDEV_UPDATE_AREA(obj, area) fbdev_update_area(obj, area) +#else +#define FBDEV_UPDATE_AREA(obj, area) Review Comment: ```suggestion # define FBDEV_UPDATE_AREA(obj, area) ``` ########## graphics/lvgl/port/lv_port_lcddev.c: ########## @@ -0,0 +1,302 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_lcddev.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/lcd/lcd_dev.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <pthread.h> +#include <semaphore.h> +#include "lv_port_lcddev.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct lcddev_obj_s +{ + int fd; + lv_disp_draw_buf_t disp_draw_buf; + lv_disp_drv_t disp_drv; + struct lcddev_area_s area; + + pthread_t write_thread; + sem_t flush_sem; + sem_t wait_sem; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lcddev_wait + ****************************************************************************/ + +static void lcddev_wait(FAR lv_disp_drv_t *disp_drv) +{ + FAR struct lcddev_obj_s *lcddev_obj = disp_drv->user_data; + + sem_wait(&(lcddev_obj->wait_sem)); + + /* Tell the flushing is ready */ + + lv_disp_flush_ready(disp_drv); +} + +/**************************************************************************** + * Name: lcddev_update_thread + ****************************************************************************/ + +static FAR void *lcddev_update_thread(FAR void *arg) +{ + int ret = OK; + int errcode = 0; + FAR struct lcddev_obj_s *lcddev_obj = arg; + + while (ret == OK) + { + sem_wait(&(lcddev_obj->flush_sem)); + + ret = ioctl(lcddev_obj->fd, LCDDEVIO_PUTAREA, + (unsigned long)&(lcddev_obj->area)); + if (ret < 0) + { + errcode = errno; + } + + sem_post(&(lcddev_obj->wait_sem)); + } + + LV_LOG_ERROR("ioctl(LCDDEVIO_PUTAREA) failed: %d", errcode); + close(lcddev_obj->fd); + lcddev_obj->fd = -1; + + return NULL; +} + +/**************************************************************************** + * Name: lcddev_flush + ****************************************************************************/ + +static void lcddev_flush(FAR lv_disp_drv_t *disp_drv, + FAR const lv_area_t *area_p, + FAR lv_color_t *color_p) +{ + struct lcddev_obj_s *lcddev_obj = disp_drv->user_data; + + lcddev_obj->area.row_start = area_p->y1; + lcddev_obj->area.row_end = area_p->y2; + lcddev_obj->area.col_start = area_p->x1; + lcddev_obj->area.col_end = area_p->x2; + lcddev_obj->area.data = (uint8_t *)color_p; + + sem_post(&(lcddev_obj->flush_sem)); Review Comment: ```suggestion sem_post(&lcddev_obj->flush_sem); ``` ########## graphics/lvgl/Makefile: ########## @@ -25,32 +25,67 @@ include $(APPDIR)/Make.defs LVGL_DIR = . LVGL_DIR_NAME = lvgl -# Relax format check for LVGL to avoid errors on prinf() use +# Relax LVGL's format checking and unused variable checking to avoid errors -CFLAGS += -Wno-format +CFLAGS += -Wno-format -Wno-unused-variable -# LVGL Libraries +-include ./lvgl/lvgl.mk --include ./lvgl/src/lv_core/lv_core.mk --include ./lvgl/src/lv_hal/lv_hal.mk --include ./lvgl/src/lv_widgets/lv_widgets.mk --include ./lvgl/src/lv_font/lv_font.mk --include ./lvgl/src/lv_misc/lv_misc.mk --include ./lvgl/src/lv_themes/lv_themes.mk --include ./lvgl/src/lv_draw/lv_draw.mk --include ./lvgl/src/lv_gpu/lv_gpu.mk +CSRCS += port/lv_port.c +CSRCS += port/lv_port_tick.c -CSRCS += lv_tick_interface.c -ifneq ($(CONFIG_USE_LV_FILESYSTEM),) -CSRCS += lv_fs_interface.c +ifneq ($(CONFIG_LV_PORT_USE_LCDDEV),) +CSRCS += port/lv_port_lcddev.c +endif + +ifneq ($(CONFIG_LV_PORT_USE_FBDEV),) +CSRCS += port/lv_port_fbdev.c +endif + +ifneq ($(CONFIG_LV_PORT_USE_TOUCHPAD),) +CSRCS += port/lv_port_touchpad.c +endif + +ifneq ($(CONFIG_LV_PORT_USE_BUTTON),) +CSRCS += port/lv_port_button.c +endif + +ifneq ($(CONFIG_LV_PORT_USE_KEYPAD),) +CSRCS += port/lv_port_keypad.c +endif + +ifneq ($(CONFIG_LV_PORT_USE_ENCODER),) +CSRCS += port/lv_port_encoder.c +endif + +ifneq ($(CONFIG_LV_PORT_USE_SYSLOG),) +CSRCS += port/lv_port_syslog.c +endif + +ifneq ($(CONFIG_LV_PORT_MEM_ATTRIBUTE_FAST_MEM_SECTION_NAME), "") +CFLAGS += "-DLV_ATTRIBUTE_FAST_MEM=__attribute__((section(CONFIG_LV_PORT_MEM_ATTRIBUTE_FAST_MEM_SECTION_NAME)))" +CXXFLAGS += "-DLV_ATTRIBUTE_FAST_MEM=__attribute__((section(CONFIG_LV_PORT_MEM_ATTRIBUTE_FAST_MEM_SECTION_NAME)))" Review Comment: ```suggestion CFLAGS += "-DLV_ATTRIBUTE_FAST_MEM=locate_data(CONFIG_LV_PORT_MEM_ATTRIBUTE_FAST_MEM_SECTION_NAME)" CXXFLAGS += "-DLV_ATTRIBUTE_FAST_MEM=locate_data(CONFIG_LV_PORT_MEM_ATTRIBUTE_FAST_MEM_SECTION_NAME)" ``` but most probably code will need to include `nuttx/compiler.h` so I'm not sure if this comment is applicable ########## graphics/lvgl/port/lv_port_lcddev.c: ########## @@ -0,0 +1,302 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_lcddev.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/lcd/lcd_dev.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <pthread.h> +#include <semaphore.h> +#include "lv_port_lcddev.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct lcddev_obj_s +{ + int fd; + lv_disp_draw_buf_t disp_draw_buf; + lv_disp_drv_t disp_drv; + struct lcddev_area_s area; + + pthread_t write_thread; + sem_t flush_sem; + sem_t wait_sem; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lcddev_wait + ****************************************************************************/ + +static void lcddev_wait(FAR lv_disp_drv_t *disp_drv) +{ + FAR struct lcddev_obj_s *lcddev_obj = disp_drv->user_data; + + sem_wait(&(lcddev_obj->wait_sem)); + + /* Tell the flushing is ready */ + + lv_disp_flush_ready(disp_drv); +} + +/**************************************************************************** + * Name: lcddev_update_thread + ****************************************************************************/ + +static FAR void *lcddev_update_thread(FAR void *arg) +{ + int ret = OK; + int errcode = 0; + FAR struct lcddev_obj_s *lcddev_obj = arg; + + while (ret == OK) + { + sem_wait(&(lcddev_obj->flush_sem)); + + ret = ioctl(lcddev_obj->fd, LCDDEVIO_PUTAREA, + (unsigned long)&(lcddev_obj->area)); + if (ret < 0) + { + errcode = errno; + } + + sem_post(&(lcddev_obj->wait_sem)); + } + + LV_LOG_ERROR("ioctl(LCDDEVIO_PUTAREA) failed: %d", errcode); + close(lcddev_obj->fd); + lcddev_obj->fd = -1; + + return NULL; +} + +/**************************************************************************** + * Name: lcddev_flush + ****************************************************************************/ + +static void lcddev_flush(FAR lv_disp_drv_t *disp_drv, + FAR const lv_area_t *area_p, + FAR lv_color_t *color_p) +{ + struct lcddev_obj_s *lcddev_obj = disp_drv->user_data; + + lcddev_obj->area.row_start = area_p->y1; + lcddev_obj->area.row_end = area_p->y2; + lcddev_obj->area.col_start = area_p->x1; + lcddev_obj->area.col_end = area_p->x2; + lcddev_obj->area.data = (uint8_t *)color_p; Review Comment: ```suggestion lcddev_obj->area.data = (FAR uint8_t *)color_p; ``` ########## graphics/lvgl/port/lv_port_button.c: ########## @@ -0,0 +1,237 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_button.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <nuttx/input/buttons.h> +#include "lv_port_button.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BUTTON_0_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_0_MAP_X +#define BUTTON_0_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_0_MAP_Y +#define BUTTON_1_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_1_MAP_X +#define BUTTON_1_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_1_MAP_Y +#define BUTTON_2_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_2_MAP_X +#define BUTTON_2_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_2_MAP_Y +#define BUTTON_3_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_3_MAP_X +#define BUTTON_3_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_3_MAP_Y +#define BUTTON_4_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_4_MAP_X +#define BUTTON_4_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_4_MAP_Y +#define BUTTON_5_MAP_X CONFIG_LV_PORT_BUTTON_BUTTON_5_MAP_X +#define BUTTON_5_MAP_Y CONFIG_LV_PORT_BUTTON_BUTTON_5_MAP_Y + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct button_obj_s +{ + int fd; + uint8_t last_btn; + lv_indev_drv_t indev_drv; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Assign buttons to points on the screen */ + +static const lv_point_t g_button_points_map[6] = +{ + {BUTTON_0_MAP_X, BUTTON_0_MAP_Y}, + {BUTTON_1_MAP_X, BUTTON_1_MAP_Y}, + {BUTTON_2_MAP_X, BUTTON_2_MAP_Y}, + {BUTTON_3_MAP_X, BUTTON_3_MAP_Y}, + {BUTTON_4_MAP_X, BUTTON_4_MAP_Y}, + {BUTTON_5_MAP_X, BUTTON_5_MAP_Y} +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: button_get_pressed_id + ****************************************************************************/ + +static int button_get_pressed_id(int fd) +{ + int btn_act = -1; + btn_buttonset_t buttonset; + const int buttonset_bits = sizeof(btn_buttonset_t) * 8; + int bit; + + int ret = read(fd, &buttonset, sizeof(btn_buttonset_t)); + if (ret < 0) + { + return -1; + } + + for (bit = 0; bit < buttonset_bits; bit++) + { + btn_buttonset_t mask = 1 << bit; + + if (buttonset & mask) + { + btn_act = bit; + break; + } + } + + return btn_act; +} + +/**************************************************************************** + * Name: button_read + ****************************************************************************/ + +static void button_read(FAR lv_indev_drv_t *drv, FAR lv_indev_data_t *data) +{ + struct button_obj_s *button_obj = drv->user_data; Review Comment: ```suggestion FAR struct button_obj_s *button_obj = drv->user_data; ``` ########## graphics/lvgl/port/lv_port_keypad.c: ########## @@ -0,0 +1,250 @@ +/**************************************************************************** + * apps/graphics/lvgl/port/lv_port_keypad.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> +#include <nuttx/input/buttons.h> +#include "lv_port_keypad.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define LV_KEY_UP_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_UP_MAP_BIT +#define LV_KEY_DOWN_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_DOWN_MAP_BIT +#define LV_KEY_RIGHT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_RIGHT_MAP_BIT +#define LV_KEY_LEFT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_LEFT_MAP_BIT + +#define LV_KEY_ESC_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_ESC_MAP_BIT +#define LV_KEY_DEL_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_DEL_MAP_BIT +#define LV_KEY_BACKSPACE_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_BACKSPACE_MAP_BIT +#define LV_KEY_ENTER_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_ENTER_MAP_BIT + +#define LV_KEY_NEXT_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_NEXT_MAP_BIT +#define LV_KEY_PREV_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_PREV_MAP_BIT +#define LV_KEY_HOME_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_HOME_MAP_BIT +#define LV_KEY_END_MAP_BIT CONFIG_LV_PORT_KEYPAD_KEY_END_MAP_BIT + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +struct keypad_map_s +{ + const lv_key_t key; + int bit; +}; + +struct keypad_obj_s +{ + int fd; + uint32_t last_key; + lv_indev_drv_t indev_drv; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct keypad_map_s g_keypad_map[] = +{ + {.key = LV_KEY_UP, .bit = LV_KEY_UP_MAP_BIT}, + {.key = LV_KEY_DOWN, .bit = LV_KEY_DOWN_MAP_BIT}, + {.key = LV_KEY_RIGHT, .bit = LV_KEY_RIGHT_MAP_BIT}, + {.key = LV_KEY_LEFT, .bit = LV_KEY_LEFT_MAP_BIT}, + {.key = LV_KEY_ESC, .bit = LV_KEY_ESC_MAP_BIT}, + {.key = LV_KEY_DEL, .bit = LV_KEY_DEL_MAP_BIT}, + {.key = LV_KEY_BACKSPACE, .bit = LV_KEY_BACKSPACE_MAP_BIT}, + {.key = LV_KEY_ENTER, .bit = LV_KEY_ENTER_MAP_BIT}, + {.key = LV_KEY_NEXT, .bit = LV_KEY_NEXT_MAP_BIT}, + {.key = LV_KEY_PREV, .bit = LV_KEY_PREV_MAP_BIT}, + {.key = LV_KEY_HOME, .bit = LV_KEY_HOME_MAP_BIT}, + {.key = LV_KEY_END, .bit = LV_KEY_END_MAP_BIT} +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: keypad_get_key + ****************************************************************************/ + +static uint32_t keypad_get_key(int fd) +{ + uint32_t act_key = 0; + btn_buttonset_t buttonset; + const int buttonset_bits = sizeof(btn_buttonset_t) * 8; + int i; + + int ret = read(fd, &buttonset, sizeof(btn_buttonset_t)); + if (ret < 0) + { + return 0; + } + + for (i = 0; i < sizeof(g_keypad_map) / sizeof(struct keypad_map_s); i++) + { + int bit = g_keypad_map[i].bit; + + if (bit >= 0 && bit < buttonset_bits) + { + btn_buttonset_t mask = 1 << bit; + if (buttonset & mask) + { + act_key = g_keypad_map[i].key; + break; + } + } + } + + return act_key; +} + +/**************************************************************************** + * Name: keypad_read + ****************************************************************************/ + +static void keypad_read(FAR lv_indev_drv_t *drv, FAR lv_indev_data_t *data) +{ + struct keypad_obj_s *keypad_obj = drv->user_data; + + /* Get whether the a key is pressed and save the pressed key */ + + uint32_t act_key = keypad_get_key(keypad_obj->fd); + if (act_key != 0) Review Comment: ```suggestion uint32_t act_key = keypad_get_key(keypad_obj->fd); if (act_key != 0) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org