1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-14 08:03:09 +03:00

Cleaning up the core (modified version of a patch by Jim Studt): moving pin definitions to program space to save RAM, changing core function arguments (e.g. pinMode(), digitalWrite()) to uint8_t, restoring old SREG after delayMicroseconds() instead of always enabling interrupts, etc.

This commit is contained in:
David A. Mellis
2007-04-20 23:17:38 +00:00
parent 440033c814
commit d277488310
13 changed files with 257 additions and 337 deletions

View File

@@ -24,39 +24,33 @@
#include <avr/io.h>
#include "wiring_private.h"
#include "pins_arduino.h"
// On the Arduino board, digital pins are also used
// for the analog output (software PWM). Analog input
// pins are a separate set.
// ATMEL ATMEGA8 / ARDUINO
// ATMEL ATMEGA8 & 168 / ARDUINO
//
// +-\/-+
// PC6 1| |28 PC5 (AI 5)
// (D 0) PD0 2| |27 PC4 (AI 4)
// (D 1) PD1 3| |26 PC3 (AI 3)
// (D 2) PD2 4| |25 PC2 (AI 2)
// (D 3) PD3 5| |24 PC1 (AI 1)
// (D 4) PD4 6| |23 PC0 (AI 0)
// VCC 7| |22 GND
// GND 8| |21 AREF
// PB6 9| |20 AVCC
// PB7 10| |19 PB5 (D 13)
// (D 5) PD5 11| |18 PB4 (D 12)
// (D 6) PD6 12| |17 PB3 (D 11) PWM
// (D 7) PD7 13| |16 PB2 (D 10) PWM
// (D 8) PB0 14| |15 PB1 (D 9) PWM
// +----+
// +-\/-+
// PC6 1| |28 PC5 (AI 5)
// (D 0) PD0 2| |27 PC4 (AI 4)
// (D 1) PD1 3| |26 PC3 (AI 3)
// (D 2) PD2 4| |25 PC2 (AI 2)
// PWM+ (D 3) PD3 5| |24 PC1 (AI 1)
// (D 4) PD4 6| |23 PC0 (AI 0)
// VCC 7| |22 GND
// GND 8| |21 AREF
// PB6 9| |20 AVCC
// PB7 10| |19 PB5 (D 13)
// PWM+ (D 5) PD5 11| |18 PB4 (D 12)
// PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM
// (D 7) PD7 13| |16 PB2 (D 10) PWM
// (D 8) PB0 14| |15 PB1 (D 9) PWM
// +----+
//
// (PWM+ indicates the additional PWM pins on the ATmega168.)
#define NUM_DIGITAL_PINS 14
#define NUM_ANALOG_OUT_PINS 11
#if defined(__AVR_ATmega168__)
#define NUM_ANALOG_IN_PINS 8
#else
#define NUM_ANALOG_IN_PINS 6
#endif
#define NUM_PORTS 4
#define PB 2
#define PC 3
@@ -65,53 +59,78 @@
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
int port_to_mode[NUM_PORTS + 1] = {
const uint8_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(DDRB),
_SFR_IO_ADDR(DDRC),
_SFR_IO_ADDR(DDRD),
&DDRB,
&DDRC,
&DDRD,
};
int port_to_output[NUM_PORTS + 1] = {
const uint8_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(PORTB),
_SFR_IO_ADDR(PORTC),
_SFR_IO_ADDR(PORTD),
&PORTB,
&PORTC,
&PORTD,
};
int port_to_input[NUM_PORTS + 1] = {
const uint8_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
_SFR_IO_ADDR(PINB),
_SFR_IO_ADDR(PINC),
_SFR_IO_ADDR(PIND),
&PINB,
&PINC,
&PIND,
};
// these arrays map the pin numbers on the arduino
// board to the atmega8 port and pin numbers
pin_t digital_pin_to_port_array[NUM_DIGITAL_PINS] = {
{ PD, 0 },
{ PD, 1 },
{ PD, 2 },
{ PD, 3 },
{ PD, 4 },
{ PD, 5 },
{ PD, 6 },
{ PD, 7 },
{ PB, 0 },
{ PB, 1 },
{ PB, 2 },
{ PB, 3 },
{ PB, 4 },
{ PB, 5 },
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, /* 0 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PB, /* 8 */
PB,
PB,
PB,
PB,
PB,
PC, /* 14 */
PC,
PC,
PC,
PC,
PC,
};
pin_t *digital_pin_to_port = digital_pin_to_port_array;
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), /* 0, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(0), /* 14, port C */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
};
int analog_out_pin_to_timer_array[NUM_DIGITAL_PINS] = {
NOT_ON_TIMER,
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER, /* 0 - port D */
NOT_ON_TIMER,
NOT_ON_TIMER,
// on the ATmega168, digital pin 3 has hardware pwm
@@ -130,7 +149,7 @@ int analog_out_pin_to_timer_array[NUM_DIGITAL_PINS] = {
NOT_ON_TIMER,
#endif
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 8 - port B */
TIMER1A,
TIMER1B,
#if defined(__AVR_ATmega168__)
@@ -140,42 +159,11 @@ int analog_out_pin_to_timer_array[NUM_DIGITAL_PINS] = {
#endif
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 14 - port C */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
};
int *analog_out_pin_to_timer = analog_out_pin_to_timer_array;
/*
// Some of the digital pins also support hardware PWM (analog output).
pin_t analog_out_pin_to_port_array[NUM_DIGITAL_PINS] = {
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
{ PB, 1 },
{ PB, 2 },
{ PB, 3 },
{ NOT_A_PIN, NOT_A_PIN },
{ NOT_A_PIN, NOT_A_PIN },
};
pin_t *analog_out_pin_to_port = analog_out_pin_to_port_array;
*/
pin_t analog_in_pin_to_port_array[NUM_ANALOG_IN_PINS] = {
{ PC, 0 },
{ PC, 1 },
{ PC, 2 },
{ PC, 3 },
{ PC, 4 },
{ PC, 5 },
#if defined(__AVR_ATmega168__)
{ NOT_A_PIN, 6 },
{ NOT_A_PIN, 7 },
#endif
};
pin_t *analog_in_pin_to_port = analog_in_pin_to_port_array;