From 821fea2c2bcb3af8eb3cf3457bb202e2785d8e2b Mon Sep 17 00:00:00 2001 From: Kerogit Date: Sun, 13 Apr 2025 16:59:00 +0200 Subject: [PATCH] arch/avr/src/avrdx: introduce header file for I/O port constants Maps letter-marked I/O ports to numbers in alphabetical order. --- arch/avr/src/avrdx/avrdx_gpio.h | 89 ++++++++++++++++++++++++++ arch/avr/src/avrdx/avrdx_peripherals.c | 10 ++- 2 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 arch/avr/src/avrdx/avrdx_gpio.h diff --git a/arch/avr/src/avrdx/avrdx_gpio.h b/arch/avr/src/avrdx/avrdx_gpio.h new file mode 100644 index 0000000000..e53a7df31d --- /dev/null +++ b/arch/avr/src/avrdx/avrdx_gpio.h @@ -0,0 +1,89 @@ +/**************************************************************************** + * arch/avr/src/avrdx/avrdx_gpio.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_AVR_SRC_AVRDX_AVRDX_GPIO_H +#define __ARCH_AVR_SRC_AVRDX_AVRDX_GPIO_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Mapping of port name to numeric index alphabetically. + * Ports missing on a specific device are not skipped. + */ + +#define AVRDX_GPIO_PORTA_IDX 0 +#define AVRDX_GPIO_PORTC_IDX 2 +#define AVRDX_GPIO_PORTD_IDX 3 +#define AVRDX_GPIO_PORTF_IDX 5 + +#ifdef CONFIG_AVR_HAS_PORTB +# define AVRDX_GPIO_PORTB_IDX 1 +#endif + +#ifdef CONFIG_AVR_HAS_PORTE +# define AVRDX_GPIO_PORTE_IDX 4 +#endif + +#ifdef CONFIG_AVR_HAS_PORTG +# define AVRDX_GPIO_PORTG_IDX 6 +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_AVR_SRC_AVRDX_AVRDX_GPIO_H */ diff --git a/arch/avr/src/avrdx/avrdx_peripherals.c b/arch/avr/src/avrdx/avrdx_peripherals.c index 75653f2b7d..62c86ef4c2 100644 --- a/arch/avr/src/avrdx/avrdx_peripherals.c +++ b/arch/avr/src/avrdx/avrdx_peripherals.c @@ -26,6 +26,7 @@ #include #include "avrdx.h" +#include "avrdx_gpio.h" #include /**************************************************************************** @@ -77,13 +78,16 @@ static const IOBJ uint8_t avrdx_main_pdiv[] = \ const IOBJ uint8_t avrdx_usart_ports[] = { # ifdef CONFIG_AVR_HAS_USART_2 - 0, 2, 5 /* A, C, F */ + AVRDX_GPIO_PORTA_IDX, /* A, C, F */ + AVRDX_GPIO_PORTC_IDX, + AVRDX_GPIO_PORTF_IDX # endif # ifdef CONFIG_AVR_HAS_USART_4 - , 1, 4 /* B, E */ + , AVRDX_GPIO_PORTB_IDX /* B, E */ + , AVRDX_GPIO_PORTE_IDX # endif # ifdef CONFIG_AVR_HAS_USART_5 - , 6 /* port G */ + , AVRDX_GPIO_PORTG_IDX /* port G */ # endif };