I also removed trailing spaces from modpyb.c which affected a couple
of lines technically not part of this patch.
Tested using: https://github.com/dhylands/upy-examples/blob/master/micros_test.py
which eventually fails due to wraparound issues (I could fix the test to compensate
but didn't bother)
It's still "safe" because no scripts are run. Remove the SD card if you
want to access the internal flash filesystem. Addresses issue #616.
Also: remove obsolete pyb.source_dir setting, and reset pyb.main and
pyb.usb_mode settings on soft-reset.
Converts generted pins to use qstrs instead of string pointers.
This patch also adds the following functions:
pyb.Pin.names()
pyb.Pin.af_list()
pyb.Pin.gpio()
dir(pyb.Pin.board) and dir(pyb.Pin.cpu) also produce useful results.
pyb.Pin now takes kw args.
pyb.Pin.__str__ now prints more useful information about the pin
configuration.
I found the following functions in my boot.py to be useful:
```python
def pins():
for pin_name in dir(pyb.Pin.board):
pin = pyb.Pin(pin_name)
print('{:10s} {:s}'.format(pin_name, str(pin)))
def af():
for pin_name in dir(pyb.Pin.board):
pin = pyb.Pin(pin_name)
print('{:10s} {:s}'.format(pin_name, str(pin.af_list())))
```
Some important changes to the way the file system is structured on the
pyboard:
1. 0: and 1: drive names are now replaced with POSIX inspired
directories, namely /flash and /sd.
2. Filesystem now supports the notion of a current working directory.
Supports the standard Python way of manipulating it: os.chdir and
os.getcwd.
3. On boot up, current directory is /flash if no SD inserted, else /sd
if SD inserted. Then runs boot.py and main.py from the current dir.
This is the same as the old behaviour, but is much more consistent and
flexible (eg you can os.chdir in boot.py to change where main.py is run
from).
4. sys.path (for import) is now set to '' (current dir), plus /flash
and /flash/lib, and then /sd and /sd/lib if SD inserted. This, along
with CWD, means that import now works properly. You can import a file
from the current directory.
5. os.listdir is fixed to return just the basename, not the full path.
See issue #537 for background and discussion.
Before, pyb.stdin/pyb.stdout allowed some kind of access to the USB VCP
device, but it was basic access.
This patch adds a proper USB_VCP class and object with much more control
over the USB VCP device. Create an object with pyb.USB_VCP(), then use
this object as if it were a UART object. It has send, recv, read,
write, and other methods. send and recv allow a timeout to be specified.
Addresses issue 774.
This adds a hook to get/set pyb_uart_global_debug from Python, using
pyb.repl_uart(). You can set it to an arbitrary UART object, and then
the REPL (in and out) is repeated on this UART object (as well as on USB
CDC).
Ultimately, this will be replaced with a proper Pythonic interface to
set sys.stdin and sys.stdout.
Blanket wide to all .c and .h files. Some files originating from ST are
difficult to deal with (license wise) so it was left out of those.
Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
Instead of pyb.switch() as a function, it's more consistent (with
respect to all the other modules and peripherals) to have
pyb.Switch() create a switch object. This then generalises to having
multiple switches. Call the object to get its state. Use sw.callback
to set the callback function for when the switch is pressed.
Simple but functional timer control. More sophistication will
eventually be added, or for now just use direct register access :)
Also added pyb.freq() function to get MCU clock frequencies.
It's really a UART because there is no external clock line (and hence no
synchronous ability, at least in the implementation of this module).
USART should be reserved for a module that has "S"ynchronous capabilities.
Also, UART is shorter and easier to type :)
The three classes I2C, SPI and USART now have a fairly uniform (Python)
API. All are constructed, initialised and deinitialised in the same
way. They can have most of their parameters set, using keyword arguments.
All have send and recv (although slightly different with I2C requiring an
address in master mode). recv can do inplace receiving (ie store the
data in a previously-created bytearray).
It's just polling mode at the moment, but interrupt and DMA would be
nice to add.
This is an attempt to clean up the Micro Python API on the pyboard.
Gpio functionality is now in the Pin object, which seems more natural.
Constants for MODE and PULL are now in pyb.Pin. Names of some
classes have been adjusted to conform to CamelCase. Other
miscellaneous changes and clean up here and there.
Reads ADC values into a bytearray (or similar) at a fixed rate. Needs a
better name and improved API. Also fix up DAC dma function (which also
needs a better name and API).
Also contains raw memory read/write functions, read8, read16, read32,
write8, write16, write32. Can now do:
stm.write16(stm.GPIOA + stm.GPIO_BSRRL, 1 << 13)
This turns on the red LED.
With the new constant folding, the above constants for the GPIO address
are actually compiled to constants (and the addition done) at compile
time. For viper code and inline assembler, this optimisation will make
a big difference. In the inline assembler, using these constants would
not be possible without this constant folding.
This is to reduce ROM usage. stream_p is used in file and socket types
only (at the moment), so seems a good idea to make the protocol
functions a pointer instead of the actual structure.
It saves 308 bytes of ROM in the stmhal/ port, 928 in unix/.
Can now choose at boot up whether the USB device is CDC+MSC or CDC+HID.
Choice is made by an option in boot.py, with default being CDC+MSC.
HID+MSC is not currently supported, but should be easy to implement.
Boot up now has ability to change the reset mode: hold down USR switch
while booting and LEDs will count from 1 to 7 to indicate the boot mode.
Release USR when correct mode is selected. Current modes are 1 (normal
boot), 2 (safe mode), 3 (reset FS mode).