[Gambas-user] Declaring external C libraries

Christer Johansson lists at ...2828...
Wed Aug 1 12:28:12 CEST 2012


With some luck and Google I managed to compile a shared version of the
C library to RaspberryPi I/O by Mike McCauley and it seems to work
(at least partly) within Gambas3 using the EXTERN function.

I started with the simplest function there was in the library and that
was pretty strait forward and it works fine in Gambas3 using the
code below...

  ' Declare external function
  Public Extern delay(millis As Integer) In "libbcm2835"

  ' Delay 2 sec
  delay(2000)

Next up was to declare an actual I/O function to toggle I/O pins
and looks like this in the C code (bcm2835.c from the library at
http://www.open.com.au/mikem/bcm2835/index.html)...

  ...
  // Set putput pin
  void bcm2835_gpio_set(uint8_t pin)
  {
      volatile uint32_t* paddr = gpio + BCM2835_GPSET0/4 + pin/32;
      uint8_t shift = pin % 32;
      bcm2835_peri_write(paddr, 1 << shift);
  }
  ...

Since my C knowledge is very limited I wonder what to declare "uint8_t"
as? According to Google it seems to be the same as unsigned char so I
tried to use Byte in the declaration but no go, I get segmentation
fault when calling that function.

  Public Extern bcm2835_gpio_set(pin As Byte) In "libbcm2835"

Anyone have any ideas what I am doing wrong?

BTW: Let me know if anyone wants the shared library file and I will
upload it somewhere, it's compiled in Debain Squeeze.

/CJ





More information about the User mailing list