mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
241 lines
6.8 KiB
C
241 lines
6.8 KiB
C
/*
|
|
Arduino.h - Main include file for the Arduino SDK
|
|
Copyright (c) 2005-2013 Arduino Team. All right reserved.
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#ifndef Arduino_h
|
|
#define Arduino_h
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
|
|
#include "stdlib_noniso.h"
|
|
#include "binary.h"
|
|
#include "pgmspace.h"
|
|
#include "esp8266_peri.h"
|
|
#include "twi.h"
|
|
|
|
void yield(void);
|
|
|
|
#define HIGH 0x1
|
|
#define LOW 0x0
|
|
|
|
#define PWMRANGE 1023
|
|
|
|
//GPIO FUNCTIONS
|
|
#define INPUT 0x00
|
|
#define INPUT_PULLUP 0x02
|
|
#define INPUT_PULLDOWN 0x04
|
|
#define OUTPUT 0x01
|
|
#define OUTPUT_OPEN_DRAIN 0x03
|
|
#define SPECIAL 0xF8 //defaults to the usable BUSes uart0rx/tx uart1tx and hspi
|
|
#define FUNCTION_0 0x08
|
|
#define FUNCTION_1 0x18
|
|
#define FUNCTION_2 0x28
|
|
#define FUNCTION_3 0x38
|
|
#define FUNCTION_4 0x48
|
|
|
|
#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 0
|
|
#define MSBFIRST 1
|
|
|
|
//Interrupt Modes
|
|
#define DISABLED 0x00
|
|
#define RISING 0x01
|
|
#define FALLING 0x02
|
|
#define CHANGE 0x03
|
|
#define ONLOW 0x04
|
|
#define ONHIGH 0x05
|
|
#define ONLOW_WE 0x0C
|
|
#define ONHIGH_WE 0x0D
|
|
|
|
#define DEFAULT 1
|
|
#define EXTERNAL 0
|
|
|
|
//timer dividers
|
|
#define TIM_DIV1 0 //80MHz (80 ticks/us - 104857.588 us max)
|
|
#define TIM_DIV16 1 //5MHz (5 ticks/us - 1677721.4 us max)
|
|
#define TIM_DIV265 3 //312.5Khz (1 tick = 3.2us - 26843542.4 us max)
|
|
//timer int_types
|
|
#define TIM_EDGE 0
|
|
#define TIM_LEVEL 1
|
|
//timer reload values
|
|
#define TIM_SINGLE 0 //on interrupt routine you need to write a new value to start the timer again
|
|
#define TIM_LOOP 1 //on interrupt the counter will start with the same value again
|
|
|
|
#define timer1_read() (T1V)
|
|
#define timer1_enabled() ((T1C & (1 << TCTE)) != 0)
|
|
#define timer1_interrupted() ((T1C & (1 << TCIS)) != 0)
|
|
|
|
void timer1_isr_init(void);
|
|
void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload);
|
|
void timer1_disable(void);
|
|
void timer1_attachInterrupt(void (*userFunc)(void));
|
|
void timer1_detachInterrupt(void);
|
|
void timer1_write(uint32_t ticks); //maximum ticks 8388607
|
|
|
|
// 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))
|
|
|
|
void ets_intr_lock();
|
|
void ets_intr_unlock();
|
|
|
|
// level (0-15),
|
|
// level 15 will disable ALL interrupts,
|
|
// level 0 will disable most software interrupts
|
|
//
|
|
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) "; esync; isync; dsync" : "=a" (state))
|
|
#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; esync" :: "a" (state) : "memory")
|
|
|
|
extern uint32_t interruptsState;
|
|
|
|
#define interrupts() xt_enable_interrupts(interruptsState)
|
|
#define noInterrupts() __asm__ __volatile__("rsil %0,15; esync; isync; dsync" : "=a" (interruptsState))
|
|
|
|
#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 bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
|
|
|
|
// avr-libc defines _NOP() since 1.6.2
|
|
#ifndef _NOP
|
|
#define _NOP() do { __asm__ volatile ("nop"); } while (0)
|
|
#endif
|
|
|
|
typedef unsigned int word;
|
|
|
|
#define bit(b) (1UL << (b))
|
|
#define _BV(b) (1UL << (b))
|
|
|
|
typedef uint8_t boolean;
|
|
typedef uint8_t byte;
|
|
|
|
void init(void);
|
|
void initVariant(void);
|
|
|
|
int atexit(void (*func)()) __attribute__((weak));
|
|
|
|
void pinMode(uint8_t, uint8_t);
|
|
void digitalWrite(uint8_t, uint8_t);
|
|
int digitalRead(uint8_t);
|
|
int analogRead(uint8_t);
|
|
void analogReference(uint8_t mode);
|
|
void analogWrite(uint8_t, int);
|
|
void analogWriteFreq(uint32_t freq);
|
|
|
|
unsigned long millis(void);
|
|
unsigned long micros(void);
|
|
void delay(unsigned long);
|
|
void delayMicroseconds(unsigned int us);
|
|
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
|
|
|
|
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
|
|
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
|
|
|
|
void attachInterrupt(uint8_t, void (*)(void), int mode);
|
|
void detachInterrupt(uint8_t);
|
|
|
|
void setup(void);
|
|
void loop(void);
|
|
|
|
// Get the bit location within the hardware port of the given virtual pin.
|
|
// This comes from the pins_*.c file for the active board configuration.
|
|
#define digitalPinToPort(pin) (0)
|
|
#define digitalPinToBitMask(pin) (1UL << (pin))
|
|
#define portOutputRegister(port) ((volatile uint32_t*) GPO)
|
|
#define portInputRegister(port) ((volatile uint32_t*) GPI)
|
|
#define portModeRegister(port) ((volatile uint32_t*) GPE)
|
|
|
|
#define NOT_A_PIN -1
|
|
#define NOT_A_PORT -1
|
|
#define NOT_AN_INTERRUPT -1
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#include "WCharacter.h"
|
|
#include "WString.h"
|
|
|
|
#include "HardwareSerial.h"
|
|
#include "FileSystem.h"
|
|
#include "Esp.h"
|
|
#include "debug.h"
|
|
|
|
#define min(a,b) ((a)<(b)?(a):(b))
|
|
#define max(a,b) ((a)>(b)?(a):(b))
|
|
|
|
uint16_t makeWord(uint16_t w);
|
|
uint16_t makeWord(byte h, byte l);
|
|
|
|
#define word(...) makeWord(__VA_ARGS__)
|
|
|
|
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
|
|
|
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
|
|
void noTone(uint8_t _pin);
|
|
|
|
// WMath prototypes
|
|
long random(long);
|
|
long random(long, long);
|
|
void randomSeed(unsigned int);
|
|
long map(long, long, long, long, long);
|
|
|
|
|
|
#endif
|
|
|
|
#include "pins_arduino.h"
|
|
|
|
#endif
|