-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d16cbb2
commit 90340aa
Showing
12 changed files
with
201 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,64 @@ | ||
PROJ = lamp | ||
DEVICE = atmega328 | ||
PROJ = lamp | ||
OSC = 16000000UL | ||
LFUSE = 0xdf | ||
DEVICE = atmega328 | ||
PROGDEV = m328 | ||
PROGVAR = usbasp | ||
|
||
SRCDIR = src/mcu-basic/ | ||
OUTDIR = build/mcu-basic/ | ||
G++ = avr-g++ | ||
SIZE = avr-size | ||
OBJCOPY = avr-objcopy | ||
PROG = avrdude | ||
|
||
SRCDIR = src/mcu-basic/ | ||
COREDIR = src/mcu/core/ | ||
STLDIR = src/mcu-basic/stl/ | ||
OUTDIR = build/mcu-basic/ | ||
|
||
C++FLAGS = -Os | ||
C++FLAGS += -Wall | ||
C++FLAGS += -std=c++11 | ||
C++FLAGS += -DF_CPU=$(OSC) | ||
C++FLAGS += -DBASIC | ||
C++FLAGS += -mmcu=$(DEVICE) | ||
C++FLAGS += -I$(STLDIR) | ||
C++FLAGS += -I$(COREDIR) | ||
C++FLAGS += -fno-exceptions | ||
|
||
OBJECTS = \ | ||
$(patsubst $(SRCDIR)%.cpp,$(OUTDIR)%.o,$(wildcard $(SRCDIR)*.cpp)) \ | ||
$(patsubst $(COREDIR)%.cpp,$(OUTDIR)%.o,$(wildcard $(COREDIR)*.cpp)) | ||
|
||
.PHONY: all | ||
all: $(OUTDIR)$(PROJ).hex | ||
|
||
$(OUTDIR)%.o: $(SRCDIR)%.c | ||
mkdir -p $(OUTDIR) | ||
avr-gcc -g -Os -mmcu=$(DEVICE) -o $@ -c $< | ||
$(OUTDIR)%.hex: $(OUTDIR)%.elf | ||
$(OBJCOPY) -j .text -j .data -O ihex $< $@ | ||
|
||
$(OUTDIR)%.elf: $(OUTDIR)%.o | ||
avr-gcc -g -mmcu=$(DEVICE) -o $@ $< | ||
avr-size --format=avr --mcu=$(DEVICE) $@ | ||
$(OUTDIR)%.elf: $(OBJECTS) | ||
$(G++) $(C++FLAGS) $(OBJECTS) --output $@ | ||
$(SIZE) --format=avr --mcu=$(DEVICE) $@ | ||
|
||
$(OUTDIR)%.hex: $(OUTDIR)%.elf | ||
avr-objcopy -j .text -j .data -O ihex $< $@ | ||
$(OUTDIR)%.o: $(SRCDIR)%.cpp | ||
mkdir -p $(OUTDIR) | ||
$(G++) $< $(C++FLAGS) -c -o $@ | ||
|
||
$(OUTDIR)%.o: $(COREDIR)%.cpp | ||
mkdir -p $(OUTDIR) | ||
$(G++) $< $(C++FLAGS) -c -o $@ | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf $(OUTDIR) | ||
rm -rf $(OUTDIR) | ||
|
||
.PHONY: list | ||
list: | ||
echo $(OBJECTS) | ||
|
||
.PHONY: flash | ||
flash: | ||
$(PROG) -p $(PROGDEV) -c $(PROGVAR) -B 5 -U flash:w:$(OUTDIR)$(PROJ).hex | ||
|
||
.PHONY: fuses | ||
fuses: | ||
$(PROG) -p $(PROGDEV) -c $(PROGVAR) -B 5 -U lfuse:w:$(LFUSE):m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "RgbLed.h" | ||
#include <avr/io.h> | ||
|
||
using namespace lamp; | ||
|
||
// PD3 - OC2B - red | ||
// PD5 - OC0B - green | ||
// PD6 - OC0A - blue | ||
|
||
RgbLed::RgbLed() { | ||
DDRD = (1 << PD3) | (1 << PD5) | (1 << PD6); | ||
TCCR0A = (1 << WGM00) | (1 << WGM01); | ||
TCCR0B = (1 << CS00); | ||
TCCR2A = (1 << WGM20) | (1 << WGM21); | ||
TCCR2B = (1 << CS20); | ||
} | ||
|
||
void RgbLed::setLedColor(RgbLedColor color) { | ||
if(color.r == 0) { | ||
TCCR2A &= ~(1 << COM2B1); | ||
} else { | ||
TCCR2A |= (1 << COM2B1); | ||
OCR2B = color.r; | ||
} | ||
if(color.g == 0) { | ||
TCCR0A &= ~(1 << COM0B1); | ||
} else { | ||
TCCR0A |= (1 << COM0B1); | ||
OCR0B = color.g; | ||
} | ||
if(color.b == 0) { | ||
TCCR0A &= ~(1 << COM0A1); | ||
} else { | ||
TCCR0A |= (1 << COM0A1); | ||
OCR0A = color.b; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include "IRgbLed.h" | ||
|
||
namespace lamp { | ||
|
||
class RgbLed : public IRgbLed { | ||
|
||
public: | ||
explicit RgbLed(); | ||
|
||
void setLedColor(RgbLedColor color) override; | ||
|
||
}; | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "new.h" | ||
//#include <util/delay.h> | ||
|
||
#include "RgbLed.h" | ||
#include "Lamp.h" | ||
|
||
using namespace lamp; | ||
|
||
extern "C" { | ||
int main(void); | ||
} | ||
|
||
int main(void) { | ||
auto led = new RgbLed(); | ||
auto lamp = new Lamp(led); | ||
lamp->start(0); | ||
while(1){ | ||
/*for(uint8_t i = 0; i < 255; i++) { | ||
led->setLedColor({ i, 0, 0 }); | ||
_delay_ms(10); | ||
} | ||
for(uint8_t i = 0; i < 255; i++) { | ||
led->setLedColor({ 0, i, 0 }); | ||
_delay_ms(10); | ||
}; | ||
for(uint8_t i = 0; i < 255; i++) { | ||
led->setLedColor({ 0, 0, i }); | ||
_delay_ms(10); | ||
} | ||
for(uint8_t i = 0; i < 255; i++) { | ||
led->setLedColor({ i, i, i }); | ||
_delay_ms(10); | ||
}*/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include <stdint.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <stdlib.h> | ||
|
||
void *operator new(size_t size) { | ||
return malloc(size); | ||
} | ||
|
||
void *operator new[](size_t size) { | ||
return malloc(size); | ||
} | ||
|
||
void operator delete(void * ptr) { | ||
free(ptr); | ||
} | ||
|
||
void operator delete[](void * ptr) { | ||
free(ptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters