I’m trying to write a library for the HX711, for a weight scale usage. It has a non-standard serial protocol and it is relevant to control at microseconds precision the time that a digital output (used as HX711 serial clock) is high or low.
My starting point is the well-known bogde library for the Arduino platform (https://github.com/bogde/HX711) and I’m trying to write an equivalent in python in Zerynth, but I’ve encountered the following blocking problems:
- I need a way to delay with microsecond precision but the sleep(…, MICROS) built-in function doesn’t work with my ESP32 and neither hwtimers’ sleep_micros(…) works with it.
- I need a way to define a sequence of operations as an atomic block: no context switching is possible since I have to avoid a HIGH serial clock time longer than 60microseconds, otherwise the HX711 will go to sleep mode, and I can do this only if I can assert that no other thread will take control (possibly I need also to disable and re-enable interrupts).
The bodge library do it using some board-specific defined macros in C that allows him to recognize the hardware and call the appropriate functions. How can I do that in Zerynth? I don’t think that the usual threading module functionalities will help, since it is like I have to acquire a “global” lock, that stops every other thread, including the interrupts thread.