Renamed to adafruit_bus_device
This commit is contained in:
parent
197539bd82
commit
4c93db3595
@ -134,7 +134,7 @@ ifeq ($(CIRCUITPY_BOARD),1)
|
||||
SRC_PATTERNS += board/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_BUSDEVICE),1)
|
||||
SRC_PATTERNS += busdevice/%
|
||||
SRC_PATTERNS += adafruit_bus_device/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_BUSIO),1)
|
||||
SRC_PATTERNS += busio/% bitbangio/OneWire.%
|
||||
@ -435,9 +435,9 @@ SRC_SHARED_MODULE_ALL = \
|
||||
bitbangio/SPI.c \
|
||||
bitbangio/__init__.c \
|
||||
board/__init__.c \
|
||||
busdevice/__init__.c \
|
||||
busdevice/I2CDevice.c \
|
||||
busdevice/SPIDevice.c \
|
||||
adafruit_bus_device/__init__.c \
|
||||
adafruit_bus_device/I2CDevice.c \
|
||||
adafruit_bus_device/SPIDevice.c \
|
||||
busio/OneWire.c \
|
||||
displayio/Bitmap.c \
|
||||
displayio/ColorConverter.c \
|
||||
|
@ -325,8 +325,8 @@ extern const struct _mp_obj_module_t board_module;
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_BUSDEVICE
|
||||
extern const struct _mp_obj_module_t busdevice_module;
|
||||
#define BUSDEVICE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_busdevice), (mp_obj_t)&busdevice_module },
|
||||
extern const struct _mp_obj_module_t adafruit_bus_device_module;
|
||||
#define BUSDEVICE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_adafruit_bus_device), (mp_obj_t)&adafruit_bus_device_module },
|
||||
#else
|
||||
#define BUSDEVICE_MODULE
|
||||
#endif
|
||||
|
@ -90,7 +90,7 @@ CFLAGS += -DCIRCUITPY_BLEIO=$(CIRCUITPY_BLEIO)
|
||||
CIRCUITPY_BOARD ?= 1
|
||||
CFLAGS += -DCIRCUITPY_BOARD=$(CIRCUITPY_BOARD)
|
||||
|
||||
CIRCUITPY_BUSDEVICE ?= 1
|
||||
CIRCUITPY_BUSDEVICE ?= $(CIRCUITPY_FULL_BUILD)
|
||||
CFLAGS += -DCIRCUITPY_BUSDEVICE=$(CIRCUITPY_BUSDEVICE)
|
||||
|
||||
CIRCUITPY_BUSIO ?= 1
|
||||
|
@ -28,9 +28,9 @@
|
||||
// busio.I2C class.
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/busdevice/I2CDevice.h"
|
||||
#include "shared-bindings/adafruit_bus_device/I2CDevice.h"
|
||||
#include "shared-bindings/util.h"
|
||||
#include "shared-module/busdevice/I2CDevice.h"
|
||||
#include "shared-module/adafruit_bus_device/I2CDevice.h"
|
||||
|
||||
#include "lib/utils/buffer_helper.h"
|
||||
#include "lib/utils/context_manager_helpers.h"
|
||||
@ -64,9 +64,9 @@
|
||||
//| device.write(bytes_read)"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busdevice_i2cdevice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
busdevice_i2cdevice_obj_t *self = m_new_obj(busdevice_i2cdevice_obj_t);
|
||||
self->base.type = &busdevice_i2cdevice_type;
|
||||
STATIC mp_obj_t adafruit_bus_device_i2cdevice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
adafruit_bus_device_i2cdevice_obj_t *self = m_new_obj(adafruit_bus_device_i2cdevice_obj_t);
|
||||
self->base.type = &adafruit_bus_device_i2cdevice_type;
|
||||
enum { ARG_i2c, ARG_device_address, ARG_probe };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
@ -78,9 +78,9 @@ STATIC mp_obj_t busdevice_i2cdevice_make_new(const mp_obj_type_t *type, size_t n
|
||||
|
||||
busio_i2c_obj_t* i2c = args[ARG_i2c].u_obj;
|
||||
|
||||
common_hal_busdevice_i2cdevice_construct(MP_OBJ_TO_PTR(self), i2c, args[ARG_device_address].u_int);
|
||||
common_hal_adafruit_bus_device_i2cdevice_construct(MP_OBJ_TO_PTR(self), i2c, args[ARG_device_address].u_int);
|
||||
if (args[ARG_probe].u_bool == true) {
|
||||
common_hal_busdevice_i2cdevice_probe_for_device(self);
|
||||
common_hal_adafruit_bus_device_i2cdevice_probe_for_device(self);
|
||||
}
|
||||
|
||||
return (mp_obj_t)self;
|
||||
@ -90,22 +90,22 @@ STATIC mp_obj_t busdevice_i2cdevice_make_new(const mp_obj_type_t *type, size_t n
|
||||
//| """Context manager entry to lock bus."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busdevice_i2cdevice_obj___enter__(mp_obj_t self_in) {
|
||||
busdevice_i2cdevice_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_busdevice_i2cdevice_lock(self);
|
||||
STATIC mp_obj_t adafruit_bus_device_i2cdevice_obj___enter__(mp_obj_t self_in) {
|
||||
adafruit_bus_device_i2cdevice_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_adafruit_bus_device_i2cdevice_lock(self);
|
||||
return self;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(busdevice_i2cdevice___enter___obj, busdevice_i2cdevice_obj___enter__);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adafruit_bus_device_i2cdevice___enter___obj, adafruit_bus_device_i2cdevice_obj___enter__);
|
||||
|
||||
//| def __exit__(self) -> None:
|
||||
//| """Automatically unlocks the bus on exit."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busdevice_i2cdevice_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
common_hal_busdevice_i2cdevice_unlock(MP_OBJ_TO_PTR(args[0]));
|
||||
STATIC mp_obj_t adafruit_bus_device_i2cdevice_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
common_hal_adafruit_bus_device_i2cdevice_unlock(MP_OBJ_TO_PTR(args[0]));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busdevice_i2cdevice___exit___obj, 4, 4, busdevice_i2cdevice_obj___exit__);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(adafruit_bus_device_i2cdevice___exit___obj, 4, 4, adafruit_bus_device_i2cdevice_obj___exit__);
|
||||
|
||||
//| def readinto(self, buf, *, start=0, end=None) -> None:
|
||||
//| """
|
||||
@ -119,7 +119,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busdevice_i2cdevice___exit___obj, 4,
|
||||
//| :param int end: Index to write up to but not include; if None, use ``len(buf)``"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC void readinto(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end) {
|
||||
STATIC void readinto(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_WRITE);
|
||||
|
||||
@ -129,13 +129,13 @@ STATIC void readinto(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t s
|
||||
mp_raise_ValueError(translate("Buffer must be at least length 1"));
|
||||
}
|
||||
|
||||
uint8_t status = common_hal_busdevice_i2cdevice_readinto(MP_OBJ_TO_PTR(self), ((uint8_t*)bufinfo.buf) + start, length);
|
||||
uint8_t status = common_hal_adafruit_bus_device_i2cdevice_readinto(MP_OBJ_TO_PTR(self), ((uint8_t*)bufinfo.buf) + start, length);
|
||||
if (status != 0) {
|
||||
mp_raise_OSError(status);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t busdevice_i2cdevice_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC mp_obj_t adafruit_bus_device_i2cdevice_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_buffer, ARG_start, ARG_end };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
@ -143,7 +143,7 @@ STATIC mp_obj_t busdevice_i2cdevice_readinto(size_t n_args, const mp_obj_t *pos_
|
||||
{ MP_QSTR_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} },
|
||||
};
|
||||
|
||||
busdevice_i2cdevice_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
adafruit_bus_device_i2cdevice_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
@ -151,7 +151,7 @@ STATIC mp_obj_t busdevice_i2cdevice_readinto(size_t n_args, const mp_obj_t *pos_
|
||||
readinto(self, args[ARG_buffer].u_obj, args[ARG_start].u_int, args[ARG_end].u_int);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busdevice_i2cdevice_readinto_obj, 2, busdevice_i2cdevice_readinto);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_readinto_obj, 2, adafruit_bus_device_i2cdevice_readinto);
|
||||
|
||||
//| def write(self, buf, *, start=0, end=None) -> None:
|
||||
//| """
|
||||
@ -165,7 +165,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busdevice_i2cdevice_readinto_obj, 2, busdevice
|
||||
//| """
|
||||
//| ...
|
||||
//|
|
||||
STATIC void write(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end) {
|
||||
STATIC void write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t start, mp_int_t end) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_READ);
|
||||
|
||||
@ -175,20 +175,20 @@ STATIC void write(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, int32_t star
|
||||
mp_raise_ValueError(translate("Buffer must be at least length 1"));
|
||||
}
|
||||
|
||||
uint8_t status = common_hal_busdevice_i2cdevice_write(MP_OBJ_TO_PTR(self), ((uint8_t*)bufinfo.buf) + start, length);
|
||||
uint8_t status = common_hal_adafruit_bus_device_i2cdevice_write(MP_OBJ_TO_PTR(self), ((uint8_t*)bufinfo.buf) + start, length);
|
||||
if (status != 0) {
|
||||
mp_raise_OSError(status);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t busdevice_i2cdevice_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC mp_obj_t adafruit_bus_device_i2cdevice_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_buffer, ARG_start, ARG_end };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_start, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} },
|
||||
};
|
||||
busdevice_i2cdevice_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
adafruit_bus_device_i2cdevice_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
@ -196,7 +196,7 @@ STATIC mp_obj_t busdevice_i2cdevice_write(size_t n_args, const mp_obj_t *pos_arg
|
||||
write(self, args[ARG_buffer].u_obj, args[ARG_start].u_int, args[ARG_end].u_int);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(busdevice_i2cdevice_write_obj, 2, busdevice_i2cdevice_write);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 2, adafruit_bus_device_i2cdevice_write);
|
||||
|
||||
|
||||
//| def write_then_readinto(self, out_buffer, in_buffer, *, out_start=0, out_end=None, in_start=0, in_end=None) -> None:
|
||||
@ -221,7 +221,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busdevice_i2cdevice_write_obj, 2, busdevice_i2cdevice
|
||||
//| """
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busdevice_i2cdevice_write_then_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC mp_obj_t adafruit_bus_device_i2cdevice_write_then_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_out_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
@ -231,7 +231,7 @@ STATIC mp_obj_t busdevice_i2cdevice_write_then_readinto(size_t n_args, const mp_
|
||||
{ MP_QSTR_in_start, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_in_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} },
|
||||
};
|
||||
busdevice_i2cdevice_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
adafruit_bus_device_i2cdevice_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
@ -242,21 +242,21 @@ STATIC mp_obj_t busdevice_i2cdevice_write_then_readinto(size_t n_args, const mp_
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(busdevice_i2cdevice_write_then_readinto_obj, 3, busdevice_i2cdevice_write_then_readinto);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_then_readinto_obj, 3, adafruit_bus_device_i2cdevice_write_then_readinto);
|
||||
|
||||
STATIC const mp_rom_map_elem_t busdevice_i2cdevice_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&busdevice_i2cdevice___enter___obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&busdevice_i2cdevice___exit___obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&busdevice_i2cdevice_readinto_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&busdevice_i2cdevice_write_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_write_then_readinto), MP_ROM_PTR(&busdevice_i2cdevice_write_then_readinto_obj) },
|
||||
STATIC const mp_rom_map_elem_t adafruit_bus_device_i2cdevice_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&adafruit_bus_device_i2cdevice___enter___obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&adafruit_bus_device_i2cdevice___exit___obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&adafruit_bus_device_i2cdevice_readinto_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&adafruit_bus_device_i2cdevice_write_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_write_then_readinto), MP_ROM_PTR(&adafruit_bus_device_i2cdevice_write_then_readinto_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(busdevice_i2cdevice_locals_dict, busdevice_i2cdevice_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(adafruit_bus_device_i2cdevice_locals_dict, adafruit_bus_device_i2cdevice_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t busdevice_i2cdevice_type = {
|
||||
const mp_obj_type_t adafruit_bus_device_i2cdevice_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_I2CDevice,
|
||||
.make_new = busdevice_i2cdevice_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&busdevice_i2cdevice_locals_dict,
|
||||
.make_new = adafruit_bus_device_i2cdevice_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&adafruit_bus_device_i2cdevice_locals_dict,
|
||||
};
|
@ -36,18 +36,18 @@
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
#include "shared-module/busdevice/I2CDevice.h"
|
||||
#include "shared-module/adafruit_bus_device/I2CDevice.h"
|
||||
//#include "shared-bindings/busio/I2C.h"
|
||||
|
||||
// Type object used in Python. Should be shared between ports.
|
||||
extern const mp_obj_type_t busdevice_i2cdevice_type;
|
||||
extern const mp_obj_type_t adafruit_bus_device_i2cdevice_type;
|
||||
|
||||
// Initializes the hardware peripheral.
|
||||
extern void common_hal_busdevice_i2cdevice_construct(busdevice_i2cdevice_obj_t *self, busio_i2c_obj_t *i2c, uint8_t device_address);
|
||||
extern uint8_t common_hal_busdevice_i2cdevice_readinto(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length);
|
||||
extern uint8_t common_hal_busdevice_i2cdevice_write(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length);
|
||||
extern void common_hal_busdevice_i2cdevice_lock(busdevice_i2cdevice_obj_t *self);
|
||||
extern void common_hal_busdevice_i2cdevice_unlock(busdevice_i2cdevice_obj_t *self);
|
||||
extern void common_hal_busdevice_i2cdevice_probe_for_device(busdevice_i2cdevice_obj_t *self);
|
||||
extern void common_hal_adafruit_bus_device_i2cdevice_construct(adafruit_bus_device_i2cdevice_obj_t *self, busio_i2c_obj_t *i2c, uint8_t device_address);
|
||||
extern uint8_t common_hal_adafruit_bus_device_i2cdevice_readinto(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length);
|
||||
extern uint8_t common_hal_adafruit_bus_device_i2cdevice_write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length);
|
||||
extern void common_hal_adafruit_bus_device_i2cdevice_lock(adafruit_bus_device_i2cdevice_obj_t *self);
|
||||
extern void common_hal_adafruit_bus_device_i2cdevice_unlock(adafruit_bus_device_i2cdevice_obj_t *self);
|
||||
extern void common_hal_adafruit_bus_device_i2cdevice_probe_for_device(adafruit_bus_device_i2cdevice_obj_t *self);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSDEVICE_I2CDEVICE_H
|
@ -25,9 +25,9 @@
|
||||
*/
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/busdevice/SPIDevice.h"
|
||||
#include "shared-bindings/adafruit_bus_device/SPIDevice.h"
|
||||
#include "shared-bindings/util.h"
|
||||
#include "shared-module/busdevice/SPIDevice.h"
|
||||
#include "shared-module/adafruit_bus_device/SPIDevice.h"
|
||||
#include "common-hal/digitalio/DigitalInOut.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
|
||||
@ -69,9 +69,9 @@
|
||||
//| spi.write(bytes_read)"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busdevice_spidevice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
busdevice_spidevice_obj_t *self = m_new_obj(busdevice_spidevice_obj_t);
|
||||
self->base.type = &busdevice_spidevice_type;
|
||||
STATIC mp_obj_t adafruit_bus_device_spidevice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
adafruit_bus_device_spidevice_obj_t *self = m_new_obj(adafruit_bus_device_spidevice_obj_t);
|
||||
self->base.type = &adafruit_bus_device_spidevice_type;
|
||||
enum { ARG_spi, ARG_chip_select, ARG_baudrate, ARG_polarity, ARG_phase, ARG_extra_clocks };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_spi, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
@ -86,7 +86,7 @@ STATIC mp_obj_t busdevice_spidevice_make_new(const mp_obj_type_t *type, size_t n
|
||||
|
||||
busio_spi_obj_t* spi = args[ARG_spi].u_obj;
|
||||
|
||||
common_hal_busdevice_spidevice_construct(MP_OBJ_TO_PTR(self), spi, args[ARG_chip_select].u_obj, args[ARG_baudrate].u_int, args[ARG_polarity].u_int,
|
||||
common_hal_adafruit_bus_device_spidevice_construct(MP_OBJ_TO_PTR(self), spi, args[ARG_chip_select].u_obj, args[ARG_baudrate].u_int, args[ARG_polarity].u_int,
|
||||
args[ARG_phase].u_int, args[ARG_extra_clocks].u_int);
|
||||
|
||||
if (args[ARG_chip_select].u_obj != MP_OBJ_NULL) {
|
||||
@ -100,29 +100,29 @@ STATIC mp_obj_t busdevice_spidevice_make_new(const mp_obj_type_t *type, size_t n
|
||||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t busdevice_spidevice_obj___enter__(mp_obj_t self_in) {
|
||||
busdevice_spidevice_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_busdevice_spidevice_enter(self);
|
||||
STATIC mp_obj_t adafruit_bus_device_spidevice_obj___enter__(mp_obj_t self_in) {
|
||||
adafruit_bus_device_spidevice_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_adafruit_bus_device_spidevice_enter(self);
|
||||
return self->spi;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(busdevice_spidevice___enter___obj, busdevice_spidevice_obj___enter__);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adafruit_bus_device_spidevice___enter___obj, adafruit_bus_device_spidevice_obj___enter__);
|
||||
|
||||
STATIC mp_obj_t busdevice_spidevice_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
common_hal_busdevice_spidevice_exit(MP_OBJ_TO_PTR(args[0]));
|
||||
STATIC mp_obj_t adafruit_bus_device_spidevice_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
common_hal_adafruit_bus_device_spidevice_exit(MP_OBJ_TO_PTR(args[0]));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busdevice_spidevice___exit___obj, 4, 4, busdevice_spidevice_obj___exit__);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(adafruit_bus_device_spidevice___exit___obj, 4, 4, adafruit_bus_device_spidevice_obj___exit__);
|
||||
|
||||
STATIC const mp_rom_map_elem_t busdevice_spidevice_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&busdevice_spidevice___enter___obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&busdevice_spidevice___exit___obj) },
|
||||
STATIC const mp_rom_map_elem_t adafruit_bus_device_spidevice_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&adafruit_bus_device_spidevice___enter___obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&adafruit_bus_device_spidevice___exit___obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(busdevice_spidevice_locals_dict, busdevice_spidevice_locals_dict_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(adafruit_bus_device_spidevice_locals_dict, adafruit_bus_device_spidevice_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t busdevice_spidevice_type = {
|
||||
const mp_obj_type_t adafruit_bus_device_spidevice_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_SPIDevice,
|
||||
.make_new = busdevice_spidevice_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&busdevice_spidevice_locals_dict,
|
||||
.make_new = adafruit_bus_device_spidevice_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&adafruit_bus_device_spidevice_locals_dict,
|
||||
};
|
@ -36,15 +36,15 @@
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
#include "shared-module/busdevice/SPIDevice.h"
|
||||
#include "shared-module/adafruit_bus_device/SPIDevice.h"
|
||||
|
||||
// Type object used in Python. Should be shared between ports.
|
||||
extern const mp_obj_type_t busdevice_spidevice_type;
|
||||
extern const mp_obj_type_t adafruit_bus_device_spidevice_type;
|
||||
|
||||
// Initializes the hardware peripheral.
|
||||
extern void common_hal_busdevice_spidevice_construct(busdevice_spidevice_obj_t *self, busio_spi_obj_t *spi, digitalio_digitalinout_obj_t *cs,
|
||||
extern void common_hal_adafruit_bus_device_spidevice_construct(adafruit_bus_device_spidevice_obj_t *self, busio_spi_obj_t *spi, digitalio_digitalinout_obj_t *cs,
|
||||
uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t extra_clocks);
|
||||
extern void common_hal_busdevice_spidevice_enter(busdevice_spidevice_obj_t *self);
|
||||
extern void common_hal_busdevice_spidevice_exit(busdevice_spidevice_obj_t *self);
|
||||
extern void common_hal_adafruit_bus_device_spidevice_enter(adafruit_bus_device_spidevice_obj_t *self);
|
||||
extern void common_hal_adafruit_bus_device_spidevice_exit(adafruit_bus_device_spidevice_obj_t *self);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSDEVICE_SPIDEVICE_H
|
@ -31,30 +31,30 @@
|
||||
#include "py/mphal.h"
|
||||
#include "py/objproperty.h"
|
||||
|
||||
#include "shared-bindings/busdevice/__init__.h"
|
||||
#include "shared-bindings/busdevice/I2CDevice.h"
|
||||
#include "shared-bindings/busdevice/SPIDevice.h"
|
||||
#include "shared-bindings/adafruit_bus_device/__init__.h"
|
||||
#include "shared-bindings/adafruit_bus_device/I2CDevice.h"
|
||||
#include "shared-bindings/adafruit_bus_device/SPIDevice.h"
|
||||
|
||||
STATIC const mp_rom_map_elem_t busdevice_i2c_device_globals_table[] = {
|
||||
STATIC const mp_rom_map_elem_t adafruit_bus_device_i2c_device_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_i2c_device) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_I2CDevice), MP_ROM_PTR(&busdevice_i2cdevice_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_I2CDevice), MP_ROM_PTR(&adafruit_bus_device_i2cdevice_type) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(busdevice_i2c_device_globals, busdevice_i2c_device_globals_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(adafruit_bus_device_i2c_device_globals, adafruit_bus_device_i2c_device_globals_table);
|
||||
|
||||
const mp_obj_module_t busdevice_i2c_device_module = {
|
||||
const mp_obj_module_t adafruit_bus_device_i2c_device_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&busdevice_i2c_device_globals,
|
||||
.globals = (mp_obj_dict_t*)&adafruit_bus_device_i2c_device_globals,
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t busdevice_spi_device_globals_table[] = {
|
||||
STATIC const mp_rom_map_elem_t adafruit_bus_device_spi_device_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_spi_device) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SPIDevice), MP_ROM_PTR(&busdevice_spidevice_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SPIDevice), MP_ROM_PTR(&adafruit_bus_device_spidevice_type) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(busdevice_spi_device_globals, busdevice_spi_device_globals_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(adafruit_bus_device_spi_device_globals, adafruit_bus_device_spi_device_globals_table);
|
||||
|
||||
const mp_obj_module_t busdevice_spi_device_module = {
|
||||
const mp_obj_module_t adafruit_bus_device_spi_device_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&busdevice_spi_device_globals,
|
||||
.globals = (mp_obj_dict_t*)&adafruit_bus_device_spi_device_globals,
|
||||
};
|
||||
|
||||
//| """Hardware accelerated external bus access
|
||||
@ -64,15 +64,15 @@ const mp_obj_module_t busdevice_spi_device_module = {
|
||||
//| devices, it manages the chip select and protocol changes such as mode. For I2C, it
|
||||
//| manages the device address."""
|
||||
//|
|
||||
STATIC const mp_rom_map_elem_t busdevice_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_busdevice) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_i2c_device), MP_ROM_PTR(&busdevice_i2c_device_module) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_spi_device), MP_ROM_PTR(&busdevice_spi_device_module) },
|
||||
STATIC const mp_rom_map_elem_t adafruit_bus_device_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_adafruit_bus_device) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_i2c_device), MP_ROM_PTR(&adafruit_bus_device_i2c_device_module) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_spi_device), MP_ROM_PTR(&adafruit_bus_device_spi_device_module) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(busdevice_module_globals, busdevice_module_globals_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(adafruit_bus_device_module_globals, adafruit_bus_device_module_globals_table);
|
||||
|
||||
const mp_obj_module_t busdevice_module = {
|
||||
const mp_obj_module_t adafruit_bus_device_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&busdevice_module_globals,
|
||||
.globals = (mp_obj_dict_t*)&adafruit_bus_device_module_globals,
|
||||
};
|
@ -24,18 +24,18 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/busdevice/I2CDevice.h"
|
||||
#include "shared-bindings/adafruit_bus_device/I2CDevice.h"
|
||||
#include "shared-bindings/busio/I2C.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
void common_hal_busdevice_i2cdevice_construct(busdevice_i2cdevice_obj_t *self, busio_i2c_obj_t *i2c, uint8_t device_address) {
|
||||
void common_hal_adafruit_bus_device_i2cdevice_construct(adafruit_bus_device_i2cdevice_obj_t *self, busio_i2c_obj_t *i2c, uint8_t device_address) {
|
||||
self->i2c = i2c;
|
||||
self->device_address = device_address;
|
||||
}
|
||||
|
||||
void common_hal_busdevice_i2cdevice_lock(busdevice_i2cdevice_obj_t *self) {
|
||||
void common_hal_adafruit_bus_device_i2cdevice_lock(adafruit_bus_device_i2cdevice_obj_t *self) {
|
||||
bool success = false;
|
||||
while (!success) {
|
||||
success = common_hal_busio_i2c_try_lock(self->i2c);
|
||||
@ -44,31 +44,31 @@ void common_hal_busdevice_i2cdevice_lock(busdevice_i2cdevice_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
void common_hal_busdevice_i2cdevice_unlock(busdevice_i2cdevice_obj_t *self) {
|
||||
void common_hal_adafruit_bus_device_i2cdevice_unlock(adafruit_bus_device_i2cdevice_obj_t *self) {
|
||||
common_hal_busio_i2c_unlock(self->i2c);
|
||||
}
|
||||
|
||||
uint8_t common_hal_busdevice_i2cdevice_readinto(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length) {
|
||||
uint8_t common_hal_adafruit_bus_device_i2cdevice_readinto(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length) {
|
||||
return common_hal_busio_i2c_read(self->i2c, self->device_address, buffer, length);
|
||||
}
|
||||
|
||||
uint8_t common_hal_busdevice_i2cdevice_write(busdevice_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length) {
|
||||
uint8_t common_hal_adafruit_bus_device_i2cdevice_write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length) {
|
||||
return common_hal_busio_i2c_write(self->i2c, self->device_address, buffer, length, true);
|
||||
}
|
||||
|
||||
void common_hal_busdevice_i2cdevice_probe_for_device(busdevice_i2cdevice_obj_t *self) {
|
||||
common_hal_busdevice_i2cdevice_lock(self);
|
||||
void common_hal_adafruit_bus_device_i2cdevice_probe_for_device(adafruit_bus_device_i2cdevice_obj_t *self) {
|
||||
common_hal_adafruit_bus_device_i2cdevice_lock(self);
|
||||
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_obj_t buffer = mp_obj_new_bytearray_of_zeros(1);
|
||||
|
||||
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_WRITE);
|
||||
|
||||
uint8_t status = common_hal_busdevice_i2cdevice_readinto(self, (uint8_t*)bufinfo.buf, 1);
|
||||
uint8_t status = common_hal_adafruit_bus_device_i2cdevice_readinto(self, (uint8_t*)bufinfo.buf, 1);
|
||||
if (status != 0) {
|
||||
common_hal_busdevice_i2cdevice_unlock(self);
|
||||
common_hal_adafruit_bus_device_i2cdevice_unlock(self);
|
||||
mp_raise_ValueError_varg(translate("No I2C device at address: %x"), self->device_address);
|
||||
}
|
||||
|
||||
common_hal_busdevice_i2cdevice_unlock(self);
|
||||
common_hal_adafruit_bus_device_i2cdevice_unlock(self);
|
||||
}
|
@ -34,6 +34,6 @@ typedef struct {
|
||||
mp_obj_base_t base;
|
||||
busio_i2c_obj_t *i2c;
|
||||
uint8_t device_address;
|
||||
} busdevice_i2cdevice_obj_t;
|
||||
} adafruit_bus_device_i2cdevice_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BUSDEVICE_I2CDEVICE_H
|
@ -24,14 +24,14 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/busdevice/SPIDevice.h"
|
||||
#include "shared-bindings/adafruit_bus_device/SPIDevice.h"
|
||||
#include "shared-bindings/busio/SPI.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
void common_hal_busdevice_spidevice_construct(busdevice_spidevice_obj_t *self, busio_spi_obj_t *spi, digitalio_digitalinout_obj_t *cs,
|
||||
void common_hal_adafruit_bus_device_spidevice_construct(adafruit_bus_device_spidevice_obj_t *self, busio_spi_obj_t *spi, digitalio_digitalinout_obj_t *cs,
|
||||
uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t extra_clocks) {
|
||||
self->spi = spi;
|
||||
self->baudrate = baudrate;
|
||||
@ -41,7 +41,7 @@ void common_hal_busdevice_spidevice_construct(busdevice_spidevice_obj_t *self, b
|
||||
self->chip_select = cs;
|
||||
}
|
||||
|
||||
void common_hal_busdevice_spidevice_enter(busdevice_spidevice_obj_t *self) {
|
||||
void common_hal_adafruit_bus_device_spidevice_enter(adafruit_bus_device_spidevice_obj_t *self) {
|
||||
bool success = false;
|
||||
while (!success) {
|
||||
success = common_hal_busio_spi_try_lock(self->spi);
|
||||
@ -56,7 +56,7 @@ void common_hal_busdevice_spidevice_enter(busdevice_spidevice_obj_t *self) {
|
||||
}
|
||||
}
|
||||
|
||||
void common_hal_busdevice_spidevice_exit(busdevice_spidevice_obj_t *self) {
|
||||
void common_hal_adafruit_bus_device_spidevice_exit(adafruit_bus_device_spidevice_obj_t *self) {
|
||||
if (self->chip_select != MP_OBJ_NULL) {
|
||||
common_hal_digitalio_digitalinout_set_value(MP_OBJ_TO_PTR(self->chip_select), true);
|
||||
}
|
@ -39,6 +39,6 @@ typedef struct {
|
||||
uint8_t phase;
|
||||
uint8_t extra_clocks;
|
||||
digitalio_digitalinout_obj_t *chip_select;
|
||||
} busdevice_spidevice_obj_t;
|
||||
} adafruit_bus_device_spidevice_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_SHARED_MODULE_BUSDEVICE_SPIDEVICE_H
|
Loading…
Reference in New Issue
Block a user