Use Python to develop Hongmeng equipment program (0-first experience)

To learn more, please visit:

Hongmeng technology community built by 51CTO and Huawei official strategic cooperation

https://harmonyos.51cto.com/#bkwz


So far, the "officially designated language" developed by Hongmeng Equipment is still the C language!

 

This seems to be a normal thing. After all, the development of Hongmeng equipment belongs to the category of embedded development, and the C language is the well-deserved first choice in embedded development. Therefore, everyone has accepted this reality. . . . . . .

 

Last weekend, I was fortunate enough to have face-to-face communication with Huawei’s bigwigs (actually I went to hug my thighs). We all agreed that if equipment development can support more concise development methods (such as: simple language, simple development environment) ), I believe that more developers will join. . .

 

Now, is there a language that has a wide audience and is easy to learn?

 

Of course there is, I believe you already know it, it is Python!

In the past few years, Python has entered the public eye with the help of the rise of AI. Her simplicity and ease of learning are very popular, and many elementary school students can use her to program.

Therefore, a crazy-looking idea popped out of my brain: If the development of Hongmeng devices can use Python, it will definitely lower the learning threshold and attract more developers. . .

 

So just do it. . .

 

I first investigated the current various Python implementations (Python is open source and can be implemented through the source code), and found that both the public version of Python and MicroPython can be my starting point (baseline). After all, I don’t need to write an explanation according to the Python specification. Come out! However, there are still difficulties. These two implementations have a lot of dependencies, and the design goals are different: the public version of Python is a large and comprehensive system (interpreter, library, etc.), and the goal is as long as the resources are abundant Play as you like; MicroPython is tailored from the public version of Python and has been extended to basically define it as an operating system on a micro embedded device.

 

So, how do you start? Making choices is really hard! ! ! !

 

I started to organize my thoughts, what do I want to do? ! Then there is the following architecture diagram.

Obviously, what I want is to provide other ways of developing Hongmeng equipment, not to replace the C language with Python! Therefore, my first milestone (milestone) is to obtain a Python interpreter that can run on the Hongmeng device (Hi3861)! With this Python interpreter, the next step is to design the Python version of the Hongmeng system development interface. . .

 

After determining the goal, the next question is: Should I use the public version of Python or MicroPython?

 

After comparing the two codes, I found that MicroPython actually tailored the public version of Python in the interpreter. . . Why is this? ? ? I don't have an exact answer for the time being, but from the code implementation, it can be seen that MicroPython is a trade-off for adapting to more low-configuration hardware! Obviously, many things have been considered! I think that the current positioning of Hongmeng equipment is also low-profile hardware, so it seems more appropriate to use MicroPython to operate.

 

=========== Gorgeous dividing line Begin ===========

 

After 2 days of surgery, there is a running version (DTPython)! !

 

The usage is as follows:

1. Download libdtpython.a in the attachment at the end of the article, and copy it to the \code-1.0\vendor\hisi\hi3861\hi3861\build\libs directory, as shown in the figure:

2. [Optional] Write Python code (currently no library support is provided), and use the Txt2Str tool in the attachment at the end of the article to convert it to a C string. The usage is as follows:

Description:

  • Txt2Str stores the Python code in a C file in the form of a C string (such as test.c in the figure above)
  • Add the converted C file to the project to use the Python code in the C code (refer to the example in the attachment at the end of the article)

 

Note: There is no easy way to directly program Python source files to the device, so the above steps are required.

 

3. Use Python code in device development, examples are as follows:

4. The running results are as follows:

 

=========== Gorgeous dividing line End ===========

 

postscript:

At present, only basic Python code can be run, and there are still many problems that need to be solved.

I hope everyone will try my solution, find more bugs, and mention issues more.

 

The code at this stage is messy, I'm really embarrassed to take it out, the basic functions are a little more stable, directly open source! ! !

 

Enjoy It !


The article involves downloading, you can click on the original link below to download the

article source: https://harmonyos.51cto.com/posts/1887


To learn more, please visit:

Hongmeng technology community built by 51CTO and Huawei official strategic cooperation

https://harmonyos.51cto.com/#bkwz


Guess you like

Origin blog.51cto.com/14901125/2555591