diff --git a/drivers/disp_dev/disp_dev.c b/drivers/disp_dev/disp_dev.c index acd716239e..5653d59656 100644 --- a/drivers/disp_dev/disp_dev.c +++ b/drivers/disp_dev/disp_dev.c @@ -21,9 +21,46 @@ #include #include #include +#include #include "disp_dev.h" +disp_dev_reg_t *disp_dev_reg = NULL; + +int disp_dev_reg_add(disp_dev_reg_t *dev) +{ + disp_dev_reg_t *tmp = disp_dev_reg; + + if (dev == NULL) { + return -ENODEV; + } + + /* prepare new entry */ + dev->next = NULL; + /* add to registry */ + if (disp_dev_reg == NULL) { + disp_dev_reg = dev; + } + else { + while (tmp->next != NULL) { + tmp = tmp->next; + } + tmp->next = dev; + } + return 0; +} + +disp_dev_reg_t *disp_dev_reg_find_screen(uint8_t screen_id) +{ + disp_dev_reg_t *tmp = disp_dev_reg; + + while (tmp && tmp->screen_id != screen_id) { + tmp = tmp->next; + } + + return tmp; +} + void disp_dev_map(const disp_dev_t *dev, uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, const uint16_t *color) diff --git a/drivers/include/disp_dev.h b/drivers/include/disp_dev.h index c5c21f7b9a..a2d8e680b4 100644 --- a/drivers/include/disp_dev.h +++ b/drivers/include/disp_dev.h @@ -101,6 +101,40 @@ struct disp_dev { const disp_dev_driver_t *driver; /**< Pointer to driver of the display device */ }; +/** + * @brief Disp dev registry entry + */ +typedef struct disp_dev_reg { + struct disp_dev_reg *next; /**< pointer to the next display device in the list */ + disp_dev_t *dev; /**< pointer to the device descriptor */ + uint8_t screen_id; /**< id of the screen this display is attached to */ +} disp_dev_reg_t; + +/** + * @brief Export the display device registry as global variable + */ +extern disp_dev_reg_t *disp_dev_reg; + +/** + * @brief Add pointer to a display device item to the list of display items + * + * @param[in] dev Pointer to the display device + * + * @return 0 on success + * @return -ENODEV on invalid entry +*/ +int disp_dev_reg_add(disp_dev_reg_t *dev); + +/** + * @brief Find the display device that is attached to a given screen + * + * @param[in] screen_id Identifier (number) of the screen + * + * @return pointer to the display device in the registry + * @return NULL if there's no match +*/ +disp_dev_reg_t *disp_dev_reg_find_screen(uint8_t screen_id); + /** * @brief Map an area to display on the device *