Landfall

pkg/landfall-examples/jz4740_lcd_driver/jz4740_lcd_driver.c

181:04e69fba99d8
13 months ago Paul Boddie Removed superfluous clock methods. cpm-library-improvements
     1 /*     2  * Access the LCD on JZ4740-based platforms.     3  *     4  * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>     5  *     6  * This program is free software; you can redistribute it and/or     7  * modify it under the terms of the GNU General Public License as     8  * published by the Free Software Foundation; either version 2 of     9  * the License, or (at your option) any later version.    10  *    11  * This program is distributed in the hope that it will be useful,    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    14  * GNU General Public License for more details.    15  *    16  * You should have received a copy of the GNU General Public License    17  * along with this program; if not, write to the Free Software    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor,    19  * Boston, MA  02110-1301, USA    20  */    21     22 #include <l4/devices/lcd-device.h>    23 #include <l4/re/c/video/view.h>    24 #include <l4/sys/cache.h>    25     26 #include <stdint.h>    27     28 int main(void)    29 {    30   l4re_video_view_info_t view_info;    31   l4_size_t i, limit, line, digit, row, mask, value, onpix, offpix;    32     33   /* Obtain device and get framebuffer details. */    34     35   void *lcd_device = lcd_get_device();    36   l4_addr_t fb_vaddr = lcd_get_framebuffer(lcd_device);    37   l4_size_t fb_size = lcd_get_framebuffer_size(lcd_device);    38   uint32_t *fb32 = (uint32_t *) fb_vaddr;    39   uint16_t *fb16 = (uint16_t *) fb_vaddr;    40     41   if (!fb_vaddr) return 1;    42     43   lcd_get_view_info(lcd_device, &view_info);    44   lcd_enable(lcd_device);    45     46   /* Try and show some values. */    47     48   onpix = 0xffaaffaa; offpix = 0x11551155;    49   mask = 0x80000000; value = (l4_size_t) view_info.width;    50     51   i = 0;    52   limit = fb_size / view_info.pixel_info.bytes_per_pixel;    53   line = limit / view_info.height;    54   digit = line / 32;    55   row = line * 10;    56     57   while (i < limit)    58   {    59     if (view_info.pixel_info.bytes_per_pixel == 2)    60       fb16[i] = value & mask ? onpix : offpix;    61     else    62       fb32[i] = value & mask ? onpix : offpix;    63     64     i++;    65     66     if ((i % digit) == 0)    67     {    68       if (mask == 1) mask = 0x80000000;    69       else mask >>= 1;    70     71       onpix = (onpix >> 8) | ((onpix & 0xff) << 24);    72       offpix = (offpix >> 8) | ((offpix & 0xff) << 24);    73     74       if (i == row) value = (l4_size_t) view_info.height;    75       else if (i == (row * 2)) value = 0x80000001;    76     }    77   }    78     79   l4_cache_clean_data((unsigned long) fb_vaddr, (unsigned long) fb_vaddr + fb_size);    80     81   while (1);    82     83   return 0;    84 }