---
title: "Display"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/drivers/display/
last_updated: 2026-11-17
sdk_version: 4.44
---
# Display

Source: https://developer.repebble.com/pebbleos/docs/samples/drivers/display/

This sample draws colour bars across the display, `DISPLAY`, and sends the whole frame with `pbl_display_update_sync()`. Three seconds later it draws a checkerboard over the lower third and sends only those rows with `pbl_display_update()`, which runs in the background and calls back from the display’s interrupt when done. The frame buffer is allocated to the size of the display, in its pixel format: one byte per pixel in colour, one bit in mono, where anything but black shows as white.

Watch the screen, on a watch or in the emulator’s window.

Run:

`pbl samples samples/drivers/display`

Boards:

every board

## Sources

src/main.c

```
#include \<errno.h\>#include \<stdint.h\>#include \<stdio.h\>#include \<string.h\>#include \<pbl/drivers/display.h\>#include \<pbl/kernel/delay.h\>#include \<pbl/kernel/malloc.h\>#include \<pbl/kernel/sem.h\>#define BARS 8#define SQUARE 16#define SHOW\_MS 3000/\* ARGB2222, opaque: red, green and blue from 0 to 3. \*/#define RGB(r, g, b) (0xC0U | ((r) \<\< 4) | ((g) \<\< 2) | (b))static const uint8\_t s\_bar\_colors[BARS] = {RGB(3, 3, 3), RGB(3, 3, 0), RGB(0, 3, 3), RGB(0, 3, 0),RGB(3, 0, 3), RGB(3, 0, 0), RGB(0, 0, 3), RGB(0, 0, 0),};static PBL\_SEM\_DEFINE(s\_done, 0, 1);static int s\_status;static void prv\_set\_pixel(const struct pbl\_display\_props \*props,const struct pbl\_display\_buffer \*fb, uint16\_t x, uint16\_t y,uint8\_t color) {uint8\_t \*row = &fb-\>data[y \* fb-\>pitch];if (props-\>format == PBL\_DISPLAY\_FORMAT\_ARGB2222) {row[x] = color;} else if ((color & 0x3FU) != 0U) {/\* Mono: anything but black is white, the leftmost pixel in the lowest bit. \*/row[x / 8U] |= (uint8\_t)(1U \<\< (x % 8U));} else {row[x / 8U] &= (uint8\_t)~(1U \<\< (x % 8U));}}static void prv\_draw\_bars(const struct pbl\_display\_props \*props,const struct pbl\_display\_buffer \*fb) {for (uint16\_t y = 0U; y \< props-\>height; y++) {for (uint16\_t x = 0U; x \< props-\>width; x++) {prv\_set\_pixel(props, fb, x, y, s\_bar\_colors[x \* BARS / props-\>width]);}}}static void prv\_draw\_checkerboard(const struct pbl\_display\_props \*props,const struct pbl\_display\_buffer \*fb, uint16\_t y0, uint16\_t y1) {for (uint16\_t y = y0; y \<= y1; y++) {for (uint16\_t x = 0U; x \< props-\>width; x++) {prv\_set\_pixel(props, fb, x, y,((x / SQUARE + y / SQUARE) % 2U) != 0U ? RGB(3, 3, 3) : RGB(0, 0, 0));}}}/\* Runs from the display's interrupt: only hand the result over. \*/static void prv\_update\_done(int status, void \*arg) {s\_status = status;pbl\_sem\_give(&s\_done);}int main(void) {/\* Size and pixel format: what a framebuffer for this display looks like. \*/const struct pbl\_display\_props \*props = pbl\_display\_get\_props(DISPLAY);bool mono = props-\>format == PBL\_DISPLAY\_FORMAT\_MONO;uint16\_t y0 = props-\>height \* 2U / 3U;uint16\_t y1 = props-\>height - 1U;struct pbl\_display\_buffer fb;int ret;printf("display: %dx%d, %s\n", props-\>width, props-\>height, mono ? "mono" : "argb2222");/\* The buffer is the whole frame: updates send rows of it, by their position on the display. \*/fb.pitch = mono ? (props-\>width + 7U) / 8U : props-\>width;fb.data = pbl\_zalloc(fb.pitch \* props-\>height);if (fb.data == nullptr) {fprintf(stderr, "display: no memory for a frame\n");return -ENOMEM;}prv\_draw\_bars(props, &fb);ret = pbl\_display\_update\_sync(DISPLAY, &fb, 0U, props-\>height - 1U);if (ret != 0) {fprintf(stderr, "display: update failed (%d)\n", ret);goto out;}printf("display: bars shown\n");pbl\_sleep\_ms(SHOW\_MS);/\* Only the rows that changed, in the background: the callback says when they are out. \*/prv\_draw\_checkerboard(props, &fb, y0, y1);ret = pbl\_display\_update(DISPLAY, &fb, y0, y1, prv\_update\_done, nullptr);if (ret == 0) {(void)pbl\_sem\_take(&s\_done, PBL\_FOREVER);ret = s\_status;}if (ret != 0) {fprintf(stderr, "display: update failed (%d)\n", ret);goto out;}printf("display: checkerboard shown\n");pbl\_sleep\_ms(SHOW\_MS);printf("Sample done\n");out:pbl\_free(fb.data);return ret;}
```

## Output

```
display: \d+x\d+, (mono|argb2222)
display: bars shown
display: checkerboard shown
Sample done
```

Generated from PebbleOS [9e782207f](https://github.com/coredevices/pebbleos/commit/9e782207f53f8f1c02f7b13ea40cdc092d7bab3d). This page is maintained in the pebbleos repository: [docs/samples/drivers/display.md](https://github.com/coredevices/pebbleos/blob/9e782207f53f8f1c02f7b13ea40cdc092d7bab3d/docs/samples/drivers/display.md).
