diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | contrib/Makefile | 16 | ||||
-rw-r--r-- | contrib/radiohead.patch | 26 | ||||
-rw-r--r-- | include.mk | 32 | ||||
-rw-r--r-- | lib/SPI.h | 38 | ||||
-rw-r--r-- | lib/arduino-minimal.h | 54 | ||||
-rw-r--r-- | lora-test/Makefile | 34 | ||||
-rw-r--r-- | lora-test/lora-test.cpp | 51 | ||||
-rw-r--r-- | radiohead.mk | 43 |
9 files changed, 294 insertions, 2 deletions
@@ -11,6 +11,8 @@ contrib/FastLED-* contrib/PJON-* contrib/BMP180-* contrib/vusb-* +contrib/RadioHead-* +contrib/RadioHead/ contrib/.teensy-loader.prepared contrib/teensy_loader_cli contrib/.micronucleus.prepared diff --git a/contrib/Makefile b/contrib/Makefile index 05fe264..9d606bb 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -26,8 +26,10 @@ LUFA_VERSION := 151115 FASTLED_VERSION := 3.1.0 PJON_VERSION := 3.0 VUSB_VERSION := 20121206 +RADIOHEAD_VERSION := 1.89 + +all: download-lufa download-fastled download-pjon download-vusb download-radiohead update-teensy-loader update-micronucleus -all: download-lufa download-fastled download-pjon download-vusb update-teensy-loader update-micronucleus download-lufa: LUFA-${LUFA_VERSION}.zip @@ -35,6 +37,7 @@ LUFA-${LUFA_VERSION}.zip: wget "http://www.github.com/abcminiuser/lufa/archive/$@" -O "$@" unzip $@ + download-fastled: FastLED-${FASTLED_VERSION}.zip FastLED-${FASTLED_VERSION}.zip: @@ -49,12 +52,22 @@ PJON-${PJON_VERSION}.zip: wget "https://github.com/gioblu/PJON/archive/${PJON_VERSION}.zip" -O "$@" unzip $@ + download-vusb: vusb-${VUSB_VERSION}.zip vusb-${VUSB_VERSION}.zip: wget "https://www.obdev.at/downloads/vusb/vusb-${VUSB_VERSION}.zip" -O "$@" unzip $@ + +download-radiohead: RadioHead-${RADIOHEAD_VERSION}.zip + +RadioHead-${RADIOHEAD_VERSION}.zip: + wget "http://www.airspayce.com/mikem/arduino/RadioHead/$@" -O "$@" + unzip $@ + cd RadioHead; patch -p1 < ../radiohead.patch + + .teensy-loader.prepared: git clone https://github.com/PaulStoffregen/teensy_loader_cli.git touch $@ @@ -62,6 +75,7 @@ vusb-${VUSB_VERSION}.zip: update-teensy-loader: .teensy-loader.prepared cd teensy_loader_cli; git pull; make + .micronucleus.prepared: git clone https://github.com/micronucleus/micronucleus/ touch $@ diff --git a/contrib/radiohead.patch b/contrib/radiohead.patch new file mode 100644 index 0000000..e844a0a --- /dev/null +++ b/contrib/radiohead.patch @@ -0,0 +1,26 @@ +diff -Nur RadioHead.orig/RadioHead.h RadioHead/RadioHead.h +--- RadioHead.orig/RadioHead.h 2018-11-15 02:40:23.000000000 +0100 ++++ RadioHead/RadioHead.h 2018-11-22 02:28:56.058105167 +0100 +@@ -317,8 +317,6 @@ + cd /tmp + mkdir RadioHead + cd RadioHead +-cp /usr/local/projects/arduino/libraries/RadioHead/*.h . +-cp /usr/local/projects/arduino/libraries/RadioHead/*.cpp . + cp /usr/local/projects/arduino/libraries/RadioHead/examples/cc110/cc110_client/cc110_client.pde application.cpp + \endcode + - Edit application.cpp and comment out any \#include <SPI.h> so it looks like: +@@ -1283,11 +1281,13 @@ + #elif (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8) + #include <avr/io.h> + #include <avr/interrupt.h> ++ #include <avr/pgmspace.h> + #include <util/delay.h> + #include <string.h> + #include <stdbool.h> + #define RH_HAVE_HARDWARE_SPI + #include <SPI.h> ++ #include <arduino-minimal.h> + + // For Steve Childress port to ARM M4 w/CMSIS with STM's Hardware Abstraction lib. + // See ArduinoWorkarounds.h (not supplied) @@ -41,7 +41,7 @@ CXX_OBJ_LIB := $(CXX_LIBS:%=lib-%.o) CXX_SRC_LIB := $(CXX_LIBS:%=$(LIB_DIR)/%.cpp) CXX_DEP_LIB := $(CXX_LIBS:%=lib-%.d) -.PHONY: prepare clean clean-external distclean clean-lufa clean-fastled clean-pjon clean-vusb program erase flash reset run +.PHONY: prepare clean clean-external distclean clean-lufa clean-fastled clean-pjon clean-vusb clean-radiohead program erase flash reset run ELFFILE := $(NAME).elf HEXFILE := $(NAME).hex @@ -82,6 +82,13 @@ CFLAGS += -DUSES_VUSB CFLAGS += $(VUSB_OPTS) endif +ifdef RADIOHEAD_PATH +CXXFLAGS += -I$(RADIOHEAD_PATH) +CXXFLAGS += -DUSES_RADIOHEAD +CXXFLAGS += -DRH_PLATFORM=RH_PLATFORM_GENERIC_AVR8 +CXXFLAGS += $(RADIOHEAD_OPTS) +endif + prepare: $(EXTERNAL_LIBS:%=build-%) clean-external: $(EXTERNAL_LIBS:%=clean-%) @@ -179,6 +186,29 @@ clean-vusb: @echo "****************************************************" +build-radiohead: libradiohead.a + +libradiohead.a: Makefile + @echo "" + @echo "****************************************************" + @echo "building external RadioHead lib ($(RADIOHEAD_PATH))" + @echo "" + make -f $(SPREADAVR_PATH)/radiohead.mk libradiohead.a + make -f $(SPREADAVR_PATH)/radiohead.mk clean + @echo "" + @echo "****************************************************" + +clean-radiohead: + @echo "" + @echo "****************************************************" + @echo "cleaning external RadioHead lib ($(RADIOHEAD_PATH))" + @echo "" + make -f $(SPREADAVR_PATH)/radiohead.mk clean + rm -f libradiohead.a + @echo "" + @echo "****************************************************" + + ## project-specific objects %.d: %.c Makefile @set -e; rm -f $@; \ diff --git a/lib/SPI.h b/lib/SPI.h new file mode 100644 index 0000000..a770999 --- /dev/null +++ b/lib/SPI.h @@ -0,0 +1,38 @@ +/* + * spreadspace avr utils + * + * + * Copyright (C) 2013-2018 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of spreadspace avr utils. + * + * spreadspace avr utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace avr utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SPREADAVR_SPI_h_INCLUDED +#define SPREADAVR_SPI_h_INCLUDED + + // TODO: for now this is just a placeholder to make it so we + // can compile RadioHead + +class SPIClass { // AVR +public: + static void begin(); + static void end(); + static uint8_t transfer(uint8_t data); +}; + +extern SPIClass SPI; + +#endif diff --git a/lib/arduino-minimal.h b/lib/arduino-minimal.h new file mode 100644 index 0000000..64eb867 --- /dev/null +++ b/lib/arduino-minimal.h @@ -0,0 +1,54 @@ +/* + * spreadspace avr utils + * + * + * Copyright (C) 2013-2018 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of spreadspace avr utils. + * + * spreadspace avr utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace avr utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SPREADAVR_arduino_minimal_h_INCLUDED +#define SPREADAVR_arduino_minimal_h_INCLUDED + +#define HIGH 0x1 +#define LOW 0x0 + +#define INPUT 0x0 +#define OUTPUT 0x1 +#define INPUT_PULLUP 0x2 + +#define CHANGE 1 +#define FALLING 2 +#define RISING 3 + +unsigned long millis(void); +void delay(unsigned long); + +void pinMode(uint8_t, uint8_t); +void digitalWrite(uint8_t, uint8_t); +// int digitalRead(uint8_t); +// int analogRead(uint8_t); +// void analogReference(uint8_t mode); +// void analogWrite(uint8_t, int); + +void attachInterrupt(uint8_t, void (*)(void), int mode); +//void detachInterrupt(uint8_t); + +// WMath prototypes +long random(long); +long random(long, long); + +#endif diff --git a/lora-test/Makefile b/lora-test/Makefile new file mode 100644 index 0000000..8b2dc08 --- /dev/null +++ b/lora-test/Makefile @@ -0,0 +1,34 @@ +## +## spreadspace avr utils +## +## +## Copyright (C) 2013-2018 Christian Pointner <equinox@spreadspace.org> +## +## This file is part of spreadspace avr utils. +## +## spreadspace avr utils is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## any later version. +## +## spreadspace avr utils is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>. +## + +NAME := lora-test +BOARD_TYPE := elecrow32u4lora +CXX_OBJ := $(NAME).o +LIBS := util led +EXTERNAL_LIBS := radiohead +SPREADAVR_PATH := .. + +RADIOHEAD_PATH := $(SPREADAVR_PATH)/contrib/RadioHead + +RADIOHEAD_DRIVER := RF95 + +include $(SPREADAVR_PATH)/include.mk diff --git a/lora-test/lora-test.cpp b/lora-test/lora-test.cpp new file mode 100644 index 0000000..aecb0a6 --- /dev/null +++ b/lora-test/lora-test.cpp @@ -0,0 +1,51 @@ +/* + * spreadspace avr utils + * + * + * Copyright (C) 2013-2016 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of spreadspace avr utils. + * + * spreadspace avr utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace avr utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <avr/io.h> +#include <avr/wdt.h> +#include <avr/interrupt.h> +#include <avr/power.h> +#include <stdio.h> + +#include "util.h" +#include "led.h" + +#include "RadioHead.h" +#include "RH_RF95.h" + +RH_RF95 rf95; + +int main(void) +{ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + cpu_init(); + led_init(); + sei(); + + rf95.init(); + rf95.setFrequency(868.0); + for(;;) { + // for now we don't do anything here... + } +} diff --git a/radiohead.mk b/radiohead.mk new file mode 100644 index 0000000..94d1de3 --- /dev/null +++ b/radiohead.mk @@ -0,0 +1,43 @@ +## +## spreadspace avr utils +## +## +## Copyright (C) 2013-2018 Christian Pointner <equinox@spreadspace.org> +## +## This file is part of spreadspace avr utils. +## +## spreadspace avr utils is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## any later version. +## +## spreadspace avr utils is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>. +## + +include $(SPREADAVR_PATH)/defines.mk + + # TODO: add other components dependent on driver... +RADIOHEAD_COMPONENTS := RH_$(RADIOHEAD_DRIVER) RHGenericDriver RHSPIDriver RHHardwareSPI RHGenericSPI + +SRC:=$(foreach COMP,$(RADIOHEAD_COMPONENTS),$(RADIOHEAD_PATH)/$(COMP).cpp) + +CXXFLAGS += -I$(RADIOHEAD_PATH) +CXXFLAGS += -DRH_PLATFORM=RH_PLATFORM_GENERIC_AVR8 +CXXFLAGS += $(RADIOHEAD_OPTS) + +OBJ = $(SRC:%.cpp=%.o) + +libradiohead.a: $(OBJ) + $(AR) $@ $(OBJ) + +%.o: %.cpp + $(CXX) -c $(CXXFLAGS) $< -o $@ + +clean: + rm -f $(SRC:%.cpp=%.o) |