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

This commit is contained in:
bernd 2011-08-01 05:55:02 +02:00
commit 2e1587103c
31 changed files with 260 additions and 91 deletions

View File

@ -23,6 +23,8 @@ CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
REALLD = $(CROSS_COMPILE)ld
SIZE = $(CROSS_COMPILE)size
AR = $(CROSS_COMPILE)ar
RANLIB = $(CROSS_COMPILE)ranlib
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
OUTFILE = firmware

View File

@ -6,6 +6,7 @@ all: $(LIBFILE)
$(LIBFILE): $(OBJS)
$(AR) rcs $@ $(OBJS)
$(RANLIB) $(RANLIBFLAGS) $@
%.o : %.c
$(CC) $(CFLAGS) -o $@ $<

View File

@ -33,6 +33,7 @@ endif
WRAP=wrapper
LIBNAME=app
##########################################################################
# GNU GCC compiler flags
##########################################################################
@ -66,21 +67,21 @@ $(LOBJ):
OBJS += $(LOBJ)
endif
ifeq "$(APP)" "tester"
ifeq "$(wildcard $(APP))" "$(APP)"
ifndef TYPE
TYPE=$(APP)
endif
TSRCS = $(wildcard $(TYPE)/*.c)
TOBJS = $(foreach mod,$(TSRCS),$(subst .c,.o,$(mod)))
TWRAP=tester.gen
TWRAP=$(APP).gen
.PHONY: $(TWRAP)
$(APP).o: $(TWRAP)
$(TWRAP):
./mktester $(TSRCS) > $@
./mkfirmware $(APP) $(TSRCS) > $@
OBJS += $(TOBJS)
endif
@ -93,7 +94,7 @@ $(LIBFILE): $(OBJS) $(WRAPOBJ)
$(CC) $(CFLAGS) -o $@ $<
clean:
rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o */*.o
rm -f $(OBJS) $(WRAPOBJ) $(WRAPSRC) $(LIBFILE) *.o */*.o *.gen
%.c:
@echo

View File

@ -1,10 +1,12 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/lcd.h"
#include "lcd/fonts/smallfonts.h"
#include "lcd/print.h"
#include "filesystem/ff.h"
#include "usb/usbmsc.h"
#include "basic/random.h"
/**************************************************************************/
@ -12,12 +14,18 @@
void main_default(void) {
systickInit(SYSTICKSPEED);
if(getInputRaw()==BTN_ENTER){
ISPandReset();
switch(getInputRaw()){
case BTN_ENTER:
ISPandReset();
break;
case BTN_DOWN:
usbMSCInit();
while(1)
delayms_power(100);
break;
};
readConfig();
applyConfig();
randomInit();
return;
@ -41,12 +49,13 @@ void tick_default(void) {
if(ctr>100/SYSTICKSPEED){
if(isNight()){
backlightSetBrightness(GLOBAL(lcdbacklight));
if(GLOBAL(nightinvert))
lcdSetInvert(0);
lcdSetInvert(0);
} else {
backlightSetBrightness(0);
if(GLOBAL(nightinvert))
if(GLOBAL(dayinvert))
lcdSetInvert(1);
else
lcdSetInvert(0);
}
}

View File

@ -1,6 +1,7 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/print.h"
#include "lcd/display.h"

View File

@ -1,6 +1,7 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "lcd/lcd.h"
#include "lcd/print.h"
@ -29,6 +30,18 @@ void show_ticks(void) {
};
void chrg_stat(void) {
int stat;
while ((getInputRaw())==BTN_NONE){
lcdClear();
lcdPrintln("Chrg_stat:");
stat=gpioGetValue(RB_PWR_CHRG);
lcdPrint(IntToStr(stat,3,0));
lcdNl();
lcdRefresh();
};
lcdPrintln("Done.");
};
void adc_light(void) {
int dx=0;
int dy=8;
@ -37,7 +50,7 @@ void adc_light(void) {
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetLight());
DoInt(dx,dy+16,isNight());
DoInt(dx,dy+8,GLOBAL(nighttrigger));
DoInt(dx,dy+8,GLOBAL(daytrig));
lcdDisplay();
};
dy+=8;

View File

@ -1,5 +1,8 @@
#!/bin/sh
APP=$1
shift
for f in $* ; do
grep -h '^void ' $f|sed 's/^void //;s/(.*//'|while read a ; do
echo "void $a(void);"
@ -58,7 +61,7 @@ done
echo "NULL"
echo "};"
echo "inline void generated_tick(void){"
echo "inline void tick_${APP}(void){"
for f in $* ; do
grep -h '^void tick_' $f|sed 's/^void //;s/(.*//'|while read a ; do
echo "$a();"

View File

@ -16,9 +16,3 @@ void main_tester(void) {
handleMenu(&mainmenu);
gotoISP();
};
void tick_tester(void){
generated_tick();
};

View File

@ -29,6 +29,18 @@ void show_ticks(void) {
};
void chrg_stat(void) {
int stat;
while ((getInputRaw())==BTN_NONE){
lcdClear();
lcdPrintln("Chrg_stat:");
stat=gpioGetValue(RB_PWR_CHRG);
lcdPrint(IntToStr(stat,3,0));
lcdNl();
lcdRefresh();
};
lcdPrintln("Done.");
};
void adc_light(void) {
int dx=0;
int dy=8;
@ -37,7 +49,7 @@ void adc_light(void) {
while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetLight());
DoInt(dx,dy+16,isNight());
DoInt(dx,dy+8,GLOBAL(nighttrigger));
DoInt(dx,dy+8,GLOBAL(daytrig));
lcdDisplay();
};
dy+=8;

View File

@ -34,6 +34,9 @@ void rbInit() {
gpioSetDir(RB_BTN4, gpioDirection_Input);
gpioSetPullup (&RB_BTN4_IO, gpioPullupMode_PullUp);
// prepate chrg_stat
gpioSetDir(RB_PWR_CHRG, gpioDirection_Input);
gpioSetPullup (&RB_PWR_CHRG_IO, gpioPullupMode_PullUp);
// prepare LEDs
IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK;

View File

@ -81,6 +81,7 @@
#define RB_PWR_GOOD 1,8
#define RB_PWR_CHRG 2,3
#define RB_PWR_CHRG_IO IOCON_PIO2_3
#define RB_PWR_LCDBL 0,0
#define RB_PWR_LCDBL_IO IOCON_nRESET_PIO0_0
@ -185,36 +186,6 @@ void handleMenu(const struct MENU *the_menu);
#include "basic/idle.h"
// config.c
int readConfig(void);
int saveConfig(void);
void applyConfig(void);
struct CDESC {
char *name;
char value;
char min;
char max;
};
extern struct CDESC the_config[];
#define GLOBALversion (the_config[0].value)
#define GLOBALprivacy (the_config[1].value)
#define GLOBALnighttrigger (the_config[2].value)
#define GLOBALnightinvert (the_config[3].value)
#define GLOBALlcdbacklight (the_config[4].value)
#define GLOBALlcdmirror (the_config[5].value)
#define GLOBALlcdinvert (the_config[6].value)
#define GLOBALlcdcontrast (the_config[7].value)
#define GLOBAL(x) GLOBAL ## x
#define SYSTICKSPEED 10
// itoa.c
#define F_ZEROS (1<<0)
#define F_LONG (1<<1)
@ -227,4 +198,8 @@ const char* IntToStr(int num, unsigned int mxlen, char flag);
#include "basic/simpletime.h"
// global
#define SYSTICKSPEED 10
#endif

View File

@ -1,32 +1,39 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "lcd/display.h"
#include "lcd/print.h"
#include "filesystem/ff.h"
#include "basic/random.h"
#include "basic/config.h"
#define CFGVER 23
#define CFGVER 24
struct CDESC the_config[]= {
{"version", CFGVER, CFGVER, CFGVER},
{"privacy", 3, 0, 2 },
{"nighttrigger", 310/2, 0, 255},
{"nightinvert", 1, 0, 1 },
{"daytrig", 310/2, 0, 255},
{"daytrighyst", 10, 0, 50 },
{"dayinvert", 1, 0, 1 },
{"lcdbacklight", 50, 0, 100},
{"lcdmirror", 0, 0, 1 },
{"lcdinvert", 0, 0, 1 },
{"lcdcontrast", 3, 1, 6 },
{"lcdcontrast", 3, 0, 31 },
{ NULL, 0, 0, 0 },
};
char nickname[MAXNICK]="anonymous";
char nickfont[FILENAMELEN];
#define CONFFILE "r0ket.cfg"
#define CONF_ITER for(int i=0;the_config[i].name!=NULL;i++)
/**************************************************************************/
void applyConfig(){
lcdSetContrast(GLOBAL(lcdcontrast));
return 0;
if(GLOBAL(lcdcontrast)>0)
lcdSetContrast(GLOBAL(lcdcontrast));
return;
};
int saveConfig(void){

35
firmware/basic/config.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef __BASICCONFIG_H_
#define __BASICCONFIG_H_
int readConfig(void);
int saveConfig(void);
void applyConfig(void);
struct CDESC {
char *name;
char value;
char min;
char max;
};
#define MAXNICK 20
extern struct CDESC the_config[];
extern char nickname[MAXNICK];
extern char nickfont[];
#define GLOBALversion (the_config[0].value)
#define GLOBALprivacy (the_config[1].value)
#define GLOBALdaytrig (the_config[2].value)
#define GLOBALdaytrighyst (the_config[3].value)
#define GLOBALdayinvert (the_config[4].value)
#define GLOBALlcdbacklight (the_config[5].value)
#define GLOBALlcdmirror (the_config[6].value)
#define GLOBALlcdinvert (the_config[7].value)
#define GLOBALlcdcontrast (the_config[8].value)
#define GLOBALnickname (nickname)
#define GLOBALnickfont (nickfont)
#define GLOBAL(x) GLOBAL ## x
#endif

View File

@ -2,7 +2,6 @@
#include "basic/basic.h"
#include "lcd/fonts.h"
#include "lcd/render.h"
#include "lcd/print.h"
@ -21,27 +20,24 @@ void handleMenu(const struct MENU *the_menu) {
for (numentries = 0; the_menu->entries[numentries] != NULL; numentries++);
visible_lines = (RESY/font->u8Height)-1; // subtract title line
visible_lines = (RESY/getFontHeight())-1; // subtract title line
#ifdef SAFETY
if (visible_lines < 2) return;
#endif
while (!back) {
uint8_t line = 0;
// Display current menu page
lcdFill(0);
DoString(0, line, the_menu->title);
line += font->u8Height;
lcdClear();
lcdPrintln(the_menu->title);
for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) {
DoString(14, line, the_menu->entries[i]->text);
if (i == menuselection) {
DoString(0, line, "* ");
lcdPrint("*");
}
line += font->u8Height;
lcdSetCrsrX(14);
lcdPrintln(the_menu->entries[i]->text);
}
lcdDisplay();
lcdRefresh();
switch (getInputWait()) {
case BTN_UP:

View File

@ -1,45 +1,40 @@
#include <sysinit.h>
#include "basic/basic.h"
#include "basic/config.h"
#define RANGE (10)
#define HYST (4)
uint32_t light=300*HYST;
#define SAMPCT (4)
uint32_t light=150*SAMPCT;
char _isnight=1;
#define threshold GLOBAL(nighttrigger)
#define threshold GLOBAL(daytrig)
#define RANGE GLOBAL(daytrighyst)
void LightCheck(void){
int iocon;
char iodir;
int value;
iocon=IOCON_PIO1_11;
// iodir=gpioGetDir(RB_LED3);
iodir= (GPIO_GPIO1DIR & (1 << (RB_LED3) ))?1:0;
gpioSetDir(RB_LED3, gpioDirection_Input);
IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_AD7|IOCON_PIO1_11_ADMODE_ANALOG;
light-=light/HYST;
light-=light/SAMPCT;
light += (adcRead(7)/2);
gpioSetDir(RB_LED3, iodir);
IOCON_PIO1_11=iocon;
if(threshold==0){ // uninitialized?
threshold=320;
};
if(_isnight && light/HYST>(threshold+RANGE))
if(_isnight && light/SAMPCT>(threshold+RANGE))
_isnight=0;
if(!_isnight && light/HYST<threshold)
if(!_isnight && light/SAMPCT<threshold)
_isnight=1;
};
uint32_t GetLight(void){
return light/HYST;
return light/SAMPCT;
};
char isNight(void){

View File

@ -1,6 +1,7 @@
#include <stdint.h>
#include "random.h"
#include "xxtea.h"
#include "core/adc/adc.h"
#define STATE_SIZE 8
uint32_t state[STATE_SIZE];

View File

@ -11,6 +11,7 @@ void VoltageCheck(void){
results /= 1024;
if( results < 3500 ){
nrf_off();
gpioSetValue (RB_PWR_GOOD, 0);
gpioSetValue (RB_LCD_BL, 0);
SCB_SCR |= SCB_SCR_SLEEPDEEP;

View File

@ -236,9 +236,13 @@ DRESULT dataflash_ioctl(BYTE ctrl, void *buff) {
}
#endif /* _USE_IOCTL != 0 */
DWORD get_fattime () {
// ToDo!
return 0;
struct tm* tm=mygmtime(getSeconds());
DWORD t= (((tm->tm_year+YEAR0-1980)<<9)|
((tm->tm_mon+1)<<5)|
(tm->tm_mday))<<16 |
((tm->tm_hour<<11)|
(tm->tm_min<<5)|
(tm->tm_sec>>1));
return t;
}

View File

@ -329,8 +329,11 @@ int ff_del_syncobj (_SYNC_t); /* Delete a sync object */
#endif
/* Utility functions */
#define FILENAMELEN 13 // 8+1+3+1
const char* f_get_rc_string (FRESULT rc);
void fsInit();
int readFile(char * filename, char * data, int len);
int writeFile(char * filename, char * data, int len);
#ifdef __cplusplus
}

View File

@ -66,6 +66,7 @@ int selectFile(char *filename, char *extension)
}
lcdRefresh();
key=getInputWait();
getInputWaitRelease();
if( key==BTN_DOWN ){
if( selected < count-1 ){
selected++;

View File

@ -22,3 +22,44 @@ const char* f_get_rc_string (FRESULT rc) {
void fsInit(){
f_mount(0, &FatFs);
};
int readFile(char * filename, char * data, int len){
FIL file;
UINT readbytes;
int res;
res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ);
if(res){
return -1;
};
res = f_read(&file, data, len-1, &readbytes);
if(res){
return -1;
};
f_close(&file);
data[readbytes]=0;
return readbytes;
};
int writeFile(char * filename, char * data, int len){
FIL file;
UINT writebytes;
int res;
res=f_open(&file, filename, FA_OPEN_ALWAYS|FA_WRITE);
if(res){
return -1;
};
res = f_write(&file, data, len, &writebytes);
if(res){
return -1;
};
f_close(&file);
return writebytes;
};

View File

@ -108,7 +108,7 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4])
}
lcdRefresh();
if( fres < 0 )
return;
return 1;
//nrf_set_rx_mac(0, 32, 5, macbuf);
xxtea_decode_words((uint32_t *)buf, wordcount, k);

View File

@ -76,7 +76,7 @@ void mesh_recvloop(void){
};
if(MO_TYPE(buf)=='T'){
time_t toff=MO_TIME(buf)-((getTimer()-(200/SYSTICKSPEED))/(1000/SYSTICKSPEED));
time_t toff=MO_TIME(buf)-((getTimer()+(300/SYSTICKSPEED))/(1000/SYSTICKSPEED));
if (toff>_timet) // Do not live in the past.
_timet = toff;
continue;

View File

@ -395,3 +395,10 @@ void nrf_init() {
nrf_write_reg(R_RF_SETUP,DEFAULT_SPEED|R_RF_SETUP_RF_PWR_3);
};
void nrf_off() {
nrf_write_reg(R_CONFIG,
R_CONFIG_MASK_RX_DR|
R_CONFIG_MASK_TX_DS|
R_CONFIG_MASK_MAX_RT
); // Most important: no R_CONFIG_PWR_UP
};

View File

@ -138,6 +138,7 @@ int nrf_rcv_pkt_time_encr(int maxtime, int maxsize, uint8_t * pkt, uint32_t cons
char nrf_snd_pkt_crc_encr(int size, uint8_t * pkt, uint32_t const k[4]);
void nrf_init() ;
void nrf_off() ;
void nrf_cmd(uint8_t cmd);
uint8_t nrf_cmd_status(uint8_t cmd);

View File

@ -1,6 +1,7 @@
#include "rftransfer.h"
#include "nrf24l01p.h"
#include <basic/basic.h>
#include <basic/random.h>
#include <core/systick/systick.h>
#include <lcd/print.h>

View File

@ -6,6 +6,7 @@
#include "core/ssp/ssp.h"
#include "gpio/gpio.h"
#include "basic/basic.h"
#include "basic/config.h"
#include "usb/usbmsc.h"
/**************************************************************************/
@ -61,6 +62,55 @@ static void lcdWrite(uint8_t cd, uint8_t data) {
frame = SSP_SSP0DR;
}
#define CS 2,1
#define SCK 2,11
#define SDA 0,9
#define RST 2,2
uint8_t lcdRead(uint8_t data)
{
uint8_t i;
gpioSetDir(SDA, 1);
gpioSetValue(SCK, 0);
delayms(1);
gpioSetValue(CS, 0);
delayms(1);
gpioSetValue(SDA, 0);
delayms(1);
gpioSetValue(SCK, 1);
delayms(1);
for(i=0; i<8; i++){
gpioSetValue(SCK, 0);
delayms(1);
if( data & 0x80 )
gpioSetValue(SDA, 1);
else
gpioSetValue(SDA, 0);
data <<= 1;
gpioSetValue(SCK, 1);
delayms(1);
}
uint8_t ret = 0;
gpioSetDir(SDA, 0);
for(i=0; i<8; i++){
gpioSetValue(SCK, 0);
delayms(1);
ret <<= 1;
ret |= gpioGetValue(SDA);
gpioSetValue(SCK, 1);
delayms(1);
}
gpioSetValue(CS, 0);
gpioSetDir(SDA, 1);
delayms(1);
}
void lcdInit(void) {
sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge);
@ -172,8 +222,9 @@ inline void lcdInvert(void) {
}
void lcdSetContrast(int c) {
c+=0x20;
if(c>0x2e) c=0x24;
c+=0x80;
if(c>0x9F)
return;
lcd_select();
lcdWrite(TYPE_CMD,c);
lcd_deselect();

View File

@ -20,6 +20,7 @@
/* Display buffer */
extern uint8_t lcdBuffer[RESX*RESY_B];
uint8_t lcdRead(uint8_t data);
void lcdInit(void);
void lcdFill(char f);
void lcdDisplay(void);
@ -30,4 +31,5 @@ void lcdSafeSetPixel(char x, char y, bool f);
bool lcdGetPixel(char x, char y);
void lcdShift(int x, int y, bool wrap);
void lcdSetContrast(int c);
void lcdSetInvert();
#endif

View File

@ -18,10 +18,10 @@ FIL file; /* current font file */
/* Exported Functions */
void setIntFont(const struct FONT_DEF * font){
memcpy(&efont.def,font,sizeof(struct FONT_DEF));
void setIntFont(const struct FONT_DEF * newfont){
memcpy(&efont.def,newfont,sizeof(struct FONT_DEF));
efont.type=FONT_INTERNAL;
font=NULL;
font=&efont.def;
};
void setExtFont(const char *fname){

View File

@ -5,6 +5,7 @@
#include "basic/basic.h"
#include "lcd/render.h"
#include "filesystem/ff.h"
/**************************************************************************/

View File

@ -23,6 +23,8 @@ CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
REALLD = $(CROSS_COMPILE)ld
SIZE = $(CROSS_COMPILE)size
AR = $(CROSS_COMPILE)ar
RANLIB = $(CROSS_COMPILE)ranlib
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
OUTFILE = firmware
@ -44,6 +46,12 @@ endif
CFLAGS = -std=c99 -c -g -O0 $(INCLUDE_PATHS) -Wall -funsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -DRAMCODE=$(RAMCODE) -fno-builtin -DSIMULATOR -I$(ROOT_PATH)/../simcore -include libc-unc0llide.h $(CONFIG_GCC_SHOWCOLUMN)
#LDFLAGS = -nostartfiles
ifeq ($(shell uname), Darwin)
# Mac OS X provides a stdio.h with unwanted defines
CFLAGS += -D_FORTIFY_SOURCE=0
# ld64 has problems with common symbols <rdar://problem/9870713>, apply a workaround
RANLIBFLAGS = -c
endif
CONFIG_MAKE_PRINTDIRECTORY = --no-print-directory
CONFIG_GCC_SHOWCOLUMN =