Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

port to bcm2835 #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

port to bcm2835 #13

wants to merge 1 commit into from

Conversation

hstarmans
Copy link

@hstarmans hstarmans commented Oct 29, 2021

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

@xobs
Copy link
Member

xobs commented Oct 29, 2021

Thanks for recreating the pull request.

I notice that libbcm2835 is licensed under GPL3, which would require that I relicense this project under GPL3. I prefer to keep it under a BSD-like license.

@hstarmans
Copy link
Author

hstarmans commented Oct 29, 2021

I don't see a conflict... you just use it as a library... You should be able to maintain free-bsd licence.
You now actually just maintain your own free-bsd version of it, which is inefficient.
Getting up to the same level as BCM2835 requires you to put in quite some hours.
More lines is typically also more maintenance.
It is a big change, however.
You could keep it around as branch.
The main issue with your code is that it needs sudo priviliges and it breaks stuff (spi interface, reloading modules).
Sudo is a no-go from a security point of view.
Still, choice is up to you! Thanks for the library.

@xobs
Copy link
Member

xobs commented Oct 29, 2021

I'm still trying to understand GPLv3, but according to https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3) it says that All code linked with GPL 3.0 source code must be disclosed under a GPL 3.0 compatible license. This is similar to https://opensource.stackexchange.com/questions/1640/if-im-using-a-gpl-3-library-in-my-project-can-i-license-my-project-under-mit-l

https://softwarefreedom.org/resources/2007/gpl-non-gpl-collaboration.html says that I can distribute parts of it under BSD, but the project as a whole needs to be GPLv3.

We can work around the sudo requirement by checking for /dev/gpiomem, which is traditionally available to other users, and using that if it exists.

@hstarmans
Copy link
Author

hstarmans commented Oct 29, 2021

You are right... it seems that at rest it can be MIT but not once you link. This would require you to get a commercial license from airy space.
I am fine as is and need my time for other work. Still, I see you cannot accept the current license.
Feel free to close.

@mithro
Copy link
Member

mithro commented Oct 29, 2021

I am not a lawyer and you should get legal advice about legal questions. My understanding is the following.

You can keep fomu-flash under MIT license as it is GPLv3 compatible. When you distribute a combined work that result needs to comply with the GPLv3 terms.

To explicitly state things;

  • When you distribute fomu-flash with the BCM2835 library (such as binary releases or embedded in firmware image) that combined work is under the GPLv3 and thus must comply with the license by providing the source code and similar.

  • If usage of BCM2835 library is optional and you distribute fomu-flash which does not use the library - then you would have no obligations related to the GPL.

  • If there was a API compatible replacement for the BCM2835 library under the Apache 2.0 license, the result of fomu-flash when distributed with that library (rather than the GPL library) would have no GPL obligations too.

@xobs
Copy link
Member

xobs commented Oct 29, 2021

That's my understanding of GPLv2, but for GPLv3 it seems like the entire work must be GPLv3. Specifically:

5. Conveying Modified Source Versions.

You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:

c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.

It's all very fiddly and ambiguous, though...

@mithro
Copy link
Member

mithro commented Oct 29, 2021

@xobs - What that is saying is when you distribute a work (IE fomu-flash linking against BCM2835 library) then you are required to provide anyone with a copy of the complete fomu-flash + BCM2835 source code under the GPLv3 license.

That doesn't prevent you from provide fomu-flash to the receiver under the less restrictive terms of MIT at the same time.

See the last key bit;

This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants