Skip to content
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
5 changes: 5 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,11 @@ ifneq (,$(filter periph_gpio_irq,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio
endif

# Enable optionally periph_gpio_ext when the MCU supports it as feature
ifneq (,$(filter periph_gpio,$(USEMODULE)))
FEATURES_OPTIONAL += periph_gpio_exp
endif

ifneq (,$(filter periph_timer_periodic,$(USEMODULE)))
FEATURES_REQUIRED += periph_timer
endif
Expand Down
9 changes: 5 additions & 4 deletions boards/atmega256rfr2-xpro/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define BOARD_H

#include "cpu.h"
#include "periph_cpu.h"
#include "periph/gpio.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -48,10 +49,10 @@ extern "C" {
*/
#define LED0_PIN GPIO_PIN(PORT_B, 4)
#define LED0_MODE GPIO_OUT
#define LED0_ENABLE_PORT DDRB |= LED0_PIN
#define LED0_ON PORTB |= LED0_PIN
#define LED0_OFF PORTB &= ~LED0_PIN
#define LED0_TOGGLE PORTB ^= LED0_PIN
#define LED0_ENABLE_PORT DDRB |= LED0_PIN.pin
#define LED0_ON PORTB |= LED0_PIN.pin
#define LED0_OFF PORTB &= ~LED0_PIN.pin
#define LED0_TOGGLE PORTB ^= LED0_PIN.pin
/** @} */

/**
Expand Down
1 change: 1 addition & 0 deletions boards/avr-rss2/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "cpu.h"
#include "periph/gpio.h"
#include "periph_cpu.h"

#include "at24mac.h"
#include "net/eui_provider.h"
Expand Down
18 changes: 9 additions & 9 deletions boards/mega-xplained/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ extern "C" {
* @{
*/
/* LED0,2 currently unsupported due to lack of GPIO_OD support */
#define LED1_ENABLE_PORT DDRB |= LED1_PIN
#define LED1_ON PORTB |= LED1_PIN
#define LED1_OFF PORTB &= ~LED1_PIN
#define LED1_TOGGLE PORTB ^= LED1_PIN

#define LED3_ENABLE_PORT DDRB |= LED3_PIN
#define LED3_ON PORTB |= LED3_PIN
#define LED3_OFF PORTB &= ~LED3_PIN
#define LED3_TOGGLE PORTB ^= LED3_PIN
#define LED1_ENABLE_PORT DDRB |= LED1_PIN.pin
#define LED1_ON PORTB |= LED1_PIN.pin
#define LED1_OFF PORTB &= ~LED1_PIN.pin
#define LED1_TOGGLE PORTB ^= LED1_PIN.pin

#define LED3_ENABLE_PORT DDRB |= LED3_PIN.pin
#define LED3_ON PORTB |= LED3_PIN.pin
#define LED3_OFF PORTB &= ~LED3_PIN.pin
#define LED3_TOGGLE PORTB ^= LED3_PIN.pin
/** @} */

/**
Expand Down
1 change: 1 addition & 0 deletions cpu/atmega1281/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum {
PORT_E = 4, /**< port E */
PORT_F = 5, /**< port F */
PORT_G = 6, /**< port G */
GPIO_EXP_PORT = 7 /**< first GPIO expander port */
};

/**
Expand Down
8 changes: 2 additions & 6 deletions cpu/atmega1284p/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@
extern "C" {
#endif

/**
* @brief Define a CPU specific GPIO pin generator macro
*/
#define GPIO_PIN(x, y) ((x << 4) | y)

/**
* @brief Available ports on the ATmega1284p family
*/
enum {
PORT_A = 0, /**< port A */
PORT_B = 1, /**< port B */
PORT_C = 2, /**< port C */
PORT_D = 3 /**< port D */
PORT_D = 3, /**< port D */
GPIO_EXP_PORT = 4 /**< first GPIO expander port */
};

/**
Expand Down
11 changes: 6 additions & 5 deletions cpu/atmega128rfa1/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ extern "C" {
* @{
*/
enum {
PORT_B = 1, /**< port B */
PORT_D = 3, /**< port D */
PORT_E = 4, /**< port E */
PORT_F = 5, /**< port F */
PORT_G = 6, /**< port G */
PORT_B = 1, /**< port B */
PORT_D = 3, /**< port D */
PORT_E = 4, /**< port E */
PORT_F = 5, /**< port F */
PORT_G = 6, /**< port G */
GPIO_EXP_PORT = 7 /**< first GPIO expander port */
};
/** @} */

Expand Down
23 changes: 12 additions & 11 deletions cpu/atmega2560/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ extern "C" {
* @brief Available ports on the ATmega2560 family
*/
enum {
PORT_A = 0, /**< port A */
PORT_B = 1, /**< port B */
PORT_C = 2, /**< port C */
PORT_D = 3, /**< port D */
PORT_E = 4, /**< port E */
PORT_F = 5, /**< port F */
PORT_G = 6, /**< port G */
PORT_H = 7, /**< port H */
PORT_J = 8, /**< port J */
PORT_K = 9, /**< port K */
PORT_L = 10 /**< port L */
PORT_A = 0, /**< port A */
PORT_B = 1, /**< port B */
PORT_C = 2, /**< port C */
PORT_D = 3, /**< port D */
PORT_E = 4, /**< port E */
PORT_F = 5, /**< port F */
PORT_G = 6, /**< port G */
PORT_H = 7, /**< port H */
PORT_J = 8, /**< port J */
PORT_K = 9, /**< port K */
PORT_L = 10, /**< port L */
GPIO_EXP_PORT = 11 /**< first GPIO expander port */
};

/**
Expand Down
11 changes: 6 additions & 5 deletions cpu/atmega256rfr2/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ extern "C" {
* @{
*/
enum {
PORT_B = 1, /**< port B */
PORT_D = 3, /**< port D */
PORT_E = 4, /**< port E */
PORT_F = 5, /**< port F */
PORT_G = 6, /**< port G */
PORT_B = 1, /**< port B */
PORT_D = 3, /**< port D */
PORT_E = 4, /**< port E */
PORT_F = 5, /**< port F */
PORT_G = 6, /**< port G */
GPIO_EXP_PORT = 7 /**< first GPIO expander port */
};
/** @} */

Expand Down
8 changes: 2 additions & 6 deletions cpu/atmega328p/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@
extern "C" {
#endif

/**
* @brief Define a CPU specific GPIO pin generator macro
*/
#define GPIO_PIN(x, y) ((x << 4) | y)

/**
* @brief Available ports on the ATmega328p family
*/
enum {
PORT_B = 1, /**< port B */
PORT_C = 2, /**< port C */
PORT_D = 3 /**< port D */
PORT_D = 3, /**< port D */
GPIO_EXP_PORT = 4 /**< first GPIO expander port */
};

/**
Expand Down
3 changes: 2 additions & 1 deletion cpu/atmega32u4/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ enum {
PORT_C = 2, /**< port C */
PORT_D = 3, /**< port D */
PORT_E = 4, /**< port E */
PORT_F = 5 /**< port F */
PORT_F = 5, /**< port F */
GPIO_EXP_PORT = 6 /**< first GPIO expander port */
};

/**
Expand Down
1 change: 1 addition & 0 deletions cpu/atmega_common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ config CPU_COMMON_ATMEGA
select HAS_PERIPH_CPUID
select HAS_PERIPH_EEPROM
select HAS_PERIPH_GPIO
select HAS_PERIPH_GPIO_EXP
select HAS_PERIPH_GPIO_IRQ
select HAS_PERIPH_PM
select HAS_PERIPH_TIMER_PERIODIC
Expand Down
3 changes: 3 additions & 0 deletions cpu/atmega_common/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ USEMODULE += atmega_common
# peripheral drivers are linked into the final binary
USEMODULE += atmega_common_periph

# 8 bit GPIO pin mask required
USEMODULE += gpio_mask_8bit

# the atmel port uses stdio_uart by default
ifeq (,$(filter stdio_% slipdev_stdio,$(USEMODULE)))
USEMODULE += stdio_uart
Expand Down
2 changes: 1 addition & 1 deletion cpu/atmega_common/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FEATURES_PROVIDED += atmega_pcint0
FEATURES_PROVIDED += cpp
FEATURES_PROVIDED += periph_cpuid
FEATURES_PROVIDED += periph_eeprom
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
FEATURES_PROVIDED += periph_gpio periph_gpio_irq periph_gpio_exp
FEATURES_PROVIDED += periph_pm
FEATURES_PROVIDED += periph_timer_periodic
FEATURES_PROVIDED += periph_wdt
Expand Down
50 changes: 25 additions & 25 deletions cpu/atmega_common/include/atmega_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,55 +43,55 @@ extern "C" {
#define ATMEGA_GPIO_OFFSET_PIN_PORT (0x02)
#define ATMEGA_GPIO_OFFSET_PIN_PIN (0x03)


/**
* @brief Extract the pin number of the given pin
*/
static inline uint8_t atmega_pin_num(gpio_t pin)
static inline uint8_t atmega_pin_num(gpio_pin_t pin)
{
return (pin & 0x0f);
return (pin & 0x07);
}

/**
* @brief Extract the port number of the given pin
* @brief Generate the PORTx address of the give port.
*/
static inline uint8_t atmega_port_num(gpio_t pin)
static inline gpio_reg_t atmega_port_addr(gpio_port_t port)
{
return (pin >> 4) & 0x0f;
return port.reg;
}

/**
* @brief Generate the PORTx address of the give pin.
* @brief Generate the DDRx address of the given port.
*/
static inline uint16_t atmega_port_addr(gpio_t pin)
static inline gpio_reg_t atmega_ddr_addr(gpio_port_t port)
{
uint8_t port_num = atmega_port_num(pin);
uint16_t port_addr = port_num * ATMEGA_GPIO_OFFSET_PIN_PIN;

port_addr += ATMEGA_GPIO_BASE_PORT_A;
port_addr += ATMEGA_GPIO_OFFSET_PIN_PORT;

#if defined (PORTG)
if (port_num > PORT_G) {
port_addr += ATMEGA_GPIO_OFFSET_PORT_H;
}
#endif
return port_addr;
return (atmega_port_addr(port) - 0x01);
}

/**
* @brief Generate the DDRx address of the given pin
* @brief Generate the PINx address of the given port.
*/
static inline uint16_t atmega_ddr_addr(gpio_t pin)
static inline gpio_reg_t atmega_pin_addr(gpio_port_t port)
{
return (atmega_port_addr(pin) - 0x01);
return (atmega_port_addr(port) - 0x02);
}

/**
* @brief Generate the PINx address of the given pin.
* @brief Generate the port number of the given port
*/
static inline uint16_t atmega_pin_addr(gpio_t pin)
static inline uint8_t atmega_port_num(gpio_port_t port)
{
return (atmega_port_addr(pin) - 0x02);
gpio_reg_t port_addr = atmega_port_addr(port);

#ifdef PORTG
if (port_addr > ATMEGA_GPIO_OFFSET_PORT_H) {
port_addr -= ATMEGA_GPIO_OFFSET_PORT_H;
}
#endif
port_addr -= ATMEGA_GPIO_OFFSET_PIN_PORT;
port_addr -= ATMEGA_GPIO_BASE_PORT_A;

return port_addr / ATMEGA_GPIO_OFFSET_PIN_PIN;
}

#ifdef __cplusplus
Expand Down
Loading