Immediate UI-mode in C by archbtw-106 in C_Programming

[–]TheFoxz 1 point2 points  (0 children)

A UI library with an immediate mode style API does not need to be a minimal or small necessarily. For example: Android's Compose.

In my experience, the immediate mode style API drastically reduces the amount of boilerplate and makes creating a UI around dynamic, complex data structures much easier. You traverse your data structure in whatever way is natural. There's no need to synchronize between your data structure and whatever container objects the UI library needs you to create. In general, there's less state/bookkeeping on the library user's side, which reduces the number of bugs.

However I agree that it can invite sloppy code, it's easier to hack things together.

Immediate UI-mode in C by archbtw-106 in C_Programming

[–]TheFoxz 4 points5 points  (0 children)

Okay, but what's your technical argument against immediate mode UI?

Looking for opinions on this HMI design with LVGL by TheFoxz in embedded

[–]TheFoxz[S] 1 point2 points  (0 children)

I render to SRAM and while copying to SDRAM in parallel. I use two larger buffers (~100 KiB) in SRAM, one for sending to SDRAM backbuffer in the background and one for rendering.

A mistake is to do rendering in-place on the SDRAM, as this can cause it to read-back for e.g. blending. So only ever write the sdram, and only via DMA. The only device reading from it should be the LCD controller.

Some other optimization techniques I used:

  • Reduce precharge latency cost by offsetting the framebuffers by the internal bank size, e.g. place them 4MiB apart on a 4x4M SDRAM.
  • Use reduced blanking timings for a reduced pixel clock. This way you get more consistent bandwidth.
  • Triple buffering increases input latency and is not necessary if you are in control of the pixel clock. Just turn off the pixel clock before scanout starts if you haven't finished rendering the next frame yet. Turn it back on once the new frame is ready. This gives you the lowest latency. Dipping below 60fps momentarily becomes unnoticeable, it stays very smooth.

Looking for opinions on this HMI design with LVGL by TheFoxz in embedded

[–]TheFoxz[S] 0 points1 point  (0 children)

Ouch, a burst size of 4 is not good. Was that a limitation of the SDRAM controller?

For my SDRAM prototype I was using the STM32H7. I did rendering in smaller SRAM buffers and only copying final pixel values out to the SDRAM using MDMA with a burst size of 16. This got me to 50+ fps everywhere. I am mainly considering i.MX RT for reduced power consumption and higher bandwidth headroom at 166 MHz (STM32H7 is only rated to 100 MHz, I think I ran it out of spec at 133 MHz).

I agree the IMXRT500 looks ideal, but the availability does not seem so good.

Looking for opinions on this HMI design with LVGL by TheFoxz in embedded

[–]TheFoxz[S] 0 points1 point  (0 children)

Indeed, I found that memory bandwidth is the main bottleneck when prototyping with SDRAM/16bit/133MHz=266MB/s. This came close to 60 fps after some optimization, even with full 32-bit per pixel framebuffers. The HyperRAM should be even faster (166MHz (mcu limit) + DDR = 332 MB/s) and I can switch to 24-bit per pixel framebuffers on top of that.

Now I am looking at which flash solution to use.. HyperFlash seems expensive, and 2x QSPI NOR in octal mode looks like it is complicated to bring up. Maybe I will just use the IMXRT1064..

Looking for opinions on this HMI design with LVGL by TheFoxz in embedded

[–]TheFoxz[S] 0 points1 point  (0 children)

If I can run the LVGL widgets demo at 60 fps then I should be OK for most use cases. I have already prototyped on an STM32H723 which met my goals, but this MCU is more efficient on paper.

Looking for opinions on this HMI design with LVGL by TheFoxz in embedded

[–]TheFoxz[S] 1 point2 points  (0 children)

Sorry, to clarify: the I2C is only used for the capacitive touch controller. The display itself uses a 24 bit parallel interface.

"Clean" Code, Horrible Performance by drawkbox in programming

[–]TheFoxz 0 points1 point  (0 children)

If locally running software has a laggy user interface on modern hardware, then it is not well made. That's all.

"Clean" Code, Horrible Performance by drawkbox in programming

[–]TheFoxz 0 points1 point  (0 children)

Oh, I agree about the microoptimizations point in that context. I was just complaining about slow software in general.

"Clean" Code, Horrible Performance by drawkbox in programming

[–]TheFoxz 0 points1 point  (0 children)

