From d4f59ea32c3c2cfee85cc35e2b0c9523dcb0b8de Mon Sep 17 00:00:00 2001
From: asterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Date: Thu, 13 Oct 2011 15:14:46 +0000
Subject: [PATCH] Use heap to allocate bitmap for display.

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5160 38d2e660-2303-0410-9eaa-f027e97ec537
---
 .../examples/sam3x-ek_http_server/main.c      | 28 +++++++++++--------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/boards/sam3x-ek/examples/sam3x-ek_http_server/main.c b/boards/sam3x-ek/examples/sam3x-ek_http_server/main.c
index 6b545b4d..d59ed6d8 100644
--- a/boards/sam3x-ek/examples/sam3x-ek_http_server/main.c
+++ b/boards/sam3x-ek/examples/sam3x-ek_http_server/main.c
@@ -68,6 +68,7 @@
 
 #include <kern/proc.h>
 #include <kern/monitor.h>
+#include <struct/heap.h>
 
 #include <net/http.h>
 
@@ -119,9 +120,10 @@ typedef struct BoardStatus
 
 static BoardStatus status;
 static uint8_t raster[RAST_SIZE(LCD_WIDTH, LCD_HEIGHT)];
-static Bitmap lcd_bitmap;
+static Bitmap *lcd_bitmap;
 extern Font font_gohu;
 static int lcd_brightness = LCD_BACKLIGHT_MAX;
+static struct Heap heap;
 
 
 static void init(void)
@@ -145,21 +147,23 @@ static void init(void)
 
 	/* Enable the adc to read internal temperature sensor */
 	hw_enableTempRead();
-
 	LED_INIT();
 
+	heap_init(&heap, (void *)SDRAM_BASE, SDRAM_SIZE);
+	lcd_bitmap = heap_allocmem(&heap, RAST_SIZE(LCD_WIDTH, LCD_HEIGHT));
+	if (lcd_bitmap)
+		kprintf("Allocated memory for display raster, addr 0x%x\n", (unsigned)lcd_bitmap);
+	else
+	{
+		kprintf("Error allocating memory for LCD raster!\n");
+	}
+
 	lcd_hx8347_init();
 	lcd_setBacklight(lcd_brightness);
 
-	gfx_bitmapInit(&lcd_bitmap, raster, LCD_WIDTH, LCD_HEIGHT);
-	gfx_setFont(&lcd_bitmap, &font_luBS14);
-
-	lcd_hx8347_blitBitmap(&lcd_bitmap);
-	lcd_hx8347_blitBitmap24(10, 52, BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, bmp_logo);
-	timer_delay(3000);
-
-	text_xprintf(&lcd_bitmap, 1, 0, TEXT_CENTER, "Brightness: %d", lcd_brightness);
-	lcd_hx8347_blitBitmap(&lcd_bitmap);
+	gfx_bitmapInit(lcd_bitmap, raster, LCD_WIDTH, LCD_HEIGHT);
+	gfx_setFont(lcd_bitmap, &font_luBS14);
+	lcd_hx8347_blitBitmap(lcd_bitmap);
 
 	/* Initialize TCP/IP stack */
 	tcpip_init(NULL, NULL);
@@ -169,6 +173,8 @@ static void init(void)
 	netif_set_default(&netif);
 	netif_set_up(&netif);
 
+	lcd_hx8347_blitBitmap24(10, 52, BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, bmp_logo);
+	timer_delay(3000);
 }
 
 static NORETURN void proc_displayRefresh(void)
-- 
2.25.1