Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ATtiny1614 #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
117 changes: 117 additions & 0 deletions src/utility/Sd2PinMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,26 @@

//------------------------------------------------------------------------------
/** struct for mapping digital pins */
#if defined(__AVR_ATtiny1614__)
// This is compatible with megaTinyCore
// TODO: change this if to match all AVR-1 chips

struct pin_map_t {
volatile VPORT_t* port;
uint8_t bit;
};

#else

struct pin_map_t {
volatile uint8_t* ddr;
volatile uint8_t* pin;
volatile uint8_t* port;
uint8_t bit;
};

#endif // defined(__AVR_ATtiny1614__) else

//------------------------------------------------------------------------------
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// Mega
Expand Down Expand Up @@ -420,6 +434,53 @@ static const pin_map_t digitalPinMap[] = {
{&DDRF, &PINF, &PORTF, 6}, // F6 44
{&DDRF, &PINF, &PORTF, 7} // F7 45
};

#elif defined(__AVR_ATtiny1614__)

// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 8;
uint8_t const SCL_PIN = 9;

// SPI port
uint8_t const SS_PIN = 0;
uint8_t const MOSI_PIN = 8;
uint8_t const MISO_PIN = 9;
uint8_t const SCK_PIN = 10;

static const pin_map_t digitalPinMap[] = {
{&VPORTA, 4},
{&VPORTA, 5},
{&VPORTA, 6},
{&VPORTA, 7},
{&VPORTB, 3},
{&VPORTB, 2},
// Right side, bottom to top
{&VPORTB, 1},
{&VPORTB, 0},
// skip PA0 UPDI,
{&VPORTA, 1},
{&VPORTA, 2},
{&VPORTA, 3},
{&VPORTA, 0}
};

/* From megaTinyCore txy4 pins_arduino.h
PA, // 0 PA4
PA, // 1 PA5
PA, // 2 PA6
PA, // 3 PA7
PB, // 4 PB3
PB, // 5 PB2
// Right side, bottom to top
PB, // 6 PB1
PB, // 7 PB0
// skip PA0 UPDI
PA, // 8 PA1
PA, // 9 PA2
PA, // 10 PA3
PA // 11 PA0
*/

//------------------------------------------------------------------------------
#else // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// 168 and 328 Arduinos
Expand Down Expand Up @@ -458,6 +519,60 @@ static const pin_map_t digitalPinMap[] = {
};
#endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
//------------------------------------------------------------------------------

// Now this part defines some helper functions to configure, read and write the pins_arduino

#if defined(__AVR_ATtiny1614__)
// AVR-1 boards

static const uint8_t digitalPinCount = sizeof(digitalPinMap) / sizeof(pin_map_t);

uint8_t badPinNumber(void)
__attribute__((error("Pin number is too large or not a constant")));

static inline __attribute__((always_inline))
uint8_t getPinMode(uint8_t pin) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) {
return ((*digitalPinMap[pin].port).DIR >> digitalPinMap[pin].bit) & 1;
} else {
return badPinNumber();
}
}
static inline __attribute__((always_inline))
void setPinMode(uint8_t pin, uint8_t mode) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) {
if (mode) {
(*digitalPinMap[pin].port).DIR |= 1 << digitalPinMap[pin].bit;
} else {
(*digitalPinMap[pin].port).DIR &= ~(1 << digitalPinMap[pin].bit);
}
} else {
badPinNumber();
}
}
static inline __attribute__((always_inline))
uint8_t fastDigitalRead(uint8_t pin) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) {
return ((*digitalPinMap[pin].port).IN >> digitalPinMap[pin].bit) & 1;
} else {
return badPinNumber();
}
}
static inline __attribute__((always_inline))
void fastDigitalWrite(uint8_t pin, uint8_t value) {
if (__builtin_constant_p(pin) && pin < digitalPinCount) {
if (value) {
(*digitalPinMap[pin].port).OUT |= 1 << digitalPinMap[pin].bit;
} else {
(*digitalPinMap[pin].port).OUT &= ~(1 << digitalPinMap[pin].bit);
}
} else {
badPinNumber();
}
}

#else // AVR-0 boards

static const uint8_t digitalPinCount = sizeof(digitalPinMap) / sizeof(pin_map_t);

uint8_t badPinNumber(void)
Expand Down Expand Up @@ -503,6 +618,8 @@ void fastDigitalWrite(uint8_t pin, uint8_t value) {
badPinNumber();
}
}
#endif // defined(__AVR_ATtiny1614__)

#endif // Sd2PinMap_h

#elif defined (__CPU_ARC__)
Expand Down