Update of /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27111
Modified Files: Makefile Pd_firmware.pde Log Message: sketched out EEPROM library support, but it doesn't work yet ; renamed some variables for clarity ; made digital pins set to OUTPUT by default so that you don't get lots of random data, unless you want it ;)
Index: Makefile =================================================================== RCS file: /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware/Makefile,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile 5 Mar 2007 04:34:32 -0000 1.5 --- Makefile 13 Apr 2007 03:55:16 -0000 1.6 *************** *** 46,57 **** # $Id$
! PORT = /dev/tty.usbserial-1* TARGET = Pd_firmware ARDUINO = /Applications/arduino-0007 ARDUINO_SRC = $(ARDUINO)/lib/targets/arduino ! INCLUDE = -I$(ARDUINO_SRC) -I$(ARDUINO)/tools/avr/avr/include SRC = $(ARDUINO_SRC)/pins_arduino.c $(ARDUINO_SRC)/wiring.c \ $(ARDUINO_SRC)/WInterrupts.c CXXSRC = applet/$(TARGET).cpp $(ARDUINO_SRC)/HardwareSerial.cpp \ $(ARDUINO_SRC)/WRandom.cpp MCU = atmega8 --- 46,61 ---- # $Id$
! 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 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_SRC)/WRandom.cpp MCU = atmega8 *************** *** 216,219 **** --- 220,224 ---- $(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:
Index: Pd_firmware.pde =================================================================== RCS file: /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware/Pd_firmware.pde,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Pd_firmware.pde 8 Mar 2007 05:37:22 -0000 1.29 --- Pd_firmware.pde 13 Apr 2007 03:55:16 -0000 1.30 *************** *** 40,43 **** --- 40,45 ---- * IDMI/Polytechnic University, Brookyn, NY, USA * Electrolobby Ars Electronica, Linz, Austria + * + * See http://www.arduino.cc/playground/Interfacing/Firmata for docs */
*************** *** 53,167 **** /* cvs version: $Id$ */
! /*============================================================================== ! * MESSAGE FORMATS ! *============================================================================*/ ! ! /* ----------------------------------------------------------------------------- ! * 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) ! */
/*============================================================================== --- 55,59 ---- /* cvs version: $Id$ */
! #include <EEPROM.h>
/*============================================================================== *************** *** 176,180 **** #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 --- 68,72 ---- #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 *************** *** 189,193 ****
#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) --- 81,85 ----
#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) *************** *** 202,205 **** --- 94,106 ---- #define SYSTEM_RESET 0xFF // reset from MIDI
+ // these are used for EEPROM reading and writing + #define ANALOGINPUTSTOREPORT_LOW_BYTE 0x1F0 // analogInputsToReport is an int + #define ANALOGINPUTSTOREPORT_HIGH_BYTE 0x1F1 // analogInputsToReport is an int + #define REPORTDIGITALINPUTS_BYTE 0x1F2 // + #define DIGITALPINSTATUS_LOW_BYTE 0x1F3 // digitalPinStatus is an int + #define DIGITALPINSTATUS_HIGH_BYTE 0x1F4 // digitalPinStatus is an int + #define PWMSTATUS_LOW_BYTE 0x1F5 // pwmStatus is an int + #define PWMSTATUS_HIGH_BYTE 0x1F6 // pwmStatus is an int + /*============================================================================== * GLOBAL VARIABLES *************** *** 212,223 **** byte storedInputData[MAX_DATA_BYTES] = {0,0}; // multi-byte data /* digital pins */ ! boolean digitalInputsEnabled = false; // output digital inputs or not int digitalInputs; int previousDigitalInputs; // previous output to test for change ! int digitalPinStatus = 3; // bitwise array to store pin status, ignore RxTx pins /* PWM/analog outputs */ int pwmStatus = 0; // bitwise array to store PWM status /* analog inputs */ ! unsigned int analogPinsToReport = 0; // bitwise array to store pin reporting int analogPin = 0; // counter for reading analog pins int analogData; // storage variable for data from analogRead() --- 113,124 ---- byte storedInputData[MAX_DATA_BYTES] = {0,0}; // multi-byte data /* digital pins */ ! boolean reportDigitalInputs = false; // output digital inputs or not int digitalInputs; int previousDigitalInputs; // previous output to test for change ! unsigned int digitalPinStatus = 65535; // store pin status, default OUTPUT /* PWM/analog outputs */ int pwmStatus = 0; // bitwise array to store PWM status /* analog inputs */ ! int analogInputsToReport = 0; // bitwise array to store pin reporting int analogPin = 0; // counter for reading analog pins int analogData; // storage variable for data from analogRead() *************** *** 230,234 **** *============================================================================*/ /* ----------------------------------------------------------------------------- ! * output the version message to the serial port */ void printVersion() { Serial.print(REPORT_VERSION, BYTE); --- 131,135 ---- *============================================================================*/ /* ----------------------------------------------------------------------------- ! * output the protocol version message to the serial port */ void printVersion() { Serial.print(REPORT_VERSION, BYTE); *************** *** 258,262 **** * to the Serial output queue using Serial.print() */ void checkDigitalInputs(void) { ! if(digitalInputsEnabled) { previousDigitalInputs = digitalInputs; digitalInputs = _SFR_IO8(port_to_input[PB]) << 8; // get pins 8-13 --- 159,163 ---- * to the Serial output queue using Serial.print() */ void checkDigitalInputs(void) { ! if(reportDigitalInputs) { previousDigitalInputs = digitalInputs; digitalInputs = _SFR_IO8(port_to_input[PB]) << 8; // get pins 8-13 *************** *** 303,310 **** void setAnalogPinReporting(byte pin, byte state) { if(state == 0) { ! analogPinsToReport = analogPinsToReport &~ (1 << pin); } else { // everything but 0 enables reporting of that pin ! analogPinsToReport = analogPinsToReport | (1 << pin); } // TODO: save status to EEPROM here, if changed --- 204,211 ---- void setAnalogPinReporting(byte pin, byte state) { if(state == 0) { ! analogInputsToReport = analogInputsToReport &~ (1 << pin); } else { // everything but 0 enables reporting of that pin ! analogInputsToReport = analogInputsToReport | (1 << pin); } // TODO: save status to EEPROM here, if changed *************** *** 334,338 **** setPinMode(storedInputData[1], storedInputData[0]); // (pin#, mode) if(storedInputData[0] == INPUT) ! digitalInputsEnabled = true; // enable reporting of digital inputs break; case REPORT_ANALOG_PIN: --- 235,239 ---- setPinMode(storedInputData[1], storedInputData[0]); // (pin#, mode) if(storedInputData[0] == INPUT) ! reportDigitalInputs = true; // enable reporting of digital inputs break; case REPORT_ANALOG_PIN: *************** *** 342,348 **** // TODO: implement MIDI channel as port base for more than 16 digital inputs if(storedInputData[0] == 0) ! digitalInputsEnabled = false; else ! digitalInputsEnabled = true; break; } --- 243,249 ---- // TODO: implement MIDI channel as port base for more than 16 digital inputs if(storedInputData[0] == 0) ! reportDigitalInputs = false; else ! reportDigitalInputs = true; break; } *************** *** 389,392 **** --- 290,312 ---- }
+ /* ----------------------------------------------------------------------------- + * 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 *************** *** 423,427 ****
for(i=0; i<TOTAL_DIGITAL_PINS; ++i) { ! setPinMode(i,INPUT); } // TODO: load state from EEPROM here --- 343,347 ----
for(i=0; i<TOTAL_DIGITAL_PINS; ++i) { ! setPinMode(i,OUTPUT); } // TODO: load state from EEPROM here *************** *** 453,457 **** * analogReads(). These only need to be done every 4ms. */ for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) { ! if( analogPinsToReport & (1 << analogPin) ) { analogData = analogRead(analogPin); Serial.print(ANALOG_MESSAGE + analogPin, BYTE); --- 373,377 ---- * analogReads(). These only need to be done every 4ms. */ for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) { ! if( analogInputsToReport & (1 << analogPin) ) { analogData = analogRead(analogPin); Serial.print(ANALOG_MESSAGE + analogPin, BYTE);