Skip to content

Commit

Permalink
cpu/atmega_common: adds pin change interrupts.
Browse files Browse the repository at this point in the history
  • Loading branch information
roberthartung committed Aug 1, 2019
1 parent f7cdbda commit 82d7ff7
Show file tree
Hide file tree
Showing 25 changed files with 481 additions and 8 deletions.
5 changes: 5 additions & 0 deletions boards/arduino-mega2560/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ This should take care of everything!
We use the open `avrdude` tool to write the new code into the ATmega2560's
flash

## Pin Change Interrupts

More pins can be used for hardware interrupts using the Pin Change
Interrupt feature. See @ref boards_common_atmega for details.

## State
While there is basic support in RIOT, there are still some parts missing:
* Timer implementation needs love (ideally simulate a 32bit timer by adding
Expand Down
16 changes: 16 additions & 0 deletions boards/arduino-mega2560/include/atmega_pcint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef ATMEGA_PCINT_H
#define ATMEGA_PCINT_H

#ifdef __cplusplus
extern "C" {
#endif

#define ATMEGA_PCINT_MAP_PCINT0 GPIO_PIN(PORT_B, 0), GPIO_PIN(PORT_B, 1), GPIO_PIN(PORT_B, 2), GPIO_PIN(PORT_B, 3), GPIO_PIN(PORT_B, 4), GPIO_PIN(PORT_B, 5), GPIO_PIN(PORT_B, 6), GPIO_PIN(PORT_B, 7)
#define ATMEGA_PCINT_MAP_PCINT1 GPIO_PIN(PORT_E, 0), GPIO_PIN(PORT_J, 0), GPIO_PIN(PORT_J, 1), GPIO_UNDEF, GPIO_UNDEF, GPIO_UNDEF, GPIO_UNDEF, GPIO_UNDEF
#define ATMEGA_PCINT_MAP_PCINT2 GPIO_PIN(PORT_K, 0), GPIO_PIN(PORT_K, 1), GPIO_PIN(PORT_K, 2), GPIO_PIN(PORT_K, 3), GPIO_PIN(PORT_K, 4), GPIO_PIN(PORT_K, 5), GPIO_PIN(PORT_K, 6), GPIO_PIN(PORT_K, 7)

#ifdef __cplusplus
}
#endif

#endif /* ATMEGA_PCINT_H */
5 changes: 5 additions & 0 deletions boards/arduino-uno/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ This should take care of everything!
We use the open `avrdude` tool to write the new code into the ATmega328p's
flash

## Pin Change Interrupts

More pins can be used for hardware interrupts using the Pin Change
Interrupt feature. See @ref boards_common_atmega for details.

##Caution
Don't expect having a working network stack due to very limited resources.
*/
17 changes: 17 additions & 0 deletions boards/common/atmega/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
@defgroup boards_common_atmega ATmega common
@ingroup boards
@brief Shared files and configuration for ATmega-based boards

### Pin Change Interrupts

Pin Change Interrupts (PCINTs) can be enabled using pseudo modules. To provide
a low-memory overhead implementation, the PCINTs are grouped into **banks**.
Each banks corresponds to one PCINT on the ATmega (PCINT0, ..., PCINT3).

To enable only a specific bank, simply add `USEMODULE += atmega_pcintN` to your
Makefile. To enable all interrupts you can use `USEMODULE += atmega_pcint`.

In case you want to add a new CPU, simply provide an `atmega_pcint.h` with your
CPU and adapt your Makefile.dep and Makefile.featues files.
*/
5 changes: 5 additions & 0 deletions boards/jiminy-mega256rfr2/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,9 @@ the clocks for all peripherals are enabled and set to the smallest divider (high
power consumption. When the device should be put into deep sleep it is recommended to use the internal RC oscillator
as system clock source.

## Pin Change Interrupts

More pins can be used for hardware interrupts using the Pin Change
Interrupt feature. See @ref boards_common_atmega for details.

*/
6 changes: 6 additions & 0 deletions boards/mega-xplained/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ It will be used automatically with `make term`:
```
make BOARD=mega-xplained -C examples/hello-world term
```

### Pin Change Interrupts

More pins can be used for hardware interrupts using the Pin Change
Interrupt feature. See @ref boards_common_atmega for details.

*/
6 changes: 6 additions & 0 deletions boards/waspmote-pro/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
@defgroup boards_waspmote-pro Waspmote PRO v1.2
@ingroup boards
@brief Support for the Waspmote PRO v1.2 board.

## Pin Change Interrupts

More pins can be used for hardware interrupts using the Pin Change
Interrupt feature. See @ref boards_common_atmega for details.

*/
4 changes: 3 additions & 1 deletion cpu/atmega1281/Makefile.features
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-include $(RIOTCPU)/atmega_common/Makefile.features
FEATURES_PROVIDED += atmega_pcint2

include $(RIOTCPU)/atmega_common/Makefile.features
5 changes: 5 additions & 0 deletions cpu/atmega1281/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ USEMODULE += atmega_common
RAM_LEN = 8K
ROM_LEN = 128K

# atmega1281 additionally has PCINT2
ifneq (,$(filter atmega_pcint,$(USEMODULE)))
USEMODULE += atmega_pcint2
endif

# CPU depends on the atmega common module, so include it
include $(RIOTCPU)/atmega_common/Makefile.include
16 changes: 16 additions & 0 deletions cpu/atmega1281/include/atmega_pcint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef ATMEGA_PCINT_H
#define ATMEGA_PCINT_H

#ifdef __cplusplus
extern "C" {
#endif

#define ATMEGA_PCINT_MAP_PCINT0 GPIO_PIN(PORT_B, 0), GPIO_PIN(PORT_B, 1), GPIO_PIN(PORT_B, 2), GPIO_PIN(PORT_B, 3), GPIO_PIN(PORT_B, 4), GPIO_PIN(PORT_B, 5), GPIO_PIN(PORT_B, 6), GPIO_PIN(PORT_B, 7)
#define ATMEGA_PCINT_MAP_PCINT1 GPIO_PIN(PORT_E, 0), GPIO_PIN(PORT_J, 0), GPIO_PIN(PORT_J, 1), GPIO_PIN(PORT_J, 2), GPIO_PIN(PORT_J, 3), GPIO_PIN(PORT_J, 4), GPIO_PIN(PORT_J, 5), GPIO_PIN(PORT_J, 6)
#define ATMEGA_PCINT_MAP_PCINT2 GPIO_PIN(PORT_K, 0), GPIO_PIN(PORT_K, 1), GPIO_PIN(PORT_K, 2), GPIO_PIN(PORT_K, 3), GPIO_PIN(PORT_K, 4), GPIO_PIN(PORT_K, 5), GPIO_PIN(PORT_K, 6), GPIO_PIN(PORT_K, 7)

#ifdef __cplusplus
}
#endif

#endif /* ATMEGA_PCINT_H */
5 changes: 4 additions & 1 deletion cpu/atmega1284p/Makefile.features
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
-include $(RIOTCPU)/atmega_common/Makefile.features
# atmega1284p additionally has PCINT3
FEATURES_PROVIDED += atmega_pcint2 atmega_pcint3

include $(RIOTCPU)/atmega_common/Makefile.features
5 changes: 5 additions & 0 deletions cpu/atmega1284p/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ USEMODULE += atmega_common
RAM_LEN = 16K
ROM_LEN = 128K

# atmega1284p additionally has PCINT2 and PCINT3
ifneq (,$(filter atmega_pcint,$(USEMODULE)))
USEMODULE += atmega_pcint2 atmega_pcint3
endif

# CPU depends on the atmega common module, so include it
include $(RIOTCPU)/atmega_common/Makefile.include
17 changes: 17 additions & 0 deletions cpu/atmega1284p/include/atmega_pcint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef ATMEGA_PCINT_H
#define ATMEGA_PCINT_H

#ifdef __cplusplus
extern "C" {
#endif

#define ATMEGA_PCINT_MAP_PCINT0 GPIO_PIN(PORT_A, 0), GPIO_PIN(PORT_A, 1), GPIO_PIN(PORT_A, 2), GPIO_PIN(PORT_A, 3), GPIO_PIN(PORT_A, 4), GPIO_PIN(PORT_A, 5), GPIO_PIN(PORT_A, 6), GPIO_PIN(PORT_A, 7)
#define ATMEGA_PCINT_MAP_PCINT1 GPIO_PIN(PORT_B, 0), GPIO_PIN(PORT_B, 1), GPIO_PIN(PORT_B, 2), GPIO_PIN(PORT_B, 3), GPIO_PIN(PORT_B, 4), GPIO_PIN(PORT_B, 5), GPIO_PIN(PORT_B, 6), GPIO_PIN(PORT_B, 7)
#define ATMEGA_PCINT_MAP_PCINT2 GPIO_PIN(PORT_C, 0), GPIO_PIN(PORT_C, 1), GPIO_PIN(PORT_C, 2), GPIO_PIN(PORT_C, 3), GPIO_PIN(PORT_C, 4), GPIO_PIN(PORT_C, 5), GPIO_PIN(PORT_C, 6), GPIO_PIN(PORT_C, 7)
#define ATMEGA_PCINT_MAP_PCINT3 GPIO_PIN(PORT_D, 0), GPIO_PIN(PORT_D, 1), GPIO_PIN(PORT_D, 2), GPIO_PIN(PORT_D, 3), GPIO_PIN(PORT_D, 4), GPIO_PIN(PORT_D, 5), GPIO_PIN(PORT_D, 6), GPIO_PIN(PORT_D, 7)

#ifdef __cplusplus
}
#endif

#endif /* ATMEGA_PCINT_H */
6 changes: 6 additions & 0 deletions cpu/atmega2560/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# atmega1281 additionally has PCINT2
ifneq (,$(filter atmega_pcint,$(USEMODULE)))
USEMODULE += atmega_pcint2
endif

include $(RIOTCPU)/atmega_common/Makefile.dep
4 changes: 3 additions & 1 deletion cpu/atmega2560/Makefile.features
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-include $(RIOTCPU)/atmega_common/Makefile.features
FEATURES_PROVIDED += atmega_pcint2

include $(RIOTCPU)/atmega_common/Makefile.features
5 changes: 5 additions & 0 deletions cpu/atmega2560/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ USEMODULE += atmega_common
RAM_LEN = 8K
ROM_LEN = 256K

# atmega2560 additionally has PCINT2
ifneq (,$(filter atmega_pcint,$(USEMODULE)))
USEMODULE += atmega_pcint2
endif

# CPU depends on the atmega common module, so include it
include $(RIOTCPU)/atmega_common/Makefile.include
16 changes: 16 additions & 0 deletions cpu/atmega2560/include/atmega_pcint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef ATMEGA_PCINT_H
#define ATMEGA_PCINT_H

#ifdef __cplusplus
extern "C" {
#endif

#define ATMEGA_PCINT_MAP_PCINT0 GPIO_PIN(PORT_B, 0), GPIO_PIN(PORT_B, 1), GPIO_PIN(PORT_B, 2), GPIO_PIN(PORT_B, 3), GPIO_PIN(PORT_B, 4), GPIO_PIN(PORT_B, 5), GPIO_PIN(PORT_B, 6), GPIO_PIN(PORT_B, 7)
#define ATMEGA_PCINT_MAP_PCINT1 GPIO_PIN(PORT_E, 0), GPIO_PIN(PORT_J, 0), GPIO_PIN(PORT_J, 1), GPIO_PIN(PORT_J, 2), GPIO_PIN(PORT_J, 3), GPIO_PIN(PORT_J, 4), GPIO_PIN(PORT_J, 5), GPIO_PIN(PORT_J, 6)
#define ATMEGA_PCINT_MAP_PCINT2 GPIO_PIN(PORT_K, 0), GPIO_PIN(PORT_K, 1), GPIO_PIN(PORT_K, 2), GPIO_PIN(PORT_K, 3), GPIO_PIN(PORT_K, 4), GPIO_PIN(PORT_K, 5), GPIO_PIN(PORT_K, 6), GPIO_PIN(PORT_K, 7)

#ifdef __cplusplus
}
#endif

#endif /* ATMEGA_PCINT_H */
15 changes: 15 additions & 0 deletions cpu/atmega256rfr2/include/atmega_pcint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef ATMEGA_PCINT_H
#define ATMEGA_PCINT_H

#ifdef __cplusplus
extern "C" {
#endif

#define ATMEGA_PCINT_MAP_PCINT0 GPIO_PIN(PORT_B, 0), GPIO_PIN(PORT_B, 1), GPIO_PIN(PORT_B, 2), GPIO_PIN(PORT_B, 3), GPIO_PIN(PORT_B, 4), GPIO_PIN(PORT_B, 5), GPIO_PIN(PORT_B, 6), GPIO_PIN(PORT_B, 7)
#define ATMEGA_PCINT_MAP_PCINT1 GPIO_PIN(PORT_E, 0), GPIO_UNDEF, GPIO_UNDEF, GPIO_UNDEF, GPIO_UNDEF, GPIO_UNDEF, GPIO_UNDEF, GPIO_UNDEF

#ifdef __cplusplus
}
#endif

#endif /* ATMEGA_PCINT_H */
4 changes: 3 additions & 1 deletion cpu/atmega328p/Makefile.features
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-include $(RIOTCPU)/atmega_common/Makefile.features
FEATURES_PROVIDED += atmega_pcint2

include $(RIOTCPU)/atmega_common/Makefile.features
5 changes: 5 additions & 0 deletions cpu/atmega328p/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ USEMODULE += atmega_common
RAM_LEN = 2K
ROM_LEN = 32K

# atmega328p additionally has PCINT2
ifneq (,$(filter atmega_pcint,$(USEMODULE)))
USEMODULE += atmega_pcint2
endif

# CPU depends on the atmega common module, so include it
include $(RIOTCPU)/atmega_common/Makefile.include
16 changes: 16 additions & 0 deletions cpu/atmega328p/include/atmega_pcint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef ATMEGA_PCINT_H
#define ATMEGA_PCINT_H

#ifdef __cplusplus
extern "C" {
#endif

#define ATMEGA_PCINT_MAP_PCINT0 GPIO_PIN(PORT_B, 0), GPIO_PIN(PORT_B, 1), GPIO_PIN(PORT_B, 2), GPIO_PIN(PORT_B, 3), GPIO_PIN(PORT_B, 4), GPIO_PIN(PORT_B, 5), GPIO_PIN(PORT_B, 6), GPIO_PIN(PORT_B, 7)
#define ATMEGA_PCINT_MAP_PCINT1 GPIO_PIN(PORT_C, 0), GPIO_PIN(PORT_C, 1), GPIO_PIN(PORT_C, 2), GPIO_PIN(PORT_C, 3), GPIO_PIN(PORT_C, 4), GPIO_PIN(PORT_C, 5), GPIO_PIN(PORT_C, 6), GPIO_UNDEF
#define ATMEGA_PCINT_MAP_PCINT2 GPIO_PIN(PORT_D, 0), GPIO_PIN(PORT_D, 1), GPIO_PIN(PORT_D, 2), GPIO_PIN(PORT_D, 3), GPIO_PIN(PORT_D, 4), GPIO_PIN(PORT_D, 5), GPIO_PIN(PORT_D, 6), GPIO_PIN(PORT_D, 7)

#ifdef __cplusplus
}
#endif

#endif /* ATMEGA_PCINT_H */
24 changes: 24 additions & 0 deletions cpu/atmega_common/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# expand atmega_pcint module
ifneq (,$(filter atmega_pcint,$(USEMODULE)))
USEMODULE += atmega_pcint0 atmega_pcint1
endif

# feature for atmega_pcint0 module
ifneq (,$(filter atmega_pcint0,$(USEMODULE)))
FEATURES_REQUIRED += atmega_pcint0
endif

# feature for atmega_pcint1 module
ifneq (,$(filter atmega_pcint1,$(USEMODULE)))
FEATURES_REQUIRED += atmega_pcint1
endif

# feature for atmega_pcint2 module
ifneq (,$(filter atmega_pcint2,$(USEMODULE)))
FEATURES_REQUIRED += atmega_pcint2
endif

# feature for atmega_pcint3 module
ifneq (,$(filter atmega_pcint3,$(USEMODULE)))
FEATURES_REQUIRED += atmega_pcint3
endif
2 changes: 2 additions & 0 deletions cpu/atmega_common/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
FEATURES_PROVIDED += periph_eeprom
FEATURES_PROVIDED += periph_pm

FEATURES_PROVIDED += atmega_pcint0 atmega_pcint1
28 changes: 28 additions & 0 deletions cpu/atmega_common/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,32 @@ export INCLUDES += -I$(RIOTCPU)/atmega_common/include \
# avr libc needs some RIOT-specific support code
USEMODULE += avr_libc_extra

PSEUDOMODULES += atmega_pcint
PSEUDOMODULES += atmega_pcint%

# expand atmega_pcint module
ifneq (,$(filter atmega_pcint,$(USEMODULE)))
USEMODULE += atmega_pcint0 atmega_pcint1
endif

# feature for atmega_pcint0 module
ifneq (,$(filter atmega_pcint0,$(USEMODULE)))
FEATURES_REQUIRED += atmega_pcint0
endif

# feature for atmega_pcint1 module
ifneq (,$(filter atmega_pcint1,$(USEMODULE)))
FEATURES_REQUIRED += atmega_pcint1
endif

# feature for atmega_pcint2 module
ifneq (,$(filter atmega_pcint2,$(USEMODULE)))
FEATURES_REQUIRED += atmega_pcint2
endif

# feature for atmega_pcint3 module
ifneq (,$(filter atmega_pcint3,$(USEMODULE)))
FEATURES_REQUIRED += atmega_pcint3
endif

include $(RIOTMAKE)/arch/atmega.inc.mk
Loading

0 comments on commit 82d7ff7

Please sign in to comment.