arch/avr/src/avrdx: introduce header file for I/O port constants

Maps letter-marked I/O ports to numbers in alphabetical order.
This commit is contained in:
Kerogit 2025-04-13 16:59:00 +02:00 committed by Xiang Xiao
parent ca7941eec7
commit 821fea2c2b
2 changed files with 96 additions and 3 deletions

View file

@ -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 <nuttx/config.h>
/****************************************************************************
* 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 */

View file

@ -26,6 +26,7 @@
#include <nuttx/config.h>
#include "avrdx.h"
#include "avrdx_gpio.h"
#include <avr/io.h>
/****************************************************************************
@ -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
};