Skip to content

Commit f72ddd7

Browse files
authored
Merge pull request #21725 from leandrolanzieri/pr/u8g2_disp_dev
pkg/u8g2: implement `disp_dev`
2 parents bbd258d + ec9548d commit f72ddd7

File tree

16 files changed

+639
-78
lines changed

16 files changed

+639
-78
lines changed

drivers/include/disp_dev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ typedef struct {
9494
/**
9595
* @brief Invert the display device colors
9696
*
97-
* @param[in] dev Network device descriptor
97+
* @param[in] dev Pointer to the display device
9898
* @param[in] invert Invert mode (true if invert, false otherwise)
9999
*/
100100
void (*set_invert)(const disp_dev_t *dev, bool invert);

pkg/u8g2/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PKG_LICENSE=BSD-2-Clause
55

66
include $(RIOTBASE)/pkg/pkg.mk
77

8-
all: $(filter u8g2_%,$(filter-out u8g2_csrc%, $(USEMODULE)))
8+
all: $(filter u8g2_%,$(filter-out u8g2_csrc% u8g2_disp_dev, $(USEMODULE)))
99
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/csrc -f $(CURDIR)/Makefile.$(PKG_NAME)_csrc
1010

1111
u8g2_%:

pkg/u8g2/Makefile.dep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ FEATURES_REQUIRED += periph_gpio
55

66
USEMODULE += u8g2_csrc_riot
77
USEMODULE += u8g2_csrc
8+
9+
ifneq (,$(filter disp_dev,$(USEMODULE)))
10+
USEMODULE += u8g2_disp_dev
11+
endif

pkg/u8g2/Makefile.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
INCLUDES += -I$(PKGDIRBASE)/u8g2/csrc
22
INCLUDES += -I$(RIOTBASE)/pkg/u8g2/contrib
3+
INCLUDES += -I$(RIOTBASE)/pkg/u8g2/contrib/disp_dev/include
34

45
DIRS += $(RIOTBASE)/pkg/u8g2/contrib
56

pkg/u8g2/README.md

Lines changed: 0 additions & 55 deletions
This file was deleted.

pkg/u8g2/contrib/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
MODULE = u8g2_csrc_riot
22

3+
ifneq (,$(filter u8g2_disp_dev,$(USEMODULE)))
4+
DIRS += $(RIOTBASE)/pkg/u8g2/contrib/disp_dev
5+
endif
6+
37
include $(RIOTBASE)/Makefile.base

pkg/u8g2/contrib/disp_dev/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MODULE = u8g2_disp_dev
2+
3+
# Check that either I2C or SPI are there (only supported peripherals)
4+
SUPPORTED_PERIPHERALS := periph_i2c periph_spi
5+
ifeq (,$(filter $(SUPPORTED_PERIPHERALS),$(USEMODULE)))
6+
$(info u8g2_disp_dev requires either I2C or SPI to work.)
7+
$(error Please check your display and correspondingly add any of $(SUPPORTED_PERIPHERALS))
8+
endif
9+
10+
include $(RIOTBASE)/Makefile.base
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
USEMODULE_INCLUDES_u8g2_disp_dev := $(LAST_MAKEFILEDIR)/include
2+
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_u8g2_disp_dev)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
/** @} */
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 HAW Hamburg
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
#pragma once
7+
8+
/**
9+
* @ingroup u8g2_disp_dev
10+
* @{
11+
*
12+
* @file
13+
* @brief Definition of the driver for the disp_dev generic interface
14+
*
15+
* @author Leandro Lanzieri <[email protected]>
16+
*/
17+
18+
#include "disp_dev.h"
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/**
25+
* @brief Reference to the display device driver struct
26+
*/
27+
extern const disp_dev_driver_t u8g2_display_disp_dev_driver;
28+
29+
#ifdef __cplusplus
30+
}
31+
#endif
32+
33+
/** @} */

0 commit comments

Comments
 (0)