Merge git://github.com/r0ket/r0ket

This commit is contained in:
bernd 2011-07-26 04:52:22 +02:00
commit 515c39c0a8
12 changed files with 170 additions and 48 deletions

View File

@ -81,7 +81,7 @@ $(LIBFILE): $(OBJS) $(WRAPOBJ)
$(CC) $(CFLAGS) -o $@ $< $(CC) $(CFLAGS) -o $@ $<
clean: clean:
rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o tester/*.o
%.c: %.c:
@echo @echo

View File

@ -30,6 +30,9 @@ int lcdInitConfig(){
lcdPrint("open:"); lcdPrint("open:");
lcdPrintln(f_get_rc_string(res)); lcdPrintln(f_get_rc_string(res));
if(res){ if(res){
if(res==FR_NO_FILESYSTEM)
return 1;
lcdPrintln("new r0ket.cfg..."); lcdPrintln("new r0ket.cfg...");
res=f_open(&file, "r0ket.cfg", FA_OPEN_ALWAYS|FA_WRITE); res=f_open(&file, "r0ket.cfg", FA_OPEN_ALWAYS|FA_WRITE);
@ -116,9 +119,13 @@ void tick_default(void) {
ctr++; ctr++;
incTimer(); incTimer();
if(ctr>100){ if(ctr>100){
if(!adcMutex){
VoltageCheck(); VoltageCheck();
LightCheck(); LightCheck();
ctr=0; ctr=0;
}else{
ctr--;
};
}; };
if(isNight()) if(isNight())

View File

@ -37,26 +37,29 @@ void ReinvokeISP(void);
/**************************************************************************/ /**************************************************************************/
void flameSetI2C(uint8_t cr, uint8_t value) { uint8_t flameEnabled = 0;
uint8_t flameMode = FLAME_OFF;
uint8_t flameI2Cpwm = 0;
uint16_t flameTicks = 0;
uint32_t flameSetI2C(uint8_t cr, uint8_t value) {
I2CMasterBuffer[0] = FLAME_I2C_WRITE; I2CMasterBuffer[0] = FLAME_I2C_WRITE;
I2CMasterBuffer[1] = cr; I2CMasterBuffer[1] = cr;
I2CMasterBuffer[2] = value; I2CMasterBuffer[2] = value;
I2CWriteLength = 3; I2CWriteLength = 3;
I2CReadLength = 0; I2CReadLength = 0;
i2cEngine(); return i2cEngine();
} }
void setFlamePWM() {
uint8_t flameMode = FLAME_OFF; flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm
uint8_t flameI2Csend = 0; }
uint8_t flameI2Cpwm = 0;
uint16_t flameTicks = 0;
void tick_flame(void) { // every 10ms void tick_flame(void) { // every 10ms
flameTicks++; flameTicks++;
if (flameMode == FLAME_OFF) { if (flameMode == FLAME_OFF) {
if (isNight()) { if (isNight() && flameEnabled) {
flameTicks = 0; flameTicks = 0;
flameMode = FLAME_UP; flameMode = FLAME_UP;
} }
@ -64,7 +67,7 @@ void tick_flame(void) { // every 10ms
if (flameMode == FLAME_UP) { if (flameMode == FLAME_UP) {
flameI2Cpwm++; flameI2Cpwm++;
flameI2Csend = 1; push_queue(&setFlamePWM);
if (flameI2Cpwm == 0xFF) { if (flameI2Cpwm == 0xFF) {
flameMode = FLAME_UP_WAIT; flameMode = FLAME_UP_WAIT;
flameTicks = 0; flameTicks = 0;
@ -79,7 +82,7 @@ void tick_flame(void) { // every 10ms
if (flameMode == FLAME_DOWN) { if (flameMode == FLAME_DOWN) {
flameI2Cpwm--; flameI2Cpwm--;
flameI2Csend = 1; push_queue(&setFlamePWM);
if (flameI2Cpwm == 0x00) { if (flameI2Cpwm == 0x00) {
flameMode = FLAME_DOWN_WAIT; flameMode = FLAME_DOWN_WAIT;
flameTicks = 0; flameTicks = 0;
@ -97,18 +100,20 @@ void main_flame(void) {
i2cInit(I2CMASTER); // Init I2C i2cInit(I2CMASTER); // Init I2C
flameEnabled = (flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED0) == I2CSTATE_ACK); // probe i2c
if (flameEnabled) {
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED0); // set led0 off
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED1); // set led1 off
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED2); // set led2 off
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_OFF << FLAME_I2C_LS0_LED3); // set led3 off
flameSetI2C(FLAME_I2C_CR_PSC0, 0x00); // set prescaler flameSetI2C(FLAME_I2C_CR_PSC0, 0x00); // set prescaler
flameSetI2C(FLAME_I2C_CR_PWM0, 0x00); // set pwm flameSetI2C(FLAME_I2C_CR_PWM0, 0x00); // set pwm
flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_PWM0 << FLAME_I2C_LS0_LED0); // set led0 to pwm flameSetI2C(FLAME_I2C_CR_LS0, FLAME_I2C_LS0_PWM0 << FLAME_I2C_LS0_LED0); // set led0 to pwm
while (1) {
delayms(20);
if (flameI2Csend == 1) {
flameI2Csend = 0;
flameSetI2C(FLAME_I2C_CR_PWM0, flameI2Cpwm); // set pwm
} }
while (1) {
char key = getInput(); char key = getInput();
if (key == BTN_ENTER) { if (key == BTN_ENTER) {
DoString(0,50,"ISP!"); DoString(0,50,"ISP!");
@ -116,6 +121,7 @@ void main_flame(void) {
ISPandReset(); ISPandReset();
} }
work_queue();
} }
return; return;

View File

@ -0,0 +1,97 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/print.h"
#include "filesystem/ff.h"
#include "usb/usbmsc.h"
/**************************************************************************/
void main_initial(void) {
char key=BTN_NONE;
gpioSetValue (RB_LED0, 0);
gpioSetValue (RB_LED1, 0);
gpioSetValue (RB_LED2, 0);
gpioSetValue (RB_LED3, 0);
IOCON_PIO1_11 = 0x0;
gpioSetDir(RB_LED3, gpioDirection_Output);
while(1){
lcdClear();
lcdPrintln("Init v.42");
lcdNl();
lcdPrintln("Left: ISP()");
lcdPrintln("Right: MSC()");
lcdPrintln("Up: FormatDF()");
lcdPrintln("Down: ???");
lcdPrintln("Enter: LEDs()");
lcdRefresh();
key=getInputWait();
if(key&BTN_ENTER){
gpioSetValue (RB_LED0, 1);
gpioSetValue (RB_LED1, 1);
gpioSetValue (RB_LED2, 1);
gpioSetValue (RB_LED3, 1);
delayms_power(100);
getInputWaitRelease();
gpioSetValue (RB_LED0, 0);
gpioSetValue (RB_LED1, 0);
gpioSetValue (RB_LED2, 0);
gpioSetValue (RB_LED3, 0);
delayms_power(50);
};
if(key&BTN_RIGHT){
lcdClear();
lcdPrintln("MSC Enabled.");
lcdRefresh();
delayms_power(300);
usbMSCInit();
getInputWait();
lcdPrintln("MSC Disabled.");
usbMSCOff();
lcdRefresh();
}
if(key&BTN_LEFT){
lcdClear();
lcdPrintln("Enter ISP!");
lcdRefresh();
ISPandReset();
}
if(key&BTN_UP){
FATFS FatFs;
int res;
lcdClear();
lcdPrintln("Mount DF:");
res=f_mount(0, &FatFs);
lcdPrintln(f_get_rc_string(res));
lcdRefresh();
lcdPrintln("Formatting DF...");
res=f_mkfs(0,1,0);
lcdPrintln(f_get_rc_string(res));
lcdRefresh();
}
if(key&BTN_DOWN){
;
}
getInputWaitRelease();
};
}
void tick_initial(void){
static int foo=0;
static int toggle=0;
if(foo++>80){
toggle=1-toggle;
foo=0;
gpioSetValue (RB_LED0, toggle);
};
};

View File

@ -58,4 +58,13 @@ done
echo "NULL" echo "NULL"
echo "};" echo "};"
echo "inline void generated_tick(void){"
for f in $* ; do
grep -h '^void tick_' $f|sed 's/^void //;s/(.*//'|while read a ; do
echo "$a();"
done
done
echo "return;"
echo "};"

View File

@ -17,15 +17,8 @@ void main_tester(void) {
gotoISP(); gotoISP();
}; };
void no_tick_tester(void){ void tick_tester(void){
static int foo=0; generated_tick();
static int toggle=0;
if(foo++>80){
toggle=1-toggle;
foo=0;
gpioSetValue (RB_LED0, toggle);
};
return;
}; };

View File

@ -33,21 +33,18 @@ void s_ticks(void) {
void b_one(void){ void b_one(void){
gpioSetValue (RB_LED2, 0); gpioSetValue (RB_LED2, 0);
delayms_power(100); delayms(100);
gpioSetValue (RB_LED2, 1); gpioSetValue (RB_LED2, 1);
delayms_power(1000); delayms(1000);
gpioSetValue (RB_LED2, 0); gpioSetValue (RB_LED2, 0);
}; };
void do_qone(void) { void push_q(void) {
work_queue(); push_queue(&b_one);
}; push_queue(&b_one);
push_queue(&b_one);
void do_q(void) { push_queue(&b_one);
delayms_queue(500); push_queue(&b_one);
};
void push_qone(void) {
push_queue(&b_one); push_queue(&b_one);
}; };

View File

@ -150,6 +150,7 @@ char isNight(void);
uint8_t getInput(void); uint8_t getInput(void);
uint8_t getInputRaw(void); uint8_t getInputRaw(void);
uint8_t getInputWait(void); uint8_t getInputWait(void);
void getInputWaitRelease(void);
//uuid.c //uuid.c
#include "basic/uuid.h" #include "basic/uuid.h"
@ -182,3 +183,4 @@ void handleMenu(const struct MENU *the_menu);
#include "basic/idle.h" #include "basic/idle.h"
#endif #endif

View File

@ -46,12 +46,12 @@ void delayms_queue(uint32_t ms){
}; };
void delayms_power(uint32_t ms){ void delayms_power(uint32_t ms){
ms+=_timectr;
do { do {
ms-=10;
#ifdef ARM #ifdef ARM
__asm volatile ("WFI"); __asm volatile ("WFI");
#endif #endif
} while(ms>10); } while (ms >_timectr);
}; };
int push_queue(void (*new)(void)){ int push_queue(void (*new)(void)){

View File

@ -44,10 +44,16 @@ uint8_t getInput(void) {
uint8_t getInputWait(void) { uint8_t getInputWait(void) {
uint8_t key; uint8_t key;
while ((key=getInput())==BTN_NONE) while ((key=getInputRaw())==BTN_NONE)
work_queue(); work_queue();
delayms_queue(10); /* Delay a little more to debounce */ delayms_queue(10); /* Delay a little more to debounce */
return key; return key;
}; };
void getInputWaitRelease(void) {
while (getInputRaw()!=BTN_NONE)
work_queue();
delayms_queue(10); /* Delay a little more to debounce */
};

View File

@ -67,6 +67,7 @@
static bool _adcInitialised = false; static bool _adcInitialised = false;
static uint8_t _adcLastChannel = 0; static uint8_t _adcLastChannel = 0;
uint8_t adcMutex = 0;
/**************************************************************************/ /**************************************************************************/
/*! /*!
@ -89,6 +90,7 @@ static uint8_t _adcLastChannel = 0;
/**************************************************************************/ /**************************************************************************/
uint32_t adcRead (uint8_t channelNum) uint32_t adcRead (uint8_t channelNum)
{ {
adcMutex = 1;
if (!_adcInitialised) adcInit(); if (!_adcInitialised) adcInit();
uint32_t regVal, adcData; uint32_t regVal, adcData;
@ -154,11 +156,13 @@ uint32_t adcRead (uint8_t channelNum)
/* return 0 if an overrun occurred */ /* return 0 if an overrun occurred */
if ( regVal & ADC_DR_OVERRUN ) if ( regVal & ADC_DR_OVERRUN )
{ {
adcMutex = 0;
return (1); return (1);
} }
/* return conversion results */ /* return conversion results */
adcData = (regVal >> 6) & 0x3FF; adcData = (regVal >> 6) & 0x3FF;
adcMutex = 0;
return (adcData); return (adcData);
} }

View File

@ -41,6 +41,7 @@
#include "projectconfig.h" #include "projectconfig.h"
extern uint8_t adcMutex;
uint32_t adcRead (uint8_t channelNum); uint32_t adcRead (uint8_t channelNum);
void adcInit (void); void adcInit (void);