Re: How to use TWR-K60N512's GPIO in user app

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: How to use TWR-K60N512's GPIO in user app

Ilija Kocho [Илија Кочо]
On 17.05.2013 02:38, [hidden email] wrote:

> Dear ilijak
> I want to use the TWR-K60N512's GPIO in my app.c
>
> below is some of my codes, and it can't work correctly,could you
> please tell me where is the bug,thanks.
>
> #include <cyg/hal/var_io.h> //gpio function header file
>
> //set the PORTA bit_19 and bit_11 as GPIO function
> #define KEY1_GPIO_ENABLE CYGHWR_HAL_KINETIS_PIN(A, 19,
> CYGHWR_HAL_KINETIS_PORT_PCR_MUX_GPIO,
> CYGHWR_HAL_KINETIS_PORT_PCR_PE_M) //KEY1
> #define LED1_GPIO_ENABLE CYGHWR_HAL_KINETIS_PIN(A, 11,
> CYGHWR_HAL_KINETIS_PORT_PCR_MUX_GPIO,
> CYGHWR_HAL_KINETIS_PORT_PCR_PE_M) //LED1
>
> //set the GPIO as INPUT and OUTPUT
> #define KEY1_INPUT_ENABLE CYGHWR_HAL_KINETIS_GPIO_PIN_DDR_IN(A, 19)
> #define LED1_OUTPUT_ENABLE CYGHWR_HAL_KINETIS_GPIO_PIN_DDR_OUT(A, 11)
>
> //get the input value
> #define GET_KEY1_VALUE CYGHWR_HAL_KINETIS_GPIO_GET_PIN(A, 19)
>
> //set the output high or low
> #define LED1_OUTPUT_H CYGHWR_HAL_KINETIS_GPIO_SET_PIN(A, 11)
> #define LED1_OUTPUT_L CYGHWR_HAL_KINETIS_GPIO_CLEAR_PIN(A, 11)
>
> //gpio test function
> void cyg_user_start(void)
> {
> // KEY1_GPIO_ENABLE;
> // LED1_GPIO_ENABLE;
> // KEY1_INPUT_ENABLE;
> // LED1_OUTPUT_ENABLE;
>
// CYGHWR_HAL_KINETIS_PIN() computes pin setting, but does not set a
PORT register.
// You need to call hal_set_pin_function();

// Example:

hal_set_pin_function(KEY1_GPIO_ENABLE);
// etc...

// HTH
// Ilija

> for(;;)
> {
> if(1==GET_KEY1_VALUE)
> {
> LED1_OUTPUT_H;
> }
> else
> {
> LED1_OUTPU_L;
> }
> }
> }
>

Note: When you post to eCos mailing lists use only plain text. HTML will
be rejected.

I hope this helps
Ilija

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss