summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: be53622cc18069c9882c8a0515af9f5d3d650258 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Makefile for OpenWrt
#
# Copyright (C) 2007 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

all: world

TOPDIR:=${CURDIR}
LC_ALL:=C
LANG:=C
IS_TTY:=${shell tty -s && echo 1 || echo 0}
export TOPDIR LC_ALL LANG IS_TTY

ifneq ($(OPENWRT_BUILD),1)
  export OPENWRT_BUILD:=1
  include $(TOPDIR)/include/toplevel.mk
else
  include $(TOPDIR)/include/host.mk

  include rules.mk
  include $(INCLUDE_DIR)/depends.mk
  include $(INCLUDE_DIR)/subdir.mk
  include tools/Makefile
  include toolchain/Makefile

clean: FORCE
	rm -rf build_* bin tmp

dirclean: clean
	rm -rf staging_dir_* toolchain_build_* tool_build

distclean: dirclean config-clean symlinkclean docs/clean
	rm -rf dl

package/% target/%: FORCE
	$(MAKE) -C $(patsubst %/$*,%,$@) $*

world: .config $(tools/stamp) $(toolchain/stamp) FORCE
	$(MAKE) target/compile
	$(MAKE) package/compile
	$(MAKE) package/install
	$(MAKE) target/install
	$(MAKE) package/index

endif
bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdint.h>

#include "libdpf/dpf.h"

typedef struct
{
  unsigned char R;
  unsigned char G;
  unsigned char B;
  unsigned char A;
} RGBA;

static DPFContext *dpf;
static RGBA *fb;
static RGBA *fbo;
static uint8_t *fb_16;




void
lcd_on (void)
{
  DPFValue val;
  if (!dpf)
    return;
  val.type = TYPE_INTEGER;
  val.value.integer = 7;
  dpf_setproperty (dpf, PROPERTY_BRIGHTNESS, &val);
}



void
lcd_off (void)
{
  DPFValue val;
  if (!dpf)
    return;
  val.type = TYPE_INTEGER;
  val.value.integer = 0;
  dpf_setproperty (dpf, PROPERTY_BRIGHTNESS, &val);
}




void
lcd_close (void)
{
  if (!dpf)
    return;
  dpf_close (dpf);
  dpf = NULL;
  free (fb);
  free (fb_16);
}

#define _RGB565_0(p) \
        (( (((p)->R) & 0xf8)          ) | ((((p)->G) & 0xe0) >> 5))
#define _RGB565_1(p) \
        (( (((p)->G) & 0x1c) << 3 ) | ((((p)->B) & 0xf8) >> 3))


static int
find_dr (short *rect)
{
  RGBA *p = fb, *po = fbo;
  int e;
  int x, y;
  rect[0] = dpf->width;
  rect[1] = dpf->height;
  rect[2] = 0;
  rect[3] = 0;

  for (y = 0; y < dpf->height; y++)
    {
      e = 0;
      for (x = 0; x < dpf->width; x++)
        {
          if (memcmp (p, po, 4))
            {
              if (x < rect[0])
                rect[0] = x;
              if (x >= rect[2])
                rect[2] = x + 1;
              e = 1;
            }
          p++;
          po++;
        }
      if (e)
        {
          if (y < rect[1])
            rect[1] = y;
          if (y >= rect[3])
            rect[3] = y + 1;
        }
    }
  return rect[2];

}

static void
blit (int x1, int y1, int x2, int y2)
{
  int r;
  int c;
  short rect[4] = { x1, y1, x2, y2 };

  RGBA *p, *rp, *po, *rpo;
  uint8_t *p_16;

  if (!dpf)
    return;

  if (x1 == -1)
    {
      if (!find_dr (rect))
        return;
    }

  rp = fb + (dpf->width * rect[1]) + rect[0];
  rpo = fbo + (dpf->width * rect[1]) + rect[0];

  p_16 = fb_16;

  for (r = rect[1]; r < rect[3]; r++)
    {
      p = rp;
      po = rpo;
      for (c = rect[0]; c < rect[2]; c++)
        {
          *p_16++ = _RGB565_0 (p);
          *p_16++ = _RGB565_1 (p);
          memcpy (po, p, 4);
          p++;
          po++;
        }
      rp += dpf->width;
    }

  //printf ("%d %d %d %d\n", rect[0], rect[1], rect[2], rect[3]);


  dpf_screen_blit (dpf, fb_16, rect);
}


void
lcd_vline (int x, int y1, int y2, int r, int g, int b)
{
  RGBA c = {.R = r,.G = g,.B = b };
  RGBA *p = fb;
  int y;

  if (!dpf)
    return;

  if (y1 > y2)
    {
      y = y1;
      y1 = y2;
      y2 = y;
    }

  p += x + y1 * dpf->width;


  for (y = y1; y <= y2; ++y)
    {
      memcpy (p, &c, sizeof (c));
      p += dpf->width;
    }

}

