Accéder au contenu principal

Pico SDK, raspberry pi pico 2040, and semantic of the "Break"

 Belong to C++ standard of 1999, and at least since here we can define to following fact:

  1. Use break everywhere is suspect full near an avoidance in a clear definition of what is executed and what's not .
  2. Uses of Goto is greatly discouraged since you can either achieve a coding paradox using recurrent call of a function, implicating Goto , simply make the logic analyzer inside the compiler to not clearly define where it should go. We have evolve over but with my latest Hazard-3 RISCV compiler for rp2350 does not stand more than half hour running the ssd1306_i2c example it's abnormal. 

Screen Pico SDK for producing example on my new RP2350 WaveShare board, to froze at the first try of an ssd1306 looping a message, to show white raspberry moving to the right and erasing through a center line diagonal to be draw over the text in a clockwise way. Even over the evening I get doubt about the Pico SDK itself to not support the replacement of the break/goto code inserted inside ssd1306_i2c found in general Pico-Sdk example, or included in VScode. It went normal on the morning, I mean it finally understand or do some cmake stuff appealing to recognize I was doing something normal with something existing... It's weird, but that evening I was unable to let the code repeat and to loop the ssd1306_i2c description of the ssd1306 pixel draw on it. 

Over the morning when it went normal:

- realize the substitution of the break into the function Drawline ( static void DrawLine ), do have to remove the break and substitute it with a boolean approach.  

Up to my eyes it give advantage.

- inside the while statement is formed from boolean static and upon a conditional reality it uses the break to leave and the while and quit the function.

see in initial code sample:


static void DrawLine(uint8_t *buf, int x0, int y0, int x1, int y1, bool on) { int dx = abs(x1-x0); int sx = x0 &lt x1 ? 1 : -1; int dy = -abs(y1-y0); int sy = y0 &lt y1 ? 1 : -1; int err = dx+dy; int e2; while (true) { SetPixel(buf, x0, y0, on); if (x0 == x1 && y0 == y1) break; e2 = 2*err; if (e2 >= dy) { err += dy; x0 += sx; } if (e2 <= dx) { err += dx; y0 += sy; } } }

 Over this alternative: 


static void DrawLine(uint8_t *buf, int x0, int y0, int x1, int y1, bool on)
{
  int dx =  abs(x1-x0);
  int sx = x0 &lt ltx1 ? 1 : -1;
  int dy = -abs(y1-y0);
  int sy = y0 &lt y1 ? 1 : -1;
  int err = dx+dy;
  int e2;
  bool bContinueLoop=true;

  while ( bContinueLoop ) 
  {

    SetPixel(buf, x0, y0, on);
    
    if (x0 == x1 && y0 == y1)
    {
      bContinueLoop=false;
    }
    
    if ( bContinueLoop )
    {
      e2 = 2*err;

      if (e2 >= dy) 
      {
        err += dy;
        x0 += sx;
      }
      if (e2 <= dx) 
      {
        err += dx;
        y0 += sy;
      }
    }
  }
}

And up to compiler view once it's compiled for rp2040 here some strange in the story:


maxiste@XeonSrv2650:~/github/rp2040/i2c$ wc -c ssd1306_i2c_v1/build/ssd1306_i2c.uf2 ssd1306_i2c/build/ssd1306_i2c.uf2 31232 ssd1306_i2c_v1/build/ssd1306_i2c.uf2 31232 ssd1306_i2c/build/ssd1306_i2c.uf2 62464 total maxiste@XeonSrv2650:~/github/rp2040/i2c$ sha1sum ssd1306_i2c_v1/build/ssd1306_i2c.uf2 ssd1306_i2c/build/ssd1306_i2c.uf2 1a8d36a0aa2d224b398c8bf7a46e8ed54fb3f251 ssd1306_i2c_v1/build/ssd1306_i2c.uf2 51a6936ec71217b9645cb1026ae8388ff650b30d ssd1306_i2c/build/ssd1306_i2c.uf2 maxiste@XeonSrv2650:~/github/rp2040/i2c$  

 Belong to sha1sum they are different but belong to size it give the same answer turning a break from a while with coding the boolean inside the while having a variable in boolean type assigned to "True", to loop over and over, and then upon  "x0 == x1 && y0 == y1" the boolean variable is set to false. Thus require to brace the rest of the operation with usually braked with a if This is True to allow the code to be executed. But this little change to skip in problem to directly brake out does not cost in byte at the compilation time.

