50 #ifndef __ARDUINO_CORE_H__
51 #define __ARDUINO_CORE_H__
61 #include "avr/stdlib.h"
62 #include "avr/pgmspace.h"
68 #if RT_VER_NUM < 0x50000
69 #define rt_align(x) ALIGN(x)
70 #define rt_weak RT_WEAK
73 #ifndef RTDUINO_TINY_MODE
74 #include "pins_arduino.h"
77 #if RT_VER_NUM < 0x40101
78 #error "The minimum version requirement of RT-Thread is 4.1.1"
212 #define INPUT_PULLUP 0x2
219 #define INPUT_FLOATING INPUT
226 #define INPUT_PULLDOWN 0x3
233 #define OUTPUT_OPEN_DRAIN 0x4
239 #define PI 3.1415926535897932384626433832795
245 #define HALF_PI 1.5707963267948966192313216916398
251 #define TWO_PI 6.283185307179586476925286766559
257 #define DEG_TO_RAD 0.017453292519943295769236907684886
263 #define RAD_TO_DEG 57.295779513082320876798154814105
269 #define EULER 2.718281828459045235360287471352
298 #define min(a, b) ((a)<(b)?(a):(b))
307 #define max(a, b) ((a)>(b)?(a):(b))
317 #define constrain(amt, low, high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
325 #define radians(deg) ((deg)*DEG_TO_RAD)
333 #define degrees(rad) ((rad)*RAD_TO_DEG)
341 #define sq(x) ((x)*(x))
347 #define _NOP() do { __asm__ volatile ("nop"); } while (0)
354 #define clockCyclesPerMicrosecond() (F_CPU / 1000000L)
361 #define clockCyclesToMicroseconds(a) ((a) / clockCyclesPerMicrosecond())
368 #define microsecondsToClockCycles(a) ((a) * clockCyclesPerMicrosecond())
369 #elif !defined(RTDUINO_TINY_MODE)
373 #warning "Please define F_CPU in pins_arduino.h"
383 #define bit(b) (1UL << (b))
395 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
407 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
416 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
425 #define bitToggle(value, bit) ((value) ^= (1UL << (bit)))
435 #define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
444 #define lowByte(w) ((uint8_t) ((w) & 0xff))
453 #define highByte(w) ((uint8_t) ((w) >> 8))
566 void delay(
unsigned long ms);
582 unsigned long millis(
void);
590 unsigned long micros(
void);
606 unsigned long pulseIn(uint8_t pin, uint8_t state,
unsigned long timeout);
622 unsigned long pulseInLong(uint8_t pin, uint8_t state,
unsigned long timeout);
633 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
644 uint8_t
shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
706 long map(
long x,
long in_min,
long in_max,
long out_min,
long out_max);
732 #ifdef RTDUINO_USING_SPI
739 void switchToSPI(
const char *bus_name);
755 long random(
long max);
765 long random(
long min,
long max);
790 template <
typename T>
791 T
map(T x, T in_min, T in_max, T out_min, T out_max)
793 return (T)(((double)(x - in_min) * (double)(out_max - out_min)) / (
double)((in_max - in_min) + out_min));
803 uint16_t makeWord(uint16_t w);
813 uint16_t makeWord(
byte h,
byte l);
820 #define word(...) makeWord(__VA_ARGS__)
831 unsigned long pulseIn(uint8_t pin, uint8_t state,
unsigned long timeout = 1000000L);
842 unsigned long pulseInLong(uint8_t pin, uint8_t state,
unsigned long timeout = 1000000L);
852 void tone(uint8_t pin,
unsigned int frequency,
unsigned long duration = 0);
860 void noTone(uint8_t pin);
862 #include "WCharacter.h"
864 #include "HardwareSerial.h"
865 #ifdef RTDUINO_USING_USBSERIAL
866 #include "USBSerial.h"
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
Measures the duration of a pulse (in us) on the specified pin.
Definition: wiring_pulse.c:59
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
Shifts in data on a specified data pin using a specified clock pin and bit order.
Definition: wiring_shift.c:37
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
Measures the duration of a pulse (in us) on the specified pin.
Definition: wiring_pulse.c:108
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
Sends out a byte of data on the specified data pin using the specified clock and bit order.
Definition: wiring_shift.c:52
void analogReadResolution(uint8_t bits)
Sets the number of bits of resolution for the analogRead function.
Definition: wiring_analog.c:47
void analogWriteResolution(uint8_t bits)
Sets the number of bits of resolution for the analogWrite function.
Definition: wiring_analog.c:57
void analogWriteFrequency(uint32_t frequency)
Sets the frequency of the PWM on a pin.
Definition: wiring_analog.c:67
int analogRead(uint8_t pin)
Reads the analog input on a specified analog pin.
Definition: wiring_analog.c:144
void analogReference(uint8_t mode)
Configures the reference voltage used for analog input (e.g., external, internal, etc....
Definition: wiring_analog.c:35
void analogWrite(uint8_t pin, int val)
Writes an analog value (PWM wave) to a pin.
Definition: wiring_analog.c:83
unsigned int word
Represents a 16-bit unsigned integer.
Definition: Arduino.h:150
bool boolean
Represents a boolean value (true or false).
Definition: Arduino.h:157
uint8_t byte
Represents an 8-bit unsigned integer.
Definition: Arduino.h:164
void digitalWrite(uint8_t pin, uint8_t val)
Writes a HIGH or a LOW value to a digital pin.
int digitalRead(uint8_t pin)
Reads the value from a specified digital pin, either HIGH or LOW.
void pinMode(uint8_t pin, uint8_t mode)
Configures the specified pin to behave either as an input or an output.
void interrupts(void)
Enables interrupts, allowing the execution of interrupt service routines.
Definition: WInterrupts.c:22
void detachInterrupt(uint8_t interruptNum)
Detaches an interrupt service routine from a specified interrupt.
void noInterrupts(void)
Disables interrupts, preventing the execution of interrupt service routines.
Definition: WInterrupts.c:31
void attachInterrupt(uint8_t interruptNum, void(*userFunc)(void), int mode)
Attaches an interrupt service routine to a specified interrupt.
uint8_t digitalPinToInterrupt(uint8_t pin)
Converts a digital pin number to the corresponding interrupt number.
long map(long x, long in_min, long in_max, long out_min, long out_max)
Maps a value from one range to another.
Definition: WMath_c.c:44
#define min(a, b)
Returns the smaller of two values.
Definition: Arduino.h:298
#define max(a, b)
Returns the larger of two values.
Definition: Arduino.h:307
void randomSeed(unsigned long seed)
Initializes the pseudo-random number generator.
Definition: WMath_c.c:36
void loop(void)
Main loop function for the Arduino program.
void initVariant(void)
Variant-specific initialization function.
Definition: RTduino.cpp:142
void setup(void)
Initialization function for the Arduino environment.
unsigned long millis(void)
Returns the number of milliseconds since the Arduino board began running the current program.
Definition: wiring.c:25
void delayMicroseconds(unsigned int us)
Delays the program for the specified number of microseconds.
Definition: wiring.c:64
void delay(unsigned long ms)
Delays the program for the specified number of milliseconds.
Definition: wiring.c:59
unsigned long micros(void)
Returns the number of microseconds since the Arduino board began running the current program.
Definition: wiring.c:30
void yield(void)
Pauses the execution of the current task, allowing other tasks to run.
Definition: wiring.c:69
RTduino pin map structure.
Definition: Arduino.h:138
uint8_t arduino_pin
Definition: Arduino.h:139
rt_base_t rt_pin
Definition: Arduino.h:140
const char * device_name
Definition: Arduino.h:141
rt_int8_t channel
Definition: Arduino.h:142