/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes */ #include #include "board.h" #define RT_DEVICE_CTRL_RTC_GET_COUNT 0x81 /**< get count */ #define LED_NUM 4 struct fm3_gpio_ctrl { uint32_t led_num; volatile uint32_t * PDOR; volatile uint32_t * PDIR; }; struct fm3_led { /* inherit from rt_device */ struct rt_device parent; struct fm3_gpio_ctrl fm3_gpio_ctrl[LED_NUM]; }; static struct fm3_led fm3_led; static rt_err_t rt_led_init (rt_device_t dev) { uint32_t i; /* led0 : P54 */ FM3_GPIO->PFR5 &= ~((1<<7) | (1<<6) | (1<<5) |(1<<4)); /* set P54 fuction is GPIO. */ FM3_GPIO->DDR5 |= (1<<7) | (1<<6) | (1<<5) |(1<<4); /* set P54 output. */ /* LED0 */ i = 0; fm3_led.fm3_gpio_ctrl[i].led_num = 4; fm3_led.fm3_gpio_ctrl[i].PDOR = &FM3_GPIO->PDOR5; fm3_led.fm3_gpio_ctrl[i].PDIR = &FM3_GPIO->PDIR5; /* LED1 */ i++; fm3_led.fm3_gpio_ctrl[i].led_num = 5; fm3_led.fm3_gpio_ctrl[i].PDOR = &FM3_GPIO->PDOR5; fm3_led.fm3_gpio_ctrl[i].PDIR = &FM3_GPIO->PDIR5; /* LED2 */ i++; fm3_led.fm3_gpio_ctrl[i].led_num = 6; fm3_led.fm3_gpio_ctrl[i].PDOR = &FM3_GPIO->PDOR5; fm3_led.fm3_gpio_ctrl[i].PDIR = &FM3_GPIO->PDIR5; /* LED3 */ i++; fm3_led.fm3_gpio_ctrl[i].led_num = 7; fm3_led.fm3_gpio_ctrl[i].PDOR = &FM3_GPIO->PDOR5; fm3_led.fm3_gpio_ctrl[i].PDIR = &FM3_GPIO->PDIR5; return RT_EOK; } static rt_err_t rt_led_open(rt_device_t dev, rt_uint16_t oflag) { return RT_EOK; } static rt_err_t rt_led_close(rt_device_t dev) { return RT_EOK; } static rt_size_t rt_led_read (rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { rt_ubase_t index = 0; rt_ubase_t nr = size; rt_uint8_t * value = buffer; RT_ASSERT(dev == &fm3_led.parent); RT_ASSERT((pos+size) <= LED_NUM ); for(index=0; index void led(rt_uint32_t led, rt_uint32_t value) { rt_uint8_t led_value = value; rt_led_write(&fm3_led.parent, led, &led_value, 1); } FINSH_FUNCTION_EXPORT(led, e.g:led(0,100).) #endif