Recent

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

alex1991

  • Newbie
  • Posts: 5
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #45 on: February 12, 2016, 12:31:42 pm »
The data stream consists of one leading zero followed by three STATUS bits, followed by the 12 bits of conversion data.

https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
SUPPORTED BITS PER WORD
8 - Normal
9 - This is supported using LoSSI mode.

Can I obtain 12 bits data from ADC, if 8-9 bits per word supported?
And output data type - word(2 byte-(0..65535))?



Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #46 on: February 12, 2016, 01:47:18 pm »
The data stream consists of one leading zero followed by three STATUS bits, followed by the 12 bits of conversion data.

https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
SUPPORTED BITS PER WORD
8 - Normal
9 - This is supported using LoSSI mode.

Can I obtain 12 bits data from ADC, if 8-9 bits per word supported?
And output data type - word(2 byte-(0..65535))?

Mask.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

alex1991

  • Newbie
  • Posts: 5
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #47 on: February 12, 2016, 02:49:08 pm »
The data stream consists of one leading zero followed by three STATUS bits, followed by the 12 bits of conversion data.

https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
SUPPORTED BITS PER WORD
8 - Normal
9 - This is supported using LoSSI mode.

Can I obtain 12 bits data from ADC, if 8-9 bits per word supported?
And output data type - word(2 byte-(0..65535))?

Mask.

Can you show an example of using this function (SPI BUS)?

Activate SPI channel, obtaining first measurement, next measurement, ...... , last measurement, Close SPI Channel.
What type of data (byte/integer/string/other)?

How to change / specify the frequency SCLK?

Can you write example code for newbie?

Koenraad

  • Newbie
  • Posts: 3
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #48 on: March 09, 2016, 02:29:49 pm »
Hi,
I'm trying to use rpi_hal in a lazarus-project.
I'm experiencing strange things.
It's on a Pi2, with lazarus 1.6rc1. Enclosed the used project.
It's very basic, rpi_hal is not really used, but included in the "uses". It runs OK, but when I terminate it (close button), I get a number of errors (when run from the command-line). When you comment out the rpi_hal from the uses, the application runs fine.
What's happening ?

A second strange thing : add a togglebutton, or a checkbox and the application crashes when it starts.
Any help ?
Is there a lazarus-demo project ?
The fpc-demo works fine.
« Last Edit: March 09, 2016, 02:31:57 pm by Koenraad »

Koenraad

  • Newbie
  • Posts: 3
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #49 on: March 10, 2016, 11:42:00 am »
Is anyone really using rpi_hal ? With lazarus ?
I was trying to debug the problems I have and enabled debug-mode of the compiler. Then the program crashes right from the start with range-check errors. Looking into this I found some strange bugs : a number of arrays used out of bounds.
I'm really puzzled !

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1739
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #50 on: March 10, 2016, 01:09:59 pm »
I would definitely suggest to use the Aspire library !

http://forum.lazarus.freepascal.org/index.php/topic,29852.0.html

https://sourceforge.net/projects/asphyre/

It is very well written, and in use by me with great success !

mig-31

  • Sr. Member
  • ****
  • Posts: 305
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #51 on: March 10, 2016, 02:54:29 pm »
I use low-level native Freepascal code to program ARM Linux development boards.
Lazarus 2.2.6 - OpenSuse Leap 15.4, Mageia 8, CentOS 7

Koenraad

  • Newbie
  • Posts: 3
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #52 on: March 10, 2016, 03:31:32 pm »
@DonAlfredo
I hesitated because of the size of the library. Now I tried : problems !
I compiled Blinky, and I have to be root to run it. I hate running applications as root.
Then I enabled the define for RPi2. There I got errors : some assembler instructions are unknown by fpc 3.0. so disabled those instructions (enabled the rpi1 ones by modifying the "ifdef"). Still only works as root.
I also modified /dev/mem in /dev/gpiomem, but still I can't run as normal user but now the application hangs. I need to "kill" it. Running as root behaves the same.

@mig-31
What is "low-level native Freepascal" ?

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1739
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #53 on: March 10, 2016, 04:27:04 pm »
Well, you need an FPC that is compiled for ARMV7A to get this library running for RPi2, which has an ARMV7 cpu !
Only then, the dmb assembler instruction is accepted.

(you can add: {$ifdef CPUARM_HAS_DMB})

I do not think that your program has to run as root.
Perhaps you have to allow access to your hardware for non-root ?

When accessing USB (on RPi), I always have to add an udev-rule to get access for non-root !!


sfischer

  • New Member
  • *
  • Posts: 37
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #54 on: August 04, 2016, 06:34:23 pm »
Hi,
just uploaded new version of rpi-hal V4.2 to github: https://github.com/rudiratlos/rpi-hal
I have corrected several bugs and enhanced the library with new features, like reading config files...
I've testet rpi-hal in a pure free pascal environment (fpc 2.6.4).
Would be nice to get information from users, which want to use rpi-hal in lazarus environment.
 

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #55 on: August 04, 2016, 07:25:38 pm »
Will try it out this weekend. report back.
Good work!

And yes people are using it! I just didn't use it yet on RPi3, but now i have a setup that chains all the old ones into one "Powerful" RPi network computing system with some Arduino's on all of them (and some proprietary sh*t that I will share if it does what I mean.)
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

nicolap

  • Newbie
  • Posts: 4
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #56 on: August 11, 2016, 04:08:28 pm »
@sfischer
I thought a lot before posting this. Please note that my english is very bad so I'm sinthetic, not rude at all.
I think that you have done a big job, really.
But your code is a collection of "bad practices".
I will try to explain some, because I would try to help you to develop better.

All code snippets come from version 4.2.

Code: Pascal  [Select][+][-]
  1. function  I2C_word_write(baseadr,basereg:word; data:word; flip:boolean; errhdl:integer):integer;
  2. begin I2C_word_write:=I2C_word_write(RPI_I2C_busgen,baseadr,basereg,data,flip,errhdl); end;
This code is difficult to read: after punctuation (comma, semicolon, etc) put a space!
And let the begin and end alone in a line.
The "Overload" modifier is not required but I think that is a very good habit to use it http://www.freepascal.org/docs-html/ref/refsu80.html

Code: Pascal  [Select][+][-]
  1. procedure SPI_show_buffer(busnum,devnum:byte);
  2. const errlvl=LOG_WARNING; maxshowbuf=35;
  3. var i,eidx:longint; sh:string;
  4. begin
  5.  
Ouch! It's ugly, compare to this:
Code: Pascal  [Select][+][-]
  1. procedure SPI_show_buffer(busnum, devnum:byte);
  2. const
  3.   errlvl = LOG_WARNING;
  4.   maxshowbuf = 35;
  5.  
  6. var
  7.   i, eidx : longint;
  8.   sh : string;
  9.  
  10. begin
  11.  
The readability is much improved, for other people but also for you when will read the code after some time.
Learn to use "Const parameters" http://www.freepascal.org/docs-html/ref/refsu68.html

Don't mix "library code" with "test code": the GPIO_int_test or I2C_test functions MUST be in a separate file.

Learn to use objects: it's a different world :-) (after the first headache)

Code: Pascal  [Select][+][-]
  1.   with spi_buf[busnum,devnum] do
If the parameters are outside the range (that you know but the compiler no) you will have a runtime error at best. Or, if you shut off the range check errors, a "strange" behaviour.
Use Enumerations!

Last, for now: the unit initialization code decides which peripherals to initialize and which is the default log level. But these decisions are duty of the user/programmer not yours. Better if you have an RPI_hal_Initialize(...) function that do these things and return an error code (it's not your decision when to halt the program and with which error code).

Remember an important thing (that a C programmer ignores  >:D ): a programming language is a COMMON language between YOU and your computer so it must be (easily) readable from BOTH.
     NicolaP

nicolap

  • Newbie
  • Posts: 4
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #57 on: August 11, 2016, 04:10:09 pm »
Small modify required in procedure Get_CPU_INFO_Init
You must add a case for value $222082
This is returned by RPi 3B produced in China http://www.raspberrypi-spy.co.uk/2012/09/checking-your-raspberry-pi-board-version/
Thanks

sfischer

  • New Member
  • *
  • Posts: 37
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #58 on: September 09, 2016, 02:59:26 pm »
Hi nicolap,
thank you very much for your feedback. I appricate it, because I want to improve rpi_hal. I encourage all of the users to supply constructive feedback for further improvement/enhancements. I will modify the code in the next release, to avoid runtime errors (with spi_buf[busnum,devnum]..) if busnum/devnum are out of range.
I understand your feedback which addresses the readability. In general, you're right that the code could be more prettified. But I've choosen that style for several codesections, where the functionality of the code is obvious (like Num2Str, Str2Num...). E.g. your 1st example (i2c_word_write), this function is an overloaded function and differs only in the parameter line. It's my old way, to organize the code. I seperate code which is 'easy/obvious' to understand with compaction from 'complexer' code, which is more styled in your sense. I'm considering your suggestion, to seperate test-/example-code from the library, to bring down line of code. I already put the code for the pfio card in a seperate unit. But I can not say when/if it will happen. Feedback from other users and their experiance whould be very valuable for me. I really don't know how many people are using rpi_hal and I don't know if it's worth to spend more time, I dont get so much feedback. I'm using rpi_hal in a lot of my free pascal projects with rpi hw and I'm very happy with the stability and huge functionality until know.

best regards,
SF

 

ThomasE

  • Newbie
  • Posts: 2
Re: Lazarus / RaspberyPi rpi_hal Hardware Abstraction Library
« Reply #59 on: November 20, 2016, 10:07:58 am »
First of all: the rpi_hal-unit seems to be an excellent tool !
I am running lazarus (1.2.4) with fpc (2.6.4) on a Raspberry PI B+.

I installed rpi_hal without problem.
Compiling my test program without problem.

Running the program and nothing happens !

My test program starts with the code:

unit unit1;
{$mode objfpc}{$H+}

interface

uses
rpi_hal, Unix...........StdControls;


At the moment I am not using any functions or procedures from the rpi_hal-unit, just to be able to see if the unit is working ok or not.
If I take away rpi_hal under Uses, the program starts.

I really can not figure out where the problem is !

Anyone have a clue ?

 

TinyPortal © 2005-2018