Skip to content

Commit ec9548d

Browse files
pkg/u8g2: add disp_dev support
1 parent 787d687 commit ec9548d

File tree

15 files changed

+638
-77
lines changed

15 files changed

+638
-77
lines changed

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+
/** @} */
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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_params Default configuration for U8G2 displays
10+
* @ingroup u8g2_disp_dev
11+
*
12+
* These configuration parameters are used by @ref auto_init when the the integration of
13+
* @ref pkg_u8g2 to @ref drivers_disp_dev is enabled.
14+
*
15+
* @{
16+
* @file
17+
* @brief Default configuration
18+
*
19+
* @author Leandro Lanzieri <[email protected]>
20+
*/
21+
22+
#include "board.h"
23+
#include "u8g2_display.h"
24+
25+
#include "periph/i2c.h"
26+
#include "periph/spi.h"
27+
#include "periph/gpio.h"
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
/**
34+
* @name Default configuration parameters for u8g2 displays
35+
* @{
36+
*/
37+
/**
38+
* @brief Default I2C or SPI device.
39+
*
40+
* For I2C displays, set to the desired I2C bus using @ref I2C_DEV (e.g. `I2C_DEV(0)`).
41+
* For SPI displays, set to the desired SPI bus using @ref SPI_DEV (e.g. `SPI_DEV(0)`).
42+
*/
43+
#ifndef U8G2_DISPLAY_PARAM_DEV
44+
# define U8G2_DISPLAY_PARAM_DEV I2C_DEV(0)
45+
#endif
46+
47+
/**
48+
* @brief Default I2C address
49+
* @note Set to `0` when using SPI
50+
*/
51+
#ifndef U8G2_DISPLAY_PARAM_I2C_ADDR
52+
# define U8G2_DISPLAY_PARAM_I2C_ADDR (0x3c)
53+
#endif
54+
55+
/**
56+
* @brief Default SPI CS pin
57+
* @note Set to @ref GPIO_UNDEF when using I2C
58+
*/
59+
#ifndef U8G2_DISPLAY_PARAM_PIN_CS
60+
# define U8G2_DISPLAY_PARAM_PIN_CS GPIO_UNDEF
61+
#endif
62+
63+
/**
64+
* @brief Default SPI D/C pin
65+
* @note Set to @ref GPIO_UNDEF when using I2C
66+
*/
67+
#ifndef U8G2_DISPLAY_PARAM_PIN_DC
68+
# define U8G2_DISPLAY_PARAM_PIN_DC GPIO_UNDEF
69+
#endif
70+
71+
/**
72+
* @brief Default SPI Reset pin
73+
* @note Set to @ref GPIO_UNDEF when using I2C
74+
*/
75+
#ifndef U8G2_DISPLAY_PARAM_PIN_RESET
76+
# define U8G2_DISPLAY_PARAM_PIN_RESET GPIO_UNDEF
77+
#endif
78+
79+
/**
80+
* @brief Default U8G2 initialization function
81+
* @see Check the u8g2 reference for possible setup functions:
82+
* https://github.com/olikraus/u8g2/wiki/u8g2setupc#setup-function-reference
83+
*/
84+
#ifndef U8G2_DISPLAY_PARAM_INIT_FUNCTION
85+
# define U8G2_DISPLAY_PARAM_INIT_FUNCTION u8g2_Setup_ssd1306_i2c_128x64_noname_f
86+
#endif
87+
88+
/**
89+
* @brief Default configuration struct
90+
*/
91+
#ifndef U8G2_DISPLAY_PARAMS
92+
# define U8G2_DISPLAY_PARAMS \
93+
{ \
94+
.init_function = U8G2_DISPLAY_PARAM_INIT_FUNCTION, \
95+
.peripheral_configuration = { \
96+
.device_index = U8G2_DISPLAY_PARAM_DEV, \
97+
.pin_cs = U8G2_DISPLAY_PARAM_PIN_CS, \
98+
.pin_dc = U8G2_DISPLAY_PARAM_PIN_DC, \
99+
.pin_reset = U8G2_DISPLAY_PARAM_PIN_RESET, \
100+
}, \
101+
.i2c_address = U8G2_DISPLAY_PARAM_I2C_ADDR, \
102+
}
103+
#endif
104+
/**@}*/
105+
106+
/**
107+
* @brief Configuration struct
108+
*/
109+
static const u8g2_display_params_t u8g2_display_params[] =
110+
{
111+
U8G2_DISPLAY_PARAMS
112+
};
113+
114+
/**
115+
* @brief Default screen identifiers
116+
*/
117+
#ifndef U8G2_DISPLAY_PARAM_SCREEN_IDS
118+
# define U8G2_DISPLAY_PARAM_SCREEN_IDS 0
119+
#endif
120+
121+
/**
122+
* @brief Configure screen identifiers
123+
*/
124+
static const uint8_t u8g2_display_screen_ids[] =
125+
{
126+
U8G2_DISPLAY_PARAM_SCREEN_IDS,
127+
};
128+
129+
#ifdef __cplusplus
130+
}
131+
#endif
132+
133+
/** @} */

0 commit comments

Comments
 (0)