Browse Source

[BSP][all ls1c]change license to Apache-2.0
[BSP][ls1c] add rtc library
[BSP][ls1c] add pwm ,touch , rtc driver

sundm75 6 years ago
parent
commit
029e161f59
65 changed files with 2053 additions and 1097 deletions
  1. 25 0
      bsp/ls1cdev/Kconfig
  2. 3 16
      bsp/ls1cdev/applications/main.c
  3. 0 4
      bsp/ls1cdev/drivers/SConscript
  4. 2 13
      bsp/ls1cdev/drivers/board.c
  5. 4 8
      bsp/ls1cdev/drivers/board.h
  6. 167 182
      bsp/ls1cdev/drivers/display_controller.c
  7. 6 10
      bsp/ls1cdev/drivers/display_controller.h
  8. 6 20
      bsp/ls1cdev/drivers/drv_can.c
  9. 2 16
      bsp/ls1cdev/drivers/drv_can.h
  10. 2 16
      bsp/ls1cdev/drivers/drv_gpio.c
  11. 2 16
      bsp/ls1cdev/drivers/drv_gpio.h
  12. 8 22
      bsp/ls1cdev/drivers/drv_i2c.c
  13. 3 20
      bsp/ls1cdev/drivers/drv_i2c.h
  14. 178 0
      bsp/ls1cdev/drivers/drv_pwm.c
  15. 16 0
      bsp/ls1cdev/drivers/drv_pwm.h
  16. 177 0
      bsp/ls1cdev/drivers/drv_rtc.c
  17. 19 0
      bsp/ls1cdev/drivers/drv_rtc.h
  18. 6 20
      bsp/ls1cdev/drivers/drv_spi.h
  19. 202 0
      bsp/ls1cdev/drivers/drv_touch.c
  20. 51 0
      bsp/ls1cdev/drivers/drv_touch.h
  21. 408 0
      bsp/ls1cdev/drivers/drv_touch_gt9xx.c
  22. 36 19
      bsp/ls1cdev/drivers/drv_uart.c
  23. 2 16
      bsp/ls1cdev/drivers/drv_uart.h
  24. 17 31
      bsp/ls1cdev/drivers/hw_i2c.c
  25. 2 16
      bsp/ls1cdev/drivers/hw_i2c.h
  26. 6 0
      bsp/ls1cdev/drivers/net/SConscript
  27. 2 16
      bsp/ls1cdev/drivers/net/mii.c
  28. 2 16
      bsp/ls1cdev/drivers/net/mii.h
  29. 2 16
      bsp/ls1cdev/drivers/net/synopGMAC.c
  30. 2 16
      bsp/ls1cdev/drivers/net/synopGMAC.h
  31. 2 28
      bsp/ls1cdev/drivers/net/synopGMAC_Dev.c
  32. 2 27
      bsp/ls1cdev/drivers/net/synopGMAC_Dev.h
  33. 2 16
      bsp/ls1cdev/drivers/net/synopGMAC_Host.h
  34. 2 16
      bsp/ls1cdev/drivers/net/synopGMAC_debug.h
  35. 2 25
      bsp/ls1cdev/drivers/net/synopGMAC_network_interface.h
  36. 2 29
      bsp/ls1cdev/drivers/net/synopGMAC_plat.c
  37. 2 28
      bsp/ls1cdev/drivers/net/synopGMAC_plat.h
  38. 2 16
      bsp/ls1cdev/drivers/net/synopGMAC_types.h
  39. 105 118
      bsp/ls1cdev/drivers/touch.c
  40. 2 16
      bsp/ls1cdev/drivers/touch.h
  41. 6 19
      bsp/ls1cdev/libraries/ls1c_can.c
  42. 3 18
      bsp/ls1cdev/libraries/ls1c_can.h
  43. 25 21
      bsp/ls1cdev/libraries/ls1c_clock.c
  44. 7 3
      bsp/ls1cdev/libraries/ls1c_clock.h
  45. 17 8
      bsp/ls1cdev/libraries/ls1c_delay.c
  46. 9 2
      bsp/ls1cdev/libraries/ls1c_delay.h
  47. 48 40
      bsp/ls1cdev/libraries/ls1c_gpio.c
  48. 9 0
      bsp/ls1cdev/libraries/ls1c_gpio.h
  49. 2 16
      bsp/ls1cdev/libraries/ls1c_i2c.c
  50. 2 16
      bsp/ls1cdev/libraries/ls1c_i2c.h
  51. 10 0
      bsp/ls1cdev/libraries/ls1c_pin.c
  52. 10 0
      bsp/ls1cdev/libraries/ls1c_pin.h
  53. 10 0
      bsp/ls1cdev/libraries/ls1c_public.c
  54. 34 24
      bsp/ls1cdev/libraries/ls1c_public.h
  55. 10 6
      bsp/ls1cdev/libraries/ls1c_pwm.c
  56. 9 0
      bsp/ls1cdev/libraries/ls1c_pwm.h
  57. 12 0
      bsp/ls1cdev/libraries/ls1c_regs.h
  58. 102 0
      bsp/ls1cdev/libraries/ls1c_rtc.c
  59. 41 0
      bsp/ls1cdev/libraries/ls1c_rtc.h
  60. 8 23
      bsp/ls1cdev/libraries/ls1c_spi.c
  61. 44 58
      bsp/ls1cdev/libraries/ls1c_spi.h
  62. 108 7
      bsp/ls1cdev/libraries/ls1c_timer.c
  63. 28 8
      bsp/ls1cdev/libraries/ls1c_timer.h
  64. 9 0
      bsp/ls1cdev/libraries/ls1c_uart.c
  65. 9 0
      bsp/ls1cdev/libraries/ls1c_uart.h

+ 25 - 0
bsp/ls1cdev/Kconfig

@@ -27,6 +27,9 @@ if RT_USING_SERIAL
 config RT_USING_UART2
     bool "Using RT_USING_UART2"
     default y      
+config RT_USING_UART1
+    bool "Using RT_USING_UART1"
+    default y      
 
 config RT_UART_RX_BUFFER_SIZE
     int "The rx buffer size"        
@@ -80,4 +83,26 @@ config RT_CAN_USING_HDR
     default y  
 endif    
 
+choice
+    prompt "Touch format"
+    default NO_TOUCH
+
+    config NO_TOUCH
+        bool "with no touch"	
+		
+if RT_USING_RTGUI
+    config XPT2046_USING_TOUCH
+        bool "with XPT2046 touch"
+endif    
+
+    config TINA_USING_TOUCH
+        bool "with TINA touch"		
+endchoice
+
+if RT_USING_RTC
+config RT_RTC_NAME
+    string "RT_RTC_NAME"
+    default "RTC" 
+endif    
+
     

+ 3 - 16
bsp/ls1cdev/applications/main.c

@@ -1,21 +1,7 @@
 /*
- * File      : main.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2008 - 2017, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes
@@ -26,5 +12,6 @@
 
 int main(int argc, char** argv)
 {   
+
     return 0;
 }

+ 0 - 4
bsp/ls1cdev/drivers/SConscript

@@ -5,10 +5,6 @@ src = Glob('*.c')
 
 CPPPATH = [cwd]
 
-
-if GetDepend('RT_USING_RTGUI') == False:
-    SrcRemove(src, 'touch.c')
-
 group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
 
 objs = []

+ 2 - 13
bsp/ls1cdev/drivers/board.c

@@ -1,11 +1,7 @@
 /*
- * File      : board.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006-2012, RT-Thread Develop Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes
@@ -33,13 +29,6 @@ extern void rt_hw_cache_init(void);
 extern void invalidate_writeback_dcache_all(void);
 extern void invalidate_icache_all(void);
 
-
-/**
- * @addtogroup Loongson LS1B
- */
- 
-/*@{*/
-
 /**
  * This is the timer interrupt service routine.
  */

+ 4 - 8
bsp/ls1cdev/drivers/board.h

@@ -1,11 +1,7 @@
 /*
- * File      : board.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006-2012, RT-Thread Develop Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date                Author         Notes
@@ -20,7 +16,7 @@
 void rt_hw_board_init(void);
 
 /* 32M SDRAM */
-#define RT_HW_HEAP_END	(0x80000000 + 32 * 1024 * 1024)
-#define CPU_HZ			(252 * 1000000)
+#define RT_HW_HEAP_END    (0x80000000 + 32 * 1024 * 1024)
+#define CPU_HZ            (252 * 1000000)
 
 #endif

+ 167 - 182
bsp/ls1cdev/drivers/display_controller.c

@@ -1,59 +1,44 @@
 /*
- * File      :display_controller.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
- * Date           Author       	Notes
+ * Date           Author           Notes
  * 2011-08-09     lgnq         first version for LS1B DC
  * 2015-07-06    chinesebear   modified for loongson 1c
  * 2018-01-06    sundm75       modified for smartloong 
  */
+ #include <rtthread.h>
 
-#include <rtthread.h>
 #include "display_controller.h"
 #include "../../libraries/ls1c_pwm.h"
 #include "../../libraries/ls1c_public.h"
 #include "../../libraries/ls1c_gpio.h"
 #include "../../libraries/ls1c_pin.h"
 
-#ifdef RT_USING_RTGUI
-
+#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
 struct vga_struct vga_mode[] =
 {
-	{/*"480x272_60.00"*/    111000,   480,    482,    523,    525,    272,    274,    284,    286,    },
-	{/*"640x480_70.00"*/    28560,  640,    664,    728,    816,    480,    481,    484,    500,    },
-	{/*"640x640_60.00"*/	33100,	640,	672,	736,	832,	640,	641,	644,	663,	},
-	{/*"640x768_60.00"*/	39690,	640,	672,	736,	832,	768,	769,	772,	795,	},
-	{/*"640x800_60.00"*/	42130,	640,	680,	744,	848,	800,	801,	804,	828,	},
-	{/*"800x480_70.00"*/    35840,  800,    832,    912,    1024,   480,    481,    484,    500,    },
-	{/*"800x600_60.00"*/	38220,	800,	832,	912,	1024,	600,	601,	604,	622,	},
-	{/*"800x640_60.00"*/	40730,	800,	832,	912,	1024,	640,	641,	644,	663,	},
-	{/*"832x600_60.00"*/	40010,	832,	864,	952,	1072,	600,	601,	604,	622,	},
-	{/*"832x608_60.00"*/	40520,	832,	864,	952,	1072,	608,	609,	612,	630,	},
-	{/*"1024x480_60.00"*/	38170,	1024,	1048,	1152,	1280,	480,	481,	484,	497,	},
-	{/*"1024x600_60.00"*/	48960,	1024,	1064,	1168,	1312,	600,	601,	604,	622,	},
-	{/*"1024x640_60.00"*/	52830,	1024,	1072,	1176,	1328,	640,	641,	644,	663,	},
-	{/*"1024x768_60.00"*/	64110,	1024,	1080,	1184,	1344,	768,	769,	772,	795,	},
-	{/*"1152x764_60.00"*/   71380,  1152,   1208,   1328,   1504,   764,    765,    768,    791,    },
-	{/*"1280x800_60.00"*/   83460,  1280,   1344,   1480,   1680,   800,    801,    804,    828,    },
-	{/*"1280x1024_55.00"*/  98600,  1280,   1352,   1488,   1696,   1024,   1025,   1028,   1057,   },
-	{/*"1440x800_60.00"*/   93800,  1440,   1512,   1664,   1888,   800,    801,    804,    828,    },
-	{/*"1440x900_67.00"*/   120280, 1440,   1528,   1680,   1920,   900,    901,    904,    935,    },
+    {/*"480x272_60.00"*/    111000,   480,    482,    523,    525,    272,    274,    284,    286,    },
+    {/*"640x480_70.00"*/    28560,  640,    664,    728,    816,    480,    481,    484,    500,    },
+    {/*"640x640_60.00"*/    33100,    640,    672,    736,    832,    640,    641,    644,    663,    },
+    {/*"640x768_60.00"*/    39690,    640,    672,    736,    832,    768,    769,    772,    795,    },
+    {/*"640x800_60.00"*/    42130,    640,    680,    744,    848,    800,    801,    804,    828,    },
+    {/*"800x480_70.00"*/    35840,  800,    832,    912,    1024,   480,    481,    484,    500,    },
+    {/*"800x600_60.00"*/    38220,    800,    832,    912,    1024,    600,    601,    604,    622,    },
+    {/*"800x640_60.00"*/    40730,    800,    832,    912,    1024,    640,    641,    644,    663,    },
+    {/*"832x600_60.00"*/    40010,    832,    864,    952,    1072,    600,    601,    604,    622,    },
+    {/*"832x608_60.00"*/    40520,    832,    864,    952,    1072,    608,    609,    612,    630,    },
+    {/*"1024x480_60.00"*/    38170,    1024,    1048,    1152,    1280,    480,    481,    484,    497,    },
+    {/*"1024x600_60.00"*/    48960,    1024,    1064,    1168,    1312,    600,    601,    604,    622,    },
+    {/*"1024x640_60.00"*/    52830,    1024,    1072,    1176,    1328,    640,    641,    644,    663,    },
+    {/*"1024x768_60.00"*/    64110,    1024,    1080,    1184,    1344,    768,    769,    772,    795,    },
+    {/*"1152x764_60.00"*/   71380,  1152,   1208,   1328,   1504,   764,    765,    768,    791,    },
+    {/*"1280x800_60.00"*/   83460,  1280,   1344,   1480,   1680,   800,    801,    804,    828,    },
+    {/*"1280x1024_55.00"*/  98600,  1280,   1352,   1488,   1696,   1024,   1025,   1028,   1057,   },
+    {/*"1440x800_60.00"*/   93800,  1440,   1512,   1664,   1888,   800,    801,    804,    828,    },
+    {/*"1440x900_67.00"*/   120280, 1440,   1528,   1680,   1920,   900,    901,    904,    935,    },
 };
 
 ALIGN(16)
@@ -64,174 +49,174 @@ static void pwminit(void)
 {
     pwm_info_t pwm_info;
     pwm_info.gpio = LS1C_PWM0_GPIO06;           // pwm引脚位gpio06
-    pwm_info.mode = PWM_MODE_NORMAL;         // 正常模式--连续输出pwm波形
-    pwm_info.duty = 0.85;                                   // pwm占空比 85%
-    pwm_info.period_ns = 5*1000*1000;              // pwm周期5ms
+    pwm_info.mode = PWM_MODE_NORMAL;            // 正常模式--连续输出pwm波形
+    pwm_info.duty = 0.85;                       // pwm占空比 85%
+    pwm_info.period_ns = 5*1000*1000;            // pwm周期5ms
 
-	/*pwm初始化,初始化后立即产生pwm波形*/
-	pwm_init(&pwm_info);
+    /*pwm初始化,初始化后立即产生pwm波形*/
+    pwm_init(&pwm_info);
 
-	/* 使能pwm */
-	pwm_enable(&pwm_info);
+    /* 使能pwm */
+    pwm_enable(&pwm_info);
 }
 int caclulate_freq(rt_uint32_t  XIN, rt_uint32_t PCLK)
 {
-	rt_uint32_t divider_int;
-	rt_uint32_t needed_pixclk;
-	rt_uint32_t  pll_clk, pix_div;
-	rt_uint32_t  regval;
-
-
-	pll_clk = PLL_FREQ; // 读CPU的 PLL及SDRAM 分频系数
-	pll_clk =( pll_clk>>8 )& 0xff;
-	pll_clk = XIN *  pll_clk / 4 ;
-	pix_div = PLL_DIV_PARAM;//读CPU的 CPU/CAMERA/DC 分频系数
-	pix_div = (pix_div>>24)&0xff;
-	rt_kprintf("old pll_clk=%d, pix_div=%d\n", pll_clk, pix_div);
-
-	divider_int = pll_clk/(1000000) *PCLK/1000; 
-	if(divider_int%1000>=500)
-		divider_int = divider_int/1000+1;
-	else
-		divider_int = divider_int/1000;
-	rt_kprintf("divider_int = %d\n", divider_int);
-	
-	/* check whether divisor is too small. */
-	if (divider_int < 1) {
-		rt_kprintf("Warning: clock source is too slow.Try smaller resolution\n");
-		divider_int = 1;
-	}
-	else if(divider_int > 100) {
-		rt_kprintf("Warning: clock source is too fast.Try smaller resolution\n");
-		divider_int = 100;
-	}
-	/* 配置分频寄存器 */
-	{
-		rt_uint32_t regval = 0;
-		regval = PLL_DIV_PARAM;
-		/*首先需要把分频使能位清零 */
-		regval &= ~0x80000030;	//PIX_DIV_VALID  PIX_SEL  置0
-		regval &= ~(0x3f<<24);	//PIX_DIV 清零
-		regval |= divider_int << 24;
-		PLL_DIV_PARAM = regval; 
-		regval |= 0x80000030;	//PIX_DIV_VALID  PIX_SEL  置1
-		PLL_DIV_PARAM = regval; 
-	}
-	rt_kprintf("new PLL_FREQ=0x%x, PLL_DIV_PARAM=0x%x\n", PLL_FREQ, PLL_DIV_PARAM);
-	rt_thread_delay(10);
-	return 0;
+    rt_uint32_t divider_int;
+    rt_uint32_t needed_pixclk;
+    rt_uint32_t  pll_clk, pix_div;
+    rt_uint32_t  regval;
+
+
+    pll_clk = PLL_FREQ; // 读CPU的 PLL及SDRAM 分频系数
+    pll_clk =( pll_clk>>8 )& 0xff;
+    pll_clk = XIN *  pll_clk / 4 ;
+    pix_div = PLL_DIV_PARAM;//读CPU的 CPU/CAMERA/DC 分频系数
+    pix_div = (pix_div>>24)&0xff;
+    rt_kprintf("old pll_clk=%d, pix_div=%d\n", pll_clk, pix_div);
+
+    divider_int = pll_clk/(1000000) *PCLK/1000; 
+    if(divider_int%1000>=500)
+        divider_int = divider_int/1000+1;
+    else
+        divider_int = divider_int/1000;
+    rt_kprintf("divider_int = %d\n", divider_int);
+    
+    /* check whether divisor is too small. */
+    if (divider_int < 1) {
+        rt_kprintf("Warning: clock source is too slow.Try smaller resolution\n");
+        divider_int = 1;
+    }
+    else if(divider_int > 100) {
+        rt_kprintf("Warning: clock source is too fast.Try smaller resolution\n");
+        divider_int = 100;
+    }
+    /* 配置分频寄存器 */
+    {
+        rt_uint32_t regval = 0;
+        regval = PLL_DIV_PARAM;
+        /*首先需要把分频使能位清零 */
+        regval &= ~0x80000030;    //PIX_DIV_VALID  PIX_SEL  置0
+        regval &= ~(0x3f<<24);    //PIX_DIV 清零
+        regval |= divider_int << 24;
+        PLL_DIV_PARAM = regval; 
+        regval |= 0x80000030;    //PIX_DIV_VALID  PIX_SEL  置1
+        PLL_DIV_PARAM = regval; 
+    }
+    rt_kprintf("new PLL_FREQ=0x%x, PLL_DIV_PARAM=0x%x\n", PLL_FREQ, PLL_DIV_PARAM);
+    rt_thread_delay(10);
+    return 0;
 }
 
 static rt_err_t rt_dc_init(rt_device_t dev)
 {
-	int i, out, mode=-1;
-	int val;
-	
-	rt_kprintf("PWM initied\n");
-	/* Set the back light PWM. */
-	pwminit();
-	
-	for (i=0; i<sizeof(vga_mode)/sizeof(struct vga_struct); i++)
-	{
-		if (vga_mode[i].hr == FB_XSIZE && vga_mode[i].vr == FB_YSIZE)
-		{
-			mode=i;
-			/* 计算时钟 配置频率*/
-			caclulate_freq(OSC, vga_mode[i].pclk);
-			break;
-		}
-	}
-
-	if (mode<0)
-	{
-		rt_kprintf("\n\n\nunsupported framebuffer resolution\n\n\n");
-		return;
-	}
-
-	DC_FB_CONFIG = 0x0;
-	DC_FB_CONFIG = 0x3; //	// framebuffer configuration RGB565
- 	DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer - 0x80000000;
-	DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer - 0x80000000;
-	DC_DITHER_CONFIG = 0x0;  //颜色抖动配置寄存器
-	DC_DITHER_TABLE_LOW = 0x0; //颜色抖动查找表低位寄存器 
-	DC_DITHER_TABLE_HIGH = 0x0; //颜色抖动查找表高位寄存器
-	DC_PANEL_CONFIG = 0x80001311; //液晶面板配置寄存器
-	DC_PANEL_TIMING = 0x0;
-
-	DC_HDISPLAY = (vga_mode[mode].hfl<<16) | vga_mode[mode].hr;
-	DC_HSYNC = 0x40000000 | (vga_mode[mode].hse<<16) | vga_mode[mode].hss;
-	DC_VDISPLAY = (vga_mode[mode].vfl<<16) | vga_mode[mode].vr;
-	DC_VSYNC = 0x40000000 | (vga_mode[mode].vse<<16) | vga_mode[mode].vss;
+    int i, out, mode=-1;
+    int val;
+    
+    rt_kprintf("PWM initied\n");
+    /* Set the back light PWM. */
+    pwminit();
+    
+    for (i=0; i<sizeof(vga_mode)/sizeof(struct vga_struct); i++)
+    {
+        if (vga_mode[i].hr == FB_XSIZE && vga_mode[i].vr == FB_YSIZE)
+        {
+            mode=i;
+            /* 计算时钟 配置频率*/
+            caclulate_freq(OSC, vga_mode[i].pclk);
+            break;
+        }
+    }
+
+    if (mode<0)
+    {
+        rt_kprintf("\n\n\nunsupported framebuffer resolution\n\n\n");
+        return;
+    }
+
+    DC_FB_CONFIG = 0x0;
+    DC_FB_CONFIG = 0x3; //    // framebuffer configuration RGB565
+    DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer - 0x80000000;
+    DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer - 0x80000000;
+    DC_DITHER_CONFIG = 0x0;  //颜色抖动配置寄存器
+    DC_DITHER_TABLE_LOW = 0x0; //颜色抖动查找表低位寄存器 
+    DC_DITHER_TABLE_HIGH = 0x0; //颜色抖动查找表高位寄存器
+    DC_PANEL_CONFIG = 0x80001311; //液晶面板配置寄存器
+    DC_PANEL_TIMING = 0x0;
+
+    DC_HDISPLAY = (vga_mode[mode].hfl<<16) | vga_mode[mode].hr;
+    DC_HSYNC = 0x40000000 | (vga_mode[mode].hse<<16) | vga_mode[mode].hss;
+    DC_VDISPLAY = (vga_mode[mode].vfl<<16) | vga_mode[mode].vr;
+    DC_VSYNC = 0x40000000 | (vga_mode[mode].vse<<16) | vga_mode[mode].vss;
 
 #if defined(CONFIG_VIDEO_32BPP)
-	DC_FB_CONFIG = 0x00100105;
-	DC_FB_BUFFER_STRIDE = FB_XSIZE*4;
+    DC_FB_CONFIG = 0x00100105;
+    DC_FB_BUFFER_STRIDE = FB_XSIZE*4;
 #elif defined(CONFIG_VIDEO_24BPP)
-	DC_FB_CONFIG = 0x00100104;
-	DC_FB_BUFFER_STRIDE = (FB_XSIZE*4+255)&(~255);
+    DC_FB_CONFIG = 0x00100104;
+    DC_FB_BUFFER_STRIDE = (FB_XSIZE*4+255)&(~255);
 #elif defined(CONFIG_VIDEO_16BPP)// 使用这个选项
-	DC_FB_CONFIG = 0x00100103;
-	DC_FB_BUFFER_STRIDE = (FB_XSIZE*2+255)&(~255);
+    DC_FB_CONFIG = 0x00100103;
+    DC_FB_BUFFER_STRIDE = (FB_XSIZE*2+0x7f)&(~0x7f);
 #elif defined(CONFIG_VIDEO_15BPP)
-	DC_FB_CONFIG = 0x00100102;
-	DC_FB_BUFFER_STRIDE =  (FB_XSIZE*2+255)&(~255);
+    DC_FB_CONFIG = 0x00100102;
+    DC_FB_BUFFER_STRIDE =  (FB_XSIZE*2+255)&(~255);
 #elif defined(CONFIG_VIDEO_12BPP)
-	DC_FB_CONFIG = 0x00100101;
-	DC_FB_BUFFER_STRIDE =  (FB_XSIZE*2+255)&(~255);
+    DC_FB_CONFIG = 0x00100101;
+    DC_FB_BUFFER_STRIDE =  (FB_XSIZE*2+255)&(~255);
 #else  
-	DC_FB_CONFIG = 0x00100104;
-	DC_FB_BUFFER_STRIDE = (FB_XSIZE*4+255)&(~255);
+    DC_FB_CONFIG = 0x00100104;
+    DC_FB_BUFFER_STRIDE = (FB_XSIZE*4+255)&(~255);
 #endif 
-	return RT_EOK;
+    return RT_EOK;
 }
 
 static rt_err_t rt_dc_control(rt_device_t dev, int cmd, void *args)
 {
-	switch (cmd)
-	{
-	case RTGRAPHIC_CTRL_RECT_UPDATE:
-		break;
-	case RTGRAPHIC_CTRL_POWERON:
-		break;
-	case RTGRAPHIC_CTRL_POWEROFF:
-		break;
-	case RTGRAPHIC_CTRL_GET_INFO:		
-		rt_memcpy(args, &_dc_info, sizeof(_dc_info));
-		break;
-	case RTGRAPHIC_CTRL_SET_MODE:
-		break;
-	}
-
-	return RT_EOK;
+    switch (cmd)
+    {
+    case RTGRAPHIC_CTRL_RECT_UPDATE:
+        break;
+    case RTGRAPHIC_CTRL_POWERON:
+        break;
+    case RTGRAPHIC_CTRL_POWEROFF:
+        break;
+    case RTGRAPHIC_CTRL_GET_INFO:        
+        rt_memcpy(args, &_dc_info, sizeof(_dc_info));
+        break;
+    case RTGRAPHIC_CTRL_SET_MODE:
+        break;
+    }
+
+    return RT_EOK;
 }
 
 void rt_hw_dc_init(void)
 {
-	rt_device_t dc = rt_malloc(sizeof(struct rt_device));
-	if (dc == RT_NULL) 
-	{
-		rt_kprintf("dc == RT_NULL\n");
-		return; /* no memory yet */
-	}
-
-	_dc_info.bits_per_pixel = 16;
-	_dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
-	_dc_info.framebuffer = (rt_uint8_t*)HW_FB_ADDR;
-	_dc_info.width = FB_XSIZE;
-	_dc_info.height = FB_YSIZE;
-
-	/* init device structure */
-	dc->type = RT_Device_Class_Graphic;
-	dc->init = rt_dc_init;
-	dc->open = RT_NULL;
-	dc->close = RT_NULL;
-	dc->control = rt_dc_control;
-	dc->user_data = (void*)&_dc_info;
-	
-	/* register Display Controller device to RT-Thread */
-	rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR);
-	
-	rt_device_init(dc);
+    rt_device_t dc = rt_malloc(sizeof(struct rt_device));
+    if (dc == RT_NULL) 
+    {
+        rt_kprintf("dc == RT_NULL\n");
+        return; /* no memory yet */
+    }
+
+    _dc_info.bits_per_pixel = 16;
+    _dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
+    _dc_info.framebuffer = (rt_uint8_t*)HW_FB_ADDR;
+    _dc_info.width = FB_XSIZE;
+    _dc_info.height = FB_YSIZE;
+
+    /* init device structure */
+    dc->type = RT_Device_Class_Graphic;
+    dc->init = rt_dc_init;
+    dc->open = RT_NULL;
+    dc->close = RT_NULL;
+    dc->control = rt_dc_control;
+    dc->user_data = (void*)&_dc_info;
+    
+    /* register Display Controller device to RT-Thread */
+    rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR);
+    
+    rt_device_init(dc);
 }
 
 #include <rtgui/driver.h>

+ 6 - 10
bsp/ls1cdev/drivers/display_controller.h

@@ -1,11 +1,7 @@
 /*
- * File      : display_controller.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006-2012, RT-Thread Develop Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date                Author           Notes
@@ -20,7 +16,7 @@
 #include <rtthread.h>
 #include "ls1c.h"
 
-#define DC_BASE					0xBC301240  //Display Controller
+#define DC_BASE                 0xBC301240  //Display Controller
 
 /* Frame Buffer registers */
 #define DC_FB_CONFIG			__REG32(DC_BASE + 0x000)
@@ -51,9 +47,9 @@
 
 struct vga_struct
 {
-	long pclk;
-	int hr,hss,hse,hfl;
-	int vr,vss,vse,vfl;
+    long pclk;
+    int hr,hss,hse,hfl;
+    int vr,vss,vse,vfl;
 };
 
 #endif

+ 6 - 20
bsp/ls1cdev/drivers/drv_can.c

@@ -1,21 +1,7 @@
 /*
- * File      : drv_can.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author            Notes
@@ -119,6 +105,7 @@ static rt_err_t setfilter(struct ls1c_bxcan *pbxcan, struct rt_can_filter_config
     }
     return RT_EOK;
 }
+
 static void bxcan0_filter_init(struct rt_can_device *can)
 {
         struct ls1c_bxcan *pbxcan;
@@ -249,7 +236,6 @@ static void bxcan1_hw_init(void)
 }
 #endif
 
-
 static rt_err_t configure(struct rt_can_device *can, struct can_configure *cfg)
 {
     CAN_TypeDef *pbxcan;
@@ -444,7 +430,7 @@ void ls1c_can0_irqhandler(int irq, void *param)
        rt_kprintf("\r\nCan0 int TX happened!\r\n");
     }
     /*数据溢出中断*/
-    else if (( status  & CAN_IR_TI) == CAN_IR_DOI) 
+    else if (( status  & CAN_IR_DOI) == CAN_IR_DOI) 
     {
        rt_hw_can_isr(&bxcan0, RT_CAN_EVENT_RXOF_IND);
        rt_kprintf("\r\nCan0 int RX OF happened!\r\n");
@@ -484,7 +470,7 @@ void ls1c_can1_irqhandler(int irq, void *param)
        rt_kprintf("\r\nCan1 int TX happened!\r\n");
     }
     /*数据溢出中断*/
-    else if (( status  & CAN_IR_TI) == CAN_IR_DOI) 
+    else if (( status  & CAN_IR_DOI) == CAN_IR_DOI) 
     {
        rt_hw_can_isr(&bxcan1, RT_CAN_EVENT_RXOF_IND);
        rt_kprintf("\r\nCan1 int RX OF happened!\r\n");
@@ -515,7 +501,7 @@ int ls1c_bxcan_init(void)
     rt_kprintf("\r\ncan0 register! \r\n");
     
     rt_hw_interrupt_install(LS1C_CAN0_IRQ,( rt_isr_handler_t)bxcan0data.irq , RT_NULL, "can0");  
-    rt_hw_interrupt_umask(LS1C_CAN0_IRQ); 
+    rt_hw_interrupt_umask(LS1C_CAN0_IRQ);  
 #endif
 #ifdef USING_BXCAN1
     bxcan1.config.baud_rate = CAN250kBaud;

+ 2 - 16
bsp/ls1cdev/drivers/drv_can.h

@@ -1,21 +1,7 @@
 /*
- * File      : bxcan.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 16
bsp/ls1cdev/drivers/drv_gpio.c

@@ -1,21 +1,7 @@
 /*
- * File      : drv_gpio.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 16
bsp/ls1cdev/drivers/drv_gpio.h

@@ -1,21 +1,7 @@
 /*
- * File      : drv_gpio.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 8 - 22
bsp/ls1cdev/drivers/drv_i2c.c

@@ -1,25 +1,11 @@
 /*
- * File      : drv_i2c.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes
- * 2017-11-14     勤为本       first version
+ * 2017-11-14     鍕や负鏈�       first version
  */
 
 #include <rtthread.h>
@@ -30,8 +16,8 @@
 #include "../libraries/ls1c_delay.h"
 
 
-#define LS1C_I2C_SCL                (57)    // gpio57
-#define LS1C_I2C_SDA                (56)    // gpio56
+#define LS1C_I2C_SCL                (51)    // gpio57
+#define LS1C_I2C_SDA                (50)    // gpio56
 
 #define LS1C_SET_GPIO_MODE
 
@@ -104,8 +90,8 @@ static const struct rt_i2c_bit_ops bit_ops = {
 
     .udelay     = ls1c_udelay,
 
-    .delay_us   = 20,       // 此值为周期(us)
-    .timeout    = 10,       // 单位为tick
+    .delay_us   = 20,       // 姝ゅ€间负鍛ㄦ湡(us)
+    .timeout    = 10,       // 鍗曚綅涓簍ick
 };
 
 
@@ -118,7 +104,7 @@ int ls1c_i2c_init(void)
 
     ls1c_i2c_gpio_init();
 
-    rt_i2c_bit_add_bus(&bus, "i2c2");
+    rt_i2c_bit_add_bus(&bus, "i2c3");
 
     return RT_EOK;
 }

+ 3 - 20
bsp/ls1cdev/drivers/drv_i2c.h

@@ -1,34 +1,17 @@
 /*
- * File      : drv_i2c.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes
- * 2017-11-14     ÇÚΪ±¾       first version
+ * 2017-11-14     勤为本       first version
  */
 
 #ifndef LS1C_DRV_I2C_H
 #define LS1C_DRV_I2C_H
 
-
 int ls1c_i2c_init(void);
 
-
-
 #endif
 

+ 178 - 0
bsp/ls1cdev/drivers/drv_pwm.c

@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author           Notes
+ * 2018-12-04     Sundm75        the first version
+ */
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#include "ls1c.h"
+#include "../libraries/ls1c_public.h"
+#include "../libraries/ls1c_regs.h"
+#include "../libraries/ls1c_clock.h"
+#include "../libraries/ls1c_pwm.h"
+#include "../libraries/ls1c_pin.h"
+
+#define PWM_CHANNEL_MAX     (4) /* 0-3*/
+
+#ifdef RT_USING_PWM
+
+struct rt_ls1c_pwm
+{
+    struct rt_device_pwm parent;
+
+    rt_uint32_t period[PWM_CHANNEL_MAX];
+    rt_uint32_t pulse[PWM_CHANNEL_MAX];
+};
+
+static struct rt_ls1c_pwm _ls1c_pwm_device;
+
+static rt_err_t set(struct rt_device_pwm *device, struct rt_pwm_configuration *configuration)
+{
+    rt_err_t result = RT_EOK;
+    struct rt_ls1c_pwm *ls1c_pwm_device = (struct rt_ls1c_pwm *)device;
+
+    if (configuration->channel > (PWM_CHANNEL_MAX - 1))
+    {
+        result = -RT_EIO;
+        goto _exit;
+    }
+
+    rt_kprintf("drv_pwm.c set channel %d: period: %d, pulse: %d\n", configuration->channel, configuration->period, configuration->pulse);
+
+    ls1c_pwm_device->period[configuration->channel] = configuration->period;
+    ls1c_pwm_device->pulse[configuration->channel] = configuration->pulse;
+
+_exit:
+    return result;
+}
+
+static rt_err_t get(struct rt_device_pwm *device, struct rt_pwm_configuration *configuration)
+{
+    rt_err_t result = RT_EOK;
+    struct rt_ls1c_pwm *ls1c_pwm_device = (struct rt_ls1c_pwm *)device;
+    
+    if (configuration->channel > (PWM_CHANNEL_MAX - 1))
+    {
+        result = -RT_EIO;
+        goto _exit;
+    }
+    
+    configuration->period = ls1c_pwm_device->period[configuration->channel];
+    configuration->pulse = ls1c_pwm_device->pulse[configuration->channel];
+    rt_kprintf("drv_pwm.c get channel %d: period: %d, pulse: %d\n", configuration->channel, configuration->period, configuration->pulse);
+    
+_exit:
+    return result;
+}
+
+static rt_err_t control(struct rt_device_pwm *device, int cmd, void *arg)
+{
+     rt_err_t result = RT_EOK;
+    struct rt_pwm_configuration * configuration = (struct rt_pwm_configuration *)arg;
+
+    rt_kprintf("drv_pwm.c control cmd: %d. \n", cmd);
+
+    if (cmd == PWM_CMD_ENABLE)
+    {
+        rt_kprintf("PWM_CMD_ENABLE\n");
+        
+        pwm_info_t pwm_info;
+        switch ( configuration->channel)
+        {
+        case 0:
+            pwm_info.gpio = LS1C_PWM0_GPIO06;
+            //pwm_info.gpio = LS1C_PWM0_GPIO04;
+            break;
+        case 1:
+            pwm_info.gpio = LS1C_PWM1_GPIO92;
+            //pwm_info.gpio = LS1C_PWM1_GPIO05;
+            break;
+        case 2:
+            pwm_info.gpio = LS1C_PWM2_GPIO52;
+            //pwm_info.gpio = LS1C_PWM2_GPIO46;
+            break;
+        case 3:
+            pwm_info.gpio = LS1C_PWM3_GPIO47;
+            //pwm_info.gpio = LS1C_PWM3_GPIO53;
+            break;
+        default:
+            break;
+        }
+        pwm_info.mode = PWM_MODE_NORMAL;         
+        pwm_info.duty =  ( (float)configuration->pulse ) / ((float)configuration->period ); 
+        pwm_info.period_ns = configuration->period;       
+        pwm_init(&pwm_info);
+        pwm_enable(&pwm_info);
+    }
+    else if (cmd == PWM_CMD_DISABLE)
+    {
+        rt_kprintf("PWM_CMD_DISABLE\n");
+        pwm_info_t pwm_info;
+        switch ( configuration->channel)
+        {
+        case 0:
+            pwm_info.gpio = LS1C_PWM0_GPIO06;
+            //pwm_info.gpio = LS1C_PWM0_GPIO04;
+            break;
+        case 1:
+            pwm_info.gpio = LS1C_PWM1_GPIO92;
+            //pwm_info.gpio = LS1C_PWM1_GPIO05;
+            break;
+        case 2:
+            pwm_info.gpio = LS1C_PWM2_GPIO52;
+            //pwm_info.gpio = LS1C_PWM2_GPIO46;
+            break;
+        case 3:
+            pwm_info.gpio = LS1C_PWM3_GPIO47;
+            //pwm_info.gpio = LS1C_PWM3_GPIO53;
+            break;
+        default:
+            break;
+        }
+        pwm_info.mode = PWM_MODE_NORMAL;            
+        pwm_info.duty =  ( (float)configuration->pulse ) / ((float)configuration->period ); 
+        pwm_info.period_ns = configuration->period;          
+        pwm_init(&pwm_info);
+        pwm_disable(&pwm_info);
+    }
+    else if (cmd == PWM_CMD_SET)
+    {
+        rt_kprintf("PWM_CMD_SET\n");
+        result = set(device, (struct rt_pwm_configuration *)arg);
+    }
+    else if (cmd == PWM_CMD_GET)
+    {
+        rt_kprintf("PWM_CMD_GET\n");
+        result = get(device, (struct rt_pwm_configuration *)arg);
+    }
+
+    return result;
+}
+
+static const struct rt_pwm_ops pwm_ops =
+{
+    control,
+};
+
+int rt_hw_pwm_init(void)
+{
+    int ret = RT_EOK;
+
+    /* add pwm initial. */
+
+    ret = rt_device_pwm_register(&_ls1c_pwm_device.parent, "pwm", &pwm_ops, RT_NULL);
+
+    return ret;
+}
+INIT_DEVICE_EXPORT(rt_hw_pwm_init);
+
+#endif /*RT_USING_PWM*/

