drv_clcd.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <rtthread.h>
  5. #include "drv_clcd.h"
  6. #define CLCD_WIDTH 480
  7. #define CLCD_HEIGHT 320
  8. #define CLCD_DEVICE(dev) (struct drv_clcd_device*)(dev)
  9. #define PL111_CR_EN 0x001
  10. #define PL111_CR_PWR 0x800
  11. #define PL111_IOBASE 0x10020000
  12. #define PL111_PALBASE (PL111_IOBASE + 0x200)
  13. typedef struct _PL111MMIO
  14. {
  15. uint32_t volatile tim0; //0
  16. uint32_t volatile tim1; //4
  17. uint32_t volatile tim2; //8
  18. uint32_t volatile tim3; //c
  19. uint32_t volatile upbase; //10
  20. uint32_t volatile f; //14
  21. uint32_t volatile control; //18
  22. uint32_t volatile g; //1c
  23. } PL111MMIO;
  24. struct drv_clcd_device
  25. {
  26. struct rt_device parent;
  27. int width;
  28. int height;
  29. uint8_t *fb;
  30. };
  31. struct drv_clcd_device _lcd;
  32. static rt_err_t drv_clcd_init(struct rt_device *device)
  33. {
  34. struct drv_clcd_device *lcd = CLCD_DEVICE(device);
  35. lcd = lcd; /* nothing, right now */
  36. return RT_EOK;
  37. }
  38. static rt_err_t drv_clcd_control(struct rt_device *device, int cmd, void *args)
  39. {
  40. struct drv_clcd_device *lcd = CLCD_DEVICE(device);
  41. switch (cmd)
  42. {
  43. case RTGRAPHIC_CTRL_RECT_UPDATE:
  44. {
  45. struct rt_device_rect_info *info = (struct rt_device_rect_info*)args;
  46. info = info; /* nothing, right now */
  47. }
  48. break;
  49. case RTGRAPHIC_CTRL_GET_INFO:
  50. {
  51. struct rt_device_graphic_info* info = (struct rt_device_graphic_info*)args;
  52. RT_ASSERT(info != RT_NULL);
  53. info->pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
  54. // info->pixel_format = RTGRAPHIC_PIXEL_FORMAT_ARGB888;
  55. info->bits_per_pixel= 16;
  56. info->width = lcd->width;
  57. info->height = lcd->height;
  58. info->framebuffer = lcd->fb;
  59. }
  60. break;
  61. }
  62. return RT_EOK;
  63. }
  64. int drv_clcd_hw_init(void)
  65. {
  66. PL111MMIO *plio;
  67. struct rt_device *device = &_lcd.parent;
  68. /* memset _lcd to zero */
  69. memset(&_lcd, 0x0, sizeof(_lcd));
  70. _lcd.width = CLCD_WIDTH;
  71. _lcd.height = CLCD_HEIGHT;
  72. _lcd.fb = rt_malloc (_lcd.width * _lcd.height * 2);
  73. if (_lcd.fb == NULL)
  74. {
  75. rt_kprintf("initialize frame buffer failed!\n");
  76. return -1;
  77. }
  78. memset(_lcd.fb, 0xff, _lcd.width * _lcd.height * 2);
  79. plio = (PL111MMIO*)PL111_IOBASE;
  80. plio->tim0 = 0x3F1F3C00 | ((CLCD_WIDTH/16 - 1) << 2);
  81. plio->tim1 = 0x080B6000 | (CLCD_HEIGHT - 1);
  82. plio->upbase = (uint32_t)_lcd.fb;
  83. /* 16-bit 565 color */
  84. plio->control = 0x1921 | (0x6 << 1);
  85. device->type = RT_Device_Class_Graphic;
  86. device->init = drv_clcd_init;
  87. device->control = drv_clcd_control;
  88. rt_device_register(device, "lcd", RT_DEVICE_FLAG_RDWR);
  89. return 0;
  90. }
  91. INIT_DEVICE_EXPORT(drv_clcd_hw_init);