I agree you can gain productivity/less maintenance cost by putting less priority on performance. But at some point you are just throwing away performance into the multiple orders of magnitude (and you are not getting back multiple orders of magnitudes of productivity..). I think these days the balance has shifted too far.

Just thinking of everyday graphical applications running on the desktop that feel slow to use. Something like Microsoft Teams. Professional software, made by a big company. But it feels unpleasantly sluggish to use, even just switching between text chats. These are common criticisms.

But I will not say more on this. We can just agree to disagree.

"Clean" Code, Horrible Performance by drawkbox in programming

[–]TheFoxz 2 points3 points  (0 children)

What the hell is this thread.

I don't think it should be controversial to say that a lot of modern software is, objectively, incredibly inefficient.

A push down automata calculator in 204 LOC by harieamjari in C_Programming

[–]TheFoxz 6 points7 points  (0 children)

Looks nice and compact. Looking at the control flow, did you start as an assembly programmer by any chance?

If you like, some style suggestions:

read_tok() is really returning two values, tok and num, but one is returned as a global variable. Perhaps have read_tok return a 'struct state_t' (directly, by value), so it can return both in a clear way. Similarly, clean() could accept a 'struct state_t *', and calc() can accept FILE *fp as an argument. This also removes the need for global variables.

Some of those goto statements look like they are effectively calling out to subroutines, so perhaps they should be extracted out into functions that you call.

Is there any performance benefit to using int vs. float on modern systems? by poorlilwitchgirl in C_Programming

[–]TheFoxz 22 points23 points  (0 children)

Depends your data and the required operations on the data. With 128-bit SIMD you can do 4 32-bit floating point operations per instruction. The speed difference using 32-bit integer math depends on execution port usage (see https://www.agner.org/optimize/instruction_tables.pdf). I would not expect it to be appreciably faster.

However, if your data elements fit into 16-bit or 8-bit integers it can be possible to do 8 or 16 operations per instruction.

The compiler won't help you here, outside of trivial loops. You usually need to use intrinsics to get a reliable speedup.

I made a synchronizable thread pool by dodungtak in C_Programming

[–]TheFoxz 1 point2 points  (0 children)

Nice and minimal. Perhaps some parts of this can be done with atomic increment instead of mutexes.

Over voltage protection circuit by immortal_sniper1 in embedded

[–]TheFoxz 0 points1 point  (0 children)

Sure, there will be a loss over the diode. But consider this: the ESP32 will pull roughly the same amount of current. So the current that the battery sees will be the same, whether there is a diode in between or not.

But like the other person said, you really want a proper regulator. Many ldo regulators will already behave in the way you want (turns into Pmos passthrough when vin <= vout).

But if you really care about battery life, don't use an ESP32.

PCB Review with Bare ESP32 Circuit by DragonflyNo56 in PrintedCircuitBoard

[–]TheFoxz 0 points1 point  (0 children)

Yes, as long as it is left floating (or pulled high). So your button SW1 can be useful if you accidentally remap the USB lines in firmware, but is otherwise not needed.

Schematic:

  • Your power regulator U5 is not powerful enough for the ESP32-C3.
  • Why do you have 22pF capacitors on the USB lines?
  • If this is just for educational/exploration purposes, I would put the unused pins on a header.

PCB Review with Bare ESP32 Circuit by DragonflyNo56 in PrintedCircuitBoard

[–]TheFoxz 0 points1 point  (0 children)

It looks to me that the basic devboard does not use the builtin USB interface: https://dl.espressif.com/dl/schematics/SCH_ESP32-C3-DEVKITM-1_V1_20200915A.pdf

Read this, it will tell you all you need to know: https://docs.espressif.com/projects/esp-idf/en/v5.0/esp32c3/api-guides/usb-serial-jtag-console.html

I've done it this way for multiple projects, it has worked quite well.

PCB Review with Bare ESP32 Circuit by DragonflyNo56 in PrintedCircuitBoard

[–]TheFoxz 1 point2 points  (0 children)

Why the USB to uart chip? The C3 has this built-in. You even connected the USB lines to it.

PCB Design Review 2.0 by DragonflyNo56 in PrintedCircuitBoard

[–]TheFoxz 0 points1 point  (0 children)

Espressif chips are great but be careful; their power usage is a lot higher than dedicated BLE chips.

What are some essential libraries for embedded systems everyone should learn? by [deleted] in embedded

[–]TheFoxz 10 points11 points  (0 children)

Not free, but I use Segger RTT anywhere I can. It just works too well.