I'm trying to adapt the MQTT example to use the NMOS outputs.
I managed to use LED:s as output with no issues, but I'm not getting any response from NMOS pins. I also checked that there is no response in TP32.
This is the overlay I'm trying to use:
&pwm2 { status="disabled"; }; / { outs { status = "okay"; compatible = "gpio-leds"; out_1: led_1 { gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; label = "channel0"; }; out_2: led_2 { gpios = <&gpio0 14 GPIO_ACTIVE_LOW>; label = "channel1"; }; }; aliases { out1=&out_1; out2=&out_2; }; };
And I've adapted the led.c like this:
/* * Copyright (c) 2023 Nordic Semiconductor ASA * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ #include <zephyr/kernel.h> #include <zephyr/logging/log.h> #include <zephyr/zbus/zbus.h> #include <zephyr/drivers/led.h> #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/pwm.h> #include "message_channel.h" /* Register log module */ LOG_MODULE_REGISTER(led, CONFIG_MQTT_SAMPLE_LED_LOG_LEVEL); #define OUT1 DT_NODELABEL(out_1) #define OUT1_DEV DT_PHANDLE(OUT1,gpios) #define OUT1_PIN DT_PHA(OUT1,gpios,pin) #define OUT1_FLAGS DT_PHA(OUT1,gpios,flags) #define PWM_CH0_PIN DT_PROP(DT_NODELABEL(outs), ch0_pin) const static struct device *led_device = DEVICE_DT_GET_ANY(gpio_leds); const static struct device *nmos_device = DEVICE_DT_GET(OUT1_DEV); /* LED 1, green on Thingy:91 boards. */ #define LED_1_GREEN 1 void led_callback(const struct zbus_channel *chan) { int err = 0; const enum network_status *status; //const struct device *nmos_device = device_get_binding(DT_ALIAS_OUT0_GPIOS_CONTROLLER); if (&NETWORK_CHAN == chan) { if (!device_is_ready(led_device)) { LOG_ERR("LED device is not ready"); return; } if (!device_is_ready(nmos_device)) { LOG_ERR("nmos device is not ready"); return; } err=gpio_pin_configure(nmos_device, OUT1_PIN, OUT1_FLAGS); if (err) { LOG_ERR("gpio config err, error: %d", err); } /* Get network status from channel. */ status = zbus_chan_const_msg(chan); switch (*status) { case NETWORK_CONNECTED: err = led_on(led_device, LED_1_GREEN); if (err) { LOG_ERR("led_on, error: %d", err); } break; case NETWORK_DISCONNECTED: err = led_off(led_device, LED_1_GREEN); if (err) { LOG_ERR("led_off, error: %d", err); } break; case CHANNEL1_ON: err = led_on(led_device, 2); if (err) { LOG_ERR("led_off, error: %d", err); } err=gpio_pin_set(nmos_device,OUT1_PIN,1); //err = led_on(nmos_device, 1); if (err) { LOG_ERR("pin set, error: %d", err); } break; case CHANNEL1_OFF: err = led_off(led_device, 2); err=gpio_pin_set(nmos_device,OUT1_PIN,0); if (err) { LOG_ERR("pin off, error: %d", err); } break; default: LOG_ERR("Unknown event: %d", *status); break; } } } ZBUS_LISTENER_DEFINE(led, led_callback);
So what could be the issue?