kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Switch drivers over to I2C class, tidy up common include
Removes all driver-specific SDA/SCL pin definitions and defaults. Pin type is "uint" everywhere, but "PIN_UNUSED" is *int*_max for MicroPython compat. That's still a lot of pins! Adds baudrate to the I2C class, and allows a driver (like Trackball) to check the baudrate is supportedpull/129/head
rodzic
42c7555c96
commit
445737088f
|
@ -6,9 +6,10 @@
|
|||
#define PIMORONI_SPI_DEFAULT_INSTANCE spi0
|
||||
|
||||
namespace pimoroni {
|
||||
static const unsigned int PIN_UNUSED = UINT_MAX;
|
||||
static const unsigned int PIN_UNUSED = INT_MAX; // Intentionally INT_MAX to avoid overflowing MicroPython's int type
|
||||
|
||||
// I2C
|
||||
static const unsigned int I2C_DEFAULT_BAUDRATE = 400000;
|
||||
static const unsigned int I2C_DEFAULT_SDA = 20;
|
||||
static const unsigned int I2C_DEFAULT_SCL = 21;
|
||||
static const unsigned int I2C_DEFAULT_INT = 22;
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace pimoroni {
|
|||
void I2C::init() {
|
||||
i2c = ((sda / 2) & 0b1) ? i2c1 : i2c0;
|
||||
|
||||
i2c_init(i2c, 400000);
|
||||
i2c_init(i2c, baudrate);
|
||||
|
||||
gpio_set_function(sda, GPIO_FUNC_I2C); gpio_pull_up(sda);
|
||||
gpio_set_function(scl, GPIO_FUNC_I2C); gpio_pull_up(scl);
|
||||
|
@ -29,7 +29,28 @@ namespace pimoroni {
|
|||
uint8_t I2C::reg_read_uint8(uint8_t address, uint8_t reg) {
|
||||
uint8_t value;
|
||||
i2c_write_blocking(i2c, address, ®, 1, false);
|
||||
i2c_read_blocking(i2c, address, (uint8_t *)&value, 1, false);
|
||||
i2c_read_blocking(i2c, address, (uint8_t *)&value, sizeof(uint8_t), false);
|
||||
return value;
|
||||
}
|
||||
|
||||
uint16_t I2C::reg_read_uint16(uint8_t address, uint8_t reg) {
|
||||
uint16_t value;
|
||||
i2c_write_blocking(i2c, address, ®, 1, true);
|
||||
i2c_read_blocking(i2c, address, (uint8_t *)&value, sizeof(uint16_t), false);
|
||||
return value;
|
||||
}
|
||||
|
||||
uint32_t I2C::reg_read_uint32(uint8_t address, uint8_t reg) {
|
||||
uint32_t value;
|
||||
i2c_write_blocking(i2c, address, ®, 1, true);
|
||||
i2c_read_blocking(i2c, address, (uint8_t *)&value, sizeof(uint32_t), false);
|
||||
return value;
|
||||
}
|
||||
|
||||
int16_t I2C::reg_read_int16(uint8_t address, uint8_t reg) {
|
||||
int16_t value;
|
||||
i2c_write_blocking(i2c, address, ®, 1, true);
|
||||
i2c_read_blocking(i2c, address, (uint8_t *)&value, sizeof(int16_t), false);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -67,11 +88,4 @@ namespace pimoroni {
|
|||
value &= ~(mask << shift);
|
||||
write_bytes(address, reg, &value, 1);
|
||||
}
|
||||
|
||||
int16_t I2C::reg_read_int16(uint8_t address, uint8_t reg) {
|
||||
int16_t value;
|
||||
i2c_write_blocking(i2c, address, ®, 1, true);
|
||||
i2c_read_blocking(i2c, address, (uint8_t *)&value, 2, false);
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -13,9 +13,10 @@ namespace pimoroni {
|
|||
uint sda = I2C_DEFAULT_SDA;
|
||||
uint scl = I2C_DEFAULT_SCL;
|
||||
uint interrupt = PIN_UNUSED;
|
||||
uint32_t baudrate = I2C_DEFAULT_BAUDRATE;
|
||||
|
||||
public:
|
||||
I2C(BOARD board) {
|
||||
I2C(BOARD board, uint32_t baudrate = I2C_DEFAULT_BAUDRATE) : baudrate(baudrate) {
|
||||
switch(board) {
|
||||
case BREAKOUT_GARDEN:
|
||||
sda = I2C_BG_SDA;
|
||||
|
@ -32,10 +33,12 @@ namespace pimoroni {
|
|||
init();
|
||||
}
|
||||
|
||||
I2C(uint sda, uint scl) : sda(sda), scl(scl) {
|
||||
I2C(uint sda, uint scl, uint32_t baudrate = I2C_DEFAULT_BAUDRATE) : sda(sda), scl(scl), baudrate(baudrate) {
|
||||
init();
|
||||
}
|
||||
|
||||
I2C() : I2C(I2C_DEFAULT_SDA, I2C_DEFAULT_SCL) {}
|
||||
|
||||
~I2C() {
|
||||
i2c_deinit(i2c);
|
||||
gpio_disable_pulls(sda);
|
||||
|
@ -46,7 +49,9 @@ namespace pimoroni {
|
|||
|
||||
void reg_write_uint8(uint8_t address, uint8_t reg, uint8_t value);
|
||||
uint8_t reg_read_uint8(uint8_t address, uint8_t reg);
|
||||
uint16_t reg_read_uint16(uint8_t address, uint8_t reg);
|
||||
int16_t reg_read_int16(uint8_t address, uint8_t reg);
|
||||
uint32_t reg_read_uint32(uint8_t address, uint8_t reg);
|
||||
|
||||
int write_bytes(uint8_t address, uint8_t reg, uint8_t *buf, int len);
|
||||
int read_bytes(uint8_t address, uint8_t reg, uint8_t *buf, int len);
|
||||
|
@ -60,6 +65,7 @@ namespace pimoroni {
|
|||
i2c_inst_t* get_i2c() {return i2c;}
|
||||
uint get_scl() {return scl;}
|
||||
uint get_sda() {return sda;}
|
||||
uint32_t get_baudrate() {return baudrate;}
|
||||
private:
|
||||
void init();
|
||||
};
|
||||
|
|
|
@ -15,10 +15,6 @@ namespace pimoroni {
|
|||
//--------------------------------------------------
|
||||
public:
|
||||
static const uint8_t DEFAULT_I2C_ADDRESS = 0x49;
|
||||
static const uint8_t DEFAULT_SDA_PIN = 20;
|
||||
static const uint8_t DEFAULT_SCL_PIN = 21;
|
||||
static const uint8_t DEFAULT_INT_PIN = 22;
|
||||
static const uint8_t PIN_UNUSED = UINT8_MAX;
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
|
@ -76,24 +72,17 @@ namespace pimoroni {
|
|||
|
||||
// interface pins with our standard defaults where appropriate
|
||||
int8_t address = DEFAULT_I2C_ADDRESS;
|
||||
int8_t interrupt = DEFAULT_INT_PIN;
|
||||
uint interrupt = PIN_UNUSED;
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Constructors/Destructor
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
AS7262() {
|
||||
i2c = new I2C(DEFAULT_SDA_PIN, DEFAULT_SCL_PIN);
|
||||
};
|
||||
AS7262(uint8_t address) : address(address) {
|
||||
i2c = new I2C(DEFAULT_SDA_PIN, DEFAULT_SCL_PIN);
|
||||
};
|
||||
AS7262(i2c_inst_t *i2c_inst, uint8_t address, uint sda, uint scl, uint8_t interrupt = PIN_UNUSED) : address(address), interrupt(interrupt) {
|
||||
i2c = new I2C(sda, scl);
|
||||
}
|
||||
AS7262(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint8_t interrupt = PIN_UNUSED) :
|
||||
i2c(i2c), address(address), interrupt(interrupt) {}
|
||||
AS7262() : AS7262(DEFAULT_I2C_ADDRESS) {};
|
||||
AS7262(uint8_t address) : i2c(new I2C()), address(address) {};
|
||||
AS7262(i2c_inst_t *i2c_inst, uint8_t address, uint sda, uint scl, uint interrupt = PIN_UNUSED) : i2c(new I2C()), address(address), interrupt(interrupt) {}
|
||||
AS7262(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED) : i2c(i2c), address(address), interrupt(interrupt) {}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
|
|
|
@ -298,18 +298,18 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
IOExpander::IOExpander() :
|
||||
IOExpander(new I2C(DEFAULT_SDA_PIN, DEFAULT_SCL_PIN), DEFAULT_I2C_ADDRESS, DEFAULT_INT_PIN, timeout, debug) {};
|
||||
IOExpander(new I2C(), DEFAULT_I2C_ADDRESS, DEFAULT_INT_PIN, timeout, debug) {};
|
||||
|
||||
IOExpander::IOExpander(uint8_t address, uint32_t timeout, bool debug) :
|
||||
IOExpander(new I2C(DEFAULT_SDA_PIN, DEFAULT_SCL_PIN), address, DEFAULT_INT_PIN, timeout, debug) {};
|
||||
IOExpander(new I2C(), address, DEFAULT_INT_PIN, timeout, debug) {};
|
||||
|
||||
IOExpander::IOExpander(uint8_t address, uint8_t sda, uint8_t scl, uint8_t interrupt, uint32_t timeout, bool debug) :
|
||||
IOExpander::IOExpander(uint8_t address, uint sda, uint scl, uint interrupt, uint32_t timeout, bool debug) :
|
||||
IOExpander(new I2C(sda, scl), address, interrupt, timeout, debug) {};
|
||||
|
||||
IOExpander::IOExpander(i2c_inst_t *i2c, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interrupt, uint32_t timeout, bool debug) :
|
||||
IOExpander::IOExpander(i2c_inst_t *i2c, uint8_t address, uint sda, uint scl, uint interrupt, uint32_t timeout, bool debug) :
|
||||
IOExpander(new I2C(sda, scl), address, interrupt, timeout, debug) {};
|
||||
|
||||
IOExpander::IOExpander(I2C *i2c, uint8_t address, uint8_t interrupt, uint32_t timeout, bool debug) :
|
||||
IOExpander::IOExpander(I2C *i2c, uint8_t address, uint interrupt, uint32_t timeout, bool debug) :
|
||||
i2c(i2c),
|
||||
address(address), interrupt(interrupt),
|
||||
timeout(timeout), debug(debug), vref(3.3f),
|
||||
|
|
|
@ -148,7 +148,7 @@ namespace pimoroni {
|
|||
|
||||
// interface pins with our standard defaults where appropriate
|
||||
int8_t address = DEFAULT_I2C_ADDRESS;
|
||||
int8_t interrupt = DEFAULT_INT_PIN;
|
||||
uint interrupt = DEFAULT_INT_PIN;
|
||||
|
||||
uint32_t timeout;
|
||||
bool debug;
|
||||
|
@ -164,9 +164,9 @@ namespace pimoroni {
|
|||
public:
|
||||
IOExpander();
|
||||
IOExpander(uint8_t address, uint32_t timeout = 1, bool debug = false);
|
||||
IOExpander(uint8_t address, uint8_t sda, uint8_t scl, uint8_t interrupt = PIN_UNUSED, uint32_t timeout = 1, bool debug = false);
|
||||
IOExpander(i2c_inst_t *i2c, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interrupt = PIN_UNUSED, uint32_t timeout = 1, bool debug = false);
|
||||
IOExpander(I2C *i2c, uint8_t address=DEFAULT_I2C_ADDRESS, uint8_t interrupt = PIN_UNUSED, uint32_t timeout = 1, bool debug = false);
|
||||
IOExpander(uint8_t address, uint sda, uint scl, uint interrupt = PIN_UNUSED, uint32_t timeout = 1, bool debug = false);
|
||||
IOExpander(i2c_inst_t *i2c, uint8_t address, uint sda, uint scl, uint interrupt = PIN_UNUSED, uint32_t timeout = 1, bool debug = false);
|
||||
IOExpander(I2C *i2c, uint8_t address=DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED, uint32_t timeout = 1, bool debug = false);
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
|
|
|
@ -112,10 +112,6 @@ namespace pimoroni {
|
|||
//--------------------------------------------------
|
||||
public:
|
||||
static const uint8_t DEFAULT_I2C_ADDRESS = 0x23;
|
||||
static const uint8_t DEFAULT_SDA_PIN = 20;
|
||||
static const uint8_t DEFAULT_SCL_PIN = 21;
|
||||
static const uint8_t DEFAULT_INT_PIN = 22;
|
||||
static const uint8_t PIN_UNUSED = UINT8_MAX;
|
||||
|
||||
private:
|
||||
const int ch0_c[4] = {17743, 42785, 5926, 0};
|
||||
|
@ -133,7 +129,7 @@ namespace pimoroni {
|
|||
|
||||
// interface pins with our standard defaults where appropriate
|
||||
uint8_t address = DEFAULT_I2C_ADDRESS;
|
||||
uint8_t interrupt = DEFAULT_INT_PIN;
|
||||
uint interrupt = PIN_UNUSED;
|
||||
|
||||
static pimoroni::lookup lookup_led_current;
|
||||
static pimoroni::lookup lookup_led_duty_cycle;
|
||||
|
@ -148,16 +144,10 @@ namespace pimoroni {
|
|||
// Constructors/Destructor
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
LTR559() {
|
||||
i2c = new I2C(DEFAULT_SDA_PIN, DEFAULT_SCL_PIN);
|
||||
};
|
||||
LTR559(uint8_t address) : address(address) {
|
||||
i2c = new I2C(DEFAULT_SDA_PIN, DEFAULT_SCL_PIN);
|
||||
};
|
||||
LTR559(i2c_inst_t *i2c_inst, uint8_t address, uint sda, uint scl, uint8_t interrupt = PIN_UNUSED) : address(address), interrupt(interrupt) {
|
||||
i2c = new I2C(sda, scl);
|
||||
}
|
||||
LTR559(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint8_t interrupt = PIN_UNUSED) :
|
||||
LTR559() : LTR559(DEFAULT_I2C_ADDRESS) {};
|
||||
LTR559(uint8_t address) : i2c(new I2C()), address(address) {};
|
||||
LTR559(i2c_inst_t *i2c_inst, uint8_t address, uint sda, uint scl, uint interrupt = PIN_UNUSED) : i2c(new I2C()), address(address), interrupt(interrupt) {}
|
||||
LTR559(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED) :
|
||||
i2c(i2c), address(address), interrupt(interrupt) {}
|
||||
|
||||
//--------------------------------------------------
|
||||
|
|
|
@ -13,10 +13,6 @@ namespace pimoroni {
|
|||
//--------------------------------------------------
|
||||
public:
|
||||
static const uint8_t DEFAULT_I2C_ADDRESS = 0x26;
|
||||
static const uint8_t DEFAULT_SDA_PIN = 20;
|
||||
static const uint8_t DEFAULT_SCL_PIN = 21;
|
||||
static const uint8_t DEFAULT_INT_PIN = 22;
|
||||
static const uint8_t PIN_UNUSED = UINT8_MAX;
|
||||
|
||||
static const uint8_t SOFT_RESET = 0x00;
|
||||
static const uint8_t PART_ID = 0x01;
|
||||
|
@ -109,26 +105,17 @@ namespace pimoroni {
|
|||
//--------------------------------------------------
|
||||
private:
|
||||
I2C *i2c;
|
||||
|
||||
// interface pins with our standard defaults where appropriate
|
||||
uint8_t address = DEFAULT_I2C_ADDRESS;
|
||||
uint interrupt = I2C_DEFAULT_INT;
|
||||
uint8_t address = DEFAULT_I2C_ADDRESS;
|
||||
uint interrupt = PIN_UNUSED;
|
||||
|
||||
//--------------------------------------------------
|
||||
// Constructors/Destructor
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
MSA301() {
|
||||
i2c = new I2C(DEFAULT_SDA_PIN, DEFAULT_SCL_PIN);
|
||||
};
|
||||
MSA301(uint8_t address) : address(address) {
|
||||
i2c = new I2C(DEFAULT_SDA_PIN, DEFAULT_SCL_PIN);
|
||||
};
|
||||
MSA301(i2c_inst_t *i2c_inst, uint8_t address, uint sda, uint scl, uint8_t interrupt = PIN_UNUSED) : address(address), interrupt(interrupt) {
|
||||
i2c = new I2C(sda, scl);
|
||||
}
|
||||
MSA301(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED) :
|
||||
i2c(i2c), address(address), interrupt(interrupt) {}
|
||||
MSA301() : MSA301(DEFAULT_I2C_ADDRESS) {};
|
||||
MSA301(uint8_t address) : i2c(new I2C()), address(address) {};
|
||||
MSA301(i2c_inst_t *i2c_inst, uint8_t address, uint sda, uint scl, uint interrupt = PIN_UNUSED) : i2c(new I2C(sda, scl)), address(address), interrupt(interrupt) {}
|
||||
MSA301(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED) : i2c(i2c), address(address), interrupt(interrupt) {}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
|
|
|
@ -18,8 +18,6 @@ namespace pimoroni {
|
|||
//--------------------------------------------------
|
||||
public:
|
||||
static const uint8_t DEFAULT_I2C_ADDRESS = 0x58;
|
||||
static const uint8_t DEFAULT_SDA_PIN = 20;
|
||||
static const uint8_t DEFAULT_SCL_PIN = 21;
|
||||
|
||||
private:
|
||||
/***** Private constants here *****/
|
||||
|
@ -48,20 +46,11 @@ namespace pimoroni {
|
|||
// Constructors/Destructor
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
SGP30() {
|
||||
i2c = new I2C(DEFAULT_SDA_PIN, DEFAULT_SCL_PIN);
|
||||
};
|
||||
SGP30(uint8_t address) : address(address) {
|
||||
i2c = new I2C(DEFAULT_SDA_PIN, DEFAULT_SCL_PIN);
|
||||
};
|
||||
SGP30(i2c_inst_t *i2c_inst, uint sda, uint scl) {
|
||||
i2c = new I2C(sda, scl);
|
||||
}
|
||||
SGP30(i2c_inst_t *i2c_inst, uint8_t address, uint sda, uint scl) : address(address) {
|
||||
i2c = new I2C(sda, scl);
|
||||
}
|
||||
SGP30(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED) :
|
||||
i2c(i2c), address(address) {}
|
||||
SGP30() : SGP30(DEFAULT_I2C_ADDRESS) {};
|
||||
SGP30(uint8_t address) : i2c(new I2C()), address(address) {};
|
||||
SGP30(i2c_inst_t *i2c_inst, uint sda, uint scl) : i2c(new I2C(sda, scl)) { }
|
||||
SGP30(i2c_inst_t *i2c_inst, uint8_t address, uint sda, uint scl) : i2c(new I2C(sda, scl)) , address(address) {}
|
||||
SGP30(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED) : i2c(i2c), address(address) {}
|
||||
|
||||
//--------------------------------------------------
|
||||
// Methods
|
||||
|
|
|
@ -7,4 +7,4 @@ target_sources(${DRIVER_NAME} INTERFACE
|
|||
target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib hardware_i2c)
|
||||
target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib hardware_i2c pimoroni_i2c)
|
||||
|
|
|
@ -42,12 +42,9 @@ namespace pimoroni {
|
|||
bool Trackball::init() {
|
||||
bool succeeded = false;
|
||||
|
||||
i2c_init(i2c, 100000);
|
||||
|
||||
gpio_set_function(sda, GPIO_FUNC_I2C);
|
||||
gpio_pull_up(sda);
|
||||
gpio_set_function(scl, GPIO_FUNC_I2C);
|
||||
gpio_pull_up(scl);
|
||||
if(i2c->get_baudrate() > 100000) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(interrupt != PIN_UNUSED) {
|
||||
gpio_set_function(interrupt, GPIO_FUNC_SIO);
|
||||
|
@ -55,7 +52,7 @@ namespace pimoroni {
|
|||
gpio_pull_up(interrupt);
|
||||
}
|
||||
|
||||
uint16_t chip_id = ((uint16_t)i2c_reg_read_uint8(reg::CHIP_ID_H) << 8) | (uint16_t)i2c_reg_read_uint8(reg::CHIP_ID_L);
|
||||
uint16_t chip_id = ((uint16_t)i2c->reg_read_uint8(address, reg::CHIP_ID_H) << 8) | (uint16_t)i2c->reg_read_uint8(address, reg::CHIP_ID_L);
|
||||
if(chip_id == CHIP_ID) {
|
||||
enable_interrupt();
|
||||
succeeded = true;
|
||||
|
@ -65,7 +62,7 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
i2c_inst_t* Trackball::get_i2c() const {
|
||||
return i2c;
|
||||
return i2c->get_i2c();
|
||||
}
|
||||
|
||||
int Trackball::get_address() const {
|
||||
|
@ -73,11 +70,11 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
int Trackball::get_sda() const {
|
||||
return sda;
|
||||
return i2c->get_sda();
|
||||
}
|
||||
|
||||
int Trackball::get_scl() const {
|
||||
return scl;
|
||||
return i2c->get_scl();
|
||||
}
|
||||
|
||||
int Trackball::get_int() const {
|
||||
|
@ -85,17 +82,17 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
void Trackball::change_address(uint8_t new_address) {
|
||||
i2c_reg_write_uint8(reg::I2C_ADDR, new_address);
|
||||
i2c->reg_write_uint8(address, reg::I2C_ADDR, new_address);
|
||||
wait_for_flash();
|
||||
}
|
||||
|
||||
void Trackball::enable_interrupt(bool use_interrupt) {
|
||||
uint8_t value = i2c_reg_read_uint8(reg::INT);
|
||||
uint8_t value = i2c->reg_read_uint8(address, reg::INT);
|
||||
value &= ~MSK_INT_OUT_EN;
|
||||
if(use_interrupt)
|
||||
value |= MSK_INT_OUT_EN;
|
||||
|
||||
i2c_reg_write_uint8(reg::INT, value);
|
||||
i2c->reg_write_uint8(address, reg::INT, value);
|
||||
}
|
||||
|
||||
bool Trackball::get_interrupt() {
|
||||
|
@ -105,61 +102,49 @@ namespace pimoroni {
|
|||
value = !gpio_get(interrupt);
|
||||
}
|
||||
else {
|
||||
value = i2c_reg_read_uint8(reg::INT);
|
||||
value = i2c->reg_read_uint8(address, reg::INT);
|
||||
value &= MSK_INT_TRIGGERED;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Trackball::set_rgbw(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
i2c_reg_write_uint8(reg::LED_RED, r);
|
||||
i2c_reg_write_uint8(reg::LED_GRN, g);
|
||||
i2c_reg_write_uint8(reg::LED_BLU, b);
|
||||
i2c_reg_write_uint8(reg::LED_WHT, w);
|
||||
i2c->reg_write_uint8(address, reg::LED_RED, r);
|
||||
i2c->reg_write_uint8(address, reg::LED_GRN, g);
|
||||
i2c->reg_write_uint8(address, reg::LED_BLU, b);
|
||||
i2c->reg_write_uint8(address, reg::LED_WHT, w);
|
||||
}
|
||||
|
||||
void Trackball::set_red(uint8_t value) {
|
||||
i2c_reg_write_uint8(reg::LED_RED, value);
|
||||
i2c->reg_write_uint8(address, reg::LED_RED, value);
|
||||
}
|
||||
|
||||
void Trackball::set_green(uint8_t value) {
|
||||
i2c_reg_write_uint8(reg::LED_GRN, value);
|
||||
i2c->reg_write_uint8(address, reg::LED_GRN, value);
|
||||
}
|
||||
|
||||
void Trackball::set_blue(uint8_t value) {
|
||||
i2c_reg_write_uint8(reg::LED_BLU, value);
|
||||
i2c->reg_write_uint8(address, reg::LED_BLU, value);
|
||||
}
|
||||
|
||||
void Trackball::set_white(uint8_t value) {
|
||||
i2c_reg_write_uint8(reg::LED_WHT, value);
|
||||
i2c->reg_write_uint8(address, reg::LED_WHT, value);
|
||||
}
|
||||
|
||||
Trackball::State Trackball::read() {
|
||||
State state;
|
||||
uint8_t sw_state;
|
||||
state.left = i2c_reg_read_uint8(reg::LEFT);
|
||||
state.right = i2c_reg_read_uint8(reg::RIGHT);
|
||||
state.up = i2c_reg_read_uint8(reg::UP);
|
||||
state.down = i2c_reg_read_uint8(reg::DOWN);
|
||||
sw_state = i2c_reg_read_uint8(reg::SWITCH);
|
||||
state.left = i2c->reg_read_uint8(address, reg::LEFT);
|
||||
state.right = i2c->reg_read_uint8(address, reg::RIGHT);
|
||||
state.up = i2c->reg_read_uint8(address, reg::UP);
|
||||
state.down = i2c->reg_read_uint8(address, reg::DOWN);
|
||||
sw_state = i2c->reg_read_uint8(address, reg::SWITCH);
|
||||
|
||||
state.sw_changed = sw_state & ~MSK_SWITCH_STATE;
|
||||
state.sw_pressed = (sw_state & MSK_SWITCH_STATE) > 0;
|
||||
return state;
|
||||
}
|
||||
|
||||
uint8_t Trackball::i2c_reg_read_uint8(uint8_t reg) {
|
||||
uint8_t value;
|
||||
i2c_write_blocking(i2c, address, ®, 1, true);
|
||||
i2c_read_blocking(i2c, address, (uint8_t *)&value, 1, false);
|
||||
return value;
|
||||
}
|
||||
|
||||
void Trackball::i2c_reg_write_uint8(uint8_t reg, uint8_t value) {
|
||||
uint8_t buffer[2] = {reg, value};
|
||||
i2c_write_blocking(i2c, address, buffer, 2, false);
|
||||
}
|
||||
|
||||
void Trackball::wait_for_flash(void) {
|
||||
unsigned long start_time = millis();
|
||||
while(get_interrupt()) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "hardware/i2c.h"
|
||||
#include "hardware/gpio.h"
|
||||
#include "common/pimoroni_i2c.hpp"
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
|
@ -12,11 +13,7 @@ namespace pimoroni {
|
|||
public:
|
||||
static const uint8_t DEFAULT_I2C_ADDRESS = 0x0A;
|
||||
static const uint8_t I2C_ADDRESS_ALTERNATIVE = 0x0B;
|
||||
static const uint8_t DEFAULT_SDA_PIN = 20;
|
||||
static const uint8_t DEFAULT_SCL_PIN = 21;
|
||||
static const uint8_t DEFAULT_INT_PIN = 22;
|
||||
static const uint32_t DEFAULT_TIMEOUT = 5;
|
||||
static const uint8_t PIN_UNUSED = UINT8_MAX;
|
||||
|
||||
private:
|
||||
static const uint16_t CHIP_ID = 0xBA11;
|
||||
|
@ -41,13 +38,9 @@ namespace pimoroni {
|
|||
// Variables
|
||||
//--------------------------------------------------
|
||||
private:
|
||||
i2c_inst_t *i2c = i2c0;
|
||||
|
||||
// interface pins with our standard defaults where appropriate
|
||||
I2C *i2c;
|
||||
int8_t address = DEFAULT_I2C_ADDRESS;
|
||||
int8_t sda = DEFAULT_SDA_PIN;
|
||||
int8_t scl = DEFAULT_SCL_PIN;
|
||||
int8_t interrupt = DEFAULT_INT_PIN;
|
||||
uint interrupt = PIN_UNUSED;
|
||||
uint32_t timeout = DEFAULT_TIMEOUT;
|
||||
|
||||
|
||||
|
@ -55,13 +48,10 @@ namespace pimoroni {
|
|||
// Constructors/Destructor
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
Trackball() {};
|
||||
|
||||
Trackball(uint8_t address) :
|
||||
address(address) {}
|
||||
|
||||
Trackball(i2c_inst_t *i2c, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interrupt = PIN_UNUSED, uint32_t timeout = DEFAULT_TIMEOUT) :
|
||||
i2c(i2c), address(address), sda(sda), scl(scl), interrupt(interrupt), timeout(timeout) {}
|
||||
Trackball() : Trackball(DEFAULT_I2C_ADDRESS) {};
|
||||
Trackball(uint8_t address) : i2c(new I2C()), address(address) {};
|
||||
Trackball(i2c_inst_t *i2c_inst, uint8_t address, uint sda, uint scl, uint interrupt = PIN_UNUSED, uint32_t timeout = DEFAULT_TIMEOUT) : i2c(new I2C(sda, scl)), address(address), interrupt(interrupt) {}
|
||||
Trackball(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED, uint32_t timeout = DEFAULT_TIMEOUT) : i2c(i2c), address(address), interrupt(interrupt) {}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
|
@ -88,9 +78,6 @@ namespace pimoroni {
|
|||
State read();
|
||||
|
||||
private:
|
||||
uint8_t i2c_reg_read_uint8(uint8_t reg);
|
||||
void i2c_reg_write_uint8(uint8_t reg, uint8_t value);
|
||||
|
||||
void wait_for_flash();
|
||||
|
||||
uint32_t millis();
|
||||
|
|
|
@ -7,4 +7,4 @@ target_sources(vl53l1x INTERFACE
|
|||
target_include_directories(vl53l1x INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Pull in pico libraries that we need
|
||||
target_link_libraries(vl53l1x INTERFACE pico_stdlib hardware_i2c)
|
||||
target_link_libraries(vl53l1x INTERFACE pico_stdlib hardware_i2c pimoroni_i2c)
|
||||
|
|
|
@ -37,12 +37,6 @@ namespace pimoroni {
|
|||
saved_vhv_timeout = 0;
|
||||
// distance_mode = 1;
|
||||
|
||||
// Initialise I2C connection
|
||||
i2c_init(i2c, 400000);
|
||||
|
||||
gpio_set_function(sda, GPIO_FUNC_I2C); gpio_pull_up(sda);
|
||||
gpio_set_function(scl, GPIO_FUNC_I2C); gpio_pull_up(scl);
|
||||
|
||||
last_status = 0;
|
||||
|
||||
// check model ID and module type registers (values specified in datasheet)
|
||||
|
@ -169,14 +163,14 @@ namespace pimoroni {
|
|||
void VL53L1X::writeReg(uint16_t reg, uint8_t value)
|
||||
{
|
||||
uint8_t buffer[3] = {(reg >> 8) & 0xFF, reg & 0xFF, value};
|
||||
i2c_write_blocking(i2c, address, buffer, 3, false);
|
||||
i2c->write_blocking(address, buffer, 3, false);
|
||||
}
|
||||
|
||||
// Write a 16-bit register
|
||||
void VL53L1X::writeReg16Bit(uint16_t reg, uint16_t value)
|
||||
{
|
||||
uint8_t buffer[4] = {(reg >> 8) & 0xFF, reg & 0xFF, (value >> 8) & 0xFF, value & 0xFF};
|
||||
i2c_write_blocking(i2c, address, buffer, 4, false);
|
||||
i2c->write_blocking(address, buffer, 4, false);
|
||||
}
|
||||
|
||||
// Write a 32-bit register
|
||||
|
@ -184,7 +178,7 @@ namespace pimoroni {
|
|||
{
|
||||
uint8_t buffer[6] = {(reg >> 8) & 0xFF, reg & 0xFF,
|
||||
(value >> 24) & 0xFF, (value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF};
|
||||
i2c_write_blocking(i2c, address, buffer, 6, false);
|
||||
i2c->write_blocking(address, buffer, 6, false);
|
||||
}
|
||||
|
||||
// Read an 8-bit register
|
||||
|
@ -193,8 +187,8 @@ namespace pimoroni {
|
|||
uint8_t regbuf[2] = {((uint8_t)reg >> 8) & 0xFF, (uint8_t)reg & 0xFF};
|
||||
uint8_t buffer[1];
|
||||
uint8_t value;
|
||||
i2c_write_blocking(i2c, address, regbuf, 2, true);
|
||||
i2c_read_blocking(i2c, address, buffer, 1, false);
|
||||
i2c->write_blocking(address, regbuf, 2, true);
|
||||
i2c->read_blocking(address, buffer, 1, false);
|
||||
value = buffer[0];
|
||||
return value;
|
||||
}
|
||||
|
@ -206,8 +200,8 @@ namespace pimoroni {
|
|||
uint8_t buffer[2];
|
||||
uint16_t value;
|
||||
reg= (reg << 8) + (reg >> 8);
|
||||
i2c_write_blocking(i2c, address, regbuf, 2, true);
|
||||
i2c_read_blocking(i2c, address, buffer, 2, false);
|
||||
i2c->write_blocking(address, regbuf, 2, true);
|
||||
i2c->read_blocking(address, buffer, 2, false);
|
||||
value= (buffer[0] << 8) + buffer[1];
|
||||
return value;
|
||||
}
|
||||
|
@ -219,8 +213,8 @@ namespace pimoroni {
|
|||
uint8_t buffer[4];
|
||||
uint32_t value;
|
||||
reg= (reg << 8) + (reg >> 8);
|
||||
i2c_write_blocking(i2c, address, regbuf, 2, true);
|
||||
i2c_read_blocking(i2c, address, buffer, 4, false);
|
||||
i2c->write_blocking(address, regbuf, 2, true);
|
||||
i2c->read_blocking(address, buffer, 4, false);
|
||||
value= (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3];
|
||||
return value;
|
||||
}
|
||||
|
@ -580,8 +574,8 @@ namespace pimoroni {
|
|||
uint16_t reg = RESULT__RANGE_STATUS;
|
||||
uint8_t regbuf[2] = {(reg >> 8) & 0xFF, reg & 0xFF};
|
||||
uint8_t buffer[17];
|
||||
i2c_write_blocking(i2c, address, regbuf, 2, true);
|
||||
i2c_read_blocking(i2c, address, buffer, 17, false);
|
||||
i2c->write_blocking(address, regbuf, 2, true);
|
||||
i2c->read_blocking(address, buffer, 17, false);
|
||||
|
||||
results.range_status = buffer[0];
|
||||
|
||||
|
|
|
@ -15,17 +15,17 @@ Distributed as-is; no warranty is given.
|
|||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "common/pimoroni_i2c.hpp"
|
||||
|
||||
namespace pimoroni {
|
||||
|
||||
class VL53L1X {
|
||||
static const uint8_t DEFAULT_I2C_ADDRESS = 0x29;
|
||||
|
||||
i2c_inst_t *i2c = i2c0;
|
||||
I2C *i2c;
|
||||
|
||||
int8_t address = 0x29;
|
||||
int8_t sda = 20;
|
||||
int8_t scl = 21;
|
||||
int8_t interrupt = 22;
|
||||
int8_t address = DEFAULT_I2C_ADDRESS;
|
||||
uint interrupt = 22;
|
||||
|
||||
// register addresses from API vl53l1x_register_map.h
|
||||
enum regAddr : uint16_t
|
||||
|
@ -1291,7 +1291,10 @@ namespace pimoroni {
|
|||
uint8_t last_status; // status of last I2C transmission
|
||||
|
||||
public:
|
||||
VL53L1X() {}
|
||||
VL53L1X() : VL53L1X(DEFAULT_I2C_ADDRESS) {};
|
||||
VL53L1X(uint8_t address) : i2c(new I2C()), address(address) {};
|
||||
VL53L1X(i2c_inst_t *i2c_inst, uint8_t address, uint sda, uint scl, uint interrupt = PIN_UNUSED) : i2c(new I2C()), address(address), interrupt(interrupt) {}
|
||||
VL53L1X(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED) : i2c(i2c), address(address), interrupt(interrupt) {}
|
||||
|
||||
uint16_t getid();
|
||||
uint16_t getosc();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using namespace pimoroni;
|
||||
|
||||
I2C i2c(4, 5);
|
||||
I2C i2c(BOARD::BREAKOUT_GARDEN);
|
||||
BreakoutLTR559 ltr559(&i2c);
|
||||
|
||||
int main() {
|
||||
|
@ -14,7 +14,13 @@ int main() {
|
|||
ltr559.init();
|
||||
|
||||
uint8_t part_id = ltr559.part_id();
|
||||
printf("Found LTR559. Part ID: 0x%02x\n", part_id);
|
||||
if(part_id == LTR559_VALID_PART_ID) {
|
||||
printf("Found LTR559. Part ID: 0x%02x\n", part_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Could not find LTR559. Got Part ID: 0x%02x, expected 0x%02x\n", part_id, LTR559_VALID_PART_ID);
|
||||
}
|
||||
|
||||
while(true){
|
||||
bool new_data = ltr559.get_reading();
|
||||
|
|
|
@ -7,11 +7,19 @@ using namespace pimoroni;
|
|||
|
||||
static const uint8_t SENSITIVITY = 2;
|
||||
|
||||
|
||||
BreakoutTrackball trackball;
|
||||
// Trackball requires I2C at 100kHz or less.
|
||||
I2C i2c(BOARD::BREAKOUT_GARDEN, 100000);
|
||||
BreakoutTrackball trackball(&i2c);
|
||||
|
||||
int main() {
|
||||
trackball.init();
|
||||
stdio_init_all();
|
||||
|
||||
if(!trackball.init()) {
|
||||
printf("Trackball failed to init!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Roll the Trackball to change colour!\n");
|
||||
|
||||
trackball.set_rgbw(0, 0, 0, 64);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
BreakoutColourLCD160x80::BreakoutColourLCD160x80(uint16_t *buf, spi_inst_t *spi,
|
||||
uint8_t cs, uint8_t dc, uint8_t sck, uint8_t mosi, uint8_t miso, uint8_t bl)
|
||||
uint cs, uint dc, uint sck, uint mosi, uint miso, uint bl)
|
||||
: PicoGraphics(WIDTH, HEIGHT, buf), screen(WIDTH, HEIGHT, buf, spi, cs, dc, sck, mosi, miso, bl) {
|
||||
__fb = buf;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@ namespace pimoroni {
|
|||
public:
|
||||
static const int WIDTH = 160;
|
||||
static const int HEIGHT = 80;
|
||||
static const uint8_t PIN_UNUSED = UINT8_MAX;
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Variables
|
||||
|
@ -31,7 +29,7 @@ namespace pimoroni {
|
|||
public:
|
||||
BreakoutColourLCD160x80(uint16_t *buf);
|
||||
BreakoutColourLCD160x80(uint16_t *buf, spi_inst_t *spi,
|
||||
uint8_t cs, uint8_t dc, uint8_t sck, uint8_t mosi, uint8_t miso = PIN_UNUSED, uint8_t bl = PIN_UNUSED);
|
||||
uint cs, uint dc, uint sck, uint mosi, uint miso = PIN_UNUSED, uint bl = PIN_UNUSED);
|
||||
BreakoutColourLCD160x80(uint16_t *buf, BG_SPI_SLOT slot);
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
BreakoutColourLCD240x240::BreakoutColourLCD240x240(uint16_t *buf, spi_inst_t *spi,
|
||||
uint8_t cs, uint8_t dc, uint8_t sck, uint8_t mosi, uint8_t miso, uint8_t bl)
|
||||
uint cs, uint dc, uint sck, uint mosi, uint miso, uint bl)
|
||||
: PicoGraphics(WIDTH, HEIGHT, buf), screen(WIDTH, HEIGHT, buf, spi, cs, dc, sck, mosi, miso, bl) {
|
||||
__fb = buf;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@ namespace pimoroni {
|
|||
public:
|
||||
static const int WIDTH = 240;
|
||||
static const int HEIGHT = 240;
|
||||
static const uint8_t PIN_UNUSED = UINT8_MAX;
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// Variables
|
||||
|
@ -31,7 +29,7 @@ namespace pimoroni {
|
|||
public:
|
||||
BreakoutColourLCD240x240(uint16_t *buf);
|
||||
BreakoutColourLCD240x240(uint16_t *buf, spi_inst_t *spi,
|
||||
uint8_t cs, uint8_t dc, uint8_t sck, uint8_t mosi, uint8_t miso = PIN_UNUSED, uint8_t bl = PIN_UNUSED);
|
||||
uint cs, uint dc, uint sck, uint mosi, uint miso = PIN_UNUSED, uint bl = PIN_UNUSED);
|
||||
BreakoutColourLCD240x240(uint16_t *buf, BG_SPI_SLOT slot);
|
||||
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace pimoroni {
|
|||
IOExpander ioe;
|
||||
Direction direction = DEFAULT_DIRECTION;
|
||||
float brightness = DEFAULT_BRIGHTNESS;
|
||||
uint8_t interrupt_pin = PIN_UNUSED; // A local copy of the value passed to the IOExpander, used in initialisation
|
||||
uint interrupt_pin = PIN_UNUSED; // A local copy of the value passed to the IOExpander, used in initialisation
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
|
@ -60,10 +60,10 @@ namespace pimoroni {
|
|||
BreakoutEncoder(uint8_t address) :
|
||||
ioe(address) {}
|
||||
|
||||
BreakoutEncoder(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint8_t interrupt = PIN_UNUSED, uint32_t timeout = DEFAULT_TIMEOUT, bool debug = false) :
|
||||
BreakoutEncoder(I2C *i2c, uint8_t address = DEFAULT_I2C_ADDRESS, uint interrupt = PIN_UNUSED, uint32_t timeout = DEFAULT_TIMEOUT, bool debug = false) :
|
||||
ioe(i2c, address, interrupt, timeout, debug) {}
|
||||
|
||||
BreakoutEncoder(i2c_inst_t *i2c, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interrupt = PIN_UNUSED, uint32_t timeout = DEFAULT_TIMEOUT) :
|
||||
BreakoutEncoder(i2c_inst_t *i2c, uint8_t address, uint8_t sda, uint8_t scl, uint interrupt = PIN_UNUSED, uint32_t timeout = DEFAULT_TIMEOUT) :
|
||||
ioe(i2c, address, sda, scl, interrupt, timeout),
|
||||
interrupt_pin(interrupt) {}
|
||||
|
||||
|
|
|
@ -47,9 +47,9 @@ mp_obj_t BreakoutAS7262_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
|||
enum { ARG_i2c, ARG_sda, ARG_scl, 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 = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = BreakoutAS7262::PIN_UNUSED} },
|
||||
{ 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} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -120,7 +120,7 @@ mp_obj_t BreakoutColourLCD160x80_make_new(const mp_obj_type_t *type, size_t n_ar
|
|||
|
||||
spi_inst_t *spi = (spi_id == 0) ? spi0 : spi1;
|
||||
self->breakout = new BreakoutColourLCD160x80((uint16_t *)bufinfo.buf, spi,
|
||||
args[ARG_cs].u_int, args[ARG_dc].u_int, sck, mosi, BreakoutColourLCD160x80::PIN_UNUSED, args[ARG_bl].u_int);
|
||||
args[ARG_cs].u_int, args[ARG_dc].u_int, sck, mosi, PIN_UNUSED, args[ARG_bl].u_int);
|
||||
}
|
||||
|
||||
self->breakout->init();
|
||||
|
|
|
@ -120,7 +120,7 @@ mp_obj_t BreakoutColourLCD240x240_make_new(const mp_obj_type_t *type, size_t n_a
|
|||
|
||||
spi_inst_t *spi = (spi_id == 0) ? spi0 : spi1;
|
||||
self->breakout = new BreakoutColourLCD240x240((uint16_t *)bufinfo.buf, spi,
|
||||
args[ARG_cs].u_int, args[ARG_dc].u_int, sck, mosi, BreakoutColourLCD240x240::PIN_UNUSED, args[ARG_bl].u_int);
|
||||
args[ARG_cs].u_int, args[ARG_dc].u_int, sck, mosi, PIN_UNUSED, args[ARG_bl].u_int);
|
||||
}
|
||||
|
||||
self->breakout->init();
|
||||
|
|
|
@ -51,8 +51,8 @@ mp_obj_t BreakoutDotMatrix_make_new(const mp_obj_type_t *type, size_t n_args, si
|
|||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutDotMatrix::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -54,9 +54,9 @@ mp_obj_t BreakoutEncoder_make_new(const mp_obj_type_t *type, size_t n_args, size
|
|||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutEncoder::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = BreakoutEncoder::PIN_UNUSED} },
|
||||
{ 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} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -54,9 +54,9 @@ mp_obj_t BreakoutIOExpander_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutIOExpander::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = BreakoutIOExpander::PIN_UNUSED} },
|
||||
{ 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} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -54,9 +54,9 @@ mp_obj_t BreakoutLTR559_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
|||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutLTR559::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = BreakoutLTR559::PIN_UNUSED} },
|
||||
{ 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} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -51,8 +51,8 @@ mp_obj_t BreakoutMatrix11x7_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||
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 = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -54,9 +54,9 @@ mp_obj_t BreakoutMICS6814_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
|||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutMICS6814::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = BreakoutMICS6814::PIN_UNUSED} },
|
||||
{ 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} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -47,9 +47,9 @@ mp_obj_t BreakoutMSA301_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
|||
enum { ARG_i2c, ARG_sda, ARG_scl, 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 = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = BreakoutMSA301::PIN_UNUSED} },
|
||||
{ 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} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -54,9 +54,9 @@ mp_obj_t BreakoutPotentiometer_make_new(const mp_obj_type_t *type, size_t n_args
|
|||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutPotentiometer::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = BreakoutPotentiometer::PIN_UNUSED} },
|
||||
{ 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} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -51,8 +51,8 @@ mp_obj_t BreakoutRGBMatrix5x5_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
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 = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -120,7 +120,7 @@ mp_obj_t BreakoutRoundLCD_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
|||
|
||||
spi_inst_t *spi = (spi_id == 0) ? spi0 : spi1;
|
||||
self->breakout = new BreakoutRoundLCD((uint16_t *)bufinfo.buf, spi,
|
||||
args[ARG_cs].u_int, args[ARG_dc].u_int, sck, mosi, BreakoutRoundLCD::PIN_UNUSED, args[ARG_bl].u_int);
|
||||
args[ARG_cs].u_int, args[ARG_dc].u_int, sck, mosi, PIN_UNUSED, args[ARG_bl].u_int);
|
||||
}
|
||||
|
||||
self->breakout->init();
|
||||
|
|
|
@ -50,9 +50,9 @@ mp_obj_t BreakoutRTC_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
|||
enum { ARG_i2c, ARG_sda, ARG_scl, 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 = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = BreakoutRTC::PIN_UNUSED} },
|
||||
{ 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} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -44,8 +44,8 @@ mp_obj_t BreakoutSGP30_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
|||
enum { ARG_i2c, ARG_sda, ARG_scl };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = I2C_DEFAULT_SDA} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = I2C_DEFAULT_SCL} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
|
@ -54,9 +54,9 @@ mp_obj_t BreakoutTrackball_make_new(const mp_obj_type_t *type, size_t n_args, si
|
|||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_i2c, MP_ARG_INT, {.u_int = -1} },
|
||||
{ MP_QSTR_address, MP_ARG_INT, {.u_int = BreakoutTrackball::DEFAULT_I2C_ADDRESS} },
|
||||
{ MP_QSTR_sda, MP_ARG_INT, {.u_int = 20} },
|
||||
{ MP_QSTR_scl, MP_ARG_INT, {.u_int = 21} },
|
||||
{ MP_QSTR_interrupt, MP_ARG_INT, {.u_int = BreakoutTrackball::PIN_UNUSED} },
|
||||
{ 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} },
|
||||
};
|
||||
|
||||
// Parse args.
|
||||
|
|
Ładowanie…
Reference in New Issue