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 MSP430G2x44 ========
    38     *  MSP430 General Purpose Input Output Ports
    39     */
    40    metaonly module GPIO_MSP430G2x44 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         *  MSP430G2x44 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        /*! Implementation of Device Pin Functional Configuration */
    66        override config DevicePinFunctionSetting_t devicePinSetting[4][8];
    67    
    68        /*! Determine if each Register needs to be forced set or not */
    69        readonly config ForceSetDefaultRegister_t forceSetDefaultRegister[] =
    70        [
    71            { register : "P1OUT" , regForceSet : true  },
    72            { register : "P1SEL" , regForceSet : false },
    73            { register : "P1DIR" , regForceSet : true  },
    74            { register : "P1REN" , regForceSet : false },
    75            { register : "P1IES" , regForceSet : true },
    76            { register : "P1IFG" , regForceSet : true },
    77            { register : "P1IE"  , regForceSet : false },
    78            { register : "P2OUT" , regForceSet : true  },
    79            { register : "P2SEL" , regForceSet : false },
    80            { register : "P2DIR" , regForceSet : true  },
    81            { register : "P2REN" , regForceSet : false },
    82            { register : "P2IES" , regForceSet : true },
    83            { register : "P2IFG" , regForceSet : true },
    84            { register : "P2IE"  , regForceSet : false },
    85            { register : "P3OUT" , regForceSet : true  },
    86            { register : "P3SEL" , regForceSet : false },
    87            { register : "P3DIR" , regForceSet : true  },
    88            { register : "P3REN" , regForceSet : false },
    89            { register : "P4OUT" , regForceSet : true  },
    90            { register : "P4SEL" , regForceSet : false },
    91            { register : "P4DIR" , regForceSet : true  },
    92            { register : "P4REN" , regForceSet : false }
    93        ];
    94    
    95        /*
    96         *  GPIO Digital I/O Registers
    97         *
    98         *  One GIPO instance defines the configuration of an entire,
    99         *  8-bit wide digital I/O port.
   100         */
   101    
   102        /*! Port 1 Output Register */
   103        config GpioBits8PxOut_t P1OUT = {
   104            Bit0        : BIT0_OFF,
   105            Bit1        : BIT1_OFF,
   106            Bit2        : BIT2_OFF,
   107            Bit3        : BIT3_OFF,
   108            Bit4        : BIT4_OFF,
   109            Bit5        : BIT5_OFF,
   110            Bit6        : BIT6_OFF,
   111            Bit7        : BIT7_OFF
   112        };
   113    
   114        /*! Port 1 Port Select Register */
   115        config GpioBits8PxSel_t P1SEL = {
   116            Bit0        : BIT0_OFF,
   117            Bit1        : BIT1_OFF,
   118            Bit2        : BIT2_OFF,
   119            Bit3        : BIT3_OFF,
   120            Bit4        : BIT4_OFF,
   121            Bit5        : BIT5_OFF,
   122            Bit6        : BIT6_OFF,
   123            Bit7        : BIT7_OFF
   124        };
   125    
   126        /*! Port 1 Direction Register */
   127        config GpioBits8PxDir_t P1DIR = {
   128            Bit0        : BIT0_OFF,
   129            Bit1        : BIT1_OFF,
   130            Bit2        : BIT2_OFF,
   131            Bit3        : BIT3_OFF,
   132            Bit4        : BIT4_OFF,
   133            Bit5        : BIT5_OFF,
   134            Bit6        : BIT6_OFF,
   135            Bit7        : BIT7_OFF
   136        };
   137    
   138        /*! Port 1 Resistor Enable Register */
   139        config GpioBits8PxRen_t P1REN = {
   140            Bit0        : BIT0_OFF,
   141            Bit1        : BIT1_OFF,
   142            Bit2        : BIT2_OFF,
   143            Bit3        : BIT3_OFF,
   144            Bit4        : BIT4_OFF,
   145            Bit5        : BIT5_OFF,
   146            Bit6        : BIT6_OFF,
   147            Bit7        : BIT7_OFF
   148        };
   149    
   150        /*! Port 2 Output Register */
   151        config GpioBits8PxOut_t P2OUT = {
   152            Bit0        : BIT0_OFF,
   153            Bit1        : BIT1_OFF,
   154            Bit2        : BIT2_OFF,
   155            Bit3        : BIT3_OFF,
   156            Bit4        : BIT4_OFF,
   157            Bit5        : BIT5_OFF,
   158            Bit6        : BIT6_OFF,
   159            Bit7        : BIT7_OFF
   160        };
   161    
   162        /*! Port 2 Port Select Register */
   163        config GpioBits8PxSel_t P2SEL = {
   164            Bit0        : BIT0_OFF,
   165            Bit1        : BIT1_OFF,
   166            Bit2        : BIT2_OFF,
   167            Bit3        : BIT3_OFF,
   168            Bit4        : BIT4_OFF,
   169            Bit5        : BIT5_OFF,
   170            Bit6        : BIT6,         /* POR default for all 2xx devices */
   171            Bit7        : BIT7          /* POR default for all 2xx devices */
   172        };
   173    
   174        /*! Port 2 Direction Register */
   175        config GpioBits8PxDir_t P2DIR = {
   176            Bit0        : BIT0_OFF,
   177            Bit1        : BIT1_OFF,
   178            Bit2        : BIT2_OFF,
   179            Bit3        : BIT3_OFF,
   180            Bit4        : BIT4_OFF,
   181            Bit5        : BIT5_OFF,
   182            Bit6        : BIT6_OFF,
   183            Bit7        : BIT7_OFF
   184        };
   185    
   186        /*! Port 2 Resistor Enable Register */
   187        config GpioBits8PxRen_t P2REN = {
   188            Bit0        : BIT0_OFF,
   189            Bit1        : BIT1_OFF,
   190            Bit2        : BIT2_OFF,
   191            Bit3        : BIT3_OFF,
   192            Bit4        : BIT4_OFF,
   193            Bit5        : BIT5_OFF,
   194            Bit6        : BIT6_OFF,
   195            Bit7        : BIT7_OFF
   196        };
   197    
   198        /*! Port 3 Output Register */
   199        config GpioBits8PxOut_t P3OUT = {
   200            Bit0        : BIT0_OFF,
   201            Bit1        : BIT1_OFF,
   202            Bit2        : BIT2_OFF,
   203            Bit3        : BIT3_OFF,
   204            Bit4        : BIT4_OFF,
   205            Bit5        : BIT5_OFF,
   206            Bit6        : BIT6_OFF,
   207            Bit7        : BIT7_OFF
   208        };
   209    
   210        /*! Port 3 Port Select Register */
   211        config GpioBits8PxSel_t P3SEL = {
   212            Bit0        : BIT0_OFF,
   213            Bit1        : BIT1_OFF,
   214            Bit2        : BIT2_OFF,
   215            Bit3        : BIT3_OFF,
   216            Bit4        : BIT4_OFF,
   217            Bit5        : BIT5_OFF,
   218            Bit6        : BIT6_OFF,
   219            Bit7        : BIT7_OFF
   220        };
   221    
   222        /*! Port 3 Direction Register */
   223        config GpioBits8PxDir_t P3DIR = {
   224            Bit0        : BIT0_OFF,
   225            Bit1        : BIT1_OFF,
   226            Bit2        : BIT2_OFF,
   227            Bit3        : BIT3_OFF,
   228            Bit4        : BIT4_OFF,
   229            Bit5        : BIT5_OFF,
   230            Bit6        : BIT6_OFF,
   231            Bit7        : BIT7_OFF
   232        };
   233    
   234        /*! Port 3 Resistor Enable Register */
   235        config GpioBits8PxRen_t P3REN = {
   236            Bit0        : BIT0_OFF,
   237            Bit1        : BIT1_OFF,
   238            Bit2        : BIT2_OFF,
   239            Bit3        : BIT3_OFF,
   240            Bit4        : BIT4_OFF,
   241            Bit5        : BIT5_OFF,
   242            Bit6        : BIT6_OFF,
   243            Bit7        : BIT7_OFF
   244        };
   245    
   246        /*! Port 4 Output Register */
   247        config GpioBits8PxOut_t P4OUT = {
   248            Bit0        : BIT0_OFF,
   249            Bit1        : BIT1_OFF,
   250            Bit2        : BIT2_OFF,
   251            Bit3        : BIT3_OFF,
   252            Bit4        : BIT4_OFF,
   253            Bit5        : BIT5_OFF,
   254            Bit6        : BIT6_OFF,
   255            Bit7        : BIT7_OFF
   256        };
   257    
   258        /*! Port 4 Port Select Register */
   259        config GpioBits8PxSel_t P4SEL = {
   260            Bit0        : BIT0_OFF,
   261            Bit1        : BIT1_OFF,
   262            Bit2        : BIT2_OFF,
   263            Bit3        : BIT3_OFF,
   264            Bit4        : BIT4_OFF,
   265            Bit5        : BIT5_OFF,
   266            Bit6        : BIT6_OFF,
   267            Bit7        : BIT7_OFF
   268        };
   269    
   270        /*! Port 4 Direction Register */
   271        config GpioBits8PxDir_t P4DIR = {
   272            Bit0        : BIT0_OFF,
   273            Bit1        : BIT1_OFF,
   274            Bit2        : BIT2_OFF,
   275            Bit3        : BIT3_OFF,
   276            Bit4        : BIT4_OFF,
   277            Bit5        : BIT5_OFF,
   278            Bit6        : BIT6_OFF,
   279            Bit7        : BIT7_OFF
   280        };
   281    
   282        /*! Port 4 Resistor Enable Register */
   283        config GpioBits8PxRen_t P4REN = {
   284            Bit0        : BIT0_OFF,
   285            Bit1        : BIT1_OFF,
   286            Bit2        : BIT2_OFF,
   287            Bit3        : BIT3_OFF,
   288            Bit4        : BIT4_OFF,
   289            Bit5        : BIT5_OFF,
   290            Bit6        : BIT6_OFF,
   291            Bit7        : BIT7_OFF
   292        };
   293    }