src/pi_lw_gpio.c
static int config_gpio(void) {
    int pi_version;

    int bcm_peri_base_phys_addr;
    int gpio_base_phys_addr;

    // Get PI version by parsing /proc/cpu_info:
    pi_version = get_pi_version__();

    // Set BCM base addresses according to the found PI version:
    if ((pi_version == 0) || (pi_version == 1)) {
        // Set BCM base addresses:
        bcm_peri_base_phys_addr = BCM2835_PERI_BASE_PHYS_ADDR;
    } else if ((pi_version == 2) || (pi_version == 3)) {
        // Set BCM base addresses:
        bcm_peri_base_phys_addr = BCM2837_PERI_BASE_PHYS_ADDR;
    } else if (pi_version == 4) {
        // Set BCM base addresses:
        bcm_peri_base_phys_addr = BCM2711_PERI_BASE_PHYS_ADDR;
    } else {
        return -ENOPIVER;
    }

    // Add GPIO peripheral offset to find base physical address:
    gpio_base_phys_addr = (bcm_peri_base_phys_addr + 0x200000);

    // Map physical address into virtual address space to manipulate registers:
    gpio_base_virt_addr = map_peripheral__(gpio_base_phys_addr);

    if ((void *) gpio_base_phys_addr == MAP_FAILED) {
        return (int) gpio_base_virt_addr;
    }

    // Set flag so only one mapping is done:
    config_gpio_flag = 1;

    return 0;
}
// Configure for GPIO by mapping peripheral into virtual address space
Configure for GPIO by mapping peripheral into virtual address space
Configure for GPIO by mapping peripheral into virtual address space
static int config_gpio(void) {
    int pi_version;
    int bcm_peri_base_phys_addr;
    int gpio_base_phys_addr;
    pi_version = get_pi_version__();
    if ((pi_version == 0) || (pi_version == 1)) {
        bcm_peri_base_phys_addr = BCM2835_PERI_BASE_PHYS_ADDR;
    } else if ((pi_version == 2) || (pi_version == 3)) {
        bcm_peri_base_phys_addr = BCM2837_PERI_BASE_PHYS_ADDR;
    } else if (pi_version == 4) {
        bcm_peri_base_phys_addr = BCM2711_PERI_BASE_PHYS_ADDR;
    } else {
        return -ENOPIVER;
    }
    gpio_base_phys_addr = (bcm_peri_base_phys_addr + 0x200000);
    gpio_base_virt_addr = map_peripheral__(gpio_base_phys_addr);
    if ((void *) gpio_base_phys_addr == MAP_FAILED) {
        return (int) gpio_base_virt_addr;
    }
    config_gpio_flag = 1;
    return 0;
}
static int config_gpio ( void ) { int pi_version ; int bcm_peri_base_phys_addr ; int gpio_base_phys_addr ; pi_version = get_pi_version__ ( ) ; if ( ( pi_version == 0 ) || ( pi_version == 1 ) ) { bcm_peri_base_phys_addr = BCM2835_PERI_BASE_PHYS_ADDR ; } else if ( ( pi_version == 2 ) || ( pi_version == 3 ) ) { bcm_peri_base_phys_addr = BCM2837_PERI_BASE_PHYS_ADDR ; } else if ( pi_version == 4 ) { bcm_peri_base_phys_addr = BCM2711_PERI_BASE_PHYS_ADDR ; } else { return - ENOPIVER ; } gpio_base_phys_addr = ( bcm_peri_base_phys_addr + 0x200000 ) ; gpio_base_virt_addr = map_peripheral__ ( gpio_base_phys_addr ) ; if ( ( void * ) gpio_base_phys_addr == MAP_FAILED ) { return ( int ) gpio_base_virt_addr ; } config_gpio_flag = 1 ; return 0 ; }
Configure for GPIO by mapping peripheral into virtual address space
Configure for GPIO by mapping peripheral into virtual address space
// Get PI version by parsing /proc/cpu_info: // Set BCM base addresses according to the found PI version: // Set BCM base addresses: // Set BCM base addresses: // Set BCM base addresses: // Add GPIO peripheral offset to find base physical address: // Map physical address into virtual address space to manipulate registers: // Set flag so only one mapping is done: