diff --git a/arch/arm/src/max326xx/chip/max32660_gpio.h b/arch/arm/src/max326xx/chip/max32660_gpio.h index bcee53e605..d84dbfb7e5 100644 --- a/arch/arm/src/max326xx/chip/max32660_gpio.h +++ b/arch/arm/src/max326xx/chip/max32660_gpio.h @@ -58,7 +58,7 @@ #define MAX326_GPIO_INTPOL_OFFSET 0x002c /* Interrupt Polarity Select * Register */ #define MAX326_GPIO_INTEN_OFFSET 0x0034 /* Interrupt Enable Register */ -#define MAX326_GPIO_INTFL_OFFSET 0x0040 /*1C Interrupt Flag Register */ +#define MAX326_GPIO_INTFL_OFFSET 0x0040 /* Interrupt Flag Register */ #define MAX326_GPIO_WAKEEN_OFFSET 0x004c /* Wakeup Enable Register */ #define MAX326_GPIO_INTDUALEDGE_OFFSET 0x005c /* Dual Edge Select Interrupt * Register */ @@ -126,7 +126,7 @@ #define GPIO_INTEN(n) (1 << (n)) /* GPIO Pin n interrupt enabled */ -/*1C Interrupt Flag Register */ +/* Interrupt Flag Register */ #define GPIO_INTFL(n) (1 << (n)) /* GPIO Pin n interrupt pending */ diff --git a/arch/arm/src/max326xx/max32660_gpio.h b/arch/arm/src/max326xx/max32660_gpio.h new file mode 100644 index 0000000000..ecce628044 --- /dev/null +++ b/arch/arm/src/max326xx/max32660_gpio.h @@ -0,0 +1,189 @@ +/************************************************************************************ + * arch/arm/src/max326xx/max32660_gpio.h + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __ARCH_ARM_SRC_MAX326XX_MAX32660_GPIO_H +#define __ARCH_ARM_SRC_MAX326XX_MAX32660_GPIO_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/* Bit-encoded input to max326_gpio_config() ******************************************/ + +/* 16-Bit Encoding: FFFF WRRV HSDD NNNN + * + * Pin Function: FFFF + * Wakeup: W + * Pin Pull Up/Down: RR + * Initial Value: V (output pins) + * Input Hysteresis: H + * Slew Rate: S + * Drive Strength: DD + * Port Number: (implicitly 0) + * Pin Number: NNNN (0-13) + */ + +/* Pin Function bits: + * Only meaningful when the GPIO function is GPIO_PIN + * + * FFFF .... .... .... + */ + +#define GPIO_FUNC_SHIFT (11) /* Bits 12-15: Pin Function */ +#define GPIO_FUNC_MASK (15 << GPIO_FUNC_SHIFT) +# define GPIO_INPUT (0 << GPIO_FUNC_SHIFT) /* 0000 GPIO input pin */ +# define GPIO_OUTPUT (1 << GPIO_FUNC_SHIFT) /* 0001 GPIO output pin */ +# define GPIO_ALT0 (4 << GPIO_FUNC_SHIFT) /* 0100 GPIO Alternate function 0 */ +# define GPIO_ALT1 (5 << GPIO_FUNC_SHIFT) /* 0101 GPIO Alternate function 1 */ +# define GPIO_ALT2 (6 << GPIO_FUNC_SHIFT) /* 0110 GPIO Alternate function 2 */ +# define GPIO_ALT3 (7 << GPIO_FUNC_SHIFT) /* 0111 GPIO Alternate function 3 */ +# define GPIO_INTFE (9 << GPIO_FUNC_SHIFT) /* 1001 GPIO interrupt falling edge */ +# define GPIO_INTRE (10 << GPIO_FUNC_SHIFT) /* 1010 GPIO interrupt rising edge */ +# define GPIO_INTBOTH (11 << GPIO_FUNC_SHIFT) /* 1011 GPIO interrupt both edges */ +# define GPIO_INTLOW (13 << GPIO_FUNC_SHIFT) /* 1101 GPIO interrupt low level */ +# define GPIO_INTHIGH (14 << GPIO_FUNC_SHIFT) /* 1110 GPIO interrupt high level */ + +/* Bit encoding */ + +#define GPIO_GPIO_MASK (0xc << GPIO_FUNC_SHIFT) /* 11xx */ +#define GPIO_GPIO_CODE (0x0 << GPIO_FUNC_SHIFT) /* 00xx */ +#define GPIO_ALT_MASK (0xc << GPIO_FUNC_SHIFT) /* 11xx */ +#define GPIO_ALT_CODE (0x4 << GPIO_FUNC_SHIFT) /* 01xx */ +#define GPIO_INTR_MASK (0x8 << GPIO_FUNC_SHIFT) /* 1xxx */ +#define GPIO_INTR_CODE (0x8 << GPIO_FUNC_SHIFT) /* 1xxx */ +#define GPIO_INTEDGE_MASK (0xc << GPIO_FUNC_SHIFT) /* 11xx */ +#define GPIO_INTEDGE_CODE (0x8 << GPIO_FUNC_SHIFT) /* 10xx */ +#define GPIO_INTLVL_MASK (0xc << GPIO_FUNC_SHIFT) /* 11xx */ +#define GPIO_INTLVL_CODE (0xc << GPIO_FUNC_SHIFT) /* 11xx */ + +#define GPIO_IS_GPIO(ps) (((uint16_t)(ps) & GPIO_GPIO_MASK) == GPIO_GPIO_CODE) +#define GPIO_IS_ALT(ps) (((uint16_t)(ps) & GPIO_ALT_MASK) == GPIO_ALT_CODE) +#define GPIO_IS_INTR(ps) (((uint16_t)(ps) & GPIO_ALT_MASK) == GPIO_ALT_CODE) +#define GPIO_IS_INTEDGE(ps) (((uint16_t)(ps) & GPIO_INTEDGE_MASK) == GPIO_INTEDGE_CODE) +#define GPIO_IS_INTLVL(ps) (((uint16_t)(ps) & GPIO_INTLVL_MASK) == GPIO_INTLVL_CODE) + +/* Wake-UP: + * + * .... W... .... .... + */ + +#define GPIO_WAKEUP (1 << 11) /* Bit 11: Wakeup Enable */ + +/* Pin Pull Up/Down: PP + * + * .... .RR. .... .... + */ + +#define GPIO_MODE_SHIFT (9) /* Bits 9-10: Pin pull up/down mode */ +#define GPIO_MODE_MASK (3 << GPIO_MODE_SHIFT) +# define GPIO_FLOAT (0 << GPIO_MODE_SHIFT) /* Neither pull-up nor -down */ +# define GPIO_PULLDOWN (1 << GPIO_MODE_SHIFT) /* Pull-down resistor enabled */ +# define GPIO_PULLUP (2 << GPIO_MODE_SHIFT) /* Pull-up resistor enabled */ + +/* Initial value: V + * + * .... ...V .... .... + */ + +#define GPIO_VALUE (1 << 8) /* Bit 8: Initial GPIO output value */ +# define GPIO_VALUE_ONE GPIO_VALUE +# define GPIO_VALUE_ZERO (0) + +/* Input Hysteresis: + * + * .... .... H... .... + */ + +#define GPIO_HYSTERESIS (1 << 7) /* Bit 7: Input hysteresis */ + +/* Slew Rate: + * + * .... .... .S.. .... + */ + +#define GPIO_SLEW (1 << 6) /* Bit 7: Slew rate mode */ + +/* Drive Strength: + * + * .... .... ..DD .... + */ + +#define GPIO_DRIVE_SHIFT (4) /* Bits 4-5: Drive strength */ +#define GPIO_DRIVE_MASK (3 << GPIO_MODE_SHIFT) +# define GPIO_DRIVE_LO (0 << GPIO_MODE_SHIFT) /* Low drive strength */ +# define GPIO_DRIVE_MEDLO (1 << GPIO_MODE_SHIFT) /* Low or medium-low drive */ +# define GPIO_DRIVE_MEDHI (2 << GPIO_MODE_SHIFT) /* High or midium-high driver */ +# define GPIO_DRIVE_HI (3 << GPIO_MODE_SHIFT) /* High drive strength */ + +/* Port number: There is only one port, GPIO0 + * + * .... .... .... .... + */ + +#define GPIO_PORT0 (0) + +/* Pin number: NNNN (0-13) + * + * .... .... .... NNNN + */ + +#define GPIO_PIN_SHIFT 0 /* Bits 0-3: GPIO number: 0-14 */ +#define GPIO_PIN_MASK (15 << GPIO_PIN_SHIFT) +# define GPIO_PIN0 (0 << GPIO_PIN_SHIFT) +# define GPIO_PIN1 (1 << GPIO_PIN_SHIFT) +# define GPIO_PIN2 (2 << GPIO_PIN_SHIFT) +# define GPIO_PIN3 (3 << GPIO_PIN_SHIFT) +# define GPIO_PIN4 (4 << GPIO_PIN_SHIFT) +# define GPIO_PIN5 (5 << GPIO_PIN_SHIFT) +# define GPIO_PIN6 (6 << GPIO_PIN_SHIFT) +# define GPIO_PIN7 (7 << GPIO_PIN_SHIFT) +# define GPIO_PIN8 (8 << GPIO_PIN_SHIFT) +# define GPIO_PIN9 (9 << GPIO_PIN_SHIFT) +# define GPIO_PIN10 (10 << GPIO_PIN_SHIFT) +# define GPIO_PIN11 (11 << GPIO_PIN_SHIFT) +# define GPIO_PIN12 (12 << GPIO_PIN_SHIFT) +# define GPIO_PIN13 (13 << GPIO_PIN_SHIFT) + +/************************************************************************************ + * Public Types + ************************************************************************************/ + +typedef uint16_t max326_pinset_t; + +#endif /* __ARCH_ARM_SRC_MAX326XX_MAX32660_GPIO_H */ diff --git a/arch/arm/src/max326xx/max326_gpio.h b/arch/arm/src/max326xx/max326_gpio.h new file mode 100644 index 0000000000..7fde688311 --- /dev/null +++ b/arch/arm/src/max326xx/max326_gpio.h @@ -0,0 +1,146 @@ +/************************************************************************************ + * arch/arm/src/max326xx/max326_gpio.h + * + * Copyright (C) 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __ARCH_ARM_SRC_MAX326XX_MAX326_GPIO_H +#define __ARCH_ARM_SRC_MAX326XX_MAX326_GPIO_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include + +#include "chip/max326_gpio.h" + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/* Bit-encoded input to max326_gpio_config() ******************************************/ + +#if defined(CONFIG_ARCH_FAMILY_MAX32620) || defined(CONFIG_ARCH_FAMILY_MAX32630) +# include "max32620_30_gpio.h" +#if defined(CONFIG_ARCH_FAMILY_MAX32660) +# include "max32660_gpio.h" +#else +# error "Unsupported MAX326XX family" +#endif + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +#ifndef __ASSEMBLY__ +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: max326_gpio_irqinitialize + * + * Description: + * Initialize logic to support interrupting GPIO pins. This function is called by + * the OS initialization logic and is not a user interface. + * + ************************************************************************************/ + +#ifdef CONFIG_MAX326_GPIOIRQ +void max326_gpio_irqinitialize(void); +#else +# define max326_gpio_irqinitialize() +#endif + +/************************************************************************************ + * Name: max326_gpio_config + * + * Description: + * Configure a GPIO pin based on bit-encoded description of the pin. + * + ************************************************************************************/ + +int max326_gpio_config(max326_pinset_t cfgset); + +/************************************************************************************ + * Name: max326_gpio_write + * + * Description: + * Write one or zero to the selected GPIO pin + * + ************************************************************************************/ + +void max326_gpio_write(max326_pinset_t pinset, bool value); + +/************************************************************************************ + * Name: max326_gpio_read + * + * Description: + * Read one or zero from the selected GPIO pin + * + ************************************************************************************/ + +bool max326_gpio_read(max326_pinset_t pinset); + +/************************************************************************************ + * Function: max326_gpio_dump + * + * Description: + * Dump all GPIO registers associated with the base address of the provided pinset. + * + ************************************************************************************/ + +#ifdef CONFIG_DEBUG_GPIO_INFO +int max326_gpio_dump(max326_pinset_t pinset, const char *msg); +#else +# define max326_gpio_dump(p,m) +#endif + +#ifdef __cplusplus +} +#endif +#endif /* __ASSEMBLY__ */ + +#endif /* __ARCH_ARM_SRC_MAX326XX_MAX326_GPIO_H */ diff --git a/configs/max32660-evsys/src/max326_autoleds.c b/configs/max32660-evsys/src/max326_autoleds.c index 204b360594..0b1b1254fc 100644 --- a/configs/max32660-evsys/src/max326_autoleds.c +++ b/configs/max32660-evsys/src/max326_autoleds.c @@ -90,7 +90,7 @@ void board_autoled_initialize(void) { /* Configure LED PIOs for output */ - max326_configgpio(GPIO_LED); + max326_gpio_config(GPIO_LED); } /**************************************************************************** @@ -101,7 +101,7 @@ void board_autoled_on(int led) { if (led == 1 || led == 3) { - max326_gpiowrite(GPIO_LED, false); /* Low illuminates */ + max326_gpio_write(GPIO_LED, false); /* Low illuminates */ } } @@ -113,7 +113,7 @@ void board_autoled_off(int led) { if (led == 3) { - max326_gpiowrite(GPIO_LED, true); /* High extinguishes */ + max326_gpio_write(GPIO_LED, true); /* High extinguishes */ } } diff --git a/configs/max32660-evsys/src/max326_userleds.c b/configs/max32660-evsys/src/max326_userleds.c index 1551a9c7f2..2639ea7162 100644 --- a/configs/max32660-evsys/src/max326_userleds.c +++ b/configs/max32660-evsys/src/max326_userleds.c @@ -60,7 +60,7 @@ void board_userled_initialize(void) { /* Configure LED PIOs for output */ - max326_configgpio(GPIO_LED); + max326_gpio_config(GPIO_LED); } /**************************************************************************** @@ -71,7 +71,7 @@ void board_userled(int led, bool ledon) { if (led == BOARD_LED) { - max326_gpiowrite(GPIO_LED, !ledon); /* Low illuminates */ + max326_gpio_write(GPIO_LED, !ledon); /* Low illuminates */ } } @@ -83,5 +83,5 @@ void board_userled_all(uint8_t ledset) { /* Low illuminates */ - max326_gpiowrite(GPIO_LED, (ledset & BOARD_LED_BIT) == 0)); + max326_gpio_write(GPIO_LED, (ledset & BOARD_LED_BIT) == 0)); }