|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2025 HAW Hamburg |
| 3 | + * SPDX-License-Identifier: LGPL-2.1-only |
| 4 | + */ |
| 5 | + |
| 6 | +#pragma once |
| 7 | + |
| 8 | +/** |
| 9 | + * @defgroup u8g2_disp_dev Display device generic API implementation for U8G2 |
| 10 | + * @ingroup pkg_u8g2 |
| 11 | + * @brief Implementation of display device generic API for U8G2 monochrome displays |
| 12 | + * |
| 13 | + * For more information on how to use this module, refer to @ref pkg_u8g2. |
| 14 | + * |
| 15 | + * @{ |
| 16 | + * |
| 17 | + * @file |
| 18 | + * |
| 19 | + * @author Leandro Lanzieri <[email protected]> |
| 20 | + */ |
| 21 | + |
| 22 | +#include <inttypes.h> |
| 23 | + |
| 24 | +#include "u8g2.h" |
| 25 | +#include "u8x8_riotos.h" |
| 26 | + |
| 27 | +#include "disp_dev.h" |
| 28 | + |
| 29 | +#ifdef __cplusplus |
| 30 | +extern "C" { |
| 31 | +#endif |
| 32 | + |
| 33 | +/** |
| 34 | + * @brief Function pointer type for u8g2 initialization functions |
| 35 | + * @see Check the u8g2 reference for possible setup functions: |
| 36 | + * https://github.com/olikraus/u8g2/wiki/u8g2setupc#setup-function-reference |
| 37 | + */ |
| 38 | +typedef void (*u8g2_init_function_t)(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, |
| 39 | + u8x8_msg_cb gpio_and_delay_cb); |
| 40 | + |
| 41 | +/** |
| 42 | + * @brief U8G2 display initialization parameters |
| 43 | + */ |
| 44 | +typedef struct { |
| 45 | + u8g2_init_function_t init_function; /**< Initialization function for u8g2 */ |
| 46 | + u8x8_riotos_t peripheral_configuration; /**< Peripheral configuration for RIOT-OS */ |
| 47 | + /** |
| 48 | + * I2C address of the display. Set to 0 when using SPI. |
| 49 | + */ |
| 50 | + uint8_t i2c_address; |
| 51 | +} u8g2_display_params_t; |
| 52 | + |
| 53 | +/** |
| 54 | + * @brief U8G2 display device structure |
| 55 | + */ |
| 56 | +typedef struct { |
| 57 | + disp_dev_t *dev; /**< Pointer to disp_dev instance (@ref drivers_disp_dev) */ |
| 58 | + u8g2_display_params_t params; /**< Device initialization parameters */ |
| 59 | + u8g2_t u8g2; /**< U8G2 instance (@ref pkg_u8g2) */ |
| 60 | +} u8g2_display_t; |
| 61 | + |
| 62 | +/** |
| 63 | + * @brief Initialize a monochrome u8g2 display device |
| 64 | + * |
| 65 | + * @param[in,out] dev Device descriptor of the driver |
| 66 | + * @param[in] params Initialization parameters |
| 67 | + * |
| 68 | + * @retval 0 on success |
| 69 | + * @retval -1 on error |
| 70 | + * |
| 71 | + * @pre @p dev must not be `NULL` |
| 72 | + * @pre @p params must not be `NULL` |
| 73 | + */ |
| 74 | +int u8g2_display_init(u8g2_display_t *dev, const u8g2_display_params_t *params); |
| 75 | + |
| 76 | +#ifdef __cplusplus |
| 77 | +} |
| 78 | +#endif |
| 79 | + |
| 80 | +/** @} */ |
0 commit comments