Add adc to example.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 22 Mar 2011 13:10:18 +0000 (13:10 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 22 Mar 2011 13:10:18 +0000 (13:10 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4791 38d2e660-2303-0410-9eaa-f027e97ec537

boards/sam3x-ek/examples/display/display.mk
boards/sam3x-ek/examples/display/main.c

index 4cb1a03ea5f6d6e6fdf3e60da9ef62d89a80a217..d114592670e9a9232cae19a54f7083f20edff7f7 100644 (file)
@@ -26,6 +26,8 @@ display_WIZARD_CSRC = \
        bertos/gfx/text.c \
        bertos/cpu/cortex-m3/drv/timer_cm3.c \
        bertos/drv/timer.c \
+       bertos/drv/adc.c \
+       bertos/cpu/cortex-m3/drv/adc_sam3.c \
        bertos/mware/formatwr.c \
        bertos/mware/sprintf.c \
        bertos/gfx/line.c \
@@ -84,10 +86,10 @@ display_ASRC = $(display_CPU_ASRC) $(display_WIZARD_ASRC) $(display_USER_ASRC)
 
 # CPU specific flags and options, defined in the CPU definition files.
 # Automatically generated by the wizard. PLEASE DO NOT EDIT!
-display_CPU_CPPASRC = bertos/cpu/cortex-m3/hw/crt_cm3.S bertos/cpu/cortex-m3/hw/vectors_cm3.S 
+display_CPU_CPPASRC = bertos/cpu/cortex-m3/hw/crt_cm3.S bertos/cpu/cortex-m3/hw/vectors_cm3.S
 display_CPU_CPPAFLAGS = -g -gdwarf-2 -mthumb -mno-thumb-interwork
 display_CPU_CPPFLAGS = -O0 -g3 -gdwarf-2 -mthumb -mno-thumb-interwork -fno-strict-aliasing -fwrapv -fverbose-asm -Ibertos/cpu/cortex-m3/ -D__ARM_SAM3X8__
-display_CPU_CSRC = bertos/cpu/cortex-m3/hw/init_cm3.c bertos/cpu/cortex-m3/drv/irq_cm3.c bertos/cpu/cortex-m3/drv/clock_sam3.c 
+display_CPU_CSRC = bertos/cpu/cortex-m3/hw/init_cm3.c bertos/cpu/cortex-m3/drv/irq_cm3.c bertos/cpu/cortex-m3/drv/clock_sam3.c
 display_PROGRAMMER_CPU = sam3
 display_CPU_LDFLAGS = -mthumb -mno-thumb-interwork -nostartfiles -Wl,--no-warn-mismatch -Wl,-dT bertos/cpu/cortex-m3/scripts/sam3x8_rom.ld
 display_STOPFLASH_SCRIPT = bertos/prg_scripts/arm/stopopenocd.sh
index ac7ad2f75a86e26c7881f23fbe8f7fa7faabea26..c712289306a94a4ac7c5b2eee8ad386c782f5427 100644 (file)
 
 #include "hw/hw_led.h"
 #include "hw/hw_lcd.h"
+#include "hw/hw_adc.h"
 #include "hw/hw_sdram.h"
 
 #include <cfg/debug.h>
+
 #include <cpu/irq.h>
+
 #include <struct/heap.h>
+
 #include <drv/timer.h>
 #include <drv/kbd.h>
 #include <drv/lcd_hx8347.h>
+#include <drv/adc.h>
+
 #include <gfx/gfx.h>
 #include <gfx/font.h>
 #include <gfx/text.h>
 #include <gui/menu.h>
 #include <icons/logo.h>
+
 #include <io/kfile.h>
+
 #include <kern/signal.h>
 #include <kern/proc.h>
 
@@ -307,6 +315,26 @@ static void NORETURN soft_reset(Bitmap * bm)
        UNREACHABLE();
 }
 
+static void read_adc(Bitmap *bm)
+{
+       gfx_bitmapClear(bm);
+       text_xprintf(bm, 0, 0, TEXT_FILL | TEXT_CENTER, "ADC Value");
+       while (1)
+       {
+               uint16_t value = ADC_RANGECONV(adc_read(1), 0, 3300);
+               uint16_t temp = hw_convertToDegree (adc_read(ADC_TEMPERATURE_CH));
+
+               text_xprintf(lcd_bitmap, 2, 0, TEXT_FILL | TEXT_CENTER,
+                                                                       "Volage on VR1: %d.%dV", value / 1000, value % 1000);
+               text_xprintf(lcd_bitmap, 3, 0, TEXT_FILL | TEXT_CENTER,
+                                                                       "CPU temperature: %d.%dC", temp / 10, temp % 10);
+               lcd_hx8347_blitBitmap(bm);
+               timer_delay(400);
+               if (kbd_peek() & KEY_MASK)
+                       break;
+       }
+}
+
 
 static struct MenuItem main_items[] =
 {
@@ -318,6 +346,7 @@ static struct MenuItem main_items[] =
        { (const_iptr_t)"Show uptime", 0, (MenuHook)uptime, NULL },
        { (const_iptr_t)"Display brightness", 0, (MenuHook)setBrightness, NULL },
        { (const_iptr_t)"Reboot", 0, (MenuHook)soft_reset, NULL },
+       { (const_iptr_t)"Read ADC value", 0, (MenuHook)read_adc, NULL },
        { (const_iptr_t)0, 0, NULL, (iptr_t)0 }
 };
 static struct Menu main_menu = { main_items, "BeRTOS", MF_STICKY | MF_SAVESEL, NULL, 0, lcd_hx8347_blitBitmap };
@@ -328,12 +357,15 @@ int main(void)
        unsigned i;
 
        IRQ_ENABLE;
-
        kdbg_init();
        LED_INIT();
        timer_init();
        proc_init();
        sdram_init();
+       adc_init();
+
+       /* Enable the adc to read internal temperature sensor */
+       hw_enableTempRead();
 
        heap_init(&heap, (void *)SDRAM_BASE, SDRAM_SIZE);
        lcd_bitmap = heap_allocmem(&heap, RAST_SIZE(LCD_WIDTH, LCD_HEIGHT));
@@ -372,4 +404,5 @@ int main(void)
                menu_handle(&main_menu);
                cpu_relax();
        }
+
 }