So it's the comment of the day. Because having to reduce the goto restart into a similar before :restart we can get a sort of setup() like function like Arduino code owning a setup which is unique and a main which naturally loop. But actually solution over rp2350 compiled for pico2 with RISVC compiler allowing encrypted boot and couple of strange solution to be performed by pico2, does froze after 30 minutes of run while actually pico-w rp2040 does run it for day either the break/goto version and the version without break. 

 As some say there is ultimately one kind of break which is right to use. Related to switch semantic using break to stop a sequence from inside a switch. Yes it's not forbidden to pass to a switch choice and fall into the other bottom switch label if you did not supply any break between them. As some suggest the break work semantic inside a switch is different of the concurrent break inside a while or for, I am getting rid of them.

Other suspect full things inside the code.  


restart: area.start_col = 0; area.end_col = IMG_WIDTH - 1; calc_render_area_buflen(&area); uint8_t offset = 5 + IMG_WIDTH; // 5px padding for (int i = 0; i < 3; i++) { render(raspberry26x32, &area); area.start_col += offset; area.end_col += offset; } SSD1306_scroll(true); sleep_ms(5000); SSD1306_scroll(false); char *text[] = { "A long time ago", " on an OLED ", " display", " far far away", "Lived a small", "red raspberry", "by the name of", " PICO" }; 

 As this extract from the int( main ) does own a loop initiated with the label ":restart" is more the char *text[] that is re-initialized every turn the goto do the jump to the label and I don't know is every variable are really re-initialized, but this case suggest to move the variable *text out of the loop because it's not yet changed here and still loop. It's not mention either if the rp2350 or rp2040 write down to the ssd1306 the remaining "Lived a small red raspberry by name of PICO", but no one can really see it. It stop at "far far away", so if there is memory related between the pico and the ssd1306. We are not seeing it and might be another bogus write down into memory that require to be handled. Like doing a upper scroll text to see the rest and prevent to write down all the draw pixel into a void region because the lcd is 128x32 height high and deal with 64 pixel in height to allow seeing everything. Or someone being all the 56 coders from Pico did not see the problems or it's all C-RUST things they did not craft out a good way to allow things to work.


Posts les plus consultés de ce blog

Does George Santos have receive money from Honest Gill.

 Back to five point of Honest Gill was :  76% of Americans say their representatives do a very bad job of listening to them. We used to aim big in this country – what happened? I’ll work hard to make sure 100% of Americans feel unrepresented.  I’ll make elections more representative for people who pay me. Ranked Choice Voting would disenfranchise campaign mega-donors and carelessly empower everyday Americans who don’t understand the wants and needs of the fundraising class. I’ll strengthen partisan gerry mandering. It’s better that politicians choose their voters, not the other way around, right ? Lobbyists spend $4 million per member of Congress. How are us poor Congress Members supposed to live on chump change? I pledge to continue to take gobs of cash from unscrupulous lobbyists. Just 4% of U.S. adults say the political system is working extremely or very well. Honest Gil will do his gosh darndest to get that number down to 0%.   To point 1, Honest Gil wi...

What are you doing here, another one ?

 Yeah, that's another one piece of Intel Corporation. Not in is box, already plugged somewhere. And now it's not sold with a board and not only wrap into a bubble bag. It come with the plastic box, and at least.    At 5.59$CA, if one of my board ares misconfiguration and lacking BIOS update to support higher than 10 Mb of memory, for family e5 2650v4 with 10 core rather than 14 and less than 20 Mb of L3 cache and will probably report only 60% of the memory is inaccessible rather than yelling for 66% of the memory if this one calculate the L3 memory as internal memory error for being unable to count the edge. Yes it's true an e5-2650 own 30Mb of L3 cache while the e5-2630 own 25 Mb. Ok it's not also the theoretical 2 cores in less. I seriously believe the second one will fail, for not having around 6 to 8 core and up to 15 Mb of memory on L3 cache. But apparently there is so many option withing the bios it let you disable the core. And mean I do request to investigate fo...

South Park Season 6 episode 8, Getting entry from everywhere, and talk that purge.

 Inside Red Hot Catholic love: Mostly engaged in a quest with old paper that compromise Vatican, we can empirically see the spider invade the Vatican as web that is origin of the sin and may compromise a story long of a big king willing to eat whole religion itself and there is drawn a idea the king will someday enter in the Vatican to invade it. But it's not the detailed reason, two other sub-talk from parent and delegation of believe do something strange among South Park resident.   Starting at the seventh minutes where Cartman challenge everyone. He not only winning but  got a slang talk to inherit from a strange symptoms against talk .     And manifestation of that symptoms lets people refluxing theirs 'expelation' back from the exit to normal way we are using to eat or express themselves.   We call it intro-digestion symptoms and beware of what you are doing it take you by surprise.  Accordingly to Stan report or Cartman slang to get a pooh out of...