fomu-flash icon indicating copy to clipboard operation
fomu-flash copied to clipboard

port to bcm2835

Open hstarmans opened this issue 2 years ago • 7 comments

New pull request in single commit

  • moved to Broadcom BCM 2835, it does not require admin privelige for pin acces
  • removed all functions which were not used from rpi.c, rpi.h , these files are changed by maybe 90 percent.
  • I use the same GPIO pins as you do, so it should work out of the box.

The only thing that breaks is the function gpiohardware revision. You use it to get the correct pins for different versions of the raspberry. In BCM2835 you simply need to give the right pin as defined in enum RPiGPIOPin

With regards to your questions; Additionally, do you have any information on how to use the library? For example, what is needed to run it on something like Fedberry? Are there packages to install?

This is how it is installed. I have only tested on Raspbian and Ubuntu, not fedberry.

# download the latest version of the library, say bcm2835-1.xx.tar.gz, then:
tar zxvf bcm2835-1.xx.tar.gz
cd bcm2835-1.xx
./configure
make
sudo make check
sudo make install

This is how you use it to blink a LED, see also webpage with extensive docs.

// blink.c
//
// Example program for bcm2835 library
// Blinks a pin on an off every 0.5 secs
//
// After installing bcm2835, you can build this 
// with something like:
// gcc -o blink blink.c -l bcm2835
// sudo ./blink
//
// Or you can test it before installing with:
// gcc -o blink -I ../../src ../../src/bcm2835.c blink.c
// sudo ./blink
//
// Author: Mike McCauley
// Copyright (C) 2011 Mike McCauley
// $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $
 
#include <bcm2835.h>
#include <stdio.h>
 
// Blinks on RPi Plug P1 pin 11 (which is GPIO pin 17)
#define PIN RPI_GPIO_P1_11
 
int main(int argc, char **argv)
{
    // If you call this, it will not actually access the GPIO
    // Use for testing
//    bcm2835_set_debug(1);
 
    if (!bcm2835_init())
      return 1;
 
    // Set the pin to be an output
    bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);
 
    // Blink
    while (1)
    {
        // Turn it on
        bcm2835_gpio_write(PIN, HIGH);
        
        // wait a bit
        bcm2835_delay(500);
        
        // turn it off
        bcm2835_gpio_write(PIN, LOW);
        
        // wait a bit
        bcm2835_delay(500);
    }
    bcm2835_close();
    return 0;
}

As a final note, I use a custom FPGA board to control a laser scanner, see Hackaday

hstarmans avatar Oct 29 '21 08:10 hstarmans