diff options
-rw-r--r-- | defines.mk | 29 | ||||
-rw-r--r-- | include.mk | 29 | ||||
-rw-r--r-- | lib/anyio.h | 8 | ||||
-rw-r--r-- | lib/cc1101.h | 8 | ||||
-rw-r--r-- | lib/cc1101_defines.h | 8 | ||||
-rw-r--r-- | lib/ds1820.h | 10 | ||||
-rw-r--r-- | lib/dualusbio.h | 8 | ||||
-rw-r--r-- | lib/led.h | 8 | ||||
-rw-r--r-- | lib/lufa-descriptor-keyboardmouse.h | 7 | ||||
-rw-r--r-- | lib/lufa-descriptor-midi.h | 8 | ||||
-rw-r--r-- | lib/lufa-descriptor-rndis.h | 8 | ||||
-rw-r--r-- | lib/lufa-descriptor-usbdualserial.h | 8 | ||||
-rw-r--r-- | lib/lufa-descriptor-usbserial.h | 8 | ||||
-rw-r--r-- | lib/onewire.h | 8 | ||||
-rw-r--r-- | lib/rda1846.h | 8 | ||||
-rw-r--r-- | lib/rda1846_defines.h | 8 | ||||
-rw-r--r-- | lib/serialio.h | 8 | ||||
-rw-r--r-- | lib/usbio.h | 8 | ||||
-rw-r--r-- | lib/util.h | 8 | ||||
-rw-r--r-- | usb-led++/Makefile | 48 | ||||
-rw-r--r-- | usb-led++/usb-led.cpp | 67 |
21 files changed, 288 insertions, 22 deletions
@@ -193,6 +193,7 @@ ifeq ($(BOARD_TYPE),AvrNetIo) endif CC = avr-gcc +CXX = avr-g++ OBJCOPY = avr-objcopy AR = avr-ar rcs SIZE = avr-size @@ -203,26 +204,28 @@ DFU = dfu-programmer teensy = teensy_loader_cli avrdude = avrdude -## Options common to compile, link and assembly rules +## Options common to C and C++ compiler COMMON = -mmcu=$(MCU) +COMMON += -O2 +COMMON += -funsigned-char +COMMON += -funsigned-bitfields +COMMON += -ffunction-sections +COMMON += -fpack-struct +COMMON += -fshort-enums +COMMON += -Wall +COMMON += -I$(LIB_DIR) +COMMON += -DF_CPU=$(F_CPU)UL +COMMON += -D__BOARD_$(BOARD_TYPE)__ +COMMON += -DARCH=ARCH_$(ARCH) ## Compile options common for all C compilation units. CFLAGS = $(COMMON) -CFLAGS += -O2 -CFLAGS += -funsigned-char -CFLAGS += -funsigned-bitfields -CFLAGS += -ffunction-sections -CFLAGS += -fpack-struct -CFLAGS += -fshort-enums -CFLAGS += -Wall CFLAGS += -Wstrict-prototypes -CFLAGS += -I$(LIB_DIR) -CFLAGS += -DF_CPU=$(F_CPU)UL -CFLAGS += -D__BOARD_$(BOARD_TYPE)__ -CFLAGS += -DARCH=ARCH_$(ARCH) CFLAGS += -std=c99 +## Compile options common for all C++ compilation units. +CXXFLAGS = $(COMMON) ## Linker flags -LDFLAGS = $(COMMON) +LDFLAGS = -mmcu=$(MCU) LDFLAGS += @@ -28,6 +28,9 @@ include $(SPREADAVR_PATH)/defines.mk ## project-specific objects SRC := $(OBJ:%.o=%.c) DEP := $(SRC:%.c=%.d) +CXX_SRC := $(CXX_OBJ:%.o=%.cpp) +CXX_DEP := $(CXX_SRC:%.cpp=%.d) + OBJ_LIB := $(LIBS:%=lib-%.o) SRC_LIB := $(LIBS:%=$(LIB_DIR)/%.c) DEP_LIB := $(LIBS:%=lib-%.d) @@ -68,31 +71,41 @@ clean-lufa: ## project-specific objects -lib-%.d: $(LIB_DIR)/%.c Makefile +%.d: %.c Makefile @set -e; rm -f $@; \ $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ - sed 's,\($*\)\.o[ :]*,lib-\1.o $@ : ,g' < $@.$$$$ > $@; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$; echo '(re)building $@' -%.d: %.c Makefile +%.d: %.cpp Makefile @set -e; rm -f $@; \ - $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ + $(CXX) -MM $(CXXFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$; echo '(re)building $@' +lib-%.d: $(LIB_DIR)/%.c Makefile + @set -e; rm -f $@; \ + $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,lib-\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$; echo '(re)building $@' + ifneq ($(MAKECMDGOALS),distclean) -include $(DEP) +-include $(CXX_DEP) -include $(DEP_LIB) endif -lib-%.o: $(LIB_DIR)/%.c Makefile +%.o: %.c Makefile $(CC) $(CFLAGS) -c $< -o $@ -%.o: %.c Makefile +%.o: %.cpp Makefile + $(CXX) $(CXXFLAGS) -c $< -o $@ + +lib-%.o: $(LIB_DIR)/%.c Makefile $(CC) $(CFLAGS) -c $< -o $@ -$(ELFFILE): $(OBJ) $(OBJ_LIB) $(EXTERNAL_LIBS:%=lib%.a) - $(CC) $(LDFLAGS) $(OBJ) $(OBJ_LIB) $(EXTERNAL_LIBS:%=-l%) -o $@ +$(ELFFILE): $(OBJ) $(CXX_OBJ) $(OBJ_LIB) $(EXTERNAL_LIBS:%=lib%.a) + $(CC) $(LDFLAGS) $(OBJ) $(CXX_OBJ) $(OBJ_LIB) $(EXTERNAL_LIBS:%=-l%) -o $@ $(SIZE) $@ @echo "" diff --git a/lib/anyio.h b/lib/anyio.h index ef5a832..9d7dee4 100644 --- a/lib/anyio.h +++ b/lib/anyio.h @@ -24,10 +24,18 @@ #ifndef SPREADAVR_anyio_h_INCLUDED #define SPREADAVR_anyio_h_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + #include <stdint.h> void anyio_init(const uint32_t baudrate, const uint8_t doublespeed); void anyio_task(void); int16_t anyio_bytes_received(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/cc1101.h b/lib/cc1101.h index b575c96..52dbf20 100644 --- a/lib/cc1101.h +++ b/lib/cc1101.h @@ -23,6 +23,10 @@ #ifndef SPREADAVR_cc1101_h_INCLUDED #define SPREADAVR_cc1101_h_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { unknown, sleep, idle, xoff, mancal, fs_wakeup, calibrate, settling, rx, txrx_settling, rxfifo_overflow, fstxon, tx, rxtx_settling, txfifo_underflow } cc1101_state_t; char* cc1101_state_to_string(cc1101_state_t); @@ -150,4 +154,8 @@ uint8_t cc1101_write_txfifo(const uint8_t* data, const uint8_t len); void cc1101_dump_register(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/cc1101_defines.h b/lib/cc1101_defines.h index 6130fd6..35ee5bd 100644 --- a/lib/cc1101_defines.h +++ b/lib/cc1101_defines.h @@ -23,6 +23,10 @@ #ifndef SPREADAVR_CC1101_defines_h_INCLUDED #define SPREADAVR_CC1101_defines_h_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + //// header byte #define CC1101_HEADER_READ 0x80 #define CC1101_HEADER_WRITE 0x00 @@ -234,4 +238,8 @@ #define CC1101_REG_RO_RCCTRL1_STATUS_MASK 0x7F #define CC1101_REG_RO_RCCTRL0_STATUS_MASK 0x7F +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/ds1820.h b/lib/ds1820.h index 64a0089..4623de4 100644 --- a/lib/ds1820.h +++ b/lib/ds1820.h @@ -25,6 +25,10 @@ #ifndef __DS1820__ #define __DS1820__ +#ifdef __cplusplus +extern "C" { +#endif + #include <stdint.h> #define DS1820_FAMILY_ID 0x10 @@ -58,4 +62,8 @@ void ds1820_wait_conversion_time(uint8_t bits); int16_t ds1820_read_temperature(uint8_t d); float ds1820_raw_temp_to_celsius(int16_t t); -#endif
\ No newline at end of file +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/dualusbio.h b/lib/dualusbio.h index 99c139e..14dcfa0 100644 --- a/lib/dualusbio.h +++ b/lib/dualusbio.h @@ -23,6 +23,10 @@ #ifndef SPREADAVR_dualusbio_h_INCLUDED #define SPREADAVR_dualusbio_h_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + #include <stdio.h> #include <stdint.h> @@ -34,4 +38,8 @@ void dualusbio_make_stdio(uint8_t port); int16_t dualusbio_bytes_received(uint8_t port); int16_t dualusbio_bytes_received_std(void); +#ifdef __cplusplus +} +#endif + #endif @@ -23,6 +23,10 @@ #ifndef SPREADAVR_led_h_INCLUDED #define SPREADAVR_led_h_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + void led_init(void); void led_on(void); @@ -33,4 +37,8 @@ void led2_on(void); void led2_off(void); void led2_toggle(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/lufa-descriptor-keyboardmouse.h b/lib/lufa-descriptor-keyboardmouse.h index fa02300..8328e5b 100644 --- a/lib/lufa-descriptor-keyboardmouse.h +++ b/lib/lufa-descriptor-keyboardmouse.h @@ -36,6 +36,10 @@ #ifndef _DESCRIPTORS_H_ #define _DESCRIPTORS_H_ +#ifdef __cplusplus +extern "C" { +#endif + /* Includes: */ #include <avr/pgmspace.h> @@ -98,5 +102,8 @@ const void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); +#ifdef __cplusplus +} #endif +#endif diff --git a/lib/lufa-descriptor-midi.h b/lib/lufa-descriptor-midi.h index 8b4b00d..38ee2ff 100644 --- a/lib/lufa-descriptor-midi.h +++ b/lib/lufa-descriptor-midi.h @@ -36,6 +36,10 @@ #ifndef _DESCRIPTORS_H_ #define _DESCRIPTORS_H_ +#ifdef __cplusplus +extern "C" { +#endif + /* Includes: */ #include <LUFA/Drivers/USB/USB.h> @@ -104,5 +108,9 @@ const void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/lufa-descriptor-rndis.h b/lib/lufa-descriptor-rndis.h index 9390ef2..90a1d25 100644 --- a/lib/lufa-descriptor-rndis.h +++ b/lib/lufa-descriptor-rndis.h @@ -36,6 +36,10 @@ #ifndef _DESCRIPTORS_H_ #define _DESCRIPTORS_H_ +#ifdef __cplusplus +extern "C" { +#endif + /* Includes: */ #include <LUFA/Drivers/USB/USB.h> @@ -106,5 +110,9 @@ const void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/lufa-descriptor-usbdualserial.h b/lib/lufa-descriptor-usbdualserial.h index 195c644..58dcc36 100644 --- a/lib/lufa-descriptor-usbdualserial.h +++ b/lib/lufa-descriptor-usbdualserial.h @@ -36,6 +36,10 @@ #ifndef _DESCRIPTORS_H_ #define _DESCRIPTORS_H_ +#ifdef __cplusplus +extern "C" { +#endif + /* Includes: */ #include <avr/pgmspace.h> @@ -131,5 +135,9 @@ const void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/lufa-descriptor-usbserial.h b/lib/lufa-descriptor-usbserial.h index 2c9ecaa..fa834f3 100644 --- a/lib/lufa-descriptor-usbserial.h +++ b/lib/lufa-descriptor-usbserial.h @@ -36,6 +36,10 @@ #ifndef _DESCRIPTORS_H_ #define _DESCRIPTORS_H_ +#ifdef __cplusplus +extern "C" { +#endif + /* Includes: */ #include <avr/pgmspace.h> @@ -106,5 +110,9 @@ const void** const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/onewire.h b/lib/onewire.h index 1410fde..b1112e1 100644 --- a/lib/onewire.h +++ b/lib/onewire.h @@ -1,6 +1,10 @@ #ifndef OneWire_h #define OneWire_h +#ifdef __cplusplus +extern "C" { +#endif + #include <inttypes.h> #include <stdbool.h> #include <avr/pgmspace.h> @@ -203,4 +207,8 @@ uint16_t owi_crc16(const uint8_t* input, uint16_t len, uint16_t crc); #endif #endif +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/rda1846.h b/lib/rda1846.h index d043f00..c744444 100644 --- a/lib/rda1846.h +++ b/lib/rda1846.h @@ -23,6 +23,10 @@ #ifndef SPREADAVR_rda1846_h_INCLUDED #define SPREADAVR_rda1846_h_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { b_2m, b_1m5, b_70cm } rf_band_t; char* rda1846_rf_band_to_string(rf_band_t); typedef enum { bw_12k5, bw_25k } channel_bw_t; @@ -64,4 +68,8 @@ uint16_t rda1846_get_flags(void); void rda1846_dump_register(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/rda1846_defines.h b/lib/rda1846_defines.h index 37f1fba..8693f36 100644 --- a/lib/rda1846_defines.h +++ b/lib/rda1846_defines.h @@ -23,6 +23,10 @@ #ifndef SPREADAVR_rda1846_defines_h_INCLUDED #define SPREADAVR_rda1846_defines_h_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + // TWI #define RDA1846_CHIP_ADDR 0xE2 #define RDA1846_ADDR_W (0<<7) @@ -235,4 +239,8 @@ #define RDA1846_DTMF_C7 0xFB // 1633 Hz #endif // RDA_QUARTZ_13M +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/serialio.h b/lib/serialio.h index 3d1cbe1..ca24482 100644 --- a/lib/serialio.h +++ b/lib/serialio.h @@ -23,10 +23,18 @@ #ifndef SPREADAVR_serialio_h_INCLUDED #define SPREADAVR_serialio_h_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + #include <stdint.h> void serialio_init(const uint32_t baudrate, const uint8_t doublespeed); void serialio_task(void); int16_t serialio_bytes_received(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/lib/usbio.h b/lib/usbio.h index 4abdb2c..3373855 100644 --- a/lib/usbio.h +++ b/lib/usbio.h @@ -24,10 +24,18 @@ #ifndef SPREADAVR_usbio_h_INCLUDED #define SPREADAVR_usbio_h_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + #include <stdint.h> void usbio_init(void); void usbio_task(void); int16_t usbio_bytes_received(void); +#ifdef __cplusplus +} +#endif + #endif @@ -23,10 +23,18 @@ #ifndef SPREADAVR_util_h_INCLUDED #define SPREADAVR_util_h_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + void cpu_init(void); #if defined JTD void jtag_disable(void); #endif void reset2bootloader(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/usb-led++/Makefile b/usb-led++/Makefile new file mode 100644 index 0000000..a77b38c --- /dev/null +++ b/usb-led++/Makefile @@ -0,0 +1,48 @@ +## +## spreadspace avr utils +## +## +## Copyright (C) 2013-2015 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 := usb-led +BOARD_TYPE := teensy2 +OBJ := +CXX_OBJ := $(NAME).o +LIBS := util led lufa-descriptor-usbserial usbio +EXTERNAL_LIBS := lufa +SPREADAVR_PATH := .. +RESET_FUNC := $(SPREADAVR_PATH)/tools/reset_lufa_cdc +RESET_PARAM := 'r' + +LUFA_PATH := $(SPREADAVR_PATH)/contrib/lufa-LUFA-140928 +LUFA_OPTS = -D USB_DEVICE_ONLY +LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0 +LUFA_OPTS += -D ORDERED_EP_CONFIG +LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8 +LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 +LUFA_OPTS += -D USE_FLASH_DESCRIPTORS +LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" +LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT + +LUFA_OPTS += -D USB_MANUFACTURER="L\"equinox\"" +LUFA_OPTS += -D USB_PRODUCT="L\"spreadspace usb-led++ example\"" + +LUFA_COMPONENTS := USB USBCLASS + +include $(SPREADAVR_PATH)/include.mk diff --git a/usb-led++/usb-led.cpp b/usb-led++/usb-led.cpp new file mode 100644 index 0000000..08fcb39 --- /dev/null +++ b/usb-led++/usb-led.cpp @@ -0,0 +1,67 @@ +/* + * spreadspace avr utils + * + * + * Copyright (C) 2013-2015 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 "usbio.h" + +void handle_cmd(uint8_t cmd) +{ + switch(cmd) { + case '0': led_off(); break; + case '1': led_on(); break; + case 't': led_toggle(); break; + case 'r': reset2bootloader(); break; + default: printf("error\r\n"); return; + } + printf("ok\r\n"); +} + +int main(void) +{ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + cpu_init(); + led_init(); + usbio_init(); + sei(); + + for(;;) { + int16_t BytesReceived = usbio_bytes_received(); + while(BytesReceived > 0) { + int ReceivedByte = fgetc(stdin); + if(ReceivedByte != EOF) { + handle_cmd(ReceivedByte); + } + BytesReceived--; + } + + usbio_task(); + } +} |