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>
The PWM.init() method has been added. Calling init() without arguments
restarts a PWM channel stopped with deinit(). Otherwise single parameters
except for "device=n" can be changed again. The device can only be
specified once, either in the constructor or the first init() call.
Also simplify get_pwm_config() and get_adc_config(), and shrink the PWM
object.
Any update of freq or duty_cycle requires the previous PWM cycle to be
finished. Otherwise the new settings are not accepted.
Other changes in this commit:
- Report the set duty cycles even when the PWM is not yet started.
- pwm.freq(0) stops the pwm device, instead of raising an expception.
- Clear the duty cycle value cache on soft reset.
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.
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.