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

Hottest Snapshoot from my ThF4_LaFe Hard-State Nuclear Holdrum

This is my ThF 4 + LaFe (α-Fe) Nuclear Holdrum ( more than quantic-one ), for it's hard-state design. It's the revealed reproduction from 1980, after seeing the images with my tiny eyes from M.Villeneuve having a snapshoot from the Psychiatric hives, or vault. It was forbidden to stole because it was not yet made at this moment... To reproduce the image on the picture, they use white paint on the Xenon tube on external side of the holdrum... In fact this is PTFE thread used and it have it's property... Ionisation from PTFE thread is mildly-helper driving photo-source like filter-to-filter of a « ridicule » quater-plate effect side of using Fluor in light filtering, while in high-energy and high velocity light it en-lighting prior to filter... In This case  it's good, we are dealing with Ultra-violet led PaInSe ( also know as Hard-state gamma-ray pulse led from Praseodymium/Indium with filter to throw down wavelength to UV region...   ). I can conclude it's 5 xeno...

Oups, The AME 2012 Atomic Mass Evalutation fall in my Hand...

 I don't know what Zantagor, a real fanatic of Japanese / Chinese games told me about the Word Downloading in Japanese, but during I was looking to update data toward my Python module names NuclearMassTable from masstable having a lot of inexact information behind nndc.bnl.gov, but this PDF just fall in my hand when I was trying to seek for a document from cpc-hepnp.ihep.ac.cn , which is the type of hack-site not made to be KANJI-prone and backend still in english... The AME2012 Atomic Mass Evaluation Some content in Image.. Sorry my ImagePathDesign is not ready, but orcad give about perfect conversion and PDF2DJVU seems to work fine with... Few example about the content : Units; recalibration of α- and γ-ray energies Atomic mass determination for a particular nuclide can be generally performed by establishing an energy relation between the mass we want to deduce and that for a well known nuclide. This energy relation is then expressed in electron-volts (eV). Mass value...

My Xeon got afraid of it so it have run it out.

 Yes, there is an alternative to make Windows working. It's changing inside bios inside "CSM" section which have it and some item where left into "UEFI" and not auto-detect between "UEFI" and Legacy and does support Windows installation.    With such speed.   Belong to images it's my "DDR4 ECC" memory which are 2x 16 Gigabytes at 2133 Mhz that is actually running at 2194 Mhz, so close to processor speed which is 2.2Ghz. And it's only what is supported in overclock-ability the memory is pushed hard. Pushed at 103% of it's clock it might be the reason sometime it shut down silently or simply doing a task and shutdown. Except in Linux Min Xia installation it reboot before it end the loading of all the module. But exceptional it can last for 10 hours long formatting a Tera Byte ( out of it's 8 days of formatting ) and by using the Linux Mint installer of Xia ( which is the previous version of Linux Mint ). Apparently Virginia or W...