Commit Graph

40 Commits

Author SHA1 Message Date
Damien George a8a4b01af6 stmhal: Add PWM capability for LED(3) and LED(4) on pyboards.
USB CDC no longer needs TIM3 (which was originally used for LED(4) PWM)
and so TIM3 has been freed for general purpose use by the user.  Hence
LED(4) lost its PWM capabilities.

This patch reinstates the PWM capabilities using a semi-generic piece
of code which allows to configure a timer and PWM channel to use for any
LED.  But the PWM capability is only configured if the LED is set to an
intensity between 1 and 254 (ie only when needed).  In that case the
relevant timer is configured for PWM.  It's up to the user to make sure
the timers are not used if PWM is active.

This patch also makes sure that PWM LEDs are turned off using standard
GPIO when calling led.off() or led.intensity(0), instead of just setting
the PWM counter to zero.
2016-01-29 22:44:43 +00:00
Damien George ea89b80ff4 stmhal: Make TIM3 available for use by the user.
TIM3 is no longer used by USB CDC for triggering outgoing data, so we
can now make it available to the user.

PWM fading on LED(4) is now gone, but will be reinstated in a new way.
2016-01-29 22:31:56 +00:00
Damien George 5b3f0b7f39 py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.
The first argument to the type.make_new method is naturally a uPy type,
and all uses of this argument cast it directly to a pointer to a type
structure.  So it makes sense to just have it a pointer to a type from
the very beginning (and a const pointer at that).  This patch makes
such a change, and removes all unnecessary casting to/from mp_obj_t.
2016-01-11 00:49:27 +00:00
Damien George 731f359292 all: Add py/mphal.h and use it in all ports.
py/mphal.h contains declarations for generic mp_hal_XXX functions, such
as stdio and delay/ticks, which ports should provide definitions for.  A
port will also provide mphalport.h with further HAL declarations.
2015-10-31 19:14:30 +03:00
Damien George 0851751615 stmhal: Factor GPIO clock enable logic into mp_hal_gpio_clock_enable.
Extracted GPIO clock enable logic into mp_hal_gpio_clock_enable
and called from anyplace which might need to use GPIO functions
on ports other than A-D.

Thanks to Dave Hylands for the patch.
2015-08-03 00:14:48 +01:00
Dave Hylands ea8bf81058 stmhal: Replace #include "stm32f4xx_hal.h" with #include STM32_HAL_H. 2015-07-30 00:38:25 +01:00
Damien George 2e5704d101 stmhal: Make a HW config option for LED4 being controlled by PWM. 2015-04-18 21:40:58 +01:00
Damien George 7f9d1d6ab9 py: Overhaul and simplify printf/pfenv mechanism.
Previous to this patch the printing mechanism was a bit of a tangled
mess.  This patch attempts to consolidate printing into one interface.

All (non-debug) printing now uses the mp_print* family of functions,
mainly mp_printf.  All these functions take an mp_print_t structure as
their first argument, and this structure defines the printing backend
through the "print_strn" function of said structure.

Printing from the uPy core can reach the platform-defined print code via
two paths: either through mp_sys_stdout_obj (defined pert port) in
conjunction with mp_stream_write; or through the mp_plat_print structure
which uses the MP_PLAT_PRINT_STRN macro to define how string are printed
on the platform.  The former is only used when MICROPY_PY_IO is defined.

With this new scheme printing is generally more efficient (less layers
to go through, less arguments to pass), and, given an mp_print_t*
structure, one can call mp_print_str for efficiency instead of
mp_printf("%s", ...).  Code size is also reduced by around 200 bytes on
Thumb2 archs.
2015-04-16 14:30:16 +00:00
Damien George 7a6dbaa89b stmhal: Make LED object print LED(x) for consistency with constructor. 2015-04-11 21:50:53 +01:00
Dave Hylands d7f199465f stmhal: Add support for FEZ Cerb40 II board from ghielectronics.com. 2015-01-21 00:11:04 +00:00
Damien George 2cf6dfa280 stmhal: Prefix includes with py/; remove need for -I../py. 2015-01-01 21:06:20 +00: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 40f3c02682 Rename machine_(u)int_t to mp_(u)int_t.
See discussion in issue #50.
2014-07-03 13:25:24 +01:00
Paul Sokolovsky 09e3f8f0d1 Merge pull request #707 from eblot/master-v1.1.1-build-fixes
Fix missing declaration of assert()
Replace ARRAY_SIZE with MP_ARRAY_SIZE
2014-06-20 17:29:58 +03:00
Emmanuel Blot f6932d6506 Prefix ARRAY_SIZE with micropython prefix MP_ 2014-06-19 18:54:34 +02:00
Damien George bcb3ab451b stmhal: Toggle LED using ODR ^= pin_mask. 2014-06-17 19:57:17 +01:00
Damien George 04b9147e15 Add license header to (almost) all files.
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/.
2014-05-03 23:27:38 +01:00
Paul Sokolovsky 9b71b16a94 unix,stmhal: Make "mpconfig.h" be first included, as other headers depend on it. 2014-05-02 18:08:16 +03:00
Damien George cab23051d9 stmhal: Make LED.intensity return the same value it was set to.
Also give proper error message when trying to construct a non-existent
LED.

