mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-07 01:54:26 +01:00
Checked in latest from pure-data.sourceforge.net CVS, which includes the
beginnings of ripping the guts out of the firmware to create a Firmata library.
This commit is contained in:
parent
d3d63dd1b0
commit
413b439974
260
firmwares/Standard_Firmata/Makefile
Normal file
260
firmwares/Standard_Firmata/Makefile
Normal file
@ -0,0 +1,260 @@
|
|||||||
|
# Arduino makefile
|
||||||
|
#
|
||||||
|
# This makefile allows you to build sketches from the command line
|
||||||
|
# without the Arduino environment (or Java).
|
||||||
|
#
|
||||||
|
# The Arduino environment does preliminary processing on a sketch before
|
||||||
|
# compiling it. If you're using this makefile instead, you'll need to do
|
||||||
|
# a few things differently:
|
||||||
|
#
|
||||||
|
# - Give your program's file a .cpp extension (e.g. foo.cpp).
|
||||||
|
#
|
||||||
|
# - Put this line at top of your code: #include <WProgram.h>
|
||||||
|
#
|
||||||
|
# - Write prototypes for all your functions (or define them before you
|
||||||
|
# call them). A prototype declares the types of parameters a
|
||||||
|
# function will take and what type of value it will return. This
|
||||||
|
# means that you can have a call to a function before the definition
|
||||||
|
# of the function. A function prototype looks like the first line of
|
||||||
|
# the function, with a semi-colon at the end. For example:
|
||||||
|
# int digitalRead(int pin);
|
||||||
|
#
|
||||||
|
# Instructions for using the makefile:
|
||||||
|
#
|
||||||
|
# 1. Copy this file into the folder with your sketch.
|
||||||
|
#
|
||||||
|
# 2. Below, modify the line containing "TARGET" to refer to the name of
|
||||||
|
# of your program's file without an extension (e.g. TARGET = foo).
|
||||||
|
#
|
||||||
|
# 3. Modify the line containg "ARDUINO" to point the directory that
|
||||||
|
# contains the Arduino core (for normal Arduino installations, this
|
||||||
|
# is the lib/targets/arduino sub-directory).
|
||||||
|
#
|
||||||
|
# 4. Modify the line containing "PORT" to refer to the filename
|
||||||
|
# representing the USB or serial connection to your Arduino board
|
||||||
|
# (e.g. PORT = /dev/tty.USB0). If the exact name of this file
|
||||||
|
# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*).
|
||||||
|
#
|
||||||
|
# 5. At the command line, change to the directory containing your
|
||||||
|
# program's file and the makefile.
|
||||||
|
#
|
||||||
|
# 6. Type "make" and press enter to compile/verify your program.
|
||||||
|
#
|
||||||
|
# 7. Type "make upload", reset your Arduino board, and press enter to
|
||||||
|
# upload your program to the Arduino board.
|
||||||
|
#
|
||||||
|
# $Id: Makefile,v 1.7 2007/04/13 05:28:23 eighthave Exp $
|
||||||
|
|
||||||
|
PORT = /dev/tty.usbserial-*
|
||||||
|
TARGET = Pd_firmware
|
||||||
|
ARDUINO = /Applications/arduino-0007
|
||||||
|
ARDUINO_SRC = $(ARDUINO)/lib/targets/arduino
|
||||||
|
ARDUINO_LIB_SRC = $(ARDUINO)/lib/targets/libraries
|
||||||
|
INCLUDE = -I$(ARDUINO_SRC) -I$(ARDUINO)/tools/avr/avr/include \
|
||||||
|
-I$(ARDUINO)/lib/targets/libraries/EEPROM \
|
||||||
|
-I$(ARDUINO)/lib/targets/libraries/Firmata \
|
||||||
|
-I$(ARDUINO)/lib/targets/libraries
|
||||||
|
SRC = $(ARDUINO_SRC)/pins_arduino.c $(ARDUINO_SRC)/wiring.c \
|
||||||
|
$(ARDUINO_SRC)/WInterrupts.c
|
||||||
|
CXXSRC = applet/$(TARGET).cpp $(ARDUINO_SRC)/HardwareSerial.cpp \
|
||||||
|
$(ARDUINO_LIB_SRC)/EEPROM/EEPROM.cpp \
|
||||||
|
$(ARDUINO_LIB_SRC)/Firmata/Firmata.cpp \
|
||||||
|
$(ARDUINO_SRC)/WRandom.cpp
|
||||||
|
MCU = atmega8
|
||||||
|
F_CPU = 16000000
|
||||||
|
FORMAT = ihex
|
||||||
|
UPLOAD_RATE = 19200
|
||||||
|
|
||||||
|
# Name of this Makefile (used for "make depend").
|
||||||
|
MAKEFILE = Makefile
|
||||||
|
|
||||||
|
# Debugging format.
|
||||||
|
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
|
||||||
|
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
|
||||||
|
DEBUG = stabs
|
||||||
|
|
||||||
|
OPT = s
|
||||||
|
|
||||||
|
# Place -D or -U options here
|
||||||
|
CDEFS = -DF_CPU=$(F_CPU)
|
||||||
|
CXXDEFS = -DF_CPU=$(F_CPU)
|
||||||
|
|
||||||
|
# Compiler flag to set the C Standard level.
|
||||||
|
# c89 - "ANSI" C
|
||||||
|
# gnu89 - c89 plus GCC extensions
|
||||||
|
# c99 - ISO C99 standard (not yet fully implemented)
|
||||||
|
# gnu99 - c99 plus GCC extensions
|
||||||
|
CSTANDARD = -std=gnu99
|
||||||
|
CDEBUG = -g$(DEBUG)
|
||||||
|
CWARN = -Wall -Wstrict-prototypes
|
||||||
|
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
|
||||||
|
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
|
||||||
|
|
||||||
|
CFLAGS = $(CDEBUG) $(CDEFS) $(INCLUDE) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
|
||||||
|
CXXFLAGS = $(CDEFS) $(INCLUDE) -O$(OPT)
|
||||||
|
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
|
||||||
|
LDFLAGS =
|
||||||
|
|
||||||
|
|
||||||
|
# Programming support using avrdude. Settings and variables.
|
||||||
|
AVRDUDE_PROGRAMMER = stk500
|
||||||
|
AVRDUDE_PORT = $(PORT)
|
||||||
|
AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex
|
||||||
|
AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
|
||||||
|
-b $(UPLOAD_RATE) -q -V
|
||||||
|
|
||||||
|
# Program settings
|
||||||
|
CC = avr-gcc
|
||||||
|
CXX = avr-g++
|
||||||
|
OBJCOPY = avr-objcopy
|
||||||
|
OBJDUMP = avr-objdump
|
||||||
|
SIZE = avr-size
|
||||||
|
NM = avr-nm
|
||||||
|
AVRDUDE = avrdude
|
||||||
|
REMOVE = rm -f
|
||||||
|
MV = mv -f
|
||||||
|
|
||||||
|
# Define all object files.
|
||||||
|
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
|
||||||
|
|
||||||
|
# Define all listing files.
|
||||||
|
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
|
||||||
|
|
||||||
|
# Combine all necessary flags and optional flags.
|
||||||
|
# Add target processor to flags.
|
||||||
|
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
|
||||||
|
ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
|
||||||
|
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
# Default target.
|
||||||
|
all: build
|
||||||
|
echo 'close;' | /Applications/Pd-0.39.2-extended-RC1.app/Contents/Resources/bin/pdsend 34567 || true
|
||||||
|
say "press the button"
|
||||||
|
make upload
|
||||||
|
|
||||||
|
build: applet_files elf hex
|
||||||
|
|
||||||
|
applet_files:
|
||||||
|
test -d applet || mkdir applet
|
||||||
|
echo '#include "WProgram.h"' > applet/$(TARGET).cpp
|
||||||
|
echo '#include "avr/interrupt.h"' >> applet/$(TARGET).cpp
|
||||||
|
sed -n 's|^\(void .*)\).*|\1;|p' Pd_firmware.pde | grep -v 'setup()' | \
|
||||||
|
grep -v 'loop()' >> applet/$(TARGET).cpp
|
||||||
|
cat $(TARGET).pde >> applet/$(TARGET).cpp
|
||||||
|
|
||||||
|
elf: applet/$(TARGET).elf
|
||||||
|
hex: applet/$(TARGET).hex
|
||||||
|
eep: applet/$(TARGET).eep
|
||||||
|
lss: applet/$(TARGET).lss
|
||||||
|
sym: applet/$(TARGET).sym
|
||||||
|
|
||||||
|
# Program the device.
|
||||||
|
upload: applet/$(TARGET).hex
|
||||||
|
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
|
||||||
|
COFFCONVERT=$(OBJCOPY) --debugging \
|
||||||
|
--change-section-address .data-0x800000 \
|
||||||
|
--change-section-address .bss-0x800000 \
|
||||||
|
--change-section-address .noinit-0x800000 \
|
||||||
|
--change-section-address .eeprom-0x810000
|
||||||
|
|
||||||
|
|
||||||
|
coff: applet/$(TARGET).elf
|
||||||
|
$(COFFCONVERT) -O coff-avr applet/$(TARGET).elf applet/$(TARGET).cof
|
||||||
|
|
||||||
|
|
||||||
|
extcoff: applet/$(TARGET).elf
|
||||||
|
$(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf applet/$(TARGET).cof
|
||||||
|
|
||||||
|
|
||||||
|
.SUFFIXES: .elf .hex .eep .lss .sym
|
||||||
|
|
||||||
|
.elf.hex:
|
||||||
|
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
|
||||||
|
|
||||||
|
.elf.eep:
|
||||||
|
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
||||||
|
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
|
||||||
|
|
||||||
|
# Create extended listing file from ELF output file.
|
||||||
|
.elf.lss:
|
||||||
|
$(OBJDUMP) -h -S $< > $@
|
||||||
|
|
||||||
|
# Create a symbol table from ELF output file.
|
||||||
|
.elf.sym:
|
||||||
|
$(NM) -n $< > $@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Link: create ELF output file from object files.
|
||||||
|
applet/$(TARGET).elf: $(OBJ)
|
||||||
|
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
# Compile: create object files from C++ source files.
|
||||||
|
.cpp.o:
|
||||||
|
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
|
||||||
|
|
||||||
|
# Compile: create object files from C source files.
|
||||||
|
.c.o:
|
||||||
|
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Compile: create assembler files from C source files.
|
||||||
|
.c.s:
|
||||||
|
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Assemble: create object files from assembler source files.
|
||||||
|
.S.o:
|
||||||
|
$(CC) -c $(ALL_ASFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Target: clean project.
|
||||||
|
clean:
|
||||||
|
$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
|
||||||
|
$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss \
|
||||||
|
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
|
||||||
|
find $(ARDUINO)/lib/ -name '*.o' -delete
|
||||||
|
|
||||||
|
depend:
|
||||||
|
if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
|
||||||
|
then \
|
||||||
|
sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
|
||||||
|
$(MAKEFILE).$$$$ && \
|
||||||
|
$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
|
||||||
|
fi
|
||||||
|
echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
|
||||||
|
>> $(MAKEFILE); \
|
||||||
|
$(CC) -M -mmcu=$(MCU) $(CDEFS) $(INCLUDE) $(SRC) $(ASRC) >> $(MAKEFILE)
|
||||||
|
|
||||||
|
.PHONY: all build elf hex eep lss sym program coff extcoff clean depend
|
||||||
|
|
||||||
|
# for emacs
|
||||||
|
etags:
|
||||||
|
make etags_`uname -s`
|
||||||
|
etags *.pde \
|
||||||
|
$(ARDUINO_SRC)/*.[ch] \
|
||||||
|
$(ARDUINO_SRC)/*.cpp \
|
||||||
|
$(ARDUINO)/lib/targets/libraries/*/*.[ch] \
|
||||||
|
$(ARDUINO)/lib/targets/libraries/*/*.cpp \
|
||||||
|
$(ARDUINO)/tools/avr/avr/include/avr/*.[ch] \
|
||||||
|
$(ARDUINO)/tools/avr/avr/include/*.[ch]
|
||||||
|
|
||||||
|
etags_Darwin:
|
||||||
|
# etags -a
|
||||||
|
|
||||||
|
etags_Linux:
|
||||||
|
# etags -a /usr/include/*.h linux/input.h /usr/include/sys/*.h
|
||||||
|
|
||||||
|
etags_MINGW:
|
||||||
|
# etags -a /usr/include/*.h /usr/include/sys/*.h
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -39,6 +39,8 @@
|
|||||||
* @locations: STEIM, Amsterdam, Netherlands
|
* @locations: STEIM, Amsterdam, Netherlands
|
||||||
* IDMI/Polytechnic University, Brookyn, NY, USA
|
* IDMI/Polytechnic University, Brookyn, NY, USA
|
||||||
* Electrolobby Ars Electronica, Linz, Austria
|
* Electrolobby Ars Electronica, Linz, Austria
|
||||||
|
*
|
||||||
|
* See http://www.arduino.cc/playground/Interfacing/Firmata for docs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -50,156 +52,10 @@
|
|||||||
* TODO: use Program Control to load stored profiles from EEPROM
|
* TODO: use Program Control to load stored profiles from EEPROM
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* cvs version: $Id: Pd_firmware.pde,v 1.29 2007/03/08 05:37:22 eighthave Exp $ */
|
/* cvs version: $Id: Pd_firmware.pde,v 1.32 2007/06/27 20:59:24 eighthave Exp $ */
|
||||||
|
|
||||||
/*==============================================================================
|
#include <EEPROM.h>
|
||||||
* MESSAGE FORMATS
|
#include <Firmata.h>
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* MAPPING DATA TO MIDI
|
|
||||||
*
|
|
||||||
* This protocol uses the MIDI message format, but does not use the whole
|
|
||||||
* protocol. Most of the command mappings here will not be directly usable in
|
|
||||||
* terms of MIDI controllers and synths. It should co-exist with MIDI without
|
|
||||||
* trouble and can be parsed by standard MIDI interpreters. Just some of the
|
|
||||||
* message data is used differently.
|
|
||||||
*
|
|
||||||
* MIDI format: http://www.harmony-central.com/MIDI/Doc/table1.html
|
|
||||||
*
|
|
||||||
* MIDI
|
|
||||||
* type command channel first byte second byte
|
|
||||||
* -----------------------------------------------------------------------------
|
|
||||||
* analog I/O 0xE0 pin # LSB(bits 0-6) MSB(bits 7-13)
|
|
||||||
* digital I/O 0x90 port base LSB(bits 0-6) MSB(bits 7-13)
|
|
||||||
* report analog pin 0xC0 pin # disable/enable(0/1) - n/a -
|
|
||||||
* report digital ports 0xD0 port base disable/enable(0/1) - n/a -
|
|
||||||
*
|
|
||||||
* digital pin mode(I/O) 0xF4 - n/a - pin # (0-63) pin state(0=in)
|
|
||||||
* firmware version 0xF9 - n/a - minor version major version
|
|
||||||
* system reset 0xFF - n/a - - n/a - - n/a -
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* proposed extensions using SysEx
|
|
||||||
*
|
|
||||||
* type SysEx start command data bytes SysEx stop
|
|
||||||
* -----------------------------------------------------------------------------
|
|
||||||
* pulse I/O 0xF0 0xA0 five 7-bit chunks, LSB first 0xF7
|
|
||||||
* shiftOut 0xF0 0xF5 dataPin; clockPin; 7-bit LSB; 7-bit MSB 0xF7
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* DATA MESSAGE FORMAT */
|
|
||||||
|
|
||||||
/* two byte digital data format
|
|
||||||
* ----------------------------
|
|
||||||
* 0 digital data, 0x90-0x9F, (MIDI NoteOn, but different data usage)
|
|
||||||
* 1 digital pins 0-6 bitmask
|
|
||||||
* 2 digital pins 7-13 bitmask
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* analog 14-bit data format
|
|
||||||
* -------------------------
|
|
||||||
* 0 analog pin, 0xE0-0xEF, (MIDI Pitch Wheel)
|
|
||||||
* 1 analog least significant 7 bits
|
|
||||||
* 2 analog most significant 7 bits
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* version report format
|
|
||||||
* Send a single byte 0xF9, Arduino will reply with:
|
|
||||||
* -------------------------------------------------
|
|
||||||
* 0 version report header (0xF9) (MIDI Undefined)
|
|
||||||
* 1 minor version (0-127)
|
|
||||||
* 2 major version (0-127)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* pulseIn/Out (uses 32-bit value)
|
|
||||||
* -------------------------------
|
|
||||||
* 0 START_SYSEX (0xF0) (MIDI System Exclusive)
|
|
||||||
* 1 pulseIn/Out (0xA0-0xAF)
|
|
||||||
* 2 bits 0-6 (least significant byte)
|
|
||||||
* 3 bits 7-13
|
|
||||||
* 4 bits 14-20
|
|
||||||
* 5 bits 21-27
|
|
||||||
* 6 bits 28-34 (most significant byte)
|
|
||||||
* 7 END_SYSEX (0xF7) (MIDI End of SysEx - EOX)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* shiftIn/Out (uses 8-bit value)
|
|
||||||
* ------------------------------
|
|
||||||
* 0 START_SYSEX (0xF0)
|
|
||||||
* 1 shiftOut (0xF5)
|
|
||||||
* 2 dataPin (0-127)
|
|
||||||
* 3 clockPin (0-127)
|
|
||||||
* 4 bits 0-6 (least significant byte)
|
|
||||||
* 5 bit 7 (most significant bit)
|
|
||||||
* 6 END_SYSEX (0xF7)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* CONTROL MESSAGES */
|
|
||||||
|
|
||||||
/* set digital pin mode
|
|
||||||
* --------------------
|
|
||||||
* 1 set digital pin mode (0xF4) (MIDI Undefined)
|
|
||||||
* 2 pin number (0-127)
|
|
||||||
* 3 state (INPUT/OUTPUT, 0/1)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* toggle analogIn reporting by pin
|
|
||||||
* --------------------------------
|
|
||||||
* 0 toggle digitalIn reporting (0xC0-0xCF) (MIDI Program Change)
|
|
||||||
* 1 disable(0)/enable(non-zero)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* toggle digitalIn reporting by port pairs
|
|
||||||
* ----------------------------------------
|
|
||||||
* 0 toggle digitalIn reporting (0xD0-0xDF) (MIDI Aftertouch)
|
|
||||||
* 1 disable(0)/enable(non-zero)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* request version report
|
|
||||||
* ----------------------
|
|
||||||
* 0 request version report (0xF9) (MIDI Undefined)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* MACROS
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/* Version numbers for the protocol. The protocol is still changing, so these
|
|
||||||
* version numbers are important. This number can be queried so that host
|
|
||||||
* software can test whether it will be compatible with the currently
|
|
||||||
* installed firmware. */
|
|
||||||
#define FIRMATA_MAJOR_VERSION 1 // for non-compatible changes
|
|
||||||
#define FIRMATA_MINOR_VERSION 0 // for backwards compatible changes
|
|
||||||
|
|
||||||
/* total number of pins currently supported */
|
|
||||||
#define TOTAL_ANALOG_PINS 6
|
|
||||||
#define TOTAL_DIGITAL_PINS 14
|
|
||||||
|
|
||||||
// for comparing along with INPUT and OUTPUT
|
|
||||||
#define PWM 2
|
|
||||||
|
|
||||||
// for selecting digital inputs
|
|
||||||
#define PB 2 // digital input, pins 8-13
|
|
||||||
#define PC 3 // analog input port
|
|
||||||
#define PD 4 // digital input, pins 0-7
|
|
||||||
|
|
||||||
#define MAX_DATA_BYTES 2 // max number of data bytes in non-SysEx messages
|
|
||||||
/* message command bytes */
|
|
||||||
#define DIGITAL_MESSAGE 0x90 // send data for a digital pin
|
|
||||||
#define ANALOG_MESSAGE 0xE0 // send data for an analog pin (or PWM)
|
|
||||||
//#define PULSE_MESSAGE 0xA0 // proposed pulseIn/Out message (SysEx)
|
|
||||||
//#define SHIFTOUT_MESSAGE 0xB0 // proposed shiftOut message (SysEx)
|
|
||||||
#define REPORT_ANALOG_PIN 0xC0 // enable analog input by pin #
|
|
||||||
#define REPORT_DIGITAL_PORTS 0xD0 // enable digital input by port pair
|
|
||||||
#define START_SYSEX 0xF0 // start a MIDI SysEx message
|
|
||||||
#define SET_DIGITAL_PIN_MODE 0xF4 // set a digital pin to INPUT or OUTPUT
|
|
||||||
#define END_SYSEX 0xF7 // end a MIDI SysEx message
|
|
||||||
#define REPORT_VERSION 0xF9 // report firmware version
|
|
||||||
#define SYSTEM_RESET 0xFF // reset from MIDI
|
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
* GLOBAL VARIABLES
|
* GLOBAL VARIABLES
|
||||||
@ -211,16 +67,15 @@ byte executeMultiByteCommand = 0; // execute this after getting multi-byte data
|
|||||||
byte multiByteChannel = 0; // channel data for multiByteCommands
|
byte multiByteChannel = 0; // channel data for multiByteCommands
|
||||||
byte storedInputData[MAX_DATA_BYTES] = {0,0}; // multi-byte data
|
byte storedInputData[MAX_DATA_BYTES] = {0,0}; // multi-byte data
|
||||||
/* digital pins */
|
/* digital pins */
|
||||||
boolean digitalInputsEnabled = false; // output digital inputs or not
|
boolean reportDigitalInputs = false; // output digital inputs or not
|
||||||
int digitalInputs;
|
int digitalInputs;
|
||||||
int previousDigitalInputs; // previous output to test for change
|
int previousDigitalInputs; // previous output to test for change
|
||||||
int digitalPinStatus = 3; // bitwise array to store pin status, ignore RxTx pins
|
unsigned int digitalPinStatus = 65535; // store pin status, default OUTPUT
|
||||||
/* PWM/analog outputs */
|
/* PWM/analog outputs */
|
||||||
int pwmStatus = 0; // bitwise array to store PWM status
|
int pwmStatus = 0; // bitwise array to store PWM status
|
||||||
/* analog inputs */
|
/* analog inputs */
|
||||||
unsigned int analogPinsToReport = 0; // bitwise array to store pin reporting
|
int analogInputsToReport = 0; // bitwise array to store pin reporting
|
||||||
int analogPin = 0; // counter for reading analog pins
|
int analogPin = 0; // counter for reading analog pins
|
||||||
int analogData; // storage variable for data from analogRead()
|
|
||||||
/* timer variables */
|
/* timer variables */
|
||||||
extern volatile unsigned long timer0_overflow_count; // timer0 from wiring.c
|
extern volatile unsigned long timer0_overflow_count; // timer0 from wiring.c
|
||||||
unsigned long nextExecuteTime; // for comparison with timer0_overflow_count
|
unsigned long nextExecuteTime; // for comparison with timer0_overflow_count
|
||||||
@ -228,13 +83,6 @@ unsigned long nextExecuteTime; // for comparison with timer0_overflow_count
|
|||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
* FUNCTIONS
|
* FUNCTIONS
|
||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* output the version message to the serial port */
|
|
||||||
void printVersion() {
|
|
||||||
Serial.print(REPORT_VERSION, BYTE);
|
|
||||||
Serial.print(FIRMATA_MINOR_VERSION, BYTE);
|
|
||||||
Serial.print(FIRMATA_MAJOR_VERSION, BYTE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* output digital bytes received from the serial port */
|
* output digital bytes received from the serial port */
|
||||||
@ -257,16 +105,17 @@ void outputDigitalBytes(byte pin0_6, byte pin7_13) {
|
|||||||
* check all the active digital inputs for change of state, then add any events
|
* check all the active digital inputs for change of state, then add any events
|
||||||
* to the Serial output queue using Serial.print() */
|
* to the Serial output queue using Serial.print() */
|
||||||
void checkDigitalInputs(void) {
|
void checkDigitalInputs(void) {
|
||||||
if(digitalInputsEnabled) {
|
if(reportDigitalInputs) {
|
||||||
previousDigitalInputs = digitalInputs;
|
previousDigitalInputs = digitalInputs;
|
||||||
digitalInputs = PINB << 8; // get pins 8-13
|
digitalInputs = PINB << 8; // get pins 8-13
|
||||||
digitalInputs += PIND; // get pins 0-7
|
digitalInputs += PIND; // get pins 0-7
|
||||||
digitalInputs = digitalInputs &~ digitalPinStatus; // ignore pins set OUTPUT
|
digitalInputs = digitalInputs &~ digitalPinStatus; // ignore pins set OUTPUT
|
||||||
if(digitalInputs != previousDigitalInputs) {
|
if(digitalInputs != previousDigitalInputs) {
|
||||||
// TODO: implement more ports as channels for more than 16 digital pins
|
// TODO: implement more ports as channels for more than 16 digital pins
|
||||||
Serial.print(DIGITAL_MESSAGE,BYTE);
|
Firmata.sendDigitalPortPair(0, digitalInputs); // port 0 till more are implemented
|
||||||
|
/* Serial.print(DIGITAL_MESSAGE,BYTE);
|
||||||
Serial.print(digitalInputs % 128, BYTE); // Tx pins 0-6
|
Serial.print(digitalInputs % 128, BYTE); // Tx pins 0-6
|
||||||
Serial.print(digitalInputs >> 7, BYTE); // Tx pins 7-13
|
Serial.print(digitalInputs >> 7, BYTE); // Tx pins 7-13*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -302,10 +151,10 @@ void setPinMode(byte pin, byte mode) {
|
|||||||
*/
|
*/
|
||||||
void setAnalogPinReporting(byte pin, byte state) {
|
void setAnalogPinReporting(byte pin, byte state) {
|
||||||
if(state == 0) {
|
if(state == 0) {
|
||||||
analogPinsToReport = analogPinsToReport &~ (1 << pin);
|
analogInputsToReport = analogInputsToReport &~ (1 << pin);
|
||||||
}
|
}
|
||||||
else { // everything but 0 enables reporting of that pin
|
else { // everything but 0 enables reporting of that pin
|
||||||
analogPinsToReport = analogPinsToReport | (1 << pin);
|
analogInputsToReport = analogInputsToReport | (1 << pin);
|
||||||
}
|
}
|
||||||
// TODO: save status to EEPROM here, if changed
|
// TODO: save status to EEPROM here, if changed
|
||||||
}
|
}
|
||||||
@ -333,7 +182,7 @@ void processInput(int inputData) {
|
|||||||
case SET_DIGITAL_PIN_MODE:
|
case SET_DIGITAL_PIN_MODE:
|
||||||
setPinMode(storedInputData[1], storedInputData[0]); // (pin#, mode)
|
setPinMode(storedInputData[1], storedInputData[0]); // (pin#, mode)
|
||||||
if(storedInputData[0] == INPUT)
|
if(storedInputData[0] == INPUT)
|
||||||
digitalInputsEnabled = true; // enable reporting of digital inputs
|
reportDigitalInputs = true; // enable reporting of digital inputs
|
||||||
break;
|
break;
|
||||||
case REPORT_ANALOG_PIN:
|
case REPORT_ANALOG_PIN:
|
||||||
setAnalogPinReporting(multiByteChannel,storedInputData[0]);
|
setAnalogPinReporting(multiByteChannel,storedInputData[0]);
|
||||||
@ -341,9 +190,9 @@ void processInput(int inputData) {
|
|||||||
case REPORT_DIGITAL_PORTS:
|
case REPORT_DIGITAL_PORTS:
|
||||||
// TODO: implement MIDI channel as port base for more than 16 digital inputs
|
// TODO: implement MIDI channel as port base for more than 16 digital inputs
|
||||||
if(storedInputData[0] == 0)
|
if(storedInputData[0] == 0)
|
||||||
digitalInputsEnabled = false;
|
reportDigitalInputs = false;
|
||||||
else
|
else
|
||||||
digitalInputsEnabled = true;
|
reportDigitalInputs = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
executeMultiByteCommand = 0;
|
executeMultiByteCommand = 0;
|
||||||
@ -373,7 +222,7 @@ void processInput(int inputData) {
|
|||||||
// this doesn't do anything yet
|
// this doesn't do anything yet
|
||||||
break;
|
break;
|
||||||
case REPORT_VERSION:
|
case REPORT_VERSION:
|
||||||
printVersion();
|
Firmata.printVersion();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -388,6 +237,25 @@ void checkForSerialReceive() {
|
|||||||
processInput(Serial.read());
|
processInput(Serial.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* these functions are for loading and saving the state of the digital pins and
|
||||||
|
* pin reporting so that the Arduino will start up again in the same state. The
|
||||||
|
* EEPROM is supposed to have a life of at least 100,000 writes.
|
||||||
|
*/
|
||||||
|
void loadSettings() {
|
||||||
|
//EEPROM.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveSettings() {
|
||||||
|
EEPROM.write(ANALOGINPUTSTOREPORT_LOW_BYTE, analogInputsToReport & 0xFF);
|
||||||
|
EEPROM.write(ANALOGINPUTSTOREPORT_HIGH_BYTE, analogInputsToReport >> 8);
|
||||||
|
EEPROM.write(REPORTDIGITALINPUTS_BYTE, reportDigitalInputs & 0xFF);
|
||||||
|
EEPROM.write(DIGITALPINSTATUS_LOW_BYTE, digitalPinStatus & 0xFF);
|
||||||
|
EEPROM.write(DIGITALPINSTATUS_HIGH_BYTE, digitalPinStatus >> 8);
|
||||||
|
EEPROM.write(PWMSTATUS_LOW_BYTE, pwmStatus & 0xFF);
|
||||||
|
EEPROM.write(PWMSTATUS_HIGH_BYTE, pwmStatus >> 8);
|
||||||
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// used for flashing the pin for the version number
|
// used for flashing the pin for the version number
|
||||||
void pin13strobe(int count, int onInterval, int offInterval) {
|
void pin13strobe(int count, int onInterval, int offInterval) {
|
||||||
@ -407,8 +275,6 @@ void pin13strobe(int count, int onInterval, int offInterval) {
|
|||||||
void setup() {
|
void setup() {
|
||||||
byte i;
|
byte i;
|
||||||
|
|
||||||
Serial.begin(57600); // 9600, 14400, 38400, 57600, 115200
|
|
||||||
|
|
||||||
// flash the pin 13 with the protocol version
|
// flash the pin 13 with the protocol version
|
||||||
pinMode(13,OUTPUT);
|
pinMode(13,OUTPUT);
|
||||||
pin13strobe(2,1,4); // separator, a quick burst
|
pin13strobe(2,1,4); // separator, a quick burst
|
||||||
@ -422,12 +288,10 @@ void setup() {
|
|||||||
pin13strobe(2,1,4); // separator, a quick burst
|
pin13strobe(2,1,4); // separator, a quick burst
|
||||||
|
|
||||||
for(i=0; i<TOTAL_DIGITAL_PINS; ++i) {
|
for(i=0; i<TOTAL_DIGITAL_PINS; ++i) {
|
||||||
setPinMode(i,INPUT);
|
setPinMode(i,OUTPUT);
|
||||||
}
|
}
|
||||||
// TODO: load state from EEPROM here
|
// TODO: load state from EEPROM here
|
||||||
|
|
||||||
printVersion();
|
|
||||||
|
|
||||||
/* TODO: send digital inputs here, if enabled, to set the initial state on the
|
/* TODO: send digital inputs here, if enabled, to set the initial state on the
|
||||||
* host computer, since once in the loop(), the Arduino will only send data on
|
* host computer, since once in the loop(), the Arduino will only send data on
|
||||||
* change. */
|
* change. */
|
||||||
@ -452,13 +316,8 @@ void loop() {
|
|||||||
/* ANALOGREAD - right after the event character, do all of the
|
/* ANALOGREAD - right after the event character, do all of the
|
||||||
* analogReads(). These only need to be done every 4ms. */
|
* analogReads(). These only need to be done every 4ms. */
|
||||||
for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
|
for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
|
||||||
if( analogPinsToReport & (1 << analogPin) ) {
|
if( analogInputsToReport & (1 << analogPin) )
|
||||||
analogData = analogRead(analogPin);
|
Firmata.sendAnalog(analogPin, analogRead(analogPin));
|
||||||
Serial.print(ANALOG_MESSAGE + analogPin, BYTE);
|
|
||||||
// These two bytes converted back into the 10-bit value on host
|
|
||||||
Serial.print(analogData % 128, BYTE);
|
|
||||||
Serial.print(analogData >> 7, BYTE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user