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 LD = $(CROSS_COMPILE)ld
REALLD = $(CROSS_COMPILE)ld REALLD = $(CROSS_COMPILE)ld
SIZE = $(CROSS_COMPILE)size SIZE = $(CROSS_COMPILE)size
AR = $(CROSS_COMPILE)ar
RANLIB = $(CROSS_COMPILE)ranlib
OBJCOPY = $(CROSS_COMPILE)objcopy OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump OBJDUMP = $(CROSS_COMPILE)objdump
OUTFILE = firmware OUTFILE = firmware

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
#include <sysinit.h> #include <sysinit.h>
#include "basic/basic.h" #include "basic/basic.h"
#include "basic/config.h"
#include "lcd/lcd.h" #include "lcd/lcd.h"
#include "lcd/print.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) { void adc_light(void) {
int dx=0; int dx=0;
int dy=8; int dy=8;
@ -37,7 +50,7 @@ void adc_light(void) {
while ((getInputRaw())==BTN_NONE){ while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetLight()); DoInt(dx,dy,GetLight());
DoInt(dx,dy+16,isNight()); DoInt(dx,dy+16,isNight());
DoInt(dx,dy+8,GLOBAL(nighttrigger)); DoInt(dx,dy+8,GLOBAL(daytrig));
lcdDisplay(); lcdDisplay();
}; };
dy+=8; dy+=8;

View File

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

View File

