Thanks for your continued support of the project and for all of your comments and questions. The campaign is going very well, and I hope soon to have a bit more publicity to get even more people interested. Please continue to spread the word as wide as you can!
I have placed orders for a couple of Ethernet and Wi-fi modules so I can try to get them supported by the Micro Python board. If all goes well, Micro Python will be able to connect to the internet (if you add the module) and do all sorts of wonderful things!
But, right now, I would like to explain how the inline assembler works in Micro Python.
We have seen (in updates 4 and 5) how to use Python function decorators to control the compilation of functions. There is a fourth decorator to select inline assembler. To keep the Micro Python parser simple, the inline assembler uses the same syntax as normal Python, but completely different semantics. This is how you might write a millisecond delay function in Micro Python's inline assembler:
This is written specifically for a CPU that decodes ARM Thumb v2 machine instructions (such as the one on the Micro Python board). Each individual instruction is written as a Python function call, with the arguments of the machine instruction given as the arguments of the function call. Branches and labels are also written like a function call. The registers are r0, r1, r2, ... and integers are written as plain numbers (in base 2, 8, 10 or 16 as per normal Python). Hopefully you can understand what the above function does: it has 2 loops, one nested in the other, and uses registers r0 and r1 as counters for the 2 loops.
Arguments to inline assembler functions are passed in the usual way for the ARM EABI: r0 is the first argument, then r1, r2, r3. So if you write an inline assembler function, the arguments must appear with these names in this order (and you use only as many as your function needs). Inline assembler functions return whatever is in register r0 at the end.
Entry and exit code (to save and restore registers, and return correctly) is automatically added to the function to make it act like a normal C function when called (fine tuning of this might be added in the future if needed).
This inline assembler function can be called from normal Python code. You don't even need to know that it's inline assembler. You just call it as "delay(100)" for a 100 millisecond delay. The Micro Python runtime will work out that "delay" is a native function and will convert the arguments for you. Integers are converted to their value (so in this example, the delay function is passed 100 in r0) and lists, tuples and strings are converted to a pointer to their first element (you can pass the length in by passing len(obj) as another argument).
The overhead of calling an inline assembler function is the overhead of a dictionary lookup to find the function, working out that it's a native function, checking the number of arguments, and converting arguments that need converting. This is a relatively small but necessary overhead. The main use for inline assembler is for precise timing within the inline assembler function, doing tricks that can't be done in Python, optimising for speed something like a buffer copy, and so on.
At the moment I'm not completely happy with the syntactic style of the inline assembler. It's a bit difficult to notice the labels and see the structure of the code. I'm thinking of changing it to something like:
Here, we use the Python "with" statement to act like a label at that point. I find this much easier to read than the previous version, but am still deciding if it's the best solution or not. If you have any comments, please let me know.
So, that's the basics of how inline assembler works in Micro Python.
In updates to come I intend to explain how the parser works (it's a 300-line C header file and a 320-line, non-recursive function, plus a few support functions), and how to interface your own C functions to Micro Python (that is, call, and be called by, Python code).
seconds to go
Pledge £10 or moreYou selected
Supporter: support the development of Micro Python, thank you! Receive updates, and get early access to the source code so you can use it in your own projects. You can also have your name included in the code as a backer.Estimated delivery:
Pledge £20 or moreYou selected
100 backers All gone!
Get the Micro Python board at an early-bird price! Comes preinstalled with the Micro Python language and is ready to run. Requires a USB cable. You are also helping to make Micro Python open source, thank you!Estimated delivery:Add £4 to ship outside the UK
Pledge £24 or moreYou selected
Get the Micro Python board! Comes preinstalled with the Micro Python language and is ready to run. Requires a USB cable. You are also helping to make Micro Python open source, thank you!Estimated delivery:Add £4 to ship outside the UK
Pledge £40 or moreYou selected
Robotics kit: get a Micro Python board which is ready to run, 2 servo motors, header pins, a battery clip, and online instructions. Everything you need to start building your first robot! Requires a USB cable.Estimated delivery:Add £5 to ship outside the UK
Pledge £50 or moreYou selected
Hacker's kit: get 2 Micro Python boards ready-to-run, and a set of header pins. Requires a USB cable.Estimated delivery:Add £4 to ship outside the UK
Pledge £60 or moreYou selected
Starter kit: get a Micro Python board read-to-run, a graphical LCD display, a servo motor, LEDs, touch sensor, push buttons, header pins, solderless breadboard, resistors, capacitors, wires, and online instructions for projects to make. Requires a USB cable.Estimated delivery:Add £5 to ship outside the UK
Pledge £80 or moreYou selected
Wireless kit: get a Micro Python board ready-to-run, a Bluetooth module, a graphical LCD, a servo motor, touch sensor, a speaker and amplifier chip, microphone, light sensor, LEDs, push buttons, header pins, solderless breadboard, resistors, capacitors, wires, and online instructions.Estimated delivery:Add £6 to ship outside the UK
Pledge £95 or moreYou selected
Jumbo hacker's kit: you just want boards! Get 4 Micro Python boards.Estimated delivery:Add £5 to ship outside the UK
Pledge £130 or moreYou selected
Batteries included kit: get 2 Micro Python boards, a Bluetooth module, a graphical LCD, 2 servo motors, a LiPo rechargeable battery with battery charger, touch sensor, LEDs, a mini-joystick and push buttons, header pins, solderless breadboard, resistors, capacitors, wires, and online instructions.Estimated delivery:Add £10 to ship outside the UK
Pledge £150 or moreYou selected
10 backers All gone!
Get a handmade Micro Python board as soon as the Kickstarter campaign ends. And be the first to get access to the source code and board design files, as soon as the campaign ends. Also get a production version of the board when they are ready, and, if you like, a personal call from me to say thank you! Free shipping.Estimated delivery:
Pledge £300 or moreYou selected
2 backers Limited (4 left of 6)
A Python library of your choice will be implemented in Micro Python. It must be feasible and be able to run on the board. Get in touch for details. Also includes a Micro Python board.Estimated delivery:
Pledge £1,000 or moreYou selected
2 backers Limited (1 left of 3)
Micro Python will be ported to run on a microcontroller of your choice. The microcontroller must have the capabilities, and you are responsible for set-up costs for the development board and/or software. Get in touch for details. Also includes a Micro Python board.Estimated delivery:
- (30 days)