Commit Graph

417 Commits

Author SHA1 Message Date
Damien George
9d2bf9c405 drivers, wiznet5k: Wrap exported functions in a macro for renaming.
3rd party drivers should not export generic names like "close".
2014-09-30 22:51:47 +01:00
Damien George
3a1c4c5bc6 stmhal: Add network and usocket module.
As per issue #876, the network module is used to configure NICs
(hardware modules) and configure routing.  The usocket module is
supposed to implement the normal Python socket module and selects the
underlying NIC using routing logic.

Right now the routing logic is brain dead: first-initialised,
first-used.  And the routing table is just a list of registered NICs.

cc3k and wiznet5k work, but not at the same time due to C name clashes
(to be fixed).

Note that the usocket module has alias socket, so that one can import
socket and it works as normal.  But you can also override socket with
your own module, using usocket at the backend.
2014-09-30 22:36:47 +01:00
Damien George
bfa7b480a7 stmhal: For spi_init, add argument to select if NSS pin is enabled.
Most of the time you don't use the NSS pin of the SPI bus, and so it
shouldn't be enabled by default (this gave some bugs in the past).
2014-09-30 22:36:47 +01:00
Damien George
8b03d944e2 py: Remove IOError since it's deprecated; use OSError instead.
In CPython IOError (and EnvironmentError) is deprecated and aliased to
OSError.  All modules that used to raise IOError now raise OSError (or a
derived exception).

In Micro Python we never used IOError (except 1 place, incorrectly) and
so don't need to keep it.

See http://legacy.python.org/dev/peps/pep-3151/ for background.
2014-09-30 13:59:30 +00:00
Damien George
41249e17c3 stmhal, fatfs: Use stdlib for string fns; make all private fns static.
We save some code bytes by using builtin string functions.
2014-09-29 15:26:46 +01:00
Damien George
3a2795e200 stmhal: Add label to internal flash drive on creation. 2014-09-29 15:26:11 +01:00
Damien George
f042d7a4d7 stmhal: Fix edge case for timer PWM of 100%.
Also improve precision of calculating PWM percent in integer mode.
Also update teensy with edge case fix.
2014-09-29 14:15:01 +01:00
Damien George
853708738e Merge pull request #881 from dhylands/elapsed
Added pyb.elapsed_millis and pyb.elapsed_micros
2014-09-29 12:42:31 +01:00
Damien George
bf683e6b32 Merge pull request #877 from dhylands/timer-overflow
Fix timer overflow code.
2014-09-29 12:18:48 +01:00
Dave Hylands
a21f56b2d5 Added pyb.elapsed_millis and pyb.elapsed_micros
tested using:
stmhal: https://github.com/dhylands/upy-examples/blob/master/elapsed.py
teensy: https://github.com/dhylands/upy-examples/blob/master/teensy/elapsed.py
2014-09-28 11:24:44 -07:00
Dave Hylands
39296b40d4 Fix timer overflow code.
Teensy doesn't need to worry about overflows since all of
its timers are only 16-bit.

For PWM, the pulse width needs to be able to vary from 0..period+1
(pulse-width == period+1 corresponds to 100% PWM)

I couldn't test the 0xffffffff cases since we can't currently get a
period that big in python. With a prescaler of 0, that corresponds
to a freq of 0.039 (i.e. cycle every 25.56 seconds), and we can't
set that using freq or period.

I also tested both stmhal and teensy with floats disabled, which
required a few other code changes to compile.
2014-09-27 19:40:37 -07:00
Damien George
f90b59e610 stmhal, modcc3k: Add ioctl to cc3k sockets so select works. 2014-09-26 13:52:41 +00:00
Damien George
b766e79510 stmhal: Initial implementation of cc3k module and driver.
Pulled in and modified work done by mux/iabdalkader on cc3k driver, from
iabdalkader-cc3k-update branch.  That branch was terribly messy and had
too many conflicts to merge neatly.
2014-09-26 00:57:26 +01:00
Damien George
f996d8854f drivers, cc3k: Move cc3000 driver from stmhal to drivers directory. 2014-09-26 00:56:45 +01:00
Damien George
ac04a8a56a stmhal: Enable 8-byte stack alignment for IRQ handlers. 2014-09-25 15:47:53 +01:00
Damien George
e8ea0724da stmhal, timer: Factor code to compute PWM percent; improve 32bit case.
Also do the same for teensy timer code.
2014-09-25 15:44:10 +01:00
Damien George
3fafe730d3 Merge pull request #868 from dhylands/fix-teensy-float
Add pulse_width_percent to teensy.
2014-09-25 14:51:44 +01:00
Dave Hylands
53d5fa641f Add pulse_width_percent to teensy.
Fix stmhal and teensy print routines to report actual prescaler an period.
Fix teensy build to use soft-float
Add USE_ARDUINO_TOOLCHAIN option to teensy build
2014-09-23 23:19:36 -07:00
Damien George
52b5d76a6b py: Free non-interned strings in the parser when not needed.
mp_parse_node_free now frees the memory associated with non-interned
strings.  And the parser calls mp_parse_node_free when discarding a
non-used node (such as a doc string).

Also, the compiler now frees the parse tree explicitly just before it
exits (as opposed to relying on the caller to do this).

Addresses issue #708 as best we can.
2014-09-23 15:31:56 +00:00
Damien George
eaaebf3291 stmhal: Initialise stack pointer correctly.
Stack is full descending and must be 8-byte aligned.  It must start off
pointing to just above the last byte of RAM.

Previously, stack started pointed to last byte of RAM (eg 0x2001ffff)
and so was not 8-byte aligned.  This caused a bug in combination with
alloca.

This patch also updates some debug printing code.

