Commit Graph

35 Commits

Author SHA1 Message Date
Jim Mussared
2eba98f1e0 all: Use MP_REGISTER_EXTENSIBLE_MODULE for overrideable built-ins.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:21 +10:00
Jim Mussared
7f5d5c7271 all: Rename mod_umodule*, ^umodule* to remove the "u" prefix.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:07 +10:00
Jim Mussared
30628d1bb7 all: Rename MP_QSTR_umodule to MP_QSTR_module everywhere.
This renames the builtin-modules, such that help('modules') and printing
the module object will show "module" rather than "umodule".

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:53:57 +10: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
b2df094bf8 samd/modmachine: Add machine.deepsleep as alias of machine.lightsleep.
Just for coverage.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-05-22 18:38:51 +10:00
robert-hh
17ab2f671b samd: Support entering bootloader via USB CDC 1200bps touch. 2022-12-14 12:50:04 +11:00
robert-hh
fcccfc176b samd/modmachine: Add machine.softreset().
For consistency with other ports.
2022-10-25 23:49:52 +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
robert-hh
f0399d35e4 samd/modmachine: Get the bootloader magic address from the lib.
Instead of being hard-coded, and then it works for all MCUs.

That fits except for a Sparkfun SAMD51 Thing Plus (known) bug, which uses
192k - 4 as magic address.  Therefore, that address is set as well to avoid
a problem when this bug is fixed by Sparkfun.
2022-10-25 23:09:04 +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
a7113e95d7 samd/modmachine: Add machine.dht_readinto and enable on SAMD51. 2022-10-25 23:06:44 +11:00
robert-hh
64e3c351de samd/modmachine: Add machine.reset_cause(). 2022-10-25 22:41:31 +11:00
robert-hh
1c32cec7f1 samd/clock_config: Support changing machine.freq() for SAMD21.
The range is 1MHz - 48 MHz.  Note that below 8 MHz there is no USB support.
The frequency will be set to an integer fraction of 48 MHz.  And after
changing the frequency, the peripherals like PWM, UART, I2C, SPI have to be
reconfigured.

Current consumption e.g. of the Seeed Xiao board at 1 MHz is about 1.5 mA,
mostly caused by the on-board LED (green LED with 1k resistor at 3.3V).
2022-10-25 22:40:16 +11:00
robert-hh
edc3f3d0d3 samd/clock_config: Extend the range of machine.freq().
The value given for machine.freq(f) is extend to the range of 1_000_000 to
200_000_000.  Frequencies below 48 MHz will be forced to an integer
fraction of 48 MHz.  At frequencies below 8 MHz USB is switched off.  The
power consumption e.g. of ADAFRUIT_ITSYBITSY_M4_EXPRESS drops to about
1.5 mA at 1 MHz.

Since the peripheral frequency is dropped as well, timing e.g. of PWM,
UART, I2C and SPI is affected and frequency/baud rate has to set again
after a frequency change below 48 MHz.
2022-10-25 22:38:45 +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
a415752173 samd/machine_bitstream: Add the machine.bitstream() function.
The SAMD21 implementation is an adaption of @jimmo's code for STM32Lxx.
The only changes are the addresses and names of the port registers and the
timing parameters.

SAMD21: The precision is about +/-25ns at 48MHz clock frequency.  The first
two cycles are about 40-60 ns longer than set.  But still good enough to
drive a neopixel device.

SAMD51: The precision is about +/-30ns at 120MHz clock frequency.  Good
enough to drive a neopixel device.
2022-10-06 23:00:00 +11:00
robert-hh
029e9af457 samd/modmachine: Add machine.time_pulse_us.
Software based. Resolution:
- +/-2 microseconds on SAMD51.
- +/-4 microseconds on SAMD21.
2022-10-06 22:55:45 +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
7d281f6165 samd/modmachine: Add disable_irq(), enable_irq() and idle() to machine.
No specific features.
2022-10-06 22:47:52 +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
4013577af2 samd/modmachine: Enable SoftSPI and SoftI2C. 2022-10-06 22:38:33 +11:00
robert-hh
5af54ad61f samd/modmachine: Allow changing the CPU freq with machine.freq(f).
SAMD51 only.  Accepted values are 48_000_000 to 200_000_000.  The range
specified by Atmel is 96_000_000 to 120_000_000.
2022-10-06 22:34:42 +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
Damien George
efe23aca71 all: Remove third argument to MP_REGISTER_MODULE.
It's no longer needed because this macro is now processed after
preprocessing the source code via cpp (in the qstr extraction stage), which
means unused MP_REGISTER_MODULE's are filtered out by the preprocessor.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-02 16:31:37 +10:00
Jim Mussared
4eab44a1ec extmod: Make extmod modules use MP_REGISTER_MODULE.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-18 20:49:12 +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
Damien George
69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Damien George
5f9bd11527 samd: Add new port to Microchip SAMDxx microcontrollers.
Initially supporting SAMD21 and SAMD51.
2019-07-01 17:19:18 +10:00