+ 16 - 0
bsp/ls1cdev/drivers/drv_pwm.h

@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author           Notes
+ * 2018-12-04     Sundm75        the first version
+ */
+
+#ifndef LS1C_DRV_PWM_H
+#define LS1C_DRV_PWM_H
+
+int ls1c_pwm_init(void);
+
+#endif /*DRV_CAN_H_*/

+ 177 - 0
bsp/ls1cdev/drivers/drv_rtc.c

@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date			Author		Notes
+ * 2018-05-05   sundm75     first version
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include "board.h"
+#include "drv_rtc.h"
+#include <rtdevice.h>
+
+#include "../libraries/ls1c_regs.h"
+#include "../libraries/ls1c_rtc.h"
+
+//#define RT_RTC_DEBUG
+
+#if defined(RT_USING_RTC)
+#ifdef RT_RTC_DEBUG
+#define rtc_debug(format,args...) 			rt_kprintf(format, ##args)
+#else
+#define rtc_debug(format,args...)
+#endif
+
+static struct rt_device rtc;
+
+RTC_TypeDef * RTC_Handler;  
+
+static time_t get_timestamp(void) 
+{
+    struct tm tm_new = {0}; 
+    RTC_TimeTypeDef rtcDate; 
+    
+    RTC_GetTime(RTC_Handler, &rtcDate); 
+    
+    tm_new.tm_sec  = rtcDate.Seconds; 
+    tm_new.tm_min  = rtcDate.Minutes; 
+    tm_new.tm_hour = rtcDate.Hours;
+    
+    tm_new.tm_mday = rtcDate.Date; 
+    tm_new.tm_mon  = rtcDate.Month- 1; 
+    tm_new.tm_year = rtcDate.Year + 2000 - 1900; 
+
+    return mktime(&tm_new);
+}
+
+static int set_timestamp(time_t timestamp)
+{
+    struct tm *p_tm;
+    RTC_TimeTypeDef rtcDate; 
+    
+    p_tm = localtime(&timestamp);
+    
+    rtcDate.Seconds= p_tm->tm_sec ; 
+    rtcDate.Minutes= p_tm->tm_min ; 
+    rtcDate.Hours= p_tm->tm_hour; 
+
+    rtcDate.Date= p_tm->tm_mday; 
+    rtcDate.Month= p_tm->tm_mon  + 1;  
+    rtcDate.Year= p_tm->tm_year + 1900 - 2000; 
+    
+    RTC_SetTime(RTC_Handler, &rtcDate); 
+    rt_kprintf("\r\nrtcDate is %d.%d.%d - %d:%d:%d",rtcDate.Year, rtcDate.Month, rtcDate.Date, rtcDate.Hours, rtcDate.Minutes, rtcDate.Seconds);
+    return RT_EOK;
+}
+
+rt_uint8_t RTC_Init(void)
+{      
+    RTC_Handler = RTC; 
+    return 0;
+}
+
+static rt_err_t rt_rtc_open(rt_device_t dev, rt_uint16_t oflag)
+{
+    if (dev->rx_indicate != RT_NULL)
+    {
+        /* Open Interrupt */
+    }
+
+    return RT_EOK;
+}
+
+static rt_size_t rt_rtc_read(
+    rt_device_t     dev,
+    rt_off_t        pos,
+    void*           buffer,
+    rt_size_t       size)
+{
+    
+    return 0;
+}
+
+ /**
+ * This function configure RTC device.
+ *
+ * @param dev, pointer to device descriptor.
+ * @param cmd, RTC control command.
+ *
+ * @return the error code.
+ */
+static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
+{
+    rt_err_t result;
+    RT_ASSERT(dev != RT_NULL);
+    switch (cmd)
+    {
+    case RT_DEVICE_CTRL_RTC_GET_TIME:
+       
+        *(rt_uint32_t *)args = get_timestamp();
+        rtc_debug("RTC: get rtc_time %x\n", *(rt_uint32_t *)args);
+        break;
+
+    case RT_DEVICE_CTRL_RTC_SET_TIME:
+    {
+        result = set_timestamp(*(rt_uint32_t *)args);
+        rtc_debug("RTC: set rtc_time %x\n", *(rt_uint32_t *)args);
+    }
+    break;
+    }
+
+    return result;
+}
+
+ /**
+ * This function register RTC device.
+ *
+ * @param device, pointer to device descriptor.
+ * @param name, device name.
+ * @param flag, configuration flags.
+ *
+ * @return the error code.
+ */
+rt_err_t rt_hw_rtc_register(
+    rt_device_t     device,
+    const char      *name,
+    rt_uint32_t     flag)
+{
+    RT_ASSERT(device != RT_NULL);
+
+    device->type        = RT_Device_Class_RTC;
+    device->rx_indicate = RT_NULL;
+    device->tx_complete = RT_NULL;
+    device->init        = RT_NULL;
+    device->open        = rt_rtc_open;
+    device->close       = RT_NULL;
+    device->read        = rt_rtc_read;
+    device->write       = RT_NULL;
+    device->control     = rt_rtc_control;
+    device->user_data   = RT_NULL; /* no private */
+
+    /* register a character device */
+    return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | flag);
+}
+
+ /**
+ * This function initialize RTC module related hardware and register RTC device to kernel.
+ *
+ * @param none.
+ *
+ * @return the error code.
+ */
+int  rt_hw_rtc_init(void)
+{
+    RTC_Init();
+    /* register rtc device */
+    rt_hw_rtc_register(&rtc, RT_RTC_NAME, 0);
+    return RT_EOK;
+}
+INIT_BOARD_EXPORT(rt_hw_rtc_init);
+#endif
+
+
+
+

+ 19 - 0
bsp/ls1cdev/drivers/drv_rtc.h

@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date			Author		Notes
+ * 2018-05-05   sundm75     first version
+ */
+ 
+#ifndef __DRV_RTC_H__
+#define __DRV_RTC_H__
+
+#include <rtthread.h> 
+#include <rtdevice.h> 
+
+int rt_hw_rtc_init(void);
+
+#endif

+ 6 - 20
bsp/ls1cdev/drivers/drv_spi.h

@@ -1,25 +1,11 @@
 /*
- * File      : drv_spi.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes
- * 2017-11-02     勤为本       first version
+ * 2017-11-02     鍕や负鏈�       first version
  */
 
 #ifndef LS1C_DRV_SPI_H
@@ -43,9 +29,9 @@ struct ls1c_spi_cs
 
 
 /*
- * 初始化并注册龙芯1c的spi总线
- * @SPI SPI总线,比如LS1C_SPI_0, LS1C_SPI_1
- * @spi_bus_name 总线名字
+ * 鍒濆�鍖栧苟娉ㄥ唽榫欒姱1c鐨剆pi鎬荤嚎
+ * @SPI SPI鎬荤嚎锛屾瘮濡侺S1C_SPI_0锛� LS1C_SPI_1
+ * @spi_bus_name 鎬荤嚎鍚嶅瓧
  * @ret 
  */
 rt_err_t ls1c_spi_bus_register(rt_uint8_t SPI, const char *spi_bus_name);

+ 202 - 0
bsp/ls1cdev/drivers/drv_touch.c

