Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

1.Pin define

SP7021's GPIO pins have two kinds name system, one is GPIO_Pm_n which m is 0~8 and n is 0~7, another is G_MX[z] which z is 0~71. G_MX means general mux pin which can be program to other functions.
For example, SP7021 pin21 which pin name is GPIO_P2_6, the general mux pin name is G_MX[22]. The relationship between pin name and general mux pin name is 2*8+6=22 in this case and so on.
Figure1 show portion of F2S board SP7021 GPIO pin define. Figure2 show F2S board Rpi like 40 pins GPIO port. So F2S board can collect the same functions as Rpi 40 pins output port with appropriate source code setting.

Figure1 F2S board SP7021 GPIO pin define

Figure2 F2S board Rpi like 40 pins GPIO port

2.GPIO control example by C code

Set pins of Rpi like port number 18 and 22 (SP7021 pin mux number is G_MX[22] and G_MX[24]) as output. In this example, both LEDs will be on for 3 seconds at the beginning and then turn on for 1 second rotary.

...


    printf("GPIO test main start \n");
    pinnum1 = 22; //mean GPIO_P2_6=MX[22]
    pinnum2 = 24; //mean GPIO_P3_0=MX[24]
    gpio_init(pinnum1);
    gpio_init(pinnum2);
    gpio_dir_set(pinnum1,PIN_DIR_O);
    gpio_dir_set(pinnum2,PIN_DIR_O);
    gpio_write(pinnum1,1);
    gpio_write(pinnum2,0);
    usleep(3000*1000);
    while(1)
    {
        gpio_write(pinnum1,1);
        gpio_write(pinnum2,0);
        usleep(1000*1000);
        gpio_write(pinnum1,0);
        gpio_write(pinnum2,1);
        usleep(1000*1000);
    }
}


3.Makefile


/******************************/

...

 
CC = $(CROSS_COMPILE)gcc
CFLAGS= -O2 -Wall -D_GNU_SOURCE -static -march=armv7-a
LDFLAGS= -static
SOURCES= main.c gpio.c
OBJECTS= ${SOURCES:.c=.o}

OUT = gpiotest
all: $(OUT)
@echo Build DONE.
$(OUT): $(OBJECTS)
$(CC) $(LDFLAGS) -o $(OUT) $(OBJECTS) $(LIBS)
clean:
rm -f $(OBJECTS) $(OUT) 



Anchor
_GoBack
_GoBack

4.執行=>$ sudo ./gpiotest