Zephyr Backlight Examples for PineTime
This is a very junior question but I am just trying to get the backlight going using Zephyr, VS Code (with nRF Connect for VS Code Add-In), the PineTime DevKit0 board in Zephyr, and a PineTime DK.

I am trying to figure out how to do the backlight from the button example (which replaced the board specific example). I have not been able to get it working. It uses code like this:

static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,
static struct gpio_callback button_cb_data;

* The led0 devicetree alias is optional. If present, we'll use it
* to turn on the LED whenever the button is pressed.
static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,

void button_pressed(const struct device *dev, struct gpio_callback *cb,
            uint32_t pins)
    printk("Button pressed at %" PRIu32 "\n", k_cycle_get_32());

void main(void)
    int ret;

    if (!device_is_ready(button.port)) {
        printk("Error: button device %s is not ready\n",

    ret = gpio_pin_configure_dt(&button, GPIO_INPUT);
    if (ret != 0) {
        printk("Error %d: failed to configure %s pin %d\n",
               ret, button.port->name, button.pin);

    ret = gpio_pin_interrupt_configure_dt(&button,
    if (ret != 0) {
        printk("Error %d: failed to configure interrupt on %s pin %d\n",
            ret, button.port->name, button.pin);

These other examples:

pinetime-zephyr/main.c at master · najnesnaj/pinetime-zephyr · GitHub

[/url][url=https://github.com/albsod/pinetime-hypnos/blob/master/app/hypnos/src/backlight.c]pinetime-hypnos/backlight.c at master · albsod/pinetime-hypnos · GitHub

pinetime/backlight.c at develop · ck-telecom/pinetime · GitHub

Use code which looks like this:

#define LED0    DT_GPIO_LABEL(LED0_NODE, gpios)
#define PIN     DT_GPIO_PIN(LED0_NODE, gpios)
#define FLAGS   DT_GPIO_FLAGS(LED0_NODE, gpios)

static void backlight_init(void)
        const struct device *dev;

        dev = device_get_binding(LED0);
        /* If you have a backlight, set it up and turn it on here */
        gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
        gpio_pin_set(dev, PIN, 1);

or this:

/* ********** ********** DEFINES ********** ********** ********** */
#define BACKLIGHT_1     DT_GPIO_PIN(DT_ALIAS(led0), gpios)
#define BACKLIGHT_2     DT_GPIO_PIN(DT_ALIAS(led1), gpios)
#define BACKLIGHT_3     DT_GPIO_PIN(DT_ALIAS(led2), gpios)
/* ********** **********  ********** ********** ********** */

/* ********** ********** VARIABLES AND STRUCTS ********** ********** */
static const struct device* backlight_dev;
static bool backlight_enabled = false;
/* ********** ********** ********** ********** ********** ********** */

/* ********** ********** FUNCTIONS ********** ********** */
void backlight_init()
    backlight_dev = device_get_binding(BACKLIGHT_PORT);
    gpio_pin_configure(backlight_dev, BACKLIGHT_1, GPIO_OUTPUT);
    gpio_pin_configure(backlight_dev, BACKLIGHT_2, GPIO_OUTPUT);
    gpio_pin_configure(backlight_dev, BACKLIGHT_3, GPIO_OUTPUT);
    LOG_DBG("Backlight init: Done");

I guess my questions is should I try to use the GPIO_DT_SPEC_GET_OR syntax or DT_GPIO_PIN, DT_GPIO_LABEL, and DT_GPIO_FLAGS.

I'm really new at this, as you can probably tell. I might be mixing things up. Trying to figure out the GPIO to turn on/off the backlight and it seems like this commonly/historically used device* structure and the gpio_dt_spec from the examples.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Develop a new firmware for PineTime belushi 1 369 05-06-2023, 02:26 PM
Last Post: lcj
  Zephyr is ready for pinetime jandy 1 1,248 05-06-2023, 02:15 PM
Last Post: lcj
  Send a message from Android to pinetime via BLE razrosman 0 461 11-05-2022, 08:24 AM
Last Post: razrosman
  PineTime Stuck in DFU Mode Eesha Barua 1 1,165 07-25-2022, 09:17 PM
Last Post: heyhewmike
  Idle tracking with PineTime: how versatile it is? schaman 1 965 07-13-2022, 12:50 AM
Last Post: wibble
  PineTime implemented with partial of pebble API jandy 0 1,077 03-20-2022, 08:58 PM
Last Post: jandy
  "Pine64 USB JTAG Adapter + OpenOCD + PineTime" should it work? ITCactus 4 2,683 03-02-2022, 05:58 AM
Last Post: wibble
  Zephyr based Pinetime jandy 4 3,444 11-11-2021, 05:53 AM
Last Post: jandy
  Problems with pinetime watch face simulator Elements 0 1,550 08-18-2021, 03:05 PM
Last Post: Elements
  PineTime display and micropython danielt 17 19,336 05-07-2021, 12:15 PM
Last Post: danielt

Forum Jump:

Users browsing this thread: 1 Guest(s)