@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2018-02-08     Zhangyihong  the first version
+ */
+ 
+#include <rtthread.h>
+#include <drivers/pin.h>
+
+#include <rthw.h>
+ 
+#include "drv_touch.h"
+#ifdef TINA_USING_TOUCH
+#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
+#include <rtgui/event.h>
+#include <rtgui/rtgui_server.h>
+#endif
+#define BSP_TOUCH_SAMPLE_HZ    (50)
+static rt_list_t driver_list;
+
+extern void touch_down(void);
+extern void touch_mo(void);
+extern void touch_up(void);
+
+void rt_touch_drivers_register(touch_drv_t drv)
+{
+    rt_list_insert_before(&driver_list, &drv->list);
+}
+
+static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
+{
+#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
+    struct rtgui_event_mouse emouse;
+
+    emouse.parent.sender = RT_NULL;
+    emouse.wid = RT_NULL;
+
+    emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
+    emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN;
+    emouse.x = x;
+    emouse.y = y;
+#ifdef PKG_USING_GUIENGINE
+    emouse.ts = rt_tick_get();
+    emouse.id = ts;
+#endif
+    rtgui_server_post_event(&emouse.parent, sizeof(emouse));
+    rt_kprintf("touch down x:%d,y%d,id:%d\r\n", x, y, ts);
+    touch_down();
+#endif
+}
+
+static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
+{
+#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
+    struct rtgui_event_mouse emouse;
+
+    emouse.parent.sender = RT_NULL;
+    emouse.wid = RT_NULL;
+
+    emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN;
+    emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
+    emouse.x = x;
+    emouse.y = y;
+#ifdef PKG_USING_GUIENGINE
+    emouse.ts = rt_tick_get();
+    emouse.id = ts;
+#endif
+    rtgui_server_post_event(&emouse.parent, sizeof(emouse));
+    rt_kprintf("touch motion x:%d,y%d,id:%d\r\n", x, y, ts);
+	touch_mo();
+#endif
+}
+
+static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
+{
+#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
+    struct rtgui_event_mouse emouse;
+
+    emouse.parent.sender = RT_NULL;
+    emouse.wid = RT_NULL;
+
+    emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
+    emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP;
+    emouse.x = x;
+    emouse.y = y;
+#ifdef PKG_USING_GUIENGINE
+    emouse.ts = rt_tick_get();
+    emouse.id = ts;
+#endif
+    rtgui_server_post_event(&emouse.parent, sizeof(emouse));
+    rt_kprintf("touch up x:%d,y%d,id:%d\r\n", x, y, ts);
+	touch_up();
+#endif
+}
+
+static void touch_thread_entry(void *parameter)
+{
+    touch_drv_t touch = (touch_drv_t)parameter;
+    struct touch_message msg;
+    rt_tick_t emouse_id = 0;
+    touch->ops->isr_enable(RT_TRUE);
+    while (1)
+    {
+
+        if (rt_sem_take(touch->isr_sem, RT_WAITING_FOREVER) != RT_EOK)
+        {
+            continue;
+        }
+        if (touch->ops->read_point(&msg) != RT_EOK)
+        {
+            touch->ops->isr_enable(RT_TRUE);
+            continue;
+        }
+        switch (msg.event)
+        {
+        case TOUCH_EVENT_UP:
+            post_up_event(msg.x, msg.y, emouse_id);
+            break;
+        case TOUCH_EVENT_DOWN:
+            emouse_id = rt_tick_get();
+            post_down_event(msg.x, msg.y, emouse_id);
+            break;
+        case TOUCH_EVENT_MOVE:
+            post_motion_event(msg.x, msg.y, emouse_id);
+            break;
+        default:
+            break;
+        }
+        rt_thread_delay(RT_TICK_PER_SECOND / BSP_TOUCH_SAMPLE_HZ);
+        touch->ops->isr_enable(RT_TRUE);
+    }
+}
+
+int rt_touch_driver_init(void)
+{
+	rt_kprintf("\r\n%s \r\n", __FUNCTION__);
+    rt_list_init(&driver_list);
+    return 0;
+}
+INIT_BOARD_EXPORT(rt_touch_driver_init);
+
+static struct rt_i2c_bus_device *i2c_bus = RT_NULL;
+static int rt_touch_thread_init(void)
+{
+    rt_list_t *l;
+    touch_drv_t current_driver;
+    rt_thread_t tid = RT_NULL;
+    i2c_bus = (struct rt_i2c_bus_device *)rt_device_find("i2c1");
+    RT_ASSERT(i2c_bus);
+    current_driver = RT_NULL;
+    if (rt_device_open((rt_device_t)i2c_bus, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
+        return -1;
+    for (l = driver_list.next; l != &driver_list; l = l->next)
+    {
+        if (rt_list_entry(l, struct touch_drivers, list)->probe(i2c_bus))
+        {
+            current_driver = rt_list_entry(l, struct touch_drivers, list);
+            break;
+        }
+    }
+    if (current_driver == RT_NULL)
+    {
+        rt_kprintf("no touch screen or do not have driver\r\n");
+        rt_device_close((rt_device_t)i2c_bus);
+        return -1;
+    }
+    current_driver->ops->init(i2c_bus);
+    rt_kprintf("touch screen found driver\r\n");
+    tid = rt_thread_create("touch", touch_thread_entry, current_driver, 2048, 27, 20);
+    if (tid == RT_NULL)
+    {
+        current_driver->ops->deinit();
+        rt_device_close((rt_device_t)i2c_bus);
+        return -1;
+    }
+    rt_thread_startup(tid);
+    return 0;
+}
+
+static void touch_init_thread_entry(void *parameter)
+{
+    rt_touch_thread_init();
+}
+static int touc_bg_init(void)
+{
+    rt_thread_t tid = RT_NULL;
+    tid = rt_thread_create("touchi", touch_init_thread_entry, RT_NULL, 2048, 28, 20);
+    if (tid == RT_NULL)
+    {
+        return -1;
+    }
+    rt_thread_startup(tid);
+    return 0;
+}
+INIT_APP_EXPORT(touc_bg_init);
+
+
+#endif

+ 51 - 0
bsp/ls1cdev/drivers/drv_touch.h

@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2018-02-08     Zhangyihong  the first version
+ */
+#ifndef __DRV_TOUCH_H__
+#define __DRV_TOUCH_H__
+
+#include "rtthread.h"
+#include "rtdevice.h"
+
+#define TOUCH_EVENT_UP      (0x01)
+#define TOUCH_EVENT_DOWN    (0x02)
+#define TOUCH_EVENT_MOVE    (0x03)
+#define TOUCH_EVENT_NONE    (0x80)
+
+struct touch_message
+{
+    rt_uint16_t x;
+    rt_uint16_t y;
+    rt_uint8_t event;
+};
+typedef struct touch_message *touch_msg_t;
+
+struct touch_ops
+{
+    void (* isr_enable)(rt_bool_t);
+    rt_err_t (* read_point)(touch_msg_t);
+    void (* init)(struct rt_i2c_bus_device *);
+    void (* deinit)(void);
+};
+typedef struct touch_ops *touch_ops_t;
+
+struct touch_drivers
+{
+    rt_list_t       list;
+    unsigned char   address;
+    rt_bool_t (*probe)(struct rt_i2c_bus_device *i2c_bus);
+    rt_sem_t        isr_sem;
+    touch_ops_t     ops;
+    void           *user_data;
+};
+typedef struct touch_drivers *touch_drv_t;
+
+extern void rt_touch_drivers_register(touch_drv_t drv);
+
+#endif

+ 408 - 0
bsp/ls1cdev/drivers/drv_touch_gt9xx.c

@@ -0,0 +1,408 @@
+/*
+ * File      : drv_touch_gt9xx.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2017, RT-Thread Development Team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2018-02-08     Zhangyihong  the first version
+ * 2018-04-03     XY           gt9xx for 1024 * 600
+ * 2018-10-11     sundm75      ls1c for  480 * 272
+ */
+#include "rtthread.h"
+
+#include "drv_touch.h"
+#include "string.h"
+#include "ls1c_gpio.h"
+#include "ls1c.h"
+#include "ls1c_pin.h"
+
+#ifdef TINA_USING_TOUCH
+
+#define TP_INT_PIN          (89)
+#define TP_RESET_PIN        (87)
+#define LED_PIN        		(52)
+
+
+#define gt9xx_READ_XY_REG 			0x814E    	/* 坐标寄存器 当前检测到的触摸情况 */
+#define gt9xx_CLEARBUF_REG 			0x814E   	/* 清除坐标寄存器 */
+#define gt9xx_CONFIG_REG    		0x8047  	/* 配置参数寄存器 */
+#define gt9xx_COMMAND_REG 			0x8040 		/* 实时命令 */
+#define gt9xx_PRODUCT_ID_REG 		0x8140 		/* productid */
+#define gt9xx_VENDOR_ID_REG 		0x814A 		/* 当前模组选项信息 */
+#define gt9xx_CONFIG_VERSION_REG 	0x8047 		/* 配置文件版本号 */
+#define gt9xx_CONFIG_CHECKSUM_REG 	0x80FF 		/* 配置文件校验码 */
+#define gt9xx_FIRMWARE_VERSION_REG 	0x8144 		/* 固件版本号 */
+
+#define IIC_RETRY_NUM 1
+
+void touch_down(void);
+void touch_mo(void);
+void touch_up(void);
+
+static struct rt_i2c_bus_device *gt9xx_i2c_bus;
+static void gt9xx_isr_enable(rt_bool_t enable);
+static rt_err_t gt9xx_read_point(touch_msg_t msg);
+static void gt9xx_init(struct rt_i2c_bus_device *i2c_bus);
+static void gt9xx_deinit(void);
+static int gt9xx_read_xy(void);
+
+static gpio_direction_output( int pin, int level)
+{
+    gpio_init(pin, gpio_mode_output);
+    gpio_set(pin, level);
+}
+static gpio_direction_input(int pin)
+{
+    gpio_init(pin, gpio_mode_input);
+}
+static gpio_irq_enable( int pin)
+{
+    int touch_irq = LS1C_GPIO_TO_IRQ(TP_INT_PIN); 
+    rt_hw_interrupt_umask(touch_irq); 
+}
+static gpio_irq_disable(int pin)
+{
+    int touch_irq = LS1C_GPIO_TO_IRQ(TP_INT_PIN);
+    rt_hw_interrupt_mask(touch_irq); 
+}
+static gpio_set_value(int pin, int level)
+{
+    gpio_set(pin, level); 
+}
+struct touch_ops gt9xx_ops =
+{
+    gt9xx_isr_enable,
+    gt9xx_read_point,
+    gt9xx_init,
+    gt9xx_deinit,
+};
+
+static struct touch_drivers gt9xx_driver;
+extern struct lcd_config lcd_config;
+
+static rt_uint8_t gt9xx_config[186];
+
+static int gt9xx_read(struct rt_i2c_bus_device *i2c_bus, rt_uint16_t addr, rt_uint8_t *buffer, rt_size_t length)
+{
+    int ret = -1;
+    int retries = 0;
+    rt_uint8_t tmp_buf[2];
+
+    struct rt_i2c_msg msgs[] =
+    {
+        {
+            .addr   = gt9xx_driver.address,
+            .flags  = RT_I2C_WR,
+            .len    = 2,
+            .buf    = tmp_buf,
+        },
+        {
+            .addr   = gt9xx_driver.address,
+            .flags  = RT_I2C_RD,
+            .len    = length,
+            .buf    = buffer,
+        },
+    };
+
+    tmp_buf[0] = (rt_uint8_t)(addr >> 8);
+    tmp_buf[1] = (rt_uint8_t)(addr);
+
+    while (retries < IIC_RETRY_NUM)
+    {
+        ret = rt_i2c_transfer(i2c_bus, msgs, 2);
+        ret = rt_i2c_transfer(i2c_bus, msgs, 2);
+        ret = rt_i2c_transfer(i2c_bus, msgs, 2);
+        ret = rt_i2c_transfer(i2c_bus, msgs, 2);
+        if (ret == 2)break;
+        retries++;
+    }
+
+    if (retries >= IIC_RETRY_NUM)
+    {
+        rt_kprintf("%s i2c read error: %d\n", __func__, ret);
+        return -1;
+    }
+
+    return ret;
+}
+
+static void gt9xx_write(struct rt_i2c_bus_device *i2c_bus, rt_uint16_t addr, rt_uint8_t *buffer, rt_size_t length)
+{
+
+    rt_uint8_t *send_buffer = rt_malloc(length + 2);
+
+    RT_ASSERT(send_buffer);
+
+    send_buffer[0] = (rt_uint8_t)(addr >> 8);
+    send_buffer[1] = (rt_uint8_t)(addr);
+    memcpy(send_buffer + 2, buffer, length);
+
+    struct rt_i2c_msg msgs[] =
+    {
+        {
+            .addr   = gt9xx_driver.address,
+            .flags  = RT_I2C_WR,
+            .len    = length + 2,
+            .buf    = send_buffer,
+        }
+    };
+
+    length = rt_i2c_transfer(i2c_bus, msgs, 1);
+    rt_free(send_buffer);
+    send_buffer = RT_NULL;
+}
+
+static void gt9xx_isr_enable(rt_bool_t enable)
+{
+    if (enable)
+    {
+        gpio_irq_enable( TP_INT_PIN);
+    }
+    else
+    {
+        gpio_irq_disable( TP_INT_PIN);
+    }
+}
+
+static rt_err_t gt9xx_read_point(touch_msg_t msg)
+{
+    rt_uint8_t buf[8];
+    rt_uint8_t clean = 0;
+    static rt_uint8_t s_tp_down = 0;
+
+    gt9xx_read(gt9xx_i2c_bus, gt9xx_READ_XY_REG, buf, 8);
+    gt9xx_write(gt9xx_i2c_bus, gt9xx_CLEARBUF_REG, &clean, 1);
+    if ((buf[0] & 0x80) == 0)
+    {
+        if (s_tp_down)
+        {
+            s_tp_down = 0;
+            msg->event = TOUCH_EVENT_UP;
+            return RT_EOK;
+        }
+        msg->event = TOUCH_EVENT_NONE;
+        return RT_EOK;
+    }
+    msg->x = ((rt_uint16_t)buf[3] << 8) | buf[2];
+    msg->y = ((rt_uint16_t)buf[5] << 8) | buf[4];
+    if (s_tp_down)
+    {
+        msg->event = TOUCH_EVENT_MOVE;
+        return RT_EOK;
+    }
+    msg->event = TOUCH_EVENT_DOWN;
+    s_tp_down = 1;
+
+    return RT_EOK;
+}
+
+void gt9xx_touch_isr(int irq, void *param)  
+{
+    gpio_irq_disable(TP_INT_PIN);
+    rt_sem_release(gt9xx_driver.isr_sem);
+}
+
+static void gt9xx_set_address(rt_uint8_t address)
+{
+    pin_set_purpose(TP_INT_PIN, PIN_PURPOSE_OTHER);
+    pin_set_purpose(TP_RESET_PIN, PIN_PURPOSE_OTHER);
+    gpio_direction_output( TP_INT_PIN, 0);
+    gpio_direction_output( TP_RESET_PIN, 0);
+    if (address == 0x5D)
+    {
+        rt_thread_delay(30);
+        gpio_set_value( TP_RESET_PIN, 1);
+        rt_thread_delay(300);
+        pin_set_purpose(TP_INT_PIN, PIN_PURPOSE_OTHER);
+        gpio_direction_input(TP_INT_PIN);
+        rt_thread_delay(10);
+    }
+    else
+    {
+        gpio_set_value( TP_INT_PIN, 1);
+        gpio_set_value( TP_RESET_PIN, 0);
+        rt_thread_delay(30);
+        gpio_set_value( TP_RESET_PIN, 1);
+        gpio_set_value( TP_INT_PIN, 1);
+        rt_thread_delay(30);
+        gpio_set_value( TP_INT_PIN, 0);
+        rt_thread_delay(30);
+        gpio_set_value( TP_INT_PIN, 1);    
+    }
+}
+
+static void gt9xx_soft_reset(struct rt_i2c_bus_device *i2c_bus)
+{
+    rt_uint8_t buf = 2;
+    gt9xx_write(i2c_bus, gt9xx_COMMAND_REG, &buf, 1);
+}
+
+static void gt9xx_init(struct rt_i2c_bus_device *i2c_bus)
+{
+    rt_uint8_t id = 0;
+    int touch_irq = LS1C_GPIO_TO_IRQ(TP_INT_PIN); 
+    
+    gt9xx_driver.isr_sem = rt_sem_create("gt9xx", 0, RT_IPC_FLAG_FIFO);
+    RT_ASSERT(gt9xx_driver.isr_sem);
+    
+    gt9xx_i2c_bus = i2c_bus;
+    gt9xx_set_address(gt9xx_driver.address);
+    
+    gt9xx_read(i2c_bus, gt9xx_CONFIG_VERSION_REG, &id, 1);
+    rt_kprintf("\r\nGT9xx Config version:0x%02X\r\n", id);
+    
+    gt9xx_read(i2c_bus, gt9xx_VENDOR_ID_REG, &id, 1);
+    rt_kprintf("\r\nGT9xx sensor id:0x%02X\r\n", id);
+    
+    gpio_set_irq_type( TP_INT_PIN, IRQ_TYPE_EDGE_RISING);	
+    gpio_irq_disable( TP_INT_PIN);
+
+    rt_hw_interrupt_install(touch_irq, gt9xx_touch_isr, RT_NULL, "touch");  
+    
+    rt_thread_delay(RT_TICK_PER_SECOND / 5);
+    gpio_init(LED_PIN, gpio_mode_output);
+}
+
+static int gt9xx_write_config(void)
+{
+    int i;
+    rt_uint8_t config_checksum = 0;
+    gt9xx_set_address(gt9xx_driver.address);
+    //Add sth...
+    gt9xx_config[5] = 0x05;
+    gt9xx_config[6] = 0x0C;
+    for (i = 0; i < sizeof(gt9xx_config) - 2; i++)
+    {
+        config_checksum += gt9xx_config[i];
+    }
+    gt9xx_config[184] = (~config_checksum) + 1;
+    gt9xx_config[185] = 0x01;
+    gt9xx_write(gt9xx_i2c_bus, gt9xx_CONFIG_REG, gt9xx_config, sizeof(gt9xx_config));
+    return 0;
+}
+MSH_CMD_EXPORT(gt9xx_write_config,please read first);
+
+static int gt9xx_read_config(void)
+{
+    int i;
+    rt_uint8_t buf[8];
+    rt_uint8_t clean = 0;
+    gt9xx_read(gt9xx_i2c_bus, gt9xx_CONFIG_VERSION_REG, gt9xx_config, sizeof(gt9xx_config));
+    gt9xx_config[sizeof(gt9xx_config)-1] = 1;
+    
+    rt_kprintf("\n");
+    for(i = 0; i < sizeof(gt9xx_config); i++)
+    {
+        rt_kprintf("0x%02X,",gt9xx_config[i]);
+        if((i+1)%8 == 0)
+        {
+            rt_kprintf("\n");
+        }
+    }
+    rt_kprintf("\n");
+    return 0;
+}
+MSH_CMD_EXPORT(gt9xx_read_config,read gt9xx config);
+static int gt9xx_read_xy(void)
+{
+    int i;
+    rt_uint8_t buf[8];
+    rt_uint8_t clean = 0;
+    rt_uint16_t x,y;
+    
+    gt9xx_read(gt9xx_i2c_bus, gt9xx_READ_XY_REG, buf, 8);
+    gt9xx_write(gt9xx_i2c_bus, gt9xx_CLEARBUF_REG, &clean, 1);
+    x = ((rt_uint16_t)buf[3] << 8) | buf[2];
+    y = ((rt_uint16_t)buf[5] << 8) | buf[4];
+    rt_kprintf("\n814e= 0x%02x; 814f= 0x%02x;\n x1 : %d, y1 : %d\n", buf[0], buf[1], x, y);	
+
+    rt_kprintf("\n");
+    return 0;
+}
+MSH_CMD_EXPORT(gt9xx_read_xy,read gt9xx xy);
+
+static rt_bool_t gt9xx_probe(struct rt_i2c_bus_device *i2c_bus)
+{
+    rt_uint8_t buffer[5] = { 0 };
+
+    gt9xx_set_address(gt9xx_driver.address);
+    gt9xx_soft_reset(i2c_bus);
+	rt_thread_delay(10);
+    gt9xx_read(i2c_bus, gt9xx_PRODUCT_ID_REG, buffer, 4);
+    buffer[4] = '\0';
+    if (buffer[0] == '9' && buffer[1] == '1' && buffer[2] == '1')
+    {
+        rt_kprintf("Found chip gt911\r\n");
+        return RT_TRUE;
+    }
+    else if (buffer[0] == '9' && buffer[1] == '1' && buffer[2] == '4' && buffer[3] == '7')
+    {
+        rt_kprintf("Found chip gt9147\r\n");
+        return RT_TRUE;
+    }
+    else if (buffer[0] == '9' && buffer[1] == '1' && buffer[2] == '5' && buffer[3] == '7')
+    {
+        rt_kprintf("Found chip gt9157\r\n");
+        return RT_TRUE;
+    }
+    else
+    {
+        rt_kprintf("Uknow chip :");
+	    rt_kprintf("%d%d%d%d\r\n",buffer[0], buffer[1] , buffer[2], buffer[3]);
+		return RT_TRUE;
+    }
+    return RT_FALSE;
+}
+
+static void gt9xx_deinit(void)
+{
+    rt_sem_delete(gt9xx_driver.isr_sem);
+}
+
+static int gt9xx_driver_register(void)
+{
+    rt_kprintf("\r\n%s \r\n", __FUNCTION__);
+    gt9xx_driver.address = 0x5D;
+    gt9xx_driver.probe = gt9xx_probe;
+    gt9xx_driver.ops = &gt9xx_ops;
+    gt9xx_driver.user_data = RT_NULL;
+    rt_touch_drivers_register(&gt9xx_driver);
+    return 0;
+}
+INIT_ENV_EXPORT(gt9xx_driver_register);
+
+void touch_down(void)
+{
+    gpio_set(LED_PIN, gpio_level_low);
+}
+
+void touch_mo(void)
+{
+    if (0 == (gpio_get(LED_PIN)))
+        gpio_set(LED_PIN, gpio_level_high); 
+    else
+        gpio_set(LED_PIN, gpio_level_low); 
+}
+
+void touch_up(void)
+{
+    gpio_set(LED_PIN, gpio_level_high); 
+}
+
+
+#endif

+ 36 - 19
bsp/ls1cdev/drivers/drv_uart.c

@@ -1,21 +1,7 @@
 /*
- * File      : drv_uart.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes
@@ -131,7 +117,7 @@ static void uart_irq_handler(int vector, void *param)
 
 }
 
-static const struct rt_uart_ops stm32_uart_ops =
+static const struct rt_uart_ops ls1c_uart_ops =
 {
     ls1c_uart_configure,
     ls1c_uart_control,
@@ -146,6 +132,15 @@ struct rt_uart_ls1c uart2 =
     LS1C_UART2_IRQ,
 };
 struct rt_serial_device serial2;
+#endif /* RT_USING_UART2 */
+
+#if defined(RT_USING_UART1)
+struct rt_uart_ls1c uart1 =
+{
+    LS1C_UART1,
+    LS1C_UART1_IRQ,
+};
+struct rt_serial_device serial1;
 #endif /* RT_USING_UART1 */
 
 void rt_hw_uart_init(void)
@@ -156,7 +151,7 @@ void rt_hw_uart_init(void)
 #ifdef RT_USING_UART2
     uart = &uart2;
 
-    serial2.ops    = &stm32_uart_ops;
+    serial2.ops    = &ls1c_uart_ops;
     serial2.config = config;
 
     pin_set_purpose(36, PIN_PURPOSE_OTHER);
@@ -166,12 +161,34 @@ void rt_hw_uart_init(void)
 
     rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial2, "UART2");
 
-    /* register UART1 device */
+    /* register UART2 device */
     rt_hw_serial_register(&serial2,
                           "uart2",
                           //RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_RX,
                           RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
                           uart);
+#endif /* RT_USING_UART2 */
+
+#ifdef RT_USING_UART1
+    uart = &uart1;
+
+    serial1.ops    = &ls1c_uart_ops;
+    serial1.config = config;
+
+    pin_set_purpose(2, PIN_PURPOSE_OTHER);
+    pin_set_purpose(3, PIN_PURPOSE_OTHER);
+    pin_set_remap(2, PIN_REMAP_FOURTH);
+    pin_set_remap(3, PIN_REMAP_FOURTH);
+
+    rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial1, "UART1");
+
+    /* register UART1 device */
+    rt_hw_serial_register(&serial1,
+                          "uart1",
+                          //RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_RX,
+                          RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
+                          uart);
 #endif /* RT_USING_UART1 */
+
 }
 

+ 2 - 16
bsp/ls1cdev/drivers/drv_uart.h

@@ -1,21 +1,7 @@
 /*
- * File      : drv_uart.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 17 - 31
bsp/ls1cdev/drivers/hw_i2c.c

@@ -1,24 +1,10 @@
 /*
- * File      :hw_i2c.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
- * Date           Author       	Notes
+ * Date           Author           Notes
  * 2018-01-04     Sundm75        the first version
  */
 
@@ -40,31 +26,31 @@ rt_size_t rt_i2c_master_xfer(struct rt_i2c_bus_device *bus,
                           rt_uint32_t               num)
 {
     struct ls1c_i2c_bus * i2c_bus = (struct ls1c_i2c_bus *)bus;
-	ls1c_i2c_info_t i2c_info;  
+    ls1c_i2c_info_t i2c_info;  
     struct rt_i2c_msg *msg;
     int i;
     rt_int32_t ret = RT_EOK;
     i2c_info.clock = 50000;       // 50kb/s  
-	i2c_info.I2Cx  = i2c_bus->u32Module;
-	i2c_init(&i2c_info);
-	
+    i2c_info.I2Cx  = i2c_bus->u32Module;
+    i2c_init(&i2c_info);
+    
     for (i = 0; i < num; i++)
     {
         msg = &msgs[i];
         if (msg->flags == RT_I2C_RD)
         {
-			i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_READ);  
-			i2c_receive_ack(&i2c_info); 
-			i2c_receive_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len);  
-			i2c_send_stop(&i2c_info);   
-		 }
+            i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_READ);  
+            i2c_receive_ack(&i2c_info); 
+            i2c_receive_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len);  
+            i2c_send_stop(&i2c_info);   
+         }
         else if(msg->flags == RT_I2C_WR)
         {
-			i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_WRITE);  
-			i2c_receive_ack(&i2c_info);  
-			i2c_send_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len);  
-			i2c_send_stop(&i2c_info);  
-		}
+            i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_WRITE);  
+            i2c_receive_ack(&i2c_info);  
+            i2c_send_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len);  
+            i2c_send_stop(&i2c_info);  
+        }
         ret++;
     }
     return ret;

+ 2 - 16
bsp/ls1cdev/drivers/hw_i2c.h

