lnn800x480.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * File : lnn800x480.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2010 - 2012, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-01-01 bernard first version from QiuYi's driver
  13. */
  14. #include <rtthread.h>
  15. #include <soc3210.h>
  16. /* LCD driver for 800x480 16bit */
  17. #define RT_HW_LCD_WIDTH 800
  18. #define RT_HW_LCD_HEIGHT 480
  19. #define K1BASE 0xA0000000
  20. #define KSEG1(addr) ((void *)(K1BASE | (rt_uint32_t)(addr)))
  21. #define HW_FB_ADDR KSEG1(_rt_framebuffer)
  22. #define HW_FB_PIXEL(x, y) *(volatile rt_uint16_t*)((rt_uint8_t*)HW_FB_ADDR + (y * RT_HW_LCD_WIDTH * 2) + x * 2)
  23. ALIGN(4)
  24. volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
  25. static struct rt_device_graphic_info _lcd_info;
  26. static rt_err_t rt_lcd_init (rt_device_t dev)
  27. {
  28. /* disable LCD controller */
  29. LCD_CTRL = LCD_CTRL & 0xfffe;
  30. /* set LCD clock */
  31. HSB_MISC_REG = (HSB_MISC_REG & 0xFFFD01FF) |
  32. (0x01 << 17) | /* enable LCD */
  33. (0x05 << 9); /* clock */
  34. LCD_VBARA = (rt_uint32_t)_rt_framebuffer - 0x80000000;
  35. LCD_VBARB = (rt_uint32_t)_rt_framebuffer - 0x80000000;
  36. LCD_HTIM = 0x12c031f;
  37. LCD_VTIM = 0x11501df;
  38. LCD_HVLEN = 0x41e0279;
  39. LCD_CTRL = 0x8709;
  40. rt_kprintf("VBARA 0x%08x\n", LCD_VBARA);
  41. rt_kprintf("CTRL 0x%08x\n", LCD_CTRL);
  42. rt_kprintf("HTIM 0x%08x\n", LCD_HTIM);
  43. rt_kprintf("VTIM 0x%08x\n", LCD_VTIM);
  44. rt_kprintf("HVLEN 0x%08x\n", LCD_HVLEN);
  45. rt_kprintf("HSB_MISC 0x%08x\n", HSB_MISC_REG);
  46. return RT_EOK;
  47. }
  48. static rt_err_t rt_lcd_control (rt_device_t dev, rt_uint8_t cmd, void *args)
  49. {
  50. switch (cmd)
  51. {
  52. case RTGRAPHIC_CTRL_RECT_UPDATE:
  53. break;
  54. case RTGRAPHIC_CTRL_POWERON:
  55. break;
  56. case RTGRAPHIC_CTRL_POWEROFF:
  57. break;
  58. case RTGRAPHIC_CTRL_GET_INFO:
  59. rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
  60. break;
  61. case RTGRAPHIC_CTRL_SET_MODE:
  62. break;
  63. }
  64. return RT_EOK;
  65. }
  66. void rt_hw_lcd_init(void)
  67. {
  68. rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
  69. if (lcd == RT_NULL)
  70. return; /* no memory yet */
  71. _lcd_info.bits_per_pixel = 16;
  72. _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
  73. _lcd_info.framebuffer = (rt_uint8_t*)HW_FB_ADDR;
  74. _lcd_info.width = RT_HW_LCD_WIDTH;
  75. _lcd_info.height = RT_HW_LCD_HEIGHT;
  76. /* init device structure */
  77. lcd->type = RT_Device_Class_Graphic;
  78. lcd->init = rt_lcd_init;
  79. lcd->open = RT_NULL;
  80. lcd->close = RT_NULL;
  81. lcd->control = rt_lcd_control;
  82. lcd->user_data = (void*)&_lcd_info;
  83. /* register lcd device to RT-Thread */
  84. rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
  85. }