PINE64
Zephyr Backlight Examples for PineTime - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: PineTime (https://forum.pine64.org/forumdisplay.php?fid=134)
+--- Forum: Development Discussion on PineTime (https://forum.pine64.org/forumdisplay.php?fid=136)
+--- Thread: Zephyr Backlight Examples for PineTime (/showthread.php?tid=18206)



Zephyr Backlight Examples for PineTime - lcj - 05-06-2023

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.