@@ -1,21 +1,7 @@
 /*
- * File      : hw_i2c.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 6 - 0
bsp/ls1cdev/drivers/net/SConscript

@@ -5,6 +5,12 @@ src = Glob('*.c')
 
 CPPPATH = [cwd]
 
+if GetDepend('RT_USING_LWIP') == False:
+	SrcRemove(src, 'mii.c')
+	SrcRemove(src, 'synopGMAC.c')
+	SrcRemove(src, 'synopGMAC_Dev.c')
+	SrcRemove(src, 'synopGMAC_plat.c')
+
 group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
 
 

+ 2 - 16
bsp/ls1cdev/drivers/net/mii.c

@@ -1,21 +1,7 @@
 /*
- * File      : mii.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 16
bsp/ls1cdev/drivers/net/mii.h

@@ -1,21 +1,7 @@
 /*
- * File      : mii.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 16
bsp/ls1cdev/drivers/net/synopGMAC.c

@@ -1,21 +1,7 @@
 /*
- * File      : synopGMAC.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 16
bsp/ls1cdev/drivers/net/synopGMAC.h

@@ -1,21 +1,7 @@
 /*
- * File      : synopGMAC.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 28
bsp/ls1cdev/drivers/net/synopGMAC_Dev.c

@@ -1,33 +1,7 @@
-/** \file
- * This file defines the synopsys GMAC device dependent functions.
- * Most of the operations on the GMAC device are available in this file.
- * Functions for initiliasing and accessing MAC/DMA/PHY registers and the DMA descriptors
- * are encapsulated in this file. The functions are platform/host/OS independent.
- * These functions in turn use the low level device dependent (HAL) functions to 
- * access the register space.
- * \internal
- * ------------------------REVISION HISTORY---------------------------------
- * Synopsys                 01/Aug/2007                              Created
- */
-
 /*
- * File      : synopGMAC_Dev.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 27
bsp/ls1cdev/drivers/net/synopGMAC_Dev.h

@@ -1,32 +1,7 @@
-/**\file
- * This file defines the function prototypes for the Synopsys GMAC device and the 
- * Marvell 88E1011/88E1011S integrated 10/100/1000 Gigabit Ethernet Transceiver.
- * Since the phy register mapping are standardised, the phy register map and the 
- * bit definitions remain the same for other phy as well.
- * This also defines some of the Ethernet related parmeters.
- * \internal
- *  -----------------------------REVISION HISTORY------------------------------------
- * Synopsys			   01/Aug/2007				Created
- */
-
 /*
- * File      : synopGMAC_Dev.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 16
bsp/ls1cdev/drivers/net/synopGMAC_Host.h

@@ -1,21 +1,7 @@
 /*
- * File      : synopGMAC_Host.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 16
bsp/ls1cdev/drivers/net/synopGMAC_debug.h

@@ -1,21 +1,7 @@
 /*
- * File      : synopGMAC_debug.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 25
bsp/ls1cdev/drivers/net/synopGMAC_network_interface.h

@@ -1,30 +1,7 @@
-/** \file
- * Header file for the nework dependent functionality.
- * The function prototype listed here are linux dependent.
- *   
- * \internal
- * ---------------------------REVISION HISTORY-------------------
- * Synopsys 			01/Aug/2007		Created
- */
-
 /*
- * File      : synopGMAC_network_interface.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 29
bsp/ls1cdev/drivers/net/synopGMAC_plat.c

@@ -1,34 +1,7 @@
-/**\file
- *  This file defines the wrapper for the platform/OS related functions
- *  The function definitions needs to be modified according to the platform 
- *  and the Operating system used.
- *  This file should be handled with greatest care while porting the driver
- *  to a different platform running different operating system other than
- *  Linux 2.6.xx.
- * \internal
- * ----------------------------REVISION HISTORY-----------------------------
- * Synopsys			01/Aug/2007			Created
- */
-
-
 /*
- * File      : synopGMAC_plat.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 28
bsp/ls1cdev/drivers/net/synopGMAC_plat.h

@@ -1,33 +1,7 @@
-/**\file
- *  This file serves as the wrapper for the platform/OS dependent functions
- *  It is needed to modify these functions accordingly based on the platform and the
- *  OS. Whenever the synopsys GMAC driver ported on to different platform, this file
- *  should be handled at most care.
- *  The corresponding function definitions for non-inline functions are available in 
- *  synopGMAC_plat.c file.
- * \internal
- * -------------------------------------REVISION HISTORY---------------------------
- * Synopsys 				01/Aug/2007		 	   Created
- */
-
 /*
- * File      : synopGMAC_plat.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 16
bsp/ls1cdev/drivers/net/synopGMAC_types.h

@@ -1,21 +1,7 @@
 /*
- * File      : synopGMAC_types.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) chinesebear
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 105 - 118
bsp/ls1cdev/drivers/touch.c

@@ -1,21 +1,7 @@
 /*
- * File      : touch.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes
@@ -32,7 +18,7 @@
 #include "drv_spi.h"
 #include "touch.h"
 
-#ifdef RT_USING_RTGUI
+#ifdef XPT2046_USING_TOUCH
 
 #include <rtgui/calibration.h>
 #include <rtgui/event.h>
@@ -40,8 +26,9 @@
 #include <rtgui/rtgui_server.h>
 #include <rtgui/rtgui_system.h>
 
-//竖屏幕 不需要  _ILI_HORIZONTAL_DIRECTION_
-//横屏幕 需要  _ILI_HORIZONTAL_DIRECTION_
+
+//绔栧睆骞� 涓嶉渶瑕�  _ILI_HORIZONTAL_DIRECTION_
+//妯�睆骞� 闇€瑕�  _ILI_HORIZONTAL_DIRECTION_
 
 //#define _ILI_HORIZONTAL_DIRECTION_
 
@@ -57,7 +44,7 @@ TOUCH INT: 84
 */
 #define IS_TOUCH_UP()     gpio_get(TOUCH_INT_PIN)
 
-#define led_gpio 52    // led1指示 
+#define led_gpio 52    // led1鎸囩ず 
 
 #define DUMMY                 0x00
 
@@ -97,7 +84,7 @@ s  A2-A0 MODE SER/DFR PD1-PD0
 #define TOUCH_MSR_Y     (START | MEASURE_Y | MODE_12BIT | DIFFERENTIAL | POWER_MODE0)
 
 
-/* 以下定义XPT2046 的触摸屏位置*/
+/* 浠ヤ笅瀹氫箟XPT2046 鐨勮Е鎽稿睆浣嶇疆*/
 #if defined(_ILI_HORIZONTAL_DIRECTION_)
 #define MIN_X_DEFAULT   2047
 #define MAX_X_DEFAULT   47
@@ -117,7 +104,7 @@ s  A2-A0 MODE SER/DFR PD1-PD0
 #define SH   10                                 // Valve value
 
 
-/*宏定义 */
+/*瀹忓畾涔� */
 #define TOUCH_SPI_X                 SPI1 
 #define TOUCH_INT_PIN               84 
 #define TOUCH_CS_PIN                49 
@@ -126,21 +113,21 @@ s  A2-A0 MODE SER/DFR PD1-PD0
 #define TOUCH_MOSI_PIN              48     
 
 
-/*创建结构体将需要用到的东西进行打包*/
+/*鍒涘缓缁撴瀯浣撳皢闇€瑕佺敤鍒扮殑涓滆タ杩涜�鎵撳寘*/
 struct rtgui_touch_device 
 {
-    struct rt_device parent;                    /* 用于注册设备*/
+    struct rt_device parent;                    /* 鐢ㄤ簬娉ㄥ唽璁惧�*/
 
-    rt_uint16_t x, y;                           /* 记录读取到的位置值  */ 
+    rt_uint16_t x, y;                           /* 璁板綍璇诲彇鍒扮殑浣嶇疆鍊�  */ 
 
-    rt_bool_t calibrating;                      /* 触摸校准标志 */ 
-    rt_touch_calibration_func_t calibration_func;/* 触摸函数 函数指针 */       
+    rt_bool_t calibrating;                      /* 瑙︽懜鏍″噯鏍囧織 */ 
+    rt_touch_calibration_func_t calibration_func;/* 瑙︽懜鍑芥暟 鍑芥暟鎸囬拡 */       
 
-    rt_uint16_t min_x, max_x;                   /* 校准后 X 方向最小 最大值 */ 
-    rt_uint16_t min_y, max_y;                   /* 校准后 Y 方向最小 最大值 */
+    rt_uint16_t min_x, max_x;                   /* 鏍″噯鍚� X 鏂瑰悜鏈€灏� 鏈€澶у€� */ 
+    rt_uint16_t min_y, max_y;                   /* 鏍″噯鍚� Y 鏂瑰悜鏈€灏� 鏈€澶у€� */
 
-    struct rt_spi_device * spi_device;          /* SPI 设备 用于通信 */ 
-    struct rt_event event;                       /* 事件同步,用于“笔中断” */ 
+    struct rt_spi_device * spi_device;          /* SPI 璁惧� 鐢ㄤ簬閫氫俊 */ 
+    struct rt_event event;                       /* 浜嬩欢鍚屾�锛岀敤浜庘€滅瑪涓�柇鈥� */ 
 };
 static struct rtgui_touch_device *touch = RT_NULL;
 
@@ -230,14 +217,14 @@ static void rtgui_touch_calculate(void)
         /* read touch */
         {
             rt_uint8_t i, j, k, min;
-	        rt_uint16_t temp;
+            rt_uint16_t temp;
             rt_uint16_t tmpxy[2][SAMP_CNT];
             rt_uint8_t send_buffer[1];
             rt_uint8_t recv_buffer[2];
             for(i=0; i<SAMP_CNT; i++)
             {
                 send_buffer[0] = TOUCH_MSR_X;
-		  touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2);
+          touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2);
                 rt_kprintf("touch x: %d ",(recv_buffer[0]*256|recv_buffer[1])>>4);
 #if defined(_ILI_HORIZONTAL_DIRECTION_)
                 tmpxy[1][i]  = (recv_buffer[0]<<8)|recv_buffer[1] ;
@@ -249,7 +236,7 @@ static void rtgui_touch_calculate(void)
 #endif
                 send_buffer[0] = TOUCH_MSR_Y;
                 touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2);
-		  rt_kprintf("touch y: %d \n",(recv_buffer[0]*256|recv_buffer[1])>>4);
+          rt_kprintf("touch y: %d \n",(recv_buffer[0]*256|recv_buffer[1])>>4);
 
 #if defined(_ILI_HORIZONTAL_DIRECTION_)
                 tmpxy[0][i]  = (recv_buffer[0]<<8)|recv_buffer[1] ;
@@ -259,46 +246,46 @@ static void rtgui_touch_calculate(void)
                 tmpxy[1][i] >>= 4;
 #endif
             }
-            /*再次打开触摸中断*/
+            /*鍐嶆�鎵撳紑瑙︽懜涓�柇*/
             send_buffer[0] = 1 << 7;
-		  touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2);
+          touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2);
                 touch_send_then_recv(touch->spi_device, send_buffer, 1, recv_buffer, 2);
             /* calculate average */
-			{
-				rt_uint32_t total_x = 0;
-				rt_uint32_t total_y = 0;
-				for(k=0; k<2; k++)
-				{ 
-					// sorting the ADC value
-					for(i=0; i<SAMP_CNT-1; i++)
-					{
-						min=i;
-						for (j=i+1; j<SAMP_CNT; j++)
-						{
-							if (tmpxy[k][min] > tmpxy[k][j]) 
-								min=j;
-						}
-						temp = tmpxy[k][i];
-						tmpxy[k][i] = tmpxy[k][min];
-						tmpxy[k][min] = temp;
-				    }
-				    //check value for Valve value
-					if((tmpxy[k][SAMP_CNT_DIV2+1]-tmpxy[k][SAMP_CNT_DIV2-2]) > SH)
-					{
-						return;
-					}
-				}
-				total_x=tmpxy[0][SAMP_CNT_DIV2-2]+tmpxy[0][SAMP_CNT_DIV2-1]+tmpxy[0][SAMP_CNT_DIV2]+tmpxy[0][SAMP_CNT_DIV2+1];
-				total_y=tmpxy[1][SAMP_CNT_DIV2-2]+tmpxy[1][SAMP_CNT_DIV2-1]+tmpxy[1][SAMP_CNT_DIV2]+tmpxy[1][SAMP_CNT_DIV2+1];
-				//calculate average value
-				touch->x=total_x>>2;
-				touch->y=total_y>>2;
+            {
+                rt_uint32_t total_x = 0;
+                rt_uint32_t total_y = 0;
+                for(k=0; k<2; k++)
+                { 
+                    // sorting the ADC value
+                    for(i=0; i<SAMP_CNT-1; i++)
+                    {
+                        min=i;
+                        for (j=i+1; j<SAMP_CNT; j++)
+                        {
+                            if (tmpxy[k][min] > tmpxy[k][j]) 
+                                min=j;
+                        }
+                        temp = tmpxy[k][i];
+                        tmpxy[k][i] = tmpxy[k][min];
+                        tmpxy[k][min] = temp;
+                    }
+                    //check value for Valve value
+                    if((tmpxy[k][SAMP_CNT_DIV2+1]-tmpxy[k][SAMP_CNT_DIV2-2]) > SH)
+                    {
+                        return;
+                    }
+                }
+                total_x=tmpxy[0][SAMP_CNT_DIV2-2]+tmpxy[0][SAMP_CNT_DIV2-1]+tmpxy[0][SAMP_CNT_DIV2]+tmpxy[0][SAMP_CNT_DIV2+1];
+                total_y=tmpxy[1][SAMP_CNT_DIV2-2]+tmpxy[1][SAMP_CNT_DIV2-1]+tmpxy[1][SAMP_CNT_DIV2]+tmpxy[1][SAMP_CNT_DIV2+1];
+                //calculate average value
+                touch->x=total_x>>2;
+                touch->y=total_y>>2;
                 rt_kprintf("touch->x:%d touch->y:%d\r\n", touch->x, touch->y);
            } /* calculate average */
         } /* read touch */
 
         /* if it's not in calibration status  */
-        /*触摸值缩放*/
+        /*瑙︽懜鍊肩缉鏀�*/
         if (touch->calibrating != RT_TRUE)
         {
             if (touch->max_x > touch->min_x)
@@ -322,19 +309,19 @@ static void rtgui_touch_calculate(void)
     }
 }
 #include "ls1c_regs.h"
-#define TOUCH_INT_EN				__REG32(LS1C_INT4_EN)
+#define TOUCH_INT_EN                __REG32(LS1C_INT4_EN)
 rt_inline void touch_int_cmd(rt_bool_t NewState)
 {
-	if(NewState == RT_TRUE)
-		{
-			//TOUCH_INT_EN |= (1<<(TOUCH_INT_PIN-64));
-			reg_set_one_bit(LS1C_INT4_EN, 1<<(TOUCH_INT_PIN-64));
-		}
-	else
-		{
-			//TOUCH_INT_EN &=(~ (1<<(TOUCH_INT_PIN-64)));
-			reg_clr_one_bit(LS1C_INT4_EN, 1<<(TOUCH_INT_PIN-64));
-		}
+    if(NewState == RT_TRUE)
+        {
+            //TOUCH_INT_EN |= (1<<(TOUCH_INT_PIN-64));
+            reg_set_one_bit(LS1C_INT4_EN, 1<<(TOUCH_INT_PIN-64));
+        }
+    else
+        {
+            //TOUCH_INT_EN &=(~ (1<<(TOUCH_INT_PIN-64)));
+            reg_clr_one_bit(LS1C_INT4_EN, 1<<(TOUCH_INT_PIN-64));
+        }
 
 }
 
@@ -342,29 +329,29 @@ void ls1c_touch_irqhandler(void) /* TouchScreen */
 {
   if(gpio_get(TOUCH_INT_PIN)==0)
   {
-    /* 触摸屏按下后操作 */  
-	if (gpio_level_low == gpio_get(led_gpio))
-		gpio_set(led_gpio, gpio_level_high); 
-	else
-		gpio_set(led_gpio, gpio_level_low); 
-	touch_int_cmd(RT_FALSE);
-	rt_event_send(&touch->event, 1);
+    /* 瑙︽懜灞忔寜涓嬪悗鎿嶄綔 */  
+    if (gpio_level_low == gpio_get(led_gpio))
+        gpio_set(led_gpio, gpio_level_high); 
+    else
+        gpio_set(led_gpio, gpio_level_low); 
+    touch_int_cmd(RT_FALSE);
+    rt_event_send(&touch->event, 1);
   }
 }
 
-/*管脚初始化,配置中断打开SPI1 CS0 设备*/
+/*绠¤剼鍒濆�鍖栵紝閰嶇疆涓�柇鎵撳紑SPI1 CS0 璁惧�*/
 rt_inline void touch_init(void)
