A33's GPIO operation

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/YYGY731793898/article/details/79358551

                                    A33's GPIO operation

1. First, set the corresponding GPIO sys_config.fex in the configuration file. And then re-packaged mirror.

[Gpio_para]

gpio_used         =1

gpio_pin_1        =port:PH07<1><default><default><0>

;gpio_pin_2       =port:PH09<0><default><default><default>

gpio_pin_2        =port:PH04<1><default><default><1> ;work led

gpio_pin_3        =port:PH05<1><default><default><1> ;485 en

Brackets content: output function is assigned to an input 0 Reference

      Internal resistance state 0 by default: disabled 1: 2 pull: pull-down

      01 default drive capability, 2, 3, four

      Output level state only 0 and 1, take effect only when the PIN configured to output.

2. Test procedures bsp_led.c

#define LED_MODULE 

#include"bsp_led.h"


#include <string.h>

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include<pthread.h> 


static unsigned char ledrun; 

#define LED_FILEPATH   "/sys/class/gpio_sw/PH4/data"        //LED

int Bsp_Led_UpData(unsigned charpin_value)

{

      FILE*fp;

      if((fp= fopen(LED_FILEPATH, "rb+")) == NULL)

      {

           printf("Cannotopen value file!\n");

           exit(1);

      }

      if(pin_value== 0)

           fprintf(fp, "0");

      else

           fprintf(fp, "1");

 

      fclose(fp);

      return0;

}

 

 

void *Led_pthread(void *arg)

{

     while(ledrun)

      {

           usleep(500000);

            Bsp_Led_UpData(0);     

            usleep(500000);

            Bsp_Led_UpData(1);

      }

      returnNULL;

}

 

int Led_thread_create(void)

{

      ledrun= TRUE;

      returnpthread_create(&pth_led, NULL, Led_pthread, NULL);

}

 

int Led_thread_destroy(void)

{

      ledrun = FALSE;

      pthread_join(pth_led,NULL);

      return0;

}

 

 

3.   Bsp_led.h

#ifndef __BSP_LED_H__

#define __BSP_LED_H__

 

#ifndef LED_MODULE

#define LED_EXT       extern

#else

#define LED_EXT

#endif//LED_MODULE

 

LED_EXT int Led_thread_create(void);

LED_EXT int Led_thread_destroy(void);

#endif//__BSP_LED_H__

4.    main.c

#include"bsp_led.h"

int main(int argc, char **argv)

{

      Led_thread_create();

    while(1)

    { 

    }

      Led_thread_destroy();

    return 0;

}

5. Test, a breathing A33 become light.

Guess you like

Origin blog.csdn.net/YYGY731793898/article/details/79358551