atmega_gpio.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2015 HAW Hamburg
3  * SPDX-FileCopyrightText: 2016 INRIA
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
23 #include <stddef.h>
24 #include <stdio.h>
25 
26 #include <avr/interrupt.h>
27 
28 #include "cpu.h"
29 #include "board.h"
30 #include "periph/gpio.h"
31 #include "periph_conf.h"
32 #include "periph_cpu.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
41 static inline uint8_t atmega_pin_num(gpio_t pin)
42 {
43  return (pin & 0x0f);
44 }
45 
49 static inline uint8_t atmega_port_num(gpio_t pin)
50 {
51  return (pin >> 4) & 0x0f;
52 }
53 
57 static inline uint16_t atmega_pin_addr(gpio_t pin)
58 {
59  return (uintptr_t)atmega_gpio_port(atmega_port_num(pin));
60 }
61 
65 static inline uint16_t atmega_ddr_addr(gpio_t pin)
66 {
67  return atmega_pin_addr(pin) + offsetof(atmega_gpio_port_t, ddr);
68 }
69 
73 static inline uint16_t atmega_port_addr(gpio_t pin)
74 {
75  return atmega_pin_addr(pin) + offsetof(atmega_gpio_port_t, port);
76 }
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
static atmega_gpio_port_t * atmega_gpio_port(uint8_t port_num)
Get the GPIO PORT registers of the given GPIO PORT.
static uint16_t atmega_port_addr(gpio_t pin)
Generate the PORTx address of the give pin.
Definition: atmega_gpio.h:73
static uint16_t atmega_ddr_addr(gpio_t pin)
Generate the DDRx address of the given pin.
Definition: atmega_gpio.h:65
static uint8_t atmega_pin_num(gpio_t pin)
Extract the pin number of the given pin.
Definition: atmega_gpio.h:41
static uint16_t atmega_pin_addr(gpio_t pin)
Generate the PINx address of the given pin.
Definition: atmega_gpio.h:57
static uint8_t atmega_port_num(gpio_t pin)
Extract the port number of the given pin.
Definition: atmega_gpio.h:49
Low-level GPIO peripheral driver interface definitions.
Structure describing the memory layout of the registers of a GPIO port on ATmega MCUs.