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 2 1,015 09-25-2023, 12:32 PM
Last Post: ccchan234
  Bluetooth BLE-MIDI-controller app for PineTime / InfiniTime Luno 0 364 08-20-2023, 05:17 AM
Last Post: Luno
  Zephyr is ready for pinetime jandy 1 1,869 05-06-2023, 02:15 PM
Last Post: lcj
  Send a message from Android to pinetime via BLE razrosman 0 799 11-05-2022, 08:24 AM
Last Post: razrosman
  PineTime Stuck in DFU Mode Eesha Barua 1 1,698 07-25-2022, 09:17 PM
Last Post: heyhewmike
  Idle tracking with PineTime: how versatile it is? schaman 1 1,421 07-13-2022, 12:50 AM
Last Post: wibble
  PineTime implemented with partial of pebble API jandy 0 1,419 03-20-2022, 08:58 PM
Last Post: jandy
  "Pine64 USB JTAG Adapter + OpenOCD + PineTime" should it work? ITCactus 4 3,541 03-02-2022, 05:58 AM
Last Post: wibble
  Zephyr based Pinetime jandy 4 4,294 11-11-2021, 05:53 AM
Last Post: jandy
  Problems with pinetime watch face simulator Elements 0 1,820 08-18-2021, 03:05 PM
Last Post: Elements

Forum Jump:

Users browsing this thread: 1 Guest(s)