Recent

Author Topic: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library  (Read 88531 times)

sfischer

  • New Member
  • *
  • Posts: 37
Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« on: May 25, 2013, 05:48:17 pm »
Hi,

below you can find the source code of unit rpi_hal on my web shop. You can use the code without the piggy back board, so there is no need to buy the board, but I whould apreciate it.

The rpi_hal unit delivers functions and procedures to access rpi's HW: SPI, I2C and GPIO. Hope you can use it in your rpi projects. Have a lot of fun and pls. discuss code enhancements and report bugs here in this forum.

http://shop.basis.biz/shop/Raspberry-PI/piggy-back-board/

Thanks,
Stefan

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #1 on: May 26, 2013, 09:39:43 am »
That is intereseting, but where is the link to your source code?
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

pridi

  • Newbie
  • Posts: 1
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #2 on: May 26, 2013, 09:49:01 pm »
Hi!! I'm very interested in your unit....may I have the link???

Thank you!!

sfischer

  • New Member
  • *
  • Posts: 37
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #3 on: May 27, 2013, 09:51:36 am »
The SW can be found here:
http://shop.basis.biz/shop/Raspberry-PI/piggy-back-board/
under the point SW: SW e.g. rpi_hal:

sfischer

  • New Member
  • *
  • Posts: 37
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #4 on: July 26, 2013, 06:08:35 pm »
Hi,

new version of rpi_hal is available. Now it supports the PiFace Board.

Stefan

angel

  • Newbie
  • Posts: 1
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #5 on: July 30, 2013, 06:15:52 pm »
This is very interesting.
My only problem is: I'm an electronics technician, and I have limited programming knowledge.
Is there any tutorial on how to use the HAL? I can follow part of the code...
What I would like is how to do a simple data := read(address, register) and write(address, register, data) just byte by byte.
And if I need to open/close the I2C bus...
« Last Edit: July 30, 2013, 09:40:22 pm by angel »

sfischer

  • New Member
  • *
  • Posts: 37
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #6 on: July 31, 2013, 01:44:46 pm »
I have added an i2test routine in rpi_hal to show you the usage of the i2c routines.
pls. download newest rpi_hal (Version 1.3). the i2c_test reads and writes to an rtc 3232m clock
chip. If you have a different chip hooked up to the i2c bus, then the code give you just an idea how to use them:

i2c_string_write($68,$05,#$08+#$12,NO_TEST); // write 08 in reg 0x05 and 12 in reg 0x06
s:=i2c_string_read($68,$05,2,NO_TEST); showstr(s); // read 2 bytes. startreg is 0x05


program i2ctest;
uses rpi_hal;  { minimum version V1.3 required }
begin
  writeln('program start');
  i2c_test;
  writeln('program end');
end.

hallenberger

  • New Member
  • *
  • Posts: 43
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #7 on: July 31, 2013, 02:27:23 pm »
Hello!

I can't compile the unit, because of a variable name named "result".

How do you compile it?
Debian/Sparky Linux
OS: Windows XP
Lazarus: with fpcupdeluxe

sfischer

  • New Member
  • *
  • Posts: 37
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #8 on: July 31, 2013, 02:30:05 pm »
just install lazarus on rpi:

root@rpi> apt-get install lazarus

copy rpi_hal.pas and i2ctest.pas in a directory and compile it.

root@rpi>  fpc i2ctest

 

sfischer

  • New Member
  • *
  • Posts: 37
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #9 on: July 31, 2013, 02:34:01 pm »
in which line do you get the error with 'result'

can you paste the compiler messages pls.

hallenberger

  • New Member
  • *
  • Posts: 43
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #10 on: July 31, 2013, 02:46:31 pm »
Hi!

For example here:

function  BitSlice32(data:longword; bitstartpos,slicelgt:byte) : longword; 
{.c returns Bit slice area (Bit Nr. from  1 to 32)
i.e. data(bin) = 00101100; startpos=6; slicelgt=4; result:= 00001011 }
var result,msk : longword; i:longint;
begin
  result := 0; msk:=0;
  for i:= bitstartpos downto (bitstartpos-slicelgt+1) do msk := msk or Bit_Set_OR_Mask32(i);
  result:= data and msk;
  result:=result shr (bitstartpos-slicelgt);
  BitSlice32 := result;
end;

Tho compiler message is:

rpi_hal.pas(565,5) Error: Duplicate identifier "RESULT"


And here:

function  rpi_mmap_reg_write(adr,value: longword) : longword;
var result:longword;
begin

rpi_hal.pas(629,5) Error: Duplicate identifier "RESULT"
Debian/Sparky Linux
OS: Windows XP
Lazarus: with fpcupdeluxe

sfischer

  • New Member
  • *
  • Posts: 37
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #11 on: July 31, 2013, 03:10:28 pm »
pls. add {$MODE FPC} in the first line of rpi_hal.pas

or compile it as follows:

fpc -MFPC rpi_hal
 

hallenberger

  • New Member
  • *
  • Posts: 43
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #12 on: July 31, 2013, 05:05:49 pm »
Thank you!

Now it compiles.

But another question:
If I make a new project (only one form) an add rpi_hal.pas in the uses clause, compile and run the project I get an exception (SIGSEGV) when I close the program.
Without rpi_hal in the uses the program works.

What am I doin wrong?
Debian/Sparky Linux
OS: Windows XP
Lazarus: with fpcupdeluxe

sfischer

  • New Member
  • *
  • Posts: 37
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #13 on: August 01, 2013, 01:08:57 pm »
Hi,

i'm not using Lazarus itself, only fpc on commanline.
just compile your program, which is using rpi_hal with uses clause, with fpc.

What OS are you using ?
I've tested rpi_hal V1.3 only on wheezy:
Linux rpi 3.6.11+ #474 PREEMPT Thu Jun 13 17:14:42 BST 2013 armv6l GNU/Linux

bartdereu

  • New Member
  • *
  • Posts: 17
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #14 on: August 10, 2013, 09:22:13 pm »
Hi,

i tried to use this library in Lazarus, but i can't get it compiled without errors (211)
Anyone has a piece of code that works with this in Lazarus,

btw, GREAT work !

 

TinyPortal © 2005-2018