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.adc.ADC10 as ADC10;
    34    import ti.catalog.msp430.peripherals.clock.BCSplus as BCSplus;
    35    
    36    /*!
    37     *  ======== GPIO for MSP430F22x4 ========
    38     *  MSP430 General Purpose Input Output Ports
    39     */
    40    metaonly module GPIO_MSP430F22x4 inherits IGPIO {
    41        /*!
    42         *  ======== create ========
    43         *  Create an instance of this peripheral. Use a customized
    44         *  init function so that we can get access to the ADC10
    45         *  and BCS+ instances.
    46         */
    47        create(ADC10.Instance adc10, BCSplus.Instance clock);
    48    
    49    instance:
    50        /*! @_nodoc */
    51        config ADC10.Instance adc10;
    52    
    53        /*! @_nodoc */
    54        config BCSplus.Instance clock;
    55    
    56        /*! Define an array to describe all device pins. The 1st dimension
    57         *  denotes the port, the second the pin on that port. On an
    58         *  MSP430F22xx device, there are 4 x 8 = 32 pins total.
    59         */
    60    
    61        /* TODO: This here should really be a module-wide feature, rather than an instance feature,
    62         * however due to limitations in XDCtools 3.21.0.0 the data is located here */
    63        readonly config DevicePin_t devicePins[4][8];
    64    
    65    
    66        /*! Implementation of Device Pin Functional Configuration */
    67        override config DevicePinFunctionSetting_t devicePinSetting[4][8];
    68    
    69        /*! Determine if each Register needs to be forced set or not */
    70        readonly config ForceSetDefaultRegister_t forceSetDefaultRegister[] =
    71        [
    72            { register : "P1OUT" , regForceSet : true  },
    73            { register : "P1SEL" , regForceSet : false },
    74            { register : "P1DIR" , regForceSet : true  },
    75            { register : "P1REN" , regForceSet : false },
    76            { register : "P1IES" , regForceSet : true },
    77            { register : "P1IFG" , regForceSet : true },
    78            { register : "P1IE"  , regForceSet : false },
    79            { register : "P2OUT" , regForceSet : true  },
    80            { register : "P2SEL" , regForceSet : false },
    81            { register : "P2DIR" , regForceSet : true  },
    82            { register : "P2REN" , regForceSet : false },
    83            { register : "P2IES" , regForceSet : true },
    84            { register : "P2IFG" , regForceSet : true },
    85            { register : "P2IE"  , regForceSet : false },
    86            { register : "P3OUT" , regForceSet : true  },
    87            { register : "P3SEL" , regForceSet : false },
    88            { register : "P3DIR" , regForceSet : true  },
    89            { register : "P3REN" , regForceSet : false },
    90            { register : "P4OUT" , regForceSet : true  },
    91            { register : "P4SEL" , regForceSet : false },
    92            { register : "P4DIR" , regForceSet : true  },
    93            { register : "P4REN" , regForceSet : false }
    94        ];
    95    
    96        /*
    97         *  GPIO Digital I/O Registers
    98         *
    99         *  One GIPO instance defines the configuration of an entire,
   100         *  8-bit wide digital I/O port.
   101         */
   102    
   103        /*! Port 1 Output Register */
   104        config GpioBits8PxOut_t P1OUT = {
   105            Bit0        : BIT0_OFF,
   106            Bit1        : BIT1_OFF,
   107            Bit2        : BIT2_OFF,
   108            Bit3        : BIT3_OFF,
   109            Bit4        : BIT4_OFF,
   110            Bit5        : BIT5_OFF,
   111            Bit6        : BIT6_OFF,
   112            Bit7        : BIT7_OFF
   113        };
   114    
   115        /*! Port 1 Port Select Register */
   116        config GpioBits8PxSel_t P1SEL = {
   117            Bit0        : BIT0_OFF,
   118            Bit1        : BIT1_OFF,
   119            Bit2        : BIT2_OFF,
   120            Bit3        : BIT3_OFF,
   121            Bit4        : BIT4_OFF,
   122            Bit5        : BIT5_OFF,
   123            Bit6        : BIT6_OFF,
   124            Bit7        : BIT7_OFF
   125        };
   126    
   127        /*! Port 1 Direction Register */
   128        config GpioBits8PxDir_t P1DIR = {
   129            Bit0        : BIT0_OFF,
   130            Bit1        : BIT1_OFF,
   131            Bit2        : BIT2_OFF,
   132            Bit3        : BIT3_OFF,
   133            Bit4        : BIT4_OFF,
   134            Bit5        : BIT5_OFF,
   135            Bit6        : BIT6_OFF,
   136            Bit7        : BIT7_OFF
   137        };
   138    
   139        /*! Port 1 Resistor Enable Register */
   140        config GpioBits8PxRen_t P1REN = {
   141            Bit0        : BIT0_OFF,
   142            Bit1        : BIT1_OFF,
   143            Bit2        : BIT2_OFF,
   144            Bit3        : BIT3_OFF,
   145            Bit4        : BIT4_OFF,
   146            Bit5        : BIT5_OFF,
   147            Bit6        : BIT6_OFF,
   148            Bit7        : BIT7_OFF
   149        };
   150    
   151        /*! Port 2 Output Register */
   152        config GpioBits8PxOut_t P2OUT = {
   153            Bit0        : BIT0_OFF,
   154            Bit1        : BIT1_OFF,
   155            Bit2        : BIT2_OFF,
   156            Bit3        : BIT3_OFF,
   157            Bit4        : BIT4_OFF,
   158            Bit5        : BIT5_OFF,
   159            Bit6        : BIT6_OFF,
   160            Bit7        : BIT7_OFF
   161        };
   162    
   163        /*! Port 2 Port Select Register */
   164        config GpioBits8PxSel_t P2SEL = {
   165            Bit0        : BIT0_OFF,
   166            Bit1        : BIT1_OFF,
   167            Bit2        : BIT2_OFF,
   168            Bit3        : BIT3_OFF,
   169            Bit4        : BIT4_OFF,
   170            Bit5        : BIT5_OFF,
   171            Bit6        : BIT6,         /* POR default for all 2xx devices */
   172            Bit7        : BIT7          /* POR default for all 2xx devices */
   173        };
   174    
   175        /*! Port 2 Direction Register */
   176        config GpioBits8PxDir_t P2DIR = {
   177            Bit0        : BIT0_OFF,
   178            Bit1        : BIT1_OFF,
   179            Bit2        : BIT2_OFF,
   180            Bit3        : BIT3_OFF,
   181            Bit4        : BIT4_OFF,
   182            Bit5        : BIT5_OFF,
   183            Bit6        : BIT6_OFF,
   184            Bit7        : BIT7_OFF
   185        };
   186    
   187        /*! Port 2 Resistor Enable Register */
   188        config GpioBits8PxRen_t P2REN = {
   189            Bit0        : BIT0_OFF,
   190            Bit1        : BIT1_OFF,
   191            Bit2        : BIT2_OFF,
   192            Bit3        : BIT3_OFF,
   193            Bit4        : BIT4_OFF,
   194            Bit5        : BIT5_OFF,
   195            Bit6        : BIT6_OFF,
   196            Bit7        : BIT7_OFF
   197        };
   198    
   199        /*! Port 3 Output Register */
   200        config GpioBits8PxOut_t P3OUT = {
   201            Bit0        : BIT0_OFF,
   202            Bit1        : BIT1_OFF,
   203            Bit2        : BIT2_OFF,
   204            Bit3        : BIT3_OFF,
   205            Bit4        : BIT4_OFF,
   206            Bit5        : BIT5_OFF,
   207            Bit6        : BIT6_OFF,
   208            Bit7        : BIT7_OFF
   209        };
   210    
   211        /*! Port 3 Port Select Register */
   212        config GpioBits8PxSel_t P3SEL = {
   213            Bit0        : BIT0_OFF,
   214            Bit1        : BIT1_OFF,
   215            Bit2        : BIT2_OFF,
   216            Bit3        : BIT3_OFF,
   217            Bit4        : BIT4_OFF,
   218            Bit5        : BIT5_OFF,
   219            Bit6        : BIT6_OFF,
   220            Bit7        : BIT7_OFF
   221        };
   222    
   223        /*! Port 3 Direction Register */
   224        config GpioBits8PxDir_t P3DIR = {
   225            Bit0        : BIT0_OFF,
   226            Bit1        : BIT1_OFF,
   227            Bit2        : BIT2_OFF,
   228            Bit3        : BIT3_OFF,
   229            Bit4        : BIT4_OFF,
   230            Bit5        : BIT5_OFF,
   231            Bit6        : BIT6_OFF,
   232            Bit7        : BIT7_OFF
   233        };
   234    
   235        /*! Port 3 Resistor Enable Register */
   236        config GpioBits8PxRen_t P3REN = {
   237            Bit0        : BIT0_OFF,
   238            Bit1        : BIT1_OFF,
   239            Bit2        : BIT2_OFF,
   240            Bit3        : BIT3_OFF,
   241            Bit4        : BIT4_OFF,
   242            Bit5        : BIT5_OFF,
   243            Bit6        : BIT6_OFF,
   244            Bit7        : BIT7_OFF
   245        };
   246    
   247        /*! Port 4 Output Register */
   248        config GpioBits8PxOut_t P4OUT = {
   249            Bit0        : BIT0_OFF,
   250            Bit1        : BIT1_OFF,
   251            Bit2        : BIT2_OFF,
   252            Bit3        : BIT3_OFF,
   253            Bit4        : BIT4_OFF,
   254            Bit5        : BIT5_OFF,
   255            Bit6        : BIT6_OFF,
   256            Bit7        : BIT7_OFF
   257        };
   258    
   259        /*! Port 4 Port Select Register */
   260        config GpioBits8PxSel_t P4SEL = {
   261            Bit0        : BIT0_OFF,
   262            Bit1        : BIT1_OFF,
   263            Bit2        : BIT2_OFF,
   264            Bit3        : BIT3_OFF,
   265            Bit4        : BIT4_OFF,
   266            Bit5        : BIT5_OFF,
   267            Bit6        : BIT6_OFF,
   268            Bit7        : BIT7_OFF
   269        };
   270    
   271        /*! Port 4 Direction Register */
   272        config GpioBits8PxDir_t P4DIR = {
   273            Bit0        : BIT0_OFF,
   274            Bit1        : BIT1_OFF,
   275            Bit2        : BIT2_OFF,
   276            Bit3        : BIT3_OFF,
   277            Bit4        : BIT4_OFF,
   278            Bit5        : BIT5_OFF,
   279            Bit6        : BIT6_OFF,
   280            Bit7        : BIT7_OFF
   281        };
   282    
   283        /*! Port 4 Resistor Enable Register */
   284        config GpioBits8PxRen_t P4REN = {
   285            Bit0        : BIT0_OFF,
   286            Bit1        : BIT1_OFF,
   287            Bit2        : BIT2_OFF,
   288            Bit3        : BIT3_OFF,
   289            Bit4        : BIT4_OFF,
   290            Bit5        : BIT5_OFF,
   291            Bit6        : BIT6_OFF,
   292            Bit7        : BIT7_OFF
   293        };
   294    }