├── .gitignore ├── .travis.yml ├── config.h ├── version.json ├── eeprom.c ├── main.c ├── eeprom.h ├── macros.h ├── CHANGELOG.md ├── pwm.h ├── timers.c ├── timers.h ├── pwm.c ├── mapping.h ├── gpio.h ├── onesheeld.h ├── README.md ├── mapping.c ├── uart.h ├── gpio.c ├── uart.c ├── onesheeld.c ├── firmata.h ├── Makefile ├── firmata.c └── LICENSE.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated Files 2 | build/ 3 | Debug/ 4 | Release/ 5 | 6 | # Doxygen 7 | docs/ 8 | 9 | # Atmel Studio 10 | *.atsln 11 | *.cproj 12 | *.atsuo 13 | *.xml 14 | 15 | # OSX 16 | .DS_Store 17 | 18 | # Windows 19 | thumbs.db -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | before_install: 3 | - sudo apt-get update -qq 4 | install: 5 | - sudo apt-get install -y -qq gcc-avr binutils-avr avr-libc 6 | script: 7 | - make all CONFIG=DEBUG 8 | - make all CONFIG=RELEASE 9 | notifications: 10 | email: 11 | on_success: change 12 | on_failure: change 13 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: config.h 5 | 6 | Compiler: avr-gcc 4.9.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2016.3 11 | 12 | */ 13 | 14 | 15 | #ifndef CONFIG_H_ 16 | #define CONFIG_H_ 17 | 18 | 19 | //#define PLUS_BOARD 20 | //#define CLASSIC_BOARD 21 | 22 | 23 | #endif /* CONFIG_H_ */ -------------------------------------------------------------------------------- /version.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1Sheeld Firmware v1.6", 3 | "description": "\n- Made the board testable using a special frame.\nAdded the ability to rename the bluetooth module.\n", 4 | "major": 1, 5 | "minor": 6, 6 | "date": "10/4/2016", 7 | "classic": "https://github.com/Integreight/1Sheeld-Firmware/releases/download/v1.6/1Sheeld.Firmware.Classic.Board.v1.6.bin", 8 | "plus": "https://github.com/Integreight/1Sheeld-Firmware/releases/download/v1.6/1Sheeld.Firmware.Plus.Board.v1.6.bin" 9 | } -------------------------------------------------------------------------------- /eeprom.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: eeprom.cpp 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2016.4 11 | 12 | */ 13 | #include "config.h" 14 | #include "eeprom.h" 15 | 16 | 17 | 18 | uint8_t readFromEeprom(uint8_t location) 19 | { 20 | return eeprom_read_byte((uint8_t*)(uint16_t)location); 21 | } 22 | 23 | void writeToEeprom(uint8_t location, uint8_t data) 24 | { 25 | eeprom_write_byte ((uint8_t*)(uint16_t)location,data); 26 | } 27 | 28 | void updateEeprom(uint8_t location, uint8_t data) 29 | { 30 | eeprom_update_byte((uint8_t*)(uint16_t)location,data); 31 | } -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: main.cpp 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | #include "stdint.h" 14 | #include "config.h" 15 | #include "onesheeld.h" 16 | 17 | int main(void) 18 | { 19 | initialization(); 20 | catchTimeForSomeVariables(); 21 | while (1) 22 | { 23 | newMillis = millis(); 24 | checkDigitalPinStatus(); 25 | #ifdef PLUS_BOARD 26 | checkArduinoRx0BufferSpace(); 27 | #endif // PLUS_BOARD 28 | processDataFromApp(); 29 | checkBluetoothResetResponse(); 30 | checkAppConnection(); 31 | sendDataToApp(); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /eeprom.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: eeprom.h 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2016.4 11 | 12 | */ 13 | 14 | #ifndef EEPROM_H_ 15 | #define EEPROM_H_ 16 | 17 | #include 18 | 19 | /** 20 | * @brief Read byte from a certain EEPROM cell. 21 | * @param Cell address to be extracting the byte from. 22 | * @return Data byte. 23 | */ 24 | uint8_t readFromEeprom(uint8_t); 25 | /** 26 | * @brief Write a byte to a certain EEPROM cell. 27 | * @param Data byte and the address to be written to. 28 | * @return None. 29 | */ 30 | void writeToEeprom(uint8_t , uint8_t); 31 | /** 32 | * @brief Checks the cell data before writing then updating it if the data is not equal. 33 | * @param Data byte and the address to be written to. 34 | * @return None. 35 | */ 36 | void updateEeprom(uint8_t , uint8_t); 37 | 38 | 39 | #endif /* EEPROM_H_ */ -------------------------------------------------------------------------------- /macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: macros.h 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | 14 | #ifndef MACROS_H_ 15 | #define MACROS_H_ 16 | 17 | #define CLR_BIT(var, bit) var &= (~(1< 27 | #include "mapping.h" 28 | 29 | #define TIMER_00 0 30 | #define TIMER_1A 1 31 | #define TIMER_1B 2 32 | #define TIMER_02 3 33 | #define TIMER_3A 4 34 | #define TIMER_3B 5 35 | 36 | 37 | /** 38 | * @brief Setup the prescalers of the timers except timer3=16 and timer 2=32. 39 | * @param timer The number of timer 0 --> 5. 40 | * @return None. 41 | */ 42 | void initPwm(uint8_t); 43 | /** 44 | * @brief Set the duty cycle of the signal on timers. 45 | * @param dutyCycle value of the signals duty cycle. 46 | * @param timerNo The number of timer 0 --> 5. 47 | * @return None. 48 | */ 49 | void setPwmDutyCycle(uint8_t, uint8_t); 50 | /** 51 | * @brief turning of the certain timers used by the library 52 | * @param timer number of the timer to be turned off 53 | * @return None 54 | */ 55 | void turnOffPWM(uint8_t); 56 | 57 | 58 | 59 | 60 | 61 | #endif /* PWM_H_ */ -------------------------------------------------------------------------------- /timers.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: timers.cpp 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | #include "config.h" 14 | #include "timers.h" 15 | 16 | volatile uint16_t countRx=0; 17 | volatile uint16_t countTx=0; 18 | volatile uint16_t count=0; 19 | volatile uint32_t timer0_overflow_count = 0; 20 | volatile uint32_t timer0_millis = 0; 21 | static uint8_t timer0_fract = 0; 22 | void enableTimerOverflow() 23 | { 24 | SET_BIT(TIMSK,TOIE2); 25 | } 26 | 27 | void enableRxLedBlinking(){ 28 | //isRxEnabled=1; 29 | countRx =1 ; 30 | } 31 | 32 | void enableTxLedBlinking(){ 33 | //isTxEnabled=1; 34 | countTx =1 ; 35 | } 36 | uint32_t millis() 37 | { 38 | uint32_t m; 39 | uint8_t oldSREG = SREG; 40 | // disable interrupts while we read timer0_millis or we might get an 41 | // inconsistent value (e.g. in the middle of a write to timer0_millis) 42 | cli(); 43 | m = timer0_millis; 44 | SREG = oldSREG; 45 | sei(); 46 | return m; 47 | } 48 | ISR (TIMER0_OVF_vect) 49 | { 50 | uint32_t m = timer0_millis; 51 | uint8_t f = timer0_fract; 52 | m += MILLIS_INC; 53 | f += FRACT_INC; 54 | if (f >= FRACT_MAX) { 55 | f -= FRACT_MAX; 56 | m += 1; 57 | } 58 | 59 | timer0_fract = f; 60 | timer0_millis = m; 61 | timer0_overflow_count++; 62 | } 63 | ISR(TIMER2_OVF_vect) 64 | { 65 | if(count%100==0) 66 | { 67 | if(countRx>0&&countRx<=6){ 68 | TOG_BIT(PORTA,6); 69 | countRx++; 70 | } 71 | if(countTx>0&&countTx<=6){ 72 | TOG_BIT(PORTA,7); 73 | countTx++; 74 | } 75 | 76 | if(countRx>=6&&countTx>=6) 77 | { 78 | CLR_BIT(TIMSK,TOIE2); 79 | SET_BIT(PORTA,6); 80 | SET_BIT(PORTA,7); 81 | } 82 | else if(countRx>=6){ 83 | //isRxEnabled=false; 84 | countRx=0; 85 | SET_BIT(PORTA,6); 86 | } 87 | else if(countTx>=6){ 88 | //isTxEnabled=false; 89 | countTx=0; 90 | SET_BIT(PORTA,7); 91 | } 92 | } 93 | 94 | 95 | count++; 96 | } 97 | 98 | void setupMillisTimers() 99 | { 100 | TCCR0=(1< 25 | #include 26 | #include "mapping.h" 27 | 28 | 29 | /** 30 | * the prescaler is set so that timer0 ticks every 64 clock cycles, and the 31 | * the overflow handler is called every 256 ticks. 32 | */ 33 | #define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256)) 34 | /* the whole number of milliseconds per timer0 overflow */ 35 | #define MILLIS_INC ((uint32_t)MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) 36 | /** the fractional number of milliseconds per timer0 overflow. we shift right 37 | * by three to fit these numbers into a byte. (for the clock speeds we care 38 | * about - 8 and 16 MHz - this doesn't lose precision.) 39 | */ 40 | #define FRACT_INC (((uint32_t)MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) 41 | #define FRACT_MAX (1000 >> 3) 42 | 43 | /** 44 | * @brief Enables timer overflow interrupt. 45 | * @param None. 46 | * @return None. 47 | */ 48 | void enableTimerOverflow(); 49 | /** 50 | * @brief Disables timer overflow interrupt. 51 | * @param None. 52 | * @return None. 53 | */ 54 | void disableTimerOverflow(); 55 | /** 56 | * @brief Turns on Rx Leds blinking on 1Sheeld board. 57 | * @param None. 58 | * @return None. 59 | */ 60 | void enableRxLedBlinking(); 61 | /** 62 | * @brief Turns on Tx Leds blinking on 1Sheeld board. 63 | * @param None. 64 | * @return None. 65 | */ 66 | void enableTxLedBlinking(); 67 | /** 68 | * @brief Returns the number of milliseconds since 1Sheeld board began running. 69 | * @param None. 70 | * @return Number of milliseconds since the program started (unsigned long). 71 | */ 72 | uint32_t millis(); 73 | /** 74 | * @brief Setup the millis timers 75 | * @param None 76 | * @return None 77 | */ 78 | void setupMillisTimers(); 79 | #endif /* TIMERS_H_ */ -------------------------------------------------------------------------------- /pwm.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: pwm.cpp 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | #include "config.h" 14 | #include "pwm.h" 15 | 16 | void initPwm(uint8_t timer) 17 | { 18 | switch(timer) 19 | { 20 | // make 64 prescalar for all timers except timer3=16 and timer 2=32 21 | case TIMER_00 : 22 | TCCR0|=(1< 18 | #include 19 | #include 20 | #include "macros.h" 21 | 22 | #define F_CPU 7372800UL 23 | 24 | #define digitalPinHasPWM(p) ( ((p) == 3) || ((p) == 5) || ((p) == 6) || ((p) == 9) || ((p) == 10) || ((p) == 11) ) 25 | #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) <= 19) 26 | #define IS_PIN_PWM(p) digitalPinHasPWM(p) 27 | #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK) 28 | #define NUM_ANALOG_INPUTS 0 29 | #define analogInputToDigitalPin(p) (-1) 30 | 31 | #define NOT_A_PIN 255 32 | #define NOT_A_PORT 255 33 | // SPI pins 34 | static const uint8_t SS = 10; 35 | static const uint8_t MOSI = 28; 36 | static const uint8_t MISO = 29; 37 | static const uint8_t SCK = 30; 38 | 39 | //ATMEGA 162 40 | // +-\/-+ 41 | // PWM (D11) PB0 1| |40 VCC 42 | // PWM (D 9) PB1 2| |39 PA0 (D19) 43 | // (D23) PB2 3| |38 PA1 (D18) 44 | // (D24) PB3 4| |37 PA2 (D17) 45 | // PWM (D10) PB4 5| |36 PA3 (D16) 46 | // (D28) PB5 6| |35 PA4 (D15) 47 | // (D29) PB6 7| |34 PA5 (D14) 48 | // (D30) PB7 8| |33 PA6 (D20) 49 | // RST 9| |32 PA7 (D21) 50 | // (D 0) PD0 10| |31 PE0 (D33) 51 | // (D 1) PD1 11| |30 PE1 (D34) 52 | // (D25) PD2 12| |29 PE2 (D 6) PWM 53 | // (D26) PD3 13| |28 PC7 (D32) 54 | // PWM (D 3) PD4 14| |27 PC6 (D31) 55 | // PWM (D 5) PD5 15| |26 PC5 (D13) 56 | // (D22) PD6 16| |25 PC4 (D12) 57 | // (D27) PD7 17| |24 PC3 (D 8) 58 | // XT2 18| |23 PC2 (D 7) 59 | // XT1 19| |22 PC1 (D 4) 60 | // GND 20| |21 PC0 (D 2) 61 | // +----+ 62 | // 63 | 64 | extern const uint16_t PROGMEM port_to_input_PGM[]; 65 | 66 | extern const uint16_t PROGMEM port_to_register_PGM[]; 67 | 68 | extern const uint8_t PROGMEM digital_pin_to_port_PGM[]; 69 | 70 | extern const uint8_t PROGMEM digital_pin_to_bit_mask_PWM_PGM[]; 71 | 72 | extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; 73 | 74 | extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; 75 | 76 | #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) 77 | #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) 78 | #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) ) 79 | #define analogInPinToBit(P) (P) 80 | #define portModeRegister(P) ( ( pgm_read_word( port_to_register_PGM + (P))) ) 81 | 82 | #define digitalPinToBitMaskPWM(P) ( pgm_read_byte( digital_pin_to_bit_mask_PWM_PGM + (P) ) ) 83 | // for pulseIn 84 | #define clockCyclesPerMicrosecond() ( F_CPU /(double) 1000000L ) 85 | #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) 86 | #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) 87 | #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) ) 88 | #endif /* MAPPING_H_ */ -------------------------------------------------------------------------------- /gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: gpio.h 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | 14 | /** 15 | * @file gpio.h 16 | * @brief GPIO driver for configuring and dealing with GPIOs on ATmega162 17 | * @author Integreight 18 | * @version 1.1 19 | */ 20 | 21 | #ifndef GPIO_H_ 22 | #define GPIO_H_ 23 | #include "pwm.h" 24 | 25 | 26 | typedef struct 27 | { 28 | uint8_t portInReg;//pin 29 | uint8_t portDirReg;//ddrc 30 | uint8_t portOutReg;//portc 31 | 32 | }t_stPort; 33 | 34 | typedef struct 35 | { 36 | uint8_t Portdir; 37 | uint16_t pID; 38 | }t_SetPortCfg; 39 | 40 | /** 41 | * @brief Sets the registers for a pin in a certain port to be an output. 42 | * @param *cfg pointer to the t_SetPortCfg structure . 43 | * @return None. 44 | */ 45 | void setPinModeOutput(t_SetPortCfg* cfg, uint8_t bit); 46 | /** 47 | * @brief Sets the registers for a pin in a certain port to be an input. 48 | * @param *cfg pointer to the t_SetPortCfg structure . 49 | * @return None. 50 | */ 51 | void setPinModeInput(t_SetPortCfg* cfg, uint8_t bit); 52 | /** 53 | * @brief Gets a certain value from pin of certain port. 54 | * @param pid the port id. 55 | * @param pinNum pin number. 56 | * @return None. 57 | */ 58 | uint8_t getPinValue(uint16_t pid,uint8_t pinNum); 59 | /** 60 | * @brief Sets a certain value to a pin of certain port. 61 | * @param data data to be put on the pin. 62 | * @param pid the port id. 63 | * @param pinNum pin number. 64 | * @return None. 65 | */ 66 | void setPinValue(uint8_t data,uint16_t pid,uint8_t pinNum); 67 | /** 68 | * @brief Reads the value of a certain digital pin 69 | * @param pinNumber pin number 70 | * @return current state of the pin 71 | */ 72 | uint8_t digitalRead(uint8_t); 73 | /** 74 | * @brief Output a value to a digital pin 75 | * @param pinNumber pin number 76 | * @param value HIGH or LOW 77 | * @return None 78 | */ 79 | void digitalWrite(uint8_t, uint8_t); 80 | /** 81 | * @brief Sets the pin whether it's Input, Output or PWM 82 | * @param pinNumber pin number 83 | * @param pinMode Mode (INPUT/OUTPUT/PWM) 84 | * @return None 85 | */ 86 | void setPinMode(uint8_t , uint8_t); 87 | /** 88 | * @brief Sets the duty cycle of a PWM pin. 89 | * @param pinNumber pwm pin number 90 | * @param val duty cycle 0 --> 255 91 | * @return None 92 | */ 93 | void analogWrite(uint8_t, int16_t); 94 | /** 95 | * @brief output a value to the whole port 96 | * @param port port number 97 | * @param value the value of the whole port to be output 98 | * @param bitmask masks the port to protect some pins and to retain their values 99 | * @return None 100 | */ 101 | void writePort(uint8_t, uint8_t, uint8_t); 102 | /** 103 | * @brief reads the whole port value 104 | * @param port port number to be red 105 | * @param bitmask masks the port to protect some pins and to retain their values 106 | * @return None 107 | */ 108 | uint8_t readPort(uint8_t, uint8_t); 109 | /** 110 | * @brief Sets all unused pins to be Output 111 | * @param None 112 | * @return None 113 | */ 114 | void setUnusedPinsAsOutput(); 115 | 116 | #endif /* GPIO_H_ */ -------------------------------------------------------------------------------- /onesheeld.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: onesheeld.h 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | 14 | /** 15 | * @file onesheeld.h 16 | * @brief This library contains an Arduino abstraction layer to mimic Arduino methods and a set of 1Sheeld related methods. 17 | * @author Integreight 18 | * @version 1.1 19 | */ 20 | 21 | #ifndef ONESHEELD_H_ 22 | #define ONESHEELD_H_ 23 | #include "stdint.h" 24 | #include "firmata.h" 25 | 26 | #if (!defined(PLUS_BOARD) && !defined(CLASSIC_BOARD)) 27 | #error "Board not defined" 28 | #endif 29 | #if (defined(PLUS_BOARD) && defined(CLASSIC_BOARD)) 30 | #error "Defined PLUS_BOARD and CLASSIC_BOARD" 31 | #endif 32 | 33 | /** 34 | * @brief Send a frame to Arduino that the app is disconected 35 | * @param None 36 | * @return None 37 | */ 38 | void sendArduinoAppDisconnected(); 39 | /** 40 | * @brief Initializes the Hardware peripherals and setup for communications 41 | * @param None 42 | * @return None 43 | */ 44 | void initialization(); 45 | /** 46 | * @brief Grab Time using Millis timer function 47 | * @param None 48 | * @return None 49 | */ 50 | void catchTimeForSomeVariables(); 51 | /** 52 | * @brief Checks digitalPorts status 53 | * @param None 54 | * @return None 55 | */ 56 | void checkDigitalPinStatus(); 57 | /** 58 | * @brief Process data coming from application. 59 | * @param None. 60 | * @return None. 61 | */ 62 | void processDataFromApp(); 63 | /** 64 | * @brief Check if application responded to the Bluetooth reset request. 65 | * @param None. 66 | * @return None. 67 | */ 68 | void checkBluetoothResetResponse(); 69 | /** 70 | * @brief Check if app responded as alive and is still connected. 71 | * @param None. 72 | * @return None. 73 | */ 74 | void checkAppConnection(); 75 | /** 76 | * @brief Send Data to the application in 20bytes frame each 15ms. 77 | * @param None. 78 | * @return None. 79 | */ 80 | void sendDataToApp(); 81 | /** 82 | * @brief Send a frame to Arduino to stop sending Data 83 | * @param None 84 | * @return None 85 | */ 86 | void sendArduinoToStopData(); 87 | /** 88 | * @brief Send a frame to Arduino to start sending Data 89 | * @param None 90 | * @return None 91 | */ 92 | void sendArduinoToSendData(); 93 | /** 94 | * @brief Check if the Arduino Buffer is Empty 95 | * @param None 96 | * @return None 97 | */ 98 | void checkArduinoRx0BufferSpace(); 99 | /** 100 | * @brief Check digital ports pin state equality. 101 | * @param oldPort state,newPort state,number of pins. 102 | * @return None. 103 | */ 104 | uint16_t checkPortStateEquality(uint8_t * oldPort ,uint8_t * newPort,uint8_t numberOfPins); 105 | /** 106 | * @brief Put digital ports values in the 20byte buffer to be sent. 107 | * @param None. 108 | * @return None. 109 | */ 110 | void fillBufferWithPinStates(uint8_t * portArray,uint8_t portNumber); 111 | /** 112 | * @brief Put digital ports values in the 20byte buffer to be sent. 113 | * @param None. 114 | * @return None. 115 | */ 116 | uint8_t getSavedBaudRateFromEeprom(); 117 | /** 118 | * @brief Check the changes of the pins and place them in the small buffer. 119 | * @param None. 120 | * @return None. 121 | */ 122 | void checkIfPinsChangedSendThem(); 123 | #endif /* 1SHEELDS_FUNCTIONS_H_ */ 124 | 125 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 1Sheeld Firmware [![Build Status](https://travis-ci.org/Integreight/1Sheeld-Firmware.svg?branch=master)](https://travis-ci.org/Integreight/1Sheeld-Firmware)# 2 | 3 | ## Overview ## 4 | 5 | This is the source code of the firmware shipped with your 1Sheeld board. It is an implementation of a custom version of the Firmata protocal ported to ATmega162. It supports some of Firmata's messages like digital messages but lacks capability query, analog, I2C and servos messages. 6 | 7 | ## Building ## 8 | 9 | The project is an generic C project, and can be built using any port of *avr-gcc* for either Microsoft Windows, Linux, or Mac OSX. Just make sure you have both *GNU Make* and *avr-gcc* tool chain installed on your platform then run ``` make ``` on the repo's root directory and both the classic and plus boards variations will be built in a new subdirectory called *build*. 10 | 11 | If you are not going to use the *make* command, make sure you that either *PLUS_BOARD* or *CLASSIC_BOARD* is defined. (You can use the config.h file for that) 12 | 13 | ## Fuse Bits ## 14 | 15 | - Low Value: 0xFD 16 | - High Value: 0xD8 17 | - Extended Value: 0xFB 18 | 19 | Click [here](http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega162&LOW=FD&HIGH=D8&EXTENDED=FB&LOCKBIT=CC) for a description of the enabled fuse bits. 20 | 21 | ## Uploading ## 22 | 23 | The ICSP pins are exposed with a 6-pin header on the bottom of your 1Sheeld board. You can easily connect any ATmega programmer and upload your own version of the firmware. 24 | 25 | If you are using any [USBasp programmer](http://www.fischl.de/usbasp/) and have *avrdude* installed, after building using ``` make ``` you can flash your board by running either ``` make flashdebug ``` or ``` make flashrelease ``` on the repo's root directory. Make sure you erase the chip first by running ``` make erase ```. 26 | 27 | Note: 1Sheeld is equipped with a bootloader that enables us to push updates to the firmware from the app. If you attempt to upload this firmware and erased the chip, you will lose this functionality. 28 | 29 | ## Documentation ## 30 | 31 | You can generate the documentation by installing and running ``` doxygen ``` on the repo's root directory. 32 | 33 | ## Contribution ## 34 | 35 | Contributions are welcomed, please follow this pattern: 36 | - Fork the repo. 37 | - Open an issue with your proposed feature or bug fix. 38 | - Commit and push code to a new branch in your forked repo. 39 | - Submit a pull request to our *development* branch. 40 | 41 | Don't forget to drop us an email, post on our forum, or mention us on Twitter or Facebook about what you have built using 1Sheeld, we would love to hear about it. 42 | 43 | ## Changelog ## 44 | 45 | To see what has changed in recent versions of 1Sheeld Firmware, see the [Change Log](CHANGELOG.md). 46 | 47 | ## License and Copyright ## 48 | 49 | ``` 50 | This code is free software; you can redistribute it and/or modify it 51 | under the terms of the GNU General Public License version 3 only, as 52 | published by the Free Software Foundation. 53 | 54 | This code is distributed in the hope that it will be useful, but WITHOUT 55 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 56 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 57 | version 3 for more details (a copy is included in the LICENSE file that 58 | accompanied this code). 59 | 60 | Please contact Integreight, Inc. at info@integreight.com or post on our 61 | support forums www.1sheeld.com/forum if you need additional information 62 | or have any questions. 63 | ``` 64 | -------------------------------------------------------------------------------- /mapping.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: mapping.c 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | #include "config.h" 14 | #include "mapping.h" 15 | 16 | #define F_CPU 7372800UL 17 | 18 | const uint16_t PROGMEM port_to_input_PGM[] = { 19 | (uint16_t) &PINA, 20 | (uint16_t) &PINB, 21 | (uint16_t) &PINC, 22 | (uint16_t) &PIND, 23 | (uint16_t) &PINE, 24 | }; 25 | 26 | const uint16_t PROGMEM port_to_register_PGM[] = { 27 | (uint16_t) 0x39, 28 | (uint16_t) 0x36, 29 | (uint16_t) 0x33, 30 | (uint16_t) 0x30, 31 | (uint16_t) 0x25, 32 | }; 33 | 34 | const uint8_t PROGMEM digital_pin_to_port_PGM[] = { 35 | PD, // PD0 36 | PD, // PD1 37 | PC, // PC0 38 | PD, // PD4 39 | PC, // PC1 40 | PD, // PD5 41 | PE, // PE2 42 | PC, // PC2 43 | PC, // PC3 44 | PB, // PB1 45 | PB, // PB4 46 | PB, // PB0 47 | PC, // PC4 48 | PC, // PC5 49 | PA, // PA5 50 | PA, // PA4 51 | PA, // PA3 52 | PA, // PA2 53 | PA, // PA1 54 | PA, // PA0 55 | PA, // PA6 56 | PA, // PA7 57 | PD, // PD6 58 | PB, // PB2 59 | PB, // PB3 60 | PD, // PD2 61 | PD, // PD3 62 | PD, // PD7 63 | PB, // PB5 64 | PB, // PB6 65 | PB, // PB7 66 | PC, // PC6 67 | PC, // PC7 68 | PE, // PE0 69 | PE, // PE1 70 | }; 71 | 72 | const uint8_t PROGMEM digital_pin_to_bit_mask_PWM_PGM[] = { 73 | _BV(0), 74 | _BV(1), 75 | _BV(0), 76 | _BV(4), 77 | _BV(1), 78 | _BV(5), 79 | _BV(2), // PORT 80 | _BV(2), 81 | _BV(3), /* 8, port B */ 82 | _BV(0), 83 | _BV(4), 84 | _BV(1), 85 | _BV(4), 86 | _BV(5), 87 | _BV(5), /* 14, port A */ 88 | _BV(4), 89 | _BV(3), 90 | _BV(2), 91 | _BV(1), 92 | _BV(0), 93 | _BV(6), 94 | _BV(7), 95 | _BV(6), 96 | _BV(2), 97 | _BV(3), 98 | _BV(2), 99 | _BV(3), 100 | _BV(7), 101 | _BV(5), 102 | _BV(6), 103 | _BV(7), 104 | _BV(6), 105 | _BV(7), 106 | _BV(0), 107 | _BV(1), 108 | 109 | }; 110 | 111 | const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { 112 | 0,//_BV(0), 113 | 1,//_BV(1), 114 | 0,//_BV(0), 115 | 4,//_BV(4), 116 | 1,//_BV(1), 117 | 5,//_BV(5), 118 | 2,//_BV(2), // PORT 119 | 2,//_BV(2), 120 | 3,//_BV(3), /* 8, port B */ 121 | 1,//_BV(0), 122 | 4,//_BV(4), 123 | 0,//_BV(1), 124 | 4,//_BV(4), 125 | 5,//_BV(5), 126 | 5,//_BV(0), /* 14, port A */ 127 | 4,//_BV(1), 128 | 3,//_BV(2), 129 | 2,//_BV(3), 130 | 1,//_BV(4), 131 | 0,//_BV(5), 132 | 6,//_BV(6), 133 | 7,//_BV(7), 134 | 6,//_BV(6), 135 | 2,//_BV(2), 136 | 3,//_BV(3), 137 | 2,//_BV(2), 138 | 3,//_BV(3), 139 | 7,//_BV(7), 140 | 5,//_BV(5), 141 | 6,//_BV(6), 142 | 7,//_BV(7), 143 | 6,//_BV(6), 144 | 7,//_BV(7), 145 | 0,//_BV(0), 146 | 1,//_BV(1), 147 | 148 | }; 149 | 150 | const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { 151 | NOT_ON_TIMER, /* 0 - port D */ 152 | NOT_ON_TIMER, 153 | NOT_ON_TIMER, 154 | TIMER3A, 155 | NOT_ON_TIMER, 156 | TIMER1A, 157 | TIMER1B, 158 | NOT_ON_TIMER, 159 | NOT_ON_TIMER, 160 | TIMER2, 161 | TIMER3B, 162 | TIMER0, 163 | NOT_ON_TIMER, 164 | NOT_ON_TIMER, 165 | NOT_ON_TIMER, 166 | NOT_ON_TIMER, 167 | NOT_ON_TIMER, 168 | NOT_ON_TIMER, 169 | NOT_ON_TIMER, 170 | NOT_ON_TIMER, 171 | NOT_ON_TIMER, 172 | NOT_ON_TIMER, 173 | NOT_ON_TIMER, 174 | NOT_ON_TIMER, 175 | NOT_ON_TIMER, 176 | NOT_ON_TIMER, 177 | NOT_ON_TIMER, 178 | NOT_ON_TIMER, 179 | NOT_ON_TIMER, 180 | NOT_ON_TIMER, 181 | NOT_ON_TIMER, 182 | NOT_ON_TIMER, 183 | NOT_ON_TIMER, 184 | NOT_ON_TIMER, 185 | NOT_ON_TIMER, 186 | }; 187 | -------------------------------------------------------------------------------- /uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: uart.h 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | 14 | /** 15 | * @file Uart.h 16 | * @brief UART driver for handling the serial data on ATmega162 uart modules 17 | * @author Integreight 18 | * @version 1.1 19 | */ 20 | 21 | #ifndef UART_H_ 22 | #define UART_H_ 23 | #include "stdint.h" 24 | #include 25 | #include 26 | #include "timers.h" 27 | 28 | #define BAUD_9600 0x01 29 | #define BAUD_14400 0x02 30 | #define BAUD_19200 0x03 31 | #define BAUD_28800 0x04 32 | #define BAUD_38400 0x05 33 | #define BAUD_57600 0x06 34 | #define BAUD_115200 0x07 35 | 36 | #define UART_RX0_INTERRUPT ENABLED 37 | #define UART_RX1_INTERRUPT ENABLED 38 | #define UART_RX1_BUFFER_SIZE 256 39 | #define UART_RX1_BUFFER_MASK ( UART_RX1_BUFFER_SIZE - 1) 40 | #define UART1_STATUS UCSR1A 41 | #define UART1_DATA UDR1 42 | #define UART0_RX0_BUFFER_SIZE 256 43 | #define UART0_RX0_BUFFER_MASK ( UART0_RX0_BUFFER_SIZE - 1) 44 | #define UART0_STATUS UCSR0A 45 | #define UART0_DATA UDR0 46 | 47 | //Error codes 48 | #define UART_NO_DATA -1 /**< no receive data available */ 49 | #define UART_BUFFER_OVERFLOW -2 /**< receive ringbuffer overflow */ 50 | #ifdef PLUS_BOARD 51 | volatile uint8_t isArduinoRx0BufferEmpty; 52 | volatile uint8_t isArduinoRx0BufferOverFlowed; 53 | #endif 54 | /** 55 | * @brief Initialize the serial port, it's status registers and buffers. 56 | * @param serialPort specify which serial port to initialize 0 or 1 57 | * @return None 58 | */ 59 | void initUart(uint8_t serialPort,uint8_t baudrate); 60 | /** 61 | * @brief Disables the serial port, it's status registers and buffers. and returns rx and tx pins to their defaults. 62 | * @param serialPort specify which serial port to disable 0 or 1 63 | * @return None 64 | */ 65 | void terminateUart(uint8_t serialPort); 66 | /** 67 | * @brief Transmits a byte to serial port 0. 68 | * @param data the byte to be sent 69 | * @return None 70 | */ 71 | void writeOnUart0(uint8_t data); 72 | /** 73 | * @brief Transmits a byte to serial port 1. 74 | * @param data the byte to be sent 75 | * @return None 76 | */ 77 | void writeOnUart1(uint8_t data); 78 | /** 79 | * @brief Receives a byte from serial port 0. 80 | * @param None. 81 | * @return the received byte. 82 | */ 83 | int16_t readFromUart0(); 84 | /** 85 | * @brief Receives a byte from serial port 1. 86 | * @param None. 87 | * @return the received byte. 88 | */ 89 | int16_t readFromUart1(); 90 | /** 91 | * @brief Setup the LEDs as UART communication indicator 92 | * @param None 93 | * @return None 94 | */ 95 | void setupUartLeds(); 96 | /** 97 | * @brief Returns true if Arduino buffer is Empty. 98 | * @param None. 99 | * @return True or False. 100 | */ 101 | uint8_t getIsArduinoRx0BufferEmptyFlag(); 102 | /** 103 | * @brief Sets the boolean. 104 | * @param True or False. 105 | * @return None. 106 | */ 107 | void setIsArduinoRx0BufferEmptyFlag(uint8_t); 108 | /** 109 | * @brief Returns true if Arduino buffer is Empty. 110 | * @param None. 111 | * @return True or False. 112 | */ 113 | uint8_t getIsArduinoRx0BufferOverFlowedFlag(); 114 | /** 115 | * @brief Sets the boolean. 116 | * @param True or False. 117 | * @return None. 118 | */ 119 | void setIsArduinoRx0BufferOverFlowedFlag(uint8_t); 120 | /** 121 | * @brief Gets the count of the available data in the buffer of serial 1. 122 | * @param None. 123 | * @return the data count. 124 | */ 125 | int16_t getAvailableDataCountOnUart1(); 126 | /** 127 | * @brief Gets the count of the available data in the buffer of serial 0. 128 | * @param None. 129 | * @return the data count. 130 | */ 131 | int16_t getAvailableDataCountOnUart0(); 132 | 133 | #endif /* UART_H_ */ -------------------------------------------------------------------------------- /gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: gpio.cpp 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | #include "config.h" 14 | #include "gpio.h" 15 | 16 | void setPinModeOutput(t_SetPortCfg* cfg, uint8_t bit) 17 | { 18 | SET_BIT(cfg->Portdir,bit); 19 | t_stPort* stport=(t_stPort *)cfg->pID; //make the pointer points to the Port Registers in memory 20 | stport->portDirReg |= cfg->Portdir; 21 | } 22 | 23 | void setPinModeInput(t_SetPortCfg* cfg, uint8_t bit) 24 | { 25 | t_stPort* stport=(t_stPort *)cfg->pID; //make the pointer points to the Port Registers in memory 26 | cfg->Portdir=stport->portDirReg; 27 | CLR_BIT(cfg->Portdir,bit); 28 | stport->portDirReg &= cfg->Portdir; 29 | } 30 | 31 | uint8_t getPinValue(uint16_t pid,uint8_t pinNum) 32 | { 33 | t_stPort* stport; 34 | 35 | 36 | stport=(t_stPort *)pid; 37 | return ((stport->portInReg)&(1<portOutReg),pinNum); 51 | break; 52 | 53 | case 1: 54 | SET_BIT((stport->portOutReg),pinNum); 55 | break; 56 | 57 | default: 58 | SET_BIT((stport->portOutReg),pinNum);//19/1 59 | break; 60 | 61 | } 62 | } 63 | 64 | void setPinMode(uint8_t pin , uint8_t pinMode) 65 | { 66 | uint8_t bit = digitalPinToBitMask(pin); 67 | uint8_t port = digitalPinToPort(pin); 68 | t_SetPortCfg cfg; 69 | 70 | 71 | if(port == NOT_A_PIN) 72 | { 73 | return; 74 | } 75 | 76 | cfg.pID = portModeRegister(port); 77 | 78 | if(pinMode == INPUT) 79 | { 80 | setPinModeInput(&cfg, bit); 81 | } 82 | else 83 | { 84 | setPinModeOutput(&cfg, bit); 85 | } 86 | 87 | } 88 | 89 | uint8_t digitalRead(uint8_t pin) 90 | { 91 | uint8_t timer = digitalPinToTimer(pin); 92 | uint8_t bit = digitalPinToBitMask(pin); 93 | uint8_t port = digitalPinToPort(pin); 94 | t_SetPortCfg cfg; 95 | 96 | if (timer != NOT_ON_TIMER) turnOffPWM(timer); 97 | 98 | if(port == NOT_A_PIN) 99 | { 100 | return 0; 101 | } 102 | 103 | cfg.pID = (uint16_t)portModeRegister(port); 104 | 105 | return getPinValue(cfg.pID,bit); 106 | 107 | } 108 | 109 | void digitalWrite(uint8_t pin, uint8_t value) 110 | { 111 | uint8_t timer = digitalPinToTimer(pin); 112 | uint8_t bit = digitalPinToBitMask(pin); 113 | uint8_t port = digitalPinToPort(pin); 114 | t_SetPortCfg cfg; 115 | 116 | if (timer != NOT_ON_TIMER) turnOffPWM(timer); 117 | 118 | if(port == NOT_A_PORT) 119 | { 120 | return; 121 | } 122 | 123 | cfg.pID = (uint16_t)portModeRegister(port); 124 | 125 | setPinValue(value,cfg.pID,bit); 126 | } 127 | 128 | void analogWrite(uint8_t pin, int16_t val) 129 | { 130 | uint8_t timer = 0xff; 131 | setPinMode(pin, OUTPUT); 132 | 133 | if ((val == 0) || (val <0)) 134 | { 135 | digitalWrite(pin, LOW); 136 | 137 | } 138 | else if ((val > 255) || (val == 255)) 139 | { 140 | digitalWrite(pin, HIGH); 141 | 142 | } 143 | else 144 | { 145 | timer = digitalPinToTimer(pin); 146 | initPwm(timer); 147 | setPwmDutyCycle((uint8_t)val, timer); 148 | 149 | } 150 | 151 | } 152 | 153 | 154 | uint8_t readPort(uint8_t port, uint8_t bitmask) 155 | { 156 | uint8_t out=0, pin=port*8; 157 | if ((IS_PIN_DIGITAL(pin+0)) && (bitmask & 0x01) && ( digitalRead(pin+0))) out |= 0x01; 158 | if ((IS_PIN_DIGITAL(pin+1)) && (bitmask & 0x02) && ( digitalRead(pin+1))) out |= 0x02; 159 | if ((IS_PIN_DIGITAL(pin+2)) && (bitmask & 0x04) && ( digitalRead(pin+2))) out |= 0x04; 160 | if ((IS_PIN_DIGITAL(pin+3)) && (bitmask & 0x08) && ( digitalRead(pin+3))) out |= 0x08; 161 | if ((IS_PIN_DIGITAL(pin+4)) && (bitmask & 0x10) && ( digitalRead(pin+4))) out |= 0x10; 162 | if ((IS_PIN_DIGITAL(pin+5)) && (bitmask & 0x20) && ( digitalRead(pin+5))) out |= 0x20; 163 | if ((IS_PIN_DIGITAL(pin+6)) && (bitmask & 0x40) && ( digitalRead(pin+6))) out |= 0x40; 164 | if ((IS_PIN_DIGITAL(pin+7)) && (bitmask & 0x80) && ( digitalRead(pin+7))) out |= 0x80; 165 | return out; 166 | } 167 | 168 | void writePort(uint8_t port, uint8_t value, uint8_t bitmask) 169 | { 170 | uint8_t pin=port*8; 171 | 172 | if (port==0) 173 | { 174 | bitmask&=0xfc; // don't touch uart pins (0,1)!! 175 | } 176 | else if (port==2) 177 | { 178 | bitmask&=0x7f; // don't touch uart pins (23)!! 179 | } 180 | else if (port==3) 181 | { 182 | bitmask&=0xfe; // don't touch uart pins (24)!! 183 | } 184 | 185 | if ((bitmask & 0x01)) digitalWrite((pin+0), (value & 0x01)); 186 | if ((bitmask & 0x02)) digitalWrite((pin+1), (value & 0x02)); 187 | if ((bitmask & 0x04)) digitalWrite((pin+2), (value & 0x04)); 188 | if ((bitmask & 0x08)) digitalWrite((pin+3), (value & 0x08)); 189 | if ((bitmask & 0x10)) digitalWrite((pin+4), (value & 0x10)); 190 | if ((bitmask & 0x20)) digitalWrite((pin+5), (value & 0x20)); 191 | if ((bitmask & 0x40)) digitalWrite((pin+6), (value & 0x40)); 192 | if ((bitmask & 0x80)) digitalWrite((pin+7), (value & 0x80)); 193 | } 194 | 195 | void setUnusedPinsAsOutput() 196 | { 197 | setPinMode(22,OUTPUT); 198 | for (int16_t i =25;i<35;i++) 199 | setPinMode(i,OUTPUT); 200 | } -------------------------------------------------------------------------------- /uart.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: uart.cpp 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | 14 | #include "config.h" 15 | #include "uart.h" 16 | 17 | 18 | static volatile uint8_t UART0_RxBuf[UART0_RX0_BUFFER_SIZE]; 19 | static volatile uint8_t UART0_LastRxError; 20 | static volatile uint16_t UART0_RxHead; 21 | static volatile uint16_t UART0_RxTail; 22 | 23 | static volatile uint8_t UART1_RxBuf[UART_RX1_BUFFER_SIZE]; 24 | static volatile uint8_t UART1_LastRxError; 25 | static volatile uint16_t UART1_RxHead; 26 | static volatile uint16_t UART1_RxTail; 27 | 28 | 29 | void setupUartLeds() 30 | { 31 | SET_BIT(DDRA,6); 32 | SET_BIT(DDRA,7); 33 | SET_BIT(PORTA,6); 34 | SET_BIT(PORTA,7); 35 | TCCR2|=(1<> 8; 167 | #ifdef PLUS_BOARD 168 | isArduinoRx0BufferOverFlowed = true; 169 | #endif 170 | } else { 171 | /* store new index */ 172 | UART0_RxHead = tmphead; 173 | /* store received data in buffer */ 174 | UART0_RxBuf[tmphead] = data; 175 | } 176 | UART0_LastRxError = lastRxError; 177 | } 178 | 179 | 180 | 181 | int16_t readFromUart1(){ 182 | uint16_t tmptail; 183 | uint8_t data; 184 | 185 | if ( UART1_RxHead == UART1_RxTail ) { 186 | return UART_NO_DATA; /* no data available */ 187 | } 188 | 189 | /* calculate /store buffer index */ 190 | tmptail = (UART1_RxTail + 1) & UART_RX1_BUFFER_MASK; 191 | UART1_RxTail = tmptail; 192 | 193 | /* get data from receive buffer */ 194 | data = UART1_RxBuf[tmptail]; 195 | 196 | return (UART1_LastRxError << 8) + data; 197 | } 198 | 199 | 200 | int16_t getAvailableDataCountOnUart1(){ 201 | return (UART_RX1_BUFFER_SIZE + UART1_RxHead - UART1_RxTail) & UART_RX1_BUFFER_MASK; 202 | } 203 | 204 | ISR (USART1_RXC_vect){ 205 | uint16_t tmphead; 206 | uint8_t data; 207 | uint8_t usr; 208 | uint8_t lastRxError; 209 | 210 | /* read UART status register and UART data register */ 211 | usr = UART1_STATUS; 212 | data = UART1_DATA; 213 | 214 | /* */ 215 | lastRxError = (usr & (_BV(FE1)|_BV(DOR1)) ); 216 | 217 | /* calculate buffer index */ 218 | tmphead = ( UART1_RxHead + 1) & UART_RX1_BUFFER_MASK; 219 | 220 | if ( tmphead == UART1_RxTail ) { 221 | /* error: receive buffer overflow */ 222 | lastRxError = UART_BUFFER_OVERFLOW >> 8; 223 | } else { 224 | /* store new index */ 225 | UART1_RxHead = tmphead; 226 | /* store received data in buffer */ 227 | UART1_RxBuf[tmphead] = data; 228 | } 229 | UART1_LastRxError = lastRxError; 230 | enableTimerOverflow(); 231 | enableRxLedBlinking(); 232 | } 233 | ISR(USART1_TXC_vect) 234 | { 235 | enableTimerOverflow(); 236 | enableTxLedBlinking(); 237 | } 238 | 239 | #ifdef PLUS_BOARD 240 | uint8_t getIsArduinoRx0BufferEmptyFlag() 241 | { 242 | return isArduinoRx0BufferEmpty; 243 | } 244 | 245 | void setIsArduinoRx0BufferEmptyFlag(uint8_t state) 246 | { 247 | isArduinoRx0BufferEmpty = state; 248 | } 249 | 250 | 251 | uint8_t getIsArduinoRx0BufferOverFlowedFlag() 252 | { 253 | return isArduinoRx0BufferOverFlowed; 254 | } 255 | 256 | void setIsArduinoRx0BufferOverFlowedFlag(uint8_t state) 257 | { 258 | isArduinoRx0BufferOverFlowed = state; 259 | } 260 | #endif -------------------------------------------------------------------------------- /onesheeld.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: onesheeld.cpp 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | 14 | #include "config.h" 15 | #include "onesheeld.h" 16 | 17 | void sendArduinoAppDisconnected() 18 | { 19 | uint8_t dataArray[7]={0xff,0x00,0xF0,0x02,0x00,0xff,0x00}; 20 | for (uint16_t i = 0; i < 7; i++) 21 | { 22 | writeOnUart0(dataArray[i]); 23 | } 24 | } 25 | 26 | void initialization() 27 | { 28 | sei(); 29 | setupMillisTimers(); 30 | initFirmata(); 31 | systemReset(); 32 | initUart(1,BAUD_115200); 33 | #ifdef PLUS_BOARD 34 | initUart(0,getSavedBaudRateFromEeprom()); 35 | #endif 36 | #ifdef CLASSIC_BOARD 37 | initUart(0,BAUD_115200); 38 | #endif 39 | setUnusedPinsAsOutput(); 40 | setupUartLeds(); 41 | requestBluetoothReset(); 42 | sendIsAlive(); 43 | } 44 | 45 | void catchTimeForSomeVariables() 46 | { 47 | bluetoothResponseMillis=millis(); 48 | isAliveMillis=millis(); 49 | #ifdef PLUS_BOARD 50 | sentFramesMillis=millis(); 51 | #endif // PLUS_BOARD 52 | } 53 | 54 | void checkDigitalPinStatus() 55 | { 56 | checkDigitalInputs(); 57 | } 58 | 59 | void processDataFromApp() 60 | { 61 | while(available()>0) 62 | { 63 | processInput(); 64 | } 65 | } 66 | 67 | void checkBluetoothResetResponse() 68 | { 69 | if (((newMillis-bluetoothResponseMillis)>=BLUETOOH_RESET_RESPONSE_INTERVAL) && (!bluetoothResetResponded) ) 70 | { 71 | resetBluetooth(); 72 | bluetoothResetResponded = true; 73 | } 74 | } 75 | 76 | void checkAppConnection() 77 | { 78 | if (!notAliveSentToArduino) 79 | { 80 | if((newMillis-isAliveMillis)>=APP_ISALIVE_RESPONSE_INTERVAL) 81 | { 82 | if (!isAppResponded) 83 | { 84 | sendArduinoAppDisconnected(); 85 | notAliveSentToArduino = true; 86 | } 87 | else 88 | { 89 | sendIsAlive(); 90 | isAliveMillis=millis(); 91 | isAppResponded = false; 92 | } 93 | } 94 | } 95 | } 96 | #ifdef PLUS_BOARD 97 | void checkIfPinsChangedSendThem() 98 | { 99 | if(port0StatusChanged)fillBufferWithPinStates(digitalPort0array,0); 100 | if(port1StatusChanged)fillBufferWithPinStates(digitalPort1array,1); 101 | if(port2StatusChanged)fillBufferWithPinStates(digitalPort2array,2); 102 | } 103 | #endif // PLUS_BOARD 104 | 105 | 106 | void sendDataToApp() 107 | { 108 | #ifdef PLUS_BOARD 109 | if ((newMillis-sentFramesMillis)> FRAME_GAP && (muteFirmata==0)) 110 | { 111 | if (getAvailableDataCountOnUart0()>0) 112 | { 113 | if (!toggelingIndicator) 114 | { 115 | toggelingIndicator=true; 116 | } 117 | else 118 | { 119 | checkIfPinsChangedSendThem(); 120 | toggelingIndicator= false; 121 | } 122 | } 123 | else 124 | { 125 | checkIfPinsChangedSendThem(); 126 | } 127 | 128 | processUart0Input(); 129 | if(txBufferIndex!=0) 130 | { 131 | for (uint16_t i=0; i0 && oldPort[numberOfPins]==newPort[numberOfPins]); 191 | return numberOfPins!=0; 192 | } 193 | 194 | void fillBufferWithPinStates(uint8_t * portArray,uint8_t portNumber) 195 | { 196 | if(portNumber == 0) 197 | { 198 | if(checkPortStateEquality(oldDigitalPort0array,portArray,3)){ 199 | isPort0StatusEqual = false; 200 | for(uint16_t i = 0 ;i <3 ; i++) oldDigitalPort0array[i]=portArray[i]; 201 | }else{ 202 | isPort0StatusEqual = true; 203 | } 204 | }else if(portNumber == 1){ 205 | if(checkPortStateEquality(oldDigitalPort1array,portArray,3)){ 206 | isPort1StatusEqual = false; 207 | for(uint16_t i = 0 ;i <3 ; i++) oldDigitalPort1array[i]=portArray[i]; 208 | }else{ 209 | isPort1StatusEqual = true; 210 | } 211 | }else if(portNumber == 2){ 212 | if(checkPortStateEquality(oldDigitalPort2array,portArray,3)){ 213 | isPort2StatusEqual = false; 214 | for(uint16_t i = 0 ;i <3 ; i++) oldDigitalPort2array[i]=portArray[i]; 215 | }else{ 216 | isPort2StatusEqual = true; 217 | } 218 | } 219 | uint8_t bufferIndex = txBufferIndex; 220 | if (bufferIndex+3<20 && ((!isPort0StatusEqual)||(!isPort1StatusEqual)||(!isPort2StatusEqual))){ 221 | uint16_t j = 0; 222 | for (uint16_t i = bufferIndex; i/dev/null; echo; fi 137 | 138 | sizeafter_classic: 139 | @if test -f $(OBJECTDIRCLASSIC)/$(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE_CLASSIC); \ 140 | 2>/dev/null; echo; fi 141 | 142 | sizebefore_plus: 143 | @if test -f $(OBJECTDIRPLUS)/$(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE_PLUS); \ 144 | 2>/dev/null; echo; fi 145 | 146 | sizeafter_plus: 147 | @if test -f $(OBJECTDIRPLUS)/$(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE_PLUS); \ 148 | 2>/dev/null; echo; fi 149 | 150 | # Display compiler version information. 151 | gccversion : 152 | @$(CC) --version 153 | 154 | flashclassic: 155 | avrdude -c usbasp -p m162 -P usb -v -u -D -U efuse:w:0xfb:m -U hfuse:w:0xd8:m -U lfuse:w:0xfd:m -u -U flash:w:$(OBJECTDIRCLASSIC)/$(TARGET).hex 156 | 157 | flashplus: 158 | avrdude -c usbasp -p m162 -P usb -v -u -D -U efuse:w:0xfb:m -U hfuse:w:0xd8:m -U lfuse:w:0xfd:m -u -U flash:w:$(OBJECTDIRPLUS)/$(TARGET).hex 159 | 160 | erase: 161 | avrdude -c usbasp -p m162 -P usb -v -u -e 162 | 163 | # Create final output files (.hex, .eep) from ELF output file. 164 | $(OBJECTDIRCLASSIC)/%.hex: $(OBJECTDIRCLASSIC)/%.elf 165 | @echo 166 | @echo $(MSG_FLASH) $@ 167 | $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "$(OBJECTDIRCLASSIC)/$(TARGET).elf" "$(OBJECTDIRCLASSIC)/$(TARGET).hex" 168 | 169 | 170 | $(OBJECTDIRCLASSIC)/%.eep: $(OBJECTDIRCLASSIC)/%.elf 171 | @echo 172 | @echo $(MSG_EEPROM) $@ 173 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "$(OBJECTDIRCLASSIC)/$(TARGET).elf" "$(OBJECTDIRCLASSIC)/$(TARGET).eep" || exit 0 174 | #-j .eeprom --set-section-flags=.eeprom="alloc,load" \ 175 | #--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0 176 | 177 | # Create extended listing file from ELF output file. 178 | $(OBJECTDIRCLASSIC)/%.lss: $(OBJECTDIRCLASSIC)/%.elf 179 | @echo 180 | @echo $(MSG_EXTENDED_LISTING) $@ 181 | $(OBJDUMP) -h -S -z $< > $@ 182 | 183 | # Create a symbol table from ELF output file. 184 | $(OBJECTDIRCLASSIC)/%.sym: $(OBJECTDIRCLASSIC)/%.elf 185 | @echo 186 | @echo $(MSG_SYMBOL_TABLE) $@ 187 | $(NM) -n $< > $@ 188 | # Create a binary output file from ELF output file 189 | $(OBJECTDIRCLASSIC)/%.bin: $(OBJECTDIRCLASSIC)/%.elf 190 | @echo 191 | @echo $(MSG_BINARY_FILE) $@ 192 | $(OBJCOPY) -O binary $< $@ 193 | 194 | # Link: create ELF output file from object files. 195 | .SECONDARY : $(OBJECTDIRCLASSIC)/$(TARGET).elf 196 | .PRECIOUS : $(OBJCLASSIC) 197 | $(OBJECTDIRCLASSIC)/%.elf: $(OBJCLASSIC) 198 | @echo 199 | @echo $(MSG_LINKING) $< 200 | $(CC) -o $(OBJECTDIRCLASSIC)/$(TARGET).elf $(OBJCLASSIC) $(LDFLAGSCLASSIC) 201 | 202 | # Compile: create object files from C source files. 203 | $(OBJECTDIRCLASSIC)/%.o : %.c 204 | $(shell mkdir build 2>/dev/null) 205 | $(shell mkdir -p $(OBJECTDIRCLASSIC) 2>/dev/null) 206 | @echo 207 | @echo $(MSG_COMPILING) $< 208 | $(CC) -c $(ALL_CFLAGS_CLASSIC) $< -o $@ 209 | ##################################################################################################################### 210 | # Create final output files (.hex, .eep) from ELF output file :Release version. 211 | $(OBJECTDIRPLUS)/%.hex: $(OBJECTDIRPLUS)/%.elf 212 | @echo 213 | @echo $(MSG_FLASH) $@ 214 | $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "$(OBJECTDIRPLUS)/$(TARGET).elf" "$(OBJECTDIRPLUS)/$(TARGET).hex" 215 | 216 | 217 | $(OBJECTDIRPLUS)/%.eep: $(OBJECTDIRPLUS)/%.elf 218 | @echo 219 | @echo $(MSG_EEPROM) $@ 220 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "$(OBJECTDIRPLUS)/$(TARGET).elf" "$(OBJECTDIRPLUS)/$(TARGET).eep" || exit 0 221 | #-j .eeprom --set-section-flags=.eeprom="alloc,load" \ 222 | #--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0 223 | 224 | # Create extended listing file from ELF output file. 225 | $(OBJECTDIRPLUS)/%.lss: $(OBJECTDIRPLUS)/%.elf 226 | @echo 227 | @echo $(MSG_EXTENDED_LISTING) $@ 228 | $(OBJDUMP) -h -S -z $< > $@ 229 | 230 | # Create a symbol table from ELF output file. 231 | $(OBJECTDIRPLUS)/%.sym: $(OBJECTDIRPLUS)/%.elf 232 | @echo 233 | @echo $(MSG_SYMBOL_TABLE) $@ 234 | $(NM) -n $< > $@ 235 | # Create a binary output file from ELF output file 236 | $(OBJECTDIRPLUS)/%.bin: $(OBJECTDIRPLUS)/%.elf 237 | @echo 238 | @echo $(MSG_BINARY_FILE) $@ 239 | $(OBJCOPY) -O binary $< $@ 240 | 241 | # Link: create ELF output file from object files. 242 | .SECONDARY : $(OBJECTDIRPLUS)/$(TARGET).elf 243 | .PRECIOUS : $(OBJPLUS) 244 | $(OBJECTDIRPLUS)/%.elf: $(OBJPLUS) 245 | @echo 246 | @echo $(MSG_LINKING) $< 247 | $(CC) -o $(OBJECTDIRPLUS)/$(TARGET).elf $(OBJPLUS) $(LDFLAGSPLUS) 248 | 249 | # Compile: create object files from C source files. 250 | $(OBJECTDIRPLUS)/%.o : %.c 251 | $(shell mkdir build 2>/dev/null) 252 | $(shell mkdir -p $(OBJECTDIRPLUS) 2>/dev/null) 253 | @echo 254 | @echo $(MSG_COMPILING) $< 255 | $(CC) -c $(ALL_CFLAGS_PLUS) $< -o $@ 256 | ##################################################################################################################### 257 | # Target: clean project. 258 | clean: begin clean_list end 259 | 260 | clean_list : 261 | @echo 262 | @echo $(MSG_CLEANING) 263 | $(REMOVEDIR) build 264 | 265 | # Create object files directory 266 | 267 | 268 | # Listing of phony targets. 269 | .PHONY : all begin finish end sizebefore_classic build_classic sizeafter_classic elf_classic hex_classic eep_classic lss_classic sym_classic bin_classic elf_plus hex_plus eep_plus \ lss_plus sym_plus bin_plus sizebefore_plus build_plus sizeafter_plus clean clean_list flashclassic flashplus erase 270 | 271 | 272 | -------------------------------------------------------------------------------- /firmata.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Project: 1Sheeld Firmware 4 | File: firmata.cpp 5 | 6 | Compiler: avr-gcc 3.4.2 7 | 8 | Author: Integreight 9 | 10 | Date: 2014.5 11 | 12 | */ 13 | 14 | #include "config.h" 15 | #include "firmata.h" 16 | #include 17 | #include 18 | 19 | //****************************************************************************** 20 | //* Support Functions 21 | //****************************************************************************** 22 | 23 | const uint8_t atNameArray[7] PROGMEM = {'A','T','+','N','A','M','E'}; 24 | 25 | void reportDigitalPorts() 26 | { 27 | #ifdef PLUS_BOARD 28 | if((!firstFrameToSend) && txBufferIndex +10 >20) 29 | { 30 | resendDigitalPort = true; 31 | }else 32 | { 33 | resendDigitalPort =false; 34 | outputPort(0, readPort(0, portConfigInputs[0]), true); 35 | outputPort(1, readPort(1, portConfigInputs[1]), true); 36 | outputPort(2, readPort(2, portConfigInputs[2]), true); 37 | } 38 | #endif 39 | #ifdef CLASSIC_BOARD 40 | outputPort(0, readPort(0, portConfigInputs[0]), true); 41 | outputPort(1, readPort(1, portConfigInputs[1]), true); 42 | outputPort(2, readPort(2, portConfigInputs[2]), true); 43 | #endif 44 | } 45 | 46 | void write(uint8_t data) 47 | { 48 | #ifdef PLUS_BOARD 49 | if (txBufferIndex<20) 50 | { 51 | UartTx1Buffer[txBufferIndex]=data; 52 | txBufferIndex++; 53 | } 54 | #endif 55 | #ifdef CLASSIC_BOARD 56 | if (muteFirmata == 0) 57 | { 58 | writeOnUart1(data); 59 | } 60 | #endif 61 | } 62 | 63 | void sendValueAsTwo7bitBytes(int16_t value) 64 | { 65 | write(value & 0b01111111); // LSB 66 | write(value >> 7 & 0b01111111); // MSB 67 | } 68 | 69 | void startSysex(void) 70 | { 71 | write(START_SYSEX); 72 | } 73 | 74 | void endSysex(void) 75 | { 76 | write(END_SYSEX); 77 | } 78 | 79 | 80 | //****************************************************************************** 81 | //* Public Methods 82 | //****************************************************************************** 83 | 84 | void forceHardReset() 85 | { 86 | cli(); 87 | // disable interrupts 88 | wdt_enable(WDTO_15MS); 89 | // enable watchdog 90 | while(1); 91 | // wait for watchdog to reset processor 92 | } 93 | 94 | /* begin method for overriding default serial bitrate */ 95 | void initFirmata() 96 | { 97 | muteFirmata=0;// 1 for rx1,tx1 with 98 | } 99 | 100 | int16_t available(void) 101 | { 102 | return getAvailableDataCountOnUart1(); 103 | } 104 | 105 | void processSysexMessage(void) 106 | { 107 | 108 | sysexCallback(storedInputData[0], sysexBytesRead - 1, storedInputData + 1); 109 | } 110 | 111 | void processUart0Input() 112 | { 113 | #ifdef PLUS_BOARD 114 | if (resendIsAlive) 115 | { 116 | sendIsAlive(); 117 | } 118 | 119 | if(resendDigitalPort) 120 | { 121 | reportDigitalPorts(); 122 | } 123 | 124 | if (resendPrintVersion) 125 | { 126 | printVersion(); 127 | } 128 | 129 | if (resendTestingAnswer) 130 | { 131 | sendAnswerToApplication(); 132 | } 133 | 134 | if (resendCurrentBaudRate) 135 | { 136 | getCurrentUart0BaudRate(); 137 | } 138 | 139 | if(getAvailableDataCountOnUart0()>0) 140 | { 141 | if (txBufferIndex <=15) 142 | { 143 | uint8_t availableBytesInTxBuffer; 144 | availableBytesInTxBuffer = ((20-txBufferIndex)-3)/2; 145 | if(getAvailableDataCountOnUart0()0){ 164 | uint8_t arr[availableData]; 165 | for(uint16_t i=0;i=MAX_DATA_BYTES) { 187 | parsingSysex = false; 188 | } 189 | else{ 190 | //normal data byte - add to buffer 191 | storedInputData[sysexBytesRead] = inputData; 192 | sysexBytesRead++; 193 | } 194 | } else if( (waitForData > 0) && (inputData < 128) ) { 195 | waitForData--; 196 | storedInputData[waitForData] = inputData; 197 | if( (waitForData==0) && executeMultiByteCommand ) { // got the whole message 198 | switch(executeMultiByteCommand) { 199 | case ANALOG_MESSAGE: 200 | analogWriteCallback(multiByteChannel, 201 | (storedInputData[0] << 7) 202 | + storedInputData[1]); 203 | 204 | break; 205 | 206 | case DIGITAL_MESSAGE: 207 | digitalWriteCallback(multiByteChannel, 208 | (storedInputData[0] << 7) 209 | + storedInputData[1]); 210 | 211 | break; 212 | case SET_PIN_MODE: 213 | setPinModeCallback(storedInputData[1], storedInputData[0]); 214 | break; 215 | 216 | case REPORT_DIGITAL: 217 | reportDigitalCallback(multiByteChannel,storedInputData[0]); 218 | break; 219 | } 220 | executeMultiByteCommand = 0; 221 | } 222 | } else { 223 | // remove channel info from command byte if less than 0xF0 224 | if(inputData < 0xF0) { 225 | command = inputData & 0xF0; 226 | multiByteChannel = inputData & 0x0F; 227 | } else { 228 | command = inputData; 229 | // commands in the 0xF* range don't use channel data 230 | } 231 | switch (command) { 232 | 233 | case DIGITAL_MESSAGE: 234 | case ANALOG_MESSAGE: 235 | case SET_PIN_MODE: 236 | waitForData = 2; // two data bytes needed 237 | executeMultiByteCommand = command; 238 | break; 239 | 240 | case REPORT_DIGITAL: 241 | waitForData = 1; // two data bytes needed 242 | executeMultiByteCommand = command; 243 | break; 244 | case START_SYSEX: 245 | parsingSysex = true; 246 | sysexBytesRead = 0; 247 | break; 248 | case REPORT_VERSION: 249 | printVersion(); 250 | break; 251 | case SYSTEM_RESET: 252 | systemReset(); 253 | break; 254 | 255 | } 256 | } 257 | } 258 | 259 | void sendDigitalPort(uint8_t portNumber, int16_t portData) 260 | { 261 | #ifdef PLUS_BOARD 262 | if(portNumber == 0){ 263 | digitalPort0array[0]= DIGITAL_MESSAGE | (portNumber & 0xF); 264 | digitalPort0array[1]= (uint8_t)portData % 128; 265 | digitalPort0array[2]= portData >> 7; 266 | port0StatusChanged =true; 267 | }else if(portNumber == 1){ 268 | digitalPort1array[0]= DIGITAL_MESSAGE | (portNumber & 0xF); 269 | digitalPort1array[1]= (uint8_t)portData % 128; 270 | digitalPort1array[2]= portData >> 7; 271 | port1StatusChanged =true; 272 | }else if(portNumber == 2){ 273 | digitalPort2array[0]= DIGITAL_MESSAGE | (portNumber & 0xF); 274 | digitalPort2array[1]= (uint8_t)portData % 128; 275 | digitalPort2array[2]= portData >> 7; 276 | port2StatusChanged=true; 277 | } 278 | #endif 279 | #ifdef CLASSIC_BOARD 280 | write(DIGITAL_MESSAGE | (portNumber & 0xF)); 281 | write((uint8_t)portData % 128); // Tx bits 0-6 282 | write(portData >> 7); // Tx bits 7-13 283 | #endif 284 | 285 | } 286 | 287 | void sendSysex(uint8_t command, uint8_t bytec, uint8_t* bytev) 288 | { 289 | uint8_t i; 290 | startSysex(); 291 | write(command); 292 | for(i=0; i20)) 312 | { 313 | resendIsAlive = true; 314 | } 315 | else 316 | { 317 | write(START_SYSEX); 318 | write(IS_ALIVE); 319 | write(END_SYSEX); 320 | resendIsAlive = false; 321 | } 322 | #endif 323 | #ifdef CLASSIC_BOARD 324 | write(START_SYSEX); 325 | write(IS_ALIVE); 326 | write(END_SYSEX); 327 | #endif 328 | 329 | } 330 | 331 | //****************************************************************************** 332 | //* Private Methods 333 | //****************************************************************************** 334 | // resets the system state upon a SYSTEM_RESET message from the host software 335 | void systemReset(void) 336 | { 337 | waitForData = 0; // this flag says the next serial input will be data 338 | executeMultiByteCommand = 0; // execute this after getting multi-byte data 339 | multiByteChannel = 0; // channel data for multiByteCommands 340 | parsingSysex = false; 341 | sysexBytesRead = 0; 342 | bluetoothResetResponded=false; 343 | isAppResponded=false; 344 | notAliveSentToArduino=false; 345 | systemResetCallback(); 346 | #ifdef PLUS_BOARD 347 | txBufferIndex = 0; 348 | firstFrameToSend = false; 349 | resendDigitalPort = false; 350 | resendIsAlive = false ; 351 | resendPrintVersion = false; 352 | resendCurrentBaudRate = false; 353 | resendTestingAnswer = false; 354 | setIsArduinoRx0BufferEmptyFlag(true) ; 355 | setIsArduinoRx0BufferOverFlowedFlag(false); 356 | arduinoStopped =false; 357 | port0StatusChanged = false; 358 | port1StatusChanged = false; 359 | port2StatusChanged = false; 360 | isPort0StatusEqual = true; 361 | isPort1StatusEqual = true; 362 | isPort2StatusEqual = true; 363 | toggelingIndicator=false; 364 | #endif 365 | } 366 | 367 | void printVersion() 368 | { 369 | #ifdef PLUS_BOARD 370 | if ((!firstFrameToSend) && (txBufferIndex + 3 >20)) 371 | { 372 | resendPrintVersion = true; 373 | } 374 | else 375 | { 376 | write(REPORT_VERSION); 377 | write(ONESHEELD_MINOR_FIRMWARE_VERSION); 378 | write(ONESHEELD_MAJOR_FIRMWARE_VERSION); 379 | resendPrintVersion = false; 380 | } 381 | #endif 382 | #ifdef CLASSIC_BOARD 383 | write(REPORT_VERSION); 384 | write(ONESHEELD_MINOR_FIRMWARE_VERSION); 385 | write(ONESHEELD_MAJOR_FIRMWARE_VERSION); 386 | #endif 387 | } 388 | 389 | /*============================================================================== 390 | * FUNCTIONS 391 | *============================================================================*/ 392 | 393 | 394 | void outputPort(uint8_t portNumber, uint8_t portValue, uint8_t forceSend) 395 | { 396 | // pins not configured as INPUT are cleared to zeros 397 | portValue = portValue & portConfigInputs[portNumber]; 398 | // only send if the value is different than previously sent 399 | if(forceSend || previousPINs[portNumber] != portValue) { 400 | sendDigitalPort(portNumber, portValue); 401 | previousPINs[portNumber] = portValue; 402 | } 403 | 404 | } 405 | 406 | /* ----------------------------------------------------------------------------- 407 | * check all the active digital inputs for change of state, then add any events 408 | * to the Serial output queue using Serial.print() */ 409 | void checkDigitalInputs(void) 410 | { 411 | /* Using non-looping code allows constants to be given to readPort(). 412 | * The compiler will apply substantial optimizations if the inputs 413 | * to readPort() are compile-time constants. */ 414 | if (reportPINs[0]) outputPort(0, readPort(0, portConfigInputs[0]), false); 415 | if (reportPINs[1]) outputPort(1, readPort(1, portConfigInputs[1]), false); 416 | if (reportPINs[2]) outputPort(2, readPort(2, portConfigInputs[2]), false); 417 | } 418 | 419 | // ----------------------------------------------------------------------------- 420 | /* sets the pin mode to the correct state and sets the relevant bits in the 421 | * two bit-arrays that track Digital I/O and PWM status 422 | */ 423 | void setPinModeCallback(uint8_t pin, int16_t mode) 424 | { 425 | if (IS_PIN_DIGITAL(pin)) { 426 | if (mode == INPUT) { 427 | portConfigInputs[pin/8] |= (1 << (pin & 7)); 428 | } else { 429 | portConfigInputs[pin/8] &= ~(1 << (pin & 7)); 430 | } 431 | } 432 | pinState[pin] = 0; 433 | switch(mode) { 434 | case INPUT: 435 | if (IS_PIN_DIGITAL(pin)) { 436 | setPinMode(pin, INPUT); // disable output driver 437 | digitalWrite(pin, LOW); // disable internal pull-ups 438 | pinConfig[pin] = INPUT; 439 | } 440 | break; 441 | case OUTPUT: 442 | if (IS_PIN_DIGITAL(pin)) { 443 | digitalWrite(pin, LOW); // disable PWM 444 | setPinMode(pin, OUTPUT); 445 | pinConfig[pin] = OUTPUT; 446 | 447 | } 448 | break; 449 | case PWM: 450 | if (IS_PIN_PWM(pin)) { 451 | setPinMode(pin, OUTPUT); 452 | analogWrite(pin, 0); 453 | pinConfig[pin] = PWM; 454 | } 455 | break; 456 | default: 457 | break; 458 | } 459 | } 460 | 461 | void analogWriteCallback(uint8_t pin, int16_t value) 462 | { 463 | if (pin < TOTAL_PINS) { 464 | 465 | if (IS_PIN_PWM(pin)) 466 | analogWrite(pin, value); 467 | pinState[pin] = value; 468 | 469 | } 470 | } 471 | 472 | void digitalWriteCallback(uint8_t port, int16_t value) 473 | { 474 | uint8_t pin, lastPin, mask=1, pinWriteMask=0; 475 | 476 | if (port < TOTAL_PORTS) { 477 | // create a mask of the pins on this port that are writable. 478 | lastPin = port*8+8; 479 | if (lastPin > TOTAL_PINS) lastPin = TOTAL_PINS; 480 | for (pin=port*8; pin < lastPin; pin++) { 481 | // do not disturb non-digital pins (eg, Rx & Tx) 482 | if (IS_PIN_DIGITAL(pin)) { 483 | // only write to OUTPUT and INPUT (enables pullup) 484 | // do not touch pins in PWM, ANALOG, SERVO or other modes 485 | if (pinConfig[pin] == OUTPUT || pinConfig[pin] == INPUT) { 486 | pinWriteMask |= mask; 487 | pinState[pin] = ((uint8_t)value & mask) ? 1 : 0; 488 | } 489 | } 490 | mask = mask << 1; 491 | } 492 | writePort(port, (uint8_t)value, pinWriteMask); 493 | } 494 | } 495 | 496 | void reportDigitalCallback(uint8_t port, int16_t value) 497 | { 498 | if (port < TOTAL_PORTS) { 499 | reportPINs[port] = (uint8_t)value; 500 | } 501 | 502 | } 503 | 504 | /*============================================================================== 505 | * SYSEX-BASED commands 506 | *============================================================================*/ 507 | 508 | void sysexCallback(uint8_t command, uint8_t argc, uint8_t *argv) 509 | { 510 | switch(command) { 511 | case UART_DATA: 512 | { 513 | uint8_t newData [argc/2]; 514 | for (uint16_t i = 0; i < argc; i+=2) // run over and over 515 | { 516 | newData[i/2]=(argv[i]|(argv[i+1]<<7)); 517 | writeOnUart0(newData[i/2]); 518 | } 519 | } 520 | break; 521 | case FIRMATA_MUTE: 522 | { 523 | if ((uint8_t)(argv[0]|(argv[1]<<7))==0) 524 | { 525 | muteFirmata=0; 526 | } 527 | else if ((uint8_t)(argv[0]|(argv[1]<<7))==1) 528 | { 529 | muteFirmata=1; 530 | } 531 | }break; 532 | 533 | case IS_ALIVE: 534 | { 535 | isAppResponded=true; 536 | notAliveSentToArduino=false; 537 | }break; 538 | 539 | case RESET_MICRO: 540 | { 541 | forceHardReset(); 542 | }break; 543 | 544 | case RESET_BLUETOOTH: 545 | { 546 | if ((uint8_t)(argv[0]|argv[1]<<7) &&!(((uint8_t)(argv[2]|argv[3]<<7))&((uint8_t)(argv[4]|argv[5]<<7)))) 547 | { 548 | resetBluetooth(); 549 | } 550 | 551 | bluetoothResetResponded=true; 552 | }break; 553 | 554 | case REPORT_INPUT_PINS: 555 | { 556 | reportDigitalPorts(); 557 | }break; 558 | 559 | case BLUETOOTH_RENAMING: 560 | { 561 | if (argc > 0) 562 | { 563 | _delay_ms(100); 564 | sendBluetoothRenameConfirmation(); 565 | _delay_ms(100); 566 | resetBluetooth(); /* reset bluetooth to enter AT mode. */ 567 | _delay_ms(1000); 568 | sendATNameCommand(); /* send the AT+NAME command to rename the bluetooth. */ 569 | uint8_t newName [argc/2]; /* newName array to re-assemble name from sysex message*/ 570 | for (uint16_t i = 0; i < argc; i+=2) 571 | { 572 | newName[i/2]=(argv[i]|(argv[i+1]<<7)); 573 | writeOnUart1(newName[i/2]); 574 | } /* send New name*/ 575 | _delay_ms(1000); /* 1 Second was chosen to support latecny of HC-06 bluetooth module */ 576 | resetBluetooth(); /* reset the bluetooth again to restart with new configuration. */ 577 | } 578 | }break; 579 | 580 | case TESTING_FRAME: 581 | { 582 | if (argc>0) 583 | { 584 | uint8_t testNumbers [argc/2]; /* newName array to re-assemble name from sysex message*/ 585 | uint16_t sumOfData = 0; 586 | for (uint16_t i = 0; i < argc; i+=2) testNumbers[i/2]=(argv[i]|(argv[i+1]<<7)); 587 | for (uint16_t i =0 ; i< argc/2 ;i++) sumOfData+=testNumbers[i]; 588 | testAnswer = sumOfData%256; 589 | sendAnswerToApplication(); 590 | } 591 | }break; 592 | #ifdef PLUS_BOARD 593 | case SET_UART0_BAUD_RATE: 594 | { 595 | if (argc == 6) 596 | { 597 | uint8_t data [argc/2]; 598 | for (uint16_t i = 0; i < argc; i+=2) data[i/2]=(argv[i]|(argv[i+1]<<7)); 599 | if(!(data[1] & data[2])) 600 | { 601 | //update the new value in eeprom and initialize the uart with the new value 602 | uint8_t newBaudRateValue = data[0]; 603 | updateEeprom(CURRENT_UART0_BAUD_RATE_EEPROM_ADDRESS,newBaudRateValue); 604 | initUart(0,newBaudRateValue); 605 | } 606 | } 607 | }break; 608 | 609 | case QUERY_UART0_BAUD_RATE: 610 | { 611 | getCurrentUart0BaudRate(); 612 | }break; 613 | #endif // PLUS_BOARD 614 | } 615 | } 616 | 617 | #ifdef PLUS_BOARD 618 | void getCurrentUart0BaudRate() 619 | { 620 | uint8_t baudRate = readFromEeprom(CURRENT_UART0_BAUD_RATE_EEPROM_ADDRESS); 621 | if(txBufferIndex + 5 >20) 622 | { 623 | resendCurrentBaudRate = true; 624 | } 625 | else 626 | { 627 | sendSysex(QUERY_UART0_BAUD_RATE,1,&baudRate); 628 | resendCurrentBaudRate = false; 629 | } 630 | } 631 | #endif 632 | 633 | void sendAnswerToApplication() 634 | { 635 | #ifdef PLUS_BOARD 636 | if(txBufferIndex + 5 >20) 637 | { 638 | resendTestingAnswer = true; 639 | } 640 | else 641 | { 642 | sendSysex(TESTING_FRAME,1,&testAnswer); 643 | resendTestingAnswer = false; 644 | } 645 | #endif 646 | #ifdef CLASSIC_BOARD 647 | sendSysex(TESTING_FRAME,1,&testAnswer); 648 | #endif 649 | } 650 | 651 | void sendBluetoothRenameConfirmation() 652 | { 653 | writeOnUart1(START_SYSEX); 654 | writeOnUart1(BLUETOOTH_RENAMING); 655 | writeOnUart1(END_SYSEX); 656 | } 657 | 658 | void sendATNameCommand() 659 | { 660 | for(uint16_t i = 0 ; i < 7 ; i++ )writeOnUart1(pgm_read_byte(&(atNameArray[i]))); 661 | } 662 | 663 | void resetBluetooth() 664 | { 665 | //bt reset 666 | SET_BIT(DDRE,0); 667 | SET_BIT(PORTE,0); 668 | _delay_ms(5); 669 | CLR_BIT(PORTE,0); 670 | } 671 | 672 | void systemResetCallback() 673 | { 674 | for (uint8_t i=0; i < TOTAL_PORTS; i++) { 675 | reportPINs[i] = false; // by default, reporting off 676 | portConfigInputs[i] = 0; // until activated 677 | previousPINs[i] = 0; 678 | } 679 | 680 | for (uint8_t i=0; i < TOTAL_PINS; i++) 681 | { 682 | setPinModeCallback(i, INPUT); 683 | } 684 | } 685 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------