void
lcd_hline (int y, int x1, int x2, int r, int g, int b)
{
  RGBA c = {.R = r,.G = g,.B = b };
  RGBA *p = fb;
  int x;

  if (!dpf)
    return;


  if (x1 > x2)
    {
      x = x1;
      x1 = x2;
      x2 = x;
    }

  p += x1 + y * dpf->width;

  for (x = x1; x <= x2; ++x)
    {
      memcpy (p, &c, sizeof (c));
      p++;
    }

}

void
lcd_box (int x1, int y1, int x2, int y2, int r, int g, int b)
{
  lcd_vline (x1, y1, y2, r, g, b);
  blit (x1, y1, x1 + 1, y2 + 1);
  lcd_vline (x2, y1, y2, r, g, b);
  blit (x2, y1, x2 + 1, y2 + 1);
  lcd_hline (y1, x1 + 1, x2 - 1, r, g, b);
  blit (x1 + 1, y1, x2, y1 + 1);
  lcd_hline (y2, x1 + 1, x2 - 1, r, g, b);
  blit (x1 + 1, y2, x2, y2 + 1);
}

#define LCD_SS_A	(1 << 0)
#define LCD_SS_B	(1 << 1)
#define LCD_SS_C	(1 << 2)
#define LCD_SS_D	(1 << 3)
#define LCD_SS_E	(1 << 4)
#define LCD_SS_F	(1 << 5)
#define LCD_SS_G	(1 << 6)

void
lcd_ss (int v, int x1, int y1, int w, int h)
{
  int x2 = x1 + w;
  int y2 = y1 + (h / 2);
  int y3 = y1 + h;

  int lut[] =
    { LCD_SS_A | LCD_SS_B | LCD_SS_C | LCD_SS_D | LCD_SS_E | LCD_SS_F,
    LCD_SS_B | LCD_SS_C,
    LCD_SS_A | LCD_SS_B | LCD_SS_D | LCD_SS_E | LCD_SS_G,
    LCD_SS_A | LCD_SS_B | LCD_SS_C | LCD_SS_D | LCD_SS_G,
    LCD_SS_B | LCD_SS_C | LCD_SS_F | LCD_SS_G,
    LCD_SS_A | LCD_SS_C | LCD_SS_D | LCD_SS_F | LCD_SS_G,
    LCD_SS_A | LCD_SS_C | LCD_SS_D | LCD_SS_E | LCD_SS_F | LCD_SS_G,
    LCD_SS_A | LCD_SS_B | LCD_SS_C,
    LCD_SS_A | LCD_SS_B | LCD_SS_C | LCD_SS_D | LCD_SS_E | LCD_SS_F |
      LCD_SS_G,
    LCD_SS_A | LCD_SS_B | LCD_SS_C | LCD_SS_D | LCD_SS_F | LCD_SS_G,
    0
  };

  int l;
  int c;


  if (v == 0)
    v = 10;

  l = lut[v];

  printf ("SS %d %x %d %d %d %d %d\n", v, l, x1, x2, y1, y2, y3);

  c = (l & LCD_SS_A) ? 255 : 0;
  lcd_hline (y1, x1, x2, c, c, c);

  c = (l & LCD_SS_B) ? 255 : 0;
  lcd_vline (x2, y1, y2, c, c, c);

  c = (l & LCD_SS_C) ? 255 : 0;
  lcd_vline (x2, y2, y3, c, c, c);

  c = (l & LCD_SS_D) ? 255 : 0;
  lcd_hline (y3, x1, x2, c, c, c);

  c = (l & LCD_SS_E) ? 255 : 0;
  lcd_vline (x1, y2, y3, c, c, c);

  c = (l & LCD_SS_F) ? 255 : 0;
  lcd_vline (x1, y1, y2, c, c, c);

  c = (l & LCD_SS_G) ? 255 : 0;
  lcd_hline (y2, x1, x2, c, c, c);

  blit (x1, y1, x1 + 1, y3 + 1);
  blit (x2, y1, x2 + 1, y3 + 1);

  blit (x1, y1, x2 + 1, y1 + 1);
  blit (x1, y2, x2 + 1, y2 + 1);
  blit (x1, y3, x2 + 1, y3 + 1);

}



int
lcd_open (void)
{
  int err;
  DPFValue val;


  err = dpf_open ("usb0", &dpf);

  if (err < 0)
    {
      dpf = NULL;
      return -1;
    }


  val.type = TYPE_INTEGER;
  val.value.integer = 1;
  dpf_setproperty (dpf, PROPERTY_ORIENTATION, &val);


  fb_16 = malloc (dpf->height * dpf->width * dpf->bpp);
  fb = malloc (dpf->height * dpf->width * sizeof (RGBA));
  fbo = malloc (dpf->height * dpf->width * sizeof (RGBA));

  bzero (fb, dpf->height * dpf->width * sizeof (RGBA));
  blit (0, 0, 320, 240);



  return 0;
}