bbcmicrobit / bbcmicrobit/micropython

Setting parameters consistency

Open
#306 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C
Stars
646
Forks
290
PR merge metrics
No merged PRs in 30d

Description

I've opened this issue to continue a general discussion initiated in a Pull Request, that would probably have much broader effect.

We currently have `init()` methods for the SPI and UART modules, but not for the I2C. Apart from that there are other modules like the accelerometer or compass that could be configured using a similar pattern, but at the moment have different accessors for these properties.

Quoting @dpgeorge:

> I think we need to have a broader discussion wrt setting parameters, to make sure things are consistent. Things that are configurable are:
>
> GPIO: set pull (see #304), set analog period
> I2C: set frequency (see #296), change scl/sda pins
> SPI: phase, polarity, clock speed, bits, sck/mosi/miso pins
> UART: baudrate, bits, stop bit, parity, tx/rx pins
> accelerometer: set rate, range (see #266)
> compass: set sample rate
> radio: set freq, channel, address, etc (see #283)
>
> It might make sense for some of these parameters to also have a "get", but probably not all of them.
>
> Currently UART and SPI have an init() method that works as follows: the device starts up in a default mode (eg UART is used for the REPL) and calling init() is used to completely re-initialise the device. Any parameters that are passed are used, but any parameters that are not specified will take their default values.
>
> One way to proceed is provide a generic config() method that takes keyword arguments to set a value, eg i2c.config(freq=100000); accel.config(range=8). You could get the value using i2c.config('freq').
>
> Another way is to provide an individual method for each value to set (and perhaps get), eg i2c.set_freq(100000); accel.set_range(8).

Current PRs that could be affected by this are:
- Radio module https://github.com/bbcmicrobit/micropython/pull/283
- I2C frequency https://github.com/bbcmicrobit/micropython/pull/296
- Accelerometer rate and range https://github.com/bbcmicrobit/micropython/pull/266
- GPIO set pull https://github.com/bbcmicrobit/micropython/pull/304

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.