mirror of
https://github.com/digistump/DigistumpArduino.git
synced 2025-09-17 17:32:25 -07:00
switch to setup for Arduino Boards Manager
This commit is contained in:
321
digistump-avr/variants/digispark/pins_arduino.c
Normal file
321
digistump-avr/variants/digispark/pins_arduino.c
Normal file
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
pins_arduino.c - pin definitions for the Arduino board
|
||||
Part of Arduino / Wiring Lite
|
||||
|
||||
Copyright (c) 2005 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: pins_arduino.c 565 2009-03-25 10:50:00Z dmellis $
|
||||
|
||||
Modified 28-08-2009 for attiny84 R.Wiersma
|
||||
Modified 09-10-2009 for attiny45 A.Saporetti
|
||||
Modified for Atmel ATTiny2313 mcu by Ren<65> Bohne
|
||||
|
||||
Corrected 17-05-2010 for ATtiny84 B.Cook ...
|
||||
|
||||
The default analog_reference leaves chip pin 13 (digital pin 10; PA0)
|
||||
unconnected. So the pin can be set to a non-floating state and so the
|
||||
pin can be used as another digital pin, support for digital pin 10 was
|
||||
added.
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include "pins_arduino.h"
|
||||
#include "wiring_private.h"
|
||||
|
||||
|
||||
#if defined( __AVR_ATtinyX313__ )
|
||||
|
||||
// On the Arduino board, digital pins are also used
|
||||
// for the analog output (software PWM). Analog input
|
||||
// pins are a separate set.
|
||||
|
||||
// ATMEL ATTINY2313
|
||||
//
|
||||
// +-\/-+
|
||||
// (D 17) PA2 1| |29 VCC
|
||||
// RX (D 0) PD0 2| |19 PB7 (D 16)
|
||||
// TX (D 1) PD1 3| |18 PB6 (D 15)
|
||||
// (D 2) PA1 4| |17 PB5 (D 14)
|
||||
// (D 3) PA0 5| |16 PB4 (D 13)*
|
||||
// INT0 (D 4) PD2 6| |15 PB3 (D 12)*
|
||||
// INT1 (D 5) PD3 7| |14 PB2 (D 11)*
|
||||
// (D 6) PD4 8| |13 PB1 (D 10)
|
||||
// *(D 7) PD5 9| |12 PB0 (D 9)
|
||||
// GND 10| |11 PD6 (D 8)
|
||||
// +----+
|
||||
//
|
||||
// * indicates PWM port
|
||||
|
||||
// these arrays map port names (e.g. port B) to the
|
||||
// appropriate addresses for various functions (e.g. reading
|
||||
// and writing)
|
||||
const uint8_t PROGMEM port_to_mode_PGM[] =
|
||||
{
|
||||
NOT_A_PORT,
|
||||
&DDRA,
|
||||
&DDRB,
|
||||
NOT_A_PORT,
|
||||
&DDRD,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM port_to_output_PGM[] =
|
||||
{
|
||||
NOT_A_PORT,
|
||||
&PORTA,
|
||||
&PORTB,
|
||||
NOT_A_PORT,
|
||||
&PORTD,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM port_to_input_PGM[] =
|
||||
{
|
||||
NOT_A_PORT,
|
||||
&PINA,
|
||||
&PINB,
|
||||
NOT_A_PORT,
|
||||
&PIND,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM digital_pin_to_port_PGM[] =
|
||||
{
|
||||
PORT_D_ID, /* 0 */
|
||||
PORT_D_ID,
|
||||
PORT_A_ID,
|
||||
PORT_A_ID,
|
||||
PORT_D_ID,
|
||||
PORT_D_ID,
|
||||
PORT_D_ID,
|
||||
PORT_D_ID,
|
||||
PORT_D_ID, /* 8 */
|
||||
PORT_B_ID,
|
||||
PORT_B_ID,
|
||||
PORT_B_ID,
|
||||
PORT_B_ID,
|
||||
PORT_B_ID,
|
||||
PORT_B_ID, /* 14 */
|
||||
PORT_B_ID,
|
||||
PORT_B_ID,
|
||||
PORT_A_ID,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
|
||||
{
|
||||
_BV(0), /* 0 */
|
||||
_BV(1),
|
||||
_BV(1),
|
||||
_BV(0),
|
||||
_BV(2),
|
||||
_BV(3),
|
||||
_BV(4),
|
||||
_BV(5),
|
||||
_BV(6), /* 8 */
|
||||
_BV(0),
|
||||
_BV(1),
|
||||
_BV(2),
|
||||
_BV(3),
|
||||
_BV(4),
|
||||
_BV(5), /* 14 */
|
||||
_BV(6),
|
||||
_BV(7),
|
||||
_BV(2),
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
|
||||
{
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
TIMER0B,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
TIMER0A,
|
||||
TIMER1A,
|
||||
TIMER1B,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined( __AVR_ATtinyX4__ )
|
||||
|
||||
// ATMEL ATTINY84 / ARDUINO
|
||||
//
|
||||
// +-\/-+
|
||||
// VCC 1| |14 GND
|
||||
// (D 0) PB0 2| |13 AREF (D 10)
|
||||
// (D 1) PB1 3| |12 PA1 (D 9)
|
||||
// PB3 4| |11 PA2 (D 8)
|
||||
// PWM INT0 (D 2) PB2 5| |10 PA3 (D 7)
|
||||
// PWM (D 3) PA7 6| |9 PA4 (D 6)
|
||||
// PWM (D 4) PA6 7| |8 PA5 (D 5) PWM
|
||||
// +----+
|
||||
|
||||
// these arrays map port names (e.g. port B) to the
|
||||
// appropriate addresses for various functions (e.g. reading
|
||||
// and writing)
|
||||
const uint8_t PROGMEM port_to_mode_PGM[] =
|
||||
{
|
||||
NOT_A_PORT,
|
||||
&DDRA,
|
||||
&DDRB,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM port_to_output_PGM[] =
|
||||
{
|
||||
NOT_A_PORT,
|
||||
&PORTA,
|
||||
&PORTB,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM port_to_input_PGM[] =
|
||||
{
|
||||
NOT_A_PORT,
|
||||
&PINA,
|
||||
&PINB,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM port_to_pcmask_PGM[] =
|
||||
{
|
||||
NOT_A_PORT,
|
||||
&PCMSK0,
|
||||
&PCMSK1,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM digital_pin_to_port_PGM[] =
|
||||
{
|
||||
PORT_B_ID, /* 0 */
|
||||
PORT_B_ID,
|
||||
PORT_B_ID,
|
||||
PORT_A_ID,
|
||||
PORT_A_ID,
|
||||
PORT_A_ID,
|
||||
PORT_A_ID,
|
||||
PORT_A_ID,
|
||||
PORT_A_ID, /* 8 */
|
||||
PORT_A_ID,
|
||||
PORT_A_ID,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
|
||||
{
|
||||
_BV(0), /* 0, port B */
|
||||
_BV(1),
|
||||
_BV(2),
|
||||
_BV(7), /* 3 port B */
|
||||
_BV(6),
|
||||
_BV(5),
|
||||
_BV(4),
|
||||
_BV(3),
|
||||
_BV(2),
|
||||
_BV(1),
|
||||
_BV(0),
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
|
||||
{
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
TIMER0A, /* OC0A */
|
||||
TIMER0B, /* OC0B */
|
||||
TIMER1A, /* OC1A */
|
||||
TIMER1B, /* OC1B */
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined( __AVR_ATtinyX5__ )
|
||||
|
||||
// ATMEL ATTINY45 / ARDUINO
|
||||
//
|
||||
// +-\/-+
|
||||
// Ain0 (D 5) PB5 1| |8 VCC
|
||||
// Ain3 (D 3) PB3 2| |7 PB2 (D 2) INT0 Ain1
|
||||
// Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1
|
||||
// GND 4| |5 PB0 (D 0) pwm0
|
||||
// +----+
|
||||
|
||||
// these arrays map port names (e.g. port B) to the
|
||||
// appropriate addresses for various functions (e.g. reading
|
||||
// and writing) tiny45 only port B
|
||||
const uint8_t PROGMEM port_to_mode_PGM[] =
|
||||
{
|
||||
NOT_A_PORT,
|
||||
&DDRB,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM port_to_output_PGM[] =
|
||||
{
|
||||
NOT_A_PORT,
|
||||
&PORTB,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM port_to_input_PGM[] =
|
||||
{
|
||||
NOT_A_PIN,
|
||||
&PINB,
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM digital_pin_to_port_PGM[] =
|
||||
{
|
||||
PORT_B_ID, /* 0 */
|
||||
PORT_B_ID,
|
||||
PORT_B_ID,
|
||||
PORT_B_ID,
|
||||
PORT_B_ID,
|
||||
PORT_B_ID, /* 5 */
|
||||
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
|
||||
{
|
||||
_BV(0), /* 0, port B */
|
||||
_BV(1),
|
||||
_BV(2),
|
||||
_BV(3), /* 3 port B */
|
||||
_BV(4),
|
||||
_BV(5),
|
||||
|
||||
};
|
||||
|
||||
const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
|
||||
{
|
||||
TIMER0A, /* OC0A */
|
||||
TIMER1A, /* OC1A? */
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
NOT_ON_TIMER,
|
||||
};
|
||||
|
||||
#endif
|
115
digistump-avr/variants/digispark/pins_arduino.h
Normal file
115
digistump-avr/variants/digispark/pins_arduino.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
pins_arduino.h - Pin definition functions for Arduino
|
||||
Part of Arduino - http://www.arduino.cc/
|
||||
|
||||
Copyright (c) 2007 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: wiring.h 249 2007-02-03 16:52:51Z mellis $
|
||||
|
||||
Modified 28-08-2009 for attiny84 R.Wiersma
|
||||
Modified 14-10-2009 for attiny45 Saposoft
|
||||
*/
|
||||
|
||||
#ifndef Pins_Arduino_h
|
||||
#define Pins_Arduino_h
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#include "core_build_options.h"
|
||||
|
||||
#if defined( __AVR_ATtinyX313__ )
|
||||
#define PORT_A_ID 1
|
||||
#define PORT_B_ID 2
|
||||
#define PORT_D_ID 4
|
||||
#endif
|
||||
|
||||
#if defined( __AVR_ATtinyX4__ )
|
||||
#define PORT_A_ID 1
|
||||
#define PORT_B_ID 2
|
||||
#endif
|
||||
|
||||
#if defined( __AVR_ATtinyX5__ )
|
||||
#define PORT_B_ID 1
|
||||
#endif
|
||||
|
||||
#define NOT_A_PIN 0
|
||||
#define NOT_A_PORT 0
|
||||
|
||||
#define NOT_ON_TIMER 0
|
||||
#define TIMER0A 1
|
||||
#define TIMER0B 2
|
||||
#define TIMER1A 3
|
||||
#define TIMER1B 4
|
||||
|
||||
//changed it to uint16_t to uint8_t
|
||||
extern const uint8_t PROGMEM port_to_mode_PGM[];
|
||||
extern const uint8_t PROGMEM port_to_input_PGM[];
|
||||
extern const uint8_t PROGMEM port_to_output_PGM[];
|
||||
extern const uint8_t PROGMEM port_to_pcmask_PGM[];
|
||||
|
||||
extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
|
||||
// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
|
||||
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
|
||||
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
|
||||
|
||||
// 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.
|
||||
//
|
||||
// These perform slightly better as macros compared to inline functions
|
||||
//
|
||||
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
|
||||
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
|
||||
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
|
||||
#define analogInPinToBit(P) (P)
|
||||
// in the following lines modified pgm_read_word in pgm_read_byte, word doesn't work on attiny45
|
||||
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_output_PGM + (P))) )
|
||||
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_input_PGM + (P))) )
|
||||
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_mode_PGM + (P))) )
|
||||
#define portPcMaskRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_pcmask_PGM + (P))) )
|
||||
|
||||
#if defined(__AVR_ATtinyX5__)
|
||||
#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 5) ? (&GIMSK) : ((uint8_t *)NULL))
|
||||
#define digitalPinToPCICRbit(p) (PCIE)
|
||||
#define digitalPinToPCMSK(p) (((p) >= 0 && (p) <= 5) ? (&PCMSK) : ((uint8_t *)NULL))
|
||||
#define digitalPinToPCMSKbit(p) (p)
|
||||
#endif
|
||||
|
||||
#if defined(__AVR_ATtinyX4__)
|
||||
#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 10) ? (&GIMSK) : ((uint8_t *)NULL))
|
||||
#define digitalPinToPCICRbit(p) (((p) <= 2) ? PCIE1 : PCIE0)
|
||||
#define digitalPinToPCMSK(p) (((p) <= 2) ? (&PCMSK1) : (((p) <= 10) ? (&PCMSK0) : ((uint8_t *)NULL)))
|
||||
#define digitalPinToPCMSKbit(p) (((p) <= 2) ? (p) : (10 - (p)))
|
||||
#endif
|
||||
|
||||
#if defined(__AVR_ATtiny4313__)
|
||||
#define digitalPinToPCX(p,s1,s2,s3,s4,s5) \
|
||||
(((p) >= 0) \
|
||||
? (((p) <= 1) ? (s1) /* 0 - 1 ==> D0 - D1 */ \
|
||||
: (((p) <= 3) ? (s2) /* 2 - 3 ==> A1 - A0 */ \
|
||||
: (((p) <= 8) ? (s3) /* 4 - 8 ==> D2 - D6 */ \
|
||||
: (((p) <= 16) ? (s4) /* 9 - 16 ==> B0 - B7 */ \
|
||||
: (s5))))) \
|
||||
: (s5))
|
||||
// s1 D s2 A s3 D s4 B
|
||||
#define digitalPinToPCICR(p) digitalPinToPCX( p, &GIMSK, &GIMSK, &GIMSK, &GIMSK, NULL )
|
||||
#define digitalPinToPCICRbit(p) digitalPinToPCX( p, PCIE2, PCIE1, PCIE2, PCIE0, 0 )
|
||||
#define digitalPinToPCMSK(p) digitalPinToPCX( p, &PCMSK2, &PCMSK1, &PCMSK2, &PCMSK0, NULL )
|
||||
#define digitalPinToPCMSKbit(p) digitalPinToPCX( p, p, 3-p, p-2, p-9, 0 )
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user