This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Question about how to use user pushbuttons on LCDK board

Other Parts Discussed in Thread: OMAP-L138, OMAPL138

Hi,

I tried to use the examples provided by logic PD to test the LEDs on my LCDK using pushbuttons. However, the LEDs failed to initialize. 

The code is intended for a SOM1 board they manufactured before, but I am not sure what I need to do to change this to be a LCDK compatible code. Can someone provided with some tutorial about how to use the user pushbuttons on CCS? Thank you. The code for using user pushbuttons to control the LEDs is as follows:

//-----------------------------------------------------------------------------

// \file    test_led_pb.c

// \brief   implementation of OMAP-L138 leds/dip switch/pushbutton test.

//

//-----------------------------------------------------------------------------

#include "stdio.h"

#include "types.h"

#include "evmomapl138.h"

#include "evmomapl138_timer.h"

#include "evmomapl138_led.h"

#include "evmomapl138_pb.h"

#include "test_led_pb.h"

//-----------------------------------------------------------------------------

// Private Defines and Macros

//-----------------------------------------------------------------------------

#define PB_MASK_LED_1      (0x0000001E)

#define PB_MASK_LED_2      (0x000001E0)

//-----------------------------------------------------------------------------

// Static Variable Declarations

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------

// Private Function Prototypes

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------

// Public Function Definitions

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------

// \brief   tests the leds and pushbuttons. lights each led.

//          prints message to stdout for pushbutton changes.

//

// \param   none.

//

// \return  uint32_t

//-----------------------------------------------------------------------------

uint32_t TEST_ledPB(void)

{

   uint32_t rtn;

   uint32_t i;

   uint8_t tmp_val;

   uint32_t last_pb_state = 0;

   printf("------------------------------------------------------------\r\n");

   printf("              OMAP-L138 LED and Pushbutton Test\r\n\r\n");

   printf("Test Description\r\n");

   printf("----------------\r\n");

   printf("this code will begin by flashing the leds, then it will sit in\r\n");

   printf("a forever loop checking the pushbuttons. when a change in the \r\n");

   printf("pushbuttons is detected, a message will be printed to stdout \r\n");

   printf("and an led will be toggled.\r\n");

   printf("------------------------------------------------------------\r\n\r\n");

   //-------------------------------------

   // initialize the required bsl modules.

   //-------------------------------------

   printf("Initialize the Required BSL Modules\r\n");

   printf("-----------------------------------\r\n\r\n");

   rtn = LED_init();

   if (rtn != ERR_NO_ERROR)

   {

      printf("error initializing leds!\r\n");

      return (rtn);

   }

   

   rtn = PB_init();

   if (rtn != ERR_NO_ERROR)

   {

      printf("error initializing pushbuttons.\r\n\r\n");

      return (rtn);

   }

   

   //--------------

   // execute test.

   //--------------

   printf("\r\nExecute Test\r\n");

   printf("------------\r\n\r\n");

   printf("flash led patterns\r\n\r\n");

   

   // turn led 0 on and wait 1 second.

   LED_turnOn(LED_1);

   USTIMER_delay(DELAY_1_SEC);

   

   // turn led 1 on and wait 1 second.

   LED_turnOn(LED_2);

   USTIMER_delay(DELAY_1_SEC);

   

   // flash leds for a few seconds.

   for (i = 0; i < 5; i++)

   {

      LED_toggle(LED_1);

      LED_toggle(LED_2);

      USTIMER_delay(DELAY_HALF_SEC);

   }

   

   printf("loop forever printing pushbutton status\r\n\r\n");

   while (1)

   {

      // check the pushbuttons and print status changes.

      for (i = 0; i < MAX_PB_NUM; i++)

      {

         rtn = PB_get(i, &tmp_val);

         if (rtn != ERR_NO_ERROR)

            return (rtn);

         if (tmp_val)

         {

            if (!CHKBIT(last_pb_state, bitval_u32[i]))

            {

               printf("Pushbutton[%u] was pressed\r\n\r\n", i + 1);

            }

            SETBIT(last_pb_state, bitval_u32[i]);

         }

         else

         {

            if (CHKBIT(last_pb_state, bitval_u32[i]))

            {

               printf("Pushbutton[%u] was released\r\n\r\n", i + 1);

            }

            CLRBIT(last_pb_state, bitval_u32[i]);

         }

      }

      // set leds based on latest pb status.

      if (CHKBIT(last_pb_state, PB_MASK_LED_1))

         LED_turnOn(LED_1);

      else

         LED_turnOff(LED_1);

      if (CHKBIT(last_pb_state, PB_MASK_LED_2))

         LED_turnOn(LED_2);

      else

         LED_turnOff(LED_2);

   }

   // currently can't reach this due to the forever loop.

//    return (rtn);

}

