blob: 6c015dfcd36ed347219ce632761ee241a121f03d [file] [log] [blame]
// Copyright 2024 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include "pw_log/log.h"
#include "pw_string/string.h"
#define LED0_NODE DT_ALIAS(led0)
#define SLEEP_TIME_MS 1000
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
// Logs messages with pw_log and pw_string and blinks an LED using Zephyr's
// GPIO Driver API. Blinky logic is adapted from Zephyr's basic blinky sample:
// https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/basic/blinky
int main() {
pw::InlineString<32> greetings = "Hello, world!";
PW_LOG_INFO("%s", greetings.c_str());
int ret;
bool led_state = true;
if (!gpio_is_ready_dt(&led)) {
PW_LOG_ERROR("LED unavailable");
return 0;
}
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
PW_LOG_ERROR("LED configuration failed");
return 0;
}
while (true) {
ret = gpio_pin_toggle_dt(&led);
if (ret < 0) {
return 0;
}
led_state = !led_state;
PW_LOG_INFO("LED state: %s", led_state ? "ON" : "OFF");
k_msleep(SLEEP_TIME_MS);
}
return 0;
}