From 5726c1622a1dc4d12d9a71d90e3dce167dba5e27 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Mon, 28 Nov 2011 21:23:38 -0800 Subject: [PATCH 1/8] Fixed bug in scanner display, thanks to David Bath. Also upgraded to latest Jam toolchain and moved pins over to the new GettingStarted defaults. --- examples/scanner/Jamfile | 368 ++++++++++++++++++----------------- examples/scanner/scanner.pde | 10 +- 2 files changed, 191 insertions(+), 187 deletions(-) diff --git a/examples/scanner/Jamfile b/examples/scanner/Jamfile index 901f8da..1bf541e 100644 --- a/examples/scanner/Jamfile +++ b/examples/scanner/Jamfile @@ -1,206 +1,210 @@ -PROJECT_NAME = $(PWD:B) ; -PROJECT_DIR = . ; -PROJECT_LIBS = SPI RF24 ; +# (1) Project Information -OUT_DIR = ojam ; -F_CPU = 16000000 ; -MCU = atmega328p ; -PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; +PROJECT_LIBS = SPI RF24 ; -UPLOAD_RATE = 57600 ; -AVRDUDE_PROTOCOL = stk500v1 ; -COM = 33 ; +# (2) Board Information + +UPLOAD_PROTOCOL ?= stk500v1 ; +UPLOAD_SPEED ?= 57600 ; +MCU ?= atmega328p ; +F_CPU ?= 16000000 ; +CORE ?= arduino ; +VARIANT ?= standard ; +ARDUINO_VERSION ?= 100 ; + +# (3) USB Ports + +PORTS = p4 p6 p9 u0 u1 u2 ; +PORT_p6 = /dev/tty.usbserial-A600eHIs ; +PORT_p4 = /dev/tty.usbserial-A40081RP ; +PORT_p9 = /dev/tty.usbserial-A9007LmI ; +PORT_u0 = /dev/ttyUSB0 ; +PORT_u1 = /dev/ttyUSB1 ; +PORT_u2 = /dev/ttyUSB2 ; + +# (4) Location of AVR tools +# +# This configuration assumes using avr-tools that were obtained separate from the Arduino +# distribution. -# Host-specific overrides for locations if $(OS) = MACOSX { -ARDUINO_VERSION = 22 ; -OLD_DIR = /opt/arduino-0021 ; -AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; -AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; -ARDUINO_DIR = /opt/Arduino ; -ARDUINO_AVR = /usr/lib/avr/include ; + AVR_BIN = /usr/local/avrtools/bin ; + AVR_ETC = /usr/local/avrtools/etc ; + AVR_INCLUDE = /usr/local/avrtools/include ; +} +else +{ + AVR_BIN = /usr/bin ; + AVR_INCLUDE = /usr/lib/avr/include ; + AVR_ETC = /etc ; } -# Where is everything? -ARDUINO_VERSION ?= 22 ; -AVR_TOOLS_PATH ?= /usr/bin ; -ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; -ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; -AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; -ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; +# (5) Directories where Arduino core and libraries are located + +ARDUINO_DIR ?= /opt/Arduino ; +ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; -AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; -AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; -AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; -DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -CTUNING = -ffunction-sections -fdata-sections ; -CXXTUNING = -fno-exceptions -fno-strict-aliasing ; -CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; -CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; -LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; +# +# -------------------------------------------------- +# Below this line usually never needs to be modified +# + +# Tool locations + +CC = $(AVR_BIN)/avr-gcc ; +C++ = $(AVR_BIN)/avr-g++ ; +LINK = $(AVR_BIN)/avr-gcc ; +OBJCOPY = $(AVR_BIN)/avr-objcopy ; +AVRDUDE = $(AVR_BIN)/avrdude ; + +# Flags + +DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; +OPTIM = -Os ; +CCFLAGS = -Wall -Wextra -mmcu=$(MCU) -ffunction-sections -fdata-sections ; +C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; +LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; +AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; # Search everywhere for headers -HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; + +HDRS = $(PWD) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; + +# Output locations + +LOCATE_TARGET = $(F_CPU) ; +LOCATE_SOURCE = $(F_CPU) ; + +# +# Custom rules +# + +rule GitVersion +{ + Always $(<) ; + Depends all : $(<) ; +} + +actions GitVersion +{ + echo "const char program_version[] = \"\\" > $(<) + git log -1 --pretty=format:%h >> $(<) + echo "\";" >> $(<) +} + +GitVersion version.h ; + +rule Pde +{ + Depends $(<) : $(>) ; + MakeLocate $(<) : $(LOCATE_SOURCE) ; + Clean clean : $(<) ; +} + +if ( $(ARDUINO_VERSION) < 100 ) +{ + ARDUINO_H = WProgram.h ; +} +else +{ + ARDUINO_H = Arduino.h ; +} + +actions Pde +{ + echo "#include <$(ARDUINO_H)>" > $(<) + echo "#line 1 \"$(>)\"" >> $(<) + cat $(>) >> $(<) +} + +rule C++Pde +{ + local _CPP = $(>:B).cpp ; + Pde $(_CPP) : $(>) ; + C++ $(<) : $(_CPP) ; +} + +rule UserObject +{ + switch $(>:S) + { + case .ino : C++Pde $(<) : $(>) ; + case .pde : C++Pde $(<) : $(>) ; + } +} + +rule Objects +{ + local _i ; + + for _i in [ FGristFiles $(<) ] + { + local _b = $(_i:B)$(SUFOBJ) ; + local _o = $(_b:G=$(SOURCE_GRIST:E)) ; + Object $(_o) : $(_i) ; + Depends obj : $(_o) ; + } +} + +rule Main +{ + MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; + Objects $(>) ; +} + +rule Hex +{ + Depends $(<) : $(>) ; + MakeLocate $(<) : $(LOCATE_TARGET) ; + Depends hex : $(<) ; + Clean clean : $(<) ; +} + +actions Hex +{ + $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) +} + +rule Upload +{ + Depends $(1) : $(2) ; + Depends $(2) : $(3) ; + NotFile $(1) ; + Always $(1) ; + Always $(2) ; + UploadAction $(2) : $(3) ; +} + +actions UploadAction +{ + $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i +} + +# +# Targets +# # Grab everything from the core directory CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; # Grab everything from libraries. To avoid this "grab everything" behaviour, you # can specify specific modules to pick up in PROJECT_MODULES -LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; +LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; -# In addition to explicitly-specified program modules, pick up anything from the current -# dir. -PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; +# Grab everything from the current dir +PROJECT_MODULES += [ GLOB $(PWD) : *.c *.cpp *.pde *.ino ] ; -# Shortcut for the out files -OUT = $(OUT_DIR)/$(PROJECT_NAME) ; +# Main output executable +MAIN = $(PWD:B).elf ; -# AvrDude setup -AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; +Main $(MAIN) : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; +Hex $(MAIN:B).hex : $(MAIN) ; -rule GitVersion +# Upload targets +for _p in $(PORTS) { - Always $(<) ; - Depends all : $(<) ; + Upload $(_p) : $(PORT_$(_p)) : $(MAIN:B).hex ; } - -actions GitVersion -{ - echo "const char program_version[] = \"\\" > $(<) - git log -1 --pretty=format:%h >> $(<) - echo "\";" >> $(<) -} - -GitVersion version.h ; - -rule AvrCc -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrCc -{ - $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) -} - -rule AvrC++ -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrC++ -{ - $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) -} - -rule Pde -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - -} - -actions Pde -{ - echo "#include " > $(<) - echo "#line 1 \"$(>)\"" >> $(<) - cat $(>) >> $(<) -} - -rule AvrPde -{ - local _CPP = $(OUT_DIR)/$(_I:B).cpp ; - Pde $(_CPP) : $(>) ; - AvrC++ $(<) : $(_CPP) ; -} - -rule AvrObject -{ - switch $(>:S) - { - case .c : AvrCc $(<) : $(>) ; - case .cpp : AvrC++ $(<) : $(>) ; - case .pde : AvrPde $(<) : $(>) ; - } -} - -rule AvrObjects -{ - for _I in $(<) - { - AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; - } -} - -rule AvrMainFromObjects -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - MkDir $(<:D) ; - Depends all : $(<) ; - Clean clean : $(<) ; -} - -actions AvrMainFromObjects -{ - $(AVR_LD) $(LDFLAGS) -o $(<) $(>) -} - -rule AvrMain -{ - AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; - AvrObjects $(>) ; -} - -rule AvrHex -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Depends hex : $(<) ; - Clean clean : $(<) ; -} - -actions AvrHex -{ - $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) -} - -rule AvrUpload -{ - Depends $(1) : $(2) ; - Depends $(2) : $(3) ; - NotFile $(1) ; - Always $(1) ; - Always $(2) ; - AvrUploadAction $(2) : $(3) ; -} - -actions AvrUploadAction -{ - $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i -} - -AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; -AvrHex $(OUT).hex : $(OUT).elf ; - -AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; -AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; -AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; - diff --git a/examples/scanner/scanner.pde b/examples/scanner/scanner.pde index f8beaf9..6e74286 100644 --- a/examples/scanner/scanner.pde +++ b/examples/scanner/scanner.pde @@ -29,14 +29,14 @@ // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 -RF24 radio(8,9); +RF24 radio(9,10); // // Channel info // -const short num_channels = 128; -short values[num_channels]; +const uint8_t num_channels = 128; +uint8_t values[num_channels]; // // Setup @@ -84,12 +84,12 @@ void setup(void) // Loop // -const short num_reps = 100; +const int num_reps = 100; void loop(void) { // Clear measurement values - memset(values,0,num_channels); + memset(values,0,sizeof(values)); // Scan all channels num_reps times int rep_counter = num_reps; From 9f806a5b00ee2809a530b2695661431970267db9 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Mon, 28 Nov 2011 21:24:37 -0800 Subject: [PATCH 2/8] Move default pins over to Getting Started defaults --- examples/led_remote/led_remote.pde | 2 +- examples/pingpair/pingpair.pde | 2 +- examples/pingpair_dyn/pingpair_dyn.pde | 2 +- examples/pingpair_irq/pingpair_irq.pde | 2 +- examples/pingpair_pl/pingpair_pl.pde | 2 +- examples/pingpair_sleepy/pingpair_sleepy.pde | 2 +- examples/starping/starping.pde | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/led_remote/led_remote.pde b/examples/led_remote/led_remote.pde index 45f971d..02f89f5 100644 --- a/examples/led_remote/led_remote.pde +++ b/examples/led_remote/led_remote.pde @@ -36,7 +36,7 @@ // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 -RF24 radio(8,9); +RF24 radio(9,10); // sets the role of this unit in hardware. Connect to GND to be the 'led' board receiver // Leave open to be the 'remote' transmitter diff --git a/examples/pingpair/pingpair.pde b/examples/pingpair/pingpair.pde index 2bf2267..3cedd66 100644 --- a/examples/pingpair/pingpair.pde +++ b/examples/pingpair/pingpair.pde @@ -26,7 +26,7 @@ // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 -RF24 radio(8,9); +RF24 radio(9,10); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver // Leave open to be the 'ping' transmitter diff --git a/examples/pingpair_dyn/pingpair_dyn.pde b/examples/pingpair_dyn/pingpair_dyn.pde index 5d3be9e..cea56ee 100644 --- a/examples/pingpair_dyn/pingpair_dyn.pde +++ b/examples/pingpair_dyn/pingpair_dyn.pde @@ -23,7 +23,7 @@ // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 -RF24 radio(8,9); +RF24 radio(9,10); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver // Leave open to be the 'ping' transmitter diff --git a/examples/pingpair_irq/pingpair_irq.pde b/examples/pingpair_irq/pingpair_irq.pde index bf565cb..2c4f583 100644 --- a/examples/pingpair_irq/pingpair_irq.pde +++ b/examples/pingpair_irq/pingpair_irq.pde @@ -24,7 +24,7 @@ // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 -RF24 radio(8,9); +RF24 radio(9,10); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver // Leave open to be the 'ping' transmitter diff --git a/examples/pingpair_pl/pingpair_pl.pde b/examples/pingpair_pl/pingpair_pl.pde index 8980293..94a0da5 100644 --- a/examples/pingpair_pl/pingpair_pl.pde +++ b/examples/pingpair_pl/pingpair_pl.pde @@ -26,7 +26,7 @@ // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 -RF24 radio(8,9); +RF24 radio(9,10); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver // Leave open to be the 'ping' transmitter diff --git a/examples/pingpair_sleepy/pingpair_sleepy.pde b/examples/pingpair_sleepy/pingpair_sleepy.pde index dea0d3c..809679e 100644 --- a/examples/pingpair_sleepy/pingpair_sleepy.pde +++ b/examples/pingpair_sleepy/pingpair_sleepy.pde @@ -33,7 +33,7 @@ // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 -RF24 radio(8,9); +RF24 radio(9,10); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver // Leave open to be the 'ping' transmitter diff --git a/examples/starping/starping.pde b/examples/starping/starping.pde index ac5197a..97b0953 100644 --- a/examples/starping/starping.pde +++ b/examples/starping/starping.pde @@ -33,7 +33,7 @@ // Set up nRF24L01 radio on SPI bus plus pins 8 & 9 -RF24 radio(8,9); +RF24 radio(9,10); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver // Leave open to be the 'pong' receiver. From f3934084a1368a2e1683ce9b7739a4099edf8c69 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Sat, 10 Dec 2011 00:42:23 -0800 Subject: [PATCH 3/8] Changes to work on Maple --- RF24.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 98e0c42..c6edc1a 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -24,13 +24,19 @@ #endif // Avoid spurious warnings -#ifndef NATIVE +#if ! defined( NATIVE ) && defined( ARDUINO ) #undef PROGMEM #define PROGMEM __attribute__(( section(".progmem.data") )) #undef PSTR #define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];})) #endif +#ifdef ARDUINO +#define PRIPSTR "%S" +#else +#define PRIPSTR "%s" +#endif + /****************************************************************************/ void RF24::csn(int mode) @@ -39,9 +45,11 @@ void RF24::csn(int mode) // If we assume 2Mbs data rate and 16Mhz clock, a // divider of 4 is the minimum we want. // CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz +#ifdef ARDUINO SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); SPI.setClockDivider(SPI_CLOCK_DIV4); +#endif digitalWrite(csn_pin,mode); } @@ -102,7 +110,7 @@ uint8_t RF24::write_register(uint8_t reg, uint8_t value) { uint8_t status; - IF_SERIAL_DEBUG(printf_P(PSTR("write_register(%02x,%02x)\n\r"),reg,value)); + IF_SERIAL_DEBUG(printf_P(PSTR("write_register(%02x,%02x)\r\n"),reg,value)); csn(LOW); status = SPI.transfer( W_REGISTER | ( REGISTER_MASK & reg ) ); @@ -202,7 +210,7 @@ uint8_t RF24::get_status(void) void RF24::print_status(uint8_t status) { - printf_P(PSTR("STATUS\t\t = 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\n\r"), + printf_P(PSTR("STATUS\t\t = 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\r\n"), status, (status & _BV(RX_DR))?1:0, (status & _BV(TX_DS))?1:0, @@ -216,7 +224,7 @@ void RF24::print_status(uint8_t status) void RF24::print_observe_tx(uint8_t value) { - printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\n\r"), + printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\r\n"), value, (value >> PLOS_CNT) & B1111, (value >> ARC_CNT) & B1111 @@ -228,10 +236,10 @@ void RF24::print_observe_tx(uint8_t value) void RF24::print_byte_register(prog_char* name, uint8_t reg, uint8_t qty) { char extra_tab = strlen_P(name) < 8 ? '\t' : 0; - printf_P(PSTR("%S\t%c ="),name,extra_tab); + printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab); while (qty--) printf_P(PSTR(" 0x%02x"),read_register(reg++)); - printf_P(PSTR("\n\r")); + printf_P(PSTR("\r\n")); } /****************************************************************************/ @@ -239,7 +247,7 @@ void RF24::print_byte_register(prog_char* name, uint8_t reg, uint8_t qty) void RF24::print_address_register(prog_char* name, uint8_t reg, uint8_t qty) { char extra_tab = strlen_P(name) < 8 ? '\t' : 0; - printf_P(PSTR("%S\t%c ="),name,extra_tab); + printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab); while (qty--) { @@ -252,7 +260,7 @@ void RF24::print_address_register(prog_char* name, uint8_t reg, uint8_t qty) printf_P(PSTR("%02x"),*bufptr); } - printf_P(PSTR("\n\r")); + printf_P(PSTR("\r\n")); } /****************************************************************************/ @@ -313,10 +321,10 @@ void RF24::printDetails(void) const char * rf24_crclength_e_str[] = { "Disabled", "8 bits", "16 bits" } ; const char * rf24_pa_dbm_e_str[] = { "PA_MIN", "PA_LOW", "LA_MED", "PA_HIGH"} ; - printf_P(PSTR("Data Rate\t = %s\n\r"),rf24_datarate_e_str[getDataRate()]); - printf_P(PSTR("Model\t\t = %s\n\r"),rf24_model_e_str[isPVariant()]); - printf_P(PSTR("CRC Length\t = %s\n\r"),rf24_crclength_e_str[getCRCLength()]); - printf_P(PSTR("PA Power\t = %s\n\r"),rf24_pa_dbm_e_str[getPALevel()]); + printf_P(PSTR("Data Rate\t = %s\r\n"),rf24_datarate_e_str[getDataRate()]); + printf_P(PSTR("Model\t\t = %s\r\n"),rf24_model_e_str[isPVariant()]); + printf_P(PSTR("CRC Length\t = %s\r\n"),rf24_crclength_e_str[getCRCLength()]); + printf_P(PSTR("PA Power\t = %s\r\n"),rf24_pa_dbm_e_str[getPALevel()]); } /****************************************************************************/ @@ -470,7 +478,7 @@ bool RF24::write( const void* buf, uint8_t len ) bool tx_ok, tx_fail; whatHappened(tx_ok,tx_fail,ack_payload_available); - //printf("%u%u%u\n\r",tx_ok,tx_fail,ack_payload_available); + //printf("%u%u%u\r\n",tx_ok,tx_fail,ack_payload_available); result = tx_ok; IF_SERIAL_DEBUG(Serial.print(result?"...OK.":"...Failed")); @@ -670,7 +678,7 @@ void RF24::enableDynamicPayloads(void) write_register(FEATURE,read_register(FEATURE) | _BV(EN_DPL) ); } - IF_SERIAL_DEBUG(printf("FEATURE=%i\n\r",read_register(FEATURE))); + IF_SERIAL_DEBUG(printf("FEATURE=%i\r\n",read_register(FEATURE))); // Enable dynamic payload on all pipes // @@ -699,7 +707,7 @@ void RF24::enableAckPayload(void) write_register(FEATURE,read_register(FEATURE) | _BV(EN_ACK_PAY) | _BV(EN_DPL) ); } - IF_SERIAL_DEBUG(printf("FEATURE=%i\n\r",read_register(FEATURE))); + IF_SERIAL_DEBUG(printf("FEATURE=%i\r\n",read_register(FEATURE))); // // Enable dynamic payload on pipes 0 & 1 From 53cb579400a76db6583ee973332c6c6d17a7f7d5 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Sat, 10 Dec 2011 15:52:33 -0800 Subject: [PATCH 4/8] Moved environment-specific checking out to RF24_config.h --- RF24.cpp | 28 +---------------------- RF24.h | 3 +-- RF24_config.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 RF24_config.h diff --git a/RF24.cpp b/RF24.cpp index c6edc1a..574910b 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -6,37 +6,11 @@ version 2 as published by the Free Software Foundation. */ -#if ARDUINO < 100 -#include -#else -#include -#endif - #include #include "nRF24L01.h" +#include "RF24_config.h" #include "RF24.h" -#undef SERIAL_DEBUG -#ifdef SERIAL_DEBUG -#define IF_SERIAL_DEBUG(x) ({x;}) -#else -#define IF_SERIAL_DEBUG(x) -#endif - -// Avoid spurious warnings -#if ! defined( NATIVE ) && defined( ARDUINO ) -#undef PROGMEM -#define PROGMEM __attribute__(( section(".progmem.data") )) -#undef PSTR -#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];})) -#endif - -#ifdef ARDUINO -#define PRIPSTR "%S" -#else -#define PRIPSTR "%s" -#endif - /****************************************************************************/ void RF24::csn(int mode) diff --git a/RF24.h b/RF24.h index 9af5844..7d041ce 100644 --- a/RF24.h +++ b/RF24.h @@ -9,8 +9,7 @@ #ifndef __RF24_H__ #define __RF24_H__ -#include -#include +#include typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ; typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e; diff --git a/RF24_config.h b/RF24_config.h new file mode 100644 index 0000000..321a0fd --- /dev/null +++ b/RF24_config.h @@ -0,0 +1,61 @@ + +/* + Copyright (C) 2011 James Coliz, Jr. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + */ + +#ifndef __RF24_CONFIG_H__ +#define __RF24_CONFIG_H__ + +#if ARDUINO < 100 +#include +#else +#include +#endif + +#include + +// Stuff that is normally provided by Arduino +#ifndef ARDUINO +#include +#include +#include +extern HardwareSPI SPI; +#define _BV(x) (1<<(x)) +#endif + +#undef SERIAL_DEBUG +#ifdef SERIAL_DEBUG +#define IF_SERIAL_DEBUG(x) ({x;}) +#else +#define IF_SERIAL_DEBUG(x) +#endif + +// Avoid spurious warnings +#if ! defined( NATIVE ) && defined( ARDUINO ) +#undef PROGMEM +#define PROGMEM __attribute__(( section(".progmem.data") )) +#undef PSTR +#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];})) +#endif + +// Progmem is Arduino-specific +#ifdef ARDUINO +#include +#define PRIPSTR "%S" +#else +typedef char const prog_char; +typedef uint16_t prog_uint16_t; +#define PSTR(x) (x) +#define printf_P printf +#define strlen_P strlen +#define PROGMEM +#define pgm_read_word(p) (*(p)) +#define PRIPSTR "%s" +#endif + +#endif // __RF24_CONFIG_H__ +// vim:ai:cin:sts=2 sw=2 ft=cpp From a6bf911f5a99253c7b718d4c119f5a65d4f59d59 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Sat, 10 Dec 2011 15:54:11 -0800 Subject: [PATCH 5/8] Added example for Maple --- examples/pingpair_maple/Jamfile | 182 ++++++++++++++++ examples/pingpair_maple/main.cpp | 87 ++++++++ examples/pingpair_maple/pingpair_maple.pde | 240 +++++++++++++++++++++ 3 files changed, 509 insertions(+) create mode 100644 examples/pingpair_maple/Jamfile create mode 100644 examples/pingpair_maple/main.cpp create mode 100644 examples/pingpair_maple/pingpair_maple.pde diff --git a/examples/pingpair_maple/Jamfile b/examples/pingpair_maple/Jamfile new file mode 100644 index 0000000..798096c --- /dev/null +++ b/examples/pingpair_maple/Jamfile @@ -0,0 +1,182 @@ +MCU = cortex-m3 ; +CHIP = STM32F103ZE ; +BOARD = maple_native ; + +#CHIP = at91sam3u4 ; +#BOARD = sam3u-ek ; + +if ! $(TOOLSET) +{ + TOOLSET = devkit ; + Echo "Assuming TOOLSET=devkit" ; +} + +if $(TOOLSET) = yagarto +{ + TOOLS_PATH = ~/Source/yagarto-4.6.2/bin ; + TOOLS_ARCH = arm-none-eabi- ; +} +if $(TOOLSET) = yagarto-install +{ + TOOLS_PATH = ~/Source/yagarto/install/bin ; + TOOLS_ARCH = arm-none-eabi- ; +} +else if $(TOOLSET) = devkit +{ + TOOLS_PATH = /opt/devkitARM/bin ; + TOOLS_ARCH = arm-eabi- ; +} +else if $(TOOLSET) = maple +{ + TOOLS_PATH = /opt/Maple/Resources/Java/hardware/tools/arm/bin ; + TOOLS_ARCH = arm-none-eabi- ; +} +else if $(TOOLSET) = ports +{ + TOOLS_PATH = /opt/local/bin ; + TOOLS_ARCH = arm-none-eabi- ; +} + +CC = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc ; +C++ = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ; +AS = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc -c ; +LINK = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ; +OBJCOPY = $(TOOLS_PATH)/$(TOOLS_ARCH)objcopy ; +DFU = dfu-util ; + +DEFINES += VECT_TAB_FLASH BOARD_$(BOARD) MCU_$(CHIP) ERROR_LED_PORT=GPIOC ERROR_LED_PIN=15 STM32_HIGH_DENSITY MAPLE_IDE ; +OPTIM = -Os ; +MFLAGS = cpu=$(MCU) thumb arch=armv7-m ; +CCFLAGS = -Wall -m$(MFLAGS) -g -nostdlib -ffunction-sections -fdata-sections -Wl,--gc-sections ; +C++FLAGS = $(CCFLAGS) -fno-rtti -fno-exceptions ; +LINKFLAGS += -m$(MFLAGS) -Xlinker --gc-sections ; +DFUFLAGS = -a1 -d 0x1eaf:0x0003 -R ; + +MAPLE_DIR = $(HOME)/Source/SAM3U/libmaple ; +MAPLE_LIBS = Servo LiquidCrystal Wire FreeRTOS ; +MAPLE_SUBDIRS = wirish wirish/comm wirish/boards libmaple libmaple/usb libmaple/usb/usb_lib ; + +SKETCH_DIR = $(HOME)/Source/Arduino ; +SKETCH_LIBS = RF24 ; + +MODULE_DIRS = . $(MAPLE_DIR)/$(MAPLE_SUBDIRS) $(MAPLE_DIR)/libraries/$(MAPLE_LIBS) $(SKETCH_DIR)/libraries/$(SKETCH_LIBS) ; +HDRS = $(MODULE_DIRS) ; +LOCATE_TARGET = out/$(TOOLSET) ; +LOCATE_SOURCE = $(LOCATE_TARGET) ; + +rule Pde +{ + Depends $(<) : $(>) ; + MakeLocate $(<) : $(LOCATE_SOURCE) ; + Clean clean : $(<) ; +} + +if ( $(ARDUINO_VERSION) < 100 ) +{ + ARDUINO_H = WProgram.h ; +} +else +{ + ARDUINO_H = Arduino.h ; +} + +actions Pde +{ + echo "#include <$(ARDUINO_H)>" > $(<) + echo "#line 1 \"$(>)\"" >> $(<) + cat $(>) >> $(<) +} + +rule C++Pde +{ + local _CPP = $(>:B).cpp ; + Pde $(_CPP) : $(>) ; + C++ $(<) : $(_CPP) ; +} + +rule Hex +{ + Depends $(<) : $(>) ; + MakeLocate $(<) : $(LOCATE_TARGET) ; + Depends hex : $(<) ; + Clean clean : $(<) ; +} + +actions Hex +{ + $(OBJCOPY) -O ihex $(>) $(<) +} + +rule Binary +{ + Depends $(<) : $(>) ; + MakeLocate $(<) : $(LOCATE_TARGET) ; + Depends binary : $(<) ; + Clean clean : $(<) ; +} + +actions Binary +{ + $(OBJCOPY) -O binary $(>) $(<) +} + +rule UserObject +{ + switch $(>:S) + { + case .S : As $(<) : $(>) ; + case .ino : C++Pde $(<) : $(>) ; + case .pde : C++Pde $(<) : $(>) ; + } +} + +rule Upload +{ + Depends up : $(<) ; + NotFile up ; + Always $(<) ; + Always up ; +} + +actions Upload +{ + $(DFU) $(DFUFLAGS) -D $(<) +} + +# Override base objects rule, so all output can go in the output dir +rule Objects +{ + local _i ; + + for _i in [ FGristFiles $(<) ] + { + local _b = $(_i:B)$(SUFOBJ) ; + local _o = $(_b:G=$(SOURCE_GRIST:E)) ; + Object $(_o) : $(_i) ; + Depends obj : $(_o) ; + } +} + +# Override base main rule, so all output can go in the output dir +rule Main +{ + MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; + Objects $(>) ; +} + +# Modules +MODULES = [ GLOB $(MODULE_DIRS) : *.pde *.c *.cpp *.S ] ; + +# Main output executable +MAIN = $(PWD:B).elf ; + +# Linker script +LINK_DIR = $(MAPLE_DIR)/support/ld ; +LINKSCRIPT = $(LINK_DIR)/$(BOARD)/flash.ld ; + +# Bring in the map and link script +LINKFLAGS += -Wl,-Map=$(LOCATE_TARGET)/$(MAIN:B).map -T$(LINKSCRIPT) -L$(LINK_DIR) ; + +Main $(MAIN) : $(MODULES) ; +Binary $(MAIN:B).bin : $(MAIN) ; +Upload $(MAIN:B).bin ; diff --git a/examples/pingpair_maple/main.cpp b/examples/pingpair_maple/main.cpp new file mode 100644 index 0000000..b4f976d --- /dev/null +++ b/examples/pingpair_maple/main.cpp @@ -0,0 +1,87 @@ +#ifdef MAPLE_IDE + +#include +#include "wirish.h" + +extern void setup(void); +extern void loop(void); + +void board_start(const char* program_name) +{ + // Set up the LED to steady on + pinMode(BOARD_LED_PIN, OUTPUT); + digitalWrite(BOARD_LED_PIN, HIGH); + + // Setup the button as input + pinMode(BOARD_BUTTON_PIN, INPUT); + digitalWrite(BOARD_BUTTON_PIN, HIGH); + + SerialUSB.begin(); + SerialUSB.println("Press BUT"); + + // Wait for button press + while ( !isButtonPressed() ) + { + } + + SerialUSB.println("Welcome!"); + SerialUSB.println(program_name); + + int i = 11; + while (i--) + { + toggleLED(); + delay(50); + } +} + +/** + * Custom version of _write, which will print to the USB. + * In order to use it you MUST ADD __attribute__((weak)) + * to _write in libmaple/syscalls.c +*/ +extern "C" int _write (int file, char * ptr, int len) +{ + if ( (file != 1) && (file != 2) ) + return 0; + else + SerialUSB.write(ptr,len); + return len; +} + +/** + * Re-entrant version of _write. Yagarto and Devkit now use + * the re-entrant newlib, so these get called instead of the + * non_r versions. + */ +extern "C" int _write_r (void*, int file, char * ptr, int len) +{ + return _write( file, ptr, len); +} + +__attribute__((constructor)) __attribute__ ((weak)) void premain() +{ + init(); +} + +__attribute__((weak)) void setup(void) +{ + board_start("No program defined"); +} + +__attribute__((weak)) void loop(void) +{ +} + +__attribute__((weak)) int main(void) +{ + setup(); + + while (true) + { + loop(); + } + return 0; +} +#endif // ifdef MAPLE_IDE +// vim:cin:ai:sts=2 sw=2 ft=cpp diff --git a/examples/pingpair_maple/pingpair_maple.pde b/examples/pingpair_maple/pingpair_maple.pde new file mode 100644 index 0000000..a992570 --- /dev/null +++ b/examples/pingpair_maple/pingpair_maple.pde @@ -0,0 +1,240 @@ +/* + Copyright (C) 2011 James Coliz, Jr. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + */ + +/** + * Example RF Radio Ping Pair ... for Maple + * + * This is an example of how to use the RF24 class. Write this sketch to two different nodes, + * connect the role_pin to ground on one. The ping node sends the current time to the pong node, + * which responds by sending the value back. The ping node can then see how long the whole cycle + * took. + */ + +#include "WProgram.h" +#include +#include "nRF24L01.h" +#include "RF24.h" + +// +// Maple specific setup. Other than this section, the sketch is the same on Maple as on +// Arduino +// + +#ifdef MAPLE_IDE + +// External startup function +extern void board_start(const char* program_name); + +// Use SPI #2. +HardwareSPI SPI(2); + +#else +#define board_startup printf +#define toggleLED(x) (x) +#endif + +// +// Hardware configuration +// + +// Set up nRF24L01 radio on SPI bus plus pins 8 & 9 + +RF24 radio(7,6); + +// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver +// Leave open to be the 'ping' transmitter +const int role_pin = 7; + +// +// Topology +// + +// Radio pipe addresses for the 2 nodes to communicate. +const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; + +// +// Role management +// +// Set up role. This sketch uses the same software for all the nodes +// in this system. Doing so greatly simplifies testing. The hardware itself specifies +// which node it is. +// +// This is done through the role_pin +// + +// The various roles supported by this sketch +typedef enum { role_ping_out = 1, role_pong_back } role_e; + +// The debug-friendly names of those roles +const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; + +// The role of the current running sketch +role_e role; + +void setup(void) +{ + // + // Role + // + + // set up the role pin + pinMode(role_pin, INPUT); + digitalWrite(role_pin,HIGH); + delay(20); // Just to get a solid reading on the role pin + + // read the address pin, establish our role + if ( digitalRead(role_pin) ) + role = role_ping_out; + else + role = role_pong_back; + + // + // Print preamble + // + + board_start("\n\rRF24/examples/pingpair/\n\r"); + printf("ROLE: %s\n\r",role_friendly_name[role]); + + // + // Setup and configure rf radio + // + + radio.begin(); + + // optionally, increase the delay between retries & # of retries + radio.setRetries(15,15); + + // optionally, reduce the payload size. seems to + // improve reliability + radio.setPayloadSize(8); + + // + // Open pipes to other nodes for communication + // + + // This simple sketch opens two pipes for these two nodes to communicate + // back and forth. + // Open 'our' pipe for writing + // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) + + if ( role == role_ping_out ) + { + radio.openWritingPipe(pipes[0]); + radio.openReadingPipe(1,pipes[1]); + } + else + { + radio.openWritingPipe(pipes[1]); + radio.openReadingPipe(1,pipes[0]); + } + + // + // Start listening + // + + radio.startListening(); + + // + // Dump the configuration of the rf unit for debugging + // + + radio.printDetails(); +} + +void loop(void) +{ + // + // Ping out role. Repeatedly send the current time + // + + if (role == role_ping_out) + { + toggleLED(); + + // First, stop listening so we can talk. + radio.stopListening(); + + // Take the time, and send it. This will block until complete + unsigned long time = millis(); + printf("Now sending %lu...",time); + bool ok = radio.write( &time, sizeof(unsigned long) ); + + if (ok) + printf("ok...\r\n"); + else + printf("failed.\r\n"); + + // Now, continue listening + radio.startListening(); + + // Wait here until we get a response, or timeout (250ms) + unsigned long started_waiting_at = millis(); + bool timeout = false; + while ( ! radio.available() && ! timeout ) + if (millis() - started_waiting_at > 200 ) + timeout = true; + + // Describe the results + if ( timeout ) + { + printf("Failed, response timed out.\r\n"); + } + else + { + // Grab the response, compare, and send to debugging spew + unsigned long got_time; + radio.read( &got_time, sizeof(unsigned long) ); + + // Spew it + printf("Got response %lu, round-trip delay: %lu\r\n",got_time,millis()-got_time); + } + + toggleLED(); + + // Try again 1s later + delay(1000); + } + + // + // Pong back role. Receive each packet, dump it out, and send it back + // + + if ( role == role_pong_back ) + { + // if there is data ready + if ( radio.available() ) + { + // Dump the payloads until we've gotten everything + unsigned long got_time; + bool done = false; + while (!done) + { + // Fetch the payload, and see if this was the last one. + done = radio.read( &got_time, sizeof(unsigned long) ); + + // Spew it + printf("Got payload %lu...",got_time); + + // Delay just a little bit to let the other unit + // make the transition to receiver + delay(20); + } + + // First, stop listening so we can talk + radio.stopListening(); + + // Send the final one back. + radio.write( &got_time, sizeof(unsigned long) ); + printf("Sent response.\r\n"); + + // Now, resume listening so we catch the next packets. + radio.startListening(); + } + } +} +// vim:cin:ai:sts=2 sw=2 ft=cpp From 840ad1cd3dc5ce1d23c0d070ef14343cd4ddaf40 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Wed, 14 Dec 2011 18:35:08 -0800 Subject: [PATCH 6/8] Clean up pin assignments --- examples/pingpair_maple/pingpair_maple.pde | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/pingpair_maple/pingpair_maple.pde b/examples/pingpair_maple/pingpair_maple.pde index a992570..24f5621 100644 --- a/examples/pingpair_maple/pingpair_maple.pde +++ b/examples/pingpair_maple/pingpair_maple.pde @@ -42,13 +42,15 @@ HardwareSPI SPI(2); // Hardware configuration // -// Set up nRF24L01 radio on SPI bus plus pins 8 & 9 +// Set up nRF24L01 radio on SPI bus plus pins 7 & 6 +// (This works for the Getting Started board plugged into the +// Maple Native backwards.) RF24 radio(7,6); // sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver // Leave open to be the 'ping' transmitter -const int role_pin = 7; +const int role_pin = 10; // // Topology From 19fa3954c0d452f43ef9b8e4b8afca47d8b98a41 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Sun, 18 Dec 2011 10:54:47 -0800 Subject: [PATCH 7/8] Added new jamfile to this example --- examples/GettingStarted/Jamfile | 379 ++++++++++++++++---------------- 1 file changed, 185 insertions(+), 194 deletions(-) diff --git a/examples/GettingStarted/Jamfile b/examples/GettingStarted/Jamfile index 9e113df..6a2499a 100644 --- a/examples/GettingStarted/Jamfile +++ b/examples/GettingStarted/Jamfile @@ -1,219 +1,210 @@ -PROJECT_NAME = $(PWD:B) ; -PROJECT_DIR = . ; -PROJECT_LIBS = SPI RF24 ; +# (1) Project Information +PROJECT_LIBS = SPI RF24 ; + +# (2) Board Information + +UPLOAD_PROTOCOL ?= stk500v1 ; +UPLOAD_SPEED ?= 57600 ; +MCU ?= atmega328p ; F_CPU ?= 16000000 ; -MCU = atmega328p ; -PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; -OUT_DIR = $(F_CPU) ; +CORE ?= arduino ; +VARIANT ?= standard ; +ARDUINO_VERSION ?= 100 ; -UPLOAD_RATE = 57600 ; -AVRDUDE_PROTOCOL = stk500v1 ; -COM = 33 ; +# (3) USB Ports + +PORTS = p4 p6 p9 u0 u1 u2 ; +PORT_p6 = /dev/tty.usbserial-A600eHIs ; +PORT_p4 = /dev/tty.usbserial-A40081RP ; +PORT_p9 = /dev/tty.usbserial-A9007LmI ; +PORT_u0 = /dev/ttyUSB0 ; +PORT_u1 = /dev/ttyUSB1 ; +PORT_u2 = /dev/ttyUSB2 ; + +# (4) Location of AVR tools +# +# This configuration assumes using avr-tools that were obtained separate from the Arduino +# distribution. -# Host-specific overrides for locations if $(OS) = MACOSX { -ARDUINO_VERSION = 100 ; -OLD_DIR = /opt/arduino-0021 ; -AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; -AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; -ARDUINO_DIR = /opt/Arduino ; -ARDUINO_AVR = /usr/lib/avr/include ; + AVR_BIN = /usr/local/avrtools/bin ; + AVR_ETC = /usr/local/avrtools/etc ; + AVR_INCLUDE = /usr/local/avrtools/include ; +} +else +{ + AVR_BIN = /usr/bin ; + AVR_INCLUDE = /usr/lib/avr/include ; + AVR_ETC = /etc ; } -# Where is everything? -ARDUINO_VERSION ?= 100 ; -AVR_TOOLS_PATH ?= /usr/bin ; -ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; -ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; -AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; -ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino $(ARDUINO_DIR)/hardware/arduino/variants/standard ; +# (5) Directories where Arduino core and libraries are located + +ARDUINO_DIR ?= /opt/Arduino ; +ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; -AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; -AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; -AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; -DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -CTUNING = -ffunction-sections -fdata-sections ; -CXXTUNING = -fno-exceptions -fno-strict-aliasing ; -CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; -CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; -LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; +# +# -------------------------------------------------- +# Below this line usually never needs to be modified +# + +# Tool locations + +CC = $(AVR_BIN)/avr-gcc ; +C++ = $(AVR_BIN)/avr-g++ ; +LINK = $(AVR_BIN)/avr-gcc ; +OBJCOPY = $(AVR_BIN)/avr-objcopy ; +AVRDUDE = $(AVR_BIN)/avrdude ; + +# Flags + +DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; +OPTIM = -Os ; +CCFLAGS = -Wall -Wextra -mmcu=$(MCU) -ffunction-sections -fdata-sections ; +C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; +LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; +AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; # Search everywhere for headers -HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; + +HDRS = $(PWD) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; + +# Output locations + +LOCATE_TARGET = $(F_CPU) ; +LOCATE_SOURCE = $(F_CPU) ; + +# +# Custom rules +# + +rule GitVersion +{ + Always $(<) ; + Depends all : $(<) ; +} + +actions GitVersion +{ + echo "const char program_version[] = \"\\" > $(<) + git log -1 --pretty=format:%h >> $(<) + echo "\";" >> $(<) +} + +GitVersion version.h ; + +rule Pde +{ + Depends $(<) : $(>) ; + MakeLocate $(<) : $(LOCATE_SOURCE) ; + Clean clean : $(<) ; +} + +if ( $(ARDUINO_VERSION) < 100 ) +{ + ARDUINO_H = WProgram.h ; +} +else +{ + ARDUINO_H = Arduino.h ; +} + +actions Pde +{ + echo "#include <$(ARDUINO_H)>" > $(<) + echo "#line 1 \"$(>)\"" >> $(<) + cat $(>) >> $(<) +} + +rule C++Pde +{ + local _CPP = $(>:B).cpp ; + Pde $(_CPP) : $(>) ; + C++ $(<) : $(_CPP) ; +} + +rule UserObject +{ + switch $(>:S) + { + case .ino : C++Pde $(<) : $(>) ; + case .pde : C++Pde $(<) : $(>) ; + } +} + +rule Objects +{ + local _i ; + + for _i in [ FGristFiles $(<) ] + { + local _b = $(_i:B)$(SUFOBJ) ; + local _o = $(_b:G=$(SOURCE_GRIST:E)) ; + Object $(_o) : $(_i) ; + Depends obj : $(_o) ; + } +} + +rule Main +{ + MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; + Objects $(>) ; +} + +rule Hex +{ + Depends $(<) : $(>) ; + MakeLocate $(<) : $(LOCATE_TARGET) ; + Depends hex : $(<) ; + Clean clean : $(<) ; +} + +actions Hex +{ + $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) +} + +rule Upload +{ + Depends $(1) : $(2) ; + Depends $(2) : $(3) ; + NotFile $(1) ; + Always $(1) ; + Always $(2) ; + UploadAction $(2) : $(3) ; +} + +actions UploadAction +{ + $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i +} + +# +# Targets +# # Grab everything from the core directory CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; # Grab everything from libraries. To avoid this "grab everything" behaviour, you # can specify specific modules to pick up in PROJECT_MODULES -LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; +LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; -# In addition to explicitly-specified program modules, pick up anything from the current -# dir. -PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; +# Grab everything from the current dir +PROJECT_MODULES += [ GLOB $(PWD) : *.c *.cpp *.pde *.ino ] ; -# Shortcut for the out files -OUT = $(OUT_DIR)/$(PROJECT_NAME) ; +# Main output executable +MAIN = $(PWD:B).elf ; -# AvrDude setup -AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; +Main $(MAIN) : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; +Hex $(MAIN:B).hex : $(MAIN) ; -rule GitVersion +# Upload targets +for _p in $(PORTS) { - Always $(<) ; - Depends all : $(<) ; + Upload $(_p) : $(PORT_$(_p)) : $(MAIN:B).hex ; } - -actions GitVersion -{ - echo "const char program_version[] = \"\\" > $(<) - git log -1 --pretty=format:%h >> $(<) - echo "\";" >> $(<) -} - -GitVersion version.h ; - -rule AvrCc -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrCc -{ - $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) -} - -rule AvrC++ -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrC++ -{ - $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) -} - -rule Pde -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - -} - -if ( $(ARDUINO_VERSION) < 100 ) -{ - actions Pde - { - echo "#include " > $(<) - echo "#line 1 \"$(>)\"" >> $(<) - cat $(>) >> $(<) - } -} -else -{ - actions Pde - { - echo "#include " > $(<) - echo "#line 1 \"$(>)\"" >> $(<) - cat $(>) >> $(<) - } -} - -rule AvrPde -{ - local _CPP = $(OUT_DIR)/$(_I:B).cpp ; - Pde $(_CPP) : $(>) ; - AvrC++ $(<) : $(_CPP) ; -} - -rule AvrObject -{ - switch $(>:S) - { - case .c : AvrCc $(<) : $(>) ; - case .cpp : AvrC++ $(<) : $(>) ; - case .pde : AvrPde $(<) : $(>) ; - case .ino : AvrPde $(<) : $(>) ; - } -} - -rule AvrObjects -{ - for _I in $(<) - { - AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; - } -} - -rule AvrMainFromObjects -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - MkDir $(<:D) ; - Depends all : $(<) ; - Clean clean : $(<) ; -} - -actions AvrMainFromObjects -{ - $(AVR_LD) $(LDFLAGS) -o $(<) $(>) -} - -rule AvrMain -{ - AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; - AvrObjects $(>) ; -} - -rule AvrHex -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Depends hex : $(<) ; - Clean clean : $(<) ; -} - -actions AvrHex -{ - $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) -} - -rule AvrUpload -{ - Depends $(1) : $(2) ; - Depends $(2) : $(3) ; - NotFile $(1) ; - Always $(1) ; - Always $(2) ; - AvrUploadAction $(2) : $(3) ; -} - -actions AvrUploadAction -{ - $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i -} - -AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; -AvrHex $(OUT).hex : $(OUT).elf ; - -AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; -AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; -AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; - From 26ea4583cdebbc219b5f4460096044d911874e9d Mon Sep 17 00:00:00 2001 From: maniacbug Date: Sun, 18 Dec 2011 10:56:12 -0800 Subject: [PATCH 8/8] Added #error to printf for examples that require Arduino --- examples/GettingStarted/printf.h | 8 +- examples/led_remote/printf.h | 8 +- examples/pingpair/Jamfile | 368 +++++++++++++++--------------- examples/pingpair/pingpair.pde | 2 +- examples/pingpair/printf.h | 8 +- examples/pingpair_dyn/printf.h | 8 +- examples/pingpair_irq/printf.h | 8 +- examples/pingpair_pl/printf.h | 8 +- examples/pingpair_sleepy/printf.h | 8 +- examples/starping/printf.h | 8 +- 10 files changed, 243 insertions(+), 191 deletions(-) diff --git a/examples/GettingStarted/printf.h b/examples/GettingStarted/printf.h index 1b853db..b2efd56 100644 --- a/examples/GettingStarted/printf.h +++ b/examples/GettingStarted/printf.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2011 James Coliz, Jr. + Copyright (C) 2011 J. Coliz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -16,6 +16,8 @@ #ifndef __PRINTF_H__ #define __PRINTF_H__ +#ifdef ARDUINO + int serial_putc( char c, FILE * ) { Serial.write( c ); @@ -28,4 +30,8 @@ void printf_begin(void) fdevopen( &serial_putc, 0 ); } +#else +#error This example is only for use on Arduino. +#endif // ARDUINO + #endif // __PRINTF_H__ diff --git a/examples/led_remote/printf.h b/examples/led_remote/printf.h index 1b853db..b2efd56 100644 --- a/examples/led_remote/printf.h +++ b/examples/led_remote/printf.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2011 James Coliz, Jr. + Copyright (C) 2011 J. Coliz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -16,6 +16,8 @@ #ifndef __PRINTF_H__ #define __PRINTF_H__ +#ifdef ARDUINO + int serial_putc( char c, FILE * ) { Serial.write( c ); @@ -28,4 +30,8 @@ void printf_begin(void) fdevopen( &serial_putc, 0 ); } +#else +#error This example is only for use on Arduino. +#endif // ARDUINO + #endif // __PRINTF_H__ diff --git a/examples/pingpair/Jamfile b/examples/pingpair/Jamfile index 901f8da..7f24589 100644 --- a/examples/pingpair/Jamfile +++ b/examples/pingpair/Jamfile @@ -1,206 +1,210 @@ -PROJECT_NAME = $(PWD:B) ; -PROJECT_DIR = . ; -PROJECT_LIBS = SPI RF24 ; +# (1) Project Information -OUT_DIR = ojam ; -F_CPU = 16000000 ; -MCU = atmega328p ; -PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ; +PROJECT_LIBS = SPI RF24 ; -UPLOAD_RATE = 57600 ; -AVRDUDE_PROTOCOL = stk500v1 ; -COM = 33 ; +# (2) Board Information + +UPLOAD_PROTOCOL ?= stk500v1 ; +UPLOAD_SPEED ?= 115200 ;; +MCU = atmega328p ; +F_CPU ?= 16000000 ; +CORE ?= arduino ; +VARIANT ?= standard ; +ARDUINO_VERSION ?= 100 ; + +# (3) USB Ports + +PORTS = p4 p6 p9 u0 u1 u2 ; +PORT_p6 = /dev/tty.usbserial-A600eHIs ; +PORT_p4 = /dev/tty.usbserial-A40081RP ; +PORT_p9 = /dev/tty.usbserial-A9007LmI ; +PORT_u0 = /dev/ttyUSB0 ; +PORT_u1 = /dev/ttyUSB1 ; +PORT_u2 = /dev/ttyUSB2 ; + +# (4) Location of AVR tools +# +# This configuration assumes using avr-tools that were obtained separate from the Arduino +# distribution. -# Host-specific overrides for locations if $(OS) = MACOSX { -ARDUINO_VERSION = 22 ; -OLD_DIR = /opt/arduino-0021 ; -AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ; -AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ; -ARDUINO_DIR = /opt/Arduino ; -ARDUINO_AVR = /usr/lib/avr/include ; + AVR_BIN = /usr/local/avrtools/bin ; + AVR_ETC = /usr/local/avrtools/etc ; + AVR_INCLUDE = /usr/local/avrtools/include ; +} +else +{ + AVR_BIN = /usr/bin ; + AVR_INCLUDE = /usr/lib/avr/include ; + AVR_ETC = /etc ; } -# Where is everything? -ARDUINO_VERSION ?= 22 ; -AVR_TOOLS_PATH ?= /usr/bin ; -ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ; -ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ; -AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ; -ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ; +# (5) Directories where Arduino core and libraries are located + +ARDUINO_DIR ?= /opt/Arduino ; +ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ; ARDUINO_LIB = $(ARDUINO_DIR)/libraries ; SKETCH_LIB = $(HOME)/Source/Arduino/libraries ; -AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ; -AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ; -AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ; -AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ; -DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; -CTUNING = -ffunction-sections -fdata-sections ; -CXXTUNING = -fno-exceptions -fno-strict-aliasing ; -CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ; -CXXFLAGS = $(CFLAGS) $(CXXTUNING) ; -LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ; +# +# -------------------------------------------------- +# Below this line usually never needs to be modified +# + +# Tool locations + +CC = $(AVR_BIN)/avr-gcc ; +C++ = $(AVR_BIN)/avr-g++ ; +LINK = $(AVR_BIN)/avr-gcc ; +OBJCOPY = $(AVR_BIN)/avr-objcopy ; +AVRDUDE = $(AVR_BIN)/avrdude ; + +# Flags + +DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ; +OPTIM = -Os ; +CCFLAGS = -Wall -Wextra -mmcu=$(MCU) -ffunction-sections -fdata-sections ; +C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ; +LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ; +AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ; # Search everywhere for headers -HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ; + +HDRS = $(PWD) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ; + +# Output locations + +LOCATE_TARGET = $(F_CPU) ; +LOCATE_SOURCE = $(F_CPU) ; + +# +# Custom rules +# + +rule GitVersion +{ + Always $(<) ; + Depends all : $(<) ; +} + +actions GitVersion +{ + echo "const char program_version[] = \"\\" > $(<) + git log -1 --pretty=format:%h >> $(<) + echo "\";" >> $(<) +} + +GitVersion version.h ; + +rule Pde +{ + Depends $(<) : $(>) ; + MakeLocate $(<) : $(LOCATE_SOURCE) ; + Clean clean : $(<) ; +} + +if ( $(ARDUINO_VERSION) < 100 ) +{ + ARDUINO_H = WProgram.h ; +} +else +{ + ARDUINO_H = Arduino.h ; +} + +actions Pde +{ + echo "#include <$(ARDUINO_H)>" > $(<) + echo "#line 1 \"$(>)\"" >> $(<) + cat $(>) >> $(<) +} + +rule C++Pde +{ + local _CPP = $(>:B).cpp ; + Pde $(_CPP) : $(>) ; + C++ $(<) : $(_CPP) ; +} + +rule UserObject +{ + switch $(>:S) + { + case .ino : C++Pde $(<) : $(>) ; + case .pde : C++Pde $(<) : $(>) ; + } +} + +rule Objects +{ + local _i ; + + for _i in [ FGristFiles $(<) ] + { + local _b = $(_i:B)$(SUFOBJ) ; + local _o = $(_b:G=$(SOURCE_GRIST:E)) ; + Object $(_o) : $(_i) ; + Depends obj : $(_o) ; + } +} + +rule Main +{ + MainFromObjects $(<) : $(>:B)$(SUFOBJ) ; + Objects $(>) ; +} + +rule Hex +{ + Depends $(<) : $(>) ; + MakeLocate $(<) : $(LOCATE_TARGET) ; + Depends hex : $(<) ; + Clean clean : $(<) ; +} + +actions Hex +{ + $(OBJCOPY) -O ihex -R .eeprom $(>) $(<) +} + +rule Upload +{ + Depends $(1) : $(2) ; + Depends $(2) : $(3) ; + NotFile $(1) ; + Always $(1) ; + Always $(2) ; + UploadAction $(2) : $(3) ; +} + +actions UploadAction +{ + $(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i +} + +# +# Targets +# # Grab everything from the core directory CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ; # Grab everything from libraries. To avoid this "grab everything" behaviour, you # can specify specific modules to pick up in PROJECT_MODULES -LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ; +LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ; -# In addition to explicitly-specified program modules, pick up anything from the current -# dir. -PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ; +# Grab everything from the current dir +PROJECT_MODULES += [ GLOB $(PWD) : *.c *.cpp *.pde *.ino ] ; -# Shortcut for the out files -OUT = $(OUT_DIR)/$(PROJECT_NAME) ; +# Main output executable +MAIN = $(PWD:B).elf ; -# AvrDude setup -AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ; +Main $(MAIN) : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; +Hex $(MAIN:B).hex : $(MAIN) ; -rule GitVersion +# Upload targets +for _p in $(PORTS) { - Always $(<) ; - Depends all : $(<) ; + Upload $(_p) : $(PORT_$(_p)) : $(MAIN:B).hex ; } - -actions GitVersion -{ - echo "const char program_version[] = \"\\" > $(<) - git log -1 --pretty=format:%h >> $(<) - echo "\";" >> $(<) -} - -GitVersion version.h ; - -rule AvrCc -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrCc -{ - $(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>) -} - -rule AvrC++ -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - - CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ; - CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; -} - -actions AvrC++ -{ - $(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>) -} - -rule Pde -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Clean clean : $(<) ; - -} - -actions Pde -{ - echo "#include " > $(<) - echo "#line 1 \"$(>)\"" >> $(<) - cat $(>) >> $(<) -} - -rule AvrPde -{ - local _CPP = $(OUT_DIR)/$(_I:B).cpp ; - Pde $(_CPP) : $(>) ; - AvrC++ $(<) : $(_CPP) ; -} - -rule AvrObject -{ - switch $(>:S) - { - case .c : AvrCc $(<) : $(>) ; - case .cpp : AvrC++ $(<) : $(>) ; - case .pde : AvrPde $(<) : $(>) ; - } -} - -rule AvrObjects -{ - for _I in $(<) - { - AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ; - } -} - -rule AvrMainFromObjects -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - MkDir $(<:D) ; - Depends all : $(<) ; - Clean clean : $(<) ; -} - -actions AvrMainFromObjects -{ - $(AVR_LD) $(LDFLAGS) -o $(<) $(>) -} - -rule AvrMain -{ - AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ; - AvrObjects $(>) ; -} - -rule AvrHex -{ - Depends $(<) : $(>) ; - Depends $(<) : $(<:D) ; - Depends hex : $(<) ; - Clean clean : $(<) ; -} - -actions AvrHex -{ - $(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<) -} - -rule AvrUpload -{ - Depends $(1) : $(2) ; - Depends $(2) : $(3) ; - NotFile $(1) ; - Always $(1) ; - Always $(2) ; - AvrUploadAction $(2) : $(3) ; -} - -actions AvrUploadAction -{ - $(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i -} - -AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ; -AvrHex $(OUT).hex : $(OUT).elf ; - -AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ; -AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ; -AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ; - diff --git a/examples/pingpair/pingpair.pde b/examples/pingpair/pingpair.pde index 3cedd66..5f64005 100644 --- a/examples/pingpair/pingpair.pde +++ b/examples/pingpair/pingpair.pde @@ -70,7 +70,7 @@ void setup(void) delay(20); // Just to get a solid reading on the role pin // read the address pin, establish our role - if ( digitalRead(role_pin) ) + if ( ! digitalRead(role_pin) ) role = role_ping_out; else role = role_pong_back; diff --git a/examples/pingpair/printf.h b/examples/pingpair/printf.h index 1b853db..b2efd56 100644 --- a/examples/pingpair/printf.h +++ b/examples/pingpair/printf.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2011 James Coliz, Jr. + Copyright (C) 2011 J. Coliz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -16,6 +16,8 @@ #ifndef __PRINTF_H__ #define __PRINTF_H__ +#ifdef ARDUINO + int serial_putc( char c, FILE * ) { Serial.write( c ); @@ -28,4 +30,8 @@ void printf_begin(void) fdevopen( &serial_putc, 0 ); } +#else +#error This example is only for use on Arduino. +#endif // ARDUINO + #endif // __PRINTF_H__ diff --git a/examples/pingpair_dyn/printf.h b/examples/pingpair_dyn/printf.h index 1b853db..b2efd56 100644 --- a/examples/pingpair_dyn/printf.h +++ b/examples/pingpair_dyn/printf.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2011 James Coliz, Jr. + Copyright (C) 2011 J. Coliz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -16,6 +16,8 @@ #ifndef __PRINTF_H__ #define __PRINTF_H__ +#ifdef ARDUINO + int serial_putc( char c, FILE * ) { Serial.write( c ); @@ -28,4 +30,8 @@ void printf_begin(void) fdevopen( &serial_putc, 0 ); } +#else +#error This example is only for use on Arduino. +#endif // ARDUINO + #endif // __PRINTF_H__ diff --git a/examples/pingpair_irq/printf.h b/examples/pingpair_irq/printf.h index 1b853db..b2efd56 100644 --- a/examples/pingpair_irq/printf.h +++ b/examples/pingpair_irq/printf.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2011 James Coliz, Jr. + Copyright (C) 2011 J. Coliz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -16,6 +16,8 @@ #ifndef __PRINTF_H__ #define __PRINTF_H__ +#ifdef ARDUINO + int serial_putc( char c, FILE * ) { Serial.write( c ); @@ -28,4 +30,8 @@ void printf_begin(void) fdevopen( &serial_putc, 0 ); } +#else +#error This example is only for use on Arduino. +#endif // ARDUINO + #endif // __PRINTF_H__ diff --git a/examples/pingpair_pl/printf.h b/examples/pingpair_pl/printf.h index 1b853db..b2efd56 100644 --- a/examples/pingpair_pl/printf.h +++ b/examples/pingpair_pl/printf.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2011 James Coliz, Jr. + Copyright (C) 2011 J. Coliz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -16,6 +16,8 @@ #ifndef __PRINTF_H__ #define __PRINTF_H__ +#ifdef ARDUINO + int serial_putc( char c, FILE * ) { Serial.write( c ); @@ -28,4 +30,8 @@ void printf_begin(void) fdevopen( &serial_putc, 0 ); } +#else +#error This example is only for use on Arduino. +#endif // ARDUINO + #endif // __PRINTF_H__ diff --git a/examples/pingpair_sleepy/printf.h b/examples/pingpair_sleepy/printf.h index 1b853db..b2efd56 100644 --- a/examples/pingpair_sleepy/printf.h +++ b/examples/pingpair_sleepy/printf.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2011 James Coliz, Jr. + Copyright (C) 2011 J. Coliz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -16,6 +16,8 @@ #ifndef __PRINTF_H__ #define __PRINTF_H__ +#ifdef ARDUINO + int serial_putc( char c, FILE * ) { Serial.write( c ); @@ -28,4 +30,8 @@ void printf_begin(void) fdevopen( &serial_putc, 0 ); } +#else +#error This example is only for use on Arduino. +#endif // ARDUINO + #endif // __PRINTF_H__ diff --git a/examples/starping/printf.h b/examples/starping/printf.h index 1b853db..b2efd56 100644 --- a/examples/starping/printf.h +++ b/examples/starping/printf.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2011 James Coliz, Jr. + Copyright (C) 2011 J. Coliz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -16,6 +16,8 @@ #ifndef __PRINTF_H__ #define __PRINTF_H__ +#ifdef ARDUINO + int serial_putc( char c, FILE * ) { Serial.write( c ); @@ -28,4 +30,8 @@ void printf_begin(void) fdevopen( &serial_putc, 0 ); } +#else +#error This example is only for use on Arduino. +#endif // ARDUINO + #endif // __PRINTF_H__