From e0e2916b9bed8a5422dfd83a1e9876330e042b5f Mon Sep 17 00:00:00 2001 From: Andrej Podhajsky Date: Wed, 2 Feb 2011 11:32:35 +0100 Subject: [PATCH] initial commit --- .gitignore | 3 + a2i.c | 8 ++ asdevice/device.c | 159 ++++++++++++++++++++++++ asdevice/device.h | 33 +++++ asdevice/devicetypes.h | 27 ++++ asdevice/global.h | 40 ++++++ asdevice/keypad.c | 53 ++++++++ asdevice/keypad.h | 47 +++++++ asdevice/keypadconfig.h | 21 ++++ asdevice/lcdconf.h | 104 ++++++++++++++++ asdevice/makefile | 304 ++++++++++++++++++++++++++++++++++++++++++++++ asdevice/portoperations.h | 7 ++ asdevice/screen.c | 24 ++++ asdevice/screen.h | 37 ++++++ asdevice/tags | 6 + pointertest.c | 65 ++++++++++ randomgen.c | 34 ++++++ test.c | 31 +++++ 18 files changed, 1003 insertions(+) create mode 100644 .gitignore create mode 100644 a2i.c create mode 100755 asdevice/device.c create mode 100755 asdevice/device.h create mode 100644 asdevice/devicetypes.h create mode 100755 asdevice/global.h create mode 100755 asdevice/keypad.c create mode 100755 asdevice/keypad.h create mode 100755 asdevice/keypadconfig.h create mode 100755 asdevice/lcdconf.h create mode 100755 asdevice/makefile create mode 100755 asdevice/portoperations.h create mode 100644 asdevice/screen.c create mode 100644 asdevice/screen.h create mode 100755 asdevice/tags create mode 100644 pointertest.c create mode 100644 randomgen.c create mode 100644 test.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07d1ba4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +*.lst +*.hex diff --git a/a2i.c b/a2i.c new file mode 100644 index 0000000..83e6011 --- /dev/null +++ b/a2i.c @@ -0,0 +1,8 @@ +#include +#include + +int main(void){ + char* str = "00034005xxxxx"; + printf("cislo: %d\n",atoi(str)); + return 0; +} diff --git a/asdevice/device.c b/asdevice/device.c new file mode 100755 index 0000000..8613c75 --- /dev/null +++ b/asdevice/device.c @@ -0,0 +1,159 @@ +/** + ************************************************************************************************ + ** Program pre ariadenie emulujuce nastrazny system pozostavajuce z : + ** - 2x majak + ** - 1x sirena + ** - 1x LCD + ** - 1x keypad 4x4 + ** Umoznuje hrat scenar pre 2 timy, kazdy z timov sa snazi o zapnutie resp. vypnutie zariadenia. + ************************************************************************************************ +**/ +#include "device.h" + +// menu strings +//---------------------0123456789ABCDEF---- +char s000[] PROGMEM = " \0"; +char s001[] PROGMEM = "by OP-Force\0"; +char s002[] PROGMEM = "Start game\0"; +char s003[] PROGMEM = "Game Setup\0"; +char s004[] PROGMEM = "Device state\0"; +char s005[] PROGMEM = "Act/Def codes:\n"; + +//set screens +PGM_P welcomeScreen[] PROGMEM = {s000,s001}; +#define welcomeScreenSize (sizeof(welcomeScreen)/sizeof(&welcomeScreen)) +PGM_P mainScreen[] PROGMEM = {s002,s003,s004}; +#define mainScreenSize (sizeof(mainScreen)/sizeof(&mainScreen)) +PGM_P codeScreen[] PROGMEM = {s005}; +#define codeScreenSize (sizeof(codeScreen)/sizeof(&codeScreen)) + + +PGM_P* screens[] PROGMEM = {welcomeScreen,mainScreen,codeScreen}; +int screensSizes[] = {welcomeScreenSize,mainScreenSize,codeScreenSize}; + +void welcomeAction(DeviceState*, PGM_P*, int scrSize); +void mainAction(DeviceState*, PGM_P*, int scrSize); +void startGame(DeviceState*, PGM_P*, int scrSize); +void setupDevice(DeviceState*, PGM_P*, int scrSize); +void showCodes(DeviceState*, PGM_P*, int scrSize); + +void delay_us(unsigned short time_us); +void generateCodes(DeviceState*); +long getUniqueRandom(DeviceState* d); + +int main(void){ + // LCD init and printf to LCD + lcdInit(); + + // set initial device state and menu + DeviceState* device = malloc(sizeof(DeviceState)); + + (*device).stateChanged = 1; + (*device).screenChanged = 0; + (*device).stateId = 0; + (*device).menuOffset = 0; + + //set function array + StateAction* actions = malloc(sizeof(StateAction)*10); + actions[0].action = welcomeAction; + actions[1].action = mainAction; + actions[3].action = startGame; + + + while(1){ + actions[(*device).stateId].action(device,screens[(*device).stateId],screensSizes[(*device).stateId]); + } + + return 0; +} + +void welcomeAction(DeviceState* d, PGM_P* s, int scrSize){ + char key = getKey(); + + if((*d).stateChanged){ + (*d).menuOffset = 0; + drawScreen(s,2,(*d).menuOffset,scrSize); + (*d).stateChanged = 0; + } else { + if(key != 0xff){ + (*d).stateId = 1; + (*d).stateChanged = 1; + (*d).menuOffset = 0; + } + } +} + +void mainAction(DeviceState* d, PGM_P* s, int scrSize){ + char key = getKey(); + + if((*d).stateChanged){ + lcdClear(); lcdGotoXY(0,0); + (*d).menuOffset = 0; + drawScreen(s,2,(*d).menuOffset,scrSize); + (*d).stateChanged = 0; + } else { + if(key != 0xff){ + switch (key) { + case '*': { + next(s,d,scrSize); + }; break; + case '#' : { + prev(s,d,scrSize); + }; break; + case '0' : { + if((*d).menuOffset == 1) { + (*d).stateChanged = 1; + (*d).stateId = 2; + } + }; break; + } + } + } +} + +void startGame(DeviceState* d, PGM_P* s, int scrSize){ + char key = getKey(); + + if((*d).stateChanged){ + lcdClear(); lcdGotoXY(0,0); + (*d).menuOffset = 0; + drawScreen(s,2,(*d).menuOffset,scrSize); + (*d).stateChanged = 0; + } else { + switch (key) { + case '*': { + next(s,d,scrSize); + }; break; + case '#' : { + prev(s,d,scrSize); + }; break; + } + } +} + +void delay_us(unsigned short time_us){ + unsigned short delay_loops; + register unsigned short i; + + delay_loops = (time_us+3)/5*CYCLES_PER_US; // +3 for rounding up (dirty) + // one loop takes 5 cpu cycles + for (i=0; i < delay_loops; i++) {}; +} + +void generateCodes(DeviceState* d){ + for(int i=0; i<5; i++){(*d).aCodes[i] = getUniqueRandom(d);} + for(int i=0; i<5; i++){(*d).dCodes[i] = getUniqueRandom(d);} +} + +long getUniqueRandom(DeviceState* d){ + int run = 1; + long rnd = 0; + + while(run){ + run = 0; + rnd = random()%100000; + for(int i=0; i<5; i++){ if(rnd == (*d).aCodes[i]){run = 1;}} + for(int i=0; i<5; i++){ if(rnd == (*d).dCodes[i]){run = 1;}} + } + return rnd; +} \ No newline at end of file diff --git a/asdevice/device.h b/asdevice/device.h new file mode 100755 index 0000000..d1202ba --- /dev/null +++ b/asdevice/device.h @@ -0,0 +1,33 @@ +#ifndef DEVICE_H +#define DEVICE_H + +#include +#include + +#ifndef GLOBAL_H +#include "global.h" +#endif +#ifndef __PGMSPACE_H_ +#include +#endif +#ifndef NAN +#include +#endif +#ifndef LCD_H +#include "lcd.h" +#endif +#include "lcdconf.h" +#ifndef KEYPADCONF_H +#include "keypadconfig.h" +#endif +#ifndef SCREEN_H +#include "screen.h" +#endif +#ifndef DEVICE_TYPES_H +#include "devicetypes.h" +#endif +#ifndef RPRINTF_SIMPLE +#include "rprintf.h" +#endif + +#endif diff --git a/asdevice/devicetypes.h b/asdevice/devicetypes.h new file mode 100644 index 0000000..c69c0aa --- /dev/null +++ b/asdevice/devicetypes.h @@ -0,0 +1,27 @@ +#ifndef DEVICE_TYPES_H +#define DEVICE_TYPES_H + +typedef struct{ + unsigned screenChanged:1; + unsigned stateChanged:1; + unsigned lcdBckLight:1; + unsigned redFlash:1; + unsigned greenFlash:1; + unsigned int stateId; + unsigned long holdedFor; + unsigned menuOffset; + unsigned long aCodes[5]; + unsigned long dCodes[5]; +} DeviceState; + +typedef struct{ + void (*action)(DeviceState*, PGM_P*,int); +} StateAction; + +typedef struct{ + unsigned char** screenLines; + unsigned* displayedLines; + unsigned selectedLine; +} Screen; + +#endif \ No newline at end of file diff --git a/asdevice/global.h b/asdevice/global.h new file mode 100755 index 0000000..cd2b2a6 --- /dev/null +++ b/asdevice/global.h @@ -0,0 +1,40 @@ + +//***************************************************************************** +// +// File Name : 'global.h' +// Title : AVR project global include +// Author : Pascal Stang +// Created : 7/12/2001 +// Revised : 9/30/2002 +// Version : 1.1 +// Target MCU : Atmel AVR series +// Editor Tabs : 4 +// +// Description : This include file is designed to contain items useful to all +// code files and projects. +// +// This code is distributed under the GNU Public License +// which can be found at http://www.gnu.org/licenses/gpl.txt +// +//***************************************************************************** + +#ifndef GLOBAL_H +#define GLOBAL_H + +// global AVRLIB defines +#include "avrlibdefs.h" +// global AVRLIB types definitions +#include "avrlibtypes.h" + +// project/system dependent defines + +// CPU clock speed +#define F_CPU 16000000 // 16MHz processor +//#define F_CPU 14745000 // 14.745MHz processor +//#define F_CPU 8000000 // 8MHz processor +//#define F_CPU 7372800 // 7.37MHz processor +//#define F_CPU 4000000 // 4MHz processor +//#define F_CPU 3686400 // 3.69MHz processor +#define CYCLES_PER_US ((F_CPU+500000)/1000000) // cpu cycles per microsecond + +#endif diff --git a/asdevice/keypad.c b/asdevice/keypad.c new file mode 100755 index 0000000..57d1ac0 --- /dev/null +++ b/asdevice/keypad.c @@ -0,0 +1,53 @@ +#include "keypad.h" + +void keyPadInit(){ + INIT_PORT; + INIT_PULLUP; +}; + +char getKey(){ + unsigned char upperNibble = 0xff; + unsigned char keyCode = 0xff; + + for(unsigned i=0; i<4; i++){ + _delay_ms(1); + PORT_OUT = ~(0x01 << i); + _delay_ms(1); //delay for port o/p settling + upperNibble = PORT_IN | 0x0f; + + if (upperNibble != 0xff){ + _delay_ms(debounceTime); //key debouncing delay + upperNibble = PORT_IN | 0x0f; + if(upperNibble == 0xff) goto OUT; + + keyCode = (upperNibble & 0xf0) | (0x0f & ~(0x01 << i)); + + while (upperNibble != 0xff) + upperNibble = PORT_IN | 0x0f; + + _delay_ms(debounceTime); //key debouncing delay + + switch (keyCode){ + case (0xee): keyCode = '0'; break; + case (0xed): keyCode = '1'; break; + case (0xeb): keyCode = '2'; break; + case (0xe7): keyCode = '3'; break; + case (0xde): keyCode = '4'; break; + case (0xdd): keyCode = '5'; break; + case (0xdb): keyCode = '6'; break; + case (0xd7): keyCode = '7'; break; + case (0xbe): keyCode = '8'; break; + case (0xbd): keyCode = '9'; break; + case (0xbb): keyCode = 'A'; break; + case (0xb7): keyCode = 'B'; break; + case (0x7e): keyCode = 'C'; break; + case (0x7d): keyCode = 'D'; break; + case (0x7b): keyCode = '*'; break; + case (0x77): keyCode = '#'; break; + default : keyCode = 'X'; + } + OUT:; + } + } +return keyCode; +}; diff --git a/asdevice/keypad.h b/asdevice/keypad.h new file mode 100755 index 0000000..1015eda --- /dev/null +++ b/asdevice/keypad.h @@ -0,0 +1,47 @@ +#ifndef KEYPAD_H +#define KEYPAD_H +#include +#ifndef GLOBAL_H + #include "global.h" +#endif +#ifndef KEYPADCONF_H + #include "keypadconfig.h" +#endif +#ifndef _UTIL_DELAY_H_ + #include +#endif + +#ifdef KEYPAD_4x4 +#define kpcolls 4 +#define kprows 4 + +unsigned char keyboard[4][4] PROGMEM = +{ + {'1','2','3','A'}, + {'4','5','6','B'}, + {'7','8','9','C'}, + {'*','0','#','D'} +}; +#endif +#ifdef KEYPAD_3x4 +#define kpcolls 3 +#define kprows 4 +unsigned char keyboard[4][3] PROGMEM = +{ + {'1','2','3'}, + {'4','5','6'}, + {'7','8','9'}, + {'*','0','#'} +}; +#endif + +typedef struct{ + unsigned pressed : 1; + unsigned holded : 1; + unsigned released : 1; + char keyChar; +} KeyPress; + +void keyPadInit(void); +char getKey(void); +#endif diff --git a/asdevice/keypadconfig.h b/asdevice/keypadconfig.h new file mode 100755 index 0000000..17fefb8 --- /dev/null +++ b/asdevice/keypadconfig.h @@ -0,0 +1,21 @@ +#ifndef KEYPADCONF_H +#define KEYPADCONF_H + +#ifndef KEYPAD_H +#include "keypad.h" +#endif + +#define KEYPAD_4x4 +//#define KEYPAD_3x4 +#define debounceTime 20 +//port settings +//0-3 - colls -OUT +//4-7 - rows - IN +#define INIT_PORT DDRD = 0x0f +#define INIT_PULLUP PORTD = 0xff +#define PORT_IN PIND +#define PORT_OUT PORTD +#define keyPadCols 4 +#define keyPadRows 4 + +#endif diff --git a/asdevice/lcdconf.h b/asdevice/lcdconf.h new file mode 100755 index 0000000..64ec7ad --- /dev/null +++ b/asdevice/lcdconf.h @@ -0,0 +1,104 @@ +/*! \file lcdconf.h \brief Character LCD driver configuration. */ +//***************************************************************************** +// +// File Name : 'lcdconf.h' +// Title : Character LCD driver for HD44780/SED1278 displays +// (usable in mem-mapped, or I/O mode) +// Author : Pascal Stang - Copyright (C) 2000-2002 +// Created : 11/22/2000 +// Revised : 4/30/2002 +// Version : 1.1 +// Target MCU : Atmel AVR series +// Editor Tabs : 4 +// +// This code is distributed under the GNU Public License +// which can be found at http://www.gnu.org/licenses/gpl.txt +// +//***************************************************************************** + +#ifndef LCDCONF_H +#define LCDCONF_H + +// Define type of interface used to access the LCD +// LCD_MEMORY_INTERFACE: +// To use this mode you must supply the necessary hardware to connect the +// LCD to the CPU's memory bus. The CONTROL and DATA registers of the LCD +// (HD44780 chip) must appear in the CPU's memory map. This mode is faster +// than the port interface but requires a little extra hardware to make it +// work. It is especially useful when your CPU is already configured to +// use an external memory bus for other purposes (like accessing memory). +// +// LCD_PORT_INTERFACE: +// This mode allows you to connect the control and data lines of the LCD +// directly to the I/O port pins (no interfacing hardware is needed), +// but it generally runs slower than the LCD_MEMORY_INTERFACE. +// Depending on your needs, when using the LCD_PORT_INTERFACE, the LCD may +// be accessed in 8-bit or 4-bit mode. In 8-bit mode, one whole I/O port +// (pins 0-7) is required for the LCD data lines, but transfers are faster. +// In 4-bit mode, only I/O port pins 4-7 are needed for data lines, but LCD +// access is slower. In either mode, three additional port pins are +// required for the LCD interface control lines (RS, R/W, and E). + +// Enable one of the following interfaces to your LCD +//#define LCD_MEMORY_INTERFACE +#define LCD_PORT_INTERFACE + +// Enter the parameters for your chosen interface' +// if you chose the LCD_PORT_INTERFACE: +#ifdef LCD_PORT_INTERFACE + #ifndef LCD_CTRL_PORT + // port and pins you will use for control lines + #define LCD_CTRL_PORT PORTC + #define LCD_CTRL_DDR DDRC + #define LCD_CTRL_RS 2 + #define LCD_CTRL_RW 3 + #define LCD_CTRL_E 4 + #endif + #ifndef LCD_DATA_POUT + // port you will use for data lines + #define LCD_DATA_POUT PORTA + #define LCD_DATA_PIN PINA + #define LCD_DATA_DDR DDRA + // access mode you will use (default is 8bit unless 4bit is selected) + #define LCD_DATA_4BIT + #endif +#endif + +// if you chose the LCD_MEMORY_INTERFACE: +#ifdef LCD_MEMORY_INTERFACE + #ifndef LCD_CTRL_ADDR + // CPU memory address of the LCD control register + #define LCD_CTRL_ADDR 0x1000 + #endif + #ifndef LCD_DATA_ADDR + // CPU memory address of the LCD data register + #define LCD_DATA_ADDR 0x1001 + #endif +#endif + + +// LCD display geometry +// change these definitions to adapt settings +#define LCD_LINES 2 // visible lines +#define LCD_LINE_LENGTH 16 // line length (in characters) +// cursor position to DDRAM mapping +#define LCD_LINE0_DDRAMADDR 0x00 +#define LCD_LINE1_DDRAMADDR 0x40 +#define LCD_LINE2_DDRAMADDR 0x14 +#define LCD_LINE3_DDRAMADDR 0x54 + +// LCD delay +// This delay affects how quickly accesses are made to the LCD controller. +// The HD44780 LCD controller requires an access time of at least 1us. +// LCD_DELAY should be scaled to take at least half that time (500us). +// Each NOP takes 1 CPU clock cycle to execute. Thus, at 4MHz, you should +// use at least 2 NOPs, at 8MHz at least 4 NOPs, etc. +// You can also use the delay_us(xx) command for longer access times. + +// LCD_DELAY is now automatically set in lcd.h, +// however, if you define it here, this definition will override the automatic setting + +// use this for a fail-safe delay +#define LCD_DELAY delay_us(5); + +#endif diff --git a/asdevice/makefile b/asdevice/makefile new file mode 100755 index 0000000..9b6f10d --- /dev/null +++ b/asdevice/makefile @@ -0,0 +1,304 @@ +######### AVR Project Makefile Template ######### +###### ###### +###### Copyright (C) 2003-2005,Pat Deegan, ###### +###### Psychogenic Inc ###### +###### All Rights Reserved ###### +###### ###### +###### You are free to use this code as part ###### +###### of your own applications provided ###### +###### you keep this copyright notice intact ###### +###### and acknowledge its authorship with ###### +###### the words: ###### +###### ###### +###### "Contains software by Pat Deegan of ###### +###### Psychogenic Inc (www.psychogenic.com)" ###### +###### ###### +###### If you use it as part of a web site ###### +###### please include a link to our site, ###### +###### http://electrons.psychogenic.com or ###### +###### http://www.psychogenic.com ###### +###### ###### +#################################################### + + +##### This Makefile will make compiling Atmel AVR +##### micro controller projects simple with Linux +##### or other Unix workstations and the AVR-GCC +##### tools. +##### +##### It supports C, C++ and Assembly source files. +##### +##### Customize the values as indicated below and : +##### make +##### make disasm +##### make stats +##### make hex +##### make writeflash +##### make gdbinit +##### or make clean +##### +##### See the http://electrons.psychogenic.com/ +##### website for detailed instructions + + +#################################################### +##### ##### +##### Configuration ##### +##### ##### +##### Customize the values in this section for ##### +##### your project. MCU, PROJECTNAME and ##### +##### PRJSRC must be setup for all projects, ##### +##### the remaining variables are only ##### +##### relevant to those needing additional ##### +##### include dirs or libraries and those ##### +##### who wish to use the avrdude programmer ##### +##### ##### +##### See http://electrons.psychogenic.com/ ##### +##### for further details. ##### +##### ##### +#################################################### + + +##### Target Specific Details ##### +##### Customize these for your project ##### + +# Name of target controller +# (e.g. 'at90s8515', see the available avr-gcc mmcu +# options for possible values) +MCU = atmega16 + +# id to use with programmer +# default: PROGRAMMER_MCU=$(MCU) +# In case the programer used, e.g avrdude, doesn't +# accept the same MCU name as avr-gcc (for example +# for ATmega8s, avr-gcc expects 'atmega8' and +# avrdude requires 'm8') +PROGRAMMER_MCU = m8 + +# Name of our project +# (use a single word, e.g. 'myproject') +PROJECTNAME = asdevice + +# Source files +# List C/C++/Assembly source files: +# (list all files to compile, e.g. 'a.c b.cpp as.S'): +# Use .cc, .cpp or .C suffix for C++ files, use .S +# (NOT .s !!!) for assembly source code files. +PRJSRC = $(AVRLIB)/lcd.c $(AVRLIB)/rprintf.c keypad.c screen.c device.c + +# additional includes (e.g. -I/path/to/mydir) +INC = -I$(AVRLIB) + +# libraries to link in (e.g. -lmylib) +LIBS = + +# Optimization level, +# use s (size opt), 1, 2, 3 or 0 (off) +OPTLEVEL = s + +##### AVR Dude 'writeflash' options ##### +##### If you are using the avrdude program +##### (http://www.bsdhome.com/avrdude/) to write +##### to the MCU, you can set the following config +##### options and use 'make writeflash' to program +##### the device. + + +# programmer id--check the avrdude for complete list +# of available opts. These should include stk500, +# avr910, avrisp, bsd, pony and more. Set this to +# one of the valid "-c PROGRAMMER-ID" values +# described in the avrdude info page. +# +AVRDUDE_PROGRAMMERID=stk500 + +# port--serial or parallel port to which your +# hardware programmer is attached +# +AVRDUDE_PORT=/dev/ttyS1 + +#################################################### +##### Config Done ##### +##### ##### +##### You shouldn't need to edit anything ##### +##### below to use the makefile but may wish ##### +##### to override a few of the flags ##### +##### nonetheless ##### +##### ##### +#################################################### + + +##### Flags #### + +# HEXFORMAT -- format for .hex file output +HEXFORMAT=ihex + +# compiler +CFLAGS=-std=c99 -I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL) \ + -fpack-struct -fshort-enums \ + -funsigned-bitfields -funsigned-char \ + -Wall -Wstrict-prototypes \ + -Wa,-ahlms=$(firstword \ + $(filter %.lst, $(<:.c=.lst))) +# c++ specific flags +CPPFLAGS=-fno-exceptions \ + -Wa,-ahlms=$(firstword \ + $(filter %.lst, $(<:.cpp=.lst)) \ + $(filter %.lst, $(<:.cc=.lst)) \ + $(filter %.lst, $(<:.C=.lst))) +# assembler +ASMFLAGS =-I. $(INC) -mmcu=$(MCU) \ + -x assembler-with-cpp \ + -Wa,-gstabs,-ahlms=$(firstword \ + $(<:.S=.lst) $(<.s=.lst)) +# linker +LDFLAGS=-Wl,-Map,$(TRG).map -mmcu=$(MCU) \ + -lm $(LIBS) +##### executables #### +CC=avr-gcc +OBJCOPY=avr-objcopy +OBJDUMP=avr-objdump +SIZE=avr-size +AVRDUDE=avrdude +REMOVE=rm -f + +##### automatic target names #### +TRG=$(PROJECTNAME).out +DUMPTRG=$(PROJECTNAME).s + +HEXROMTRG=$(PROJECTNAME).hex +HEXTRG=$(HEXROMTRG) $(PROJECTNAME).ee.hex +GDBINITFILE=gdbinit-$(PROJECTNAME) + +# Define all object files. + +# Start by splitting source files by type +# C++ +CPPFILES=$(filter %.cpp, $(PRJSRC)) +CCFILES=$(filter %.cc, $(PRJSRC)) +BIGCFILES=$(filter %.C, $(PRJSRC)) +# C +CFILES=$(filter %.c, $(PRJSRC)) +# Assembly +ASMFILES=$(filter %.S, $(PRJSRC)) + + +# List all object files we need to create +OBJDEPS=$(CFILES:.c=.o) \ + $(CPPFILES:.cpp=.o) \ + $(BIGCFILES:.C=.o) \ + $(CCFILES:.cc=.o) \ + $(ASMFILES:.S=.o) + +# Define all lst files. +LST=$(filter %.lst, $(OBJDEPS:.o=.lst)) + +# All the possible generated assembly +# files (.s files) +GENASMFILES=$(filter %.s, $(OBJDEPS:.o=.s)) + + +.SUFFIXES : .c .cc .cpp .C .o .out .s .S \ + .hex .ee.hex .h .hh .hpp + + +.PHONY: writeflash clean stats gdbinit stats + +# Make targets: +# all, disasm, stats, hex, writeflash/install, clean +all: $(TRG) + +disasm: $(DUMPTRG) stats + +stats: $(TRG) + $(OBJDUMP) -h $(TRG) + $(SIZE) $(TRG) + +hex: $(HEXTRG) + + +writeflash: hex + $(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \ + -p $(PROGRAMMER_MCU) -P $(AVRDUDE_PORT) -e \ + -U flash:w:$(HEXROMTRG) + +install: writeflash + +$(DUMPTRG): $(TRG) + $(OBJDUMP) -S $< > $@ + + +$(TRG): $(OBJDEPS) + $(CC) $(LDFLAGS) -o $(TRG) $(OBJDEPS) + + +### Generating assembly #### +# asm from C +%.s: %.c + $(CC) -S $(CFLAGS) $< -o $@ + +# asm from (hand coded) asm +%.s: %.S + $(CC) -S $(ASMFLAGS) $< > $@ + + +# asm from C++ +.cpp.s .cc.s .C.s : + $(CC) -S $(CFLAGS) $(CPPFLAGS) $< -o $@ + + + +#### Generating object files #### +# object from C +.c.o: + $(CC) $(CFLAGS) -c $< -o $@ + + +# object from C++ (.cc, .cpp, .C files) +.cc.o .cpp.o .C.o : + $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ + +# object from asm +.S.o : + $(CC) $(ASMFLAGS) -c $< -o $@ + + +#### Generating hex files #### +# hex files from elf +##### Generating a gdb initialisation file ##### +.out.hex: + $(OBJCOPY) -j .text \ + -j .data \ + -O $(HEXFORMAT) $< $@ + +.out.ee.hex: + $(OBJCOPY) -j .eeprom \ + --change-section-lma .eeprom=0 \ + -O $(HEXFORMAT) $< $@ + + +##### Generating a gdb initialisation file ##### +##### Use by launching simulavr and avr-gdb: ##### +##### avr-gdb -x gdbinit-myproject ##### +gdbinit: $(GDBINITFILE) + +$(GDBINITFILE): $(TRG) + @echo "file $(TRG)" > $(GDBINITFILE) + + @echo "target remote localhost:1212" >> $(GDBINITFILE) + + @echo "load" >> $(GDBINITFILE) + @echo "break main" >> $(GDBINITFILE) + @echo "continue" >> $(GDBINITFILE) + @echo + @echo "Use 'avr-gdb -x $(GDBINITFILE)'" + + +#### Cleanup #### +clean: + $(REMOVE) $(TRG) $(TRG).map $(DUMPTRG) + $(REMOVE) $(OBJDEPS) + $(REMOVE) $(LST) $(GDBINITFILE) + $(REMOVE) $(GENASMFILES) + $(REMOVE) $(HEXTRG) + diff --git a/asdevice/portoperations.h b/asdevice/portoperations.h new file mode 100755 index 0000000..27e2529 --- /dev/null +++ b/asdevice/portoperations.h @@ -0,0 +1,7 @@ +#define bit_get(p,m) ((p) & (m)) +#define bit_set(p,m) ((p) |= (m)) +#define bit_clear(p,m) ((p) &= ~(m)) +#define bit_flip(p,m) ((p) ^= (m)) +#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m)) +#define BIT(x) (0x01 << (x)) +#define LONGBIT(x) ((unsigned long)0x00000001 << (x)) diff --git a/asdevice/screen.c b/asdevice/screen.c new file mode 100644 index 0000000..91b392f --- /dev/null +++ b/asdevice/screen.c @@ -0,0 +1,24 @@ +#include "screen.h" + +// s - stands for array of pointers to array of screen texts +// xo - stands for x-Offset (how much spaces in front of line) +// yo - stands for y-Offset (which line first) +void drawScreen(PGM_P* s, unsigned xo, unsigned yo, int scrSize){ + lcdClear(); + rprintfInit(lcdDataWrite); + for(int i = 0; i<(unsigned)fmin(((sizeof(s)/sizeof(&s))), LCD_LINES); i++){ + lcdGotoXY(i,xo); + rprintfProgStr(s[i+yo]); + if(i == 1){rprintfChar(SELCHAR);} + } +} + +void prev(PGM_P* s, DeviceState* d, int scrSize){ + (*d).menuOffset = ((*d).menuOffset==0)?((*d).menuOffset):((*d).menuOffset-1); + drawScreen(s,2,(*d).menuOffset, scrSize); +} + +void next(PGM_P* s, DeviceState* d, int scrSize){ + (*d).menuOffset = ((*d).menuOffset==scrSize)?((*d).menuOffset):((*d).menuOffset+1); + drawScreen(s,2,(*d).menuOffset,scrSize); +} \ No newline at end of file diff --git a/asdevice/screen.h b/asdevice/screen.h new file mode 100644 index 0000000..1eaf285 --- /dev/null +++ b/asdevice/screen.h @@ -0,0 +1,37 @@ +#ifndef SCREEN_H +#define SCREEN_H + +#ifndef GLOBAL_H +#include "global.h" +#endif +#ifndef LCDCONF_H +#include "lcdconf.h" +#endif +#ifndef LCD_H +#include "lcd.h" +#endif +#ifndef RPRINTF_H +#include "rprintf.h" +#endif +#ifndef __PGMSPACE_H_ +#include +#endif +#ifndef NAN +#include +#endif +#ifndef DEVICE_TYPES_H +#include "devicetypes.h" +#endif + +#ifndef SELCHAR +#define SELCHAR 0x3e // selchar is '*' +#endif + +// s - stands for array of pointers to array of screen texts +// xo - stands for x-Offset (how much spaces in front of line) +// yo - stands for y-Offset (which line first) +void drawScreen(PGM_P*,unsigned,unsigned,int); +void next(PGM_P*,DeviceState*,int); +void prev(PGM_P*,DeviceState*,int); + +#endif \ No newline at end of file diff --git a/asdevice/tags b/asdevice/tags new file mode 100755 index 0000000..d01d39b --- /dev/null +++ b/asdevice/tags @@ -0,0 +1,6 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ +!_TAG_PROGRAM_NAME Exuberant Ctags // +!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ +!_TAG_PROGRAM_VERSION 5.8 // diff --git a/pointertest.c b/pointertest.c new file mode 100644 index 0000000..c32c418 --- /dev/null +++ b/pointertest.c @@ -0,0 +1,65 @@ +#include +#include + +char s0[] = "\0"; +char s1[] = "Line1 text\0"; +char s2[] = "line2 text\0"; +char s3[] = "line3 text\0"; +char s4[] = "line4 text\0"; + + +char* screen1[] = {s0}; +#define screen1Len (sizeof(screen1)/sizeof(&screen1)) +char* screen2[] = {s0,s1,s2,s3,s4}; +#define screen2Len (sizeof(screen2)/sizeof(&screen2)) +char* screen3[] = {s0,s1}; +#define screen3Len (sizeof(screen3)/sizeof(&screen3)) + +char** screens[] = {screen1,screen2,screen3}; +int screensLen[] = {screen1Len,screen2Len,screen3Len}; + +void drawScreen(char**,unsigned,int); +void next(char**,unsigned*,int); +void prev(char**,unsigned*,int); +float min(float a, float b){return (a < b ? a : b);} + +int main(){ + char key=0xff; + int i = 0; + unsigned* offset; + offset = malloc(sizeof(unsigned)); + *offset = 0; + drawScreen(screens[1],0,screensLen[1]); + while(1){ + key = getchar(); + switch (key) { + case 'n' : { + next(screens[1],offset,screensLen[1]); + }; break; + case 'p' : { + prev(screens[1],offset,screensLen[1]); + }; break; + } + } + return 1; +} + +void drawScreen(char** s,unsigned yo,int scrLen){ + int i = 0; + system("clear"); + for(i; i<(unsigned)min(scrLen, 2); i++){ + printf("%d ",i); + printf(i==1?"*":" "); + printf("%s\n",s[i+yo]); + } +} + +void next(char** s,unsigned* menuOffset,int scrLen){ + *menuOffset = ((*menuOffset)+2==scrLen)?(*menuOffset):(((*menuOffset)+1)); + drawScreen(s,*menuOffset,scrLen); +} + +void prev(char** s, unsigned* menuOffset,int scrLen){ + *menuOffset = (*menuOffset==0)?(*menuOffset):((*menuOffset)-1); + drawScreen(s,*menuOffset,scrLen); +} diff --git a/randomgen.c b/randomgen.c new file mode 100644 index 0000000..96e7cda --- /dev/null +++ b/randomgen.c @@ -0,0 +1,34 @@ +#include +#include +#include + +typedef struct{ + long aCodes[5]; + long dCodes[5]; +} Data; + +long getUniqueRandom(Data* d){ + int run = 1; + long rnd = 0; + + while(run){ + run = 0; + srand(time(NULL)); + rnd = rand()%100000; + for(int i=0; i<5; i++){ if(rnd == (*d).aCodes[i]){run = 1;}} + for(int i=0; i<5; i++){ if(rnd == (*d).dCodes[i]){run = 1;}} + } + return rnd; +} + +int main(void){ + Data* d = malloc(sizeof(Data)); + + for(int i=0; i<5; i++){(*d).aCodes[i] = getUniqueRandom(d);} + for(int i=0; i<5; i++){(*d).dCodes[i] = getUniqueRandom(d);} + + for(int i=0; i<5; i++){ printf("%05ld\n",(*d).aCodes[i]);} + for(int i=0; i<5; i++){ printf("%05ld\n",(*d).dCodes[i]);} + + return 0; +} diff --git a/test.c b/test.c new file mode 100644 index 0000000..f0a798e --- /dev/null +++ b/test.c @@ -0,0 +1,31 @@ +#include +#include + +typedef struct { + int a; + int b; + int (*ptFunction) (int, int); +} fraction; + +int DoIt (int x, int y){ printf("DoIt\n"); return x+y;} +int DoIt2 (int x, int y){ printf("DoIt2\n"); return y-x;} + +int main(){ + fraction *f; + f = malloc(sizeof(fraction)*2); + + f[0].a = 5; + f[0].b = 6; + f[0].ptFunction = &DoIt; + f[1].a = 10; + f[1].b = 11; + f[1].ptFunction = &DoIt2; + + printf("f[1].a: %d, f[1].b: %d \n",f[1].a,f[1].b); + printf("call 0 : %d\n",f[0].ptFunction(f[0].a,f[0].b)); + printf("call 1 : %d\n",f[1].ptFunction(f[1].a,f[1].b)); + + free(f); + + return 1; +} -- 2.11.4.GIT