Zephyr Backlight Examples for PineTime
#1
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:

Code:
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,       {0}); 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,      {0}); 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",        button.port->name); return; } 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); return; } ret = gpio_pin_interrupt_configure_dt(&button,       GPIO_INT_EDGE_TO_ACTIVE); if (ret != 0) { printk("Error %d: failed to configure interrupt on %s pin %d\n", ret, button.port->name, button.pin); return; } ... }

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:

Code:
#if DT_NODE_HAS_STATUS(LED0_NODE, okay) #define LED0    DT_GPIO_LABEL(LED0_NODE, gpios) #define PIN     DT_GPIO_PIN(LED0_NODE, gpios) #define FLAGS   DT_GPIO_FLAGS(LED0_NODE, gpios) #endif 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:

Code:
/* ********** ********** DEFINES ********** ********** ********** */ #define BACKLIGHT_PORT  DT_GPIO_LABEL(DT_ALIAS(led1), gpios) #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); backlight_enable(true); 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.
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SlateOS for PineTime highjumpman 2 1,010 08-17-2026, 07:33 PM
Last Post: highjumpman
  Update pinetime bootloader OTA? oscar-gardiazabal 1 3,662 10-08-2025, 09:24 AM
Last Post: oscar-gardiazabal
  Pinetime - Kids with special needs hidara 0 2,801 06-11-2024, 10:42 PM
Last Post: hidara
  Develop a new firmware for PineTime belushi 2 5,768 09-25-2023, 12:32 PM
Last Post: ccchan234
  Bluetooth BLE-MIDI-controller app for PineTime / InfiniTime Luno 0 3,371 08-20-2023, 05:17 AM
Last Post: Luno
  Zephyr is ready for pinetime jandy 1 6,753 05-06-2023, 02:15 PM
Last Post: lcj
  Send a message from Android to pinetime via BLE razrosman 0 4,084 11-05-2022, 08:24 AM
Last Post: razrosman
  PineTime Stuck in DFU Mode Eesha Barua 1 6,658 07-25-2022, 09:17 PM
Last Post: heyhewmike
  Idle tracking with PineTime: how versatile it is? schaman 1 5,982 07-13-2022, 12:50 AM
Last Post: wibble
  PineTime implemented with partial of pebble API jandy 0 5,151 03-20-2022, 08:58 PM
Last Post: jandy

Forum Jump:


Users browsing this thread: 1 Guest(s)