-{	 
-    unsigned int touch_int_gpio = TOUCH_INT_PIN;     // 触摸屏中断
+{     
+    unsigned int touch_int_gpio = TOUCH_INT_PIN;     // 瑙︽懜灞忎腑鏂�
     int touch_irq = LS1C_GPIO_TO_IRQ(touch_int_gpio);  
   
-    // 初始化按键中断  
+    // 鍒濆�鍖栨寜閿�腑鏂�  
     gpio_set_irq_type(touch_int_gpio, IRQ_TYPE_EDGE_FALLING);  
     rt_hw_interrupt_install(touch_irq, ls1c_touch_irqhandler, RT_NULL, "touch");  
     rt_hw_interrupt_umask(touch_irq);  
     gpio_init(touch_int_gpio, gpio_mode_input);  
   
-    // 初始化led  
+    // 鍒濆�鍖杔ed  
     gpio_init(led_gpio, gpio_mode_output); 
     gpio_set(led_gpio, gpio_level_high);   
 }
@@ -374,9 +361,9 @@ rt_inline void touch_init(void)
 static rt_err_t rtgui_touch_init (rt_device_t dev)
 {
     rt_uint8_t send;
-	rt_uint8_t recv_buffer[2];
+    rt_uint8_t recv_buffer[2];
     struct rtgui_touch_device * touch_device = (struct rtgui_touch_device *)dev;
-	
+    
     touch_init();
     rt_kprintf("touch_init ...\n");
     send = START | DIFFERENTIAL | POWER_MODE0;
@@ -433,7 +420,7 @@ static void touch_thread_entry(void *parameter)
 
     while(1)
     {
-        /* 接收到触摸中断事件 */
+        /* 鎺ユ敹鍒拌Е鎽镐腑鏂�簨浠� */
         if(rt_event_recv(&touch->event,
                          1,
                          RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
@@ -445,7 +432,7 @@ static void touch_thread_entry(void *parameter)
             {
                 if (IS_TOUCH_UP())
                 {
-                    /* 触摸笔抬起 */
+                    /* 瑙︽懜绗旀姮璧� */
                     /* touch up */
                     emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_UP);
 
@@ -461,14 +448,14 @@ static void touch_thread_entry(void *parameter)
 
                     if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
                     {
-                        /* 触摸校准处理 */
+                        /* 瑙︽懜鏍″噯澶勭悊 */
                         /* callback function */
                         touch->calibration_func(emouse.x, emouse.y);
-											
+                                            
                     }
                     else
                     {
-                        /* 向ui发送触摸坐标 */
+                        /* 鍚憉i鍙戦€佽Е鎽稿潗鏍� */
                         rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse));
                     }
                     rt_kprintf("touch up: (%d, %d)\n", emouse.x, emouse.y);
@@ -503,7 +490,7 @@ static void touch_thread_entry(void *parameter)
                     emouse.x = touch->x;
                     emouse.y = touch->y;
                     _set_mouse_position(emouse.x, emouse.y);
-                    /* 光标跟随 */
+                    /* 鍏夋爣璺熼殢 */
                     /* init mouse button */
                     emouse.button = (RTGUI_MOUSE_BUTTON_LEFT |RTGUI_MOUSE_BUTTON_DOWN);
 
@@ -519,7 +506,7 @@ static void touch_thread_entry(void *parameter)
                         {
                             touch_previous.x = touch->x;
                             touch_previous.y = touch->y;
-                            /* 向ui发送触摸坐标 */
+                            /* 鍚憉i鍙戦€佽Е鎽稿潗鏍� */
                             rtgui_server_post_event(&emouse.parent, sizeof(struct rtgui_event_mouse));
                             if(touch_down == RT_FALSE)
                             {
@@ -545,24 +532,24 @@ static void touch_thread_entry(void *parameter)
 
 rt_err_t rtgui_touch_hw_init(const char * spi_device_name)
 {
-    	 rt_uint32_t arg[2]; 
-	struct rt_device * spi_device;
-    	struct rt_thread * touch_thread;
-	rt_err_t err;
-
-	rt_kprintf("spi1 cs0 start...\n");
-	spi_device = rt_device_find("spi10");
-	if(spi_device ==  RT_NULL)
-	{
-		rt_kprintf("Did not find spi1, exit thread....\n");
-		return;
-	}
-	err = rt_device_open(spi_device, RT_DEVICE_OFLAG_RDWR);
-	if(err != RT_EOK)
-	{
-		rt_kprintf("Open spi1 failed %08X, exit thread....\n", err);
-		return;
-	}
+         rt_uint32_t arg[2]; 
+    struct rt_device * spi_device;
+        struct rt_thread * touch_thread;
+    rt_err_t err;
+
+    rt_kprintf("spi1 cs0 start...\n");
+    spi_device = rt_device_find("spi10");
+    if(spi_device ==  RT_NULL)
+    {
+        rt_kprintf("Did not find spi1, exit thread....\n");
+        return;
+    }
+    err = rt_device_open(spi_device, RT_DEVICE_OFLAG_RDWR);
+    if(err != RT_EOK)
+    {
+        rt_kprintf("Open spi1 failed %08X, exit thread....\n", err);
+        return;
+    }
       
       /* config spi */
       {
@@ -573,7 +560,7 @@ rt_err_t rtgui_touch_hw_init(const char * spi_device_name)
         rt_spi_configure((struct rt_spi_device *)spi_device, &cfg);
       }
 
-	touch = (struct rtgui_touch_device*)rt_malloc (sizeof(struct rtgui_touch_device));
+    touch = (struct rtgui_touch_device*)rt_malloc (sizeof(struct rtgui_touch_device));
     if (touch == RT_NULL) return RT_ENOMEM; /* no memory yet */
 
     /* clear device structure */
@@ -597,7 +584,7 @@ rt_err_t rtgui_touch_hw_init(const char * spi_device_name)
 
     /* register touch device to RT-Thread */
     rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR);
-	
+    
 
     touch_thread = rt_thread_create("touch_thread",
                                     touch_thread_entry, RT_NULL,

+ 2 - 16
bsp/ls1cdev/drivers/touch.h

@@ -1,21 +1,7 @@
 /*
- * File      : touch.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 6 - 19
bsp/ls1cdev/libraries/ls1c_can.c

@@ -1,21 +1,7 @@
 /*
- * File      : ls1c_can.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes
@@ -25,6 +11,7 @@
 #include "ls1c.h"
 #include "ls1c_public.h"
 #include "ls1c_can.h"
+#include "ls1c_delay.h"
 
 unsigned char  set_reset_mode(CAN_TypeDef* CANx)
 {
@@ -51,7 +38,7 @@ unsigned char  set_reset_mode(CAN_TypeDef* CANx)
     /*检查复位标志*/
     status = CANx->MOD;
   }
-  rt_kprintf("\r\nSetting SJA1000 into reset mode failed!\r\n");
+  printf("\r\nSetting SJA1000 into reset mode failed!\r\n");
   return 0;  
 }
 
@@ -77,7 +64,7 @@ static unsigned char  set_normal_mode(CAN_TypeDef* CANx)
     delay_us(10); 
     status = CANx->MOD;	
   }
-  rt_kprintf("\r\nSetting SJA1000 into normal mode failed!\r\n");
+  printf("\r\nSetting SJA1000 into normal mode failed!\r\n");
   return 0;
 }
 
@@ -102,7 +89,7 @@ unsigned char CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct)
   status = CANx->MOD;
   if( status == 0xFF)
   {
-    rt_kprintf("\n Probe can0 failed \r\n");  	   
+    printf("\n Probe can0 failed \r\n");  	   
     return CAN_InitStatus_Failed;
   }
 

+ 3 - 18
bsp/ls1cdev/libraries/ls1c_can.h

@@ -1,22 +1,7 @@
-
 /*
- * File      : ls1c_can.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:  (Pelican Mode) 
  * Date           Author       Notes
@@ -221,7 +206,7 @@ unsigned char CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage);
 void CAN_Receive(CAN_TypeDef* CANx,  CanRxMsg* RxMessage);
 
 unsigned char  set_reset_mode(CAN_TypeDef* CANx);
-unsigned char  set_start(CAN_TypeDef* CANx); 
+unsigned char  set_start(CAN_TypeDef* CANx);
 
 #endif
 

+ 25 - 21
bsp/ls1cdev/libraries/ls1c_clock.c

@@ -1,28 +1,32 @@
-/*************************************************************************
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- * 时钟相关函数
+ * SPDX-License-Identifier: Apache-2.0
  *
- *************************************************************************/
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     鍕や负鏈�       first version
+ */
 
 
 #include "ls1c_regs.h"
 #include "ls1c_public.h"
 
 
-// 晶振的频率
+// 鏅舵尟鐨勯�鐜�
 #define AHB_CLK                 (24000000)
 #define APB_CLK                 (AHB_CLK)
 
 
-// START_FREQ寄存器bits
+// START_FREQ瀵勫瓨鍣╞its
 #define M_PLL_SHIFT             (8)
-#define M_PLL                   (0xff << M_PLL_SHIFT)       // PLL倍频系数的整数部分
+#define M_PLL                   (0xff << M_PLL_SHIFT)       // PLL鍊嶉�绯绘暟鐨勬暣鏁伴儴鍒�
 #define FRAC_N_SHIFT            (16)
-#define FRAC_N                  (0xff << FRAC_N_SHIFT)      // PLL倍频系数的小数部分
+#define FRAC_N                  (0xff << FRAC_N_SHIFT)      // PLL鍊嶉�绯绘暟鐨勫皬鏁伴儴鍒�
 #define DIV_SDRAM_SHIFT         (0)
 #define DIV_SDRAM               (0x3  << DIV_SDRAM_SHIFT)
 
-// CLK_DIV_PARAM寄存器bits
+// CLK_DIV_PARAM瀵勫瓨鍣╞its
 #define DIV_PIX_EN              (0x1  << 31)
 #define DIV_PIX                 (0x7f << 24)
 #define DIV_CAM_EN              (0x1  << 23)
@@ -42,8 +46,8 @@
 
 
 /*
- * 获取PLL频率
- * @ret PLL频率
+ * 鑾峰彇PLL棰戠巼
+ * @ret PLL棰戠巼
  */
 unsigned long clk_get_pll_rate(void)
 {
@@ -58,8 +62,8 @@ unsigned long clk_get_pll_rate(void)
 
 
 /*
- * 获取CPU频率
- * @ret CPU频率
+ * 鑾峰彇CPU棰戠巼
+ * @ret CPU棰戠巼
  */
 unsigned long clk_get_cpu_rate(void)
 {
@@ -69,8 +73,8 @@ unsigned long clk_get_cpu_rate(void)
     pll_rate = clk_get_pll_rate();
     ctrl = reg_read_32((volatile unsigned int *)LS1C_CLK_DIV_PARAM);
 
-    // 选择时钟来源
-    if (DIV_CPU_SEL & ctrl)     // pll分频作为时钟信号
+    // 閫夋嫨鏃堕挓鏉ユ簮
+    if (DIV_CPU_SEL & ctrl)     // pll鍒嗛�浣滀负鏃堕挓淇″彿
     {
         if (DIV_CPU_EN & ctrl)
         {
@@ -81,7 +85,7 @@ unsigned long clk_get_cpu_rate(void)
             cpu_rate = pll_rate / 2;
         }
     }
-    else                        // bypass模式,晶振作为时钟输入
+    else                        // bypass妯″紡锛屾櫠鎸�綔涓烘椂閽熻緭鍏�
     {
         cpu_rate = APB_CLK;
     }
@@ -91,8 +95,8 @@ unsigned long clk_get_cpu_rate(void)
 
 
 /*
- * 获取DDR频率
- * @ret DDR频率
+ * 鑾峰彇DDR棰戠巼
+ * @ret DDR棰戠巼
  */
 unsigned long clk_get_ddr_rate(void)
 {
@@ -125,8 +129,8 @@ unsigned long clk_get_ddr_rate(void)
 
 
 /*
- * 获取APB频率
- * @ret APB频率
+ * 鑾峰彇APB棰戠巼
+ * @ret APB棰戠巼
  */
 unsigned long clk_get_apb_rate(void)
 {
@@ -135,8 +139,8 @@ unsigned long clk_get_apb_rate(void)
 
 
 /*
- * 获取DC频率
- * @ret DC频率
+ * 鑾峰彇DC棰戠巼
+ * @ret DC棰戠巼
  */
 unsigned long clk_get_dc_rate(void)
 {

+ 7 - 3
bsp/ls1cdev/libraries/ls1c_clock.h

@@ -1,8 +1,12 @@
-/*************************************************************************
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- * ʱÖÓÏà¹ØÍ·Îļþ
+ * SPDX-License-Identifier: Apache-2.0
  *
- *************************************************************************/
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     ÇÚΪ±¾       first version
+ */
 
 
 #ifndef __OPENLOONGSON_CLOCK_H

+ 17 - 8
bsp/ls1cdev/libraries/ls1c_delay.c

@@ -1,4 +1,12 @@
-// 软件延时源文件
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     勤为本       first version
+ */
 
 
 #include "ls1c_clock.h"
@@ -12,7 +20,7 @@
  */
 void delay_ms(int j)
 {
-    int k_max = clk_get_cpu_rate()/1000/3;  // 除以1000表示ms,除以3为测试所得的经验(可以理解为最内层循环执行一次需要的时钟个数)
+    int k_max = clk_get_cpu_rate()/1000/92;  // 除以1000表示ms,另外一个除数为实验测得的经验值
     int k = k_max;
 
     for ( ; j > 0; j--)
@@ -33,24 +41,25 @@ void delay_ms(int j)
  */
 void delay_us(int n)
 {
-    int count_1us = clk_get_cpu_rate() / 1000000 / 3;   // 延时1us的循环次数
+    int count_1us = 252000000 / 1000000 / 84;           // 延时1us的循环次数
+                    // 252000000为cpu频率,除以1000000表示延时单位为us,92为实验测得的经验值
     int count_max;                                      // 延时n微秒的循环次数
     int tmp;
 
-    // 根据延时长短微调(注意,这里是手动优化的,cpu频率改变了可能需要重新优化,此时cpu频率为252Mhz)
+    // 微调
+    count_max = n * count_1us;
     if (10 >= n)                // <=10us
     {
-        count_1us -= 35;
+        count_max = count_max / 3;
     }
     else if (100 >= n)          // <= 100us
     {
-        count_1us -= 6;
+        count_max = count_max - count_max / 5;
     }
     else                        // > 100us
     {
-        count_1us -= 1;
+        count_max = count_max - count_max / 10;
     }
-    count_max = n * count_1us;
 
     // 延时
     for (tmp = count_max; tmp > 0; tmp--)

+ 9 - 2
bsp/ls1cdev/libraries/ls1c_delay.h

@@ -1,5 +1,12 @@
-// Èí¼þÑÓʱͷÎļþ
-
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     ÇÚΪ±¾       first version
+ */
 
 
 #ifndef __OPENLOONGSON_DELAY_H

+ 48 - 40
bsp/ls1cdev/libraries/ls1c_gpio.c

@@ -1,4 +1,12 @@
-// 封装gpio接口
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     鍕や负鏈�       first version
+ */
 
 
 #include "ls1c_public.h"
@@ -8,13 +16,13 @@
 
 
 /*
- * 获取指定gpio的CFG寄存器
- * @gpio gpio编号
- * @ret CFG寄存器
+ * 鑾峰彇鎸囧畾gpio鐨凜FG瀵勫瓨鍣�
+ * @gpio gpio缂栧彿
+ * @ret CFG瀵勫瓨鍣�
  */
 volatile unsigned int *gpio_get_cfg_reg(unsigned int gpio)
 {
-    volatile unsigned int *gpio_cfgx = NULL;            // GPIO_CFGx寄存器
+    volatile unsigned int *gpio_cfgx = NULL;            // GPIO_CFGx瀵勫瓨鍣�
     unsigned int port = GPIO_GET_PORT(gpio);
 
     switch (port)
@@ -45,13 +53,13 @@ volatile unsigned int *gpio_get_cfg_reg(unsigned int gpio)
 
 
 /*
- * 获取指定gpio的EN寄存器
- * @gpio gpio编号
- * @ret EN寄存器
+ * 鑾峰彇鎸囧畾gpio鐨凟N瀵勫瓨鍣�
+ * @gpio gpio缂栧彿
+ * @ret EN瀵勫瓨鍣�
  */
 volatile unsigned int *gpio_get_en_reg(unsigned int gpio)
 {
-    volatile unsigned int *gpio_enx = NULL;         // GPIO_ENx寄存器
+    volatile unsigned int *gpio_enx = NULL;         // GPIO_ENx瀵勫瓨鍣�
     unsigned int port = GPIO_GET_PORT(gpio);
     
     switch (port)
@@ -81,28 +89,28 @@ volatile unsigned int *gpio_get_en_reg(unsigned int gpio)
 }
 
 /*
- * gpio初始化
- * @gpio gpio引脚,取值范围[0, 127]
- * @mode gpio的工作模式(输入、输出)
+ * gpio鍒濆�鍖�
+ * @gpio gpio寮曡剼锛屽彇鍊艰寖鍥碵0, 127]
+ * @mode gpio鐨勫伐浣滄ā寮�(杈撳叆銆佽緭鍑�)
  *
- * 例: 将gpio50初始化为输出
+ * 渚�: 灏唃pio50鍒濆�鍖栦负杈撳嚭
  * gpio_init(50, gpio_mode_output);
  */
 void gpio_init(unsigned int gpio, gpio_mode_t mode)
 {
-    volatile unsigned int *gpio_enx = NULL;        // GPIO_ENx寄存器
+    volatile unsigned int *gpio_enx = NULL;        // GPIO_ENx瀵勫瓨鍣�
     unsigned int pin = GPIO_GET_PIN(gpio);
 
-    // 将pin设为普通GPIO
+    // 灏唒in璁句负鏅�€欸PIO
     pin_set_purpose(gpio, PIN_PURPOSE_GPIO);
 
-    // 设置gpio工作模式(输入、输出)
+    // 璁剧疆gpio宸ヤ綔妯″紡(杈撳叆銆佽緭鍑�)
     gpio_enx  = gpio_get_en_reg(gpio);
-    if (gpio_mode_output == mode)       // 输出
+    if (gpio_mode_output == mode)       // 杈撳嚭
     {
         reg_clr_one_bit(gpio_enx, pin);
     }
-    else                                // 输入
+    else                                // 杈撳叆
     {
         reg_set_one_bit(gpio_enx, pin);
     }
@@ -112,20 +120,20 @@ void gpio_init(unsigned int gpio, gpio_mode_t mode)
 
 
 /*
- * 在指定gpio输出高电平或低电平
- * @gpio gpio引脚,取值范围[0, 127]
- * @level 电平值
+ * 鍦ㄦ寚瀹歡pio杈撳嚭楂樼數骞虫垨浣庣數骞�
+ * @gpio gpio寮曡剼锛屽彇鍊艰寖鍥碵0, 127]
+ * @level 鐢靛钩鍊�
  *
- * 例: 在gpio50上输出低电平
+ * 渚�: 鍦╣pio50涓婅緭鍑轰綆鐢靛钩
  * gpio_set(50, gpio_level_low);
  */
 void gpio_set(unsigned int gpio, gpio_level_t level)
 {
-    volatile unsigned int *gpio_outx = NULL;       // GPIO_OUTx寄存器
+    volatile unsigned int *gpio_outx = NULL;       // GPIO_OUTx瀵勫瓨鍣�
     unsigned int port   = GPIO_GET_PORT(gpio);
     unsigned int pin    = GPIO_GET_PIN(gpio);
 
-    // 获取寄存器地址
+    // 鑾峰彇瀵勫瓨鍣ㄥ湴鍧€
     switch (port)
     {
         case 0:
@@ -144,11 +152,11 @@ void gpio_set(unsigned int gpio, gpio_level_t level)
             gpio_outx = (volatile unsigned int *)LS1C_GPIO_OUT3;
             break;
 
-        default:        // 正确的程序不应该走到这里,直接返回
+        default:        // 姝g‘鐨勭▼搴忎笉搴旇�璧板埌杩欓噷锛岀洿鎺ヨ繑鍥�
             return ;
     }
 
-    // 输出
+    // 杈撳嚭
     if (gpio_level_low == level)
     {
         reg_clr_one_bit(gpio_outx, pin);
@@ -163,20 +171,20 @@ void gpio_set(unsigned int gpio, gpio_level_t level)
 
 
 /*
- * 读取指定gpio引脚的值
- * @gpio gpio引脚,取值范围[0,127]
+ * 璇诲彇鎸囧畾gpio寮曡剼鐨勫€�
+ * @gpio gpio寮曡剼锛屽彇鍊艰寖鍥碵0,127]
  *
- * 例: 读取gpio50引脚上的值
+ * 渚�: 璇诲彇gpio50寮曡剼涓婄殑鍊�
  * gpio_level_t level;
  * level = gpio_get(50);
  */
 unsigned int gpio_get(unsigned int gpio)
 {
-    volatile unsigned int *gpio_inx = NULL;        // GPIO_INx寄存器
+    volatile unsigned int *gpio_inx = NULL;        // GPIO_INx瀵勫瓨鍣�
     unsigned int port   = GPIO_GET_PORT(gpio);
     unsigned int pin    = GPIO_GET_PIN(gpio);
 
-    // 获取寄存器地址
+    // 鑾峰彇瀵勫瓨鍣ㄥ湴鍧€
     switch (port)
     {
         case 0:
@@ -195,28 +203,28 @@ unsigned int gpio_get(unsigned int gpio)
             gpio_inx = (volatile unsigned int *)LS1C_GPIO_IN3;
             break;
 
-        default:        // 正常的流程不应该走到这里,直接返回
+        default:        // 姝e父鐨勬祦绋嬩笉搴旇�璧板埌杩欓噷锛岀洿鎺ヨ繑鍥�
             return 0;
     }
 
-    // 读取
+    // 璇诲彇
     return reg_get_bit(gpio_inx, pin);
 }
 
 
 /**
- * 设置中断类型
- * @gpio gpio引脚
- * @type 触发中断的条件。高电平触发、低电平触发、上升沿触发 or 下降沿触发
+ * 璁剧疆涓�柇绫诲瀷
+ * @gpio gpio寮曡剼
+ * @type 瑙﹀彂涓�柇鐨勬潯浠躲€傞珮鐢靛钩瑙﹀彂銆佷綆鐢靛钩瑙﹀彂銆佷笂鍗囨部瑙﹀彂 or 涓嬮檷娌胯Е鍙�
  */
 void gpio_set_irq_type(unsigned int gpio, gpio_irq_type_t type)
 {
-    volatile unsigned int *int_pol = NULL;     // 中断极性选择寄存器
-    volatile unsigned int *int_edge = NULL;    // 中断边沿选择寄存器
+    volatile unsigned int *int_pol = NULL;     // 涓�柇鏋佹€ч€夋嫨瀵勫瓨鍣�
+    volatile unsigned int *int_edge = NULL;    // 涓�柇杈规部閫夋嫨瀵勫瓨鍣�
     unsigned int port = GPIO_GET_PORT(gpio);
     unsigned int pin  = GPIO_GET_PIN(gpio);
 
-    // 获取寄存器地址
+    // 鑾峰彇瀵勫瓨鍣ㄥ湴鍧€
     switch (port)
     {
         case 0:     // GPIO[31:0]
@@ -235,7 +243,7 @@ void gpio_set_irq_type(unsigned int gpio, gpio_irq_type_t type)
             break;
     }
 
-    // 设置中断类型
+    // 璁剧疆涓�柇绫诲瀷
     switch (type)
     {
         case IRQ_TYPE_EDGE_RISING:

+ 9 - 0
bsp/ls1cdev/libraries/ls1c_gpio.h

@@ -1,3 +1,12 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     ÇÚΪ±¾       first version
+ */
 
 
 #ifndef __OPENLOONGSON_GPIO_H

+ 2 - 16
bsp/ls1cdev/libraries/ls1c_i2c.c

@@ -1,21 +1,7 @@
 /*
- * File      : ls1c_i2c.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 2 - 16
bsp/ls1cdev/libraries/ls1c_i2c.h

@@ -1,21 +1,7 @@
 /*
- * File      : ls1c_i2c.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes

+ 10 - 0
bsp/ls1cdev/libraries/ls1c_pin.c

@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     勤为本       first version
+ */
+
 // 引脚功能(普通gpio,pwm,复用等)相关接口
 
 

+ 10 - 0
bsp/ls1cdev/libraries/ls1c_pin.h

@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     勤为本       first version
+ */
+
 // 引脚功能(普通gpio,pwm,复用等)相关接口
 
 #ifndef __OPENLOONGSON_PIN_H

+ 10 - 0
bsp/ls1cdev/libraries/ls1c_public.c

@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     勤为本       first version
+ */
+
 // 一些常用的、共用的接口
 
 /*

+ 34 - 24
bsp/ls1cdev/libraries/ls1c_public.h

@@ -1,4 +1,14 @@
-// 一些常用的、共用的接口
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     鍕や负鏈�       first version
+ */
+
+// 涓€浜涘父鐢ㄧ殑銆佸叡鐢ㄧ殑鎺ュ彛
 
 #ifndef __OPENLOONGSON_PUBLIC_H
 #define __OPENLOONGSON_PUBLIC_H
@@ -7,7 +17,7 @@
 #include <stdio.h>
 
 
-// pmon提供的打印函数,见main()函数
+// pmon鎻愪緵鐨勬墦鍗板嚱鏁帮紝瑙乵ain()鍑芥暟
 struct callvectors {
 	int     (*open) (char *, int, int);
 	int     (*close) (int);
@@ -35,58 +45,58 @@ typedef enum
 }BOOL;
 
 /*
- * 将指定寄存器的指定位置1
- * @reg 寄存器地址
- * @bit 需要置1的那一bit
+ * 灏嗘寚瀹氬瘎瀛樺櫒鐨勬寚瀹氫綅缃�1
+ * @reg 瀵勫瓨鍣ㄥ湴鍧€
+ * @bit 闇€瑕佺疆1鐨勯偅涓€bit
  */
 void reg_set_one_bit(volatile unsigned int *reg, unsigned int bit);
 
 
 /*
- * 将指定寄存器的指定位清零
- * @reg 寄存器地址
- * @bit 需要清零的那一bit
+ * 灏嗘寚瀹氬瘎瀛樺櫒鐨勬寚瀹氫綅娓呴浂
+ * @reg 瀵勫瓨鍣ㄥ湴鍧€
+ * @bit 闇€瑕佹竻闆剁殑閭d竴bit
  */
 void reg_clr_one_bit(volatile unsigned int *reg, unsigned int bit);
 
 
 /*
- * 获取指定寄存器的指定位的值
- * @reg 寄存器地址
- * @bit 需要读取值的那一bit
- * @ret 指定位的值
+ * 鑾峰彇鎸囧畾瀵勫瓨鍣ㄧ殑鎸囧畾浣嶇殑鍊�
+ * @reg 瀵勫瓨鍣ㄥ湴鍧€
+ * @bit 闇€瑕佽�鍙栧€肩殑閭d竴bit
+ * @ret 鎸囧畾浣嶇殑鍊�
  */
 unsigned int reg_get_bit(volatile unsigned int *reg, unsigned int bit);
 
 
 /*
- * 向寄存器中写入8bit(一个字节)数据
- * @data 待写入的数据
- * @addr 寄存器地址
+ * 鍚戝瘎瀛樺櫒涓�啓鍏�8bit(涓€涓�瓧鑺�)鏁版嵁
+ * @data 寰呭啓鍏ョ殑鏁版嵁
+ * @addr 瀵勫瓨鍣ㄥ湴鍧€
  */
 void reg_write_8(unsigned char data, volatile unsigned char *addr);
 
 
 /*
- * 从寄存器读出8bit(一个字节)数据
- * @addr 寄存器地址
- * @ret 读出的数据
+ * 浠庡瘎瀛樺櫒璇诲嚭8bit(涓€涓�瓧鑺�)鏁版嵁
+ * @addr 瀵勫瓨鍣ㄥ湴鍧€
+ * @ret 璇诲嚭鐨勬暟鎹�
  */
 unsigned char reg_read_8(volatile unsigned char *addr);
 
 
 /*
- * 向寄存器中写一个32bit的数据
- * @data 待写入的数据
- * @addr 寄存器地址
+ * 鍚戝瘎瀛樺櫒涓�啓涓€涓�32bit鐨勬暟鎹�
+ * @data 寰呭啓鍏ョ殑鏁版嵁
+ * @addr 瀵勫瓨鍣ㄥ湴鍧€
  */
 void reg_write_32(unsigned int data, volatile unsigned int *addr);
 
 
 /*
- * 从寄存器读出一个32bit数据
- * @addr 寄存器地址
- * @ret 读出的数据
+ * 浠庡瘎瀛樺櫒璇诲嚭涓€涓�32bit鏁版嵁
+ * @addr 瀵勫瓨鍣ㄥ湴鍧€
+ * @ret 璇诲嚭鐨勬暟鎹�
  */
 unsigned int reg_read_32(volatile unsigned int *addr);
 

+ 10 - 6
bsp/ls1cdev/libraries/ls1c_pwm.c

@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     勤为本       first version
+ */
+
 // 封装硬件pwm接口
 
 #include "ls1c_public.h"
@@ -6,13 +16,9 @@
 #include "ls1c_clock.h"
 #include "ls1c_regs.h"
 
-
-
 // pwm的最大周期
 #define PWM_MAX_PERIOD                  (0xFFFFFF)      // 计数器的值
 
-
-
 /*
  * 根据gpio获取相应pwm的基地址
  * @gpio pwm引脚
@@ -193,5 +199,3 @@ void pwm_init(pwm_info_t *pwm_info)
     return ;
 }
 
-
-

+ 9 - 0
bsp/ls1cdev/libraries/ls1c_pwm.h

@@ -1,3 +1,12 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     ÇÚΪ±¾       first version
+ */
 
 
 #ifndef __OPENLOONGSON_PWM_H

+ 12 - 0
bsp/ls1cdev/libraries/ls1c_regs.h

@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2017-09-06     勤为本       first version
+ */
+
 // 龙芯1c外设寄存器
 
 
@@ -139,6 +149,8 @@
 #define LS1C_UART10_BASE                    (0xbfe4ca00)
 #define LS1C_UART11_BASE                    (0xbfe4cb00)
 
+//RTC寄存器
+#define LS1C_RTC_BASE                       (0xbfe64024)
 
 
 #endif

+ 102 - 0
bsp/ls1cdev/libraries/ls1c_rtc.c

@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2018-05-06     sundm75       first version
+ */
+#include "ls1c.h"
+#include "ls1c_public.h"
+#include "ls1c_rtc.h"
+
+#define LS1C_SEC_OFFSET		(4)
+#define LS1C_MIN_OFFSET		(10)
+#define LS1C_HOUR_OFFSET	(16)
+#define LS1C_DAY_OFFSET		(21)
+#define LS1C_MONTH_OFFSET	(26)
+
+#define LS1C_SEC_MASK		(0x3f)
+#define LS1C_MIN_MASK		(0x3f)
+#define LS1C_HOUR_MASK		(0x1f)
+#define LS1C_DAY_MASK		(0x1f)
+#define LS1C_MONTH_MASK		(0x3f)
+#define LS1C_YEAR_MASK		(0xff)
+
+#define ls1c_get_sec(t)		(((t) >> LS1C_SEC_OFFSET) & LS1C_SEC_MASK)
+#define ls1c_get_min(t)		(((t) >> LS1C_MIN_OFFSET) & LS1C_MIN_MASK)
+#define ls1c_get_hour(t)	(((t) >> LS1C_HOUR_OFFSET) & LS1C_HOUR_MASK)
+#define ls1c_get_day(t)		(((t) >> LS1C_DAY_OFFSET) & LS1C_DAY_MASK)
+#define ls1c_get_month(t)	(((t) >> LS1C_MONTH_OFFSET) & LS1C_MONTH_MASK)
+
+int RTC_SetTime(RTC_TypeDef *hrtc, RTC_TimeTypeDef *sTime)
+{
+
+	hrtc->SYS_TOYWRITE0
+		= (sTime->Month  << LS1C_MONTH_OFFSET)
+		| (sTime->Date << LS1C_DAY_OFFSET)
+		| (sTime->Hours << LS1C_HOUR_OFFSET)
+		| (sTime->Minutes  << LS1C_MIN_OFFSET)
+		| (sTime->Seconds  << LS1C_SEC_OFFSET);
+	hrtc->SYS_TOYWRITE1 =  sTime->Year % 100;
+	printf("\r\ntoy_read0 = 0x%x, toy_read1 = 0x%x.\r\n", hrtc->SYS_TOYREAD0, hrtc->SYS_TOYREAD1);
+
+   return 0;
+}
+
+int RTC_GetTime(RTC_TypeDef *hrtc, RTC_TimeTypeDef *sTime)
+{
+  unsigned long toy_read0, toy_read1; 
+  toy_read0 = hrtc->SYS_TOYREAD0;
+  toy_read1 = hrtc->SYS_TOYREAD1; 
+  sTime->Seconds = ls1c_get_sec(toy_read0);
+  sTime->Minutes = ls1c_get_min(toy_read0);
+  sTime->Hours = ls1c_get_hour(toy_read0);
+  sTime->Date = ls1c_get_day(toy_read0);
+  sTime->Month = ls1c_get_month(toy_read0);
+  sTime->Year = toy_read1 & LS1C_YEAR_MASK;  
+  return 0 ;
+}
+
+unsigned char RTC_IsLeapYear(unsigned int nYear)
+{
+  if((nYear % 4U) != 0U) 
+  {
+    return 0U;
+  }
+  
+  if((nYear % 100U) != 0U) 
+  {
+    return 1U;
+  }
+  
+  if((nYear % 400U) == 0U)
+  {
+    return 1U;
+  }
+  else
+  {
+    return 0U;
+  }
+}
+
+unsigned char RTC_WeekDayNum(unsigned long nYear, unsigned char nMonth, unsigned char nDay)
+{
+  unsigned long year = 0U, weekday = 0U;
+
+  year = 2000U + nYear;
+  
+  if(nMonth < 3U)
+  {
+    /*D = { [(23 x month)/9] + day + 4 + year + [(year-1)/4] - [(year-1)/100] + [(year-1)/400] } mod 7*/
+    weekday = (((23U * nMonth)/9U) + nDay + 4U + year + ((year-1U)/4U) - ((year-1U)/100U) + ((year-1U)/400U)) % 7U;
+  }
+  else
+  {
+    /*D = { [(23 x month)/9] + day + 4 + year + [year/4] - [year/100] + [year/400] - 2 } mod 7*/
+    weekday = (((23U * nMonth)/9U) + nDay + 4U + year + (year/4U) - (year/100U) + (year/400U) - 2U ) % 7U; 
+  }
+
+  return (unsigned char)weekday;
+}

+ 41 - 0
bsp/ls1cdev/libraries/ls1c_rtc.h

@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2018-05-06     sundm75       first version
+ */
+
+ #ifndef __OPENLOONGSON_RTC_H
+#define __OPENLOONGSON_RTC_H
+
+
+#define RTC               ( (RTC_TypeDef* )LS1C_RTC_BASE)
+
+typedef struct
+{
+  unsigned char Year;     /*0 ~ 99 */
+  unsigned char Month;    /*1 ~ 12 */
+  unsigned char Date;     /*1 ~ 31 */
+  unsigned char Hours;    /*0 ~ 23 */
+  unsigned char Minutes;  /*0 ~ 59 */
+  unsigned char Seconds;  /*0 ~ 59 */
+}RTC_TimeTypeDef; 
+
+typedef struct
+{
+   unsigned long SYS_TOYWRITE0;
+   unsigned long SYS_TOYWRITE1;
+   unsigned long SYS_TOYREAD0;
+   unsigned long SYS_TOYREAD1;
+} RTC_TypeDef;
+
+int  RTC_SetTime(RTC_TypeDef *hrtc, RTC_TimeTypeDef *sTime);
+int  RTC_GetTime(RTC_TypeDef *hrtc, RTC_TimeTypeDef *sTime);
+
+unsigned char RTC_IsLeapYear(unsigned int nYear);
+unsigned char RTC_WeekDayNum(unsigned long nYear, unsigned char nMonth, unsigned char nDay);
+
+#endif

+ 8 - 23
bsp/ls1cdev/libraries/ls1c_spi.c

@@ -1,21 +1,7 @@
 /*
- * File      : ls1c_spi.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes
@@ -24,7 +10,6 @@
 
 // 硬件spi接口源文件
 
-
 #include <string.h>
 #include "ls1c_public.h"
 #include "ls1c_regs.h"
@@ -38,7 +23,7 @@
  * 获取指定SPI模块的基地址
  * @SPIx SPI模块的编号
  */
-inline void *ls1c_spi_get_base(unsigned char SPIx)
+void *ls1c_spi_get_base(unsigned char SPIx)
 {
     void *base = NULL;
 
@@ -67,7 +52,7 @@ inline void *ls1c_spi_get_base(unsigned char SPIx)
  */
 void ls1c_spi_print_all_regs_info(void *spi_base)
 {
-    rt_kprintf("[%s] SPCR=0x%x, SPSR=0x%x, SPER=0x%x, SFC_PARAM=0x%x, SFC_SOFTCS=0x%x, SFC_TIMING=0x%x\r\n",
+    printf("[%s] SPCR=0x%x, SPSR=0x%x, SPER=0x%x, SFC_PARAM=0x%x, SFC_SOFTCS=0x%x, SFC_TIMING=0x%x\r\n",
               __FUNCTION__, 
               reg_read_8(spi_base + LS1C_SPI_SPCR_OFFSET),
               reg_read_8(spi_base + LS1C_SPI_SPSR_OFFSET),
@@ -137,7 +122,7 @@ unsigned int ls1c_spi_get_div(unsigned int max_speed_hz)
             break;
     }
 /*    
-    rt_kprintf("[%s] clk=%ld, max_speed_hz=%d, div_tmp=%d, bit=%d\r\n", 
+    printf("[%s] clk=%ld, max_speed_hz=%d, div_tmp=%d, bit=%d\r\n", 
               __FUNCTION__, clk, max_speed_hz, div_tmp, bit);
 */
     return div_tmp;
@@ -229,7 +214,7 @@ void ls1c_spi_set_cs(void *spi_base, unsigned char cs, int new_status)
  * 等待收发完成
  * @spi_base 基地址
  */
-inline void ls1c_spi_wait_txrx_done(void *spi_base)
+void ls1c_spi_wait_txrx_done(void *spi_base)
 {
     int timeout = LS1C_SPI_TX_TIMEOUT;
 
@@ -247,7 +232,7 @@ inline void ls1c_spi_wait_txrx_done(void *spi_base)
  * 清中断和标志位
  * @spi_base 基地址
  */
-inline void ls1c_spi_clear(void *spi_base)
+void ls1c_spi_clear(void *spi_base)
 {
     unsigned char val = 0;
 
@@ -260,7 +245,7 @@ inline void ls1c_spi_clear(void *spi_base)
     val = reg_read_8(spi_base + LS1C_SPI_SPSR_OFFSET);
     if (LS1C_SPI_SPSR_WCOL_MASK & val)
     {
-        rt_kprintf("[%s] clear register SPSR's wcol!\r\n",__FUNCTION__);       // 手册和linux源码中不一样,加个打印看看
+        printf("[%s] clear register SPSR's wcol!\r\n");       // 手册和linux源码中不一样,加个打印看看
         reg_write_8(val & ~LS1C_SPI_SPSR_WCOL_MASK, spi_base + LS1C_SPI_SPSR_OFFSET);   // 写0,linux源码中是写0
 //        reg_write_8(val | LS1C_SPI_SPSR_WCOL_MASK, spi_base + LS1C_SPI_SPSR_OFFSET);  // 写1,按照1c手册,应该写1
     }

+ 44 - 58
bsp/ls1cdev/libraries/ls1c_spi.h

@@ -1,61 +1,47 @@
 /*
- * File      : ls1c_spi.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
+ * Copyright (c) 2006-2018, RT-Thread Development Team
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Change Logs:
  * Date           Author       Notes
- * 2017-10-23     勤为本       first version
+ * 2017-10-23     鍕や负鏈�       first version
  */
 
-// 硬件spi接口的头文件
+// 纭�欢spi鎺ュ彛鐨勫ご鏂囦欢
 
 #ifndef __OPENLOONGSON_SPI_H
 #define __OPENLOONGSON_SPI_H
 
 
-// SPI模块编号
+// SPI妯″潡缂栧彿
 #define LS1C_SPI_0                      (0)
 #define LS1C_SPI_1                      (1)
 
-// 片选
+// 鐗囬€�
 #define LS1C_SPI_CS_0                   (0)
 #define LS1C_SPI_CS_1                   (1)
 #define LS1C_SPI_CS_2                   (2)
 #define LS1C_SPI_CS_3                   (3)
 
-// 时钟极性和相位
+// 鏃堕挓鏋佹€у拰鐩镐綅
 #define SPI_CPOL_1                      (1)
 #define SPI_CPOL_0                      (0)
 #define SPI_CPHA_1                      (1)
 #define SPI_CPHA_0                      (0)
 
 
-// 寄存器偏移
-#define LS1C_SPI_SPCR_OFFSET                (0)     // 控制寄存器
-#define LS1C_SPI_SPSR_OFFSET                (1)     // 状态寄存器
-#define LS1C_SPI_TxFIFO_OFFSET              (2)     // 发送的数据寄存器,与接收数据寄存器的偏移相同
-#define LS1C_SPI_RxFIFO_OFFSET              (2)     // 接收的数据寄存器,与发送数据寄存器的偏移相同
-#define LS1C_SPI_SPER_OFFSET                (3)     // 外部寄存器
-#define LS1C_SPI_SFC_PARAM_OFFSET           (4)     // 参数控制寄存器
-#define LS1C_SPI_SFC_SOFTCS_OFFSET          (5)     // 片选控制寄存器
-#define LS1C_SPI_SFC_TIMING_OFFSET          (6)     // 时序控制寄存器
+// 瀵勫瓨鍣ㄥ亸绉�
+#define LS1C_SPI_SPCR_OFFSET                (0)     // 鎺у埗瀵勫瓨鍣�
+#define LS1C_SPI_SPSR_OFFSET                (1)     // 鐘舵€佸瘎瀛樺櫒
+#define LS1C_SPI_TxFIFO_OFFSET              (2)     // 鍙戦€佺殑鏁版嵁瀵勫瓨鍣�紝涓庢帴鏀舵暟鎹�瘎瀛樺櫒鐨勫亸绉荤浉鍚�
+#define LS1C_SPI_RxFIFO_OFFSET              (2)     // 鎺ユ敹鐨勬暟鎹�瘎瀛樺櫒锛屼笌鍙戦€佹暟鎹�瘎瀛樺櫒鐨勫亸绉荤浉鍚�
+#define LS1C_SPI_SPER_OFFSET                (3)     // 澶栭儴瀵勫瓨鍣�
+#define LS1C_SPI_SFC_PARAM_OFFSET           (4)     // 鍙傛暟鎺у埗瀵勫瓨鍣�
+#define LS1C_SPI_SFC_SOFTCS_OFFSET          (5)     // 鐗囬€夋帶鍒跺瘎瀛樺櫒
+#define LS1C_SPI_SFC_TIMING_OFFSET          (6)     // 鏃跺簭鎺у埗瀵勫瓨鍣�
 
-// 寄存器SPCR中的位域
+// 瀵勫瓨鍣⊿PCR涓�殑浣嶅煙
 #define LS1C_SPI_SPCR_SPIE_BIT              (7)
 #define LS1C_SPI_SPCR_SPIE_MASK             (0x01 << LS1C_SPI_SPCR_SPIE_BIT)
 #define LS1C_SPI_SPCR_SPE_BIT               (6)
@@ -67,75 +53,75 @@
 #define LS1C_SPI_SPCR_SPR_BIT               (0)
 #define LS1C_SPI_SPCR_SPR_MASK              (0x03 << LS1C_SPI_SPCR_SPR_BIT)
 
-// 寄存器SPSR中的位域
+// 瀵勫瓨鍣⊿PSR涓�殑浣嶅煙
 #define LS1C_SPI_SPSR_SPIF_BIT              (7)
 #define LS1C_SPI_SPSR_SPIF_MASK             (0x01 << LS1C_SPI_SPSR_SPIF_BIT)
 #define LS1C_SPI_SPSR_WCOL_BIT              (6)
 #define LS1C_SPI_SPSR_WCOL_MASK             (0x01 << LS1C_SPI_SPSR_WCOL_BIT)
 
-// 寄存器SPER中的位域
+// 瀵勫瓨鍣⊿PER涓�殑浣嶅煙
 #define LS1C_SPI_SPER_SPRE_BIT              (0)
 #define LS1C_SPI_SPER_SPRE_MASK             (0x3 << LS1C_SPI_SPER_SPRE_BIT)
 
-// 寄存器SFC_SOFTCS的位域
+// 瀵勫瓨鍣⊿FC_SOFTCS鐨勪綅鍩�
 #define LS1C_SPI_SFC_SOFTCS_CSN_BIT         (4)
 #define LS1C_SPI_SFC_SOFTCS_CSN_MASK        (0x0f << LS1C_SPI_SFC_SOFTCS_CSN_BIT)
 #define LS1C_SPI_SFC_SOFTCS_CSEN_BIT        (0)
 #define LS1C_SPI_SFC_SOFTCS_CSEN_MASK       (0x0f << LS1C_SPI_SFC_SOFTCS_CSEN_BIT)
 
-// 发送超时的门限值
+// 鍙戦€佽秴鏃剁殑闂ㄩ檺鍊�
 #define LS1C_SPI_TX_TIMEOUT                 (20000)
 
 
 
 /*
- * 获取指定SPI模块的基地址
- * @SPIx SPI模块的编号
+ * 鑾峰彇鎸囧畾SPI妯″潡鐨勫熀鍦板潃
+ * @SPIx SPI妯″潡鐨勭紪鍙�
  */
-inline void *ls1c_spi_get_base(unsigned char SPIx);
+void *ls1c_spi_get_base(unsigned char SPIx);
 
 
 /*
- * 设置时钟
- * @spi_base 基地址
- * @max_hz 最大频率,单位hz
+ * 璁剧疆鏃堕挓
+ * @spi_base 鍩哄湴鍧€
+ * @max_hz 鏈€澶ч�鐜囷紝鍗曚綅hz
  */
 void ls1c_spi_set_clock(void *spi_base, unsigned long max_hz);
 
 
 /*
- * 设置通信模式(时钟极性和相位)
- * @spi_base 基地址
- * @cpol 时钟极性
- * @cpha 时钟相位
+ * 璁剧疆閫氫俊妯″紡(鏃堕挓鏋佹€у拰鐩镐綅)
+ * @spi_base 鍩哄湴鍧€
+ * @cpol 鏃堕挓鏋佹€�
+ * @cpha 鏃堕挓鐩镐綅
  */
 void ls1c_spi_set_mode(void *spi_base, unsigned char cpol, unsigned char cpha);
 
 
 /*
- * 设置指定片选为指定状态
- * @spi_base 基地址
- * @cs 片选
- * @new_status 片选引脚的新状态,取值为0或1,即高电平或低电平
+ * 璁剧疆鎸囧畾鐗囬€変负鎸囧畾鐘舵€�
+ * @spi_base 鍩哄湴鍧€
+ * @cs 鐗囬€�
+ * @new_status 鐗囬€夊紩鑴氱殑鏂扮姸鎬侊紝鍙栧€间负0鎴�1锛屽嵆楂樼數骞虫垨浣庣數骞�
  */
 void ls1c_spi_set_cs(void *spi_base, unsigned char cs, int new_status);
 
 
 /*
- * 通过指定SPI发送接收一个字节
- * 注意,在多任务的系统中,此函数需要互斥。
- * 即保证在和某个从设备收发某个字节的过程中,不能被切换到其它任务同时与另外的在同一个SPI总线上的从设备通信
- * 因为龙芯1c的每路SPI上可能接有不同的从设备,通信频率、模式等可能不同
- * @spi_base 基地址
- * @tx_ch 待发送的数据
- * @ret 收到的数据
+ * 閫氳繃鎸囧畾SPI鍙戦€佹帴鏀朵竴涓�瓧鑺�
+ * 娉ㄦ剰锛屽湪澶氫换鍔$殑绯荤粺涓�紝姝ゅ嚱鏁伴渶瑕佷簰鏂ャ€�
+ * 鍗充繚璇佸湪鍜屾煇涓�粠璁惧�鏀跺彂鏌愪釜瀛楄妭鐨勮繃绋嬩腑锛屼笉鑳借�鍒囨崲鍒板叾瀹冧换鍔″悓鏃朵笌鍙﹀�鐨勫湪鍚屼竴涓猄PI鎬荤嚎涓婄殑浠庤�澶囬€氫俊
+ * 鍥犱负榫欒姱1c鐨勬瘡璺疭PI涓婂彲鑳芥帴鏈変笉鍚岀殑浠庤�澶囷紝閫氫俊棰戠巼銆佹ā寮忕瓑鍙�兘涓嶅悓
+ * @spi_base 鍩哄湴鍧€
+ * @tx_ch 寰呭彂閫佺殑鏁版嵁
+ * @ret 鏀跺埌鐨勬暟鎹�
  */
 unsigned char ls1c_spi_txrx_byte(void *spi_base, unsigned char tx_ch);
 
 
 /*
- * 打印指定SPI模块的所有寄存器的值
- * @spi_base 基地址
+ * 鎵撳嵃鎸囧畾SPI妯″潡鐨勬墍鏈夊瘎瀛樺櫒鐨勫€�
+ * @spi_base 鍩哄湴鍧€
  */
 void ls1c_spi_print_all_regs_info(void *spi_base);
 

+ 108 - 7
bsp/ls1cdev/libraries/ls1c_timer.c

@@ -1,6 +1,15 @@
+ /*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ *                             first version
+ */
 // 硬件定时器源码
 
-
+#include <ls1c.h>  
 #include "ls1c_public.h"
 #include "ls1c_pin.h"
 #include "ls1c_clock.h"
@@ -147,8 +156,6 @@ void timer_stop(timer_info_t *timer_info)
     return ;
 }
 
-
-
 /*
  * 获取定时器从初始化到现在的时间(实现计时功能),单位ns
  * @timer_info 硬件定时器
@@ -172,13 +179,11 @@ unsigned long timer_get_time_ns(timer_info_t *timer_info)
      */
     timer_clk = clk_get_apb_rate();
     time_ns = (cntr * 1000 ) / (timer_clk /1000000);
-//    rt_kprintf("[%s] time_us=%lu, cntr=%d, timer_clk=%d\n", __FUNCTION__, time_ns, cntr, timer_clk);
+//    printf("[%s] time_us=%lu, cntr=%d, timer_clk=%d\n", __FUNCTION__, time_ns, cntr, timer_clk);
 
     return time_ns;
 }
 
-
-
 /*
  * 打印timer相关寄存器的值
  * @timer_info 硬件定时器
@@ -188,7 +193,7 @@ void timer_print_regs(timer_info_t *timer_info)
     unsigned int timer_reg_base = 0;
 
     timer_reg_base = timer_get_reg_base(timer_info->timer);
-    rt_kprintf("CNTR=0x%x, HRC=0x%x, LRC=0x%x, CTRL=0x%x\n",
+    printf("CNTR=0x%x, HRC=0x%x, LRC=0x%x, CTRL=0x%x\n",
               reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_CNTR)),
               reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_HRC)),
               reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_LRC)),
@@ -197,4 +202,100 @@ void timer_print_regs(timer_info_t *timer_info)
     return ;
 }
 
+/*
+ * 定时器中断清
+ * @timer_info 定时器信息
+ */
+void timer_int_clr(timer_info_t *timer_info)
+{
+    unsigned int timer_reg_base = 0;        // 寄存器基地址
+    unsigned int ctrl ;  
+    
+    // 判断入参
+    if (NULL == timer_info)
+    {
+        return ;
+    }
+    timer_reg_base = timer_get_reg_base(timer_info->timer);     // 获取寄存器基地址
+    ctrl = reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
+    ctrl = ctrl | (1<<LS1C_PWM_INT_SR) ;
+    reg_write_32(ctrl , (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
+    ctrl = ctrl & (~(1<<LS1C_PWM_INT_SR))  ;
+    reg_write_32(ctrl , (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
 
+    return ;
+}
+/*
+ * 定时器计数清
+ * @timer_info 定时器信息
+ */
+void timer_cnt_clr(timer_info_t *timer_info)
+{
+    unsigned int timer_reg_base = 0;        // 寄存器基地址
+    unsigned int ctrl ;  
+    
+    // 判断入参
+    if (NULL == timer_info)
+    {
+        return ;
+    }
+    timer_reg_base = timer_get_reg_base(timer_info->timer);     // 获取寄存器基地址
+    ctrl = reg_read_32((volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
+    ctrl = ctrl | (1<<LS1C_PWM_CNTR_RST);
+    reg_write_32(ctrl , (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
+    ctrl = ctrl & (~(1<<LS1C_PWM_CNTR_RST)) ;
+    reg_write_32(ctrl , (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
+
+    return ;
+}
+
+/*
+ * 初始化定时器,并开始中断定时
+ * @timer_info 定时器和定时时间信息
+ * @hrc 高中断 lrc 低中断 为1打开,为0关闭
+*/
+void timer_int_init(timer_info_t *timer_info, int hrc, int lrc)
+{
+    unsigned int timer_reg_base = 0;        // 寄存器基地址
+    unsigned long timer_clk = 0;            // 硬件定时器的时钟
+    unsigned long h_value, l_value;
+    unsigned int ctrl = 0;                  // 控制寄存器中的控制信息
+    
+    // 判断入参
+    if (NULL == timer_info)
+    {
+        return ;
+    }
+
+    /*
+     * 把定时时间换算为计数器的值
+     * 计数器值 = 定时器的时钟 * 定时时间(单位ns) / 1000000000
+     * 龙芯1c的定时器时钟为APB时钟,达到126Mhz,
+     * 为避免计算过程发生溢出,这里采用手动优化上面的计算式,也可以采用浮点运算
+     */
+    timer_clk = clk_get_apb_rate();
+    l_value = (timer_clk / 1000000) * (timer_info->time_ns / 1000);     // 将1000000000拆分为1000000和1000
+    l_value = MIN(l_value, TIMER_COUNTER_MAX);
+    h_value = (timer_clk / 1000000) * (timer_info->time_h_ns / 1000);     // 将1000000000拆分为1000000和1000
+    h_value = MIN(h_value, l_value);
+
+    // 控制寄存器信息
+    ctrl = (lrc << LS1C_PWM_INT_LRC_EN)
+           | (hrc << LS1C_PWM_INT_HRC_EN)
+           | (0 << LS1C_PWM_CNTR_RST)
+           | (0 << LS1C_PWM_INT_SR)
+           | (1 << LS1C_PWM_INTEN)
+           | (1 << LS1C_PWM_SINGLE)
+           | (1 << LS1C_PWM_OE)
+           | (1 << LS1C_PWM_CNT_EN);
+
+    // 设置各个寄存器
+    timer_reg_base = timer_get_reg_base(timer_info->timer);     // 获取寄存器基地址
+    reg_write_32(0,                     (volatile unsigned int *)(timer_reg_base + LS1C_PWM_HRC));
+    reg_write_32(l_value--,                 (volatile unsigned int *)(timer_reg_base + LS1C_PWM_LRC));
+    reg_write_32(h_value--,                 (volatile unsigned int *)(timer_reg_base + LS1C_PWM_HRC));
+    reg_write_32(0,                     (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CNTR));
+    reg_write_32(ctrl,                  (volatile unsigned int *)(timer_reg_base + LS1C_PWM_CTRL));
+
+    return ;
+}

+ 28 - 8
bsp/ls1cdev/libraries/ls1c_timer.h

@@ -1,3 +1,12 @@
+ /*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ *                             first version
+ */
 // 硬件定时器头文件
 
 
@@ -22,18 +31,16 @@ typedef enum
 typedef struct
 {
     ls1c_timer_t timer;                  // 硬件定时器
-    unsigned long time_ns;          // 定时时间
+    unsigned long time_ns;          // 低定时时间
+    unsigned long time_h_ns;          // 高定时时间
 }timer_info_t;
 
-
-
 /*
  * 初始化定时器,并开始定时
  * @timer_info 定时器和定时时间信息
  */
 void timer_init(timer_info_t *timer_info);
 
-
 /*
  * 判断指定定时器是否超时
  * @timer_info 定时器
@@ -41,15 +48,12 @@ void timer_init(timer_info_t *timer_info);
  */
 BOOL timer_is_time_out(timer_info_t *timer_info);
 
-
 /*
  * 停止定时器
  * @timer_info 定时器
  */
 void timer_stop(timer_info_t *timer_info);
 
-
-
 /*
  * 获取定时器从初始化到现在的时间(实现计时功能),单位ns
  * @timer_info 硬件定时器
@@ -57,13 +61,29 @@ void timer_stop(timer_info_t *timer_info);
  */
 unsigned long timer_get_time_ns(timer_info_t *timer_info);
 
-
 /*
  * 打印timer相关寄存器的值
  * @timer_info 硬件定时器
  */
 void timer_print_regs(timer_info_t *timer_info);
 
+/*
+ * 定时器中断清
+ * @timer_info 定时器信息
+ */
+void timer_int_clr(timer_info_t *timer_info);
 
+/*
+ * 定时器计数清
+ * @timer_info 定时器信息
+ */
+void timer_cnt_clr(timer_info_t *timer_info);
+
+/*
+ * 初始化定时器,并开始中断定时
+ * @timer_info 定时器和定时时间信息
+ * @hrc 高中断 lrc 低中断 为1打开,为0关闭
+*/
+void timer_int_init(timer_info_t *timer_info, int hrc, int lrc);
 #endif
 

+ 9 - 0
bsp/ls1cdev/libraries/ls1c_uart.c

@@ -1,3 +1,12 @@
+ /*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ *                             first version
+ */
 // 串口相关源码
 
 #include <stdio.h>

+ 9 - 0
bsp/ls1cdev/libraries/ls1c_uart.h

@@ -1,3 +1,12 @@
+ /*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ *                             first version
+ */
 // 串口相关头文件