[Gambas-user] Declaring external C libraries

Randall Morgan rmorgan62 at ...626...
Wed Aug 1 15:11:58 CEST 2012


On Wed, Aug 1, 2012 at 4:12 AM, wally <wally at ...2037...> wrote:
> On Wednesday 01 August 2012 12:28:12 Christer Johansson wrote:
>> 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
>
> Hi,
>
> your posting is very interesting, thank you
>
> I use GB3 on Opensuse so far and now i'm learning for RaspBerry PI.
>
> 1st step was to make a Virtual machine of debian.
> 2nd is to get Gmabs3 working on it ...
> but this failed.
>
> Your information sounds as you successfully run ganbas3 on debian.
> How did you install Gambas3 ?
>
>> BTW: Let me know if anyone wants the shared library file and I will
>> upload it somewhere, it's compiled in Debain Squeeze.
>
> Yes, i will interested soon i think.
>
> wally
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user

uint8_t is a type as specified by the _t in the naming. u = unsigned
and int = integer 8 = eight bits. So this declares an unsigned integer
of 8 bits.

Hope this helps.

-- 
If you ask me if it can be done. The answer is YES, it can always be
done. The correct questions however are... What will it cost, and how
long will it take?




More information about the User mailing list