samples: lwm2m_client: Convert to use gpio_dt_spec
Move sample to use gpio_dt_spec for GPIO access. Signed-off-by: Kumar Gala <galak@kernel.org>
This commit is contained in:
parent
91f659d70a
commit
9ceeb3a0ae
|
@ -51,16 +51,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
|||
|
||||
#define ENDPOINT_LEN 32
|
||||
|
||||
#if DT_NODE_HAS_STATUS(DT_ALIAS(led0), okay)
|
||||
#define LED_GPIO_PORT DT_GPIO_LABEL(DT_ALIAS(led0), gpios)
|
||||
#define LED_GPIO_PIN DT_GPIO_PIN(DT_ALIAS(led0), gpios)
|
||||
#define LED_GPIO_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)
|
||||
#else
|
||||
/* Not an error; the relevant IPSO object will simply not be created. */
|
||||
#define LED_GPIO_PORT ""
|
||||
#define LED_GPIO_PIN 0
|
||||
#define LED_GPIO_FLAGS 0
|
||||
#endif
|
||||
/* If led0 gpios doesn't exist the relevant IPSO object will simply not be created. */
|
||||
static const struct gpio_dt_spec led_gpio = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios, {});
|
||||
|
||||
static uint8_t bat_idx = LWM2M_DEVICE_PWR_SRC_TYPE_BAT_INT;
|
||||
static int bat_mv = 3800;
|
||||
|
@ -73,7 +65,6 @@ static uint8_t bat_status = LWM2M_DEVICE_BATTERY_STATUS_CHARGING;
|
|||
static int mem_free = 15;
|
||||
static int mem_total = 25;
|
||||
|
||||
static const struct device *led_dev;
|
||||
static uint32_t led_state;
|
||||
|
||||
static struct lwm2m_ctx client;
|
||||
|
@ -111,7 +102,7 @@ static int led_on_off_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_ins
|
|||
|
||||
led_val = *(uint8_t *) data;
|
||||
if (led_val != led_state) {
|
||||
ret = gpio_pin_set(led_dev, LED_GPIO_PIN, (int) led_val);
|
||||
ret = gpio_pin_set_dt(&led_gpio, (int) led_val);
|
||||
if (ret) {
|
||||
/*
|
||||
* We need an extra hook in LWM2M to better handle
|
||||
|
@ -119,7 +110,7 @@ static int led_on_off_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_ins
|
|||
* post_write_cb, as there is not much that can be
|
||||
* done here.
|
||||
*/
|
||||
LOG_ERR("Fail to write to GPIO %d", LED_GPIO_PIN);
|
||||
LOG_ERR("Fail to write to GPIO %d", led_gpio.pin);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -135,13 +126,11 @@ static int init_led_device(void)
|
|||
{
|
||||
int ret;
|
||||
|
||||
led_dev = device_get_binding(LED_GPIO_PORT);
|
||||
if (!led_dev) {
|
||||
if (!device_is_ready(led_gpio.port)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = gpio_pin_configure(led_dev, LED_GPIO_PIN, LED_GPIO_FLAGS |
|
||||
GPIO_OUTPUT_INACTIVE);
|
||||
ret = gpio_pin_configure_dt(&led_gpio, GPIO_OUTPUT_INACTIVE);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue