#include <zephyr.h>
#include <zephyr/types.h>
#include <sys/printk.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>
#include <stdint.h>
#include <stdbool.h>
#define LED_HEAD_PIN 7
#define LED_RESET_PIN 6
#define LED_BOOT_PIN 5
void main(void)
{
struct device *dev;
int ret;
int count = 0;
printk("mySooniLED start\n");
// get gpio0 device
dev = device_get_binding("GPIO_0");
if(dev == NULL)
{
printk("device_get_binding:error, GPIO_0\n");
return;
}
printk("device_get_binding:ok, GPIO_0\n");
// config led pin
ret = gpio_pin_configure(dev, LED_HEAD_PIN, GPIO_OUTPUT_HIGH);
if(ret != 0)
{
printk("gpio_pin_configure:error, %d\n", ret);
return;
}
ret = gpio_pin_configure(dev, LED_RESET_PIN, GPIO_OUTPUT_HIGH);
if(ret != 0)
{
printk("gpio_pin_configure:error, %d\n", ret);
return;
}
ret = gpio_pin_configure(dev, LED_BOOT_PIN, GPIO_OUTPUT_HIGH);
if(ret != 0)
{
printk("gpio_pin_configure:error, %d\n", ret);
return;
}
printk("gpio_pin_configure:ok\n");
// blink and printk
while(true)
{
count++;
printk("count=%d, time=%u\n", count, k_uptime_get_32());
gpio_pin_set_raw(dev, LED_HEAD_PIN, 0); // turn on
gpio_pin_set_raw(dev, LED_RESET_PIN, 1); // turn off
gpio_pin_set_raw(dev, LED_BOOT_PIN, 1); // turn off
k_msleep(200);
gpio_pin_set_raw(dev, LED_HEAD_PIN, 1); // turn off
gpio_pin_set_raw(dev, LED_RESET_PIN, 0); // turn on
gpio_pin_set_raw(dev, LED_BOOT_PIN, 1); // turn off
k_msleep(200);
gpio_pin_set_raw(dev, LED_HEAD_PIN, 1); // turn off
gpio_pin_set_raw(dev, LED_RESET_PIN, 1); // turn off
gpio_pin_set_raw(dev, LED_BOOT_PIN, 0); // turn on
k_msleep(200);
}
}