Prex Home / Browse Source - Prex Version: 0.9.0

root/bsp/drv/arm/gba/lcd.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. lcd_cursor
  2. lcd_putc
  3. lcd_copyrows
  4. lcd_eraserows
  5. lcd_set_attr
  6. lcd_get_cursor
  7. lcd_init_font
  8. lcd_init_screen
  9. lcd_init

   1 /*-
   2  * Copyright (c) 2005-2009, Kohsuke Ohtani
   3  * All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  * 1. Redistributions of source code must retain the above copyright
   9  *    notice, this list of conditions and the following disclaimer.
  10  * 2. Redistributions in binary form must reproduce the above copyright
  11  *    notice, this list of conditions and the following disclaimer in the
  12  *    documentation and/or other materials provided with the distribution.
  13  * 3. Neither the name of the author nor the names of any co-contributors
  14  *    may be used to endorse or promote products derived from this software
  15  *    without specific prior written permission.
  16  *
  17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27  * SUCH DAMAGE.
  28  */
  29 
  30 /*
  31  * lcd.c - GBA LCD video driver
  32  */
  33 
  34 #include <driver.h>
  35 #include <wscons.h>
  36 #include "lcd.h"
  37 #include "font.h"
  38 
  39 /* #define DEBUG_LCD 1 */
  40 
  41 #ifdef DEBUG_LCD
  42 #define DPRINTF(a) printf a
  43 #else
  44 #define DPRINTF(a)
  45 #endif
  46 
  47 struct lcd_softc {
  48         device_t        dev;
  49         uint16_t        *vram;
  50 };
  51 
  52 static int      lcd_init(struct driver *);
  53 static void     lcd_cursor(void*, int, int);
  54 static void     lcd_putc(void *, int, int, int);
  55 static void     lcd_copyrows(void *,int, int, int);
  56 static void     lcd_eraserows(void *,int, int);
  57 static void     lcd_set_attr(void *, int);
  58 static void     lcd_get_cursor(void *, int *, int *);
  59 
  60 static struct devops lcd_devops = {
  61         /* open */      no_open,
  62         /* close */     no_close,
  63         /* read */      no_read,
  64         /* write */     no_write,
  65         /* ioctl */     no_ioctl,
  66         /* devctl */    no_devctl,
  67 };
  68 
  69 struct driver lcd_driver = {
  70         /* name */      "lcd",
  71         /* devops */    &lcd_devops,
  72         /* devsz */     sizeof(struct lcd_softc),
  73         /* flags */     0,
  74         /* probe */     NULL,
  75         /* init */      lcd_init,
  76         /* shutdown */  NULL,
  77 };
  78 
  79 static struct wscons_video_ops wscons_lcd_ops = {
  80         lcd_cursor,             /* cursor */
  81         lcd_putc,               /* putc */
  82         lcd_copyrows,           /* copyrows */
  83         lcd_eraserows,          /* eraserows */
  84         lcd_set_attr,           /* set_attr */
  85         lcd_get_cursor,         /* get_cursor */
  86 };
  87 
  88 static void
  89 lcd_cursor(void *aux, int row, int col)
  90 {
  91 
  92         /* DO NOTHING */
  93 }
  94 
  95 static void
  96 lcd_putc(void *aux, int row, int col, int ch)
  97 {
  98         struct lcd_softc *sc = aux;
  99 
 100         sc->vram[row * VSCR_COLS + col] = ch;
 101 }
 102 
 103 static void
 104 lcd_copyrows(void *aux, int srcrow, int dstrow, int nrows)
 105 {
 106         struct lcd_softc *sc = aux;
 107         int i;
 108 
 109         for (i = 0; i < nrows * VSCR_COLS; i++) {
 110                 sc->vram[dstrow * VSCR_COLS + i] =
 111                         sc->vram[srcrow * VSCR_COLS + i];
 112         }
 113 }
 114 
 115 static void
 116 lcd_eraserows(void *aux, int row, int nrows)
 117 {
 118         struct lcd_softc *sc = aux;
 119         int i, start, end;
 120 
 121         start = row * VSCR_COLS;
 122         end = start + nrows * VSCR_COLS;
 123 
 124         for (i = start; i < end; i++)
 125                 sc->vram[i] = ' ';
 126 }
 127 
 128 static void
 129 lcd_set_attr(void *aux, int attr)
 130 {
 131 
 132         /* DO NOTHING */
 133 }
 134 
 135 static void
 136 lcd_get_cursor(void *aux, int *col, int *row)
 137 {
 138 
 139         *col = 0;
 140         *row = 0;
 141 }
 142 
 143 static void
 144 lcd_init_font(void)
 145 {
 146         int i, row, col, bit, val = 0;
 147         uint16_t *tile = CONSOLE_TILE;
 148 
 149         for (i = 0; i < 128; i++) {
 150                 for (row = 0; row < 8; row++) {
 151                         for (col = 7; col >= 0; col--) {
 152                                 bit = (font_bitmap[i][row] & (1 << col)) ? 2 : 1;
 153                                 if (col % 2)
 154                                         val = bit;
 155                                 else
 156                                         tile[(i * 32) + (row * 4) + ((7 - col) / 2)] =
 157                                                 val + (bit << 8);
 158                         }
 159                 }
 160         }
 161 }
 162 
 163 static void
 164 lcd_init_screen(void)
 165 {
 166         uint16_t *pal = BG_PALETTE;
 167 
 168         /* Initialize palette */
 169         pal[0] = 0;             /* Transparent */
 170         pal[1] = RGB(0,0,0);    /* Black */
 171         pal[2] = RGB(31,31,31); /* White */
 172 
 173         /* Setup lcd */
 174         REG_BG3CNT = 0x1080;    /* Size0, 256color, priority0 */
 175         REG_DISPCNT = 0x0800;   /* Mode0, BG3 */
 176 }
 177 
 178 static int
 179 lcd_init(struct driver *self)
 180 {
 181         device_t dev;
 182         struct lcd_softc *sc;
 183 
 184         dev = device_create(self, "lcd", D_CHR|D_TTY);
 185 
 186         sc = device_private(dev);
 187         sc->vram = CONSOLE_MAP;
 188 
 189         lcd_init_font();
 190         lcd_init_screen();
 191 
 192         wscons_attach_video(&wscons_lcd_ops, sc);
 193         return 0;
 194 }

/* [<][>][^][v][top][bottom][index][help] */