1    /*
     2     * Copyright (c) 2016, Texas Instruments Incorporated
     3     * All rights reserved.
     4     *
     5     * Redistribution and use in source and binary forms, with or without
     6     * modification, are permitted provided that the following conditions
     7     * are met:
     8     *
     9     * *  Redistributions of source code must retain the above copyright
    10     *    notice, this list of conditions and the following disclaimer.
    11     *
    12     * *  Redistributions in binary form must reproduce the above copyright
    13     *    notice, this list of conditions and the following disclaimer in the
    14     *    documentation and/or other materials provided with the distribution.
    15     *
    16     * *  Neither the name of Texas Instruments Incorporated nor the names of
    17     *    its contributors may be used to endorse or promote products derived
    18     *    from this software without specific prior written permission.
    19     *
    20     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    21     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    22     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    23     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    24     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    25     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    26     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    27     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    28     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    29     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    30     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31     */
    32    
    33    import ti.catalog.msp430.peripherals.comparator.IComparator as Comparator;
    34    
    35    /*!
    36     *  ======== GPIO for MSP430F21x1 ========
    37     *  MSP430 General Purpose Input Output Ports
    38     */
    39    metaonly module GPIO_MSP430F21x1 inherits IGPIO {
    40        /*!
    41         *  ======== create ========
    42         *  Create an instance of this peripheral. Use a customized
    43         *  init function so that we can get access to the ADC10
    44         *  instance.
    45         */
    46        create(Comparator.Instance comparator);
    47    
    48    instance:
    49        /*! @_nodoc */
    50        config Comparator.Instance comparator;
    51    
    52       /*! Define an array to describe all device pins. The 1st dimension
    53        *  denotes the port, the second the pin on that port. On an
    54        *  MSP430F21x1 device, there are 2 x 8 = 16 pins total.
    55        */
    56    
    57        /* TODO: This here should really be a module-wide feature, rather than an instance feature,
    58         * however due to limitations in XDCtools 3.21.0.0 the data is located here */
    59        /* TODO: For this device the config variable definition has been moved into the
    60         * corresponding XS file due to its size. This needs a more consistent solution. */
    61        config DevicePin_t devicePins[2][8];
    62    
    63        /*! Implementation of Device Pin Functional Configuration */
    64        override config DevicePinFunctionSetting_t devicePinSetting[2][8];
    65    
    66        /*! Determine if each Register needs to be forced set or not */
    67        readonly config ForceSetDefaultRegister_t forceSetDefaultRegister[] =
    68        [
    69            { register : "P1OUT" , regForceSet : true  },
    70            { register : "P1SEL" , regForceSet : false },
    71            { register : "P1DIR" , regForceSet : true  },
    72            { register : "P1REN" , regForceSet : false },
    73            { register : "P1IES" , regForceSet : true },
    74            { register : "P1IFG" , regForceSet : true },
    75            { register : "P1IE"  , regForceSet : false },
    76            { register : "P2OUT" , regForceSet : true  },
    77            { register : "P2SEL" , regForceSet : false },
    78            { register : "P2DIR" , regForceSet : true  },
    79            { register : "P2REN" , regForceSet : false },
    80            { register : "P2IES" , regForceSet : true },
    81            { register : "P2IFG" , regForceSet : true },
    82            { register : "P2IE"  , regForceSet : false },
    83        ];
    84    
    85        /*
    86         *  GPIO Digital I/O Registers
    87         *
    88         *  One GIPO instance defines the configuration of an entire,
    89         *  8-bit wide digital I/O port.
    90         */
    91    
    92        /*! Port 1 Output Register */
    93        config GpioBits8PxOut_t P1OUT = {
    94            Bit0        : BIT0_OFF,
    95            Bit1        : BIT1_OFF,
    96            Bit2        : BIT2_OFF,
    97            Bit3        : BIT3_OFF,
    98            Bit4        : BIT4_OFF,
    99            Bit5        : BIT5_OFF,
   100            Bit6        : BIT6_OFF,
   101            Bit7        : BIT7_OFF
   102        };
   103    
   104        /*! Port 1 Port Select Register */
   105        config GpioBits8PxSel_t P1SEL = {
   106            Bit0        : BIT0_OFF,
   107            Bit1        : BIT1_OFF,
   108            Bit2        : BIT2_OFF,
   109            Bit3        : BIT3_OFF,
   110            Bit4        : BIT4_OFF,
   111            Bit5        : BIT5_OFF,
   112            Bit6        : BIT6_OFF,
   113            Bit7        : BIT7_OFF
   114        };
   115    
   116        /*! Port 1 Direction Register */
   117        config GpioBits8PxDir_t P1DIR = {
   118            Bit0        : BIT0_OFF,
   119            Bit1        : BIT1_OFF,
   120            Bit2        : BIT2_OFF,
   121            Bit3        : BIT3_OFF,
   122            Bit4        : BIT4_OFF,
   123            Bit5        : BIT5_OFF,
   124            Bit6        : BIT6_OFF,
   125            Bit7        : BIT7_OFF
   126        };
   127    
   128        /*! Port 1 Resistor Enable Register */
   129        config GpioBits8PxRen_t P1REN = {
   130            Bit0        : BIT0_OFF,
   131            Bit1        : BIT1_OFF,
   132            Bit2        : BIT2_OFF,
   133            Bit3        : BIT3_OFF,
   134            Bit4        : BIT4_OFF,
   135            Bit5        : BIT5_OFF,
   136            Bit6        : BIT6_OFF,
   137            Bit7        : BIT7_OFF
   138        };
   139    
   140        /*! Port 2 Output Register */
   141        config GpioBits8PxOut_t P2OUT = {
   142            Bit0        : BIT0_OFF,
   143            Bit1        : BIT1_OFF,
   144            Bit2        : BIT2_OFF,
   145            Bit3        : BIT3_OFF,
   146            Bit4        : BIT4_OFF,
   147            Bit5        : BIT5_OFF,
   148            Bit6        : BIT6_OFF,
   149            Bit7        : BIT7_OFF
   150        };
   151    
   152        /*! Port 2 Port Select Register */
   153        config GpioBits8PxSel_t P2SEL = {
   154            Bit0        : BIT0_OFF,
   155            Bit1        : BIT1_OFF,
   156            Bit2        : BIT2_OFF,
   157            Bit3        : BIT3_OFF,
   158            Bit4        : BIT4_OFF,
   159            Bit5        : BIT5_OFF,
   160            Bit6        : BIT6,         /* POR default for all 2xx devices */
   161            Bit7        : BIT7          /* POR default for all 2xx devices */
   162        };
   163    
   164        /*! Port 2 Direction Register */
   165        config GpioBits8PxDir_t P2DIR = {
   166            Bit0        : BIT0_OFF,
   167            Bit1        : BIT1_OFF,
   168            Bit2        : BIT2_OFF,
   169            Bit3        : BIT3_OFF,
   170            Bit4        : BIT4_OFF,
   171            Bit5        : BIT5_OFF,
   172            Bit6        : BIT6_OFF,
   173            Bit7        : BIT7_OFF
   174        };
   175    
   176        /*! Port 2 Resistor Enable Register */
   177        config GpioBits8PxRen_t P2REN = {
   178            Bit0        : BIT0_OFF,
   179            Bit1        : BIT1_OFF,
   180            Bit2        : BIT2_OFF,
   181            Bit3        : BIT3_OFF,
   182            Bit4        : BIT4_OFF,
   183            Bit5        : BIT5_OFF,
   184            Bit6        : BIT6_OFF,
   185            Bit7        : BIT7_OFF
   186        };
   187    }