$(shell mkdir -p dist >/dev/null)
$(shell mkdir -p build >/dev/null)
$(shell mkdir -p sim >/dev/null)
+$(shell mkdir -p sim/build >/dev/null)
NAME="test_2024-07-23_nano-644"
SRC= $(wildcard src/*.c src/*.cpp src/*/*.cpp)
-OBJ = $(SRC:src/%.c=build/%.o)
-OBJ_SIM = $(SRC:src/%.c=sim/%.o)
+OBJ_CPP = $(SRC:src/%.cpp=build/%.o)
+OBJ = $(OBJ_CPP:src/%.c=build/%.o)
+OBJ_SIM_CPP = $(SRC:src/%.cpp=sim/build/%.o)
+OBJ_SIM = $(OBJ_SIM_CPP:src/%.c=sim/build/%.o)
DEVICE=atmega644p
all: dist/$(NAME).elf dist/$(NAME).s dist/$(NAME).hex sim/$(NAME).elf sim/$(NAME).s info
-
+
+dbg:
+ @echo "OBJ_CPP" $(OBJ_CPP)
+ @echo "OBJ" $(OBJ)
+ @echo "OBJ_SIM_CPP" $(OBJ_SIM_CPP)
+ @echo "OBJ_SIM" $(OBJ_SIM)
+
info:
@echo
@avr-size --mcu=$(DEVICE) --format=avr dist/$(NAME).elf
build/%.o: src/%.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) -o $@ $<
+
+build/%.o: src/%.cpp
+ @mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $<
-sim/%.o: src/%.c
+sim/build/%.o: src/%.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS_SIM) -o $@ $<
+
+sim/build/%.o: src/%.cpp
+ @mkdir -p $(dir $@)
$(CC) $(CFLAGS_SIM) -o $@ $<
sim/%.s: sim/%.elf
ADCSRA |= (1 << ADSC); // start ADC
while (ADCSRA & (1 << ADSC)) {} // wait for result
buffer[0] = ADCH;
- printf_P(PSTR("\n write 0x%02x"), buffer[0]);
+ printf_P(PSTR("\n I2C-MASTER: to slave: 0x%02x"), buffer[0]);
if (!master.write(buffer, 1)) {
printf_P(PSTR(" -> ERROR"));
}
- printf_P(PSTR(", read "));
+ printf_P(PSTR(", from slave: "));
if (master.read(buffer, 1)) {
printf_P(PSTR("0x%02x"), buffer[0]);
} else {
ADCSRA |= (1 << ADSC); // start ADC
while (ADCSRA & (1 << ADSC)) {} // wait for result
slave.write(ADCH);
- printf_P(PSTR("\n => from master: 0x%02x -> to master: 0x%02x"), fromMaster, ADCH);
+ printf_P(PSTR("\n I2C SLAVE: from master: 0x%02x -> to master: 0x%02x"), fromMaster, ADCH);
}
} while (wait(0) == EOF);
slave.end();