Recent

Author Topic: pi PICO controlling ws2812b leds, ledstrips  (Read 2077 times)

jb007

  • Full Member
  • ***
  • Posts: 129
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #30 on: August 08, 2022, 09:14:10 pm »
success...

I managed to make pio work with fortunately very little extra changes.

please pull

https://github.com/michael-ring/pico-fpcexamples

and enjoy!




Michael


Well done!




 

« Last Edit: August 08, 2022, 09:20:15 pm by jb007 »
to DIY or not to DIY

PascalDragon

  • Hero Member
  • *****
  • Posts: 4515
  • Compiler Developer
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #31 on: August 08, 2022, 10:34:30 pm »
At present that's quite a biggy. My understanding is that the new (~FPC 3.3) attribute specification can be used for target-specific things like specifying linkage sections (as well as its nominal role for decorating types), but I've not seen any suggestion that this can be generalised to do things like invoking pioasm.

FPC 3.2.0 already supports the section NAME directive on embedded targets (e.g. section '.progmem' on AVR).
Also you can use tools like data2inc to convert binary data to include files that are essentially arrays of Byte. You just need to invoke tools that generate the binary data from the PIO assembly source (Lazarus can do this with the before-built step).

MarkMLl

  • Hero Member
  • *****
  • Posts: 5116
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #32 on: August 08, 2022, 10:56:06 pm »
FPC 3.2.0 already supports the section NAME directive on embedded targets (e.g. section '.progmem' on AVR).
Also you can use tools like data2inc to convert binary data to include files that are essentially arrays of Byte. You just need to invoke tools that generate the binary data from the PIO assembly source (Lazarus can do this with the before-built step).

Thanks for that, other people didn't mention it when I raised something related to noinit a few days ago.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 4515
  • Compiler Developer
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #33 on: August 08, 2022, 11:30:27 pm »
FPC 3.2.0 already supports the section NAME directive on embedded targets (e.g. section '.progmem' on AVR).
Also you can use tools like data2inc to convert binary data to include files that are essentially arrays of Byte. You just need to invoke tools that generate the binary data from the PIO assembly source (Lazarus can do this with the before-built step).

Thanks for that, other people didn't mention it when I raised something related to noinit a few days ago.

But ccrause had done so here?

MarkMLl

  • Hero Member
  • *****
  • Posts: 5116
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #34 on: August 09, 2022, 09:11:00 am »
But ccrause had done so here?

Sorry, you're right.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 4515
  • Compiler Developer
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #35 on: August 09, 2022, 01:22:35 pm »

jb007

  • Full Member
  • ***
  • Posts: 129
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #36 on: August 18, 2022, 08:53:33 pm »
Hi,

 gonna redo my ws2812 code.

Didn't know this, to get a bit out of a byte, now I do:

https://www.delphipraxis.net/1134-bits-eines-bytes-auslesen.html
function TestBit(aByte: Byte; aBitNum: Integer): Boolean;
   begin
      Result := (aByte and (1 shl aBitNum)) > 0;
   end;

Before I was only used to use e.g.: bit:= byte.5 to single out bit5.

I realize now that something simulair is used to set an outputPin to One/Zero!
( due of the Michel's examples )

Now, 'calculating the RGB 3-bytes' makes more sense and is easier, like I used to do on AVR/ws2812b.

I wil not to go to deep in details.

Kind regards.














« Last Edit: August 18, 2022, 08:58:24 pm by jb007 »
to DIY or not to DIY

MarkMLl

  • Hero Member
  • *****
  • Posts: 5116
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #37 on: August 18, 2022, 10:40:44 pm »
I would /hope/ that that byte.5 notation, since it's something supported by the compiler, is more efficient.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 4515
  • Compiler Developer
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #38 on: August 19, 2022, 09:02:39 am »
function TestBit(aByte: Byte; aBitNum: Integer): Boolean;
   begin
      Result := (aByte and (1 shl aBitNum)) > 0;
   end;

You should declare that as inline so the compiler can optimize this better (especially important on smaller platforms ;) ).

Before I was only used to use e.g.: bit:= byte.5 to single out bit5.

What do you mean with that?

I realize now that something simulair is used to set an outputPin to One/Zero!
( due of the Michel's examples )

Well, that's normal bit manipulation. Maybe you should read up on that as these are very common operations on microcontrollers.

jb007

  • Full Member
  • ***
  • Posts: 129
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #39 on: August 19, 2022, 08:28:21 pm »
I would /hope/ that that byte.5 notation, since it's something supported by the compiler, is more efficient.

MarkMLl


That was first thing I did, a time ago, but didn't work.

First gonna try that again!
to DIY or not to DIY

jb007

  • Full Member
  • ***
  • Posts: 129
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #40 on: August 20, 2022, 07:10:24 pm »
Same error again as I started on pi-PICO.

'illigal qualifier indentifier expected but ordinal const found'

initial I started with:


procedure bitByteStuff;   
var
   bBit: boolean;
   byByte: byte:
begin
   bByte:= 127;
   bBit:= byByte.4;  // illigal qualifier indentifier expected but ordinal const found

end; // p\


it's the .4 what Lazarus doens't want!
At least in my IDE.



Then I played/messed around, with types, but that diddn't change the .4 error:


procedure bitByteStuff;   // how to get a bit out of a byte
var                               // regualr pascal bit4:= byte.4
  byByte: byte;
  iByte : integer;

   bBit: boolean;
  byBit: byte;
   iBit: integer;

  byNumber: byte;
   iNumber: integer;


begin
  byByte:= 127;
  iByte := 127;

  byNumber:= 4;
   iNumber:= 4;

  //bBit := byByte.4;  // illigal qualifier indentifier expected but ordinal const found
  //byBit:= byByte.4; // illigal qualifier indentifier expected but ordinal const found
  //iBit := byByte.4;  // illigal qualifier indentifier expected but ordinal const found

  //bBit := iByte.4;    //illigal qualifier indentifier expected but ordinal const found
  //byBit:= iByte.4;   // illigal qualifier indentifier expected but ordinal const found
  //iBit := iByte.4;    // illigal qualifier indentifier expected but ordinal const found


// I know some of above don't make sense, with or without the error, but ok.


end; // p\bitByteStuff   



procedure from mikroPascal. ws2812b on AVR2560. working code on ATMEGA2560:
 
  procedure tstBitByte;
  var
    byOneByte: byte;
    bOneBit: boolean;
    iOneBit: integer;
  begin
    byOneByte:= 255;
    bOneBit:= byOneByte.4;
    iOneBit:= byOneByte.4;

  end; // p\



Kind regards!






« Last Edit: August 20, 2022, 07:12:11 pm by jb007 »
to DIY or not to DIY

PascalDragon

  • Hero Member
  • *****
  • Posts: 4515
  • Compiler Developer
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #41 on: August 20, 2022, 08:36:44 pm »
procedure from mikroPascal. ws2812b on AVR2560. working code on ATMEGA2560:

That would explain this then. This kind of syntax is simply not supported in Free Pascal.

But you can simulate something similar using type helpers:

Code: Pascal  [Select][+][-]
  1. program ttypehlp;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$modeswitch typehelpers}
  5.  
  6. uses
  7.   SysUtils;
  8.  
  9. type
  10.   TByteHelper = type helper for Byte
  11.   public type
  12.     TBitRange = 0..7;
  13.   private
  14.     function GetBits(aIndex: TBitRange): Boolean; inline;
  15.     procedure SetBits(aIndex: TBitRange; aValue: Boolean); inline;
  16.   public
  17.     property Bits[Index: TBitRange]: Boolean read GetBits write SetBits;
  18.   end;
  19.  
  20. function TByteHelper.GetBits(aIndex: TBitRange): Boolean; inline;
  21. begin
  22.   Result := (Self and (1 shl aIndex)) <> 0;
  23. end;
  24.  
  25. procedure TByteHelper.SetBits(aIndex: TBitRange; aValue: Boolean); inline;
  26. begin
  27.   Self := (Self and not (1 shl aIndex)) or (Ord(aValue) shl aIndex);
  28. end;
  29.  
  30. var
  31.   b: Byte;
  32.   i: SmallInt;
  33. begin
  34.   b := %10110110;
  35.   for i := 0 to 7 do
  36.     Writeln('Bit ', i, ': ', b.Bits[i]);
  37.  
  38.   b.Bits[3] := True;
  39.   b.Bits[7] := False;
  40.  
  41.   Writeln(BinStr(b, 8));
  42. end.

MiR

  • Full Member
  • ***
  • Posts: 228
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #42 on: August 20, 2022, 09:19:55 pm »
When trying to optimize stuff that lowlevel it is often helping to look at the generated assembler code to see if you have a good solution or not.

Adding -a to the commandline does the trick.

Michael

jb007

  • Full Member
  • ***
  • Posts: 129
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #43 on: August 21, 2022, 10:29:22 am »
Ok, not allowed!

Then I go back to my initial method:

type
  tLightLEDS = array[0..191] of boolean; // 8x24 bit   
var
  lightBL: tLightLEDS;
  lightBR: tLightLEDS;

begin
  // determ/wrtie array, 192-bits, non time critical,



  // procedure writeLedbar( 'barNr' )  // time critical, code is sollid from it self!

     for 0-191 loop

     'write' array to outPutpin 'barNr' using:

//logic ONE
  sio.gpio_set := 1 shl pinNr;  //   800
  for byCntr:= 0 to 4 do;            // = 720
  sio.gpio_clr := 1 shl pinNr;  //   400
  for byCntr:= 0 to 1 do;            // = 420 

//logic ZERO
  sio.gpio_set := 1 shl pinNr;  //   400
  for byCntr:= 0 to 1 do;            // = 320
  sio.gpio_clr := 1 shl pinNr;  //   800
  for byCntr:= 0 to 4 do;            // = 820 

It's ok with this!














to DIY or not to DIY

MarkMLl

  • Hero Member
  • *****
  • Posts: 5116
Re: pi PICO controlling ws2812b leds, ledstrips
« Reply #44 on: August 21, 2022, 10:32:20 am »
Ok, not allowed!

  tLightLEDS = array[0..191] of boolean; // 8x24 bit   

Hint: please use the forum's code tags. Things like array subscripts will get badly messed up if you don't, making life far more difficult for people trying to help you.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018