summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/_eve/__init__.c20
-rw-r--r--shared-module/adafruit_bus_device/I2CDevice.c50
-rw-r--r--shared-module/adafruit_bus_device/I2CDevice.h2
-rw-r--r--shared-module/adafruit_bus_device/SPIDevice.c7
-rw-r--r--shared-module/rgbmatrix/RGBMatrix.c11
-rw-r--r--shared-module/rgbmatrix/RGBMatrix.h2
6 files changed, 59 insertions, 33 deletions
diff --git a/shared-module/_eve/__init__.c b/shared-module/_eve/__init__.c
index d95c777dc..579729d42 100644
--- a/shared-module/_eve/__init__.c
+++ b/shared-module/_eve/__init__.c
@@ -226,8 +226,9 @@ void common_hal__eve_Jump(common_hal__eve_t *eve, uint32_t dest) {
}
-void common_hal__eve_LineWidth(common_hal__eve_t *eve, uint32_t width) {
- C4(eve, ((14 << 24) | ((width & 4095))));
+void common_hal__eve_LineWidth(common_hal__eve_t *eve, mp_float_t width) {
+ int16_t iw = (int)(8 * width);
+ C4(eve, ((14 << 24) | ((iw & 4095))));
}
@@ -246,8 +247,9 @@ void common_hal__eve_PaletteSource(common_hal__eve_t *eve, uint32_t addr) {
}
-void common_hal__eve_PointSize(common_hal__eve_t *eve, uint32_t size) {
- C4(eve, ((13 << 24) | ((size & 8191))));
+void common_hal__eve_PointSize(common_hal__eve_t *eve, mp_float_t size) {
+ int16_t is = (int)(8 * size);
+ C4(eve, ((13 << 24) | ((is & 8191))));
}
@@ -301,13 +303,15 @@ void common_hal__eve_Tag(common_hal__eve_t *eve, uint32_t s) {
}
-void common_hal__eve_VertexTranslateX(common_hal__eve_t *eve, uint32_t x) {
- C4(eve, ((43 << 24) | (((x) & 131071))));
+void common_hal__eve_VertexTranslateX(common_hal__eve_t *eve, mp_float_t x) {
+ int16_t ix = (int)(16 * x);
+ C4(eve, ((43 << 24) | (ix & 131071)));
}
-void common_hal__eve_VertexTranslateY(common_hal__eve_t *eve, uint32_t y) {
- C4(eve, ((44 << 24) | (((y) & 131071))));
+void common_hal__eve_VertexTranslateY(common_hal__eve_t *eve, mp_float_t y) {
+ int16_t iy = (int)(16 * y);
+ C4(eve, ((44 << 24) | (iy & 131071)));
}
diff --git a/shared-module/adafruit_bus_device/I2CDevice.c b/shared-module/adafruit_bus_device/I2CDevice.c
index 83abe80d6..6d80cf599 100644
--- a/shared-module/adafruit_bus_device/I2CDevice.c
+++ b/shared-module/adafruit_bus_device/I2CDevice.c
@@ -31,48 +31,60 @@
#include "py/runtime.h"
#include "lib/utils/interrupt_char.h"
-void common_hal_adafruit_bus_device_i2cdevice_construct(adafruit_bus_device_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, mp_obj_t *i2c, uint8_t device_address) {
self->i2c = i2c;
self->device_address = device_address;
}
void common_hal_adafruit_bus_device_i2cdevice_lock(adafruit_bus_device_i2cdevice_obj_t *self) {
- bool success = common_hal_busio_i2c_try_lock(self->i2c);
+ mp_obj_t dest[2];
+ mp_load_method(self->i2c, MP_QSTR_try_lock, dest);
- while (!success) {
+ mp_obj_t success = mp_call_method_n_kw(0, 0, dest);
+
+ while (!mp_obj_is_true(success)) {
RUN_BACKGROUND_TASKS;
if (mp_hal_is_interrupted()) {
break;
}
- success = common_hal_busio_i2c_try_lock(self->i2c);
+ success = mp_call_method_n_kw(0, 0, dest);
}
}
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_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_adafruit_bus_device_i2cdevice_write(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t buffer, size_t length, bool transmit_stop_bit) {
- return common_hal_busio_i2c_write(self->i2c, self->device_address, buffer, length, transmit_stop_bit);
+ mp_obj_t dest[2];
+ mp_load_method(self->i2c, MP_QSTR_unlock, dest);
+ mp_call_method_n_kw(0, 0, dest);
}
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_buffer_info_t write_bufinfo;
+ mp_obj_t write_buffer = mp_obj_new_bytearray_of_zeros(0);
+ mp_get_buffer_raise(write_buffer, &write_bufinfo, MP_BUFFER_READ);
- mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_WRITE);
+ mp_obj_t dest[4];
- uint8_t status = common_hal_adafruit_bus_device_i2cdevice_readinto(self, (uint8_t*)bufinfo.buf, 1);
- if (status != 0) {
+ /* catch exceptions that may be thrown while probing for the device */
+ nlr_buf_t nlr;
+ if (nlr_push(&nlr) == 0) {
+ mp_load_method(self->i2c, MP_QSTR_writeto, dest);
+ dest[2] = MP_OBJ_NEW_SMALL_INT(self->device_address);
+ dest[3] = write_buffer;
+ mp_call_method_n_kw(2, 0, dest);
+ nlr_pop();
+ } else {
common_hal_adafruit_bus_device_i2cdevice_unlock(self);
- mp_raise_ValueError_varg(translate("No I2C device at address: %x"), self->device_address);
+
+ if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t*)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_OSError))) {
+ mp_raise_ValueError_varg(translate("No I2C device at address: %x"), self->device_address);
+ }
+ else {
+ /* In case we receive an unrelated exception pass it up */
+ nlr_raise(MP_OBJ_FROM_PTR(nlr.ret_val));
+ }
}
common_hal_adafruit_bus_device_i2cdevice_unlock(self);
diff --git a/shared-module/adafruit_bus_device/I2CDevice.h b/shared-module/adafruit_bus_device/I2CDevice.h
index d06adb9f5..b76bafb2c 100644
--- a/shared-module/adafruit_bus_device/I2CDevice.h
+++ b/shared-module/adafruit_bus_device/I2CDevice.h
@@ -32,7 +32,7 @@
typedef struct {
mp_obj_base_t base;
- busio_i2c_obj_t *i2c;
+ mp_obj_t *i2c;
uint8_t device_address;
} adafruit_bus_device_i2cdevice_obj_t;
diff --git a/shared-module/adafruit_bus_device/SPIDevice.c b/shared-module/adafruit_bus_device/SPIDevice.c
index e489fc7c0..5c1a69b12 100644
--- a/shared-module/adafruit_bus_device/SPIDevice.c
+++ b/shared-module/adafruit_bus_device/SPIDevice.c
@@ -41,7 +41,7 @@ void common_hal_adafruit_bus_device_spidevice_construct(adafruit_bus_device_spid
self->chip_select = cs;
}
-void common_hal_adafruit_bus_device_spidevice_enter(adafruit_bus_device_spidevice_obj_t *self) {
+mp_obj_t 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);
@@ -54,6 +54,7 @@ void common_hal_adafruit_bus_device_spidevice_enter(adafruit_bus_device_spidevic
if (self->chip_select != MP_OBJ_NULL) {
common_hal_digitalio_digitalinout_set_value(MP_OBJ_TO_PTR(self->chip_select), false);
}
+ return self->spi;
}
void common_hal_adafruit_bus_device_spidevice_exit(adafruit_bus_device_spidevice_obj_t *self) {
@@ -83,3 +84,7 @@ void common_hal_adafruit_bus_device_spidevice_exit(adafruit_bus_device_spidevice
common_hal_busio_spi_unlock(self->spi);
}
+
+mp_obj_t common_hal_adafruit_bus_device_spidevice_get_spi(adafruit_bus_device_spidevice_obj_t *self) {
+ return self->spi;
+}
diff --git a/shared-module/rgbmatrix/RGBMatrix.c b/shared-module/rgbmatrix/RGBMatrix.c
index a09767b62..b8db0d893 100644
--- a/shared-module/rgbmatrix/RGBMatrix.c
+++ b/shared-module/rgbmatrix/RGBMatrix.c
@@ -42,7 +42,7 @@
extern Protomatter_core *_PM_protoPtr;
-void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, int width, int bit_depth, uint8_t rgb_count, uint8_t *rgb_pins, uint8_t addr_count, uint8_t *addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, void *timer) {
+void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, int width, int bit_depth, uint8_t rgb_count, uint8_t *rgb_pins, uint8_t addr_count, uint8_t *addr_pins, uint8_t clock_pin, uint8_t latch_pin, uint8_t oe_pin, bool doublebuffer, mp_obj_t framebuffer, int8_t tile, bool serpentine, void *timer) {
self->width = width;
self->bit_depth = bit_depth;
self->rgb_count = rgb_count;
@@ -53,6 +53,8 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
self->oe_pin = oe_pin;
self->latch_pin = latch_pin;
self->doublebuffer = doublebuffer;
+ self->tile = tile;
+ self->serpentine = serpentine;
self->timer = timer ? timer : common_hal_rgbmatrix_timer_allocate();
if (self->timer == NULL) {
@@ -60,7 +62,7 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
}
self->width = width;
- self->bufsize = 2 * width * rgb_count / 3 * (1 << addr_count);
+ self->bufsize = 2 * width * common_hal_rgbmatrix_rgbmatrix_get_height(self);
common_hal_rgbmatrix_rgbmatrix_reconstruct(self, framebuffer);
}
@@ -95,7 +97,8 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
self->rgb_count/6, self->rgb_pins,
self->addr_count, self->addr_pins,
self->clock_pin, self->latch_pin, self->oe_pin,
- self->doublebuffer, self->timer);
+ self->doublebuffer, self->serpentine ? -self->tile : self->tile,
+ self->timer);
if (stat == PROTOMATTER_OK) {
_PM_protoPtr = &self->protomatter;
@@ -209,7 +212,7 @@ int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self) {
}
int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
- int computed_height = (self->rgb_count / 3) << (self->addr_count);
+ int computed_height = (self->rgb_count / 3) * (1 << (self->addr_count)) * self->tile;
return computed_height;
}
diff --git a/shared-module/rgbmatrix/RGBMatrix.h b/shared-module/rgbmatrix/RGBMatrix.h
index 6dbc6fd41..4a0e9235e 100644
--- a/shared-module/rgbmatrix/RGBMatrix.h
+++ b/shared-module/rgbmatrix/RGBMatrix.h
@@ -44,4 +44,6 @@ typedef struct {
bool core_is_initialized;
bool paused;
bool doublebuffer;
+ bool serpentine;
+ int8_t tile;
} rgbmatrix_rgbmatrix_obj_t;