Wykres commitów

23 Commity (master)

Autor SHA1 Wiadomość Data
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 f2f3ef162d extmod/machine_i2s: Factor ports' I2S Python bindings to common code.
This factors the basic top-level I2S class code from the ports into
extmod/machine_i2s.c:
- I2S class definition and method table.
- The init and deinit method wrappers.
- The make_new code.

Further factoring will follow.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 17:39:57 +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
Kwabena W. Agyeman e78471416b mimxrt/modmachine: Add support for machine.deepsleep.
Signed-off-by: "Kwabena W. Agyeman" <kwagyeman@live.com>
2023-10-17 22:52:18 +11:00
Kwabena W. Agyeman 433158076f mimxrt/machine_rtc: Add RTC alarm/wakeup functionality.
Following the documented Python machine.RTC API.

Signed-off-by: "Kwabena W. Agyeman" <kwagyeman@live.com>
2023-10-17 22:51:53 +11:00
robert-hh 297892c4f4 mimxrt/machine_uart: Add a helper function to change the baudrate.
And use it in the Bluetooth bindings instead of setting the baudrate by a
call to the NXP lib.

Also fixes machine_uart.c to work with a baud rate of 921600.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-09-05 10:54:49 +10:00
robert-hh e43c669b4a mimxrt/machine_uart: Add uart.deinit method and machine_uart_deinit_all.
The call to machine_uart_deinit_all() is needed to avoid a crash after soft
reset, if a UART had been used and data arrives before it is instantiated
again.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-08-15 23:08:30 +10:00
robert-hh b70b8ce3e4 mimxrt/machine_rtc: Start RTC at boot and set datetime if not set.
Changes in this commit:
- Start the RTC Timer at system boot.  Otherwise time.time() will advance
  only if an RTC() object was created.
- Set the time to a more recent date than Jan 1, 1970, if not set.  That is
  2013/10/14, 19:53:11, MicroPython's first commit.
- Compensate an underflow in in timeutils_seconds_since_2000(), called by
  time.time(), if the time is set to a pre-2000 date.
2022-04-11 12:25:23 +10:00
MikeTeachman 1f6cb8f047 mixmrt/machine_i2s: Add I2S protocol support.
This commit adds support for machine.I2S on the mimxrt port.  The I2S API
is consistent with the existing stm32, esp32, and rp2 implementations.

I2S features:
- controller transmit and controller receive
- 16-bit and 32-bit sample sizes
- mono and stereo formats
- sampling frequencies from 8kHz to 48kHz
- 3 modes of operation:
  - blocking
  - non-blocking with callback
  - uasyncio
- configurable internal buffer
- optional MCK

Tested with the following development boards:
- MIMXRT1010_EVK, MIMXRT1015_EVK, MIMXRT1020_EVK, MIMXRT1050_EVK
- Teensy 4.0, Teensy 4.1
- Olimex RT1010
- Seeed ARCH MIX

Tested with the following I2S hardware peripherals:
- UDA1334
- GY-SPH0645LM4H
- WM8960 codec on board the MIMXRT boards and separate breakout board
- INMP441
- PCM5102
- SGTL5000 on the Teensy audio shield

Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
2022-03-30 14:12:40 +11:00
robert-hh 81f706aee4 mimxrt: Support PWM using the FLEXPWM and QTMR modules.
Frequency range 15Hz/18Hz to > 1 MHz, with decreasing resolution of the
duty cycle.  The basic API is supported as documentated, except that
keyword parameters are accepted for both the instatiaton and the
PWM.init() call.

Extensions: support PWM for channel pairs.  Channel pairs are declared by
supplying 2-element tuples for the pins.  The two channels of a pair must
be the A/B channel of a FLEXPWM module.  These form than a complementary
pair.

Additional supported keyword arguments:

- center=value Defines the center position of a pulse within the pulse
  cycle.  The align keyword is actually shortcut for center.

- sync=True|False: If set to True, the channels will be synchronized to a
  submodule 0 channel, which has already to be enabled.

- align=PWM.MIDDLE | PMW.BEGIN | PWM.END. It defines, whether synchronized
  channels are Center-Aligned or Edge-aligned.  The channels must be either
  complementary a channel pair or a group of synchronized channels.  It may
  as well be applied to a single channel, but withiout any benefit.

- invert= 0..3. Controls ouput inversion of the pins.  Bit 0 controls the
  first pin, bit 1 the second.

- deadtime=time_ns time of complementary channels for delaying the rising
  slope.

- xor=0|1|2 xor causes the output of channel A and B to be xored.  If
  applied to a X channel, it shows the value oif A ^ B.  If applied to an A
  or B channel, both channel show the xored signal for xor=1.  For xor=2,
  the xored signal is split between channels A and B.  See also the
  Reference Manual, chapter about double pulses.  The behavior of xor=2 can
  also be achieved using the center method for locating a pulse within a
  clock period.

The output is enabled for board pins only.

CPU pins may still be used for FLEXPWM, e.g. as sync source, but the signal
will not be routed to the output.  That applies only to FLEXPWM pins.  The
use of QTMR pins which are not board pins will be rejected.

As part of this commit, the _WFE() statement is removed from
ticks_delay_us64() to prevent PWM glitching during calls to sleep().
2021-11-24 13:48:27 +11:00
robert-hh c2e4759cfa mimxrt/modmachine: Implement machine.WDT() and machine.reset_cause().
The API follows that of rp2, stm32, esp32, and the docs.

    wdt=machine.WDT(0, timeout)

        Timeout is given in ms. The valid range is 500 to 128000 (128
        seconds) with 500 ms granularity. Values outside of that range will
        be silently aligned.

    wdt.feed()

        Resets the watchdog timer (feeding).

    wdt.timeout_ms(value)

        Sets a new timeout and feeds the watchdog.

        This is a new, preliminary method which is not yet documented.

    reset_cause = machine.reset_cause()

        Values returned:

        1  Power On reset
        3  Watchdog reset
        5  Software reset: state after calling machine.reset()

