From 7271b9e475278ed3e73c34dd0b74d888ee4bee33 Mon Sep 17 00:00:00 2001 From: asterix Date: Tue, 22 Mar 2011 13:10:18 +0000 Subject: [PATCH] Add adc to example. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4791 38d2e660-2303-0410-9eaa-f027e97ec537 --- boards/sam3x-ek/examples/display/display.mk | 6 ++-- boards/sam3x-ek/examples/display/main.c | 35 ++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/boards/sam3x-ek/examples/display/display.mk b/boards/sam3x-ek/examples/display/display.mk index 4cb1a03e..d1145926 100644 --- a/boards/sam3x-ek/examples/display/display.mk +++ b/boards/sam3x-ek/examples/display/display.mk @@ -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 diff --git a/boards/sam3x-ek/examples/display/main.c b/boards/sam3x-ek/examples/display/main.c index ac7ad2f7..c7122893 100644 --- a/boards/sam3x-ek/examples/display/main.c +++ b/boards/sam3x-ek/examples/display/main.c @@ -39,20 +39,28 @@ #include "hw/hw_led.h" #include "hw/hw_lcd.h" +#include "hw/hw_adc.h" #include "hw/hw_sdram.h" #include + #include + #include + #include #include #include +#include + #include #include #include #include #include + #include + #include #include @@ -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(); } + } -- 2.25.1