Addresses issue #530.
2014-04-30 19:23:21 +01:00
Damien George 8d09640b22 stmhal: Add documentation in comments, and script to generate HTML.
Decided to write own script to pull documentation from comments in C code.
Style for writing auto generated documentation is: start line with ///
and then use standard markdown to write the comment.  Keywords
recognised by the scraper begin with backslash.  See code for examples.

Running: python gendoc.py modpyb.c accel.c adc.c dac.c extint.c i2c.c
led.c pin.c rng.c servo.c spi.c uart.c usrsw.c, will generate a HTML
structure in gendoc-out/.

gendoc.py is crude but functional.  Needed something quick, and this was
it.
2014-04-29 22:55:34 +01:00
Damien George 6d3c5e4301 Add ARRAY_SIZE macro, and use it where possible. 2014-04-26 10:47:29 +01:00
Damien George d689430e79 stmhal: Add SPI class.
Also some updates to compile with latest changes to core py.
2014-04-20 00:16:30 +01:00
Damien George 44ee42de50 stmhal: Rename pyb.Led to pyb.LED to conform to naming rules.
It's Light Emitting Diode, so should be LED.
2014-04-19 00:54:33 +01:00
Damien George d553be5982 build: Simplify build directory layout by putting all headers in genhdr.
Any generated headers go in $(BUILD)/genhdr/, and are #included as
'genhdr/xxx.h'.
2014-04-17 18:03:27 +01:00
Damien George ea13f407a3 py: Change nlr_jump to nlr_raise, to aid in debugging.
This does not affect code size or performance when debugging turned off.

To address issue #420.
2014-04-05 18:32:08 +01:00
Damien George a12be917a4 stmhal: Add timer module; move servo PWM from TIM2 to TIM5.
As per issue #257, servo is better on TIM5 because TIM2 is connected to
more GPIO.
2014-04-02 15:09:36 +01:00
Dave Hylands 18d21d1abd Fix pyb.Led(n) code to work properly. 2014-04-01 10:41:22 -07:00
Damien George df6567e634 Merge map.h into obj.h.
Pretty much everyone needs to include map.h, since it's such an integral
part of the Micro Python object implementation.  Thus, the definitions
are now in obj.h instead.  map.h is removed.
2014-03-30 13:54:02 +01:00
Damien George d17926db71 Rename rt_* to mp_*.
Mostly just a global search and replace.  Except rt_is_true which
becomes mp_obj_is_true.

Still would like to tidy up some of the names, but this will do for now.
2014-03-30 13:35:08 +01:00
Damien George 09d207785c stmhal: Unify naming of HW config; make SD detect configurable.
All board config macros now begin with MICROPY_HW_.

Renamed PYBv10 to PYBV10, since macros should be all uppercase.

Made SDCARD_DETECT configurable in mpconfigport.h, so that the SD
detect pin can be easily configured.
2014-03-30 12:30:35 +01:00
Damien George 038df43183 stmhal: Implement selector for USB device mode; improve boot up.
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).
2014-03-30 00:00:15 +00:00
Damien George eed6f26bed stmhal: Use rt_check_nargs to check number of arguments. 2014-03-26 22:46:03 +00:00
Damien George 9b196cddab Remove mp_obj_type_t.methods entry and use .locals_dict instead.
Originally, .methods was used for methods in a ROM class, and
locals_dict for methods in a user-created class.  That distinction is
unnecessary, and we can use locals_dict for ROM classes now that we have
ROMable maps.

This removes an entry in the bloated mp_obj_type_t struct, saving a word
for each ROM object and each RAM object.  ROM objects that have a
methods table (now a locals_dict) need an extra word in total (removed
the methods pointer (1 word), no longer need the sentinel (2 words), but
now need an mp_obj_dict_t wrapper (4 words)).  But RAM objects save a
word because they never used the methods entry.

Overall the ROM usage is down by a few hundred bytes, and RAM usage is
down 1 word per user-defined type/class.

There is less code (no need to check 2 tables), and now consistent with
the way ROM modules have their tables initialised.

Efficiency is very close to equivaluent.
2014-03-26 21:47:19 +00:00
Damien George c12b2213c1 Change mp_method_t.name from const char * to qstr.
Addresses issue #377.
2014-03-26 20:15:40 +00:00
Damien George 0e9d96f18f stmhal: Make Led, Servo and Accel their class, not a function. 2014-03-24 11:48:39 +00:00
Damien George 965e2bafea stmhal: Improve LED intensity get/set method. 2014-03-23 00:25:09 +00:00
Damien George 908a670dfc stmhal: Add intensity method for blue LED.
As part of this, rejig the way TIM3 is initialised, since it's now
shared by USB CDC and the blue LED PWM.
2014-03-22 23:54:13 +00:00
Damien George f78d9b1a72 stmhal: Add accelerometer driver; fix bug with LFN. 2014-03-20 23:33:30 +00:00
Dave Hylands 0a64c92a9c stmhal - add led support. Add netduino_plus_2 support
Tweaked a couple of the USB files to compile if neither dev nor host was defined.
Tested on netduiono plus 2 and stm32f4discovery boards
2014-03-14 09:48:49 -07:00
Dave Hylands f14b92b9e1 REPl working on UART6 with STMHAL 2014-03-12 18:15:55 -07:00