mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
ports: Add SoftI2C and SoftSPI to machine module where appropriate.
Previous commits removed the ability for one I2C/SPI constructor to
construct both software- or hardware-based peripheral instances. Such
construction is now split to explicit soft and non-soft types.
This commit makes both types available in all ports that previously could
create both software and hardware peripherals: machine.I2C and machine.SPI
construct hardware instances, while machine.SoftI2C and machine.SoftSPI
create software instances.
This is a breaking change for use of software-based I2C and SPI. Code that
constructed I2C/SPI peripherals in the following way will need to be
changed:
machine.I2C(-1, ...) -> machine.SoftI2C(...)
machine.I2C(scl=scl, sda=sda) -> machine.SoftI2C(scl=scl, sda=sda)
machine.SPI(-1, ...) -> machine.SoftSPI(...)
machine.SPI(sck=sck, mosi=mosi, miso=miso)
-> machine.SoftSPI(sck=sck, mosi=mosi, miso=miso)
Code which uses machine.I2C and machine.SPI classes to access hardware
peripherals does not need to change.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "py/mphal.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "extmod/machine_i2c.h"
|
||||
#include "modmachine.h"
|
||||
|
||||
#include "driver/i2c.h"
|
||||
|
||||
@@ -45,7 +46,6 @@ typedef struct _machine_hw_i2c_obj_t {
|
||||
gpio_num_t sda : 8;
|
||||
} machine_hw_i2c_obj_t;
|
||||
|
||||
STATIC const mp_obj_type_t machine_hw_i2c_type;
|
||||
STATIC machine_hw_i2c_obj_t machine_hw_i2c_obj[I2C_NUM_MAX];
|
||||
|
||||
STATIC void machine_hw_i2c_init(machine_hw_i2c_obj_t *self, uint32_t freq, uint32_t timeout_us, bool first_init) {
|
||||
@@ -169,7 +169,7 @@ STATIC const mp_machine_i2c_p_t machine_hw_i2c_p = {
|
||||
.transfer = machine_hw_i2c_transfer,
|
||||
};
|
||||
|
||||
STATIC const mp_obj_type_t machine_hw_i2c_type = {
|
||||
const mp_obj_type_t machine_hw_i2c_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_I2C,
|
||||
.print = machine_hw_i2c_print,
|
||||
|
||||
Reference in New Issue
Block a user