Addresses issue #872 (among many other undiscovered issues).
2014-09-23 10:59:05 +01:00
Damien George
0e58c5810d stmhal: Add pulse_width_ratio to timer channel object.
This allows to set the pulse width (for PWM mode) as a ratio relative to
the period of the timer.  Eg, 0.5 is a 50% duty cycle.  You can set the
ratio in the channel init, or using channel.pulse_width_ratio; the
latter can also read the pulse width as a ratio.
2014-09-21 22:54:02 +01:00
Dave Hylands
becbc87fd7 Add Timer support (PWM, OC, IC) for stmhal and teensy 2014-09-19 09:26:13 -07:00
Damien George
2842945e76 stmhal: Fix bugs in documentation so it compiles. 2014-09-17 23:27:42 +00:00
Damien George
612045f53f py: Add native json printing using existing print framework.
Also add start of ujson module with dumps implemented.  Enabled in unix
and stmhal ports.  Test passes on both.
2014-09-17 22:56:34 +01:00
Damien George
1d7fb82f0a stmhal: Change 64-bit arithmetic to 32-bit for SD card block addressing.
By measuring SD card addresses in blocks and not bytes, one can get away
with using 32-bit numbers.

This patch also uses proper atomic lock/unlock around SD card
read/write, adds SD.info() function, and gives error code for failed
read/writes.
2014-09-15 23:49:57 +01:00
Felix Domke
6ff42c54bb stmhal/sdcard.c: add pyb.SD.write 2014-09-15 22:34:16 +01:00
Felix Domke
09de030651 stmhal/hal/src/stm32f4xx_hal_sd.c: fix SDHC card capacity 2014-09-15 22:34:07 +01:00
Damien George
b92cbe6129 py: Move definition of mp_sys_exit to core.
sys.exit always raises SystemExit so doesn't need a special
implementation for each port.  If C exit() is really needed, use the
standard os._exit function.

Also initialise mp_sys_path and mp_sys_argv in teensy port.
2014-09-15 15:53:09 +01:00
Damien George
8594ce2280 py: Implement divmod, % and proper // for floating point.
Tested and working on unix and pyboard.
2014-09-13 18:43:09 +01:00
Damien George
32781cce6d stmhal: Slightly improved memcpy; memset uses word store when aligned. 2014-09-13 00:12:41 +01:00
Damien George
5792500ccc Merge branch 'memcpy' of github.com:iabdalkader/micropython into iabdalkader-memcpy 2014-09-12 23:23:49 +01:00
Damien George
89ab3be0b1 Merge branch 'master' of github.com:micropython/micropython 2014-09-11 22:28:58 +01:00
Damien George
20beff9ae3 py and libm: Add asinf,acosf; print higher precision for float.
Also use less stack space when printing single precision float.

Addition of asinf and acosf addresses issue #851.
2014-09-11 22:24:45 +01:00
iabdalkader
d60580eb5e Optimize memcpy more 2014-09-11 19:01:48 +02:00
Hirotaka Kawata
2b4af54992 Add LIS3DSH accelometer support to staccel.py 2014-09-11 16:40:53 +09:00
iabdalkader
81b2ddf5d1 Memcpy: copy words 2014-09-11 07:49:21 +02:00
Damien George
5c00757a5c stmhal: uart ioctl uses EINVAL, and checks TXE bit for write-ability. 2014-09-07 20:57:18 +01:00
Damien George
013d53c0b4 Remove skeletal modselect from extmod and just put it in stmhal. 2014-09-07 20:42:01 +01:00
Damien George
e2a618615d stmhal: Fix modselect so non-hashable objects can be polled. 2014-09-07 20:41:09 +01:00
Damien George
a2f55fe12b stmhal: Add polling ability to UART object. 2014-09-07 20:40:32 +01:00
Damien George
6c9c7bc75a stmhal: Implement generic select.select and select.poll. 2014-09-07 20:40:32 +01:00
Damien George
bad2df3e95 stmhal, modwiznet5k: Add very minimal documentation. 2014-09-01 22:58:22 +01:00
Damien George
bcf041f1a3 stmhal: Add wiznet5k module, to control WIZnet ethernet adaptor.
Allows to create socket objects that support TCP and UDP in server and
client mode.  Interface is very close to standard Python socket class,
except bind and accept do not work the same (due to hardware not
supporting them in the usual way).

Not compiled by default.  To compile this module, use:
make MICROPY_PY_WIZNET5K=1
2014-09-01 22:52:38 +01:00
Damien George
ecc88e949c Change some parts of the core API to use mp_uint_t instead of uint/int.
Addressing issue #50, still some way to go yet.
2014-08-30 00:35:11 +01:00
Damien George
8707ea3421 lib: Add lib and libm, moving current files from stmhal.
Top-level lib directory is for standard C libraries that we want to
provide our own versions of (for efficiency and stand-alone reasons).
It currently has libm in it for math functions.

Also add atanf and atan2f, which addresses issue #837.
2014-08-29 22:42:26 +01:00
Damien George
f05b87bd63 Merge pull request #824 from dhylands/sdcard-power
Fix sdcard_power_on to not do anything if the card is already powered on...
2014-08-26 22:58:54 +01:00
Damien George
3b72da674e stmhal, STM32F4DISC: Small changes to ST accel driver. 2014-08-26 22:41:27 +01:00
Damien George
e00fb08f99 stmhal, staccel.py: Style cleanup. 2014-08-26 17:30:48 +01:00
David Siorpaes
f4ce26de5c Added LIS302DL ID check 2014-08-26 18:23:00 +02:00
Damien George
3bb7efc943 stmhal: Hookup USB_VCP.any().
Thanks to Dave Hylands for this patch.
2014-08-26 14:18:22 +01:00