Wykres commitów

16 Commity (master)

Autor SHA1 Wiadomość Data
Angus Gratton decf8e6a8b all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a.  The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.

This STATIC feature is rarely (if ever) used.  And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.

So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing.  For example, newcomers don't have
to learn what the STATIC macro is and why it exists.  Reading the code is
also less "loud" with a lowercase static.

One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.

Methodology for this commit was:

1) git ls-files | egrep '\.[ch]$' | \
   xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"

2) Do some manual cleanup in the diff by searching for the word STATIC in
   comments and changing those back.

3) "git-grep STATIC docs/", manually fixed those cases.

4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-03-07 14:20:42 +11:00
Jim Mussared 4d568a5bd7 samd/boards/make-pins.py: Update to use tools/boardgen.py.
This replaces the previous make-pin-table.py with an implementation based
on boardgen.py.

- MICROPY_PY_MACHINE_PIN_BOARD_CPU macro is removed. This isn't optional
  on other ports, so no need for it to be optional on SAMD.
- pin_af_table is removed, and lookups just search the cpu dict instead
  (this saves N*wordsize bytes of firmware size to have this extra table).
- pins.csv is now BOARD,CPU to match other ports.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-11-03 14:18:32 +11:00
robert-hh 4598b89ce9 samd: Add Pin.board and Pin.cpu classes to Pin.
For compatibility with other ports.  Code increase up to ~1250 bytes for
SAMD21.  The feature is configurable via MICROPY_PY_MACHINE_PIN_BOARD_CPU
in case flash memory is tight.
2023-02-17 17:27:21 +11:00
robert-hh a6760bd4ef samd/modmachine: Replace the LED class by the Signal class.
It simplifies and improves the code.  The LED_Pxxx lines of the board.csv
lines can still be used, but will be taken as Pin definitions.
2022-10-25 23:39:41 +11:00
robert-hh e5cf3fab95 samd/machine_pin: Change the pin handling and naming/numbering.
Pin numbers are now the MCU port numbers in the range:

    PA0..PA31:  0..31
    PB0..PB31: 32..63
    PC0..PC31: 64..95
    PD0..PD31: 96..127

Pins can be denoted by the GPIO port number, the name as defined in
pins.csv or a string in the form Pxnn, like "PA16" or "PD03".

The pins.c and pins.h files are now obsolete.  The pin objects are part of
the AF table.

As result of a simplification, the code now supports using pin names or
numbers instead of pin objects for modules like UART, SPI, PWM, I2C, ADC,
pininfo.
2022-10-25 23:34:07 +11:00
robert-hh 03075a6839 samd/modmachine: Implement machine.lightsleep().
Which just sets the CPU clock to 200kHz and switches the peripheral clock
off.  There are two modes:

    machine.lightsleep(duration_ms)

and

    machine.lightsleep()

In any mode any configured pin.irq() event will terminate the sleep.

Current consumption in lightsleep for some boards:
- 1.5 - 2.5 mA when supplied trough an active USB
  (Seeed XIAO w/o power LED, Adafruit ItsyBitsy)
- 0.8 - 2 mA when supplied through Gnd/+5V (Vusb)
  (Seeed XIAO w/o power LED, Adafruit ItsyBitsy)
- < 1 mA for SAMD51 when supplied trough a battery connector
  (Sparkfun Thing SAMD51 plus)

Related change: move the calls to SysTick_Config() into set_cpu_freq().  It
is required after each CPU freq change to have ticks_ms run at the proper
rate.
2022-10-25 23:07:27 +11:00
robert-hh 366c801b35 samd/machine_pin: Change the printing of Pin and LED objects.
It now prints lines like:

    Pin("D9", mode=IN, pull=PULL_UP, GPIO=PA07)

or

    LED("LED")

showing for consistency the names as given in pins.csv.  For pins, the GPIO
numer is printed as well for a reference.
2022-10-06 23:14:21 +11:00
robert-hh aa2d746ef4 samd/machine_led: Optimise size of the machine.LED class.
By reducing the methods to on(), off(), toggle() and call, and using the
method implementation of the machine.Pin class.

The code size reduction is 756 byte.
2022-10-06 22:54:11 +11:00
robert-hh 6e2dff6bae samd/modsamd: Add pininfo() function to the samd module.
samd.pininfo() returns the data stored in the pin af table for a pin.
Using a small script, a nice representation of the table can be created.
2022-10-06 22:53:28 +11:00
robert-hh 4b6f6ccf88 samd/machine_pin: Add pin.irq() to the machine.Pin class.
Its API conforms to the docs.  There are 16 IRQ channels available, which
will be used as assignable to the GPIO numbers.  In most cases, the irq
channel is GPIO_no % 16.
2022-10-06 22:46:53 +11:00
robert-hh e8615f5813 samd/machine_pin: Allow specifying a pin or LED by its name as a string.
The names are defined in pins.csv.
2022-10-06 22:37:46 +11:00
robert-hh 33eaf739d2 samd/machine_pin: Add OPEN_DRAIN mode for pins.
Changes in this commit are:
- Use mphal_xx functions whenever possible.
- Remove obsolete includes.
- Clean up traces of a non-functional pin.irq() from earlier builds.
  Pin.irq() will be added in further commits in a working manner.
2022-10-06 22:37:05 +11:00
Jim Mussared 94beeabd2e py/obj: Convert make_new into a mp_obj_type_t slot.
Instead of being an explicit field, it's now a slot like all the other
methods.

This is a marginal code size improvement because most types have a make_new
(100/138 on PYBV11), however it improves consistency in how types are
declared, removing the special case for make_new.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:15 +10:00
Jim Mussared 9dce82776d all: Remove unnecessary locals_dict cast.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Jim Mussared 662b9761b3 all: Make all mp_obj_type_t defs use MP_DEFINE_CONST_OBJ_TYPE.
In preparation for upcoming rework of mp_obj_type_t layout.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-19 19:06:01 +10:00
Peter van der Burg 2f65ded1a2 samd: Add Pin and LED classes, and machine.unique_id. 2021-11-19 11:43:06 +11:00