I have a pit that reads if battery is charging or not, its defined as
zephyr,user {
battery-charge-gpios = <&gpio1 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
};
and reading it
#define ZEPHYR_USER DT_PATH(zephyr_user)
static const struct gpio_dt_spec sChargeGpio = GPIO_DT_SPEC_GET(ZEPHYR_USER, battery_charge_gpios);
bool battery_charging() {
return (bool)gpio_pin_get_dt(&sChargeGpio);
}and its working and I can blink on and off leds
&led0 {
gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
label = "Red LED 0";
status = "okay";
};
&led1 {
gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
label = "Green LED 1";
status = "okay";
};
&led2 {
gpios = <&gpio1 10 GPIO_ACTIVE_LOW>;
label = "Blue LED 2";
status = "okay";
};but I wanted to use PWM to fade them in and out
/ {
zephyr,user {
battery-charge-gpios = <&gpio1 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
};
pwmleds {
compatible = "pwm-leds";
pwm_led0: pwm_led_0 {
status = "okay";
pwms = <&pwm0 1 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
};
pwm_led1: pwm_led_1 {
status = "okay";
pwms = <&pwm0 2 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
};
pwm_led2: pwm_led_2 {
status = "okay";
pwms = <&pwm0 3 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
};
};
};
&led0 {
gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
label = "Red LED 0";
status = "okay";
};
&led1 {
gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
label = "Green LED 1";
status = "okay";
};
&led2 {
gpios = <&gpio1 10 GPIO_ACTIVE_LOW>;
label = "Blue LED 2";
status = "okay";
};
&pwm0_default {
group1 {
status = "okay";
psels = <NRF_PSEL(PWM_OUT1, 1, 6)>,
<NRF_PSEL(PWM_OUT2, 1, 8)>,
<NRF_PSEL(PWM_OUT3, 1, 10)>;
};
};
&pwm0 {
status = "okay";
pinctrl-0 = <&pwm0_default>;
pinctrl-1 = <&pwm0_sleep>;
pinctrl-names = "default", "sleep";
};
&pwm0_sleep {
group1 {
status = "okay";
psels = <NRF_PSEL(PWM_OUT1, 1, 6)>,
<NRF_PSEL(PWM_OUT2, 1, 8)>,
<NRF_PSEL(PWM_OUT3, 1, 10)>;
low-power-enable;
};
};#define NUM_STEPS 50U
#define SLEEP_MSEC 25U
static struct pwm_dt_spec current_led;
struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_NODELABEL(pwm_led0));
struct pwm_dt_spec pwm_led1 = PWM_DT_SPEC_GET(DT_NODELABEL(pwm_led1));
struct pwm_dt_spec pwm_led2 = PWM_DT_SPEC_GET(DT_NODELABEL(pwm_led2));
void init_pwm_leds() {
if (!device_is_ready(sChargeGpio.port)) {
printErr("VBAT Charging pin not accessable");
return;
}
bool test = gpio_pin_get_dt(&sChargeGpio);
printk(">>>>>>>> %d", test);
if (!device_is_ready(pwm_led0.dev) || !device_is_ready(pwm_led1.dev) || !device_is_ready(pwm_led2.dev)) {
printErr("Error: one or more PWM devices are not ready\n");
return;
}
printLargeInfo("PWM Leds and Charge Read pin Ready");
}
void turn_off_all_leds(void) {
pwm_set_pulse_dt(&pwm_led0, 0);
pwm_set_pulse_dt(&pwm_led1, 0);
pwm_set_pulse_dt(&pwm_led2, 0);
}
void set_constant_on_led(const struct pwm_dt_spec* spec) {
pwm_set_pulse_dt(spec, spec->period); // Set the LED to a constant ON state
}
and it works, I can fade my leds but now I cant get any read from is battery charging P1.1 gpio ?