Skip to content
Snippets Groups Projects
Select Git revision
  • bf9e68e4545e3ea2bad2337985c857500374f551
  • master default protected
2 results

Arduino.h

Blame
  • Arduino.h 2.20 KiB
    /*
     From different classes in https://github.com/arduino/ArduinoCore-avr/tree/master/cores/arduino
     */
    
    #ifndef Arduino_h
    #define Arduino_h
    
    #include <stdlib.h>
    #include <stdbool.h>
    #include <string.h>
    #include <math.h>
    #include "bcm2835.h"
    
    #define INPUT BCM2835_GPIO_FSEL_INPT
    #define OUTPUT BCM2835_GPIO_FSEL_OUTP
    
    #define PI 3.1415926535897932384626433832795
    #define HALF_PI 1.5707963267948966192313216916398
    #define TWO_PI 6.283185307179586476925286766559
    #define DEG_TO_RAD 0.017453292519943295769236907684886
    #define RAD_TO_DEG 57.295779513082320876798154814105
    #define EULER 2.718281828459045235360287471352
    
    #define SERIAL 0x0
    #define DISPLAY 0x1
    
    #define LSBFIRST BCM2835_SPI_BIT_ORDER_LSBFIRST
    #define MSBFIRST BCM2835_SPI_BIT_ORDER_MSBFIRST
    
    #define CHANGE 1
    #define FALLING 2
    #define RISING 3
    
    // undefine stdlib's abs if encountered
    #ifdef abs
    #undef abs
    #endif
    
    #define abs(x) ((x) > 0 ? (x) : -(x))
    #define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
    #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 sq(x) ((x) * (x))
    
    #define clockCyclesPerMicrosecond() (F_CPU / 1000000L)
    #define clockCyclesToMicroseconds(a) ((a) / clockCyclesPerMicrosecond())
    #define microsecondsToClockCycles(a) ((a)*clockCyclesPerMicrosecond())
    
    #define lowByte(w) ((uint8_t)((w)&0xff))
    #define highByte(w) ((uint8_t)((w) >> 8))
    
    #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
    #define bitSet(value, bit) ((value) |= (1UL << (bit)))
    #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
    #define bitToggle(value, bit) ((value) ^= (1UL << (bit)))
    #define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
    #define F(s) s
    #define digitalWrite(pin, val) bcm2835_gpio_write(pin, val)
    #define pinMode(pin, val) bcm2835_gpio_fsel(pin, val)
    #define digitalRead(pin) bcm2835_gpio_lev(pin)
    
    typedef unsigned int word;
    typedef bool boolean;
    typedef uint8_t byte;
    
    unsigned long millis(void);
    unsigned long micros(void);
    
    // // WMath prototypes