# (GNU make, BSD make, SysV make)
-MCU = attiny441
+MCU = atmega1284p
FORMAT = ihex
-TARGET = PowerSwitch
-SRC = $(TARGET).c
+TARGET = main
+SRC = $(TARGET).c lcdlib/lcd-color-graphic.c lcdlib/font.c \
+ lcdlib/Fonts/digits_24px.c lcdlib/Fonts/digits_32px.c lcdlib/Fonts/font_proportional_16px.c \
+ lcdlib/Fonts/font_proportional_8px.c lcdlib/Fonts/symbols_16px.c
ASRC =
-OPT = s
+OPT = 2
+
+#usb/usb_serial.c 1wire.c
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
CSTANDARD = -std=gnu99
# Place -D or -U options here
-CDEFS =
+CDEFS = -DF_CPU=8000000UL
# Place -I options here
-CINCS =
+CINCS =
CDEBUG = -g$(DEBUG)
-CWARN = -Wall -Wstrict-prototypes
-CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
+CWARN = -Wall -Wstrict-prototypes
+CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wl,--relax
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
-CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
+CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) $(CTUNING)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
# Programming support using avrdude. Settings and variables.
-AVRDUDE_PROGRAMMER = usbtiny
+AVRDUDE_PROGRAMMER = dragon_jtag
AVRDUDE_PORT = usb
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
-#AVRDUDE_NO_VERIFY = -V
+AVRDUDE_NO_VERIFY = -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# Default target.
all: build
-build: elf hex eep
+build: elf hex eep lss
elf: $(TARGET).elf
hex: $(TARGET).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
-
-
+size:
+ $(SIZE) $(TARGET).elf
+#-C --mcu=$(MCU)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
>> $(MAKEFILE); \
$(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
-.PHONY: all build elf hex eep lss sym program coff extcoff clean depend
+.PHONY: all build elf hex eep lss sym program coff extcoff clean depend program_bootloader program_arduino
+
+program_bootloader: all
+ dfu-programmer $(MCU) erase && dfu-programmer $(MCU) flash $(TARGET).hex && dfu-programmer $(MCU) start
+
+program_arduino: all
+ avrdude -patmega32u4 -cavr109 -P$(PORT) -b57600 -D -Uflash:w:$(TARGET).hex:i
-#define F_CPU 8000000UL
+
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/eeprom.h>
#include <string.h>
-#define FIRMWARE_VERSION 0x01
+#include "main.h"
+#include "lcdlib/lcd-color-graphic.h"
+#include "lcdlib/font.h"
+
+
+/******************
+ * Init USART for LCD
+ *****************/
+void init_spi_lcd(void) {
+ UCSR1B = (1 << TXEN1);
+ UCSR1C = (1 << UMSEL10) | (0 << UDORD1) | (0 << UCPHA1) | (0 << UCPOL1);
+ UBRR1L = 0;
+ UBRR1H = 0;
+}
+
+
+/******************
+ * Init all functions
+ *****************/
void init(void) {
+
+//Init ADC SPI
+ SPCR = (0 << SPIE) | (1 << SPE ) | (0 << DORD) | (1 << MSTR) | (0 << CPOL) | (0 << CPHA) | (0 << SPR0);
+ SPSR = (1 << SPI2X); //fcpu/8
+ DDRB |= (1 << PB7) | (1 << PB5) | (1 << PB4); //ADC has three control lines
+
+//Init ADC for presence measurement
+ ADMUX = (3 << REFS0) | (1 << ADLAR) | (3 << MUX0);
+ ADCSRA = (1 << ADEN) | (0 << ADIE) | (5 << ADPS0); //fcpu/32
+ DIDR0 = 0x08; //PA3 is analog only
+
+//Init UART
+
+
+//GPIO
+ PORTD |= (0xc0); //pull-up for switches
+ PORTA |= (0x07); //spare I/O have pull-up
+
+ DDRB |= (0x03); //LED are output
+ DDRA |= (0x70); //select outputs
+ DDRC |= (0xc0); //outputs for Inhibit signals
+
+
}
-void main(void) {
+int main(void) {
+
init();
+ lcd_init();
while(1);
+ return 0;
}
\ No newline at end of file
+
+
+#define FIRMWARE_VERSION 0x01
+
+#define UDORD1 2
+#define UCPHA1 1
+
+#define ADC_SELECT() PORTB &= ~(1<< PB4)
+#define ADC_UNSELECT() PORTB |= (1<< PB4)
+
+#define LED1_ON() PORTB |= (1<< PB1)
+#define LED1_OFF() PORTB &= ~(1<< PB1)
+#define LED2_ON() PORTB |= (1<< PB0)
+#define LED2_OFF() PORTB &= ~(1<< PB0)
+
+#define SWITCH1() ((PIND>>PD6)&1)
+#define SWITCH2() ((PIND>>PD7)&1)
+
+#define SELECT(i) (PORTA = (PORTA & 0x8F) | (((i)&0x7) << 4)
+
+#define MUX_C_ON() PORTC &= ~(1<<PC7)
+#define MUX_C_OFF() PORTC |= (1<<PC7)
+#define MUX_T_ON() PORTC &= ~(1<<PC6)
+#define MUX_T_OFF() PORTC |= (1<<PC6)
\ No newline at end of file