Wykres commitów

22 Commity (master)

Autor SHA1 Wiadomość Data
Damien George 48b5a7b060 extmod/modmachine: Provide common Python bindings for bootloader().
Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George 90023b4dcf extmod/modmachine: Clean up decls of machine types to use common ones.
The machine_i2c_type, machine_spi_type and machine_timer_type symbols are
already declared in extmod/modmachine.h and should not be declared anywhere
else.

Also move declarations of machine_pin_type and machine_rtc_type to the
common header in extmod.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-26 16:20:53 +11:00
Damien George 5b4a2baff6 extmod/machine_uart: Factor ports' UART Python bindings to common code.
This is a code factoring to have the Python bindings in one location, and
all the ports use those same bindings.  For all ports except the two listed
below there is no functional change.

The nrf port has UART.sendbreak() removed, but this method previously did
nothing.

The zephyr port has the following methods added:
- UART.init(): supports setting timeout and timeout_char.
- UART.deinit(): does nothing, just returns None.
- UART.flush(): raises OSError(EINVAL) because it's not implemented.
- UART.any() and UART.txdone(): raise NotImplementedError.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-26 10:46:42 +11:00
Damien George 95d8b5fd55 extmod/machine_adc: Factor ports' ADC Python bindings to common code.
No functional change, just code factoring to have the Python bindings in
one location, and all the ports use those same bindings.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-23 17:16:45 +11:00
Damien George 7e7af71527 extmod/machine_pwm: Remove header file and move decls to .c file.
With public declarations moved to extmod/modmachine.h.  It's now mandatory
for a port to define MICROPY_PY_MACHINE_PWM_INCLUDEFILE if it enables
MICROPY_PY_MACHINE_PWM.  This follows how extmod/machine_wdt.c works.

All ports have been updated to work with this modified scheme.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 16:24:46 +11:00
Damien George 60929ec7e2 extmod/machine_wdt: Factor ports' WDT Python bindings to common code.
There are currently 7 ports that implement machine.WDT and a lot of code is
duplicated across these implementations.  This commit factors the common
parts of all these implementations to a single location in
extmod/machine_wdt.c.  This common code provides the top-level Python
bindings (class and method wrappers), and then each port implements the
back end specific to that port.

With this refactor the ports remain functionally the same except for:

- The esp8266 WDT constructor now takes keyword arguments, and accepts the
  "timeout" argument but raises an exception if it's not the default value
  (this port doesn't support changing the timeout).

- The mimxrt and samd ports now interpret the argument to WDT.timeout_ms()
  as signed and if it's negative truncate it to the minimum timeout (rather
  than it being unsigned and a negative value truncating to the maximum
  timeout).

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 15:36:09 +11:00
robert-hh 47fa723586 samd/modmachine: Make some machine classes configurable by #defines.
These include ADC, DAC, I2C, SoftI2C, SPI, SoftI2C, PWM, UART, pulse.  This
is useful for devices like the Adafruit Trinket series which have almost no
accessible GPIO pins.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:39:07 +10:00
robert-hh 05bb26010e samd: Always provide the machine.RTC class.
Even if boards do not have a clock crystal.  In that case, the clock
quality will be very poor.

Always having machine.RTC means that the date/time can be set in a way that
is consistent with other ports.

This commit also removes the special code in modutime.c for devices without
the RTC class.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-13 12:44:34 +11:00
robert-hh 17ab2f671b samd: Support entering bootloader via USB CDC 1200bps touch. 2022-12-14 12:50:04 +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 fc9d66fac6 samd/machine_rtc: Add the machine.RTC class.
Methods implemented are:
- rtc.init(date)
- rtc.datetime([new_date])
- rtc.calibration(value)

The presence of this class can be controlled by MICROPY_PY_MACHINE_RTC.  If
the RTC module is used, the time module uses the RTC as well.

For boards without a 32kHz crystal, using RTC makes no sense, since it will
then use the ULP32K oscillator, which is not precise at all.  Therefore, it
will by default only be enabled for boards using a crystal, but can be
enabled in the respective mpconfigboard.h.
2022-10-25 23:20:09 +11:00
iabdalkader e275a58ac1 samd: Rename machine I2C type consistently across ports.
This renames:
- machine_hw_i2c_type -> machine_i2c_type
2022-10-22 12:57:32 +11:00
robert-hh f5da77b5ce samd/machine_dac: Add the machine.DAC class.
It suuports 1 channel @ 10 bit for SAMD21, 2 channels @ 12 bit for SAMD51.

Instantiation by:

    dac = machine.DAC(ch) # 0 or 1

Method write:

    dac.write(value)

The output voltage range is 0..Vdd.
2022-10-06 22:55:10 +11:00
robert-hh 7a2f2d88f7 samd/machine_wdt: Add the machine.WDT class. 2022-10-06 22:53:06 +11:00
robert-hh 32c973d554 samd/machine_timer: Add machine.Timer based on the shared soft-timer. 2022-10-06 22:52:39 +11:00
robert-hh 94d27ae28f samd/machine_i2c: Add the machine.I2C class.
Using the common API.  Tested with SAMD21 and SAMD51 boards.
2022-10-06 22:49:06 +11:00
robert-hh aa870708ac samd/machine_spi: Add the machine.SPI class.
Suported by both SAMD21 and SAMD51.  It follows the generic API, except for
the bits=nn option, which is not implemented (yet).
2022-10-06 22:48:44 +11:00
robert-hh b33f204529 samd/machine_uart: Add the machine.UART class.
All board pins that have UART's assigned can be used.  Baud rate range is
75 Baud to ~2 MBaud.

No flow control yet, and only RX is buffered.  TX buffer and flow control
may be added later for SAMD51 with its larger RAM and Flash.
2022-10-06 22:48:12 +11:00
robert-hh d693758ab2 samd/machine_pwm: Add the machine.PWM class.
Features are:
- 3 to 5 different frequency groups.
- Freq range of 1Hz - 24 MHz.
- Duty rate stays stable on freq change.

Keyword options to the PWM constructor:
- device=n Select a specific PWM device.  If no device is specified, a free
           device is chosen, if available at that pin.
- freq=nnnn
- duty_u16=nnnn
- duty_ns=nnnn
- invert=True/False Allowing two outputs on the same device/channel to have
                    complementary signals.

If both freq and duty are provided, PWM output will start immediately.

Pins at the same device have the same frequency.  If the PWM output number
exceeds the number of channels at the PWM device, the effctive channel_no
is output_no % channel_count.  So with a channel count of 4, output 7 is
assigned to channel 3.  Pins at a certain channel have the same frequency
and duty rate, but may be seperately inverted.
2022-10-06 22:42:55 +11:00
robert-hh 5c7e93ec48 samd/machine_adc: Add the machine.ADC class.
With the method read_u16().  Keyword arguments of the constructor are:
- bits=n    The resolution; default is 12.
- average=n The average of samples, which are taken and cumulated.  The
            default value is 16.  Averaging by hw is faster than averaging
            in code.

The ADC runs at a clock freq 1.5 MHz.  A single 12 bit conversion takes
8 microseconds.
2022-10-06 22:41:44 +11:00
robert-hh 85afed569d samd: Remove the existing provisional support for REPL on UART.
It was only partially working and will be rpelaced later by a full
machine.UART class implementation.
2022-10-06 22:29:06 +11:00
Peter van der Burg 2f65ded1a2 samd: Add Pin and LED classes, and machine.unique_id. 2021-11-19 11:43:06 +11:00