mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
Re-arranging header files and small fixes to optimized core functions.
This commit is contained in:
parent
bb7a044884
commit
4ea2d99c1a
@ -112,6 +112,53 @@ void detachInterrupt(uint8_t);
|
|||||||
void setup(void);
|
void setup(void);
|
||||||
void loop(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 analogInPinToBit(P) (P)
|
||||||
|
|
||||||
|
INLINED uint8_t digitalPinToPort(uint8_t pin) {
|
||||||
|
if (__builtin_constant_p(pin))
|
||||||
|
return inlined_digitalPinToPort(pin);
|
||||||
|
else
|
||||||
|
return pgm_read_byte( digital_pin_to_port_PGM + pin );
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED uint8_t digitalPinToBitMask(uint8_t pin) {
|
||||||
|
if (__builtin_constant_p(pin))
|
||||||
|
return inlined_digitalPinToBitMask(pin);
|
||||||
|
else
|
||||||
|
return pgm_read_byte( digital_pin_to_bit_mask_PGM + pin );
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED uint8_t digitalPinToTimer(uint8_t pin) {
|
||||||
|
if (__builtin_constant_p(pin))
|
||||||
|
return inlined_digitalPinToTimer(pin);
|
||||||
|
else
|
||||||
|
return pgm_read_byte( digital_pin_to_timer_PGM + pin );
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED volatile uint8_t *portOutputRegister(uint8_t index) {
|
||||||
|
if (__builtin_constant_p(index))
|
||||||
|
return inlined_portOutputRegister(index);
|
||||||
|
else
|
||||||
|
return (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + index ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED volatile uint8_t* portInputRegister(uint8_t index) {
|
||||||
|
if (__builtin_constant_p(index))
|
||||||
|
return inlined_portInputRegister(index);
|
||||||
|
else
|
||||||
|
return (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + index) );
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED volatile uint8_t* portModeRegister(uint8_t index) {
|
||||||
|
if (__builtin_constant_p(index))
|
||||||
|
return inlined_portModeRegister(index);
|
||||||
|
else
|
||||||
|
return (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + index) );
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if a given pin requires locking.
|
* Check if a given pin requires locking.
|
||||||
* When accessing lower 32 IO ports we can use SBI/CBI instructions, which are atomic. However
|
* When accessing lower 32 IO ports we can use SBI/CBI instructions, which are atomic. However
|
||||||
@ -127,6 +174,15 @@ INLINED int portWriteNeedsLocking(uint8_t pin)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INLINED int portModeNeedsLocking(uint8_t pin)
|
||||||
|
{
|
||||||
|
/* SBI/CBI instructions only work on lower 32 IO ports */
|
||||||
|
if (inlined_portModeRegister(inlined_digitalPinToPort(pin)) > (volatile uint8_t*)&_SFR_IO8(0x1F)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These functions will perform OR/AND on a given register, and are atomic.
|
* These functions will perform OR/AND on a given register, and are atomic.
|
||||||
*/
|
*/
|
||||||
@ -157,11 +213,19 @@ INLINED void digitalWrite(uint8_t pin, uint8_t value)
|
|||||||
INLINED void pinMode(uint8_t pin, uint8_t mode)
|
INLINED void pinMode(uint8_t pin, uint8_t mode)
|
||||||
{
|
{
|
||||||
if (__builtin_constant_p(pin)) {
|
if (__builtin_constant_p(pin)) {
|
||||||
|
if (portModeNeedsLocking(pin)) {
|
||||||
|
if (mode==INPUT) {
|
||||||
|
__digitalWriteAND_locked(inlined_portModeRegister(inlined_digitalPinToPort(pin)),~inlined_digitalPinToBitMask(pin));
|
||||||
|
} else {
|
||||||
|
__digitalWriteOR_locked(inlined_portModeRegister(inlined_digitalPinToPort(pin)),inlined_digitalPinToBitMask(pin));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (mode==INPUT) {
|
if (mode==INPUT) {
|
||||||
*inlined_portModeRegister(inlined_digitalPinToPort(pin)) &= ~(inlined_digitalPinToBitMask(pin));
|
*inlined_portModeRegister(inlined_digitalPinToPort(pin)) &= ~(inlined_digitalPinToBitMask(pin));
|
||||||
} else {
|
} else {
|
||||||
*inlined_portModeRegister(inlined_digitalPinToPort(pin)) |= inlined_digitalPinToBitMask(pin);
|
*inlined_portModeRegister(inlined_digitalPinToPort(pin)) |= inlined_digitalPinToBitMask(pin);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
pinMode_lookup(pin,mode);
|
pinMode_lookup(pin,mode);
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
#include "wiring.h"
|
|
@ -30,7 +30,6 @@
|
|||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "WConstants.h"
|
|
||||||
#include "wiring_private.h"
|
#include "wiring_private.h"
|
||||||
|
|
||||||
volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
|
volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
|
||||||
|
@ -385,7 +385,7 @@ INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin)
|
|||||||
case 44: return TIMER5C; // PL 5 ** 44 ** D44
|
case 44: return TIMER5C; // PL 5 ** 44 ** D44
|
||||||
case 45: return TIMER5B; // PL 4 ** 45 ** D45
|
case 45: return TIMER5B; // PL 4 ** 45 ** D45
|
||||||
case 46: return TIMER5A; // PL 3 ** 46 ** D46
|
case 46: return TIMER5A; // PL 3 ** 46 ** D46
|
||||||
default: invalidPinSpecified();
|
default: return NOT_ON_TIMER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,57 +494,10 @@ INLINED uint8_t inlined_digitalPinToTimer(uint8_t pin)
|
|||||||
#endif
|
#endif
|
||||||
case 9: return TIMER1A;
|
case 9: return TIMER1A;
|
||||||
case 10: return TIMER1B;
|
case 10: return TIMER1B;
|
||||||
default: invalidPinSpecified();
|
default: return NOT_ON_TIMER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
#endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
|
|
||||||
// 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 analogInPinToBit(P) (P)
|
|
||||||
|
|
||||||
INLINED uint8_t digitalPinToPort(uint8_t pin) {
|
|
||||||
if (__builtin_constant_p(pin))
|
|
||||||
return inlined_digitalPinToPort(pin);
|
|
||||||
else
|
|
||||||
return pgm_read_byte( digital_pin_to_port_PGM + pin );
|
|
||||||
}
|
|
||||||
|
|
||||||
INLINED uint8_t digitalPinToBitMask(uint8_t pin) {
|
|
||||||
if (__builtin_constant_p(pin))
|
|
||||||
return inlined_digitalPinToBitMask(pin);
|
|
||||||
else
|
|
||||||
return pgm_read_byte( digital_pin_to_bit_mask_PGM + pin );
|
|
||||||
}
|
|
||||||
|
|
||||||
INLINED uint8_t digitalPinToTimer(uint8_t pin) {
|
|
||||||
if (__builtin_constant_p(pin))
|
|
||||||
return inlined_digitalPinToTimer(pin);
|
|
||||||
else
|
|
||||||
return pgm_read_byte( digital_pin_to_timer_PGM + pin );
|
|
||||||
}
|
|
||||||
|
|
||||||
INLINED volatile uint8_t *portOutputRegister(uint8_t index) {
|
|
||||||
if (__builtin_constant_p(index))
|
|
||||||
return inlined_portOutputRegister(index);
|
|
||||||
else
|
|
||||||
return (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + index ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
INLINED volatile uint8_t* portInputRegister(uint8_t index) {
|
|
||||||
if (__builtin_constant_p(index))
|
|
||||||
return inlined_portInputRegister(index);
|
|
||||||
else
|
|
||||||
return (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + index) );
|
|
||||||
}
|
|
||||||
|
|
||||||
INLINED volatile uint8_t* portModeRegister(uint8_t index) {
|
|
||||||
if (__builtin_constant_p(index))
|
|
||||||
return inlined_portModeRegister(index);
|
|
||||||
else
|
|
||||||
return (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + index) );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
wiring.h - Partial implementation of the Wiring API for the ATmega8.
|
|
||||||
Part of Arduino - http://www.arduino.cc/
|
|
||||||
|
|
||||||
Copyright (c) 2005-2006 David A. Mellis
|
|
||||||
|
|
||||||
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., 59 Temple Place, Suite 330,
|
|
||||||
Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
$Id$
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef Wiring_h
|
|
||||||
#define Wiring_h
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@ -66,8 +66,8 @@
|
|||||||
#define SYSEX_SAMPLING_INTERVAL 0x7A // same as SAMPLING_INTERVAL
|
#define SYSEX_SAMPLING_INTERVAL 0x7A // same as SAMPLING_INTERVAL
|
||||||
|
|
||||||
// pin modes
|
// pin modes
|
||||||
//#define INPUT 0x00 // defined in wiring.h
|
//#define INPUT 0x00 // defined in Arduino.h
|
||||||
//#define OUTPUT 0x01 // defined in wiring.h
|
//#define OUTPUT 0x01 // defined in Arduino.h
|
||||||
#define ANALOG 0x02 // analog pin in analogInput mode
|
#define ANALOG 0x02 // analog pin in analogInput mode
|
||||||
#define PWM 0x03 // digital pin in PWM output mode
|
#define PWM 0x03 // digital pin in PWM output mode
|
||||||
#define SERVO 0x04 // digital pin in Servo output mode
|
#define SERVO 0x04 // digital pin in Servo output mode
|
||||||
|
Loading…
x
Reference in New Issue
Block a user