⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpiotest.c

📁 test GPIO program code
💻 C
字号:
#include <stdio.h>
#include "fLib.h"
#include "GPIO.H"
#include "FIE702x.h"

#define GPIO_LED_NUM		16
#define GPIO_LED_BASE		16

extern unsigned int PMU_get_hclk(void);
extern void API_SYS_set_MUX_GPIOA(void);
extern unsigned int DebugSerialPort;

extern UINT32 Esc_Key;
extern char fLib_getch(unsigned int);
#define BASE_NUM        7
#define NUM_GPIO		(BASE_NUM + 8)
#define MASK_GPIO_NUM	((1 << NUM_GPIO) - 1)

volatile int ESC_check;

#ifndef FIE702X_ROCKCHIP_DEMO_KIT

void GPIOtest(UINT32 The_Times)
{
	unsigned int i, j, k;
	unsigned int trigger, active;
	unsigned int hclk_count = PMU_get_hclk();
	
	printf("\r\nBegin GPIO Test\r\n");

	API_SYS_set_MUX_GPIOA();
	
    //set input
    for (i = 0; i < NUM_GPIO; i ++)
    	fLib_SetGpioDir(FIE702x_GPIOA_BASE,i, GPIO_INPUT);

	printf("Select trigger mode (0)Edge, (1)Level:\r\n");	
		
	scanf("%d", &trigger);
	
	if (trigger)
		printf("Select level mode (0)High level, (1)Low level:\r\n");
	else
		printf("Select trigger mode (0)Rising edge, (1)Falling edge:\r\n");

	scanf("%d", &active);
	
	//all irq enable
	for (i = 0; i < NUM_GPIO; i ++)
		fLib_EnableGpioInt(FIE702x_GPIOA_BASE,i, trigger, active);
	

                
    //polling
    printf("Press GPIO Key,ESC to escape\r\n");
    
    ESC_check = 0;
    Esc_Key = 0;
    
    while (Esc_Key == 0)
    {
        if (ESC_check & 0x100)
        {
            char chr;
            chr = fLib_getch(DebugSerialPort);
            
            if (chr == 0x1b)
                Esc_Key=1;
        }        
        ESC_check ++;
        
        j = ~fLib_Gpio_ReadData(FIE702x_GPIOA_BASE);
        j = j & MASK_GPIO_NUM;
        
        if (j)
        {
            for (k = BASE_NUM; k < NUM_GPIO+1; k ++)
            {
                if ((j >> k) & 0x1)
                {
                    printf("GPIO pin %d pressed\r\n",k);
                                        
                    //check irq
                    {
                        unsigned int d = hclk_count/(20*10);
                        while(d--)
                            ;
                    }
                   
                    if(fLib_Gpio_IsRawInt(FIE702x_GPIOA_BASE,k))
                        printf("IRQ pin %d detected\r\n",k);
                        
                    {
                        unsigned int d = hclk_count/(20*50);
                        while(d--)
                            ;
                    }   
                   
                    break;
                }
            }    
            
            //clear all irq            
            for (i = 0; i < NUM_GPIO; i ++)
            	fLib_ClearGpioInt(FIE702x_GPIOA_BASE,i);
        }
    }		
}

#else
void GPIOtest(UINT32 The_Times)
{
	unsigned int i, j, k;
	unsigned int trigger, active;
	unsigned int hclk_count = PMU_get_hclk();
	
	printf("\r\nBegin GPIOC Test\r\n");
	
    //set input
    for (i = 0; i < NUM_GPIO; i ++)
    	fLib_SetGpioDir(FIE702x_GPIOC_BASE,i, GPIO_INPUT);

	printf("Select trigger mode (0)Edge, (1)Level:\r\n");	
		
	scanf("%d", &trigger);
	
	if (trigger)
		printf("Select level mode (0)High level, (1)Low level:\r\n");
	else
		printf("Select trigger mode (0)Rising edge, (1)Falling edge:\r\n");

	scanf("%d", &active);
	
	//all irq enable
	for (i = 0; i < NUM_GPIO; i ++)
		fLib_EnableGpioInt(FIE702x_GPIOC_BASE,i, trigger, active);
	

                
    //polling
    printf("Press GPIO Key,ESC to escape\r\n");
    
    ESC_check = 0;
    Esc_Key = 0;
    
    while (Esc_Key == 0)
    {
        if (ESC_check & 0x100)
        {
            char chr;
            chr = fLib_getch(DebugSerialPort);
            
            if (chr == 0x1b)
                Esc_Key=1;
        }        
        ESC_check ++;
        
        j = ~fLib_Gpio_ReadData(FIE702x_GPIOC_BASE);
        j = j & MASK_GPIO_NUM;
        
        if (j)
        {
            for (k = BASE_NUM; k < NUM_GPIO+1; k ++)
            {
                if ((j >> k) & 0x1)
                {
                    printf("GPIO pin %d pressed\r\n",k);
                                        
                    //check irq
                    {
                        unsigned int d = hclk_count/(20*10);
                        while(d--)
                            ;
                    }
                   
                    if(fLib_Gpio_IsRawInt(FIE702x_GPIOC_BASE,k))
                        printf("IRQ pin %d detected\r\n",k);
                        
                    {
                        unsigned int d = hclk_count/(20*50);
                        while(d--)
                            ;
                    }   
                   
                    break;
                }
            }    
            
            //clear all irq            
            for (i = 0; i < NUM_GPIO; i ++)
            	fLib_ClearGpioInt(FIE702x_GPIOC_BASE,i);
        }
    }		
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -