atmega_gpio.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 HAW Hamburg
3  * 2016 INRIA
4 
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
25 #ifndef ATMEGA_GPIO_H
26 #define ATMEGA_GPIO_H
27 #include <stdio.h>
28 
29 #include <avr/interrupt.h>
30 
31 #include "cpu.h"
32 #include "board.h"
33 #include "periph/gpio.h"
34 #include "periph_conf.h"
35 #include "periph_cpu.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #define ATMEGA_GPIO_BASE_PORT_A (0x20)
42 #define ATMEGA_GPIO_OFFSET_PORT_H (0xCB)
43 #define ATMEGA_GPIO_OFFSET_PIN_PORT (0x02)
44 #define ATMEGA_GPIO_OFFSET_PIN_PIN (0x03)
45 
49 static inline uint8_t atmega_pin_num(gpio_t pin)
50 {
51  return (pin & 0x0f);
52 }
53 
57 static inline uint8_t atmega_port_num(gpio_t pin)
58 {
59  return (pin >> 4) & 0x0f;
60 }
61 
65 static inline uint16_t atmega_port_addr(gpio_t pin)
66 {
67  uint8_t port_num = atmega_port_num(pin);
68  uint16_t port_addr = port_num * ATMEGA_GPIO_OFFSET_PIN_PIN;
69 
70  port_addr += ATMEGA_GPIO_BASE_PORT_A;
71  port_addr += ATMEGA_GPIO_OFFSET_PIN_PORT;
72 
73 #if defined (PORTG)
74  if (port_num > PORT_G) {
75  port_addr += ATMEGA_GPIO_OFFSET_PORT_H;
76  }
77 #endif
78  return port_addr;
79 }
80 
84 static inline uint16_t atmega_ddr_addr(gpio_t pin)
85 {
86  return (atmega_port_addr(pin) - 0x01);
87 }
88 
92 static inline uint16_t atmega_pin_addr(gpio_t pin)
93 {
94  return (atmega_port_addr(pin) - 0x02);
95 }
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif /* ATMEGA_GPIO_H */
102 
atmega_pin_num
static uint8_t atmega_pin_num(gpio_t pin)
Extract the pin number of the given pin.
Definition: atmega_gpio.h:49
atmega_port_addr
static uint16_t atmega_port_addr(gpio_t pin)
Generate the PORTx address of the give pin.
Definition: atmega_gpio.h:65
atmega_port_num
static uint8_t atmega_port_num(gpio_t pin)
Extract the port number of the given pin.
Definition: atmega_gpio.h:57
gpio.h
Low-level GPIO peripheral driver interface definitions.
atmega_pin_addr
static uint16_t atmega_pin_addr(gpio_t pin)
Generate the PINx address of the given pin.
Definition: atmega_gpio.h:92
atmega_ddr_addr
static uint16_t atmega_ddr_addr(gpio_t pin)
Generate the DDRx address of the given pin.
Definition: atmega_gpio.h:84
PORT_G
@ PORT_G
port G
Definition: periph_cpu.h:42