//-----------------------------------------------------------------------------

// Private Function Definitions

//-----------------------------------------------------------------------------

  • Hi Zhexin,

    Please use the following code for testing switches and LED on LCDK boards.

    I have used DIP switch and not push button, try to use push button with pinmuxing.

    /**
    * \file    gpio_switch.c
    *
    * \brief   This is a sample application file demonstrating the use of
    *          a GPIO pin for input (DIP switch) and output (LED)
    *
    *
    * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
    *
    *  Redistribution and use in source and binary forms, with or without
    *  modification, are permitted provided that the following conditions
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright
    *    notice, this list of conditions and the following disclaimer.
    *
    *    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.
    *
    *    Neither the name of Texas Instruments Incorporated 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.
    */
    
    #include<stdio.h>
    
    #include "gpio.h"
    #include "psc.h"
    
    #include "soc_OMAPL138.h"
    #include "lcdkOMAPL138.h"
    
    /* HW Macros */
    #include "hw_types.h"
    
    /* System Defines */
    #include "lcdkOMAPL138.h"
    #include "soc_OMAPL138.h"
    #include "hw_syscfg0_OMAPL138.h"
    
    
    
    /* Switch Configuration */
    
    /* Titus : GP0[1] to GP0[4] is mapped to SW1[3:4] on OMAPL138/C6748 LCDK boards */
    
    /* Pin Multiplexing bit mask to select GP0[1] to GP0[4] pin. */
    
    #define PINMUX1_GPIO0_1_ENABLE    (SYSCFG_PINMUX1_PINMUX1_27_24_GPIO0_1  << \
                                        SYSCFG_PINMUX1_PINMUX1_27_24_SHIFT)
    
    #define PINMUX1_GPIO0_2_ENABLE    (SYSCFG_PINMUX1_PINMUX1_23_20_GPIO0_2  << \
                                        SYSCFG_PINMUX1_PINMUX1_23_20_SHIFT)
    
    #define PINMUX1_GPIO0_3_ENABLE    (SYSCFG_PINMUX1_PINMUX1_19_16_GPIO0_3  << \
                                        SYSCFG_PINMUX1_PINMUX1_19_16_SHIFT)
    
    #define PINMUX1_GPIO0_4_ENABLE    (SYSCFG_PINMUX1_PINMUX1_15_12_GPIO0_4  << \
                                        SYSCFG_PINMUX1_PINMUX1_15_12_SHIFT)
    
    
    /* LED Configuration */
    
    /* Titus : GP6[12], GP6[13], GP2[12] and GP0[9] is mapped to D4, D5, D6, D7 LEDs on OMAPL138/C6748 LCDK boards */
    
    /* Pin Multiplexing bit mask to select GP6[12] pin. */
    #define PINMUX13_GPIO6_12_ENABLE    (SYSCFG_PINMUX13_PINMUX13_15_12_GPIO6_12  << \
                                        SYSCFG_PINMUX13_PINMUX13_15_12_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP6[13] pin. */
    #define PINMUX13_GPIO6_13_ENABLE    (SYSCFG_PINMUX13_PINMUX13_11_8_GPIO6_13  << \
                                        SYSCFG_PINMUX13_PINMUX13_11_8_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP2[12] pin. */
    #define PINMUX5_GPIO2_12_ENABLE    (SYSCFG_PINMUX5_PINMUX5_15_12_GPIO2_12  << \
                                        SYSCFG_PINMUX5_PINMUX5_15_12_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP0[9] pin. */
    #define PINMUX0_GPIO0_9_ENABLE    (SYSCFG_PINMUX0_PINMUX0_27_24_GPIO0_9  << \
                                        SYSCFG_PINMUX0_PINMUX0_27_24_SHIFT)
    
    
    void PinMuxSetup_leds(void)
    {
         unsigned int savePinmux = 0;
    
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX13 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) &
                      ~(SYSCFG_PINMUX13_PINMUX13_15_12));
    
         /* Setting the pins corresponding to GP6[12] in PINMUX13 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) =
              (PINMUX13_GPIO6_12_ENABLE | savePinmux);
    
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX13 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) &
                      ~(SYSCFG_PINMUX13_PINMUX13_11_8));
    
         /* Setting the pins corresponding to GP6[13] in PINMUX13 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) =
              (PINMUX13_GPIO6_13_ENABLE | savePinmux);
    
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX5 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5)) &
                      ~(SYSCFG_PINMUX5_PINMUX5_15_12));
    
         /* Setting the pins corresponding to GP2[12] in PINMUX5 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5)) =
              (PINMUX5_GPIO2_12_ENABLE | savePinmux);
    
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX0 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) &
                      ~(SYSCFG_PINMUX0_PINMUX0_27_24));
    
         /* Setting the pins corresponding to GP0[9] in PINMUX0 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) =
              (PINMUX0_GPIO0_9_ENABLE | savePinmux);
    
    }
    
    
    
    void PinMuxSetup_switches(void)
    {
         unsigned int savePinmux = 0;
    
         /* Setting the pins corresponding to GP0[1] in PINMUX1 register.*/
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX1 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) &
                      ~(SYSCFG_PINMUX1_PINMUX1_27_24));
    
    
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) =
              (PINMUX1_GPIO0_1_ENABLE | savePinmux);
    
    
    
         /* Setting the pins corresponding to GP0[2] in PINMUX1 register.*/
    
              /*
              ** Clearing the bit in context and retaining the other bit values
              ** in PINMUX1 register.
              */
              savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) &
                           ~(SYSCFG_PINMUX1_PINMUX1_23_20));
    
    
              HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) =
                   (PINMUX1_GPIO0_2_ENABLE | savePinmux);
    
    
    
    
              /* Setting the pins corresponding to GP0[3] in PINMUX1 register.*/
    
                   /*
                   ** Clearing the bit in context and retaining the other bit values
                   ** in PINMUX1 register.
                   */
                   savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) &
                                ~(SYSCFG_PINMUX1_PINMUX1_19_16));
    
    
                   HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) =
                        (PINMUX1_GPIO0_3_ENABLE | savePinmux);
    
    
    
                   /* Setting the pins corresponding to GP0[4] in PINMUX1 register.*/
    
                        /*
                        ** Clearing the bit in context and retaining the other bit values
                        ** in PINMUX1 register.
                        */
                        savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) &
                                     ~(SYSCFG_PINMUX1_PINMUX1_15_12));
    
    
                        HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(1)) =
                             (PINMUX1_GPIO0_4_ENABLE | savePinmux);
    
    
    }
    
    
    int main(void)
    {
    
    
        /* The Local PSC number for GPIO is 3. GPIO belongs to PSC1 module.*/
        PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON,
                 PSC_MDCTL_NEXT_ENABLE);
    
    
        /* Pin Multiplexing of pins GP0[1] to GP0[4] of GPIO Bank 2 for DIP SWITCHEs in OMAPL138 LCDK board */
        PinMuxSetup_switches();
    
        /* Pin Multiplexing of pins GP6[12], GP6[13], GP2[12], GP0[9], for LEDs in OMAPL138 LCDK board */
        PinMuxSetup_leds();
    
    
        /* Titus : 2,3,4,5 is the GPIO no for GP0[1] to GP0[4]; Refer page no 901 in OMAPL138/C6748 TRM */
    
    
    /* SWITCHEs SETUP */
    
        /* Sets the pin 2 (GP0[1]) as input.*/
        GPIODirModeSet(SOC_GPIO_0_REGS, 2, GPIO_DIR_INPUT);
    
        /* Sets the pin 3 (GP0[2]) as input.*/
        GPIODirModeSet(SOC_GPIO_0_REGS, 3, GPIO_DIR_INPUT);
    
        /* Sets the pin 4 (GP0[3]) as input.*/
        GPIODirModeSet(SOC_GPIO_0_REGS, 4, GPIO_DIR_INPUT);
    
        /* Sets the pin 5 (GP0[4]) as input.*/
        GPIODirModeSet(SOC_GPIO_0_REGS, 5, GPIO_DIR_INPUT);
    
    /* LEDs SETUP */
    
        /* Sets the pin 109 (GP6[12]) as output.*/
        GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT);
    
        /* Sets the pin 110 (GP6[13]) as output.*/
        GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT);
    
        /* Sets the pin 45 (GP2[12]) as output.*/
        GPIODirModeSet(SOC_GPIO_0_REGS, 45, GPIO_DIR_OUTPUT);
    
        /* Sets the pin 10 (GP0[9]) as output.*/
        GPIODirModeSet(SOC_GPIO_0_REGS, 10, GPIO_DIR_OUTPUT);
    
    
        while(1)
        {
    
        /* Titus : 2,3,4,5 is the GPIO no for GP0[1] to GP0[4]; Refer page no 901 in OMAPL138/C6748 TRM */
    
            if (GPIOPinRead(SOC_GPIO_0_REGS, 2))
            {
    
            GPIOPinWrite(SOC_GPIO_0_REGS, 109, GPIO_PIN_LOW);
            printf("S1 is not pressed\n");
    
            }
    
            else
            {//TODO/* Hi Mus: Put your flip code here for 90' */
                printf("S1 is pressed\n");
                GPIOPinWrite(SOC_GPIO_0_REGS, 109, GPIO_PIN_HIGH);
    
            }
    
            if (GPIOPinRead(SOC_GPIO_0_REGS, 3))
            {
    
            GPIOPinWrite(SOC_GPIO_0_REGS, 110, GPIO_PIN_LOW);
            printf("S2 is not pressed\n");
    
            }
            else
                    {//TODO/* Hi Mus: Put your flip code here for 180' */
                        printf("S2 is pressed\n");
                        GPIOPinWrite(SOC_GPIO_0_REGS, 110, GPIO_PIN_HIGH);
    
                    }
    
    
            if (GPIOPinRead(SOC_GPIO_0_REGS, 4))
            {
    
            GPIOPinWrite(SOC_GPIO_0_REGS, 45, GPIO_PIN_LOW);
            printf("S3 is not pressed\n");
    
            }
            else
                    {//TODO/* Hi Mus: Put your flip code here for 270' */
                        printf("S3 is pressed\n");
                        GPIOPinWrite(SOC_GPIO_0_REGS, 45, GPIO_PIN_HIGH);
    
                    }
    
    
            if (GPIOPinRead(SOC_GPIO_0_REGS, 5))
            {
    
            GPIOPinWrite(SOC_GPIO_0_REGS, 10, GPIO_PIN_LOW);
            printf("S4 is not pressed\n");
    
    
            }
            else
                    {//TODO/* Hi Mus: Put your flip code here for 0' or 360'' */
                        printf("S4 is pressed\n");
                        GPIOPinWrite(SOC_GPIO_0_REGS, 10, GPIO_PIN_HIGH);
    
                    }
    
    
    
        }
    
    
    }

  • Hi Titusrathinaraj, 

    Thank you for the rapid response. Can you tell me how to find those headers that you include in your program? Also, can you specifically explain how can I use pinmuxing to use the pushbuttons? I am totally new to DSP development and not very sure about what things like "

    #define PINMUX13_GPIO6_12_ENABLE    (SYSCFG_PINMUX13_PINMUX13_15_12_GPIO6_12  << \
                                        SYSCFG_PINMUX13_PINMUX13_15_12_SHIFT)

    " mean. It could be even helpful if you an provide me with some tutorial or documentation about using gpio library with LCDK. Thanks a lot.

  • Hi Zhexin,

    You have to install the OMAPL138 starterware package on your machine and take gpio example as a reference code.

    OMAPL138_StarterWare_1_10_03_03/examples/lcdkOMAPL138/gpio/gpioCardDetect.c

    You can refer to the following TI wiki for user guide and downloads.

    http://processors.wiki.ti.com/index.php/StarterWare

  • Hi Titus,

    I tried to compile the first program you provide, but it shows up some errors for unresolved symbols like GPIODirModeSet,GPIODirModeRead, GPIODirModeWrite, PSCModuleControl. Do you know where can I find the files that define these functions? Thanks a lot.

  • Hi Zhexin,

    Have you installed staterware package on your machine ?

    like GPIODirModeSet,GPIODirModeRead, GPIODirModeWrite, PSCModuleControl. Do you know where can I find the files that define these functions? Thanks a lot.

    If yes. Then you have to provide the library path for the project to avoid the linker error.

    Otherwise you have to copy and paste the above code into "gpio example" code which already had the library path and everything.

    Before that you need to import the gpio example code and copy & paste the above code which supports DIP switch and LED.

  • Hi Titus,

    I installed the StarterWare in the following path: C:\ti\OMAPL138_StarterWare_1_10_04_01 on my computer. Can you tell me how to link the required files in CCS for the program you provided? There are many folders inside the StarterWare but I am not sure where to find those definitions I need. I encountered errors like:

    Description Resource Path Location Type
    unresolved symbol _GPIOPinWrite, first referenced in ./dips_sw_leds.obj button_gpio C/C++ Problem
    unresolved symbol _GPIOPinRead, first referenced in ./dips_sw_leds.obj button_gpio C/C++ Problem
    unresolved symbol _GPIODirModeSet, first referenced in ./dips_sw_leds.obj button_gpio C/C++ Problem
    #10010 errors encountered during linking; "button_gpio.out" not built button_gpio C/C++ Problem
    #10234-D unresolved symbols remain button_gpio C/C++ Problem
    unresolved symbol _PSCModuleControl, first referenced in ./dips_sw_leds.obj button_gpio C/C++ Problem

    Thanks a lot

  • Hi Titus,

    I imported the gpio example from StarterWare in CCS and replaced the content with your program and it worked. However, since I want to incorporate the io function with my own project, I need to include my own libraries. However, when I added my own libraries in the project and include them in the source code and compiled, it showed "could not open source file "L138_LCDK_aic3106.h"" even though I clearly added them in the project. Do you know what might be the problem? Could it be due to the version of compiler I am using? Since it gave warning about the version of compiler that created the example gpio project  in StarterWare is not currently installed. Thanks a lot.

  • Hi Zhexin,

    it showed "could not open source file "L138_LCDK_aic3106.h"" even though I clearly added them in the project. Do you know what might be the problem? Could it be due to the version of compiler I am using?

    You have to set the include path for the "L138_LCDK_aic3106.h" file.

    Project Properties --> C6000 Compiler --> Include options

  • Hi Titus,

    I am sure I've included in my file. That's really weird..

  • Hi Zhexin,

    1) Where do you have "L138_LCDK_aic3106.h" file on your machine and set the path correctly ?

    Could you attach the screen shot of "include options" of CCS project properties.

    CCS Project Properties --> C6000 Compiler --> Include options


    2) Try to "L138_LCDK_aic3106.h" file in "C:\ti\OMAPL138_StarterWare_1_10_04_01\include" location.

  • Hi Titus,

    I tired what you say to copy and paste header files from Logic PD's board support library to  "C:\ti\OMAPL138_StarterWare_1_10_04_01\include". It looks better, but I still got problems like unresolved symbols _interrupt4, vectors. I attach a screen for these issues. Do you know how to fix it. Thanks a lot.

  • Hi Zhexin,

    From screen shot,

    Actually "vector_intr.c" file has definition of "_interrupt4" and "L138_LCDK_aic3106_init.c" file has definition of "vectors"

    You need to declare those variables in correct file and location & try to check these declarations and how they have used in where you got this examples.

  • Hi Titus,

    vector_intr is a .asm file that is defined in another library that we are using for signal processing. I want to combine that with the code you provide so that we can switch between different processing mode by change the dip switch settings. Your program work fine solely, but once I copied all needed files from the other library and used them with your program.  There were compilation problems like undeclared variables as shown in the screenshot provided. Do you know what is the problem. Thank you very much.