More elaborate API functions are supported by the MCU, like an interrupt
called a certain time after feeding.  But for port cosistency that is not
implemented.
2021-10-25 15:43:56 +11:00
Philipp Ebensberger 7e62c9707a mimxrt/sdram: Add SDRAM support.
Adds support for SDRAM via `SEMC` peripheral. SDRAM support can be
enabled in the mpconfigboard.mk file by setting `MICROPY_HW_SDRAM_AVAIL`
to `1` and poviding the size of the RAM via `MICROPY_HW_FLASH_SIZE`.

When SDRAM support is enabled the whole SDRAM is currently used used
for MicroPython heap.

Signed-off-by: Philipp Ebensberger
2021-10-22 08:23:24 +02:00
Philipp Ebensberger 87f97e490c mimxrt/sdcard: Implement SDCard driver.
- Configures `PLL2->PFD0` with **198MHz** as base clock of
	`USDHCx` peripheral.
- Adds guards for SDCard related files via `MICROPY_PY_MACHINE_SDCARD`
- Adds creation of pin defines for SDCard to make-pins.py
- Adds new configuration option for SDCard peripheral pinout
        to mpconfigport.h
- Adds interrupt handling support instead of polling
- Adds support for `ADMA2` powered data transfer
- Configures SDCard to run in HS (high-speed mode) with **50MHz** only!

SDCard support is optional and requires `USDHC` peripheral.
Thus this driver is not available on `MIMXRT1010_EVK`.
SDCard support is enabled by setting `MICROPY_PY_MACHINE_SDCARD = 1`
in mpconfigboard.mk.

Signed-off-by: Philipp Ebensberger
2021-09-07 20:45:33 +02:00
robert-hh 98c5703027 mimxrt/machine_i2c: Add hardware-based machine.I2C to machine module.
It uses non-blocking transfer of data.  Advantage over SoftI2C:
- Higher data rate up to ~3 MHZ.
- Full protocol support.
2021-07-15 00:36:31 +10:00
robert-hh f45412793e mimxrt/machine_spi: Add the SPI class to the machine module.
This class supports SPI bus controller mode, with blocking transfers.

SPI device numbers start at 0, to comply with the pinout of the Teensy
boards.  With the configured clock frequency the fastest baud rate is
33MHz.  For messages longer 16 bytes DMA is used.  The class uses the
existing framework with extmod/machine_spi.c.

Extended driver options:

- drive=n with n being between 1 and 6 or PIN.POWER_1 to PIN.POWER_6.
  Since the pins used by the SPI are fixed, no Pin settings can be made.
  Thus the drive option is added allowing to control ringing and crosstalk
  on the connection.

- gap_ns=nnnnn is the time between sent data items in a frame given in ns.
  Default is 2 clock cycles.
2021-06-26 22:14:47 +10:00
robert-hh 7417c6ac91 mimxrt/machine_pin: Implement pin.irq() functionality. 2021-06-16 01:42:10 +10:00
robert-hh 689476c576 mimxrt/machine_uart: Add the UART class to the machine module.
The implementation uses the LPUARTx devices.  Up to 8 UARTs can be used,
given that the pins are accessible.  E.g. 8 on Teensy 4.1, 5 on
MIMXRT1020_EVK.

For Tennsy 4.0 and 4.1 the UART numbers are as printed on the pinout 1..N.
The MIMXRT10xx-EVK boards have only one UART named, which gets the number
1.  All other UART are assigned to different Pins:

MIMXRT1010-EVK:
    D0/D1   UART 1
    D6/D7   UART 2
    A0/D4   UART 3

MIMXRT1020-EVK:
    D0/D1   UART 1
    D6/D9   UART 2
    D10/D12 UART 3
    D14/D15 UART 4
    A0/A1   UART 5

MIMXRT1050-EVK, MIMXRT1060-EVK, MIMXRT1064-EVK:
    D0/D1   UART 1
    D7/D6   UART 2
    D8/D9   UART 3
    A1/A0   UART 4
2021-06-16 01:21:15 +10:00
Philipp Ebensberger b8c65b174f mimxrt/machine_adc: Add the ADC class to the machine module.
This adds the machine.ADC class with the read_u16() method.  make-pins.py
and supporting files are updated to generate ADC information.
2021-06-04 00:51:58 +10:00
robert-hh 2f365d234e mimxrt/machine_rtc: Add the RTC class to the machine module.
Initial version, using the LP RTC clock.  It provides setting the date and
time with rtc.init() or rtc.datetime(), and reading the date and time with
rtc.datetime() or rtc.now().  The method weekday() reports the weekday of
the current date.  It starts with 0 for Monday.

The tuple order for datetime() and now() matches the CPython sequence:
(year, month, day, hour, minute, second, microsecond, TZ).  TZ is ignored
and reported as None.  Microsecond is provided at a best effort.

If a battery is not supplied, the default boot date/time is 1970/1/1 0:0:0.
With a battery, the clock continues to run even when the board is not
powered.  The clock is quite precise.  If not, using rtc.calibration() may
help.
2021-06-03 15:24:04 +10:00
robert-hh 4c407c790f mimxrt: Add the Timer class to the machine module.
It supports three hardware timer channels based on the PIT timers of the
MIMXRT MCU.  The timer id's are 0, 1 and 2.  On soft reboot all active
timers will be stopped via finalisers.
2021-06-02 00:33:13 +10:00