kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Port remaining modules to PimoroniI2C, update examples
rodzic
edf77ddb76
commit
66f6983290
|
@ -1,7 +1,12 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_as7262 import BreakoutAS7262
|
||||
|
||||
as7262 = BreakoutAS7262()
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
as7262 = BreakoutAS7262(i2c)
|
||||
|
||||
dev_type = as7262.device_type()
|
||||
hw_version = as7262.hardware_version()
|
||||
|
|
|
@ -2,9 +2,14 @@ import time
|
|||
import math
|
||||
import random
|
||||
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_dotmatrix import BreakoutDotMatrix
|
||||
|
||||
display = BreakoutDotMatrix()
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
display = BreakoutDotMatrix(i2c)
|
||||
width = display.WIDTH
|
||||
height = display.HEIGHT
|
||||
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
import math
|
||||
import time
|
||||
import math
|
||||
import random
|
||||
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_dotmatrix import BreakoutDotMatrix
|
||||
|
||||
display = BreakoutDotMatrix()
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
display = BreakoutDotMatrix(i2c)
|
||||
start_time = time.time()
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import time
|
||||
import math
|
||||
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_dotmatrix import BreakoutDotMatrix
|
||||
|
||||
display = BreakoutDotMatrix()
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
display = BreakoutDotMatrix(i2c)
|
||||
|
||||
# Left Image Padding Right Image Padding
|
||||
image = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0,
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
import time
|
||||
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_dotmatrix import BreakoutDotMatrix
|
||||
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
address = 0x61
|
||||
start_time = time.time()
|
||||
|
||||
display = BreakoutDotMatrix(address=address)
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
display = BreakoutDotMatrix(i2c, address=address)
|
||||
display.clear()
|
||||
display.show()
|
||||
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_encoder import BreakoutEncoder
|
||||
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
steps_per_rev = 24
|
||||
|
||||
enc = BreakoutEncoder()
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
enc = BreakoutEncoder(i2c)
|
||||
|
||||
enc.set_brightness(1.0)
|
||||
# enc.set_direction(BreakoutEncoder.DIRECTION_CCW) # Uncomment this to flip the direction
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_ioexpander import BreakoutIOExpander
|
||||
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
ioe_adc_pin = 10
|
||||
|
||||
ioe = BreakoutIOExpander(0x18)
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
ioe = BreakoutIOExpander(i2c, address=0x18)
|
||||
|
||||
ioe.set_mode(ioe_adc_pin, BreakoutIOExpander.PIN_ADC)
|
||||
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_ioexpander import BreakoutIOExpander
|
||||
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
ioe_button_pin = 14
|
||||
|
||||
ioe = BreakoutIOExpander(0x18)
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
ioe = BreakoutIOExpander(i2c, address=0x18)
|
||||
|
||||
ioe.set_mode(ioe_button_pin, BreakoutIOExpander.PIN_IN_PU)
|
||||
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import time
|
||||
import math
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_ioexpander import BreakoutIOExpander
|
||||
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
ioe_servo_pin = 1
|
||||
|
||||
# Settings to produce a 50Hz output from the 24MHz clock.
|
||||
|
@ -12,7 +16,8 @@ period = 60000
|
|||
cycle_time = 5.0
|
||||
servo_range = 1000.0 # Between 1000 and 2000us (1-2ms)
|
||||
|
||||
ioe = BreakoutIOExpander(0x18)
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
ioe = BreakoutIOExpander(i2c, address=0x18)
|
||||
|
||||
ioe.set_pwm_period(period)
|
||||
ioe.set_pwm_control(divider)
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_ltr559 import BreakoutLTR559
|
||||
|
||||
ltr = BreakoutLTR559()
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
ltr = BreakoutLTR559(i2c)
|
||||
|
||||
part_id = ltr.part_id()
|
||||
print("Found LTR559. Part ID: 0x", '{:02x}'.format(part_id), sep="")
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_matrix11x7 import BreakoutMatrix11x7
|
||||
|
||||
on_brightness = 64
|
||||
|
||||
matrix = BreakoutMatrix11x7()
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
matrix = BreakoutMatrix11x7(i2c)
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_mics6814 import BreakoutMICS6814
|
||||
|
||||
OUTPUT_FREQUENCY = 0.5
|
||||
|
||||
gas = BreakoutMICS6814()
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
gas = BreakoutMICS6814(i2c)
|
||||
|
||||
gas.set_brightness(1.0)
|
||||
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_msa301 import BreakoutMSA301
|
||||
|
||||
msa = BreakoutMSA301()
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
msa = BreakoutMSA301(i2c)
|
||||
|
||||
part_id = msa.part_id()
|
||||
print("Found MSA301. Part ID: 0x", '{:02x}'.format(part_id), sep="")
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_potentiometer import BreakoutPotentiometer
|
||||
|
||||
pot = BreakoutPotentiometer()
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
pot = BreakoutPotentiometer(i2c)
|
||||
|
||||
pot.set_brightness(1.0)
|
||||
# pot.set_direction(BreakoutPotentiometer.DIRECTION_CCW) # Uncomment this to flip the direction
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_rgbmatrix5x5 import BreakoutRGBMatrix5x5
|
||||
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
matrix = BreakoutRGBMatrix5x5(i2c)
|
||||
|
||||
colors = []
|
||||
colors.append((255, 0, 0))
|
||||
colors.append((0, 255, 0))
|
||||
colors.append((0, 0, 255))
|
||||
colors.append((128, 128, 128))
|
||||
|
||||
matrix = BreakoutRGBMatrix5x5()
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
col = 0
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_rtc import BreakoutRTC
|
||||
import time
|
||||
|
||||
# rtc = BreakoutRTC(sda=4, scl=5) # i2c pins 4, 5 for Breakout Garden
|
||||
rtc = BreakoutRTC() # Default i2c pins for Pico Explorer
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} # i2c pins 4, 5 for Breakout Garden
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} # Default i2c pins for Pico Explorer
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
rtc = BreakoutRTC(i2c)
|
||||
|
||||
if rtc.is_12_hour():
|
||||
rtc.set_24_hour()
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_sgp30 import BreakoutSGP30
|
||||
|
||||
# sgp30 = BreakoutSGP30(sda=4, scl=5) # i2c pins 4, 5 for Breakout Garden
|
||||
sgp30 = BreakoutSGP30() # Default i2c pins for Pico Explorer
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} # i2c pins 4, 5 for Breakout Garden
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} # Default i2c pins for Pico Explorer
|
||||
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
sgp30 = BreakoutSGP30(i2c)
|
||||
|
||||
print("SGP30 initialised - about to start measuring without waiting")
|
||||
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
import time
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from breakout_trackball import BreakoutTrackball
|
||||
|
||||
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5, "baudrate": 100000}
|
||||
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21, "baudrate": 100000}
|
||||
|
||||
sensitivity = 2
|
||||
|
||||
trackball = BreakoutTrackball()
|
||||
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
|
||||
trackball = BreakoutTrackball(i2c)
|
||||
|
||||
trackball.set_rgbw(0, 0, 0, 64)
|
||||
|
||||
print("Roll the trackball to change colour!")
|
||||
|
||||
while True:
|
||||
state = trackball.read()
|
||||
if state[BreakoutTrackball.SW_PRESSED]:
|
||||
|
|
|
@ -11,6 +11,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_as7262.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_as7262_BreakoutAS7262_obj_t {
|
||||
|
@ -44,11 +51,9 @@ void BreakoutAS7262_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
|
|||
mp_obj_t BreakoutAS7262_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_as7262_BreakoutAS7262_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_sda, ARG_scl, ARG_int };
|
||||
enum { ARG_i2c, ARG_int };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = PIN_UNUSED} },
|
||||
};
|
||||
|
||||
|
@ -56,33 +61,21 @@ mp_obj_t BreakoutAS7262_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutAS7262: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_as7262_BreakoutAS7262_obj_t);
|
||||
self->base.type = &breakout_as7262_BreakoutAS7262_type;
|
||||
|
||||
self->breakout = new BreakoutAS7262(sda, scl, args[ARG_int].u_int);
|
||||
self->breakout = new BreakoutAS7262(i2c->i2c, args[ARG_int].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "AS7262 breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutAS7262: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -12,6 +12,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_dotmatrix.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_dotmatrix_BreakoutDotMatrix_obj_t {
|
||||
|
@ -47,42 +54,27 @@ void BreakoutDotMatrix_print(const mp_print_t *print, mp_obj_t self_in, mp_print
|
|||
mp_obj_t BreakoutDotMatrix_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_dotmatrix_BreakoutDotMatrix_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_address, ARG_sda, ARG_scl };
|
||||
enum { ARG_i2c, ARG_address };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutDotMatrix::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutDotMatrix: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_dotmatrix_BreakoutDotMatrix_obj_t);
|
||||
self->base.type = &breakout_dotmatrix_BreakoutDotMatrix_type;
|
||||
|
||||
self->breakout = new BreakoutDotMatrix(args[ARG_address].u_int, sda, scl);
|
||||
self->breakout = new BreakoutDotMatrix(i2c->i2c, args[ARG_address].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "DotMatrix breakout not found when initialising");
|
||||
|
|
|
@ -69,7 +69,7 @@ mp_obj_t BreakoutEncoder_make_new(const mp_obj_type_t *type, size_t n_args, size
|
|||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad i2C object"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutEncoder: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ mp_obj_t BreakoutEncoder_make_new(const mp_obj_type_t *type, size_t n_args, size
|
|||
self->breakout = new BreakoutEncoder(i2c->i2c, args[ARG_address].u_int, args[ARG_interrupt].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "Encoder breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutEncoder: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -12,6 +12,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_ioexpander.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_ioexpander_BreakoutIOExpander_obj_t {
|
||||
|
@ -50,12 +57,10 @@ void BreakoutIOExpander_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
|
|||
mp_obj_t BreakoutIOExpander_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_ioexpander_BreakoutIOExpander_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_address, ARG_sda, ARG_scl, ARG_interrupt };
|
||||
enum { ARG_i2c, ARG_address, ARG_interrupt };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutIOExpander::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = PIN_UNUSED} },
|
||||
};
|
||||
|
||||
|
@ -64,32 +69,20 @@ mp_obj_t BreakoutIOExpander_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutIOExpander: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_ioexpander_BreakoutIOExpander_obj_t);
|
||||
self->base.type = &breakout_ioexpander_BreakoutIOExpander_type;
|
||||
|
||||
self->breakout = new BreakoutIOExpander(args[ARG_address].u_int, sda, scl, args[ARG_interrupt].u_int);
|
||||
self->breakout = new BreakoutIOExpander(i2c->i2c, args[ARG_address].u_int, args[ARG_interrupt].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "IOExpander breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutIOExpander: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -12,6 +12,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_ltr559.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_ltr559_BreakoutLTR559_obj_t {
|
||||
|
@ -50,45 +57,30 @@ void BreakoutLTR559_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
|
|||
mp_obj_t BreakoutLTR559_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_ltr559_BreakoutLTR559_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_sda, ARG_scl, ARG_interrupt };
|
||||
enum { ARG_i2c, ARG_interrupt };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = PIN_UNUSED} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutLTR559: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_ltr559_BreakoutLTR559_obj_t);
|
||||
self->base.type = &breakout_ltr559_BreakoutLTR559_type;
|
||||
|
||||
self->breakout = new BreakoutLTR559(sda, scl, args[ARG_interrupt].u_int);
|
||||
self->breakout = new BreakoutLTR559(i2c->i2c, args[ARG_interrupt].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "LTR559 breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutLTR559: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -12,6 +12,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_matrix11x7.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_matrix11x7_BreakoutMatrix11x7_obj_t {
|
||||
|
@ -47,12 +54,10 @@ void BreakoutMatrix11x7_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
|
|||
mp_obj_t BreakoutMatrix11x7_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_matrix11x7_BreakoutMatrix11x7_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_address, ARG_sda, ARG_scl };
|
||||
enum { ARG_i2c, ARG_address };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutMatrix11x7::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutMatrix11x7::DEFAULT_I2C_ADDRESS} }
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
@ -60,33 +65,20 @@ mp_obj_t BreakoutMatrix11x7_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutMatrix11x7: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_matrix11x7_BreakoutMatrix11x7_obj_t);
|
||||
self->base.type = &breakout_matrix11x7_BreakoutMatrix11x7_type;
|
||||
|
||||
i2c_inst_t *i2c = (i2c_id == 0) ? i2c0 : i2c1;
|
||||
self->breakout = new BreakoutMatrix11x7(i2c, args[ARG_address].u_int, sda, scl);
|
||||
self->breakout = new BreakoutMatrix11x7(i2c->i2c, args[ARG_address].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "Matrix11x7 breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutMatrix11x7: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -12,6 +12,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_mics6814.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_mics6814_BreakoutMICS6814_obj_t {
|
||||
|
@ -50,12 +57,10 @@ void BreakoutMICS6814_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
|
|||
mp_obj_t BreakoutMICS6814_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_mics6814_BreakoutMICS6814_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_address, ARG_sda, ARG_scl, ARG_interrupt };
|
||||
enum { ARG_i2c, ARG_address, ARG_interrupt };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutMICS6814::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = PIN_UNUSED} },
|
||||
};
|
||||
|
||||
|
@ -64,32 +69,20 @@ mp_obj_t BreakoutMICS6814_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
|||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutMICS6814: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_mics6814_BreakoutMICS6814_obj_t);
|
||||
self->base.type = &breakout_mics6814_BreakoutMICS6814_type;
|
||||
|
||||
self->breakout = new BreakoutMICS6814(args[ARG_address].u_int, sda, scl, args[ARG_interrupt].u_int);
|
||||
self->breakout = new BreakoutMICS6814(i2c->i2c, args[ARG_address].u_int, args[ARG_interrupt].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "MICS6814 breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutMICS6814: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -11,6 +11,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_msa301.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_msa301_BreakoutMSA301_obj_t {
|
||||
|
@ -44,11 +51,9 @@ void BreakoutMSA301_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
|
|||
mp_obj_t BreakoutMSA301_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_msa301_BreakoutMSA301_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_sda, ARG_scl, ARG_interrupt };
|
||||
enum { ARG_i2c, ARG_interrupt };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = PIN_UNUSED} },
|
||||
};
|
||||
|
||||
|
@ -56,34 +61,20 @@ mp_obj_t BreakoutMSA301_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutMSA301: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_msa301_BreakoutMSA301_obj_t);
|
||||
self->base.type = &breakout_msa301_BreakoutMSA301_type;
|
||||
|
||||
i2c_inst_t *i2c = (i2c_id == 0) ? i2c0 : i2c1;
|
||||
self->breakout = new BreakoutMSA301(i2c, sda, scl, args[ARG_interrupt].u_int);
|
||||
|
||||
self->breakout = new BreakoutMSA301(i2c->i2c, args[ARG_interrupt].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "MSA301 breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutMSA301: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -69,7 +69,7 @@ mp_obj_t BreakoutPotentiometer_make_new(const mp_obj_type_t *type, size_t n_args
|
|||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad i2C object"));
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutPotentiometer: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ mp_obj_t BreakoutPotentiometer_make_new(const mp_obj_type_t *type, size_t n_args
|
|||
self->breakout = new BreakoutPotentiometer(i2c->i2c, args[ARG_interrupt].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "Potentiometer breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutPotentiometer: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -12,6 +12,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_rgbmatrix5x5.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_rgbmatrix5x5_BreakoutRGBMatrix5x5_obj_t {
|
||||
|
@ -47,12 +54,10 @@ void BreakoutRGBMatrix5x5_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
|
|||
mp_obj_t BreakoutRGBMatrix5x5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_rgbmatrix5x5_BreakoutRGBMatrix5x5_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_address, ARG_sda, ARG_scl };
|
||||
enum { ARG_i2c, ARG_address };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutRGBMatrix5x5::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutRGBMatrix5x5::DEFAULT_I2C_ADDRESS} }
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
@ -60,33 +65,20 @@ mp_obj_t BreakoutRGBMatrix5x5_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutRGBMatrix5x5: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_rgbmatrix5x5_BreakoutRGBMatrix5x5_obj_t);
|
||||
self->base.type = &breakout_rgbmatrix5x5_BreakoutRGBMatrix5x5_type;
|
||||
|
||||
i2c_inst_t *i2c = (i2c_id == 0) ? i2c0 : i2c1;
|
||||
self->breakout = new BreakoutRGBMatrix5x5(i2c, args[ARG_address].u_int, sda, scl);
|
||||
|
||||
self->breakout = new BreakoutRGBMatrix5x5(i2c->i2c, args[ARG_address].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "RGBMatrix5x5 breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutRGBMatrix5x5: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -14,6 +14,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_rtc.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_rtc_BreakoutRTC_obj_t {
|
||||
|
@ -47,11 +54,9 @@ void BreakoutRTC_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
|
|||
mp_obj_t BreakoutRTC_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_rtc_BreakoutRTC_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_sda, ARG_scl, ARG_interrupt };
|
||||
enum { ARG_i2c, ARG_interrupt };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = PIN_UNUSED} },
|
||||
};
|
||||
|
||||
|
@ -60,33 +65,20 @@ mp_obj_t BreakoutRTC_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
|||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutRTC: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_rtc_BreakoutRTC_obj_t);
|
||||
self->base.type = &breakout_rtc_BreakoutRTC_type;
|
||||
|
||||
i2c_inst_t *i2c = (i2c_id == 0) ? i2c0 : i2c1;
|
||||
self->breakout = new BreakoutRTC(i2c, sda, scl, args[ARG_interrupt].u_int);
|
||||
self->breakout = new BreakoutRTC(i2c->i2c, args[ARG_interrupt].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "RTC breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutRTC: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -11,6 +11,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_sgp30.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_sgp30_BreakoutSGP30_obj_t {
|
||||
|
@ -41,11 +48,9 @@ void BreakoutSGP30_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin
|
|||
mp_obj_t BreakoutSGP30_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_sgp30_BreakoutSGP30_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_sda, ARG_scl };
|
||||
enum { ARG_i2c };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} }
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
@ -53,33 +58,20 @@ mp_obj_t BreakoutSGP30_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
|||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutSGP30: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_sgp30_BreakoutSGP30_obj_t);
|
||||
self->base.type = &breakout_sgp30_BreakoutSGP30_type;
|
||||
|
||||
i2c_inst_t *i2c = (i2c_id == 0) ? i2c0 : i2c1;
|
||||
self->breakout = new BreakoutSGP30(i2c, sda, scl);
|
||||
|
||||
self->breakout = new BreakoutSGP30(i2c->i2c);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "SGP30 breakout not found when initialising");
|
||||
mp_raise_msg(&mp_type_RuntimeError, "BreakoutSGP30: breakout not found when initialising");
|
||||
}
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
|
|
|
@ -12,6 +12,13 @@ using namespace pimoroni;
|
|||
|
||||
extern "C" {
|
||||
#include "breakout_trackball.h"
|
||||
#include "pimoroni_i2c.h"
|
||||
|
||||
/***** I2C Struct *****/
|
||||
typedef struct _PimoroniI2C_obj_t {
|
||||
mp_obj_base_t base;
|
||||
I2C *i2c;
|
||||
} _PimoroniI2C_obj_t;
|
||||
|
||||
/***** Variables Struct *****/
|
||||
typedef struct _breakout_trackball_BreakoutTrackball_obj_t {
|
||||
|
@ -50,12 +57,10 @@ void BreakoutTrackball_print(const mp_print_t *print, mp_obj_t self_in, mp_print
|
|||
mp_obj_t BreakoutTrackball_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
breakout_trackball_BreakoutTrackball_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_i2c, ARG_address, ARG_sda, ARG_scl, ARG_interrupt };
|
||||
enum { ARG_i2c, ARG_address, ARG_interrupt };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutTrackball::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = PIN_UNUSED} },
|
||||
};
|
||||
|
||||
|
@ -64,30 +69,17 @@ mp_obj_t BreakoutTrackball_make_new(const mp_obj_type_t *type, size_t n_args, si
|
|||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
// Get I2C bus.
|
||||
int i2c_id = args[ARG_i2c].u_int;
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
|
||||
if(i2c_id == -1) {
|
||||
i2c_id = (sda >> 1) & 0b1; // If no i2c specified, choose the one for the given SDA pin
|
||||
}
|
||||
if(i2c_id < 0 || i2c_id > 1) {
|
||||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2C(%d) doesn't exist"), i2c_id);
|
||||
if(!MP_OBJ_IS_TYPE(args[ARG_i2c].u_obj, &PimoroniI2C_type)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("BreakoutSGP30: Bad i2C object"));
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SDA pin"));
|
||||
}
|
||||
|
||||
if(!IS_VALID_SCL(i2c_id, scl)) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("bad SCL pin"));
|
||||
}
|
||||
_PimoroniI2C_obj_t *i2c = (_PimoroniI2C_obj_t *)MP_OBJ_TO_PTR(args[ARG_i2c].u_obj);
|
||||
|
||||
self = m_new_obj(breakout_trackball_BreakoutTrackball_obj_t);
|
||||
self->base.type = &breakout_trackball_BreakoutTrackball_type;
|
||||
|
||||
i2c_inst_t *i2c = (i2c_id == 0) ? i2c0 : i2c1;
|
||||
self->breakout = new BreakoutTrackball(i2c, args[ARG_address].u_int, sda, scl, args[ARG_interrupt].u_int);
|
||||
self->breakout = new BreakoutTrackball(i2c->i2c, args[ARG_address].u_int, args[ARG_interrupt].u_int);
|
||||
|
||||
if(!self->breakout->init()) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, "Trackball breakout not found when initialising");
|
||||
|
|
|
@ -50,10 +50,11 @@ mp_obj_t PimoroniI2C___del__(mp_obj_t self_in) {
|
|||
mp_obj_t PimoroniI2C_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
_PimoroniI2C_obj_t *self = nullptr;
|
||||
|
||||
enum { ARG_sda, ARG_scl };
|
||||
enum { ARG_sda, ARG_scl, ARG_baudrate };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = I2C_DEFAULT_BAUDRATE} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
@ -63,6 +64,7 @@ mp_obj_t PimoroniI2C_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
|||
// Get I2C bus.
|
||||
int sda = args[ARG_sda].u_int;
|
||||
int scl = args[ARG_scl].u_int;
|
||||
int baud = args[ARG_baudrate].u_int;
|
||||
int i2c_id = (sda >> 1) & 0b1; // i2c bus for given SDA pin
|
||||
|
||||
if(!IS_VALID_SDA(i2c_id, sda)) {
|
||||
|
@ -76,7 +78,7 @@ mp_obj_t PimoroniI2C_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
|||
self = m_new_obj_with_finaliser(_PimoroniI2C_obj_t);
|
||||
self->base.type = &PimoroniI2C_type;
|
||||
|
||||
self->i2c = new I2C(sda, scl);
|
||||
self->i2c = new I2C(sda, scl, baud);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue