From d16dd1e2dd310beba05d7e42db1382bff5e17581 Mon Sep 17 00:00:00 2001 From: schneider Date: Mon, 13 Jun 2011 01:03:52 +0200 Subject: [PATCH 1/2] added module to test adc --- basic/basic.c | 1 + modules/adc.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 modules/adc.c diff --git a/basic/basic.c b/basic/basic.c index 91288df..51d8e69 100644 --- a/basic/basic.c +++ b/basic/basic.c @@ -44,6 +44,7 @@ void rbInit() { gpioSetDir(RB_LED3, gpioDirection_Output); gpioSetValue (RB_LED3, 1); + IOCON_PIO1_11 = 0x41; // prepare IR //gpioSetDir(RB_IROUT, gpioDirection_Output); diff --git a/modules/adc.c b/modules/adc.c new file mode 100644 index 0000000..0d94a72 --- /dev/null +++ b/modules/adc.c @@ -0,0 +1,102 @@ +#include + +#include "basic/basic.h" + +#include "lcd/render.h" +#include "lcd/backlight.h" +#include "lcd/allfonts.h" +void ReinvokeISP(void); + +/**************************************************************************/ + +void module_adc(void) { + int yctr = 18; + int dx = 0; + uint32_t brightness = 0; + uint8_t c = 0; + + font_direction = FONT_DIR_LTR; // LeftToRight is the default + font = &Font_7x8; + + DoString(0, 0, "adc"); + + backlightInit(); + brightness = backlightGetBrightness(); + + while (1) { + uint32_t results; + lcdDisplay(0); + delayms(10); + + if(gpioGetValue(RB_BTN1)==0){ + brightness++; + if (brightness > 100) brightness = 100; + backlightSetBrightness(brightness); + } + + if(gpioGetValue(RB_BTN0)==0){ + brightness--; + if (brightness > 100) brightness = 0; + backlightSetBrightness(brightness); + } + + if (gpioGetValue(RB_BTN3) == 0) { + while(gpioGetValue(RB_BTN3)==0); + lcdInvert(); + } + + if (gpioGetValue(RB_BTN4)==0) { + while(gpioGetValue(RB_BTN4)==0); + DoString(0,8,"Enter ISP!"); + lcdDisplay(0); + EnableWatchdog(1000*5); + ReinvokeISP(); + + } + + dx = DoString(0, yctr, "Bright:"); + dx = DoInt(dx, yctr, brightness); + DoString(dx, yctr, "% "); + + results = adcRead(1); + dx=DoString(0,yctr+20,"Voltage:"); + results *= 10560; + results /= 1024; + DoInt(dx,yctr+20,results); + + if (results < 3500) { + DoString(0,yctr+30,"Shutdown"); + gpioSetValue (RB_PWR_GOOD, 0); + gpioSetValue (RB_LCD_BL, 0); + SCB_SCR |= SCB_SCR_SLEEPDEEP; + PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN; + __asm volatile ("WFI"); + } else if (results < 3550 ){ + DoString(0,yctr+30,"Warning "); + IOCON_PIO1_11 = 0x0; + gpioSetDir(RB_LED3, gpioDirection_Output); + c++; + if( c == 1 ) + gpioSetValue (RB_LED3, 1); + else if( c == 2 ) + gpioSetValue (RB_LED3, 0); + else if( c == 10 ) + c = 0; + }else { + DoString(0,yctr+30,"OK "); + } + results = adcRead(7); + dx=DoString(0,yctr+40,"Sun:"); + DoInt(dx,yctr+40,results); + + if( results > 340 ){ + backlightSetBrightness(0); + }else{ + backlightSetBrightness(33); + } + + } + + return; +} + From 225f5ee7d73c074b46598fce13259380105b46e7 Mon Sep 17 00:00:00 2001 From: schneider Date: Mon, 13 Jun 2011 01:45:20 +0200 Subject: [PATCH 2/2] added S --- modules/s.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 modules/s.c diff --git a/modules/s.c b/modules/s.c new file mode 100644 index 0000000..4f4bb9f --- /dev/null +++ b/modules/s.c @@ -0,0 +1,124 @@ +#include + +#include "basic/basic.h" + +#include "lcd/render.h" +#include "lcd/allfonts.h" + +void ReinvokeISP(void); +void EnableWatchdog(uint32_t ms); +void delayms(uint32_t ms); + +/**************************************************************************/ + +void module_s(void) { + //Make PIO1_11 an analog input + gpioSetDir(RB_LED3, gpioDirection_Input); + IOCON_PIO1_11 = 0x41; + + backlightInit(); + + uint32_t j=0; + + //disable the JTAG on PIO3_3 + IOCON_PIO3_3 = 0x10; + + int yctr=8; + int dx=0; + + font_direction = FONT_DIR_LTR; // LeftToRight is the default + font = &Font_8x8; + + static FONT fonts[] = { + &Font_7x8, + &Font_Ubuntu18pt, // 3 byte-font + &Font_8x8, + }; + + int fontctr=0; + yctr=18; + + uint8_t trigger; + +#define SEND +#ifdef SEND + trigger=200; + gpioSetDir(RB_LED0, gpioDirection_Output); + IOCON_JTAG_TDI_PIO0_11 = 0x11; +#else + trigger=380; + gpioSetDir(RB_LED0, gpioDirection_Input); + IOCON_JTAG_TDI_PIO0_11 = 0x42; +#endif + + + uint32_t ctr=0; + while (1) { + ctr++; + uint32_t results; + lcdDisplay(j); + delayms(10); + + font=fonts[fontctr]; + + if(gpioGetValue(RB_BTN3)==0){ + while(gpioGetValue(RB_BTN3)==0); + trigger +=10; + }; + if(gpioGetValue(RB_BTN2)==0){ + while(gpioGetValue(RB_BTN2)==0); + trigger -=10; + }; + //dx=DoString(0,0,"Trig:"); + //dx=DoInt(dx,0,trigger); + //DoString(dx,0," "); + + if(gpioGetValue(RB_BTN0)==0){ + while(gpioGetValue(RB_BTN0)==0); + DoString(0,8,"Enter ISP!"); + lcdDisplay(0); + EnableWatchdog(1000*5); + ReinvokeISP(); + }; + + font = &Font_Ubuntu36pt; + static uint8_t ctrx=0, ctry=0, dirx=1, diry=1; + dx=DoString(ctrx,ctry,"S"); + if( dirx ){ + if(ctrx++ == 60) + dirx = 0; + }else{ + if(ctrx-- == 0) + dirx=1; + } + if( diry ){ + if(ctry++ == 12) + diry = 0; + }else{ + if(ctry-- == 0) + diry=1; + } + font = &Font_7x8; + + results = adcRead(1); + //dx=DoString(0,yctr+28,"Voltage:"); + results *= 10560; + results /= 1024; + //DoInt(dx,yctr+28,results); + + if( results < 3500 ){ + DoString(0,yctr+30,"Shutdown"); + gpioSetValue (RB_PWR_GOOD, 0); + gpioSetValue (RB_LCD_BL, 0); + SCB_SCR |= SCB_SCR_SLEEPDEEP; + PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN; + __asm volatile ("WFI"); + }else{ + //DoString(0,yctr+30,"OK "); + ; + } + + } + + return; +}