PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Committer:
spinal
Date:
Sun Nov 18 15:47:54 2018 +0000
Revision:
64:6e6c6c2b664e
Parent:
8:754a7af30890
added fix for directrectangle()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 8:754a7af30890 1 #ifndef Arduino_h
Pokitto 8:754a7af30890 2 #define Arduino_h
Pokitto 8:754a7af30890 3
Pokitto 8:754a7af30890 4 #include <stdlib.h>
Pokitto 8:754a7af30890 5 #include <string.h>
Pokitto 8:754a7af30890 6 #include <math.h>
Pokitto 8:754a7af30890 7
Pokitto 8:754a7af30890 8 #include "PokittoFakeavr.h"
Pokitto 8:754a7af30890 9
Pokitto 8:754a7af30890 10 #include <stdint.h>
Pokitto 8:754a7af30890 11
Pokitto 8:754a7af30890 12 #include "binary.h"
Pokitto 8:754a7af30890 13
Pokitto 8:754a7af30890 14 #ifdef __cplusplus
Pokitto 8:754a7af30890 15 extern "C"{
Pokitto 8:754a7af30890 16 #endif
Pokitto 8:754a7af30890 17
Pokitto 8:754a7af30890 18 #define HIGH 0x1
Pokitto 8:754a7af30890 19 #define LOW 0x0
Pokitto 8:754a7af30890 20
Pokitto 8:754a7af30890 21 //#define INPUT 0x0
Pokitto 8:754a7af30890 22 //#define OUTPUT 0x1
Pokitto 8:754a7af30890 23 //#define INPUT_PULLUP 0x2
Pokitto 8:754a7af30890 24
Pokitto 8:754a7af30890 25 #define true 0x1
Pokitto 8:754a7af30890 26 #define false 0x0
Pokitto 8:754a7af30890 27
Pokitto 8:754a7af30890 28 #define PI 3.1415926535897932384626433832795
Pokitto 8:754a7af30890 29 #define HALF_PI 1.5707963267948966192313216916398
Pokitto 8:754a7af30890 30 #define TWO_PI 6.283185307179586476925286766559
Pokitto 8:754a7af30890 31 #define DEG_TO_RAD 0.017453292519943295769236907684886
Pokitto 8:754a7af30890 32 #define RAD_TO_DEG 57.295779513082320876798154814105
Pokitto 8:754a7af30890 33
Pokitto 8:754a7af30890 34 #define SERIAL 0x0
Pokitto 8:754a7af30890 35 #define DISPLAY 0x1
Pokitto 8:754a7af30890 36
Pokitto 8:754a7af30890 37 #define LSBFIRST 0
Pokitto 8:754a7af30890 38 #define MSBFIRST 1
Pokitto 8:754a7af30890 39
Pokitto 8:754a7af30890 40 #define CHANGE 1
Pokitto 8:754a7af30890 41 #define FALLING 2
Pokitto 8:754a7af30890 42 #define RISING 3
Pokitto 8:754a7af30890 43
Pokitto 8:754a7af30890 44 #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
Pokitto 8:754a7af30890 45 #define DEFAULT 0
Pokitto 8:754a7af30890 46 #define EXTERNAL 1
Pokitto 8:754a7af30890 47 #define INTERNAL 2
Pokitto 8:754a7af30890 48 #else
Pokitto 8:754a7af30890 49 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
Pokitto 8:754a7af30890 50 #define INTERNAL1V1 2
Pokitto 8:754a7af30890 51 #define INTERNAL2V56 3
Pokitto 8:754a7af30890 52 #else
Pokitto 8:754a7af30890 53 #define INTERNAL 3
Pokitto 8:754a7af30890 54 #endif
Pokitto 8:754a7af30890 55 #define DEFAULT 1
Pokitto 8:754a7af30890 56 #define EXTERNAL 0
Pokitto 8:754a7af30890 57 #endif
Pokitto 8:754a7af30890 58
Pokitto 8:754a7af30890 59 // undefine stdlib's abs if encountered
Pokitto 8:754a7af30890 60 #ifdef abs
Pokitto 8:754a7af30890 61 #undef abs
Pokitto 8:754a7af30890 62 #endif
Pokitto 8:754a7af30890 63
Pokitto 8:754a7af30890 64 #define min(a,b) ((a)<(b)?(a):(b))
Pokitto 8:754a7af30890 65 //#define max(a,b) ((a)>(b)?(a):(b))
Pokitto 8:754a7af30890 66 #define abs(x) ((x)>0?(x):-(x))
Pokitto 8:754a7af30890 67 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
Pokitto 8:754a7af30890 68 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
Pokitto 8:754a7af30890 69 #define radians(deg) ((deg)*DEG_TO_RAD)
Pokitto 8:754a7af30890 70 #define degrees(rad) ((rad)*RAD_TO_DEG)
Pokitto 8:754a7af30890 71 #define sq(x) ((x)*(x))
Pokitto 8:754a7af30890 72
Pokitto 8:754a7af30890 73 #define interrupts() sei()
Pokitto 8:754a7af30890 74 #define noInterrupts() cli()
Pokitto 8:754a7af30890 75
Pokitto 8:754a7af30890 76 #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
Pokitto 8:754a7af30890 77 #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
Pokitto 8:754a7af30890 78 #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
Pokitto 8:754a7af30890 79
Pokitto 8:754a7af30890 80 #define lowByte(w) ((uint8_t) ((w) & 0xff))
Pokitto 8:754a7af30890 81 #define highByte(w) ((uint8_t) ((w) >> 8))
Pokitto 8:754a7af30890 82
Pokitto 8:754a7af30890 83 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
Pokitto 8:754a7af30890 84 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
Pokitto 8:754a7af30890 85 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
Pokitto 8:754a7af30890 86 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
Pokitto 8:754a7af30890 87
Pokitto 8:754a7af30890 88
Pokitto 8:754a7af30890 89 typedef unsigned int word;
Pokitto 8:754a7af30890 90
Pokitto 8:754a7af30890 91 #define bit(b) (1UL << (b))
Pokitto 8:754a7af30890 92
Pokitto 8:754a7af30890 93 typedef bool boolean;
Pokitto 8:754a7af30890 94 typedef uint8_t byte;
Pokitto 8:754a7af30890 95
Pokitto 8:754a7af30890 96 void init(void);
Pokitto 8:754a7af30890 97
Pokitto 8:754a7af30890 98 void pinMode(uint8_t, uint8_t);
Pokitto 8:754a7af30890 99 void digitalWrite(uint8_t, uint8_t);
Pokitto 8:754a7af30890 100 int digitalRead(uint8_t);
Pokitto 8:754a7af30890 101 int analogRead(uint8_t);
Pokitto 8:754a7af30890 102 void analogReference(uint8_t mode);
Pokitto 8:754a7af30890 103 void analogWrite(uint8_t, int);
Pokitto 8:754a7af30890 104
Pokitto 8:754a7af30890 105 unsigned long millis(void);
Pokitto 8:754a7af30890 106 unsigned long micros(void);
Pokitto 8:754a7af30890 107 void delay(unsigned long);
Pokitto 8:754a7af30890 108 void delayMicroseconds(unsigned int us);
Pokitto 8:754a7af30890 109 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
Pokitto 8:754a7af30890 110
Pokitto 8:754a7af30890 111 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
Pokitto 8:754a7af30890 112 uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
Pokitto 8:754a7af30890 113
Pokitto 8:754a7af30890 114 void attachInterrupt(uint8_t, void (*)(void), int mode);
Pokitto 8:754a7af30890 115 void detachInterrupt(uint8_t);
Pokitto 8:754a7af30890 116
Pokitto 8:754a7af30890 117 //extern void setup(void);
Pokitto 8:754a7af30890 118 //extern void loop(void);
Pokitto 8:754a7af30890 119
Pokitto 8:754a7af30890 120 // Get the bit location within the hardware port of the given virtual pin.
Pokitto 8:754a7af30890 121 // This comes from the pins_*.c file for the active board configuration.
Pokitto 8:754a7af30890 122
Pokitto 8:754a7af30890 123 #define analogInPinToBit(P) (P)
Pokitto 8:754a7af30890 124
Pokitto 8:754a7af30890 125 // On the ATmega1280, the addresses of some of the port registers are
Pokitto 8:754a7af30890 126 // greater than 255, so we can't store them in uint8_t's.
Pokitto 8:754a7af30890 127
Pokitto 8:754a7af30890 128 #define PROGMEM
Pokitto 8:754a7af30890 129
Pokitto 8:754a7af30890 130 extern const uint8_t* PROGMEM port_to_mode_PGM[];
Pokitto 8:754a7af30890 131 extern const uint8_t* PROGMEM port_to_input_PGM[];
Pokitto 8:754a7af30890 132 extern const uint8_t* PROGMEM port_to_output_PGM[];
Pokitto 8:754a7af30890 133
Pokitto 8:754a7af30890 134 extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
Pokitto 8:754a7af30890 135 // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
Pokitto 8:754a7af30890 136 extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
Pokitto 8:754a7af30890 137 extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
Pokitto 8:754a7af30890 138
Pokitto 8:754a7af30890 139 // Get the bit location within the hardware port of the given virtual pin.
Pokitto 8:754a7af30890 140 // This comes from the pins_*.c file for the active board configuration.
Pokitto 8:754a7af30890 141 //
Pokitto 8:754a7af30890 142 // These perform slightly better as macros compared to inline functions
Pokitto 8:754a7af30890 143 //
Pokitto 8:754a7af30890 144 #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
Pokitto 8:754a7af30890 145 #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
Pokitto 8:754a7af30890 146 #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
Pokitto 8:754a7af30890 147 #define analogInPinToBit(P) (P)
Pokitto 8:754a7af30890 148 #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
Pokitto 8:754a7af30890 149 #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
Pokitto 8:754a7af30890 150 #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
Pokitto 8:754a7af30890 151
Pokitto 8:754a7af30890 152 #define NOT_A_PIN 0
Pokitto 8:754a7af30890 153 #define NOT_A_PORT 0
Pokitto 8:754a7af30890 154
Pokitto 8:754a7af30890 155 #ifdef ARDUINO_MAIN
Pokitto 8:754a7af30890 156 #define PA 1
Pokitto 8:754a7af30890 157 #define PB 2
Pokitto 8:754a7af30890 158 #define PC 3
Pokitto 8:754a7af30890 159 #define PD 4
Pokitto 8:754a7af30890 160 #define PE 5
Pokitto 8:754a7af30890 161 #define PF 6
Pokitto 8:754a7af30890 162 #define PG 7
Pokitto 8:754a7af30890 163 #define PH 8
Pokitto 8:754a7af30890 164 #define PJ 10
Pokitto 8:754a7af30890 165 #define PK 11
Pokitto 8:754a7af30890 166 #define PL 12
Pokitto 8:754a7af30890 167 #endif
Pokitto 8:754a7af30890 168
Pokitto 8:754a7af30890 169 #define NOT_ON_TIMER 0
Pokitto 8:754a7af30890 170 #define TIMER0A 1
Pokitto 8:754a7af30890 171 #define TIMER0B 2
Pokitto 8:754a7af30890 172 #define TIMER1A 3
Pokitto 8:754a7af30890 173 #define TIMER1B 4
Pokitto 8:754a7af30890 174 #define TIMER2 5
Pokitto 8:754a7af30890 175 #define TIMER2A 6
Pokitto 8:754a7af30890 176 #define TIMER2B 7
Pokitto 8:754a7af30890 177
Pokitto 8:754a7af30890 178 #define TIMER3A 8
Pokitto 8:754a7af30890 179 #define TIMER3B 9
Pokitto 8:754a7af30890 180 #define TIMER3C 10
Pokitto 8:754a7af30890 181 #define TIMER4A 11
Pokitto 8:754a7af30890 182 #define TIMER4B 12
Pokitto 8:754a7af30890 183 #define TIMER4C 13
Pokitto 8:754a7af30890 184 #define TIMER4D 14
Pokitto 8:754a7af30890 185 #define TIMER5A 15
Pokitto 8:754a7af30890 186 #define TIMER5B 16
Pokitto 8:754a7af30890 187 #define TIMER5C 17
Pokitto 8:754a7af30890 188
Pokitto 8:754a7af30890 189 #ifdef __cplusplus
Pokitto 8:754a7af30890 190 } // extern "C"
Pokitto 8:754a7af30890 191 #endif
Pokitto 8:754a7af30890 192
Pokitto 8:754a7af30890 193 #ifdef __cplusplus
Pokitto 8:754a7af30890 194 #include "WCharacter.h"
Pokitto 8:754a7af30890 195 #include "WString.h"
Pokitto 8:754a7af30890 196 //#include "HardwareSerial.h"
Pokitto 8:754a7af30890 197
Pokitto 8:754a7af30890 198 uint16_t makeWord(uint16_t w);
Pokitto 8:754a7af30890 199 uint16_t makeWord(byte h, byte l);
Pokitto 8:754a7af30890 200
Pokitto 8:754a7af30890 201 #define word(...) makeWord(__VA_ARGS__)
Pokitto 8:754a7af30890 202
Pokitto 8:754a7af30890 203 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
Pokitto 8:754a7af30890 204
Pokitto 8:754a7af30890 205 void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
Pokitto 8:754a7af30890 206 void noTone(uint8_t _pin);
Pokitto 8:754a7af30890 207
Pokitto 8:754a7af30890 208 // WMath prototypes
Pokitto 8:754a7af30890 209 long random(long);
Pokitto 8:754a7af30890 210 long random(long, long);
Pokitto 8:754a7af30890 211 void randomSeed(unsigned int);
Pokitto 8:754a7af30890 212 long map(long, long, long, long, long);
Pokitto 8:754a7af30890 213
Pokitto 8:754a7af30890 214 #endif
Pokitto 8:754a7af30890 215
Pokitto 8:754a7af30890 216 #include "pins_arduino.h"
Pokitto 8:754a7af30890 217
Pokitto 8:754a7af30890 218 #endif
Pokitto 8:754a7af30890 219