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:
@@ -37,8 +37,7 @@
|
||||
#include "py/mphal.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "extmod/machine_i2c.h"
|
||||
|
||||
STATIC const mp_obj_type_t machine_hard_i2c_type;
|
||||
#include "modmachine.h"
|
||||
|
||||
typedef struct _machine_hard_i2c_obj_t {
|
||||
mp_obj_base_t base;
|
||||
@@ -127,7 +126,7 @@ STATIC const mp_machine_i2c_p_t machine_hard_i2c_p = {
|
||||
.transfer_single = machine_hard_i2c_transfer_single,
|
||||
};
|
||||
|
||||
STATIC const mp_obj_type_t machine_hard_i2c_type = {
|
||||
const mp_obj_type_t machine_hard_i2c_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_I2C,
|
||||
.print = machine_hard_i2c_print,
|
||||
|
||||
@@ -60,7 +60,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&mp_machine_soft_i2c_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_hard_i2c_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) },
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "py/obj.h"
|
||||
|
||||
extern const mp_obj_type_t machine_pin_type;
|
||||
extern const mp_obj_type_t machine_hard_i2c_type;
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ_0(machine_info_obj);
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@ static inline uint64_t mp_hal_time_ns(void) {
|
||||
}
|
||||
|
||||
#define mp_hal_delay_us_fast(us) (mp_hal_delay_us(us))
|
||||
|
||||
// C-level pin API is not currently implemented
|
||||
#define MP_HAL_PIN_FMT "%d"
|
||||
#define mp_hal_pin_name(p) (0)
|
||||
#define mp_hal_pin_od_low(p) (mp_raise_NotImplementedError("mp_hal_pin_od_low"))
|
||||
#define mp_hal_pin_od_high(p) (mp_raise_NotImplementedError("mp_hal_pin_od_high"))
|
||||
#define mp_hal_pin_open_drain(p) (mp_raise_NotImplementedError("mp_hal_pin_open_drain"))
|
||||
|
||||
Reference in New Issue
Block a user