@ -16,9 +16,3 @@ void main_tester(void) {
handleMenu(&mainmenu); handleMenu(&mainmenu);
gotoISP(); 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) { void adc_light(void) {
int dx=0; int dx=0;
int dy=8; int dy=8;
@ -37,7 +49,7 @@ void adc_light(void) {
while ((getInputRaw())==BTN_NONE){ while ((getInputRaw())==BTN_NONE){
DoInt(dx,dy,GetLight()); DoInt(dx,dy,GetLight());
DoInt(dx,dy+16,isNight()); DoInt(dx,dy+16,isNight());
DoInt(dx,dy+8,GLOBAL(nighttrigger)); DoInt(dx,dy+8,GLOBAL(daytrig));
lcdDisplay(); lcdDisplay();
}; };
dy+=8; dy+=8;

View File

@ -34,6 +34,9 @@ void rbInit() {
gpioSetDir(RB_BTN4, gpioDirection_Input); gpioSetDir(RB_BTN4, gpioDirection_Input);
gpioSetPullup (&RB_BTN4_IO, gpioPullupMode_PullUp); gpioSetPullup (&RB_BTN4_IO, gpioPullupMode_PullUp);
// prepate chrg_stat
gpioSetDir(RB_PWR_CHRG, gpioDirection_Input);
gpioSetPullup (&RB_PWR_CHRG_IO, gpioPullupMode_PullUp);
// prepare LEDs // prepare LEDs
IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK; 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_GOOD 1,8
#define RB_PWR_CHRG 2,3 #define RB_PWR_CHRG 2,3
#define RB_PWR_CHRG_IO IOCON_PIO2_3
#define RB_PWR_LCDBL 0,0 #define RB_PWR_LCDBL 0,0
#define RB_PWR_LCDBL_IO IOCON_nRESET_PIO0_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" #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 // itoa.c
#define F_ZEROS (1<<0) #define F_ZEROS (1<<0)
#define F_LONG (1<<1) #define F_LONG (1<<1)
@ -227,4 +198,8 @@ const char* IntToStr(int num, unsigned int mxlen, char flag);
#include "basic/simpletime.h" #include "basic/simpletime.h"
// global
#define SYSTICKSPEED 10
#endif #endif

View File

@ -1,32 +1,39 @@
#include <sysinit.h> #include <sysinit.h>
#include "basic/basic.h" #include "basic/basic.h"
#include "lcd/display.h"
#include "lcd/print.h" #include "lcd/print.h"
#include "filesystem/ff.h" #include "filesystem/ff.h"
#include "basic/random.h" #include "basic/random.h"
#include "basic/config.h"
#define CFGVER 23 #define CFGVER 24
struct CDESC the_config[]= { struct CDESC the_config[]= {
{"version", CFGVER, CFGVER, CFGVER}, {"version", CFGVER, CFGVER, CFGVER},
{"privacy", 3, 0, 2 }, {"privacy", 3, 0, 2 },
{"nighttrigger", 310/2, 0, 255}, {"daytrig", 310/2, 0, 255},
{"nightinvert", 1, 0, 1 }, {"daytrighyst", 10, 0, 50 },
{"dayinvert", 1, 0, 1 },
{"lcdbacklight", 50, 0, 100}, {"lcdbacklight", 50, 0, 100},
{"lcdmirror", 0, 0, 1 }, {"lcdmirror", 0, 0, 1 },
{"lcdinvert", 0, 0, 1 }, {"lcdinvert", 0, 0, 1 },
{"lcdcontrast", 3, 1, 6 }, {"lcdcontrast", 3, 0, 31 },
{ NULL, 0, 0, 0 }, { NULL, 0, 0, 0 },
}; };
char nickname[MAXNICK]="anonymous";
char nickfont[FILENAMELEN];
#define CONFFILE "r0ket.cfg" #define CONFFILE "r0ket.cfg"
#define CONF_ITER for(int i=0;the_config[i].name!=NULL;i++) #define CONF_ITER for(int i=0;the_config[i].name!=NULL;i++)
/**************************************************************************/ /**************************************************************************/
void applyConfig(){ void applyConfig(){
lcdSetContrast(GLOBAL(lcdcontrast)); if(GLOBAL(lcdcontrast)>0)
return 0; lcdSetContrast(GLOBAL(lcdcontrast));
return;
}; };
int saveConfig(void){ 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 "basic/basic.h"
#include "lcd/fonts.h"
#include "lcd/render.h" #include "lcd/render.h"
#include "lcd/print.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++); 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 #ifdef SAFETY
if (visible_lines < 2) return; if (visible_lines < 2) return;
#endif #endif
while (!back) { while (!back) {
uint8_t line = 0;
// Display current menu page // Display current menu page
lcdFill(0); lcdClear();
DoString(0, line, the_menu->title); lcdPrintln(the_menu->title);
line += font->u8Height;
for (uint8_t i = current_offset; i < (visible_lines + current_offset) && i < numentries; i++) { 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) { if (i == menuselection) {
DoString(0, line, "* "); lcdPrint("*");
} }
line += font->u8Height; lcdSetCrsrX(14);
lcdPrintln(the_menu->entries[i]->text);
} }
lcdDisplay(); lcdRefresh();
switch (getInputWait()) { switch (getInputWait()) {
case BTN_UP: case BTN_UP:

View File

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

View File

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

View File

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

View File

@ -236,9 +236,13 @@ DRESULT dataflash_ioctl(BYTE ctrl, void *buff) {
} }
#endif /* _USE_IOCTL != 0 */ #endif /* _USE_IOCTL != 0 */
DWORD get_fattime () { DWORD get_fattime () {
// ToDo! struct tm* tm=mygmtime(getSeconds());
return 0; 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 #endif
/* Utility functions */ /* Utility functions */
#define FILENAMELEN 13 // 8+1+3+1
const char* f_get_rc_string (FRESULT rc); const char* f_get_rc_string (FRESULT rc);
void fsInit(); void fsInit();
int readFile(char * filename, char * data, int len);
int writeFile(char * filename, char * data, int len);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

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

View File

@ -22,3 +22,44 @@ const char* f_get_rc_string (FRESULT rc) {
void fsInit(){ void fsInit(){
f_mount(0, &FatFs); 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(); lcdRefresh();
if( fres < 0 ) if( fres < 0 )
return; return 1;
//nrf_set_rx_mac(0, 32, 5, macbuf); //nrf_set_rx_mac(0, 32, 5, macbuf);
xxtea_decode_words((uint32_t *)buf, wordcount, k); xxtea_decode_words((uint32_t *)buf, wordcount, k);

View File

@ -76,7 +76,7 @@ void mesh_recvloop(void){
}; };
if(MO_TYPE(buf)=='T'){ 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. if (toff>_timet) // Do not live in the past.
_timet = toff; _timet = toff;
continue; continue;

View File

@ -395,3 +395,10 @@ void nrf_init() {
nrf_write_reg(R_RF_SETUP,DEFAULT_SPEED|R_RF_SETUP_RF_PWR_3); 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]); char nrf_snd_pkt_crc_encr(int size, uint8_t * pkt, uint32_t const k[4]);
void nrf_init() ; void nrf_init() ;
void nrf_off() ;
void nrf_cmd(uint8_t cmd); void nrf_cmd(uint8_t cmd);
uint8_t nrf_cmd_status(uint8_t cmd); uint8_t nrf_cmd_status(uint8_t cmd);

View File

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

View File

@ -6,6 +6,7 @@
#include "core/ssp/ssp.h" #include "core/ssp/ssp.h"
#include "gpio/gpio.h" #include "gpio/gpio.h"
#include "basic/basic.h" #include "basic/basic.h"
#include "basic/config.h"
#include "usb/usbmsc.h" #include "usb/usbmsc.h"
/**************************************************************************/ /**************************************************************************/
@ -61,6 +62,55 @@ static void lcdWrite(uint8_t cd, uint8_t data) {
frame = SSP_SSP0DR; 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) { void lcdInit(void) {
sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge); sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge);
@ -172,8 +222,9 @@ inline void lcdInvert(void) {
} }
void lcdSetContrast(int c) { void lcdSetContrast(int c) {
c+=0x20; c+=0x80;
if(c>0x2e) c=0x24; if(c>0x9F)
return;
lcd_select(); lcd_select();
lcdWrite(TYPE_CMD,c); lcdWrite(TYPE_CMD,c);
lcd_deselect(); lcd_deselect();

View File

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

View File

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

View File

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

View File

@ -23,6 +23,8 @@ CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld LD = $(CROSS_COMPILE)ld
REALLD = $(CROSS_COMPILE)ld REALLD = $(CROSS_COMPILE)ld
SIZE = $(CROSS_COMPILE)size SIZE = $(CROSS_COMPILE)size
AR = $(CROSS_COMPILE)ar
RANLIB = $(CROSS_COMPILE)ranlib
OBJCOPY = $(CROSS_COMPILE)objcopy OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump OBJDUMP = $(CROSS_COMPILE)objdump
OUTFILE = firmware 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) 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 #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_MAKE_PRINTDIRECTORY = --no-print-directory
CONFIG_GCC_SHOWCOLUMN = CONFIG_GCC_SHOWCOLUMN =