This example shows how to use the Universal Graphics Library for 8 Bit Embedded Systems library to produce text and graphical elements using an on-board LCD. The example works with BSP430_PLATFORM_EXP430F5438, BSP430_PLATFORM_EXP430F5529, and BSP430_PLATFORM_TRXEB.
When built with SHARP96=1
it also works with the BSP430_PLATFORM_BOOSTERPACK_SHARP96. Note that these displays require a periodic refresh, which is supported using the BSP430 alarm infrastructure.
main.c
#include <string.h>
static u8g_t u8g_data;
#if (BSP430_U8GLIB_REFRESH_INTERVAL_MS - 0)
#ifndef REFRESH_ALARM_CCIDX
#define REFRESH_ALARM_CCIDX 1
#endif
typedef struct sRefreshTimerState {
unsigned long interval_tck;
u8g_t * u8g;
} sRefreshTimerState;
static sRefreshTimerState refresh_state;
static int
{
sRefreshTimerState * rtsp = (sRefreshTimerState *)alarm;
unsigned long setting_tck;
int rc;
int rv;
do {
setting_tck += rtsp->interval_tck;
} while (0 < rc);
return rv;
}
static int
enableRefreshTimer ()
{
int rc = 0;
if (0 == refresh_state.interval_tck) {
cprintf(
"Refresh timer defined but empty interval?");
return -1;
}
cprintf(
"Enable refresh every %lu ticks\n", refresh_state.interval_tck);
refresh_state.u8g = &u8g_data;
REFRESH_ALARM_CCIDX,
refresh_cb_ni);
if (ah) {
do {
if (0 == rc) {
}
} while (0);
}
if (0 != rc) {
cprintf(
"Failed to initialize alarm\n");
}
return rc;
}
#else
static int
enableRefreshTimer ()
{
cprintf(
"No refresh timer required\n");
return 0;
}
#endif
void main ()
{
int w;
int h;
int rc;
unsigned long t0;
unsigned long t1;
u8g_t * u8g = &u8g_data;
cprintf(
"\nBuild " __DATE__
" " __TIME__
"\n");
cprintf(
"U8G device initialization got %d\n", rc);
if (0 != enableRefreshTimer()) {
cprintf(
"ERROR: Unable to configure refresh timer\n");
return;
}
cprintf(
"Device size %u x %u, mode %d\n", u8g_GetWidth(u8g), u8g_GetHeight(u8g), u8g_GetMode(u8g));
u8g_SetDefaultForegroundColor(u8g);
u8g_SetFont(u8g, u8g_font_10x20);
w = u8g_GetFontBBXWidth(u8g);
h = u8g_GetFontBBXHeight(u8g);
cprintf(
"Font cell %u x %u\n", w, h);
u8g_FirstPage(u8g);
do {
u8g_DrawLine(u8g, 0, 0, u8g_GetWidth(u8g), u8g_GetHeight(u8g));
u8g_DrawStr(u8g, 0, h, __DATE__);
u8g_DrawStr(u8g, 0, 3*h, __TIME__);
} while (u8g_NextPage(u8g));
cprintf(
"Write screen took %lu ticks\n", t1-t0);
#if 0
{
unsigned int contrast;
cprintf(
"Cycling through contrast levels\n");
for (contrast = 0; contrast < 256; contrast += 16) {
u8g_SetContrast(u8g, contrast);
}
u8g_SetContrast(u8g, 22 << 2);
}
#endif
while (1) {
u8g_SleepOff(u8g);
u8g_SleepOn(u8g);
}
}
bsp430_config.h
#define BSP430_PLATFORM_BOOT_CONFIGURE_LFXT1 1
#define configBSP430_PLATFORM_SPIN_FOR_JUMPER 1
#define configBSP430_CONSOLE 1
#define configBSP430_UPTIME 1
#define configBSP430_UTILITY_U8GLIB 1
#define configBSP430_PLATFORM_PERIPHERAL_HELP 1
Makefile
# For SHARP96 boosterpack: SHARP96=1
# For LS013B7DH03: SHARP96=1 COLS=128 ROWS=128
# For LS027B7DH01: SHARP96=1 COLS=400 ROWS=240 WITH_WIDE_U8G=1
TEST_PLATFORMS=trxeb exp430f5438 exp430f5529
SHARP96 ?=
U8GLIB_ROOT ?= /opt/u8glib
U8GLIB_CSRC = $(U8GLIB_ROOT)/csrc
AUX_CPPFLAGS = -I$(U8GLIB_CSRC)
ifneq (,$(COLS))
AUX_CPPFLAGS += -DBSP430_PLATFORM_SHARPLCD_COLUMNS=$(COLS)
endif # COLS
ifneq (,$(ROWS))
AUX_CPPFLAGS += -DBSP430_PLATFORM_SHARPLCD_ROWS=$(ROWS)
endif # ROWS
WITH_WIDE_U8G ?=
ifneq (,$(WITH_WIDE_U8G))
# Required when $(COLS) > 255
AUX_CPPFLAGS += -DU8G_16BIT
endif # WITH_WIDE_U8G
PLATFORM ?= trxeb
MODULES=$(MODULES_PLATFORM)
MODULES += $(MODULES_UPTIME)
MODULES += $(MODULES_CONSOLE)
MODULES += $(MODULES_SERIAL)
MODULES += periph/port
ifneq (,$(SHARP96))
AUX_CPPFLAGS += -DconfigBSP430_PLATFORM_BOOSTERPACK_SHARP96=1
VPATH += $(BSP430_ROOT)/src/boosterpack/sharp96
MODULES += utility/sharplcd
PLATFORM_U8G_PB_C ?= $(U8GLIB_CSRC)/u8g_pb8h1.c
endif # SHARP96
U8GLIB_SRC = \
$(U8GLIB_CSRC)/u8g_com_api.c \
$(U8GLIB_CSRC)/u8g_ll_api.c \
$(U8GLIB_CSRC)/u8g_font.c \
$(U8GLIB_CSRC)/u8g_line.c \
$(U8GLIB_CSRC)/u8g_clip.c \
$(U8GLIB_CSRC)/u8g_page.c \
$(U8GLIB_CSRC)/u8g_state.c \
$(U8GLIB_CSRC)/u8g_pb.c \
$(PLATFORM_U8G_PB_C) \
$(U8GLIB_ROOT)/fntsrc/u8g_font_10x20.c
SRC = $(U8GLIB_SRC) u8g_bsp430.c main.c
include $(BSP430_ROOT)/make/Makefile.common