// ARDUINO Compatibility layer by Jonathan Schemoul // Parts of code from: // - friendly Launchpad : http://github.com/chrishulbert/friendly_launchpad // - WIRING project // License: LGPL #ifndef __ARDUINO_COMPAT_H #define __ARDUINO_COMPAT_H #include #include #include #include extern int16_t P1VAL[8]; #ifdef P2OUT extern int16_t P2VAL[8]; #endif #ifdef P3OUT extern int16_t P3VAL[8]; #endif #ifdef P4OUT extern int16_t P4VAL[8]; #endif #ifdef P5OUT extern int16_t P5VAL[8]; #endif #ifdef P6OUT extern int16_t P6VAL[8]; #endif #ifdef P7OUT extern int16_t P7VAL[8]; #endif #ifdef P8OUT extern int16_t P8VAL[8]; #endif #ifdef P9OUT extern int16_t P9VAL[8]; #endif #define interrupt(x) void __attribute__((interrupt (x))) void * realloc ( void * base , size_t t ); // Random defines #define HIGH 1 #define LOW 0 #define OUTPUT 1 #define INPUT 0 extern const uint8_t BITS[]; // My functions #define pinOutputRegister(pin) *(ports[(pin/10)-1].out) #define pinInputRegister(pin) port_to_input_PGM[(pin/10)-1] #define pinModeRegister(pin) *(ports[(pin/10)-1].dir) #define pinPWMRegister(pin) port_to_pwm_PGM[(pin/10)-1] #define pinBit(pin) (BITS[pin]) //#define pinMode(pin, mode) {if(mode){P1DIR|=(1<<(pin-10));}else{P1DIR&=~(1<<(pin-10));}} //#define digitalWrite(pin, mode) {if(mode){P1OUT |= (1<<(pin-10));}else{P1OUT&=~(1<<(pin-10));}} // Arduino-ish functions //#define delay(milliseconds) for(int x=0;x sfrw(TA0CCR0, TA0CCR0_); #define TACCR0 TA0CCR0 #endif*/ #define TACCR0 TA0CCR0 #endif #ifndef TACTL #define TACTL TA0CTL #endif #ifndef TACTL #define TACTL TA0CTL #endif #ifndef TACCTL0 #define TACCTL0 TA0CCTL0 #endif void msp430_init_dco(); void SetVcoreUp (unsigned int level); void Port_Mapping(void); extern int timer_cycles; void start_timers(); // The main loop void setup(); void loop(); int main(void); void analogWrite(int pin, int value); extern int pwm_counter; void change_pwm_frequency(int new_value); #endif // #ifndef __ARDUINO_COMPAT_H #ifndef __WIRING_MASHUP #define __WIRING_MASHUP #include #include #include #ifndef WCONSTANTS_H #define WCONSTANTS_H // Wiring API version for libraries // this is passed in at compile-time #ifndef WIRING #define WIRING 100 #endif // passed in at compile-time #ifndef F_CPU #define F_CPU 16000000L //#warning "F_CPU was not defined. Default to 16 MHz." #endif #define F_CPU_MCS F_CPU / 10000000 #define F_CPU_MS F_CPU / 10000 /************************************************************* * Constants *************************************************************/ //#define LOW 0x0 //#define HIGH 0x1 //#define HIGH 0xFF //#define INPUT 0x0 //#define OUTPUT 0x1 //#define OUTPUT 0xFF #define CHANGE 1 #define FALLING 2 #define RISING 3 #define LSBFIRST 0x0 #define MSBFIRST 0x1 #define true 0x1 #define false 0x0 #define TRUE 0x1 #define FALSE 0x0 #define null NULL #define DEC 10 #define HEX 16 #define OCT 8 #define BIN 2 #define BYTE 0 #define PI (3.1415926535897932384626433832795) #define TWO_PI (6.283185307179586476925286766559) #define HALF_PI (1.5707963267948966192313216916398) #define EPSILON (0.0001) #define DEG_TO_RAD (0.017453292519943295769236907684886) #define RAD_TO_DEG (57.295779513082320876798154814105) /************************************************************* * Digital Constants *************************************************************/ #define PORT0 0 #define PORT1 1 #define PORT2 2 #define PORT3 3 #define PORT4 4 #define PORT5 5 #define PORT6 6 #define PORT7 7 #define PORT8 8 #define PORT9 9 /************************************************************* * Useful macros *************************************************************/ /*#define int(x) ((int)(x)) #define char(x) ((char)(x)) #define long(x) ((long)(x)) #define byte(x) ((uint8_t)(x)) #define float(x) ((float)(x)) #define boolean(x) ((uint8_t)((x)==0?false:true)) */ // Delays by the specified Milliseconds void delay(unsigned int ms); void delayMicroseconds(unsigned int mcs); #define word(...) makeWord(__VA_ARGS__) #define sq(x) ((x)*(x)) //#define abs(x) ((x)>0?(x):-(x)) #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) //#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define radians(deg) ((deg)*DEG_TO_RAD) #define degrees(rad) ((rad)*RAD_TO_DEG) #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) #define bit(x) (1UL<<(x)) #define setBits(x, y) ((x)|=(y)) #define clearBits(x, y) ((x)&=(~(y))) //#define setBit(x, y) setBits((x), (bit((y)))) //#define clearBit(x, y) clearBits((x), (bit((y)))) #define bitsSet(x,y) (((x) & (y)) == (y)) #define bitsClear(x,y) (((x) & (y)) == 0) #define bitRead(value, bit) (((value) >> (bit)) & 0x01) #define bitSet(value, bit) ((value) |= (1UL << (bit))) #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) #define lowByte(x) ((uint8_t) ((x) & 0x00ff)) #define highByte(x) ((uint8_t) ((x)>>8)) #define clockCyclesPerMicrosecond() (F_CPU / 1000000L) #define clockCyclesToMicroseconds(a) ((a) / clockCyclesPerMicrosecond()) #define microsecondsToClockCycles(a) ((a) * clockCyclesPerMicrosecond()) /*#ifdef rand void randomSeed(uint16_t seed) { if (seed != 0) srand(seed); } int32_t random(int32_t howbig) { if (howbig == 0) return 0; return rand() % howbig; } #endif #ifndef rand*/ extern unsigned long RAND_NEXT; int random(int32_t howsmall, int32_t howbig); int random(int32_t howbig); void randomSeed(unsigned seed); #define rand random #define srand randomSeed //#endif int32_t map(int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max); uint16_t makeWord(uint16_t w); uint16_t makeWord(uint8_t highByte, uint8_t lowByte); /************************************************************* * Typedefs *************************************************************/ typedef unsigned int word; typedef uint8_t byte; typedef uint8_t boolean; typedef void (*voidFuncPtr)(void); #endif // WCONSTANTS_H uint16_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t count, uint8_t delayTime); void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint16_t val, uint8_t count, uint8_t delayTime); #endif // #ifndef __WIRING_MASHUP