summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorKevin Matocha <kmatocha@icloud.com>2021-03-17 09:30:51 -0500
committerKevin Matocha <kmatocha@icloud.com>2021-03-17 09:30:51 -0500
commitef91e1752c233e45bfa898eb67caab44f1b02313 (patch)
tree9b6f26eb1bd0d54143b4d174cec720dcaca8065e /shared-module
parent870dadc85adce4f10fa57dda1d11dda48b25dbc1 (diff)
parentbfc8c89536e12dba0cc9adc0065819d730bb0983 (diff)
merge upstream/main
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/_bleio/Characteristic.h18
-rw-r--r--shared-module/_bleio/ScanEntry.c6
-rw-r--r--shared-module/_bleio/ScanEntry.h2
-rw-r--r--shared-module/_bleio/ScanResults.c36
-rw-r--r--shared-module/_bleio/ScanResults.h28
-rw-r--r--shared-module/_eve/__init__.c22
-rw-r--r--shared-module/_pixelbuf/PixelBuf.c55
-rw-r--r--shared-module/_stage/Layer.c2
-rw-r--r--shared-module/_stage/Text.c2
-rw-r--r--shared-module/_stage/__init__.c20
-rw-r--r--shared-module/_stage/__init__.h8
-rw-r--r--shared-module/adafruit_bus_device/I2CDevice.c5
-rw-r--r--shared-module/adafruit_bus_device/SPIDevice.c7
-rw-r--r--shared-module/aesio/__init__.c74
-rw-r--r--shared-module/aesio/aes.c734
-rw-r--r--shared-module/aesio/aes.h50
-rw-r--r--shared-module/audiocore/RawSample.c50
-rw-r--r--shared-module/audiocore/RawSample.h24
-rw-r--r--shared-module/audiocore/WaveFile.c58
-rw-r--r--shared-module/audiocore/WaveFile.h28
-rw-r--r--shared-module/audiocore/__init__.c30
-rw-r--r--shared-module/audiocore/__init__.h22
-rw-r--r--shared-module/audiomixer/Mixer.c106
-rw-r--r--shared-module/audiomixer/Mixer.h26
-rw-r--r--shared-module/audiomixer/MixerVoice.c24
-rw-r--r--shared-module/audiomixer/MixerVoice.h6
-rw-r--r--shared-module/audiomp3/MP3Decoder.c113
-rw-r--r--shared-module/audiomp3/MP3Decoder.h30
-rw-r--r--shared-module/bitbangio/I2C.c12
-rw-r--r--shared-module/bitbangio/OneWire.c16
-rw-r--r--shared-module/bitbangio/SPI.c8
-rw-r--r--shared-module/bitbangio/SPI.h10
-rw-r--r--shared-module/bitmaptools/__init__.c239
-rw-r--r--shared-module/bitops/__init__.c126
-rw-r--r--shared-module/board/__init__.c60
-rw-r--r--shared-module/busio/I2C.c6
-rw-r--r--shared-module/busio/OneWire.c16
-rw-r--r--shared-module/canio/Message.c24
-rw-r--r--shared-module/canio/Message.h4
-rw-r--r--shared-module/canio/RemoteTransmissionRequest.c21
-rw-r--r--shared-module/displayio/Bitmap.c54
-rw-r--r--shared-module/displayio/Bitmap.h4
-rw-r--r--shared-module/displayio/ColorConverter.c47
-rw-r--r--shared-module/displayio/ColorConverter.h6
-rw-r--r--shared-module/displayio/Display.c84
-rw-r--r--shared-module/displayio/Display.h8
-rw-r--r--shared-module/displayio/EPaperDisplay.c74
-rw-r--r--shared-module/displayio/EPaperDisplay.h10
-rw-r--r--shared-module/displayio/FourWire.c22
-rw-r--r--shared-module/displayio/FourWire.h2
-rw-r--r--shared-module/displayio/Group.c88
-rw-r--r--shared-module/displayio/Group.h20
-rw-r--r--shared-module/displayio/I2CDisplay.c18
-rw-r--r--shared-module/displayio/I2CDisplay.h2
-rw-r--r--shared-module/displayio/OnDiskBitmap.c26
-rw-r--r--shared-module/displayio/OnDiskBitmap.h4
-rw-r--r--shared-module/displayio/Palette.c18
-rw-r--r--shared-module/displayio/Palette.h4
-rw-r--r--shared-module/displayio/Shape.c10
-rw-r--r--shared-module/displayio/Shape.h4
-rw-r--r--shared-module/displayio/TileGrid.c72
-rw-r--r--shared-module/displayio/TileGrid.h37
-rw-r--r--shared-module/displayio/__init__.c134
-rw-r--r--shared-module/displayio/__init__.h12
-rw-r--r--shared-module/displayio/area.h36
-rw-r--r--shared-module/displayio/display_core.c44
-rw-r--r--shared-module/displayio/display_core.h42
-rw-r--r--shared-module/fontio/BuiltinFont.c4
-rw-r--r--shared-module/fontio/BuiltinFont.h4
-rw-r--r--shared-module/framebufferio/FramebufferDisplay.c70
-rw-r--r--shared-module/framebufferio/FramebufferDisplay.h10
-rw-r--r--shared-module/gamepad/GamePad.c2
-rw-r--r--shared-module/gamepad/GamePad.h2
-rw-r--r--shared-module/gamepad/__init__.c4
-rw-r--r--shared-module/gamepadshift/GamePadShift.c10
-rw-r--r--shared-module/gamepadshift/GamePadShift.h6
-rw-r--r--shared-module/gamepadshift/__init__.c2
-rw-r--r--shared-module/ipaddress/IPv4Address.c4
-rw-r--r--shared-module/ipaddress/__init__.c4
-rw-r--r--shared-module/memorymonitor/AllocationAlarm.c14
-rw-r--r--shared-module/memorymonitor/AllocationAlarm.h4
-rw-r--r--shared-module/memorymonitor/AllocationSize.c18
-rw-r--r--shared-module/memorymonitor/AllocationSize.h4
-rw-r--r--shared-module/msgpack/__init__.c93
-rw-r--r--shared-module/network/__init__.c18
-rw-r--r--shared-module/os/__init__.c24
-rw-r--r--shared-module/random/__init__.c21
-rw-r--r--shared-module/rgbmatrix/RGBMatrix.c48
-rw-r--r--shared-module/rgbmatrix/allocator.h2
-rw-r--r--shared-module/sdcardio/SDCard.c32
-rw-r--r--shared-module/sharpdisplay/SharpMemoryFramebuffer.c21
-rw-r--r--shared-module/sharpdisplay/SharpMemoryFramebuffer.h6
-rw-r--r--shared-module/storage/__init__.c8
-rw-r--r--shared-module/struct/__init__.c98
-rw-r--r--shared-module/terminalio/Terminal.c6
-rw-r--r--shared-module/terminalio/Terminal.h4
-rw-r--r--shared-module/touchio/TouchIn.c14
-rw-r--r--shared-module/uheap/__init__.c28
-rw-r--r--shared-module/usb_cdc/__init__.c3
-rw-r--r--shared-module/usb_hid/Device.c24
-rw-r--r--shared-module/usb_hid/Device.h8
-rw-r--r--shared-module/usb_midi/__init__.c10
-rw-r--r--shared-module/ustack/__init__.c7
-rw-r--r--shared-module/vectorio/Circle.c14
-rw-r--r--shared-module/vectorio/Polygon.c64
-rw-r--r--shared-module/vectorio/VectorShape.c44
-rw-r--r--shared-module/vectorio/VectorShape.h2
-rw-r--r--shared-module/wiznet/wiznet5k.c38
108 files changed, 1958 insertions, 1851 deletions
diff --git a/shared-module/_bleio/Characteristic.h b/shared-module/_bleio/Characteristic.h
index 7776b1fa5..298592b9e 100644
--- a/shared-module/_bleio/Characteristic.h
+++ b/shared-module/_bleio/Characteristic.h
@@ -39,18 +39,18 @@ typedef enum {
CHAR_PROP_WRITE = 1u << 4,
CHAR_PROP_WRITE_NO_RESPONSE = 1u << 5,
CHAR_PROP_ALL = (CHAR_PROP_BROADCAST | CHAR_PROP_INDICATE | CHAR_PROP_NOTIFY |
- CHAR_PROP_READ | CHAR_PROP_WRITE | CHAR_PROP_WRITE_NO_RESPONSE)
+ CHAR_PROP_READ | CHAR_PROP_WRITE | CHAR_PROP_WRITE_NO_RESPONSE)
} bleio_characteristic_properties_enum_t;
typedef uint8_t bleio_characteristic_properties_t;
// Bluetooth spec property values
-#define BT_GATT_CHRC_BROADCAST 0x01
-#define BT_GATT_CHRC_READ 0x02
-#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
-#define BT_GATT_CHRC_WRITE 0x08
-#define BT_GATT_CHRC_NOTIFY 0x10
-#define BT_GATT_CHRC_INDICATE 0x20
-#define BT_GATT_CHRC_AUTH 0x40
-#define BT_GATT_CHRC_EXT_PROP 0x80
+#define BT_GATT_CHRC_BROADCAST 0x01
+#define BT_GATT_CHRC_READ 0x02
+#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04
+#define BT_GATT_CHRC_WRITE 0x08
+#define BT_GATT_CHRC_NOTIFY 0x10
+#define BT_GATT_CHRC_INDICATE 0x20
+#define BT_GATT_CHRC_AUTH 0x40
+#define BT_GATT_CHRC_EXT_PROP 0x80
#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H
diff --git a/shared-module/_bleio/ScanEntry.c b/shared-module/_bleio/ScanEntry.c
index af9e4b347..28ff215a3 100644
--- a/shared-module/_bleio/ScanEntry.c
+++ b/shared-module/_bleio/ScanEntry.c
@@ -52,7 +52,7 @@ bool common_hal_bleio_scanentry_get_scan_response(bleio_scanentry_obj_t *self) {
return self->scan_response;
}
-bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t* prefixes, size_t prefixes_length, bool any) {
+bool bleio_scanentry_data_matches(const uint8_t *data, size_t len, const uint8_t *prefixes, size_t prefixes_length, bool any) {
if (prefixes_length == 0) {
return true;
}
@@ -61,7 +61,7 @@ bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t
return false;
}
size_t i = 0;
- while(i < prefixes_length) {
+ while (i < prefixes_length) {
uint8_t prefix_length = prefixes[i];
i += 1;
size_t j = 0;
@@ -91,6 +91,6 @@ bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t
return !any;
}
-bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, const uint8_t* prefixes, size_t prefixes_len, bool all) {
+bool common_hal_bleio_scanentry_matches(bleio_scanentry_obj_t *self, const uint8_t *prefixes, size_t prefixes_len, bool all) {
return bleio_scanentry_data_matches(self->data->data, self->data->len, prefixes, prefixes_len, !all);
}
diff --git a/shared-module/_bleio/ScanEntry.h b/shared-module/_bleio/ScanEntry.h
index 94361a397..9e142fd6e 100644
--- a/shared-module/_bleio/ScanEntry.h
+++ b/shared-module/_bleio/ScanEntry.h
@@ -42,6 +42,6 @@ typedef struct {
uint64_t time_received;
} bleio_scanentry_obj_t;
-bool bleio_scanentry_data_matches(const uint8_t* data, size_t len, const uint8_t* prefixes, size_t prefix_length, bool any);
+bool bleio_scanentry_data_matches(const uint8_t *data, size_t len, const uint8_t *prefixes, size_t prefix_length, bool any);
#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H
diff --git a/shared-module/_bleio/ScanResults.c b/shared-module/_bleio/ScanResults.c
index cb48d636d..25ce387d0 100644
--- a/shared-module/_bleio/ScanResults.c
+++ b/shared-module/_bleio/ScanResults.c
@@ -34,8 +34,8 @@
#include "shared-bindings/_bleio/ScanEntry.h"
#include "shared-bindings/_bleio/ScanResults.h"
-bleio_scanresults_obj_t* shared_module_bleio_new_scanresults(size_t buffer_size, uint8_t* prefixes, size_t prefixes_len, mp_int_t minimum_rssi) {
- bleio_scanresults_obj_t* self = m_new_obj(bleio_scanresults_obj_t);
+bleio_scanresults_obj_t *shared_module_bleio_new_scanresults(size_t buffer_size, uint8_t *prefixes, size_t prefixes_len, mp_int_t minimum_rssi) {
+ bleio_scanresults_obj_t *self = m_new_obj(bleio_scanresults_obj_t);
self->base.type = &bleio_scanresults_type;
ringbuf_alloc(&self->buf, buffer_size, false);
self->prefixes = prefixes;
@@ -57,16 +57,16 @@ mp_obj_t common_hal_bleio_scanresults_next(bleio_scanresults_obj_t *self) {
bool connectable = (type & (1 << 0)) != 0;
bool scan_response = (type & (1 << 1)) != 0;
uint64_t ticks_ms;
- ringbuf_get_n(&self->buf, (uint8_t*) &ticks_ms, sizeof(ticks_ms));
+ ringbuf_get_n(&self->buf, (uint8_t *)&ticks_ms, sizeof(ticks_ms));
uint8_t rssi = ringbuf_get(&self->buf);
uint8_t peer_addr[NUM_BLEIO_ADDRESS_BYTES];
ringbuf_get_n(&self->buf, peer_addr, sizeof(peer_addr));
uint8_t addr_type = ringbuf_get(&self->buf);
uint16_t len;
- ringbuf_get_n(&self->buf, (uint8_t*) &len, sizeof(len));
+ ringbuf_get_n(&self->buf, (uint8_t *)&len, sizeof(len));
mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_bytes_of_zeros(len));
- ringbuf_get_n(&self->buf, (uint8_t*) o->data, len);
+ ringbuf_get_n(&self->buf, (uint8_t *)o->data, len);
bleio_scanentry_obj_t *entry = m_new_obj(bleio_scanentry_obj_t);
entry->base.type = &bleio_scanentry_type;
@@ -86,15 +86,15 @@ mp_obj_t common_hal_bleio_scanresults_next(bleio_scanresults_obj_t *self) {
}
-void shared_module_bleio_scanresults_append(bleio_scanresults_obj_t* self,
- uint64_t ticks_ms,
- bool connectable,
- bool scan_response,
- int8_t rssi,
- uint8_t *peer_addr,
- uint8_t addr_type,
- uint8_t *data,
- uint16_t len) {
+void shared_module_bleio_scanresults_append(bleio_scanresults_obj_t *self,
+ uint64_t ticks_ms,
+ bool connectable,
+ bool scan_response,
+ int8_t rssi,
+ uint8_t *peer_addr,
+ uint8_t addr_type,
+ uint8_t *data,
+ uint16_t len) {
int32_t packet_size = sizeof(uint8_t) + sizeof(ticks_ms) + sizeof(rssi) + NUM_BLEIO_ADDRESS_BYTES +
sizeof(addr_type) + sizeof(len) + len;
int32_t empty_space = self->buf.size - ringbuf_num_filled(&self->buf);
@@ -121,19 +121,19 @@ void shared_module_bleio_scanresults_append(bleio_scanresults_obj_t* self,
// Add the packet to the buffer.
ringbuf_put(&self->buf, type);
- ringbuf_put_n(&self->buf, (uint8_t*) &ticks_ms, sizeof(ticks_ms));
+ ringbuf_put_n(&self->buf, (uint8_t *)&ticks_ms, sizeof(ticks_ms));
ringbuf_put(&self->buf, rssi);
ringbuf_put_n(&self->buf, peer_addr, NUM_BLEIO_ADDRESS_BYTES);
ringbuf_put(&self->buf, addr_type);
- ringbuf_put_n(&self->buf, (uint8_t*) &len, sizeof(len));
+ ringbuf_put_n(&self->buf, (uint8_t *)&len, sizeof(len));
ringbuf_put_n(&self->buf, data, len);
}
-bool shared_module_bleio_scanresults_get_done(bleio_scanresults_obj_t* self) {
+bool shared_module_bleio_scanresults_get_done(bleio_scanresults_obj_t *self) {
return self->done;
}
-void shared_module_bleio_scanresults_set_done(bleio_scanresults_obj_t* self, bool done) {
+void shared_module_bleio_scanresults_set_done(bleio_scanresults_obj_t *self, bool done) {
self->done = done;
self->common_hal_data = NULL;
}
diff --git a/shared-module/_bleio/ScanResults.h b/shared-module/_bleio/ScanResults.h
index 8912357a9..fa181aabe 100644
--- a/shared-module/_bleio/ScanResults.h
+++ b/shared-module/_bleio/ScanResults.h
@@ -36,29 +36,29 @@
typedef struct {
mp_obj_base_t base;
// Pointers that needs to live until the scan is done.
- void* common_hal_data;
+ void *common_hal_data;
ringbuf_t buf;
// Prefixes is a length encoded array of prefixes.
- uint8_t* prefixes;
+ uint8_t *prefixes;
size_t prefix_length;
mp_int_t minimum_rssi;
bool active;
bool done;
} bleio_scanresults_obj_t;
-bleio_scanresults_obj_t* shared_module_bleio_new_scanresults(size_t buffer_size, uint8_t* prefixes, size_t prefixes_len, mp_int_t minimum_rssi);
+bleio_scanresults_obj_t *shared_module_bleio_new_scanresults(size_t buffer_size, uint8_t *prefixes, size_t prefixes_len, mp_int_t minimum_rssi);
-bool shared_module_bleio_scanresults_get_done(bleio_scanresults_obj_t* self);
-void shared_module_bleio_scanresults_set_done(bleio_scanresults_obj_t* self, bool done);
+bool shared_module_bleio_scanresults_get_done(bleio_scanresults_obj_t *self);
+void shared_module_bleio_scanresults_set_done(bleio_scanresults_obj_t *self, bool done);
-void shared_module_bleio_scanresults_append(bleio_scanresults_obj_t* self,
- uint64_t ticks_ms,
- bool connectable,
- bool scan_result,
- int8_t rssi,
- uint8_t *peer_addr,
- uint8_t addr_type,
- uint8_t* data,
- uint16_t len);
+void shared_module_bleio_scanresults_append(bleio_scanresults_obj_t *self,
+ uint64_t ticks_ms,
+ bool connectable,
+ bool scan_result,
+ int8_t rssi,
+ uint8_t *peer_addr,
+ uint8_t addr_type,
+ uint8_t *data,
+ uint16_t len);
#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANRESULTS_H
diff --git a/shared-module/_eve/__init__.c b/shared-module/_eve/__init__.c
index 579729d42..0df77b65c 100644
--- a/shared-module/_eve/__init__.c
+++ b/shared-module/_eve/__init__.c
@@ -42,25 +42,28 @@ void common_hal__eve_flush(common_hal__eve_t *eve) {
}
static void *append(common_hal__eve_t *eve, size_t m) {
- if ((eve->n + m) > sizeof(eve->buf))
+ if ((eve->n + m) > sizeof(eve->buf)) {
common_hal__eve_flush(eve);
+ }
uint8_t *r = eve->buf + eve->n;
eve->n += m;
- return (void*)r;
+ return (void *)r;
}
void common_hal__eve_add(common_hal__eve_t *eve, size_t len, void *buf) {
if (len <= sizeof(eve->buf)) {
- uint8_t *p = (uint8_t*)append(eve, len);
- // memcpy(p, buffer_info.buf, buffer_info.len);
- uint8_t *s = buf; for (size_t i = 0; i < len; i++) *p++ = *s++;
+ uint8_t *p = (uint8_t *)append(eve, len);
+ // memcpy(p, buffer_info.buf, buffer_info.len);
+ uint8_t *s = buf;
+ for (size_t i = 0; i < len; i++) { *p++ = *s++;
+ }
} else {
- common_hal__eve_flush(eve);
- write(eve, len, buf);
+ common_hal__eve_flush(eve);
+ write(eve, len, buf);
}
}
-#define C4(eve, u) (*(uint32_t*)append((eve), sizeof(uint32_t)) = (u))
+#define C4(eve, u) (*(uint32_t *)append((eve), sizeof(uint32_t)) = (u))
void common_hal__eve_Vertex2f(common_hal__eve_t *eve, mp_float_t x, mp_float_t y) {
int16_t ix = (int)(eve->vscale * x);
@@ -68,8 +71,7 @@ void common_hal__eve_Vertex2f(common_hal__eve_t *eve, mp_float_t x, mp_float_t y
C4(eve, (1 << 30) | ((ix & 32767) << 15) | (iy & 32767));
}
-void common_hal__eve_VertexFormat(common_hal__eve_t *eve, uint32_t frac)
-{
+void common_hal__eve_VertexFormat(common_hal__eve_t *eve, uint32_t frac) {
C4(eve, ((39 << 24) | ((frac & 7))));
eve->vscale = 1 << frac;
}
diff --git a/shared-module/_pixelbuf/PixelBuf.c b/shared-module/_pixelbuf/PixelBuf.c
index 4cbf6dc21..df160b1ff 100644
--- a/shared-module/_pixelbuf/PixelBuf.c
+++ b/shared-module/_pixelbuf/PixelBuf.c
@@ -34,15 +34,15 @@
#include <math.h>
// Helper to ensure we have the native super class instead of a subclass.
-static pixelbuf_pixelbuf_obj_t* native_pixelbuf(mp_obj_t pixelbuf_obj) {
+static pixelbuf_pixelbuf_obj_t *native_pixelbuf(mp_obj_t pixelbuf_obj) {
mp_obj_t native_pixelbuf = mp_instance_cast_to_native_base(pixelbuf_obj, &pixelbuf_pixelbuf_type);
mp_obj_assert_native_inited(native_pixelbuf);
return MP_OBJ_TO_PTR(native_pixelbuf);
}
void common_hal__pixelbuf_pixelbuf_construct(pixelbuf_pixelbuf_obj_t *self, size_t n,
- pixelbuf_byteorder_details_t* byteorder, mp_float_t brightness, bool auto_write,
- uint8_t* header, size_t header_len, uint8_t* trailer, size_t trailer_len) {
+ pixelbuf_byteorder_details_t *byteorder, mp_float_t brightness, bool auto_write,
+ uint8_t *header, size_t header_len, uint8_t *trailer, size_t trailer_len) {
self->pixel_count = n;
self->byteorder = *byteorder; // Copied because we modify for dotstar
@@ -56,7 +56,7 @@ void common_hal__pixelbuf_pixelbuf_construct(pixelbuf_pixelbuf_obj_t *self, size
// Abuse the bytes object a bit by mutating it's data by dropping the const. If the user's
// Python code holds onto it, they'll find out that it changes. At least this way it isn't
// mutable by the code itself.
- uint8_t* transmit_buffer = (uint8_t*) o->data;
+ uint8_t *transmit_buffer = (uint8_t *)o->data;
memcpy(transmit_buffer, header, header_len);
memcpy(transmit_buffer + header_len + pixel_len, trailer, trailer_len);
self->post_brightness_buffer = transmit_buffer + header_len;
@@ -78,37 +78,37 @@ void common_hal__pixelbuf_pixelbuf_construct(pixelbuf_pixelbuf_obj_t *self, size
}
size_t common_hal__pixelbuf_pixelbuf_get_len(mp_obj_t self_in) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
return self->pixel_count;
}
uint8_t common_hal__pixelbuf_pixelbuf_get_bpp(mp_obj_t self_in) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
return self->byteorder.bpp;
}
mp_obj_t common_hal__pixelbuf_pixelbuf_get_byteorder_string(mp_obj_t self_in) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
return self->byteorder.order_string;
}
bool common_hal__pixelbuf_pixelbuf_get_auto_write(mp_obj_t self_in) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
return self->auto_write;
}
void common_hal__pixelbuf_pixelbuf_set_auto_write(mp_obj_t self_in, bool auto_write) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
self->auto_write = auto_write;
}
mp_float_t common_hal__pixelbuf_pixelbuf_get_brightness(mp_obj_t self_in) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
return self->brightness;
}
void common_hal__pixelbuf_pixelbuf_set_brightness(mp_obj_t self_in, mp_float_t brightness) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
// Skip out if the brightness is already set. The default of self->brightness is 1.0. So, this
// also prevents the pre_brightness_buffer allocation when brightness is set to 1.0 again.
self->brightness = brightness;
@@ -149,10 +149,10 @@ uint8_t _pixelbuf_get_as_uint8(mp_obj_t obj) {
return (uint8_t)mp_obj_get_float(obj);
}
mp_raise_TypeError_varg(
- translate("can't convert %q to %q"), mp_obj_get_type_qstr(obj), MP_QSTR_int);
+ translate("can't convert %q to %q"), mp_obj_get_type_qstr(obj), MP_QSTR_int);
}
-void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* w) {
+void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t *self, mp_obj_t color, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *w) {
pixelbuf_byteorder_details_t *byteorder = &self->byteorder;
// w is shared between white in NeoPixels and brightness in dotstars (so that DotStars can have
// per-pixel brightness). Set the defaults here in case it isn't set below.
@@ -197,7 +197,7 @@ void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t* self, mp_obj_t color, uint8_
}
}
-void _pixelbuf_set_pixel_color(pixelbuf_pixelbuf_obj_t* self, size_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
+void _pixelbuf_set_pixel_color(pixelbuf_pixelbuf_obj_t *self, size_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
// DotStars don't have white, instead they have 5 bit brightness so pack it into w. Shift right
// by three to leave the top five bits.
if (self->bytes_per_pixel == 4 && self->byteorder.is_dotstar) {
@@ -235,7 +235,7 @@ void _pixelbuf_set_pixel_color(pixelbuf_pixelbuf_obj_t* self, size_t index, uint
}
}
-void _pixelbuf_set_pixel(pixelbuf_pixelbuf_obj_t* self, size_t index, mp_obj_t value) {
+void _pixelbuf_set_pixel(pixelbuf_pixelbuf_obj_t *self, size_t index, mp_obj_t value) {
uint8_t r;
uint8_t g;
uint8_t b;
@@ -244,26 +244,27 @@ void _pixelbuf_set_pixel(pixelbuf_pixelbuf_obj_t* self, size_t index, mp_obj_t v
_pixelbuf_set_pixel_color(self, index, r, g, b, w);
}
-void common_hal__pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, size_t start, mp_int_t step, size_t slice_len, mp_obj_t* values,
- mp_obj_tuple_t *flatten_to)
-{
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+void common_hal__pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, size_t start, mp_int_t step, size_t slice_len, mp_obj_t *values,
+ mp_obj_tuple_t *flatten_to) {
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
mp_obj_iter_buf_t iter_buf;
mp_obj_t iterable = mp_getiter(values, &iter_buf);
mp_obj_t item;
size_t i = 0;
bool flattened = flatten_to != mp_const_none;
- if (flattened) flatten_to->len = self->bytes_per_pixel;
+ if (flattened) {
+ flatten_to->len = self->bytes_per_pixel;
+ }
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
if (flattened) {
flatten_to->items[i % self->bytes_per_pixel] = item;
if (++i % self->bytes_per_pixel == 0) {
_pixelbuf_set_pixel(self, start, flatten_to);
- start+=step;
+ start += step;
}
} else {
_pixelbuf_set_pixel(self, start, item);
- start+=step;
+ start += step;
}
}
if (self->auto_write) {
@@ -274,7 +275,7 @@ void common_hal__pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, size_t start, mp
void common_hal__pixelbuf_pixelbuf_set_pixel(mp_obj_t self_in, size_t index, mp_obj_t value) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
_pixelbuf_set_pixel(self, index, value);
if (self->auto_write) {
common_hal__pixelbuf_pixelbuf_show(self_in);
@@ -282,9 +283,9 @@ void common_hal__pixelbuf_pixelbuf_set_pixel(mp_obj_t self_in, size_t index, mp_
}
mp_obj_t common_hal__pixelbuf_pixelbuf_get_pixel(mp_obj_t self_in, size_t index) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
mp_obj_t elems[self->byteorder.bpp];
- uint8_t* pixel_buffer = self->post_brightness_buffer;
+ uint8_t *pixel_buffer = self->post_brightness_buffer;
if (self->pre_brightness_buffer != NULL) {
pixel_buffer = self->pre_brightness_buffer;
}
@@ -307,7 +308,7 @@ mp_obj_t common_hal__pixelbuf_pixelbuf_get_pixel(mp_obj_t self_in, size_t index)
}
void common_hal__pixelbuf_pixelbuf_show(mp_obj_t self_in) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
mp_obj_t dest[2 + 1];
mp_load_method(self_in, MP_QSTR__transmit, dest);
@@ -317,7 +318,7 @@ void common_hal__pixelbuf_pixelbuf_show(mp_obj_t self_in) {
}
void common_hal__pixelbuf_pixelbuf_fill(mp_obj_t self_in, mp_obj_t fill_color) {
- pixelbuf_pixelbuf_obj_t* self = native_pixelbuf(self_in);
+ pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in);
uint8_t r;
uint8_t g;
diff --git a/shared-module/_stage/Layer.c b/shared-module/_stage/Layer.c
index d958f0d19..df2b27fa1 100644
--- a/shared-module/_stage/Layer.c
+++ b/shared-module/_stage/Layer.c
@@ -37,7 +37,7 @@ uint16_t get_layer_pixel(layer_obj_t *layer, uint16_t x, uint16_t y) {
// Bounds check.
if ((x < 0) || (x >= layer->width << 4) ||
- (y < 0) || (y >= layer->height << 4)) {
+ (y < 0) || (y >= layer->height << 4)) {
return TRANSPARENT;
}
diff --git a/shared-module/_stage/Text.c b/shared-module/_stage/Text.c
index df5bf8008..91223f525 100644
--- a/shared-module/_stage/Text.c
+++ b/shared-module/_stage/Text.c
@@ -37,7 +37,7 @@ uint16_t get_text_pixel(text_obj_t *text, uint16_t x, uint16_t y) {
// Bounds check.
if ((x < 0) || (x >= text->width << 3) ||
- (y < 0) || (y >= text->height << 3)) {
+ (y < 0) || (y >= text->height << 3)) {
return TRANSPARENT;
}
diff --git a/shared-module/_stage/__init__.c b/shared-module/_stage/__init__.c
index 6dfc18880..06a12aa0a 100644
--- a/shared-module/_stage/__init__.c
+++ b/shared-module/_stage/__init__.c
@@ -32,10 +32,10 @@
void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
- mp_obj_t *layers, size_t layers_size,
- uint16_t *buffer, size_t buffer_size,
- displayio_display_obj_t *display,
- uint8_t scale, uint16_t background) {
+ mp_obj_t *layers, size_t layers_size,
+ uint16_t *buffer, size_t buffer_size,
+ displayio_display_obj_t *display,
+ uint8_t scale, uint16_t background) {
displayio_area_t area;
@@ -51,8 +51,8 @@ void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
RUN_BACKGROUND_TASKS;
}
display->core.send(display->core.bus, DISPLAY_COMMAND,
- CHIP_SELECT_TOGGLE_EVERY_BYTE,
- &display->write_ram_command, 1);
+ CHIP_SELECT_TOGGLE_EVERY_BYTE,
+ &display->write_ram_command, 1);
size_t index = 0;
for (uint16_t y = y0; y < y1; ++y) {
for (uint8_t yscale = 0; yscale < scale; ++yscale) {
@@ -78,8 +78,8 @@ void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
// The buffer is full, send it.
if (index >= buffer_size) {
display->core.send(display->core.bus, DISPLAY_DATA,
- CHIP_SELECT_UNTOUCHED,
- ((uint8_t*)buffer), buffer_size * 2);
+ CHIP_SELECT_UNTOUCHED,
+ ((uint8_t *)buffer), buffer_size * 2);
index = 0;
}
}
@@ -89,8 +89,8 @@ void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
// Send the remaining data.
if (index) {
display->core.send(display->core.bus, DISPLAY_DATA,
- CHIP_SELECT_UNTOUCHED,
- ((uint8_t*)buffer), index * 2);
+ CHIP_SELECT_UNTOUCHED,
+ ((uint8_t *)buffer), index * 2);
}
displayio_display_core_end_transaction(&display->core);
diff --git a/shared-module/_stage/__init__.h b/shared-module/_stage/__init__.h
index 7a1826200..5cbaa235b 100644
--- a/shared-module/_stage/__init__.h
+++ b/shared-module/_stage/__init__.h
@@ -35,9 +35,9 @@
#define TRANSPARENT (0x1ff8)
void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
- mp_obj_t *layers, size_t layers_size,
- uint16_t *buffer, size_t buffer_size,
- displayio_display_obj_t *display,
- uint8_t scale, uint16_t background);
+ mp_obj_t *layers, size_t layers_size,
+ uint16_t *buffer, size_t buffer_size,
+ displayio_display_obj_t *display,
+ uint8_t scale, uint16_t background);
#endif // MICROPY_INCLUDED_SHARED_MODULE__STAGE
diff --git a/shared-module/adafruit_bus_device/I2CDevice.c b/shared-module/adafruit_bus_device/I2CDevice.c
index 6d80cf599..51c5073a7 100644
--- a/shared-module/adafruit_bus_device/I2CDevice.c
+++ b/shared-module/adafruit_bus_device/I2CDevice.c
@@ -78,10 +78,9 @@ void common_hal_adafruit_bus_device_i2cdevice_probe_for_device(adafruit_bus_devi
} else {
common_hal_adafruit_bus_device_i2cdevice_unlock(self);
- 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))) {
+ 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 {
+ } else {
/* In case we receive an unrelated exception pass it up */
nlr_raise(MP_OBJ_FROM_PTR(nlr.ret_val));
}
diff --git a/shared-module/adafruit_bus_device/SPIDevice.c b/shared-module/adafruit_bus_device/SPIDevice.c
index 65649026a..c65807aeb 100644
--- a/shared-module/adafruit_bus_device/SPIDevice.c
+++ b/shared-module/adafruit_bus_device/SPIDevice.c
@@ -68,14 +68,15 @@ void common_hal_adafruit_bus_device_spidevice_exit(adafruit_bus_device_spidevice
mp_obj_t buffer = mp_obj_new_bytearray_of_zeros(1);
mp_get_buffer_raise(buffer, &bufinfo, MP_BUFFER_READ);
- ((uint8_t*)bufinfo.buf)[0] = 0xFF;
+ ((uint8_t *)bufinfo.buf)[0] = 0xFF;
uint8_t clocks = self->extra_clocks / 8;
- if ((self->extra_clocks % 8) != 0)
+ if ((self->extra_clocks % 8) != 0) {
clocks += 1;
+ }
while (clocks > 0) {
- if (!common_hal_busio_spi_write(self->spi, ((uint8_t*)bufinfo.buf), 1)) {
+ if (!common_hal_busio_spi_write(self->spi, ((uint8_t *)bufinfo.buf), 1)) {
mp_raise_OSError(MP_EIO);
}
clocks--;
diff --git a/shared-module/aesio/__init__.c b/shared-module/aesio/__init__.c
index 2cacaeb66..bd748f980 100644
--- a/shared-module/aesio/__init__.c
+++ b/shared-module/aesio/__init__.c
@@ -6,53 +6,53 @@
#include "shared-module/aesio/__init__.h"
void common_hal_aesio_aes_construct(aesio_aes_obj_t *self, const uint8_t *key,
- uint32_t key_length, const uint8_t *iv,
- int mode, int counter) {
- self->mode = mode;
- self->counter = counter;
- common_hal_aesio_aes_rekey(self, key, key_length, iv);
+ uint32_t key_length, const uint8_t *iv,
+ int mode, int counter) {
+ self->mode = mode;
+ self->counter = counter;
+ common_hal_aesio_aes_rekey(self, key, key_length, iv);
}
void common_hal_aesio_aes_rekey(aesio_aes_obj_t *self, const uint8_t *key,
- uint32_t key_length, const uint8_t *iv) {
- memset(&self->ctx, 0, sizeof(self->ctx));
- if (iv != NULL) {
- AES_init_ctx_iv(&self->ctx, key, key_length, iv);
- } else {
- AES_init_ctx(&self->ctx, key, key_length);
- }
+ uint32_t key_length, const uint8_t *iv) {
+ memset(&self->ctx, 0, sizeof(self->ctx));
+ if (iv != NULL) {
+ AES_init_ctx_iv(&self->ctx, key, key_length, iv);
+ } else {
+ AES_init_ctx(&self->ctx, key, key_length);
+ }
}
void common_hal_aesio_aes_set_mode(aesio_aes_obj_t *self, int mode) {
- self->mode = mode;
+ self->mode = mode;
}
void common_hal_aesio_aes_encrypt(aesio_aes_obj_t *self, uint8_t *buffer,
- size_t length) {
- switch (self->mode) {
- case AES_MODE_ECB:
- AES_ECB_encrypt(&self->ctx, buffer);
- break;
- case AES_MODE_CBC:
- AES_CBC_encrypt_buffer(&self->ctx, buffer, length);
- break;
- case AES_MODE_CTR:
- AES_CTR_xcrypt_buffer(&self->ctx, buffer, length);
- break;
- }
+ size_t length) {
+ switch (self->mode) {
+ case AES_MODE_ECB:
+ AES_ECB_encrypt(&self->ctx, buffer);
+ break;
+ case AES_MODE_CBC:
+ AES_CBC_encrypt_buffer(&self->ctx, buffer, length);
+ break;
+ case AES_MODE_CTR:
+ AES_CTR_xcrypt_buffer(&self->ctx, buffer, length);
+ break;
+ }
}
void common_hal_aesio_aes_decrypt(aesio_aes_obj_t *self, uint8_t *buffer,
- size_t length) {
- switch (self->mode) {
- case AES_MODE_ECB:
- AES_ECB_decrypt(&self->ctx, buffer);
- break;
- case AES_MODE_CBC:
- AES_CBC_decrypt_buffer(&self->ctx, buffer, length);
- break;
- case AES_MODE_CTR:
- AES_CTR_xcrypt_buffer(&self->ctx, buffer, length);
- break;
- }
+ size_t length) {
+ switch (self->mode) {
+ case AES_MODE_ECB:
+ AES_ECB_decrypt(&self->ctx, buffer);
+ break;
+ case AES_MODE_CBC:
+ AES_CBC_decrypt_buffer(&self->ctx, buffer, length);
+ break;
+ case AES_MODE_CTR:
+ AES_CTR_xcrypt_buffer(&self->ctx, buffer, length);
+ break;
+ }
}
diff --git a/shared-module/aesio/aes.c b/shared-module/aesio/aes.c
index b62b5afc4..f417e76de 100644
--- a/shared-module/aesio/aes.c
+++ b/shared-module/aesio/aes.c
@@ -80,46 +80,49 @@ typedef uint8_t state_t[4][4];
// RAM - This can be useful in (embedded) bootloader applications, where ROM is
// often limited.
static const uint8_t sbox[256] = {
- //0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
- 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
- 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
- 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
- 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
- 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
- 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
- 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
- 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
- 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
- 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
- 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
- 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
- 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
- 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
- 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 };
+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
+ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
+ 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
+ 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
+ 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
+ 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
+ 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
+ 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
+ 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
+ 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
+ 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
+ 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
+ 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
+ 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
+ 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
+ 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
+ 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
+};
static const uint8_t rsbox[256] = {
- 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
- 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
- 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
- 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
- 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
- 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
- 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
- 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
- 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
- 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
- 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
- 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
- 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
- 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
- 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
- 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d };
+ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
+ 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
+ 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
+ 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
+ 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
+ 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
+ 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
+ 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
+ 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
+ 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
+ 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
+ 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
+ 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
+ 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
+ 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
+ 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
+};
// The round constant word array, Rcon[i], contains the values given by x to the
// power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8)
static const uint8_t Rcon[11] = {
- 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
+ 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
+};
/*
* Jordan Goulder points out in PR #12
@@ -139,18 +142,21 @@ static const uint8_t Rcon[11] = {
/* Private functions: */
/*****************************************************************************/
static const uint8_t *GetRoundKey(const struct AES_ctx *ctx) {
- switch (ctx->KeyLength) {
-#if defined(AES128) && (AES128 == 1)
- case 16: return ctx->RoundKey128;
-#endif
-#if defined(AES192) && (AES192 == 1)
- case 24: return ctx->RoundKey192;
-#endif
-#if defined(AES256) && (AES256 == 1)
- case 32: return ctx->RoundKey256;
-#endif
- }
- return NULL;
+ switch (ctx->KeyLength) {
+ #if defined(AES128) && (AES128 == 1)
+ case 16:
+ return ctx->RoundKey128;
+ #endif
+ #if defined(AES192) && (AES192 == 1)
+ case 24:
+ return ctx->RoundKey192;
+ #endif
+ #if defined(AES256) && (AES256 == 1)
+ case 32:
+ return ctx->RoundKey256;
+ #endif
+ }
+ return NULL;
}
@@ -171,190 +177,200 @@ static uint8_t getSBoxInvert(uint8_t num)
// This function produces Nb(Nr+1) round keys. The round keys are used in each
// round to decrypt the states.
-static void KeyExpansion(struct AES_ctx* ctx, const uint8_t* Key)
-{
- uint8_t* RoundKey = (uint8_t *)GetRoundKey(ctx);
-
- unsigned i, j, k;
- uint8_t tempa[4]; // Used for the column/row operations
-
- // The first round key is the key itself.
- for (i = 0; i < ctx->Nk; ++i)
- {
- RoundKey[(i * 4) + 0] = Key[(i * 4) + 0];
- RoundKey[(i * 4) + 1] = Key[(i * 4) + 1];
- RoundKey[(i * 4) + 2] = Key[(i * 4) + 2];
- RoundKey[(i * 4) + 3] = Key[(i * 4) + 3];
- }
-
- // All other round keys are found from the previous round keys.
- for (i = ctx->Nk; i < Nb * (ctx->Nr + 1); ++i)
- {
- {
- k = (i - 1) * 4;
- tempa[0]=RoundKey[k + 0];
- tempa[1]=RoundKey[k + 1];
- tempa[2]=RoundKey[k + 2];
- tempa[3]=RoundKey[k + 3];
+static void KeyExpansion(struct AES_ctx *ctx, const uint8_t *Key) {
+ uint8_t *RoundKey = (uint8_t *)GetRoundKey(ctx);
- }
+ unsigned i, j, k;
+ uint8_t tempa[4]; // Used for the column/row operations
- if (i % ctx->Nk == 0)
+ // The first round key is the key itself.
+ for (i = 0; i < ctx->Nk; ++i)
{
- // This function shifts the 4 bytes in a word to the left once.
- // [a0,a1,a2,a3] becomes [a1,a2,a3,a0]
-
- // Function RotWord()
- {
- const uint8_t u8tmp = tempa[0];
- tempa[0] = tempa[1];
- tempa[1] = tempa[2];
- tempa[2] = tempa[3];
- tempa[3] = u8tmp;
- }
-
- // SubWord() is a function that takes a four-byte input word and applies
- // the S-box to each of the four bytes to produce an output word.
-
- // Function Subword()
- {
- tempa[0] = getSBoxValue(tempa[0]);
- tempa[1] = getSBoxValue(tempa[1]);
- tempa[2] = getSBoxValue(tempa[2]);
- tempa[3] = getSBoxValue(tempa[3]);
- }
-
- tempa[0] = tempa[0] ^ Rcon[i/ctx->Nk];
+ RoundKey[(i * 4) + 0] = Key[(i * 4) + 0];
+ RoundKey[(i * 4) + 1] = Key[(i * 4) + 1];
+ RoundKey[(i * 4) + 2] = Key[(i * 4) + 2];
+ RoundKey[(i * 4) + 3] = Key[(i * 4) + 3];
}
-#if defined(AES256) && (AES256 == 1)
- if (ctx->KeyLength == 32) {
- if (i % ctx->Nk == 4)
- {
- // Function Subword()
+
+ // All other round keys are found from the previous round keys.
+ for (i = ctx->Nk; i < Nb * (ctx->Nr + 1); ++i)
+ {
{
- tempa[0] = getSBoxValue(tempa[0]);
- tempa[1] = getSBoxValue(tempa[1]);
- tempa[2] = getSBoxValue(tempa[2]);
- tempa[3] = getSBoxValue(tempa[3]);
+ k = (i - 1) * 4;
+ tempa[0] = RoundKey[k + 0];
+ tempa[1] = RoundKey[k + 1];
+ tempa[2] = RoundKey[k + 2];
+ tempa[3] = RoundKey[k + 3];
+
}
- }
+
+ if (i % ctx->Nk == 0) {
+ // This function shifts the 4 bytes in a word to the left once.
+ // [a0,a1,a2,a3] becomes [a1,a2,a3,a0]
+
+ // Function RotWord()
+ {
+ const uint8_t u8tmp = tempa[0];
+ tempa[0] = tempa[1];
+ tempa[1] = tempa[2];
+ tempa[2] = tempa[3];
+ tempa[3] = u8tmp;
+ }
+
+ // SubWord() is a function that takes a four-byte input word and applies
+ // the S-box to each of the four bytes to produce an output word.
+
+ // Function Subword()
+ {
+ tempa[0] = getSBoxValue(tempa[0]);
+ tempa[1] = getSBoxValue(tempa[1]);
+ tempa[2] = getSBoxValue(tempa[2]);
+ tempa[3] = getSBoxValue(tempa[3]);
+ }
+
+ tempa[0] = tempa[0] ^ Rcon[i / ctx->Nk];
+ }
+ #if defined(AES256) && (AES256 == 1)
+ if (ctx->KeyLength == 32) {
+ if (i % ctx->Nk == 4) {
+ // Function Subword()
+ {
+ tempa[0] = getSBoxValue(tempa[0]);
+ tempa[1] = getSBoxValue(tempa[1]);
+ tempa[2] = getSBoxValue(tempa[2]);
+ tempa[3] = getSBoxValue(tempa[3]);
+ }
+ }
+ }
+ #endif
+ j = i * 4;
+ k = (i - ctx->Nk) * 4;
+ RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0];
+ RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1];
+ RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2];
+ RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3];
}
-#endif
- j = i * 4; k=(i - ctx->Nk) * 4;
- RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0];
- RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1];
- RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2];
- RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3];
- }
}
-void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key, uint32_t keylen)
-{
- ctx->KeyLength = keylen;
- switch (ctx->KeyLength) {
-#if defined(AES128) && (AES128 == 1)
- case 16: ctx->Nr = Nr128; ctx->Nk = Nk128; break;
-#endif
-#if defined(AES192) && (AES192 == 1)
- case 24: ctx->Nr = Nr192; ctx->Nk = Nk192; break;
-#endif
-#if defined(AES256) && (AES256 == 1)
- case 32: ctx->Nr = Nr256; ctx->Nk = Nk256; break;
-#endif
- default: ctx->Nr = 0; ctx->Nk = 0; break;
- }
- KeyExpansion(ctx, key);
+void AES_init_ctx(struct AES_ctx *ctx, const uint8_t *key, uint32_t keylen) {
+ ctx->KeyLength = keylen;
+ switch (ctx->KeyLength) {
+ #if defined(AES128) && (AES128 == 1)
+ case 16:
+ ctx->Nr = Nr128;
+ ctx->Nk = Nk128;
+ break;
+ #endif
+ #if defined(AES192) && (AES192 == 1)
+ case 24:
+ ctx->Nr = Nr192;
+ ctx->Nk = Nk192;
+ break;
+ #endif
+ #if defined(AES256) && (AES256 == 1)
+ case 32:
+ ctx->Nr = Nr256;
+ ctx->Nk = Nk256;
+ break;
+ #endif
+ default:
+ ctx->Nr = 0;
+ ctx->Nk = 0;
+ break;
+ }
+ KeyExpansion(ctx, key);
}
#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
-void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, uint32_t keylen, const uint8_t* iv)
-{
- AES_init_ctx(ctx, key, keylen);
- memcpy (ctx->Iv, iv, AES_BLOCKLEN);
+void AES_init_ctx_iv(struct AES_ctx *ctx, const uint8_t *key, uint32_t keylen, const uint8_t *iv) {
+ AES_init_ctx(ctx, key, keylen);
+ memcpy(ctx->Iv, iv, AES_BLOCKLEN);
}
-void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv)
-{
- memcpy (ctx->Iv, iv, AES_BLOCKLEN);
+void AES_ctx_set_iv(struct AES_ctx *ctx, const uint8_t *iv) {
+ memcpy(ctx->Iv, iv, AES_BLOCKLEN);
}
#endif
// This function adds the round key to state. The round key is added to the
// state by an XOR function.
-static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey)
-{
- uint8_t i,j;
- for (i = 0; i < 4; ++i)
- {
- for (j = 0; j < 4; ++j)
+static void AddRoundKey(uint8_t round, state_t *state, const uint8_t *RoundKey) {
+ uint8_t i,j;
+ for (i = 0; i < 4; ++i)
{
- (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j];
+ for (j = 0; j < 4; ++j)
+ {
+ (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j];
+ }
}
- }
}
// The SubBytes Function Substitutes the values in the state matrix with values
// in an S-box.
-static void SubBytes(state_t* state)
-{
- uint8_t i, j;
- for (i = 0; i < 4; ++i)
- {
- for (j = 0; j < 4; ++j)
+static void SubBytes(state_t *state) {
+ uint8_t i, j;
+ for (i = 0; i < 4; ++i)
{
- (*state)[j][i] = getSBoxValue((*state)[j][i]);
+ for (j = 0; j < 4; ++j)
+ {
+ (*state)[j][i] = getSBoxValue((*state)[j][i]);
+ }
}
- }
}
// The ShiftRows() function shifts the rows in the state to the left. Each row
// is shifted with different offset. Offset = Row number. So the first row is
// not shifted.
-static void ShiftRows(state_t* state)
-{
- uint8_t temp;
-
- // Rotate first row 1 columns to left
- temp = (*state)[0][1];
- (*state)[0][1] = (*state)[1][1];
- (*state)[1][1] = (*state)[2][1];
- (*state)[2][1] = (*state)[3][1];
- (*state)[3][1] = temp;
-
- // Rotate second row 2 columns to left
- temp = (*state)[0][2];
- (*state)[0][2] = (*state)[2][2];
- (*state)[2][2] = temp;
-
- temp = (*state)[1][2];
- (*state)[1][2] = (*state)[3][2];
- (*state)[3][2] = temp;
-
- // Rotate third row 3 columns to left
- temp = (*state)[0][3];
- (*state)[0][3] = (*state)[3][3];
- (*state)[3][3] = (*state)[2][3];
- (*state)[2][3] = (*state)[1][3];
- (*state)[1][3] = temp;
+static void ShiftRows(state_t *state) {
+ uint8_t temp;
+
+ // Rotate first row 1 columns to left
+ temp = (*state)[0][1];
+ (*state)[0][1] = (*state)[1][1];
+ (*state)[1][1] = (*state)[2][1];
+ (*state)[2][1] = (*state)[3][1];
+ (*state)[3][1] = temp;
+
+ // Rotate second row 2 columns to left
+ temp = (*state)[0][2];
+ (*state)[0][2] = (*state)[2][2];
+ (*state)[2][2] = temp;
+
+ temp = (*state)[1][2];
+ (*state)[1][2] = (*state)[3][2];
+ (*state)[3][2] = temp;
+
+ // Rotate third row 3 columns to left
+ temp = (*state)[0][3];
+ (*state)[0][3] = (*state)[3][3];
+ (*state)[3][3] = (*state)[2][3];
+ (*state)[2][3] = (*state)[1][3];
+ (*state)[1][3] = temp;
}
-static uint8_t xtime(uint8_t x)
-{
- return ((x<<1) ^ (((x>>7) & 1) * 0x1b));
+static uint8_t xtime(uint8_t x) {
+ return (x << 1) ^ (((x >> 7) & 1) * 0x1b);
}
// MixColumns function mixes the columns of the state matrix
-static void MixColumns(state_t* state)
-{
- uint8_t i;
- uint8_t Tmp, Tm, t;
- for (i = 0; i < 4; ++i)
- {
- t = (*state)[i][0];
- Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ;
- Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ;
- Tm = (*state)[i][1] ^ (*state)[i][2] ; Tm = xtime(Tm); (*state)[i][1] ^= Tm ^ Tmp ;
- Tm = (*state)[i][2] ^ (*state)[i][3] ; Tm = xtime(Tm); (*state)[i][2] ^= Tm ^ Tmp ;
- Tm = (*state)[i][3] ^ t ; Tm = xtime(Tm); (*state)[i][3] ^= Tm ^ Tmp ;
- }
+static void MixColumns(state_t *state) {
+ uint8_t i;
+ uint8_t Tmp, Tm, t;
+ for (i = 0; i < 4; ++i)
+ {
+ t = (*state)[i][0];
+ Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3];
+ Tm = (*state)[i][0] ^ (*state)[i][1];
+ Tm = xtime(Tm);
+ (*state)[i][0] ^= Tm ^ Tmp;
+ Tm = (*state)[i][1] ^ (*state)[i][2];
+ Tm = xtime(Tm);
+ (*state)[i][1] ^= Tm ^ Tmp;
+ Tm = (*state)[i][2] ^ (*state)[i][3];
+ Tm = xtime(Tm);
+ (*state)[i][2] ^= Tm ^ Tmp;
+ Tm = (*state)[i][3] ^ t;
+ Tm = xtime(Tm);
+ (*state)[i][3] ^= Tm ^ Tmp;
+ }
}
// Multiply is used to multiply numbers in the field GF(2^8)
@@ -362,21 +378,20 @@ static void MixColumns(state_t* state)
// The compiler seems to be able to vectorize the operation better this way.
// See https://github.com/kokke/tiny-AES-c/pull/34
#if MULTIPLY_AS_A_FUNCTION
-static uint8_t Multiply(uint8_t x, uint8_t y)
-{
- return (((y & 1) * x) ^
- ((y>>1 & 1) * xtime(x)) ^
- ((y>>2 & 1) * xtime(xtime(x))) ^
- ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^
- ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))); /* this last call to xtime() can be omitted */
- }
+static uint8_t Multiply(uint8_t x, uint8_t y) {
+ return ((y & 1) * x) ^
+ ((y >> 1 & 1) * xtime(x)) ^
+ ((y >> 2 & 1) * xtime(xtime(x))) ^
+ ((y >> 3 & 1) * xtime(xtime(xtime(x)))) ^
+ ((y >> 4 & 1) * xtime(xtime(xtime(xtime(x))))); /* this last call to xtime() can be omitted */
+}
#else
#define Multiply(x, y) \
- ( ((y & 1) * x) ^ \
- ((y>>1 & 1) * xtime(x)) ^ \
- ((y>>2 & 1) * xtime(xtime(x))) ^ \
- ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ \
- ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))) \
+ (((y & 1) * x) ^ \
+ ((y >> 1 & 1) * xtime(x)) ^ \
+ ((y >> 2 & 1) * xtime(xtime(x))) ^ \
+ ((y >> 3 & 1) * xtime(xtime(xtime(x)))) ^ \
+ ((y >> 4 & 1) * xtime(xtime(xtime(xtime(x)))))) \
#endif
@@ -384,114 +399,109 @@ static uint8_t Multiply(uint8_t x, uint8_t y)
// MixColumns function mixes the columns of the state matrix. The method used to
// multiply may be difficult to understand for the inexperienced. Please use the
// references to gain more information.
-static void InvMixColumns(state_t* state)
-{
- int i;
- uint8_t a, b, c, d;
- for (i = 0; i < 4; ++i)
- {
- a = (*state)[i][0];
- b = (*state)[i][1];
- c = (*state)[i][2];
- d = (*state)[i][3];
-
- (*state)[i][0] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d, 0x09);
- (*state)[i][1] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d, 0x0d);
- (*state)[i][2] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d, 0x0b);
- (*state)[i][3] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d, 0x0e);
- }
+static void InvMixColumns(state_t *state) {
+ int i;
+ uint8_t a, b, c, d;
+ for (i = 0; i < 4; ++i)
+ {
+ a = (*state)[i][0];
+ b = (*state)[i][1];
+ c = (*state)[i][2];
+ d = (*state)[i][3];
+
+ (*state)[i][0] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d, 0x09);
+ (*state)[i][1] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d, 0x0d);
+ (*state)[i][2] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d, 0x0b);
+ (*state)[i][3] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d, 0x0e);
+ }
}
// The SubBytes Function Substitutes the values in the state matrix with values
// in an S-box.
-static void InvSubBytes(state_t* state)
-{
- uint8_t i, j;
- for (i = 0; i < 4; ++i)
- {
- for (j = 0; j < 4; ++j)
+static void InvSubBytes(state_t *state) {
+ uint8_t i, j;
+ for (i = 0; i < 4; ++i)
{
- (*state)[j][i] = getSBoxInvert((*state)[j][i]);
+ for (j = 0; j < 4; ++j)
+ {
+ (*state)[j][i] = getSBoxInvert((*state)[j][i]);
+ }
}
- }
}
-static void InvShiftRows(state_t* state)
-{
- uint8_t temp;
-
- // Rotate first row 1 columns to right
- temp = (*state)[3][1];
- (*state)[3][1] = (*state)[2][1];
- (*state)[2][1] = (*state)[1][1];
- (*state)[1][1] = (*state)[0][1];
- (*state)[0][1] = temp;
-
- // Rotate second row 2 columns to right
- temp = (*state)[0][2];
- (*state)[0][2] = (*state)[2][2];
- (*state)[2][2] = temp;
-
- temp = (*state)[1][2];
- (*state)[1][2] = (*state)[3][2];
- (*state)[3][2] = temp;
-
- // Rotate third row 3 columns to right
- temp = (*state)[0][3];
- (*state)[0][3] = (*state)[1][3];
- (*state)[1][3] = (*state)[2][3];
- (*state)[2][3] = (*state)[3][3];
- (*state)[3][3] = temp;
+static void InvShiftRows(state_t *state) {
+ uint8_t temp;
+
+ // Rotate first row 1 columns to right
+ temp = (*state)[3][1];
+ (*state)[3][1] = (*state)[2][1];
+ (*state)[2][1] = (*state)[1][1];
+ (*state)[1][1] = (*state)[0][1];
+ (*state)[0][1] = temp;
+
+ // Rotate second row 2 columns to right
+ temp = (*state)[0][2];
+ (*state)[0][2] = (*state)[2][2];
+ (*state)[2][2] = temp;
+
+ temp = (*state)[1][2];
+ (*state)[1][2] = (*state)[3][2];
+ (*state)[3][2] = temp;
+
+ // Rotate third row 3 columns to right
+ temp = (*state)[0][3];
+ (*state)[0][3] = (*state)[1][3];
+ (*state)[1][3] = (*state)[2][3];
+ (*state)[2][3] = (*state)[3][3];
+ (*state)[3][3] = temp;
}
#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
// Cipher is the main function that encrypts the PlainText.
-static void Cipher(state_t* state, const struct AES_ctx* ctx)
-{
- const uint8_t* RoundKey = GetRoundKey(ctx);
- uint8_t round = 0;
-
- // Add the First round key to the state before starting the rounds.
- AddRoundKey(0, state, RoundKey);
-
- // There will be Nr rounds. The first Nr-1 rounds are identical. These Nr
- // rounds are executed in the loop below. Last one without MixColumns()
- for (round = 1; ; ++round)
- {
- SubBytes(state);
- ShiftRows(state);
- if (round == ctx->Nr) {
- break;
+static void Cipher(state_t *state, const struct AES_ctx *ctx) {
+ const uint8_t *RoundKey = GetRoundKey(ctx);
+ uint8_t round = 0;
+
+ // Add the First round key to the state before starting the rounds.
+ AddRoundKey(0, state, RoundKey);
+
+ // There will be Nr rounds. The first Nr-1 rounds are identical. These Nr
+ // rounds are executed in the loop below. Last one without MixColumns()
+ for (round = 1; ; ++round)
+ {
+ SubBytes(state);
+ ShiftRows(state);
+ if (round == ctx->Nr) {
+ break;
+ }
+ MixColumns(state);
+ AddRoundKey(round, state, RoundKey);
}
- MixColumns(state);
- AddRoundKey(round, state, RoundKey);
- }
- // Add round key to last round
- AddRoundKey(ctx->Nr, state, RoundKey);
+ // Add round key to last round
+ AddRoundKey(ctx->Nr, state, RoundKey);
}
#if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
-static void InvCipher(state_t* state, const struct AES_ctx* ctx)
-{
- const uint8_t* RoundKey = GetRoundKey(ctx);
- uint8_t round = 0;
-
- // Add the First round key to the state before starting the rounds.
- AddRoundKey(ctx->Nr, state, RoundKey);
-
- // There will be Nr rounds. The first Nr-1 rounds are identical. These Nr
- // rounds are executed in the loop below. Last one without InvMixColumn()
- for (round = (ctx->Nr - 1); ; --round)
- {
- InvShiftRows(state);
- InvSubBytes(state);
- AddRoundKey(round, state, RoundKey);
- if (round == 0) {
- break;
+static void InvCipher(state_t *state, const struct AES_ctx *ctx) {
+ const uint8_t *RoundKey = GetRoundKey(ctx);
+ uint8_t round = 0;
+
+ // Add the First round key to the state before starting the rounds.
+ AddRoundKey(ctx->Nr, state, RoundKey);
+
+ // There will be Nr rounds. The first Nr-1 rounds are identical. These Nr
+ // rounds are executed in the loop below. Last one without InvMixColumn()
+ for (round = (ctx->Nr - 1); ; --round)
+ {
+ InvShiftRows(state);
+ InvSubBytes(state);
+ AddRoundKey(round, state, RoundKey);
+ if (round == 0) {
+ break;
+ }
+ InvMixColumns(state);
}
- InvMixColumns(state);
- }
}
#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
@@ -502,18 +512,16 @@ static void InvCipher(state_t* state, const struct AES_ctx* ctx)
#if defined(ECB) && (ECB == 1)
-void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf)
-{
- // The next function call encrypts the PlainText with the Key using AES
- // algorithm.
- Cipher((state_t*)buf, ctx);
+void AES_ECB_encrypt(const struct AES_ctx *ctx, uint8_t *buf) {
+ // The next function call encrypts the PlainText with the Key using AES
+ // algorithm.
+ Cipher((state_t *)buf, ctx);
}
-void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf)
-{
- // The next function call decrypts the PlainText with the Key using AES
- // algorithm.
- InvCipher((state_t*)buf, ctx);
+void AES_ECB_decrypt(const struct AES_ctx *ctx, uint8_t *buf) {
+ // The next function call decrypts the PlainText with the Key using AES
+ // algorithm.
+ InvCipher((state_t *)buf, ctx);
}
@@ -526,42 +534,39 @@ void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf)
#if defined(CBC) && (CBC == 1)
-static void XorWithIv(uint8_t* buf, const uint8_t* Iv)
-{
- uint8_t i;
- for (i = 0; i < AES_BLOCKLEN; ++i) // The block in AES is always 128bit no matter the key size
- {
- buf[i] ^= Iv[i];
- }
+static void XorWithIv(uint8_t *buf, const uint8_t *Iv) {
+ uint8_t i;
+ for (i = 0; i < AES_BLOCKLEN; ++i) // The block in AES is always 128bit no matter the key size
+ {
+ buf[i] ^= Iv[i];
+ }
}
-void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, uint32_t length)
-{
- uintptr_t i;
- uint8_t *Iv = ctx->Iv;
- for (i = 0; i < length; i += AES_BLOCKLEN)
- {
- XorWithIv(buf, Iv);
- Cipher((state_t*)buf, ctx);
- Iv = buf;
- buf += AES_BLOCKLEN;
- }
- /* store Iv in ctx for next call */
- memcpy(ctx->Iv, Iv, AES_BLOCKLEN);
+void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t *buf, uint32_t length) {
+ uintptr_t i;
+ uint8_t *Iv = ctx->Iv;
+ for (i = 0; i < length; i += AES_BLOCKLEN)
+ {
+ XorWithIv(buf, Iv);
+ Cipher((state_t *)buf, ctx);
+ Iv = buf;
+ buf += AES_BLOCKLEN;
+ }
+ /* store Iv in ctx for next call */
+ memcpy(ctx->Iv, Iv, AES_BLOCKLEN);
}
-void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
-{
- uintptr_t i;
- uint8_t storeNextIv[AES_BLOCKLEN];
- for (i = 0; i < length; i += AES_BLOCKLEN)
- {
- memcpy(storeNextIv, buf, AES_BLOCKLEN);
- InvCipher((state_t*)buf, ctx);
- XorWithIv(buf, ctx->Iv);
- memcpy(ctx->Iv, storeNextIv, AES_BLOCKLEN);
- buf += AES_BLOCKLEN;
- }
+void AES_CBC_decrypt_buffer(struct AES_ctx *ctx, uint8_t *buf, uint32_t length) {
+ uintptr_t i;
+ uint8_t storeNextIv[AES_BLOCKLEN];
+ for (i = 0; i < length; i += AES_BLOCKLEN)
+ {
+ memcpy(storeNextIv, buf, AES_BLOCKLEN);
+ InvCipher((state_t *)buf, ctx);
+ XorWithIv(buf, ctx->Iv);
+ memcpy(ctx->Iv, storeNextIv, AES_BLOCKLEN);
+ buf += AES_BLOCKLEN;
+ }
}
@@ -573,36 +578,33 @@ void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
/* Symmetrical operation: same function for encrypting as for decrypting. Note
any IV/nonce should never be reused with the same key */
-void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
-{
- uint8_t buffer[AES_BLOCKLEN];
+void AES_CTR_xcrypt_buffer(struct AES_ctx *ctx, uint8_t *buf, uint32_t length) {
+ uint8_t buffer[AES_BLOCKLEN];
- unsigned i;
- int bi;
- for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi)
- {
- if (bi == AES_BLOCKLEN) /* we need to regen xor compliment in buffer */
+ unsigned i;
+ int bi;
+ for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi)
{
- memcpy(buffer, ctx->Iv, AES_BLOCKLEN);
- Cipher((state_t*)buffer, ctx);
-
- /* Increment Iv and handle overflow */
- for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi)
- {
- /* inc will overflow */
- if (ctx->Iv[bi] == 255)
- {
- ctx->Iv[bi] = 0;
- continue;
+ if (bi == AES_BLOCKLEN) { /* we need to regen xor compliment in buffer */
+ memcpy(buffer, ctx->Iv, AES_BLOCKLEN);
+ Cipher((state_t *)buffer, ctx);
+
+ /* Increment Iv and handle overflow */
+ for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi)
+ {
+ /* inc will overflow */
+ if (ctx->Iv[bi] == 255) {
+ ctx->Iv[bi] = 0;
+ continue;
+ }
+ ctx->Iv[bi] += 1;
+ break;
+ }
+ bi = 0;
}
- ctx->Iv[bi] += 1;
- break;
- }
- bi = 0;
- }
- buf[i] = (buf[i] ^ buffer[bi]);
- }
+ buf[i] = (buf[i] ^ buffer[bi]);
+ }
}
#endif // #if defined(CTR) && (CTR == 1)
diff --git a/shared-module/aesio/aes.h b/shared-module/aesio/aes.h
index a87fa5be7..92539f1da 100644
--- a/shared-module/aesio/aes.h
+++ b/shared-module/aesio/aes.h
@@ -44,37 +44,37 @@
struct AES_ctx
{
- union {
-#if defined(AES256) && (AES256 == 1)
- uint8_t RoundKey256[AES_keyExpSize256];
-#endif
-#if defined(AES192) && (AES192 == 1)
- uint8_t RoundKey192[AES_keyExpSize192];
-#endif
-#if defined(AES128) && (AES128 == 1)
- uint8_t RoundKey128[AES_keyExpSize128];
-#endif
- };
-#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
- uint8_t Iv[AES_BLOCKLEN];
-#endif
- uint32_t KeyLength;
- uint8_t Nr;
- uint8_t Nk;
+ union {
+ #if defined(AES256) && (AES256 == 1)
+ uint8_t RoundKey256[AES_keyExpSize256];
+ #endif
+ #if defined(AES192) && (AES192 == 1)
+ uint8_t RoundKey192[AES_keyExpSize192];
+ #endif
+ #if defined(AES128) && (AES128 == 1)
+ uint8_t RoundKey128[AES_keyExpSize128];
+ #endif
+ };
+ #if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
+ uint8_t Iv[AES_BLOCKLEN];
+ #endif
+ uint32_t KeyLength;
+ uint8_t Nr;
+ uint8_t Nk;
};
-void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key, uint32_t keylen);
+void AES_init_ctx(struct AES_ctx *ctx, const uint8_t *key, uint32_t keylen);
#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
-void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, uint32_t keylen, const uint8_t* iv);
-void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv);
+void AES_init_ctx_iv(struct AES_ctx *ctx, const uint8_t *key, uint32_t keylen, const uint8_t *iv);
+void AES_ctx_set_iv(struct AES_ctx *ctx, const uint8_t *iv);
#endif
#if defined(ECB) && (ECB == 1)
// buffer size is exactly AES_BLOCKLEN bytes;
// you need only AES_init_ctx as IV is not used in ECB
// NB: ECB is considered insecure for most uses
-void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf);
-void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf);
+void AES_ECB_encrypt(const struct AES_ctx *ctx, uint8_t *buf);
+void AES_ECB_decrypt(const struct AES_ctx *ctx, uint8_t *buf);
#endif // #if defined(ECB) && (ECB == !)
@@ -84,8 +84,8 @@ void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf);
// Suggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
// NOTES: you need to set IV in ctx via AES_init_ctx_iv() or AES_ctx_set_iv()
// no IV should ever be reused with the same key
-void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
-void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
+void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t *buf, uint32_t length);
+void AES_CBC_decrypt_buffer(struct AES_ctx *ctx, uint8_t *buf, uint32_t length);
#endif // #if defined(CBC) && (CBC == 1)
@@ -97,7 +97,7 @@ void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
// Suggesting https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
// NOTES: you need to set IV in ctx with AES_init_ctx_iv() or AES_ctx_set_iv()
// no IV should ever be reused with the same key
-void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
+void AES_CTR_xcrypt_buffer(struct AES_ctx *ctx, uint8_t *buf, uint32_t length);
#endif // #if defined(CTR) && (CTR == 1)
diff --git a/shared-module/audiocore/RawSample.c b/shared-module/audiocore/RawSample.c
index 316a1c69f..1f1db0a50 100644
--- a/shared-module/audiocore/RawSample.c
+++ b/shared-module/audiocore/RawSample.c
@@ -30,13 +30,13 @@
#include "shared-module/audiocore/RawSample.h"
-void common_hal_audioio_rawsample_construct(audioio_rawsample_obj_t* self,
- uint8_t* buffer,
- uint32_t len,
- uint8_t bytes_per_sample,
- bool samples_signed,
- uint8_t channel_count,
- uint32_t sample_rate) {
+void common_hal_audioio_rawsample_construct(audioio_rawsample_obj_t *self,
+ uint8_t *buffer,
+ uint32_t len,
+ uint8_t bytes_per_sample,
+ bool samples_signed,
+ uint8_t channel_count,
+ uint32_t sample_rate) {
self->buffer = buffer;
self->bits_per_sample = bytes_per_sample * 8;
self->samples_signed = samples_signed;
@@ -45,37 +45,37 @@ void common_hal_audioio_rawsample_construct(audioio_rawsample_obj_t* self,
self->sample_rate = sample_rate;
}
-void common_hal_audioio_rawsample_deinit(audioio_rawsample_obj_t* self) {
+void common_hal_audioio_rawsample_deinit(audioio_rawsample_obj_t *self) {
self->buffer = NULL;
}
-bool common_hal_audioio_rawsample_deinited(audioio_rawsample_obj_t* self) {
+bool common_hal_audioio_rawsample_deinited(audioio_rawsample_obj_t *self) {
return self->buffer == NULL;
}
-uint32_t common_hal_audioio_rawsample_get_sample_rate(audioio_rawsample_obj_t* self) {
+uint32_t common_hal_audioio_rawsample_get_sample_rate(audioio_rawsample_obj_t *self) {
return self->sample_rate;
}
-void common_hal_audioio_rawsample_set_sample_rate(audioio_rawsample_obj_t* self,
- uint32_t sample_rate) {
+void common_hal_audioio_rawsample_set_sample_rate(audioio_rawsample_obj_t *self,
+ uint32_t sample_rate) {
self->sample_rate = sample_rate;
}
-uint8_t common_hal_audioio_rawsample_get_bits_per_sample(audioio_rawsample_obj_t* self) {
+uint8_t common_hal_audioio_rawsample_get_bits_per_sample(audioio_rawsample_obj_t *self) {
return self->bits_per_sample;
}
-uint8_t common_hal_audioio_rawsample_get_channel_count(audioio_rawsample_obj_t* self) {
+uint8_t common_hal_audioio_rawsample_get_channel_count(audioio_rawsample_obj_t *self) {
return self->channel_count;
}
-void audioio_rawsample_reset_buffer(audioio_rawsample_obj_t* self,
- bool single_channel,
- uint8_t channel) {
+void audioio_rawsample_reset_buffer(audioio_rawsample_obj_t *self,
+ bool single_channel,
+ uint8_t channel) {
}
-audioio_get_buffer_result_t audioio_rawsample_get_buffer(audioio_rawsample_obj_t* self,
- bool single_channel,
- uint8_t channel,
- uint8_t** buffer,
- uint32_t* buffer_length) {
+audioio_get_buffer_result_t audioio_rawsample_get_buffer(audioio_rawsample_obj_t *self,
+ bool single_channel,
+ uint8_t channel,
+ uint8_t **buffer,
+ uint32_t *buffer_length) {
*buffer_length = self->len;
if (single_channel) {
*buffer = self->buffer + (channel % self->channel_count) * (self->bits_per_sample / 8);
@@ -85,9 +85,9 @@ audioio_get_buffer_result_t audioio_rawsample_get_buffer(audioio_rawsample_obj_t
return GET_BUFFER_DONE;
}
-void audioio_rawsample_get_buffer_structure(audioio_rawsample_obj_t* self, bool single_channel,
- bool* single_buffer, bool* samples_signed,
- uint32_t* max_buffer_length, uint8_t* spacing) {
+void audioio_rawsample_get_buffer_structure(audioio_rawsample_obj_t *self, bool single_channel,
+ bool *single_buffer, bool *samples_signed,
+ uint32_t *max_buffer_length, uint8_t *spacing) {
*single_buffer = true;
*samples_signed = self->samples_signed;
*max_buffer_length = self->len;
diff --git a/shared-module/audiocore/RawSample.h b/shared-module/audiocore/RawSample.h
index 2ea8c89f4..8208b4c28 100644
--- a/shared-module/audiocore/RawSample.h
+++ b/shared-module/audiocore/RawSample.h
@@ -33,7 +33,7 @@
typedef struct {
mp_obj_base_t base;
- uint8_t* buffer;
+ uint8_t *buffer;
uint32_t len;
uint8_t bits_per_sample;
bool samples_signed;
@@ -43,16 +43,16 @@ typedef struct {
// These are not available from Python because it may be called in an interrupt.
-void audioio_rawsample_reset_buffer(audioio_rawsample_obj_t* self,
- bool single_channel,
- uint8_t channel);
-audioio_get_buffer_result_t audioio_rawsample_get_buffer(audioio_rawsample_obj_t* self,
- bool single_channel,
- uint8_t channel,
- uint8_t** buffer,
- uint32_t* buffer_length); // length in bytes
-void audioio_rawsample_get_buffer_structure(audioio_rawsample_obj_t* self, bool single_channel,
- bool* single_buffer, bool* samples_signed,
- uint32_t* max_buffer_length, uint8_t* spacing);
+void audioio_rawsample_reset_buffer(audioio_rawsample_obj_t *self,
+ bool single_channel,
+ uint8_t channel);
+audioio_get_buffer_result_t audioio_rawsample_get_buffer(audioio_rawsample_obj_t *self,
+ bool single_channel,
+ uint8_t channel,
+ uint8_t **buffer,
+ uint32_t *buffer_length); // length in bytes
+void audioio_rawsample_get_buffer_structure(audioio_rawsample_obj_t *self, bool single_channel,
+ bool *single_buffer, bool *samples_signed,
+ uint32_t *max_buffer_length, uint8_t *spacing);
#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_RAWSAMPLE_H
diff --git a/shared-module/audiocore/WaveFile.c b/shared-module/audiocore/WaveFile.c
index 0248d42e2..4864004d5 100644
--- a/shared-module/audiocore/WaveFile.c
+++ b/shared-module/audiocore/WaveFile.c
@@ -45,10 +45,10 @@ struct wave_format_chunk {
uint16_t extra_params; // Assumed to be zero below.
};
-void common_hal_audioio_wavefile_construct(audioio_wavefile_obj_t* self,
- pyb_file_obj_t* file,
- uint8_t *buffer,
- size_t buffer_size) {
+void common_hal_audioio_wavefile_construct(audioio_wavefile_obj_t *self,
+ pyb_file_obj_t *file,
+ uint8_t *buffer,
+ size_t buffer_size) {
// Load the wave
self->file = file;
uint8_t chunk_header[16];
@@ -96,7 +96,7 @@ void common_hal_audioio_wavefile_construct(audioio_wavefile_obj_t* self,
mp_raise_OSError(MP_EIO);
}
if (bytes_read != 4 ||
- memcmp((uint8_t *) data_tag, "data", 4) != 0) {
+ memcmp((uint8_t *)data_tag, "data", 4) != 0) {
mp_raise_ValueError(translate("Data chunk must follow fmt chunk"));
}
@@ -122,55 +122,55 @@ void common_hal_audioio_wavefile_construct(audioio_wavefile_obj_t* self,
if (self->buffer == NULL) {
common_hal_audioio_wavefile_deinit(self);
mp_raise_msg(&mp_type_MemoryError,
- translate("Couldn't allocate first buffer"));
+ translate("Couldn't allocate first buffer"));
}
self->second_buffer = m_malloc(self->len, false);
if (self->second_buffer == NULL) {
common_hal_audioio_wavefile_deinit(self);
mp_raise_msg(&mp_type_MemoryError,
- translate("Couldn't allocate second buffer"));
+ translate("Couldn't allocate second buffer"));
}
}
}
-void common_hal_audioio_wavefile_deinit(audioio_wavefile_obj_t* self) {
+void common_hal_audioio_wavefile_deinit(audioio_wavefile_obj_t *self) {
self->buffer = NULL;
self->second_buffer = NULL;
}
-bool common_hal_audioio_wavefile_deinited(audioio_wavefile_obj_t* self) {
+bool common_hal_audioio_wavefile_deinited(audioio_wavefile_obj_t *self) {
return self->buffer == NULL;
}
-uint32_t common_hal_audioio_wavefile_get_sample_rate(audioio_wavefile_obj_t* self) {
+uint32_t common_hal_audioio_wavefile_get_sample_rate(audioio_wavefile_obj_t *self) {
return self->sample_rate;
}
-void common_hal_audioio_wavefile_set_sample_rate(audioio_wavefile_obj_t* self,
- uint32_t sample_rate) {
+void common_hal_audioio_wavefile_set_sample_rate(audioio_wavefile_obj_t *self,
+ uint32_t sample_rate) {
self->sample_rate = sample_rate;
}
-uint8_t common_hal_audioio_wavefile_get_bits_per_sample(audioio_wavefile_obj_t* self) {
+uint8_t common_hal_audioio_wavefile_get_bits_per_sample(audioio_wavefile_obj_t *self) {
return self->bits_per_sample;
}
-uint8_t common_hal_audioio_wavefile_get_channel_count(audioio_wavefile_obj_t* self) {
+uint8_t common_hal_audioio_wavefile_get_channel_count(audioio_wavefile_obj_t *self) {
return self->channel_count;
}
-bool audioio_wavefile_samples_signed(audioio_wavefile_obj_t* self) {
+bool audioio_wavefile_samples_signed(audioio_wavefile_obj_t *self) {
return self->bits_per_sample > 8;
}
-uint32_t audioio_wavefile_max_buffer_length(audioio_wavefile_obj_t* self) {
+uint32_t audioio_wavefile_max_buffer_length(audioio_wavefile_obj_t *self) {
return 512;
}
-void audioio_wavefile_reset_buffer(audioio_wavefile_obj_t* self,
- bool single_channel,
- uint8_t channel) {
+void audioio_wavefile_reset_buffer(audioio_wavefile_obj_t *self,
+ bool single_channel,
+ uint8_t channel) {
if (single_channel && channel == 1) {
return;
}
@@ -183,11 +183,11 @@ void audioio_wavefile_reset_buffer(audioio_wavefile_obj_t* self,
self->right_read_count = 0;
}
-audioio_get_buffer_result_t audioio_wavefile_get_buffer(audioio_wavefile_obj_t* self,
- bool single_channel,
- uint8_t channel,
- uint8_t** buffer,
- uint32_t* buffer_length) {
+audioio_get_buffer_result_t audioio_wavefile_get_buffer(audioio_wavefile_obj_t *self,
+ bool single_channel,
+ uint8_t channel,
+ uint8_t **buffer,
+ uint32_t *buffer_length) {
if (!single_channel) {
channel = 0;
}
@@ -226,13 +226,13 @@ audioio_get_buffer_result_t audioio_wavefile_get_buffer(audioio_wavefile_obj_t*
length_read += pad;
if (self->bits_per_sample == 8) {
for (uint32_t i = 0; i < pad; i++) {
- ((uint8_t*) (*buffer))[length_read / sizeof(uint8_t) - i - 1] = 0x80;
+ ((uint8_t *)(*buffer))[length_read / sizeof(uint8_t) - i - 1] = 0x80;
}
} else if (self->bits_per_sample == 16) {
// We know the buffer is aligned because we allocated it onto the heap ourselves.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
- ((int16_t*) (*buffer))[length_read / sizeof(int16_t) - 1] = 0;
+ ((int16_t *)(*buffer))[length_read / sizeof(int16_t) - 1] = 0;
#pragma GCC diagnostic pop
}
}
@@ -265,9 +265,9 @@ audioio_get_buffer_result_t audioio_wavefile_get_buffer(audioio_wavefile_obj_t*
return self->bytes_remaining == 0 ? GET_BUFFER_DONE : GET_BUFFER_MORE_DATA;
}
-void audioio_wavefile_get_buffer_structure(audioio_wavefile_obj_t* self, bool single_channel,
- bool* single_buffer, bool* samples_signed,
- uint32_t* max_buffer_length, uint8_t* spacing) {
+void audioio_wavefile_get_buffer_structure(audioio_wavefile_obj_t *self, bool single_channel,
+ bool *single_buffer, bool *samples_signed,
+ uint32_t *max_buffer_length, uint8_t *spacing) {
*single_buffer = false;
*samples_signed = self->bits_per_sample > 8;
*max_buffer_length = 512;
diff --git a/shared-module/audiocore/WaveFile.h b/shared-module/audiocore/WaveFile.h
index 3eecbf15c..80b2fd3a5 100644
--- a/shared-module/audiocore/WaveFile.h
+++ b/shared-module/audiocore/WaveFile.h
@@ -34,9 +34,9 @@
typedef struct {
mp_obj_base_t base;
- uint8_t* buffer;
+ uint8_t *buffer;
uint32_t buffer_length;
- uint8_t* second_buffer;
+ uint8_t *second_buffer;
uint32_t second_buffer_length;
uint32_t file_length; // In bytes
uint16_t data_start; // Where the data values start
@@ -48,7 +48,7 @@ typedef struct {
uint32_t sample_rate;
uint32_t len;
- pyb_file_obj_t* file;
+ pyb_file_obj_t *file;
uint32_t read_count;
uint32_t left_read_count;
@@ -56,16 +56,16 @@ typedef struct {
} audioio_wavefile_obj_t;
// These are not available from Python because it may be called in an interrupt.
-void audioio_wavefile_reset_buffer(audioio_wavefile_obj_t* self,
- bool single_channel,
- uint8_t channel);
-audioio_get_buffer_result_t audioio_wavefile_get_buffer(audioio_wavefile_obj_t* self,
- bool single_channel,
- uint8_t channel,
- uint8_t** buffer,
- uint32_t* buffer_length); // length in bytes
-void audioio_wavefile_get_buffer_structure(audioio_wavefile_obj_t* self, bool single_channel,
- bool* single_buffer, bool* samples_signed,
- uint32_t* max_buffer_length, uint8_t* spacing);
+void audioio_wavefile_reset_buffer(audioio_wavefile_obj_t *self,
+ bool single_channel,
+ uint8_t channel);
+audioio_get_buffer_result_t audioio_wavefile_get_buffer(audioio_wavefile_obj_t *self,
+ bool single_channel,
+ uint8_t channel,
+ uint8_t **buffer,
+ uint32_t *buffer_length); // length in bytes
+void audioio_wavefile_get_buffer_structure(audioio_wavefile_obj_t *self, bool single_channel,
+ bool *single_buffer, bool *samples_signed,
+ uint32_t *max_buffer_length, uint8_t *spacing);
#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_WAVEFILE_H
diff --git a/shared-module/audiocore/__init__.c b/shared-module/audiocore/__init__.c
index 7bdfe460c..605eac70b 100644
--- a/shared-module/audiocore/__init__.c
+++ b/shared-module/audiocore/__init__.c
@@ -56,23 +56,23 @@ void audiosample_reset_buffer(mp_obj_t sample_obj, bool single_channel, uint8_t
}
audioio_get_buffer_result_t audiosample_get_buffer(mp_obj_t sample_obj,
- bool single_channel,
- uint8_t channel,
- uint8_t** buffer, uint32_t* buffer_length) {
+ bool single_channel,
+ uint8_t channel,
+ uint8_t **buffer, uint32_t *buffer_length) {
const audiosample_p_t *proto = mp_proto_get_or_throw(MP_QSTR_protocol_audiosample, sample_obj);
return proto->get_buffer(MP_OBJ_TO_PTR(sample_obj), single_channel, channel, buffer, buffer_length);
}
void audiosample_get_buffer_structure(mp_obj_t sample_obj, bool single_channel,
- bool* single_buffer, bool* samples_signed,
- uint32_t* max_buffer_length, uint8_t* spacing) {
+ bool *single_buffer, bool *samples_signed,
+ uint32_t *max_buffer_length, uint8_t *spacing) {
const audiosample_p_t *proto = mp_proto_get_or_throw(MP_QSTR_protocol_audiosample, sample_obj);
proto->get_buffer_structure(MP_OBJ_TO_PTR(sample_obj), single_channel, single_buffer,
samples_signed, max_buffer_length, spacing);
}
void audiosample_convert_u8m_s16s(int16_t *buffer_out, const uint8_t *buffer_in, size_t nframes) {
- for(;nframes--;) {
+ for (; nframes--;) {
int16_t sample = (*buffer_in++ - 0x80) << 8;
*buffer_out++ = sample;
*buffer_out++ = sample;
@@ -81,15 +81,15 @@ void audiosample_convert_u8m_s16s(int16_t *buffer_out, const uint8_t *buffer_in,
void audiosample_convert_u8s_s16s(int16_t *buffer_out, const uint8_t *buffer_in, size_t nframes) {
- size_t nsamples = 2*nframes;
- for(;nsamples--;) {
+ size_t nsamples = 2 * nframes;
+ for (; nsamples--;) {
int16_t sample = (*buffer_in++ - 0x80) << 8;
*buffer_out++ = sample;
}
}
void audiosample_convert_s8m_s16s(int16_t *buffer_out, const int8_t *buffer_in, size_t nframes) {
- for(;nframes--;) {
+ for (; nframes--;) {
int16_t sample = (*buffer_in++) << 8;
*buffer_out++ = sample;
*buffer_out++ = sample;
@@ -98,8 +98,8 @@ void audiosample_convert_s8m_s16s(int16_t *buffer_out, const int8_t *buffer_in,
void audiosample_convert_s8s_s16s(int16_t *buffer_out, const int8_t *buffer_in, size_t nframes) {
- size_t nsamples = 2*nframes;
- for(;nsamples--;) {
+ size_t nsamples = 2 * nframes;
+ for (; nsamples--;) {
int16_t sample = (*buffer_in++) << 8;
*buffer_out++ = sample;
}
@@ -107,7 +107,7 @@ void audiosample_convert_s8s_s16s(int16_t *buffer_out, const int8_t *buffer_in,
void audiosample_convert_u16m_s16s(int16_t *buffer_out, const uint16_t *buffer_in, size_t nframes) {
- for(;nframes--;) {
+ for (; nframes--;) {
int16_t sample = *buffer_in++ - 0x8000;
*buffer_out++ = sample;
*buffer_out++ = sample;
@@ -116,15 +116,15 @@ void audiosample_convert_u16m_s16s(int16_t *buffer_out, const uint16_t *buffer_i
void audiosample_convert_u16s_s16s(int16_t *buffer_out, const uint16_t *buffer_in, size_t nframes) {
- size_t nsamples = 2*nframes;
- for(;nsamples--;) {
+ size_t nsamples = 2 * nframes;
+ for (; nsamples--;) {
int16_t sample = *buffer_in++ - 0x8000;
*buffer_out++ = sample;
}
}
void audiosample_convert_s16m_s16s(int16_t *buffer_out, const int16_t *buffer_in, size_t nframes) {
- for(;nframes--;) {
+ for (; nframes--;) {
int16_t sample = *buffer_in++;
*buffer_out++ = sample;
*buffer_out++ = sample;
diff --git a/shared-module/audiocore/__init__.h b/shared-module/audiocore/__init__.h
index ec2cf1cfa..69955a25f 100644
--- a/shared-module/audiocore/__init__.h
+++ b/shared-module/audiocore/__init__.h
@@ -43,14 +43,14 @@ typedef uint32_t (*audiosample_sample_rate_fun)(mp_obj_t);
typedef uint8_t (*audiosample_bits_per_sample_fun)(mp_obj_t);
typedef uint8_t (*audiosample_channel_count_fun)(mp_obj_t);
typedef void (*audiosample_reset_buffer_fun)(mp_obj_t,
- bool single_channel, uint8_t audio_channel);
+ bool single_channel, uint8_t audio_channel);
typedef audioio_get_buffer_result_t (*audiosample_get_buffer_fun)(mp_obj_t,
- bool single_channel, uint8_t channel, uint8_t** buffer,
- uint32_t* buffer_length);
+ bool single_channel, uint8_t channel, uint8_t **buffer,
+ uint32_t *buffer_length);
typedef void (*audiosample_get_buffer_structure_fun)(mp_obj_t,
- bool single_channel, bool* single_buffer,
- bool* samples_signed, uint32_t *max_buffer_length,
- uint8_t* spacing);
+ bool single_channel, bool *single_buffer,
+ bool *samples_signed, uint32_t *max_buffer_length,
+ uint8_t *spacing);
typedef struct _audiosample_p_t {
MP_PROTOCOL_HEAD // MP_QSTR_protocol_audiosample
@@ -67,12 +67,12 @@ uint8_t audiosample_bits_per_sample(mp_obj_t sample_obj);
uint8_t audiosample_channel_count(mp_obj_t sample_obj);
void audiosample_reset_buffer(mp_obj_t sample_obj, bool single_channel, uint8_t audio_channel);
audioio_get_buffer_result_t audiosample_get_buffer(mp_obj_t sample_obj,
- bool single_channel,
- uint8_t channel,
- uint8_t** buffer, uint32_t* buffer_length);
+ bool single_channel,
+ uint8_t channel,
+ uint8_t **buffer, uint32_t *buffer_length);
void audiosample_get_buffer_structure(mp_obj_t sample_obj, bool single_channel,
- bool* single_buffer, bool* samples_signed,
- uint32_t* max_buffer_length, uint8_t* spacing);
+ bool *single_buffer, bool *samples_signed,
+ uint32_t *max_buffer_length, uint8_t *spacing);
void audiosample_convert_u8m_s16s(int16_t *buffer_out, const uint8_t *buffer_in, size_t nframes);
void audiosample_convert_u8s_s16s(int16_t *buffer_out, const uint8_t *buffer_in, size_t nframes);
diff --git a/shared-module/audiomixer/Mixer.c b/shared-module/audiomixer/Mixer.c
index 6c1ba1973..fdcd2dbfb 100644
--- a/shared-module/audiomixer/Mixer.c
+++ b/shared-module/audiomixer/Mixer.c
@@ -35,13 +35,13 @@
#include "shared-module/audiocore/__init__.h"
#include "shared-module/audiocore/RawSample.h"
-void common_hal_audiomixer_mixer_construct(audiomixer_mixer_obj_t* self,
- uint8_t voice_count,
- uint32_t buffer_size,
- uint8_t bits_per_sample,
- bool samples_signed,
- uint8_t channel_count,
- uint32_t sample_rate) {
+void common_hal_audiomixer_mixer_construct(audiomixer_mixer_obj_t *self,
+ uint8_t voice_count,
+ uint32_t buffer_size,
+ uint8_t bits_per_sample,
+ bool samples_signed,
+ uint8_t channel_count,
+ uint32_t sample_rate) {
self->len = buffer_size / 2 / sizeof(uint32_t) * sizeof(uint32_t);
self->first_buffer = m_malloc(self->len, false);
@@ -63,28 +63,28 @@ void common_hal_audiomixer_mixer_construct(audiomixer_mixer_obj_t* self,
self->voice_count = voice_count;
}
-void common_hal_audiomixer_mixer_deinit(audiomixer_mixer_obj_t* self) {
+void common_hal_audiomixer_mixer_deinit(audiomixer_mixer_obj_t *self) {
self->first_buffer = NULL;
self->second_buffer = NULL;
}
-bool common_hal_audiomixer_mixer_deinited(audiomixer_mixer_obj_t* self) {
+bool common_hal_audiomixer_mixer_deinited(audiomixer_mixer_obj_t *self) {
return self->first_buffer == NULL;
}
-uint32_t common_hal_audiomixer_mixer_get_sample_rate(audiomixer_mixer_obj_t* self) {
+uint32_t common_hal_audiomixer_mixer_get_sample_rate(audiomixer_mixer_obj_t *self) {
return self->sample_rate;
}
-uint8_t common_hal_audiomixer_mixer_get_channel_count(audiomixer_mixer_obj_t* self) {
+uint8_t common_hal_audiomixer_mixer_get_channel_count(audiomixer_mixer_obj_t *self) {
return self->channel_count;
}
-uint8_t common_hal_audiomixer_mixer_get_bits_per_sample(audiomixer_mixer_obj_t* self) {
+uint8_t common_hal_audiomixer_mixer_get_bits_per_sample(audiomixer_mixer_obj_t *self) {
return self->bits_per_sample;
}
-bool common_hal_audiomixer_mixer_get_playing(audiomixer_mixer_obj_t* self) {
+bool common_hal_audiomixer_mixer_get_playing(audiomixer_mixer_obj_t *self) {
for (uint8_t v = 0; v < self->voice_count; v++) {
if (common_hal_audiomixer_mixervoice_get_playing(MP_OBJ_TO_PTR(self->voice[v]))) {
return true;
@@ -93,9 +93,9 @@ bool common_hal_audiomixer_mixer_get_playing(audiomixer_mixer_obj_t* self) {
return false;
}
-void audiomixer_mixer_reset_buffer(audiomixer_mixer_obj_t* self,
- bool single_channel,
- uint8_t channel) {
+void audiomixer_mixer_reset_buffer(audiomixer_mixer_obj_t *self,
+ bool single_channel,
+ uint8_t channel) {
for (uint8_t i = 0; i < self->voice_count; i++) {
common_hal_audiomixer_mixervoice_stop(self->voice[i]);
}
@@ -112,11 +112,11 @@ static inline uint32_t mult16signed(uint32_t val, int32_t mul) {
int32_t hi, lo;
enum { bits = 16 }; // saturate to 16 bits
enum { shift = 15 }; // shift is done automatically
- asm volatile("smulwb %0, %1, %2" : "=r" (lo) : "r" (mul), "r" (val));
- asm volatile("smulwt %0, %1, %2" : "=r" (hi) : "r" (mul), "r" (val));
- asm volatile("ssat %0, %1, %2, asr %3" : "=r" (lo) : "I" (bits), "r" (lo), "I" (shift));
- asm volatile("ssat %0, %1, %2, asr %3" : "=r" (hi) : "I" (bits), "r" (hi), "I" (shift));
- asm volatile("pkhbt %0, %1, %2, lsl #16" : "=r" (val) : "r" (lo), "r" (hi)); // pack
+ asm volatile ("smulwb %0, %1, %2" : "=r" (lo) : "r" (mul), "r" (val));
+ asm volatile ("smulwt %0, %1, %2" : "=r" (hi) : "r" (mul), "r" (val));
+ asm volatile ("ssat %0, %1, %2, asr %3" : "=r" (lo) : "I" (bits), "r" (lo), "I" (shift));
+ asm volatile ("ssat %0, %1, %2, asr %3" : "=r" (hi) : "I" (bits), "r" (hi), "I" (shift));
+ asm volatile ("pkhbt %0, %1, %2, lsl #16" : "=r" (val) : "r" (lo), "r" (hi)); // pack
return val;
}
@@ -140,9 +140,9 @@ static inline uint32_t pack8(uint32_t val) {
return ((val & 0xff000000) >> 16) | ((val & 0xff00) >> 8);
}
-static void mix_down_one_voice(audiomixer_mixer_obj_t* self,
- audiomixer_mixervoice_obj_t* voice, bool voices_active,
- uint32_t* word_buffer, uint32_t length) {
+static void mix_down_one_voice(audiomixer_mixer_obj_t *self,
+ audiomixer_mixervoice_obj_t *voice, bool voices_active,
+ uint32_t *word_buffer, uint32_t length) {
while (length != 0) {
if (voice->buffer_length == 0) {
if (!voice->more_data) {
@@ -155,7 +155,7 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t* self,
}
if (voice->sample) {
// Load another buffer
- audioio_get_buffer_result_t result = audiosample_get_buffer(voice->sample, false, 0, (uint8_t**) &voice->remaining_buffer, &voice->buffer_length);
+ audioio_get_buffer_result_t result = audiosample_get_buffer(voice->sample, false, 0, (uint8_t **)&voice->remaining_buffer, &voice->buffer_length);
// Track length in terms of words.
voice->buffer_length /= sizeof(uint32_t);
voice->more_data = result == GET_BUFFER_MORE_DATA;
@@ -170,21 +170,21 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t* self,
if (!voices_active) {
if (MP_LIKELY(self->bits_per_sample == 16)) {
if (MP_LIKELY(self->samples_signed)) {
- for (uint32_t i = 0; i<n; i++) {
+ for (uint32_t i = 0; i < n; i++) {
uint32_t v = src[i];
word_buffer[i] = mult16signed(v, level);
}
} else {
- for (uint32_t i = 0; i<n; i++) {
+ for (uint32_t i = 0; i < n; i++) {
uint32_t v = src[i];
v = tosigned16(v);
word_buffer[i] = mult16signed(v, level);
}
}
} else {
- uint16_t *hword_buffer = (uint16_t*)word_buffer;
- uint16_t *hsrc = (uint16_t*)src;
- for (uint32_t i = 0; i<n*2; i++) {
+ uint16_t *hword_buffer = (uint16_t *)word_buffer;
+ uint16_t *hsrc = (uint16_t *)src;
+ for (uint32_t i = 0; i < n * 2; i++) {
uint32_t word = unpack8(hsrc[i]);
if (MP_LIKELY(!self->samples_signed)) {
word = tosigned16(word);
@@ -196,21 +196,21 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t* self,
} else {
if (MP_LIKELY(self->bits_per_sample == 16)) {
if (MP_LIKELY(self->samples_signed)) {
- for (uint32_t i = 0; i<n; i++) {
+ for (uint32_t i = 0; i < n; i++) {
uint32_t word = src[i];
word_buffer[i] = add16signed(mult16signed(word, level), word_buffer[i]);
}
} else {
- for (uint32_t i = 0; i<n; i++) {
+ for (uint32_t i = 0; i < n; i++) {
uint32_t word = src[i];
word = tosigned16(word);
word_buffer[i] = add16signed(mult16signed(word, level), word_buffer[i]);
- }
+ }
}
} else {
- uint16_t *hword_buffer = (uint16_t*)word_buffer;
- uint16_t *hsrc = (uint16_t*)src;
- for (uint32_t i = 0; i<n*2; i++) {
+ uint16_t *hword_buffer = (uint16_t *)word_buffer;
+ uint16_t *hsrc = (uint16_t *)src;
+ for (uint32_t i = 0; i < n * 2; i++) {
uint32_t word = unpack8(hsrc[i]);
if (MP_LIKELY(!self->samples_signed)) {
word = tosigned16(word);
@@ -228,17 +228,17 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t* self,
}
if (length && !voices_active) {
- for (uint32_t i = 0; i<length; i++) {
+ for (uint32_t i = 0; i < length; i++) {
word_buffer[i] = 0;
}
}
}
-audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t* self,
- bool single_channel,
- uint8_t channel,
- uint8_t** buffer,
- uint32_t* buffer_length) {
+audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t *self,
+ bool single_channel,
+ uint8_t channel,
+ uint8_t **buffer,
+ uint32_t *buffer_length) {
if (!single_channel) {
channel = 0;
}
@@ -251,12 +251,12 @@ audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t*
bool need_more_data = self->read_count == channel_read_count;
if (need_more_data) {
- uint32_t* word_buffer;
+ uint32_t *word_buffer;
if (self->use_first_buffer) {
- *buffer = (uint8_t*) self->first_buffer;
+ *buffer = (uint8_t *)self->first_buffer;
word_buffer = self->first_buffer;
} else {
- *buffer = (uint8_t*) self->second_buffer;
+ *buffer = (uint8_t *)self->second_buffer;
word_buffer = self->second_buffer;
}
self->use_first_buffer = !self->use_first_buffer;
@@ -264,15 +264,15 @@ audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t*
uint32_t length = self->len / sizeof(uint32_t);
for (int32_t v = 0; v < self->voice_count; v++) {
- audiomixer_mixervoice_obj_t* voice = MP_OBJ_TO_PTR(self->voice[v]);
- if(voice->sample) {
+ audiomixer_mixervoice_obj_t *voice = MP_OBJ_TO_PTR(self->voice[v]);
+ if (voice->sample) {
mix_down_one_voice(self, voice, voices_active, word_buffer, length);
voices_active = true;
}
}
if (!voices_active) {
- for (uint32_t i = 0; i<length; i++) {
+ for (uint32_t i = 0; i < length; i++) {
word_buffer[i] = 0;
}
}
@@ -291,9 +291,9 @@ audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t*
self->read_count += 1;
} else if (!self->use_first_buffer) {
- *buffer = (uint8_t*) self->first_buffer;
+ *buffer = (uint8_t *)self->first_buffer;
} else {
- *buffer = (uint8_t*) self->second_buffer;
+ *buffer = (uint8_t *)self->second_buffer;
}
@@ -306,9 +306,9 @@ audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t*
return GET_BUFFER_MORE_DATA;
}
-void audiomixer_mixer_get_buffer_structure(audiomixer_mixer_obj_t* self, bool single_channel,
- bool* single_buffer, bool* samples_signed,
- uint32_t* max_buffer_length, uint8_t* spacing) {
+void audiomixer_mixer_get_buffer_structure(audiomixer_mixer_obj_t *self, bool single_channel,
+ bool *single_buffer, bool *samples_signed,
+ uint32_t *max_buffer_length, uint8_t *spacing) {
*single_buffer = false;
*samples_signed = self->samples_signed;
*max_buffer_length = self->len;
diff --git a/shared-module/audiomixer/Mixer.h b/shared-module/audiomixer/Mixer.h
index ab4780efc..ceb04772e 100644
--- a/shared-module/audiomixer/Mixer.h
+++ b/shared-module/audiomixer/Mixer.h
@@ -34,8 +34,8 @@
typedef struct {
mp_obj_base_t base;
- uint32_t* first_buffer;
- uint32_t* second_buffer;
+ uint32_t *first_buffer;
+ uint32_t *second_buffer;
uint32_t len; // in words
uint8_t bits_per_sample;
bool use_first_buffer;
@@ -54,16 +54,16 @@ typedef struct {
// These are not available from Python because it may be called in an interrupt.
-void audiomixer_mixer_reset_buffer(audiomixer_mixer_obj_t* self,
- bool single_channel,
- uint8_t channel);
-audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t* self,
- bool single_channel,
- uint8_t channel,
- uint8_t** buffer,
- uint32_t* buffer_length); // length in bytes
-void audiomixer_mixer_get_buffer_structure(audiomixer_mixer_obj_t* self, bool single_channel,
- bool* single_buffer, bool* samples_signed,
- uint32_t* max_buffer_length, uint8_t* spacing);
+void audiomixer_mixer_reset_buffer(audiomixer_mixer_obj_t *self,
+ bool single_channel,
+ uint8_t channel);
+audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t *self,
+ bool single_channel,
+ uint8_t channel,
+ uint8_t **buffer,
+ uint32_t *buffer_length); // length in bytes
+void audiomixer_mixer_get_buffer_structure(audiomixer_mixer_obj_t *self, bool single_channel,
+ bool *single_buffer, bool *samples_signed,
+ uint32_t *max_buffer_length, uint8_t *spacing);
#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOMIXER_MIXER_H
diff --git a/shared-module/audiomixer/MixerVoice.c b/shared-module/audiomixer/MixerVoice.c
index 9be104afc..34fa907a5 100644
--- a/shared-module/audiomixer/MixerVoice.c
+++ b/shared-module/audiomixer/MixerVoice.c
@@ -37,19 +37,19 @@ void common_hal_audiomixer_mixervoice_construct(audiomixer_mixervoice_obj_t *sel
self->level = 1 << 15;
}
-void common_hal_audiomixer_mixervoice_set_parent(audiomixer_mixervoice_obj_t* self, audiomixer_mixer_obj_t *parent) {
- self->parent = parent;
+void common_hal_audiomixer_mixervoice_set_parent(audiomixer_mixervoice_obj_t *self, audiomixer_mixer_obj_t *parent) {
+ self->parent = parent;
}
-float common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t* self) {
- return ((float) self->level / (1 << 15));
+float common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t *self) {
+ return (float)self->level / (1 << 15);
}
-void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t* self, float level) {
- self->level = level * (1 << 15);
+void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *self, float level) {
+ self->level = level * (1 << 15);
}
-void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t* self, mp_obj_t sample, bool loop) {
+void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t *self, mp_obj_t sample, bool loop) {
if (audiosample_sample_rate(sample) != self->parent->sample_rate) {
mp_raise_ValueError(translate("The sample's sample rate does not match the mixer's"));
}
@@ -64,7 +64,7 @@ void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t* self, mp
uint32_t max_buffer_length;
uint8_t spacing;
audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed,
- &max_buffer_length, &spacing);
+ &max_buffer_length, &spacing);
if (samples_signed != self->parent->samples_signed) {
mp_raise_ValueError(translate("The sample's signedness does not match the mixer's"));
}
@@ -72,16 +72,16 @@ void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t* self, mp
self->loop = loop;
audiosample_reset_buffer(sample, false, 0);
- audioio_get_buffer_result_t result = audiosample_get_buffer(sample, false, 0, (uint8_t**) &self->remaining_buffer, &self->buffer_length);
+ audioio_get_buffer_result_t result = audiosample_get_buffer(sample, false, 0, (uint8_t **)&self->remaining_buffer, &self->buffer_length);
// Track length in terms of words.
self->buffer_length /= sizeof(uint32_t);
self->more_data = result == GET_BUFFER_MORE_DATA;
}
-bool common_hal_audiomixer_mixervoice_get_playing(audiomixer_mixervoice_obj_t* self) {
- return self->sample != NULL;
+bool common_hal_audiomixer_mixervoice_get_playing(audiomixer_mixervoice_obj_t *self) {
+ return self->sample != NULL;
}
-void common_hal_audiomixer_mixervoice_stop(audiomixer_mixervoice_obj_t* self) {
+void common_hal_audiomixer_mixervoice_stop(audiomixer_mixervoice_obj_t *self) {
self->sample = NULL;
}
diff --git a/shared-module/audiomixer/MixerVoice.h b/shared-module/audiomixer/MixerVoice.h
index a85316e3d..1fdc91d11 100644
--- a/shared-module/audiomixer/MixerVoice.h
+++ b/shared-module/audiomixer/MixerVoice.h
@@ -32,12 +32,12 @@
#include "shared-module/audiomixer/Mixer.h"
typedef struct {
- mp_obj_base_t base;
- audiomixer_mixer_obj_t *parent;
+ mp_obj_base_t base;
+ audiomixer_mixer_obj_t *parent;
mp_obj_t sample;
bool loop;
bool more_data;
- uint32_t* remaining_buffer;
+ uint32_t *remaining_buffer;
uint32_t buffer_length;
uint16_t level;
} audiomixer_mixervoice_obj_t;
diff --git a/shared-module/audiomp3/MP3Decoder.c b/shared-module/audiomp3/MP3Decoder.c
index 5f3f42a51..2b623233e 100644
--- a/shared-module/audiomp3/MP3Decoder.c
+++ b/shared-module/audiomp3/MP3Decoder.c
@@ -51,7 +51,7 @@
*
* Sets self->eof if any read of the file returns 0 bytes
*/
-STATIC bool mp3file_update_inbuf_always(audiomp3_mp3file_obj_t* self) {
+STATIC bool mp3file_update_inbuf_always(audiomp3_mp3file_obj_t *self) {
// If we didn't previously reach the end of file, we can try reading now
if (!self->eof) {
@@ -90,7 +90,7 @@ STATIC bool mp3file_update_inbuf_always(audiomp3_mp3file_obj_t* self) {
* This variant is introduced so that at the site of the
* add_background_callback_core call, the prototype matches.
*/
-STATIC void mp3file_update_inbuf_cb(void* self) {
+STATIC void mp3file_update_inbuf_cb(void *self) {
mp3file_update_inbuf_always(self);
}
@@ -98,9 +98,11 @@ STATIC void mp3file_update_inbuf_cb(void* self) {
*
* Returns the same as mp3file_update_inbuf_always.
*/
-STATIC bool mp3file_update_inbuf_half(audiomp3_mp3file_obj_t* self) {
+STATIC bool mp3file_update_inbuf_half(audiomp3_mp3file_obj_t *self) {
// If buffer is over half full, do nothing
- if (self->inbuf_offset < self->inbuf_length/2) return true;
+ if (self->inbuf_offset < self->inbuf_length / 2) {
+ return true;
+ }
return mp3file_update_inbuf_always(self);
}
@@ -111,23 +113,23 @@ STATIC bool mp3file_update_inbuf_half(audiomp3_mp3file_obj_t* self) {
// http://id3.org/d3v2.3.0
// http://id3.org/id3v2.3.0
-STATIC void mp3file_skip_id3v2(audiomp3_mp3file_obj_t* self) {
+STATIC void mp3file_skip_id3v2(audiomp3_mp3file_obj_t *self) {
mp3file_update_inbuf_half(self);
if (BYTES_LEFT(self) < 10) {
return;
}
uint8_t *data = READ_PTR(self);
if (!(
- data[0] == 'I' &&
- data[1] == 'D' &&
- data[2] == '3' &&
- data[3] != 0xff &&
- data[4] != 0xff &&
- (data[5] & 0x1f) == 0 &&
- (data[6] & 0x80) == 0 &&
- (data[7] & 0x80) == 0 &&
- (data[8] & 0x80) == 0 &&
- (data[9] & 0x80) == 0)) {
+ data[0] == 'I' &&
+ data[1] == 'D' &&
+ data[2] == '3' &&
+ data[3] != 0xff &&
+ data[4] != 0xff &&
+ (data[5] & 0x1f) == 0 &&
+ (data[6] & 0x80) == 0 &&
+ (data[7] & 0x80) == 0 &&
+ (data[8] & 0x80) == 0 &&
+ (data[9] & 0x80) == 0)) {
return;
}
uint32_t size = (data[6] << 21) | (data[7] << 14) | (data[8] << 7) | (data[9]);
@@ -145,7 +147,7 @@ STATIC void mp3file_skip_id3v2(audiomp3_mp3file_obj_t* self) {
/* If a sync word can be found, advance to it and return true. Otherwise,
* return false.
*/
-STATIC bool mp3file_find_sync_word(audiomp3_mp3file_obj_t* self) {
+STATIC bool mp3file_find_sync_word(audiomp3_mp3file_obj_t *self) {
do {
mp3file_update_inbuf_half(self);
int offset = MP3FindSyncWord(READ_PTR(self), BYTES_LEFT(self));
@@ -159,7 +161,7 @@ STATIC bool mp3file_find_sync_word(audiomp3_mp3file_obj_t* self) {
return false;
}
-STATIC bool mp3file_get_next_frame_info(audiomp3_mp3file_obj_t* self, MP3FrameInfo* fi) {
+STATIC bool mp3file_get_next_frame_info(audiomp3_mp3file_obj_t *self, MP3FrameInfo *fi) {
int err;
do {
err = MP3GetNextFrameInfo(self->decoder, fi, READ_PTR(self));
@@ -172,10 +174,10 @@ STATIC bool mp3file_get_next_frame_info(audiomp3_mp3file_obj_t* self, MP3FrameIn
return err == ERR_MP3_NONE;
}
-void common_hal_audiomp3_mp3file_construct(audiomp3_mp3file_obj_t* self,
- pyb_file_obj_t* file,
- uint8_t *buffer,
- size_t buffer_size) {
+void common_hal_audiomp3_mp3file_construct(audiomp3_mp3file_obj_t *self,
+ pyb_file_obj_t *file,
+ uint8_t *buffer,
+ size_t buffer_size) {
// XXX Adafruit_MP3 uses a 2kB input buffer and two 4kB output buffers.
// for a whopping total of 10kB buffers (+mp3 decoder state and frame buffer)
// At 44kHz, that's 23ms of output audio data.
@@ -192,41 +194,42 @@ void common_hal_audiomp3_mp3file_construct(audiomp3_mp3file_obj_t* self,
if (self->inbuf == NULL) {
common_hal_audiomp3_mp3file_deinit(self);
mp_raise_msg(&mp_type_MemoryError,
- translate("Couldn't allocate input buffer"));
+ translate("Couldn't allocate input buffer"));
}
self->decoder = MP3InitDecoder();
if (self->decoder == NULL) {
common_hal_audiomp3_mp3file_deinit(self);
mp_raise_msg(&mp_type_MemoryError,
- translate("Couldn't allocate decoder"));
+ translate("Couldn't allocate decoder"));
}
if ((intptr_t)buffer & 1) {
- buffer += 1; buffer_size -= 1;
+ buffer += 1;
+ buffer_size -= 1;
}
if (buffer_size >= 2 * MAX_BUFFER_LEN) {
- self->buffers[0] = (int16_t*)(void*)buffer;
- self->buffers[1] = (int16_t*)(void*)(buffer + MAX_BUFFER_LEN);
+ self->buffers[0] = (int16_t *)(void *)buffer;
+ self->buffers[1] = (int16_t *)(void *)(buffer + MAX_BUFFER_LEN);
} else {
self->buffers[0] = m_malloc(MAX_BUFFER_LEN, false);
if (self->buffers[0] == NULL) {
common_hal_audiomp3_mp3file_deinit(self);
mp_raise_msg(&mp_type_MemoryError,
- translate("Couldn't allocate first buffer"));
+ translate("Couldn't allocate first buffer"));
}
self->buffers[1] = m_malloc(MAX_BUFFER_LEN, false);
if (self->buffers[1] == NULL) {
common_hal_audiomp3_mp3file_deinit(self);
mp_raise_msg(&mp_type_MemoryError,
- translate("Couldn't allocate second buffer"));
+ translate("Couldn't allocate second buffer"));
}
}
common_hal_audiomp3_mp3file_set_file(self, file);
}
-void common_hal_audiomp3_mp3file_set_file(audiomp3_mp3file_obj_t* self, pyb_file_obj_t* file) {
+void common_hal_audiomp3_mp3file_set_file(audiomp3_mp3file_obj_t *self, pyb_file_obj_t *file) {
background_callback_begin_critical_section();
self->file = file;
@@ -248,16 +251,16 @@ void common_hal_audiomp3_mp3file_set_file(audiomp3_mp3file_obj_t* self, pyb_file
background_callback_end_critical_section();
if (!result) {
mp_raise_msg(&mp_type_RuntimeError,
- translate("Failed to parse MP3 file"));
+ translate("Failed to parse MP3 file"));
}
self->sample_rate = fi.samprate;
self->channel_count = fi.nChans;
- self->frame_buffer_size = fi.outputSamps*sizeof(int16_t);
+ self->frame_buffer_size = fi.outputSamps * sizeof(int16_t);
self->len = 2 * self->frame_buffer_size;
}
-void common_hal_audiomp3_mp3file_deinit(audiomp3_mp3file_obj_t* self) {
+void common_hal_audiomp3_mp3file_deinit(audiomp3_mp3file_obj_t *self) {
MP3FreeDecoder(self->decoder);
self->decoder = NULL;
self->inbuf = NULL;
@@ -266,34 +269,34 @@ void common_hal_audiomp3_mp3file_deinit(audiomp3_mp3file_obj_t* self) {
self->file = NULL;
}
-bool common_hal_audiomp3_mp3file_deinited(audiomp3_mp3file_obj_t* self) {
+bool common_hal_audiomp3_mp3file_deinited(audiomp3_mp3file_obj_t *self) {
return self->buffers[0] == NULL;
}
-uint32_t common_hal_audiomp3_mp3file_get_sample_rate(audiomp3_mp3file_obj_t* self) {
+uint32_t common_hal_audiomp3_mp3file_get_sample_rate(audiomp3_mp3file_obj_t *self) {
return self->sample_rate;
}
-void common_hal_audiomp3_mp3file_set_sample_rate(audiomp3_mp3file_obj_t* self,
- uint32_t sample_rate) {
+void common_hal_audiomp3_mp3file_set_sample_rate(audiomp3_mp3file_obj_t *self,
+ uint32_t sample_rate) {
self->sample_rate = sample_rate;
}
-uint8_t common_hal_audiomp3_mp3file_get_bits_per_sample(audiomp3_mp3file_obj_t* self) {
+uint8_t common_hal_audiomp3_mp3file_get_bits_per_sample(audiomp3_mp3file_obj_t *self) {
return 16;
}
-uint8_t common_hal_audiomp3_mp3file_get_channel_count(audiomp3_mp3file_obj_t* self) {
+uint8_t common_hal_audiomp3_mp3file_get_channel_count(audiomp3_mp3file_obj_t *self) {
return self->channel_count;
}
-bool audiomp3_mp3file_samples_signed(audiomp3_mp3file_obj_t* self) {
+bool audiomp3_mp3file_samples_signed(audiomp3_mp3file_obj_t *self) {
return true;
}
-void audiomp3_mp3file_reset_buffer(audiomp3_mp3file_obj_t* self,
- bool single_channel,
- uint8_t channel) {
+void audiomp3_mp3file_reset_buffer(audiomp3_mp3file_obj_t *self,
+ bool single_channel,
+ uint8_t channel) {
if (single_channel && channel == 1) {
return;
}
@@ -310,11 +313,11 @@ void audiomp3_mp3file_reset_buffer(audiomp3_mp3file_obj_t* self,
background_callback_end_critical_section();
}
-audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t* self,
- bool single_channel,
- uint8_t channel,
- uint8_t** bufptr,
- uint32_t* buffer_length) {
+audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t *self,
+ bool single_channel,
+ uint8_t channel,
+ uint8_t **bufptr,
+ uint32_t *buffer_length) {
if (!self->inbuf) {
return GET_BUFFER_ERROR;
}
@@ -325,17 +328,17 @@ audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t*
*buffer_length = self->frame_buffer_size;
if (channel == self->other_channel) {
- *bufptr = (uint8_t*)(self->buffers[self->other_buffer_index] + channel);
+ *bufptr = (uint8_t *)(self->buffers[self->other_buffer_index] + channel);
self->other_channel = -1;
return GET_BUFFER_MORE_DATA;
}
self->buffer_index = !self->buffer_index;
- self->other_channel = 1-channel;
+ self->other_channel = 1 - channel;
self->other_buffer_index = self->buffer_index;
int16_t *buffer = (int16_t *)(void *)self->buffers[self->buffer_index];
- *bufptr = (uint8_t*)buffer;
+ *bufptr = (uint8_t *)buffer;
mp3file_skip_id3v2(self);
if (!mp3file_find_sync_word(self)) {
@@ -360,9 +363,9 @@ audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t*
return GET_BUFFER_MORE_DATA;
}
-void audiomp3_mp3file_get_buffer_structure(audiomp3_mp3file_obj_t* self, bool single_channel,
- bool* single_buffer, bool* samples_signed,
- uint32_t* max_buffer_length, uint8_t* spacing) {
+void audiomp3_mp3file_get_buffer_structure(audiomp3_mp3file_obj_t *self, bool single_channel,
+ bool *single_buffer, bool *samples_signed,
+ uint32_t *max_buffer_length, uint8_t *spacing) {
*single_buffer = false;
*samples_signed = true;
*max_buffer_length = self->frame_buffer_size;
@@ -373,11 +376,11 @@ void audiomp3_mp3file_get_buffer_structure(audiomp3_mp3file_obj_t* self, bool si
}
}
-float common_hal_audiomp3_mp3file_get_rms_level(audiomp3_mp3file_obj_t* self) {
+float common_hal_audiomp3_mp3file_get_rms_level(audiomp3_mp3file_obj_t *self) {
float sumsq = 0.f;
// Assumes no DC component to the audio. Is that a safe assumption?
int16_t *buffer = (int16_t *)(void *)self->buffers[self->buffer_index];
- for(size_t i=0; i<self->frame_buffer_size / sizeof(int16_t); i++) {
+ for (size_t i = 0; i < self->frame_buffer_size / sizeof(int16_t); i++) {
sumsq += (float)buffer[i] * buffer[i];
}
return sqrtf(sumsq) / (self->frame_buffer_size / sizeof(int16_t));
diff --git a/shared-module/audiomp3/MP3Decoder.h b/shared-module/audiomp3/MP3Decoder.h
index f91f102a2..c1e617846 100644
--- a/shared-module/audiomp3/MP3Decoder.h
+++ b/shared-module/audiomp3/MP3Decoder.h
@@ -38,15 +38,15 @@ typedef struct {
mp_obj_base_t base;
struct _MP3DecInfo *decoder;
background_callback_t inbuf_fill_cb;
- uint8_t* inbuf;
+ uint8_t *inbuf;
uint32_t inbuf_length;
uint32_t inbuf_offset;
- int16_t* buffers[2];
+ int16_t *buffers[2];
uint32_t len;
uint32_t frame_buffer_size;
uint32_t sample_rate;
- pyb_file_obj_t* file;
+ pyb_file_obj_t *file;
uint8_t buffer_index;
uint8_t channel_count;
@@ -57,18 +57,18 @@ typedef struct {
} audiomp3_mp3file_obj_t;
// These are not available from Python because it may be called in an interrupt.
-void audiomp3_mp3file_reset_buffer(audiomp3_mp3file_obj_t* self,
- bool single_channel,
- uint8_t channel);
-audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t* self,
- bool single_channel,
- uint8_t channel,
- uint8_t** buffer,
- uint32_t* buffer_length); // length in bytes
-void audiomp3_mp3file_get_buffer_structure(audiomp3_mp3file_obj_t* self, bool single_channel,
- bool* single_buffer, bool* samples_signed,
- uint32_t* max_buffer_length, uint8_t* spacing);
+void audiomp3_mp3file_reset_buffer(audiomp3_mp3file_obj_t *self,
+ bool single_channel,
+ uint8_t channel);
+audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t *self,
+ bool single_channel,
+ uint8_t channel,
+ uint8_t **buffer,
+ uint32_t *buffer_length); // length in bytes
+void audiomp3_mp3file_get_buffer_structure(audiomp3_mp3file_obj_t *self, bool single_channel,
+ bool *single_buffer, bool *samples_signed,
+ uint32_t *max_buffer_length, uint8_t *spacing);
-float audiomp3_mp3file_get_rms_level(audiomp3_mp3file_obj_t* self);
+float audiomp3_mp3file_get_rms_level(audiomp3_mp3file_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MP3FILE_H
diff --git a/shared-module/bitbangio/I2C.c b/shared-module/bitbangio/I2C.c
index 170630df6..7d7380e21 100644
--- a/shared-module/bitbangio/I2C.c
+++ b/shared-module/bitbangio/I2C.c
@@ -143,10 +143,10 @@ STATIC bool read_byte(bitbangio_i2c_obj_t *self, uint8_t *val, bool ack) {
}
void shared_module_bitbangio_i2c_construct(bitbangio_i2c_obj_t *self,
- const mcu_pin_obj_t * scl,
- const mcu_pin_obj_t * sda,
- uint32_t frequency,
- uint32_t us_timeout) {
+ const mcu_pin_obj_t *scl,
+ const mcu_pin_obj_t *sda,
+ uint32_t frequency,
+ uint32_t us_timeout) {
self->us_timeout = us_timeout;
self->us_delay = 500000 / frequency;
@@ -208,7 +208,7 @@ bool shared_module_bitbangio_i2c_probe(bitbangio_i2c_obj_t *self, uint8_t addr)
}
uint8_t shared_module_bitbangio_i2c_write(bitbangio_i2c_obj_t *self, uint16_t addr,
- const uint8_t *data, size_t len, bool transmit_stop_bit) {
+ const uint8_t *data, size_t len, bool transmit_stop_bit) {
// start the I2C transaction
start(self);
uint8_t status = 0;
@@ -232,7 +232,7 @@ uint8_t shared_module_bitbangio_i2c_write(bitbangio_i2c_obj_t *self, uint16_t ad
}
uint8_t shared_module_bitbangio_i2c_read(bitbangio_i2c_obj_t *self, uint16_t addr,
- uint8_t * data, size_t len) {
+ uint8_t *data, size_t len) {
// start the I2C transaction
start(self);
uint8_t status = 0;
diff --git a/shared-module/bitbangio/OneWire.c b/shared-module/bitbangio/OneWire.c
index 3e4ec8426..8a73817f3 100644
--- a/shared-module/bitbangio/OneWire.c
+++ b/shared-module/bitbangio/OneWire.c
@@ -31,17 +31,17 @@
// Durations are taken from here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126
-void shared_module_bitbangio_onewire_construct(bitbangio_onewire_obj_t* self,
- const mcu_pin_obj_t* pin) {
+void shared_module_bitbangio_onewire_construct(bitbangio_onewire_obj_t *self,
+ const mcu_pin_obj_t *pin) {
self->pin.base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(&self->pin, pin);
}
-bool shared_module_bitbangio_onewire_deinited(bitbangio_onewire_obj_t* self) {
+bool shared_module_bitbangio_onewire_deinited(bitbangio_onewire_obj_t *self) {
return common_hal_digitalio_digitalinout_deinited(&self->pin);
}
-void shared_module_bitbangio_onewire_deinit(bitbangio_onewire_obj_t* self) {
+void shared_module_bitbangio_onewire_deinit(bitbangio_onewire_obj_t *self) {
if (shared_module_bitbangio_onewire_deinited(self)) {
return;
}
@@ -51,7 +51,7 @@ void shared_module_bitbangio_onewire_deinit(bitbangio_onewire_obj_t* self) {
// We use common_hal_mcu_delay_us(). It should not be dependent on interrupts
// to do accurate timekeeping, since we disable interrupts during the delays below.
-bool shared_module_bitbangio_onewire_reset(bitbangio_onewire_obj_t* self) {
+bool shared_module_bitbangio_onewire_reset(bitbangio_onewire_obj_t *self) {
common_hal_mcu_disable_interrupts();
common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN);
common_hal_mcu_delay_us(480);
@@ -63,7 +63,7 @@ bool shared_module_bitbangio_onewire_reset(bitbangio_onewire_obj_t* self) {
return value;
}
-bool shared_module_bitbangio_onewire_read_bit(bitbangio_onewire_obj_t* self) {
+bool shared_module_bitbangio_onewire_read_bit(bitbangio_onewire_obj_t *self) {
common_hal_mcu_disable_interrupts();
common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN);
common_hal_mcu_delay_us(6);
@@ -78,8 +78,8 @@ bool shared_module_bitbangio_onewire_read_bit(bitbangio_onewire_obj_t* self) {
return value;
}
-void shared_module_bitbangio_onewire_write_bit(bitbangio_onewire_obj_t* self,
- bool bit) {
+void shared_module_bitbangio_onewire_write_bit(bitbangio_onewire_obj_t *self,
+ bool bit) {
common_hal_mcu_disable_interrupts();
common_hal_digitalio_digitalinout_switch_to_output(&self->pin, false, DRIVE_MODE_OPEN_DRAIN);
common_hal_mcu_delay_us(bit? 6 : 60);
diff --git a/shared-module/bitbangio/SPI.c b/shared-module/bitbangio/SPI.c
index 9ed3d660a..8be6cac5f 100644
--- a/shared-module/bitbangio/SPI.c
+++ b/shared-module/bitbangio/SPI.c
@@ -37,8 +37,8 @@
#define MAX_BAUDRATE (common_hal_mcu_get_clock_frequency() / 48)
void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
- const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi,
- const mcu_pin_obj_t * miso) {
+ const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi,
+ const mcu_pin_obj_t *miso) {
digitalinout_result_t result = common_hal_digitalio_digitalinout_construct(&self->clock, clock);
if (result != DIGITALINOUT_OK) {
mp_raise_ValueError(translate("Clock pin init failed."));
@@ -90,7 +90,7 @@ void shared_module_bitbangio_spi_deinit(bitbangio_spi_obj_t *self) {
}
void shared_module_bitbangio_spi_configure(bitbangio_spi_obj_t *self,
- uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {
+ uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {
self->delay_half = 500000 / baudrate;
// round delay_half up so that: actual_baudrate <= requested_baudrate
if (500000 % baudrate != 0) {
@@ -241,7 +241,7 @@ bool shared_module_bitbangio_spi_read(bitbangio_spi_obj_t *self, uint8_t *data,
// transfer
bool shared_module_bitbangio_spi_transfer(bitbangio_spi_obj_t *self, const uint8_t *dout, uint8_t *din, size_t len) {
- if (len > 0 && (!self->has_mosi || !self->has_miso) ) {
+ if (len > 0 && (!self->has_mosi || !self->has_miso)) {
mp_raise_ValueError(translate("Cannot transfer without MOSI and MISO pins."));
}
uint32_t delay_half = self->delay_half;
diff --git a/shared-module/bitbangio/SPI.h b/shared-module/bitbangio/SPI.h
index f3e02c206..cc71a0319 100644
--- a/shared-module/bitbangio/SPI.h
+++ b/shared-module/bitbangio/SPI.h
@@ -37,11 +37,11 @@ typedef struct {
digitalio_digitalinout_obj_t mosi;
digitalio_digitalinout_obj_t miso;
uint32_t delay_half;
- bool has_miso:1;
- bool has_mosi:1;
- uint8_t polarity:1;
- uint8_t phase:1;
- volatile bool locked:1;
+ bool has_miso : 1;
+ bool has_mosi : 1;
+ uint8_t polarity : 1;
+ uint8_t phase : 1;
+ volatile bool locked : 1;
} bitbangio_spi_obj_t;
#endif // MICROPY_INCLUDED_SHARED_MODULE_BITBANGIO_SPI_H
diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c
index 044600aca..2d6aadee7 100644
--- a/shared-module/bitmaptools/__init__.c
+++ b/shared-module/bitmaptools/__init__.c
@@ -36,14 +36,14 @@
#include "stdlib.h"
void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16_t oy,
- int16_t dest_clip0_x, int16_t dest_clip0_y,
- int16_t dest_clip1_x, int16_t dest_clip1_y,
- displayio_bitmap_t *source, int16_t px, int16_t py,
- int16_t source_clip0_x, int16_t source_clip0_y,
- int16_t source_clip1_x, int16_t source_clip1_y,
- float angle,
- float scale,
- uint32_t skip_index, bool skip_index_none) {
+ int16_t dest_clip0_x, int16_t dest_clip0_y,
+ int16_t dest_clip1_x, int16_t dest_clip1_y,
+ displayio_bitmap_t *source, int16_t px, int16_t py,
+ int16_t source_clip0_x, int16_t source_clip0_y,
+ int16_t source_clip1_x, int16_t source_clip1_y,
+ float angle,
+ float scale,
+ uint32_t skip_index, bool skip_index_none) {
// Copies region from source to the destination bitmap, including rotation,
// scaling and clipping of either the source or destination regions
@@ -115,37 +115,77 @@ void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16
will be on the destination to get a bounding box for scanning */
dx = -cosAngle * px * scale + sinAngle * py * scale + ox;
dy = -sinAngle * px * scale - cosAngle * py * scale + oy;
- if(dx < minx) minx = (int16_t)dx;
- if(dx > maxx) maxx = (int16_t)dx;
- if(dy < miny) miny = (int16_t)dy;
- if(dy > maxy) maxy = (int16_t)dy;
+ if (dx < minx) {
+ minx = (int16_t)dx;
+ }
+ if (dx > maxx) {
+ maxx = (int16_t)dx;
+ }
+ if (dy < miny) {
+ miny = (int16_t)dy;
+ }
+ if (dy > maxy) {
+ maxy = (int16_t)dy;
+ }
dx = cosAngle * (source->width - px) * scale + sinAngle * py * scale + ox;
dy = sinAngle * (source->width - px) * scale - cosAngle * py * scale + oy;
- if(dx < minx) minx = (int16_t)dx;
- if(dx > maxx) maxx = (int16_t)dx;
- if(dy < miny) miny = (int16_t)dy;
- if(dy > maxy) maxy = (int16_t)dy;
+ if (dx < minx) {
+ minx = (int16_t)dx;
+ }
+ if (dx > maxx) {
+ maxx = (int16_t)dx;
+ }
+ if (dy < miny) {
+ miny = (int16_t)dy;
+ }
+ if (dy > maxy) {
+ maxy = (int16_t)dy;
+ }
dx = cosAngle * (source->width - px) * scale - sinAngle * (source->height - py) * scale + ox;
dy = sinAngle * (source->width - px) * scale + cosAngle * (source->height - py) * scale + oy;
- if(dx < minx) minx = (int16_t)dx;
- if(dx > maxx) maxx = (int16_t)dx;
- if(dy < miny) miny = (int16_t)dy;
- if(dy > maxy) maxy = (int16_t)dy;
+ if (dx < minx) {
+ minx = (int16_t)dx;
+ }
+ if (dx > maxx) {
+ maxx = (int16_t)dx;
+ }
+ if (dy < miny) {
+ miny = (int16_t)dy;
+ }
+ if (dy > maxy) {
+ maxy = (int16_t)dy;
+ }
dx = -cosAngle * px * scale - sinAngle * (source->height - py) * scale + ox;
dy = -sinAngle * px * scale + cosAngle * (source->height - py) * scale + oy;
- if(dx < minx) minx = (int16_t)dx;
- if(dx > maxx) maxx = (int16_t)dx;
- if(dy < miny) miny = (int16_t)dy;
- if(dy > maxy) maxy = (int16_t)dy;
+ if (dx < minx) {
+ minx = (int16_t)dx;
+ }
+ if (dx > maxx) {
+ maxx = (int16_t)dx;
+ }
+ if (dy < miny) {
+ miny = (int16_t)dy;
+ }
+ if (dy > maxy) {
+ maxy = (int16_t)dy;
+ }
/* Clipping */
- if(minx < dest_clip0_x) minx = dest_clip0_x;
- if(maxx > dest_clip1_x - 1) maxx = dest_clip1_x - 1;
- if(miny < dest_clip0_y) miny = dest_clip0_y;
- if(maxy > dest_clip1_y - 1) maxy = dest_clip1_y - 1;
+ if (minx < dest_clip0_x) {
+ minx = dest_clip0_x;
+ }
+ if (maxx > dest_clip1_x - 1) {
+ maxx = dest_clip1_x - 1;
+ }
+ if (miny < dest_clip0_y) {
+ miny = dest_clip0_y;
+ }
+ if (maxy > dest_clip1_y - 1) {
+ maxy = dest_clip1_y - 1;
+ }
float dvCol = cosAngle / scale;
float duCol = sinAngle / scale;
@@ -159,13 +199,13 @@ void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16
float rowu = startu + miny * duCol;
float rowv = startv + miny * dvCol;
- for(y = miny; y <= maxy; y++) {
+ for (y = miny; y <= maxy; y++) {
float u = rowu + minx * duRow;
float v = rowv + minx * dvRow;
- for(x = minx; x <= maxx; x++) {
- if(u >= source_clip0_x && u < source_clip1_x && v >= source_clip0_y && v < source_clip1_y) {
+ for (x = minx; x <= maxx; x++) {
+ if (u >= source_clip0_x && u < source_clip1_x && v >= source_clip0_y && v < source_clip1_y) {
uint32_t c = common_hal_displayio_bitmap_get_pixel(source, u, v);
- if( (skip_index_none) || (c != skip_index) ) {
+ if ((skip_index_none) || (c != skip_index)) {
common_hal_displayio_bitmap_set_pixel(self, x, y, c);
}
}
@@ -189,9 +229,9 @@ int16_t constrain(int16_t input, int16_t min, int16_t max) {
}
void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
- int16_t x1, int16_t y1,
- int16_t x2, int16_t y2,
- uint32_t value) {
+ int16_t x1, int16_t y1,
+ int16_t x2, int16_t y2,
+ uint32_t value) {
// writes the value (a bitmap color index) into a bitmap in the specified rectangular region
//
// input checks should ensure that x1 < x2 and y1 < y2 and are within the bitmap region
@@ -202,14 +242,14 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
// Ensure x1 < x2 and y1 < y2
if (x1 > x2) {
- int16_t temp=x2;
- x2=x1;
- x1=temp;
+ int16_t temp = x2;
+ x2 = x1;
+ x1 = temp;
}
if (y1 > y2) {
- int16_t temp=y2;
- y2=y1;
- y1=temp;
+ int16_t temp = y2;
+ y2 = y1;
+ y1 = temp;
}
// constrain to bitmap dimensions
@@ -223,16 +263,16 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
int16_t x, y;
for (x = x1; x < x2; x++) {
- for (y = y1; y < y2; y++ ) {
+ for (y = y1; y < y2; y++) {
displayio_bitmap_write_pixel(destination, x, y, value);
}
}
}
void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
- int16_t x0, int16_t y0,
- int16_t x1, int16_t y1,
- uint32_t value) {
+ int16_t x0, int16_t y0,
+ int16_t x1, int16_t y1,
+ uint32_t value) {
if (destination->read_only) {
mp_raise_RuntimeError(translate("Read-only object"));
@@ -277,8 +317,7 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
for (y = y0; y < (y1 + 1); y++) { // write a horizontal line
displayio_bitmap_write_pixel(destination, x0, y, value);
}
- }
- else if (y0 == y1) { // horizontal line
+ } else if (y0 == y1) { // horizontal line
if (x0 > x1) { // ensure y1 > y0
temp = x0;
x0 = x1;
@@ -287,12 +326,11 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
for (x = x0; x < (x1 + 1); x++) { // write a horizontal line
displayio_bitmap_write_pixel(destination, x, y0, value);
}
- }
- else {
+ } else {
bool steep;
- steep = ( abs(y1 - y0) > abs(x1 - x0) );
+ steep = (abs(y1 - y0) > abs(x1 - x0));
- if ( steep ) { // flip x0<->y0 and x1<->y1
+ if (steep) { // flip x0<->y0 and x1<->y1
temp = x0;
x0 = y0;
y0 = temp;
@@ -318,16 +356,14 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
if (y0 < y1) {
ystep = 1;
- }
- else {
+ } else {
ystep = -1;
}
for (x = x0; x < (x1 + 1); x++) {
if (steep) {
displayio_bitmap_write_pixel(destination, y0, x, value);
- }
- else {
+ } else {
displayio_bitmap_write_pixel(destination, x, y0, value);
}
err -= dy;
@@ -342,23 +378,23 @@ void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
void common_hal_bitmaptools_arrayblit(displayio_bitmap_t *self, void *data, int element_size, int x1, int y1, int x2, int y2, bool skip_specified, uint32_t skip_value) {
uint32_t mask = (1 << common_hal_displayio_bitmap_get_bits_per_value(self)) - 1;
- for (int y=y1; y<y2; y++) {
- for (int x=x1; x<x2; x++) {
+ for (int y = y1; y < y2; y++) {
+ for (int x = x1; x < x2; x++) {
uint32_t value;
- switch(element_size) {
- default:
- case 1:
- value = *(uint8_t*) data;
- data = (void*)((uint8_t*)data + 1);
- break;
- case 2:
- value = *(uint16_t*) data;
- data = (void*)((uint16_t*)data + 1);
- break;
- case 4:
- value = *(uint32_t*) data;
- data = (void*)((uint32_t*)data + 1);
- break;
+ switch (element_size) {
+ default:
+ case 1:
+ value = *(uint8_t *)data;
+ data = (void *)((uint8_t *)data + 1);
+ break;
+ case 2:
+ value = *(uint16_t *)data;
+ data = (void *)((uint16_t *)data + 1);
+ break;
+ case 4:
+ value = *(uint32_t *)data;
+ data = (void *)((uint32_t *)data + 1);
+ break;
}
if (!skip_specified || value != skip_value) {
displayio_bitmap_write_pixel(self, x, y, value & mask);
@@ -391,63 +427,60 @@ void common_hal_bitmaptools_readinto(displayio_bitmap_t *self, pyb_file_obj_t* f
}
if (swap_bytes) {
- switch(element_size) {
- case 2:
- for(size_t i=0; i< rowsize_in_u16; i++) {
- rowdata16[i] = __builtin_bswap16(rowdata16[i]);
- }
- break;
- case 4:
- for(size_t i=0; i< rowsize_in_u32; i++) {
- rowdata32[i] = __builtin_bswap32(rowdata32[i]);
- }
- default:
- break;
+ switch (element_size) {
+ case 2:
+ for (size_t i = 0; i < rowsize_in_u16; i++) {
+ rowdata16[i] = __builtin_bswap16(rowdata16[i]);
+ }
+ break;
+ case 4:
+ for (size_t i = 0; i < rowsize_in_u32; i++) {
+ rowdata32[i] = __builtin_bswap32(rowdata32[i]);
+ }
+ default:
+ break;
}
}
- for(int x=0; x<self->width; x++) {
+ for (int x = 0; x < self->width; x++) {
int value = 0;
- switch(bits_per_pixel) {
- case 1:
- {
+ switch (bits_per_pixel) {
+ case 1: {
int byte_offset = x / 8;
int bit_offset = reverse_pixels_in_element ? (7 - x % 8) : x % 8;
value = (rowdata8[byte_offset] >> bit_offset) & 1;
break;
}
- case 2:
- {
+ case 2: {
int byte_offset = x / 4;
int bit_offset = 2 * (reverse_pixels_in_element ? (3 - x % 4) : x % 4);
value = (rowdata8[byte_offset] >> bit_offset) & 3;
break;
}
- case 4:
- {
+ case 4: {
int byte_offset = x / 2;
int bit_offset = 4 * (reverse_pixels_in_element ? (1 - x % 2) : x % 2);
value = (rowdata8[byte_offset] >> bit_offset) & 7;
break;
}
- case 8:
- value = rowdata8[x];
- break;
+ case 8:
+ value = rowdata8[x];
+ break;
- case 16:
- value = rowdata16[x];
- break;
+ case 16:
+ value = rowdata16[x];
+ break;
- case 24:
- value = (rowdata8[x * 3] << 16) | (rowdata8[x * 3 + 1] << 8) | (rowdata8[x * 3 + 2] << 8);
- break;
+ case 24:
+ value = (rowdata8[x * 3] << 16) | (rowdata8[x * 3 + 1] << 8) | (rowdata8[x * 3 + 2] << 8);
+ break;
- case 32:
- value = rowdata32[x];
- break;
+ case 32:
+ value = rowdata32[x];
+ break;
}
displayio_bitmap_write_pixel(self, x, y_draw, value & mask);
}
diff --git a/shared-module/bitops/__init__.c b/shared-module/bitops/__init__.c
index cf0ac7bd1..168989218 100644
--- a/shared-module/bitops/__init__.c
+++ b/shared-module/bitops/__init__.c
@@ -49,49 +49,53 @@
static void transpose_var(uint32_t *result, const uint8_t *src, int src_stride, int num_strands) {
uint32_t x = 0, y = 0, t;
- src += (num_strands-1) * src_stride;
-
- switch(num_strands) {
- case 7:
- x |= *src << 16;
- src -= src_stride;
- FALLTHROUGH;
- case 6:
- x |= *src << 8;
- src -= src_stride;
- FALLTHROUGH;
- case 5:
- x |= *src;
- src -= src_stride;
- FALLTHROUGH;
- case 4:
- y |= *src << 24;
- src -= src_stride;
- FALLTHROUGH;
- case 3:
- y |= *src << 16;
- src -= src_stride;
- FALLTHROUGH;
- case 2:
- y |= *src << 8;
- src -= src_stride;
- y |= *src;
+ src += (num_strands - 1) * src_stride;
+
+ switch (num_strands) {
+ case 7:
+ x |= *src << 16;
+ src -= src_stride;
+ FALLTHROUGH;
+ case 6:
+ x |= *src << 8;
+ src -= src_stride;
+ FALLTHROUGH;
+ case 5:
+ x |= *src;
+ src -= src_stride;
+ FALLTHROUGH;
+ case 4:
+ y |= *src << 24;
+ src -= src_stride;
+ FALLTHROUGH;
+ case 3:
+ y |= *src << 16;
+ src -= src_stride;
+ FALLTHROUGH;
+ case 2:
+ y |= *src << 8;
+ src -= src_stride;
+ y |= *src;
}
- t = (x ^ (x >> 7)) & 0x00AA00AA; x = x ^ t ^ (t << 7);
- t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7);
+ t = (x ^ (x >> 7)) & 0x00AA00AA;
+ x = x ^ t ^ (t << 7);
+ t = (y ^ (y >> 7)) & 0x00AA00AA;
+ y = y ^ t ^ (t << 7);
- t = (x ^ (x >>14)) & 0x0000CCCC; x = x ^ t ^ (t <<14);
- t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14);
+ t = (x ^ (x >> 14)) & 0x0000CCCC;
+ x = x ^ t ^ (t << 14);
+ t = (y ^ (y >> 14)) & 0x0000CCCC;
+ y = y ^ t ^ (t << 14);
t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F);
y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F);
x = t;
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
x = __builtin_bswap32(x);
y = __builtin_bswap32(y);
-#endif
+ #endif
result[0] = x;
result[1] = y;
}
@@ -99,35 +103,47 @@ static void transpose_var(uint32_t *result, const uint8_t *src, int src_stride,
static void transpose_8(uint32_t *result, const uint8_t *src, int src_stride) {
uint32_t x, y, t;
- y = *src; src += src_stride;
- y |= (*src << 8); src += src_stride;
- y |= (*src << 16); src += src_stride;
- y |= (*src << 24); src += src_stride;
- x = *src; src += src_stride;
- x |= (*src << 8); src += src_stride;
- x |= (*src << 16); src += src_stride;
- x |= (*src << 24); src += src_stride;
-
- t = (x ^ (x >> 7)) & 0x00AA00AA; x = x ^ t ^ (t << 7);
- t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7);
-
- t = (x ^ (x >>14)) & 0x0000CCCC; x = x ^ t ^ (t <<14);
- t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14);
+ y = *src;
+ src += src_stride;
+ y |= (*src << 8);
+ src += src_stride;
+ y |= (*src << 16);
+ src += src_stride;
+ y |= (*src << 24);
+ src += src_stride;
+ x = *src;
+ src += src_stride;
+ x |= (*src << 8);
+ src += src_stride;
+ x |= (*src << 16);
+ src += src_stride;
+ x |= (*src << 24);
+ src += src_stride;
+
+ t = (x ^ (x >> 7)) & 0x00AA00AA;
+ x = x ^ t ^ (t << 7);
+ t = (y ^ (y >> 7)) & 0x00AA00AA;
+ y = y ^ t ^ (t << 7);
+
+ t = (x ^ (x >> 14)) & 0x0000CCCC;
+ x = x ^ t ^ (t << 14);
+ t = (y ^ (y >> 14)) & 0x0000CCCC;
+ y = y ^ t ^ (t << 14);
t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F);
y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F);
x = t;
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
x = __builtin_bswap32(x);
y = __builtin_bswap32(y);
-#endif
+ #endif
result[0] = x;
result[1] = y;
}
static void bit_transpose_8(uint32_t *result, const uint8_t *src, size_t src_stride, size_t n) {
- for(size_t i=0; i<n; i++) {
+ for (size_t i = 0; i < n; i++) {
transpose_8(result, src, src_stride);
result += 2;
src += 1;
@@ -135,7 +151,7 @@ static void bit_transpose_8(uint32_t *result, const uint8_t *src, size_t src_str
}
static void bit_transpose_var(uint32_t *result, const uint8_t *src, size_t src_stride, size_t n, int num_strands) {
- for(size_t i=0; i<n; i++) {
+ for (size_t i = 0; i < n; i++) {
transpose_var(result, src, src_stride, num_strands);
result += 2;
src += 1;
@@ -143,9 +159,9 @@ static void bit_transpose_var(uint32_t *result, const uint8_t *src, size_t src_s
}
void common_hal_bitops_bit_transpose(uint8_t *result, const uint8_t *src, size_t inlen, size_t num_strands) {
- if(num_strands == 8) {
- bit_transpose_8((uint32_t*)(void*)result, src, inlen/8, inlen/8);
- } else {
- bit_transpose_var((uint32_t*)(void*)result, src, inlen/num_strands, inlen/num_strands, num_strands);
+ if (num_strands == 8) {
+ bit_transpose_8((uint32_t *)(void *)result, src, inlen / 8, inlen / 8);
+ } else {
+ bit_transpose_var((uint32_t *)(void *)result, src, inlen / num_strands, inlen / num_strands, num_strands);
}
}
diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c
index 5d45d58b4..9dbca48fd 100644
--- a/shared-module/board/__init__.c
+++ b/shared-module/board/__init__.c
@@ -83,9 +83,9 @@ mp_obj_t common_hal_board_create_spi(void) {
busio_spi_obj_t *self = &spi_obj;
self->base.type = &busio_spi_type;
- const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK);
- const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI);
- const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO);
+ const mcu_pin_obj_t *clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK);
+ const mcu_pin_obj_t *mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI);
+ const mcu_pin_obj_t *miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO);
common_hal_busio_spi_construct(self, clock, mosi, miso);
spi_singleton = (mp_obj_t)self;
return spi_singleton;
@@ -101,39 +101,39 @@ mp_obj_t common_hal_board_create_uart(void) {
busio_uart_obj_t *self = m_new_ll_obj(busio_uart_obj_t);
self->base.type = &busio_uart_type;
- const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX);
- const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX);
-#ifdef DEFAULT_UART_BUS_RTS
- const mcu_pin_obj_t* rts = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RTS);
-#else
- const mcu_pin_obj_t* rts = NULL;
-#endif
-#ifdef DEFAULT_UART_BUS_CTS
- const mcu_pin_obj_t* cts = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_CTS);
-#else
- const mcu_pin_obj_t* cts = NULL;
-#endif
-#ifdef DEFAULT_UART_IS_RS485
- const mcu_pin_obj_t* rs485_dir = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RS485DIR);
-#ifdef DEFAULT_UART_RS485_INVERT
+ const mcu_pin_obj_t *rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX);
+ const mcu_pin_obj_t *tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX);
+ #ifdef DEFAULT_UART_BUS_RTS
+ const mcu_pin_obj_t *rts = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RTS);
+ #else
+ const mcu_pin_obj_t *rts = NULL;
+ #endif
+ #ifdef DEFAULT_UART_BUS_CTS
+ const mcu_pin_obj_t *cts = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_CTS);
+ #else
+ const mcu_pin_obj_t *cts = NULL;
+ #endif
+ #ifdef DEFAULT_UART_IS_RS485
+ const mcu_pin_obj_t *rs485_dir = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RS485DIR);
+ #ifdef DEFAULT_UART_RS485_INVERT
const bool rs485_invert = true;
-#else
+ #else
const bool rs485_invert = false;
-#endif
-#else
- const mcu_pin_obj_t* rs485_dir = NULL;
+ #endif
+ #else
+ const mcu_pin_obj_t *rs485_dir = NULL;
const bool rs485_invert = false;
-#endif
+ #endif
common_hal_busio_uart_construct(self, tx, rx, rts, cts, rs485_dir, rs485_invert,
- 9600, 8, BUSIO_UART_PARITY_NONE, 1, 1.0f, 64, NULL, false);
+ 9600, 8, BUSIO_UART_PARITY_NONE, 1, 1.0f, 64, NULL, false);
MP_STATE_VM(shared_uart_bus) = MP_OBJ_FROM_PTR(self);
return MP_STATE_VM(shared_uart_bus);
}
#endif
void reset_board_busses(void) {
-#if BOARD_I2C
+ #if BOARD_I2C
bool display_using_i2c = false;
#if CIRCUITPY_DISPLAYIO
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
@@ -149,8 +149,8 @@ void reset_board_busses(void) {
i2c_singleton = NULL;
}
}
-#endif
-#if BOARD_SPI
+ #endif
+ #if BOARD_SPI
bool display_using_spi = false;
#if CIRCUITPY_DISPLAYIO
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
@@ -175,8 +175,8 @@ void reset_board_busses(void) {
spi_singleton = NULL;
}
}
-#endif
-#if BOARD_UART
+ #endif
+ #if BOARD_UART
MP_STATE_VM(shared_uart_bus) = NULL;
-#endif
+ #endif
}
diff --git a/shared-module/busio/I2C.c b/shared-module/busio/I2C.c
index 06e1af10a..d3db18e3a 100644
--- a/shared-module/busio/I2C.c
+++ b/shared-module/busio/I2C.c
@@ -30,7 +30,7 @@
#include "py/nlr.h"
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
- const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t freq, uint32_t timeout) {
+ const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t freq, uint32_t timeout) {
shared_module_bitbangio_i2c_construct(&self->bitbang, scl, sda, freq, timeout);
}
@@ -59,12 +59,12 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
}
uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
- const uint8_t * data, size_t len, bool transmit_stop_bit) {
+ const uint8_t *data, size_t len, bool transmit_stop_bit) {
return shared_module_bitbangio_i2c_write(&self->bitbang, addr, data, len,
transmit_stop_bit);
}
uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
- uint8_t * data, size_t len) {
+ uint8_t *data, size_t len) {
return shared_module_bitbangio_i2c_read(&self->bitbang, addr, data, len);
}
diff --git a/shared-module/busio/OneWire.c b/shared-module/busio/OneWire.c
index 6bb7dedcd..80c55c7b2 100644
--- a/shared-module/busio/OneWire.c
+++ b/shared-module/busio/OneWire.c
@@ -29,31 +29,31 @@
#include "shared-bindings/bitbangio/OneWire.h"
#include "shared-module/busio/OneWire.h"
-void common_hal_busio_onewire_construct(busio_onewire_obj_t* self,
- const mcu_pin_obj_t* pin) {
+void common_hal_busio_onewire_construct(busio_onewire_obj_t *self,
+ const mcu_pin_obj_t *pin) {
shared_module_bitbangio_onewire_construct(&self->bitbang, pin);
}
-bool common_hal_busio_onewire_deinited(busio_onewire_obj_t* self) {
+bool common_hal_busio_onewire_deinited(busio_onewire_obj_t *self) {
return shared_module_bitbangio_onewire_deinited(&self->bitbang);
}
-void common_hal_busio_onewire_deinit(busio_onewire_obj_t* self) {
+void common_hal_busio_onewire_deinit(busio_onewire_obj_t *self) {
if (common_hal_busio_onewire_deinited(self)) {
return;
}
shared_module_bitbangio_onewire_deinit(&self->bitbang);
}
-bool common_hal_busio_onewire_reset(busio_onewire_obj_t* self) {
+bool common_hal_busio_onewire_reset(busio_onewire_obj_t *self) {
return shared_module_bitbangio_onewire_reset(&self->bitbang);
}
-bool common_hal_busio_onewire_read_bit(busio_onewire_obj_t* self) {
+bool common_hal_busio_onewire_read_bit(busio_onewire_obj_t *self) {
return shared_module_bitbangio_onewire_read_bit(&self->bitbang);
}
-void common_hal_busio_onewire_write_bit(busio_onewire_obj_t* self,
- bool bit) {
+void common_hal_busio_onewire_write_bit(busio_onewire_obj_t *self,
+ bool bit) {
shared_module_bitbangio_onewire_write_bit(&self->bitbang, bit);
}
diff --git a/shared-module/canio/Message.c b/shared-module/canio/Message.c
index a1df4f693..08e4d9fda 100644
--- a/shared-module/canio/Message.c
+++ b/shared-module/canio/Message.c
@@ -28,8 +28,7 @@
#include <string.h>
-void common_hal_canio_message_construct(canio_message_obj_t *self, int id, void *data, size_t size, bool extended)
-{
+void common_hal_canio_message_construct(canio_message_obj_t *self, int id, void *data, size_t size, bool extended) {
self->id = id;
self->size = size;
self->extended = extended;
@@ -38,40 +37,33 @@ void common_hal_canio_message_construct(canio_message_obj_t *self, int id, void
}
}
-int common_hal_canio_message_get_id(const canio_message_obj_t *self)
-{
+int common_hal_canio_message_get_id(const canio_message_obj_t *self) {
return self->id;
}
-void common_hal_canio_message_set_id(canio_message_obj_t *self, int id)
-{
+void common_hal_canio_message_set_id(canio_message_obj_t *self, int id) {
self->id = id;
}
-const void *common_hal_canio_message_get_data(const canio_message_obj_t *self)
-{
+const void *common_hal_canio_message_get_data(const canio_message_obj_t *self) {
return self->data;
}
-const void common_hal_canio_message_set_data(canio_message_obj_t *self, const void *data, size_t size)
-{
+const void common_hal_canio_message_set_data(canio_message_obj_t *self, const void *data, size_t size) {
self->size = size;
memcpy(self->data, data, size);
}
-size_t common_hal_canio_message_get_length(const canio_message_obj_t *self)
-{
+size_t common_hal_canio_message_get_length(const canio_message_obj_t *self) {
return self->size;
}
-bool common_hal_canio_message_get_extended(const canio_message_obj_t *self)
-{
+bool common_hal_canio_message_get_extended(const canio_message_obj_t *self) {
return self->extended;
}
-void common_hal_canio_message_set_extended(canio_message_obj_t *self, bool extended)
-{
+void common_hal_canio_message_set_extended(canio_message_obj_t *self, bool extended) {
self->extended = extended;
}
diff --git a/shared-module/canio/Message.h b/shared-module/canio/Message.h
index 1ca0d42e2..fafcaffe7 100644
--- a/shared-module/canio/Message.h
+++ b/shared-module/canio/Message.h
@@ -32,6 +32,6 @@ typedef struct {
mp_obj_base_t base;
int id;
uint8_t data[8];
- size_t size:4;
- bool extended:1;
+ size_t size : 4;
+ bool extended : 1;
} canio_message_obj_t;
diff --git a/shared-module/canio/RemoteTransmissionRequest.c b/shared-module/canio/RemoteTransmissionRequest.c
index 9b4d5632f..55c0d3ba2 100644
--- a/shared-module/canio/RemoteTransmissionRequest.c
+++ b/shared-module/canio/RemoteTransmissionRequest.c
@@ -29,39 +29,32 @@
#include <string.h>
-void common_hal_canio_remote_transmission_request_construct(canio_remote_transmission_request_obj_t *self, int id, size_t size, bool extended)
-{
+void common_hal_canio_remote_transmission_request_construct(canio_remote_transmission_request_obj_t *self, int id, size_t size, bool extended) {
self->id = id;
self->size = size;
self->extended = extended;
}
-int common_hal_canio_remote_transmission_request_get_id(const canio_remote_transmission_request_obj_t *self)
-{
+int common_hal_canio_remote_transmission_request_get_id(const canio_remote_transmission_request_obj_t *self) {
return self->id;
}
-void common_hal_canio_remote_transmission_request_set_id(canio_remote_transmission_request_obj_t *self, int id)
-{
+void common_hal_canio_remote_transmission_request_set_id(canio_remote_transmission_request_obj_t *self, int id) {
self->id = id;
}
-size_t common_hal_canio_remote_transmission_request_get_length(const canio_remote_transmission_request_obj_t *self)
-{
+size_t common_hal_canio_remote_transmission_request_get_length(const canio_remote_transmission_request_obj_t *self) {
return self->size;
}
-void common_hal_canio_remote_transmission_request_set_length(canio_remote_transmission_request_obj_t *self, size_t size)
-{
+void common_hal_canio_remote_transmission_request_set_length(canio_remote_transmission_request_obj_t *self, size_t size) {
self->size = size;
}
-bool common_hal_canio_remote_transmission_request_get_extended(const canio_remote_transmission_request_obj_t *self)
-{
+bool common_hal_canio_remote_transmission_request_get_extended(const canio_remote_transmission_request_obj_t *self) {
return self->extended;
}
-void common_hal_canio_remote_transmission_request_set_extended(canio_remote_transmission_request_obj_t *self, bool extended)
-{
+void common_hal_canio_remote_transmission_request_set_extended(canio_remote_transmission_request_obj_t *self, bool extended) {
self->extended = extended;
}
diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c
index 1831ac697..f03ade84b 100644
--- a/shared-module/displayio/Bitmap.c
+++ b/shared-module/displayio/Bitmap.c
@@ -57,7 +57,7 @@ void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t wi
self->x_shift = 0; // Used to divide the index by the number of pixels per word. Its used in a
// shift which effectively divides by 2 ** x_shift.
uint32_t power_of_two = 1;
- while (power_of_two < align_bits / bits_per_value ) {
+ while (power_of_two < align_bits / bits_per_value) {
self->x_shift++;
power_of_two <<= 1;
}
@@ -93,13 +93,13 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t
return (word >> (sizeof(size_t) * 8 - ((x & self->x_mask) + 1) * self->bits_per_value)) & self->bitmask;
} else {
- size_t* row = self->data + row_start;
+ size_t *row = self->data + row_start;
if (bytes_per_value == 1) {
- return ((uint8_t*) row)[x];
+ return ((uint8_t *)row)[x];
} else if (bytes_per_value == 2) {
- return ((uint16_t*) row)[x];
+ return ((uint16_t *)row)[x];
} else if (bytes_per_value == 4) {
- return ((uint32_t*) row)[x];
+ return ((uint32_t *)row)[x];
}
}
return 0;
@@ -157,19 +157,19 @@ void displayio_bitmap_write_pixel(displayio_bitmap_t *self, int16_t x, int16_t y
word |= (value & self->bitmask) << bit_position;
self->data[index] = word;
} else {
- size_t* row = self->data + row_start;
+ size_t *row = self->data + row_start;
if (bytes_per_value == 1) {
- ((uint8_t*) row)[x] = value;
+ ((uint8_t *)row)[x] = value;
} else if (bytes_per_value == 2) {
- ((uint16_t*) row)[x] = value;
+ ((uint16_t *)row)[x] = value;
} else if (bytes_per_value == 4) {
- ((uint32_t*) row)[x] = value;
+ ((uint32_t *)row)[x] = value;
}
}
}
void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source,
- int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none) {
+ int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none) {
// Copy region of "source" bitmap into "self" bitmap at location x,y in the "self"
// If skip_value is encountered in the source bitmap, it will not be copied.
// If skip_value is `None`, then all pixels are copied.
@@ -180,11 +180,11 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16
}
// Update the dirty area
- int16_t dirty_x_max = (x + (x2-x1));
+ int16_t dirty_x_max = (x + (x2 - x1));
if (dirty_x_max > self->width) {
dirty_x_max = self->width;
}
- int16_t dirty_y_max = y + (y2-y1);
+ int16_t dirty_y_max = y + (y2 - y1);
if (dirty_y_max > self->height) {
dirty_y_max = self->height;
}
@@ -203,21 +203,21 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16
}
// simplest version - use internal functions for get/set pixels
- for (int16_t i=0; i < (x2-x1); i++) {
+ for (int16_t i = 0; i < (x2 - x1); i++) {
- const int xs_index = x_reverse ? ( (x2) - i - 1) : x1+i; // x-index into the source bitmap
- const int xd_index = x_reverse ? ((x + (x2-x1)) - i - 1) : x+i; // x-index into the destination bitmap
+ const int xs_index = x_reverse ? ((x2) - i - 1) : x1 + i; // x-index into the source bitmap
+ const int xd_index = x_reverse ? ((x + (x2 - x1)) - i - 1) : x + i; // x-index into the destination bitmap
- if ( (xd_index >= 0) && (xd_index < self->width) ) {
- for (int16_t j=0; j < (y2-y1) ; j++){
+ if ((xd_index >= 0) && (xd_index < self->width)) {
+ for (int16_t j = 0; j < (y2 - y1); j++) {
- const int ys_index = y_reverse ? ( (y2 ) - j - 1) : y1+j ; // y-index into the source bitmap
- const int yd_index = y_reverse ? ((y + (y2-y1)) - j - 1) : y+j ; // y-index into the destination bitmap
+ const int ys_index = y_reverse ? ((y2) - j - 1) : y1 + j; // y-index into the source bitmap
+ const int yd_index = y_reverse ? ((y + (y2 - y1)) - j - 1) : y + j; // y-index into the destination bitmap
- if ((yd_index >= 0) && (yd_index < self->height) ) {
+ if ((yd_index >= 0) && (yd_index < self->height)) {
uint32_t value = common_hal_displayio_bitmap_get_pixel(source, xs_index, ys_index);
- if ( (skip_index_none) || (value != skip_index) ) { // write if skip_value_none is True
- displayio_bitmap_write_pixel(self, xd_index, yd_index, value);
+ if ((skip_index_none) || (value != skip_index)) { // write if skip_value_none is True
+ displayio_bitmap_write_pixel(self, xd_index, yd_index, value);
}
}
}
@@ -231,14 +231,14 @@ void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x,
}
// update the dirty region
- displayio_bitmap_set_dirty_area(self, x, y, x+1, y+1);
+ displayio_bitmap_set_dirty_area(self, x, y, x + 1, y + 1);
// write the pixel
displayio_bitmap_write_pixel(self, x, y, value);
}
-displayio_area_t* displayio_bitmap_get_refresh_areas(displayio_bitmap_t *self, displayio_area_t* tail) {
+displayio_area_t *displayio_bitmap_get_refresh_areas(displayio_bitmap_t *self, displayio_area_t *tail) {
if (self->dirty_area.x1 == self->dirty_area.x2) {
return tail;
}
@@ -263,11 +263,11 @@ void common_hal_displayio_bitmap_fill(displayio_bitmap_t *self, uint32_t value)
// build the packed word
uint32_t word = 0;
- for (uint8_t i=0; i<32 / self->bits_per_value; i++) {
- word |= (value & self->bitmask) << (32 - ((i+1)*self->bits_per_value));
+ for (uint8_t i = 0; i < 32 / self->bits_per_value; i++) {
+ word |= (value & self->bitmask) << (32 - ((i + 1) * self->bits_per_value));
}
// copy it in
- for (uint32_t i=0; i<self->stride * self->height; i++) {
+ for (uint32_t i = 0; i < self->stride * self->height; i++) {
self->data[i] = word;
}
}
diff --git a/shared-module/displayio/Bitmap.h b/shared-module/displayio/Bitmap.h
index d6aaaa8ba..c1ce9612b 100644
--- a/shared-module/displayio/Bitmap.h
+++ b/shared-module/displayio/Bitmap.h
@@ -37,7 +37,7 @@ typedef struct {
mp_obj_base_t base;
uint16_t width;
uint16_t height;
- size_t* data;
+ size_t *data;
uint16_t stride; // size_t's
uint8_t bits_per_value;
uint8_t x_shift;
@@ -48,7 +48,7 @@ typedef struct {
} displayio_bitmap_t;
void displayio_bitmap_finish_refresh(displayio_bitmap_t *self);
-displayio_area_t* displayio_bitmap_get_refresh_areas(displayio_bitmap_t *self, displayio_area_t* tail);
+displayio_area_t *displayio_bitmap_get_refresh_areas(displayio_bitmap_t *self, displayio_area_t *tail);
void displayio_bitmap_set_dirty_area(displayio_bitmap_t *self, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
void displayio_bitmap_write_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value);
diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c
index 40dcd9d16..be9e9dc1a 100644
--- a/shared-module/displayio/ColorConverter.c
+++ b/shared-module/displayio/ColorConverter.c
@@ -31,18 +31,17 @@
#define NO_TRANSPARENT_COLOR (0x1000000)
-uint32_t displayio_colorconverter_dither_noise_1 (uint32_t n)
-{
- n = (n >> 13) ^ n;
- int nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
- return (uint32_t) (((float)nn / (1073741824.0f*2)) * 255);
+uint32_t displayio_colorconverter_dither_noise_1(uint32_t n) {
+ n = (n >> 13) ^ n;
+ int nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
+ return (uint32_t)(((float)nn / (1073741824.0f * 2)) * 255);
}
uint32_t displayio_colorconverter_dither_noise_2(uint32_t x, uint32_t y) {
return displayio_colorconverter_dither_noise_1(x + y * 0xFFFF);
}
-void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither) {
+void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t *self, bool dither) {
self->dither = dither;
self->transparent_color = NO_TRANSPARENT_COLOR;
}
@@ -83,11 +82,11 @@ uint8_t displayio_colorconverter_compute_hue(uint32_t color_rgb888) {
int32_t hue = 0;
if (max == r8) {
- hue = (((int32_t) (g8 - b8) * 40) / c) % 240;
+ hue = (((int32_t)(g8 - b8) * 40) / c) % 240;
} else if (max == g8) {
- hue = (((int32_t) (b8 - r8) + (2 * c)) * 40) / c;
+ hue = (((int32_t)(b8 - r8) + (2 * c)) * 40) / c;
} else if (max == b8) {
- hue = (((int32_t) (r8 - g8) + (4 * c)) * 40) / c;
+ hue = (((int32_t)(r8 - g8) + (4 * c)) * 40) / c;
}
if (hue < 0) {
hue += 240;
@@ -96,7 +95,7 @@ uint8_t displayio_colorconverter_compute_hue(uint32_t color_rgb888) {
return hue;
}
-void displayio_colorconverter_compute_tricolor(const _displayio_colorspace_t* colorspace, uint8_t pixel_hue, uint8_t pixel_luma, uint32_t* color) {
+void displayio_colorconverter_compute_tricolor(const _displayio_colorspace_t *colorspace, uint8_t pixel_hue, uint8_t pixel_luma, uint32_t *color) {
int16_t hue_diff = colorspace->tricolor_hue - pixel_hue;
if ((-10 <= hue_diff && hue_diff <= 10) || hue_diff <= -220 || hue_diff >= 220) {
@@ -110,7 +109,7 @@ void displayio_colorconverter_compute_tricolor(const _displayio_colorspace_t* co
}
}
-void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color) {
+void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t *colorspace, uint32_t input_color, uint32_t *output_color) {
displayio_input_pixel_t input_pixel;
input_pixel.pixel = input_color;
input_pixel.x = input_pixel.y = input_pixel.tile = input_pixel.tile_x = input_pixel.tile_y = 0;
@@ -124,28 +123,28 @@ void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *sel
(*output_color) = output_pixel.pixel;
}
-void common_hal_displayio_colorconverter_set_dither(displayio_colorconverter_t* self, bool dither) {
+void common_hal_displayio_colorconverter_set_dither(displayio_colorconverter_t *self, bool dither) {
self->dither = dither;
}
-bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t* self) {
+bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t *self) {
return self->dither;
}
-void common_hal_displayio_colorconverter_make_transparent(displayio_colorconverter_t* self, uint32_t transparent_color) {
+void common_hal_displayio_colorconverter_make_transparent(displayio_colorconverter_t *self, uint32_t transparent_color) {
if (self->transparent_color != NO_TRANSPARENT_COLOR) {
mp_raise_RuntimeError(translate("Only one color can be transparent at a time"));
}
self->transparent_color = transparent_color;
}
-void common_hal_displayio_colorconverter_make_opaque(displayio_colorconverter_t* self, uint32_t transparent_color) {
- (void) transparent_color;
+void common_hal_displayio_colorconverter_make_opaque(displayio_colorconverter_t *self, uint32_t transparent_color) {
+ (void)transparent_color;
// NO_TRANSPARENT_COLOR will never equal a valid color
self->transparent_color = NO_TRANSPARENT_COLOR;
}
-void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color) {
+void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t *colorspace, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color) {
uint32_t pixel = input_pixel->pixel;
if (self->transparent_color == pixel) {
@@ -153,19 +152,19 @@ void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d
return;
}
- if (self->dither){
+ if (self->dither) {
uint8_t randr = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x,input_pixel->tile_y));
- uint8_t randg = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x+33,input_pixel->tile_y));
- uint8_t randb = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x,input_pixel->tile_y+33));
+ uint8_t randg = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x + 33,input_pixel->tile_y));
+ uint8_t randb = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x,input_pixel->tile_y + 33));
uint32_t r8 = (pixel >> 16);
uint32_t g8 = (pixel >> 8) & 0xff;
uint32_t b8 = pixel & 0xff;
if (colorspace->depth == 16) {
- b8 = MIN(255,b8 + (randb&0x07));
- r8 = MIN(255,r8 + (randr&0x07));
- g8 = MIN(255,g8 + (randg&0x03));
+ b8 = MIN(255,b8 + (randb & 0x07));
+ r8 = MIN(255,r8 + (randr & 0x07));
+ g8 = MIN(255,g8 + (randg & 0x03));
} else {
int bitmask = 0xFF >> colorspace->depth;
b8 = MIN(255,b8 + (randb & bitmask));
@@ -197,7 +196,7 @@ void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d
uint8_t pixel_hue = displayio_colorconverter_compute_hue(pixel);
displayio_colorconverter_compute_tricolor(colorspace, pixel_hue, luma, &output_color->pixel);
return;
- } else if (colorspace->grayscale && colorspace->depth <= 8) {
+ } else if (colorspace->grayscale && colorspace->depth <= 8) {
uint8_t luma = displayio_colorconverter_compute_luma(pixel);
size_t bitmask = (1 << colorspace->depth) - 1;
output_color->pixel = (luma >> colorspace->grayscale_bit) & bitmask;
diff --git a/shared-module/displayio/ColorConverter.h b/shared-module/displayio/ColorConverter.h
index b402625ef..ebe4b2719 100644
--- a/shared-module/displayio/ColorConverter.h
+++ b/shared-module/displayio/ColorConverter.h
@@ -41,15 +41,15 @@ typedef struct {
bool displayio_colorconverter_needs_refresh(displayio_colorconverter_t *self);
void displayio_colorconverter_finish_refresh(displayio_colorconverter_t *self);
-void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color);
+void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t *colorspace, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color);
-uint32_t displayio_colorconverter_dither_noise_1 (uint32_t n);
+uint32_t displayio_colorconverter_dither_noise_1(uint32_t n);
uint32_t displayio_colorconverter_dither_noise_2(uint32_t x, uint32_t y);
uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888);
uint8_t displayio_colorconverter_compute_luma(uint32_t color_rgb888);
uint8_t displayio_colorconverter_compute_chroma(uint32_t color_rgb888);
uint8_t displayio_colorconverter_compute_hue(uint32_t color_rgb888);
-void displayio_colorconverter_compute_tricolor(const _displayio_colorspace_t* colorspace, uint8_t pixel_hue, uint8_t pixel_luma, uint32_t* color);
+void displayio_colorconverter_compute_tricolor(const _displayio_colorspace_t *colorspace, uint8_t pixel_hue, uint8_t pixel_luma, uint32_t *color);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_COLORCONVERTER_H
diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c
index 7c8c9280b..63e098e08 100644
--- a/shared-module/displayio/Display.c
+++ b/shared-module/displayio/Display.c
@@ -41,15 +41,15 @@
#include <stdint.h>
#include <string.h>
-void common_hal_displayio_display_construct(displayio_display_obj_t* self,
- mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart,
- uint16_t rotation, uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row,
- uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word, uint8_t set_column_command,
- uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
- uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin,
- uint16_t brightness_command, mp_float_t brightness, bool auto_brightness,
- bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
- bool backlight_on_high, bool SH1107_addressing) {
+void common_hal_displayio_display_construct(displayio_display_obj_t *self,
+ mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart,
+ uint16_t rotation, uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row,
+ uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word, uint8_t set_column_command,
+ uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
+ uint8_t *init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t *backlight_pin,
+ uint16_t brightness_command, mp_float_t brightness, bool auto_brightness,
+ bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
+ bool backlight_on_high, bool SH1107_addressing) {
// Turn off auto-refresh as we init.
self->auto_refresh = false;
@@ -141,34 +141,34 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
common_hal_displayio_display_set_auto_refresh(self, auto_refresh);
}
-bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) {
+bool common_hal_displayio_display_show(displayio_display_obj_t *self, displayio_group_t *root_group) {
return displayio_display_core_show(&self->core, root_group);
}
-uint16_t common_hal_displayio_display_get_width(displayio_display_obj_t* self){
+uint16_t common_hal_displayio_display_get_width(displayio_display_obj_t *self) {
return displayio_display_core_get_width(&self->core);
}
-uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t* self){
+uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t *self) {
return displayio_display_core_get_height(&self->core);
}
-bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t* self) {
+bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t *self) {
return self->auto_brightness;
}
-void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* self, bool auto_brightness) {
+void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t *self, bool auto_brightness) {
self->auto_brightness = auto_brightness;
}
-mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t* self) {
+mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t *self) {
return self->current_brightness;
}
-bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, mp_float_t brightness) {
+bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self, mp_float_t brightness) {
self->updating_backlight = true;
- if (!self->backlight_on_high){
- brightness = 1.0-brightness;
+ if (!self->backlight_on_high) {
+ brightness = 1.0 - brightness;
}
bool ok = false;
@@ -181,7 +181,7 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self,
if (ispwm) {
#if (CIRCUITPY_PULSEIO)
- common_hal_pwmio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t) (0xffff * brightness));
+ common_hal_pwmio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t)(0xffff * brightness));
ok = true;
#else
ok = false;
@@ -193,7 +193,7 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self,
ok = displayio_display_core_begin_transaction(&self->core);
if (ok) {
if (self->data_as_commands) {
- uint8_t set_brightness[2] = {self->brightness_command, (uint8_t) (0xff * brightness)};
+ uint8_t set_brightness[2] = {self->brightness_command, (uint8_t)(0xff * brightness)};
self->core.send(self->core.bus, DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, set_brightness, 2);
} else {
uint8_t command = self->brightness_command;
@@ -212,11 +212,11 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self,
return ok;
}
-mp_obj_t common_hal_displayio_display_get_bus(displayio_display_obj_t* self) {
+mp_obj_t common_hal_displayio_display_get_bus(displayio_display_obj_t *self) {
return self->core.bus;
}
-STATIC const displayio_area_t* _get_refresh_areas(displayio_display_obj_t *self) {
+STATIC const displayio_area_t *_get_refresh_areas(displayio_display_obj_t *self) {
if (self->core.full_refresh) {
self->core.area.next = NULL;
return &self->core.area;
@@ -226,14 +226,14 @@ STATIC const displayio_area_t* _get_refresh_areas(displayio_display_obj_t *self)
return NULL;
}
-STATIC void _send_pixels(displayio_display_obj_t* self, uint8_t* pixels, uint32_t length) {
+STATIC void _send_pixels(displayio_display_obj_t *self, uint8_t *pixels, uint32_t length) {
if (!self->data_as_commands) {
self->core.send(self->core.bus, DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, &self->write_ram_command, 1);
}
self->core.send(self->core.bus, DISPLAY_DATA, CHIP_SELECT_UNTOUCHED, pixels, length);
}
-STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t* area) {
+STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t *area) {
uint16_t buffer_size = 128; // In uint32_ts
displayio_area_t clipped;
@@ -294,8 +294,8 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
remaining_rows -= rows_per_buffer;
displayio_display_core_set_region_to_update(&self->core, self->set_column_command,
- self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false,
- &subrectangle, self->SH1107_addressing);
+ self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false,
+ &subrectangle, self->SH1107_addressing);
uint16_t subrectangle_size_bytes;
if (self->core.colorspace.depth >= 8) {
@@ -315,7 +315,7 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
}
displayio_display_core_begin_transaction(&self->core);
- _send_pixels(self, (uint8_t*) buffer, subrectangle_size_bytes);
+ _send_pixels(self, (uint8_t *)buffer, subrectangle_size_bytes);
displayio_display_core_end_transaction(&self->core);
// TODO(tannewt): Make refresh displays faster so we don't starve other
@@ -325,12 +325,12 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
return true;
}
-STATIC void _refresh_display(displayio_display_obj_t* self) {
+STATIC void _refresh_display(displayio_display_obj_t *self) {
if (!displayio_display_core_start_refresh(&self->core)) {
// A refresh on this bus is already in progress. Try next display.
return;
}
- const displayio_area_t* current_area = _get_refresh_areas(self);
+ const displayio_area_t *current_area = _get_refresh_areas(self);
while (current_area != NULL) {
_refresh_area(self, current_area);
current_area = current_area->next;
@@ -338,10 +338,10 @@ STATIC void _refresh_display(displayio_display_obj_t* self) {
displayio_display_core_finish_refresh(&self->core);
}
-void common_hal_displayio_display_set_rotation(displayio_display_obj_t* self, int rotation){
+void common_hal_displayio_display_set_rotation(displayio_display_obj_t *self, int rotation) {
bool transposed = (self->core.rotation == 90 || self->core.rotation == 270);
bool will_transposed = (rotation == 90 || rotation == 270);
- if(transposed != will_transposed) {
+ if (transposed != will_transposed) {
int tmp = self->core.width;
self->core.width = self->core.height;
self->core.height = tmp;
@@ -356,13 +356,13 @@ void common_hal_displayio_display_set_rotation(displayio_display_obj_t* self, in
}
}
-uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t* self){
+uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t *self) {
return self->core.rotation;
}
-bool common_hal_displayio_display_refresh(displayio_display_obj_t* self, uint32_t target_ms_per_frame, uint32_t maximum_ms_per_real_frame) {
- if (!self->auto_refresh && !self->first_manual_refresh && (target_ms_per_frame != 0xffffffff) ) {
+bool common_hal_displayio_display_refresh(displayio_display_obj_t *self, uint32_t target_ms_per_frame, uint32_t maximum_ms_per_real_frame) {
+ if (!self->auto_refresh && !self->first_manual_refresh && (target_ms_per_frame != 0xffffffff)) {
uint64_t current_time = supervisor_ticks_ms64();
uint32_t current_ms_since_real_refresh = current_time - self->core.last_refresh;
// Test to see if the real frame time is below our minimum.
@@ -386,12 +386,12 @@ bool common_hal_displayio_display_refresh(displayio_display_obj_t* self, uint32_
return true;
}
-bool common_hal_displayio_display_get_auto_refresh(displayio_display_obj_t* self) {
+bool common_hal_displayio_display_get_auto_refresh(displayio_display_obj_t *self) {
return self->auto_refresh;
}
-void common_hal_displayio_display_set_auto_refresh(displayio_display_obj_t* self,
- bool auto_refresh) {
+void common_hal_displayio_display_set_auto_refresh(displayio_display_obj_t *self,
+ bool auto_refresh) {
self->first_manual_refresh = !auto_refresh;
if (auto_refresh != self->auto_refresh) {
if (auto_refresh) {
@@ -403,7 +403,7 @@ void common_hal_displayio_display_set_auto_refresh(displayio_display_obj_t* self
self->auto_refresh = auto_refresh;
}
-STATIC void _update_backlight(displayio_display_obj_t* self) {
+STATIC void _update_backlight(displayio_display_obj_t *self) {
if (!self->auto_brightness || self->updating_backlight) {
return;
}
@@ -417,7 +417,7 @@ STATIC void _update_backlight(displayio_display_obj_t* self) {
self->last_backlight_refresh = supervisor_ticks_ms64();
}
-void displayio_display_background(displayio_display_obj_t* self) {
+void displayio_display_background(displayio_display_obj_t *self) {
_update_backlight(self);
if (self->auto_refresh && (supervisor_ticks_ms64() - self->core.last_refresh) > self->native_ms_per_frame) {
@@ -425,7 +425,7 @@ void displayio_display_background(displayio_display_obj_t* self) {
}
}
-void release_display(displayio_display_obj_t* self) {
+void release_display(displayio_display_obj_t *self) {
common_hal_displayio_display_set_auto_refresh(self, false);
release_display_core(&self->core);
#if (CIRCUITPY_PULSEIO)
@@ -440,12 +440,12 @@ void release_display(displayio_display_obj_t* self) {
#endif
}
-void reset_display(displayio_display_obj_t* self) {
+void reset_display(displayio_display_obj_t *self) {
common_hal_displayio_display_set_auto_refresh(self, true);
self->auto_brightness = true;
common_hal_displayio_display_show(self, NULL);
}
-void displayio_display_collect_ptrs(displayio_display_obj_t* self) {
+void displayio_display_collect_ptrs(displayio_display_obj_t *self) {
displayio_display_core_collect_ptrs(&self->core);
}
diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h
index cc9cd54c4..a0049f00c 100644
--- a/shared-module/displayio/Display.h
+++ b/shared-module/displayio/Display.h
@@ -64,10 +64,10 @@ typedef struct {
bool SH1107_addressing;
} displayio_display_obj_t;
-void displayio_display_background(displayio_display_obj_t* self);
-void release_display(displayio_display_obj_t* self);
-void reset_display(displayio_display_obj_t* self);
+void displayio_display_background(displayio_display_obj_t *self);
+void release_display(displayio_display_obj_t *self);
+void reset_display(displayio_display_obj_t *self);
-void displayio_display_collect_ptrs(displayio_display_obj_t* self);
+void displayio_display_collect_ptrs(displayio_display_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_DISPLAY_H
diff --git a/shared-module/displayio/EPaperDisplay.c b/shared-module/displayio/EPaperDisplay.c
index 3fb37ff21..7eff58775 100644
--- a/shared-module/displayio/EPaperDisplay.c
+++ b/shared-module/displayio/EPaperDisplay.c
@@ -42,15 +42,15 @@
#include <stdint.h>
#include <string.h>
-void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t* self,
- mp_obj_t bus, const uint8_t* start_sequence, uint16_t start_sequence_len,
- const uint8_t* stop_sequence, uint16_t stop_sequence_len,
- uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height,
- int16_t colstart, int16_t rowstart, uint16_t rotation,
- uint16_t set_column_window_command, uint16_t set_row_window_command,
- uint16_t set_current_column_command, uint16_t set_current_row_command,
- uint16_t write_black_ram_command, bool black_bits_inverted, uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, uint16_t refresh_display_command, mp_float_t refresh_time,
- const mcu_pin_obj_t* busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool chip_select, bool grayscale) {
+void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t *self,
+ mp_obj_t bus, const uint8_t *start_sequence, uint16_t start_sequence_len,
+ const uint8_t *stop_sequence, uint16_t stop_sequence_len,
+ uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height,
+ int16_t colstart, int16_t rowstart, uint16_t rotation,
+ uint16_t set_column_window_command, uint16_t set_row_window_command,
+ uint16_t set_current_column_command, uint16_t set_current_row_command,
+ uint16_t write_black_ram_command, bool black_bits_inverted, uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, uint16_t refresh_display_command, mp_float_t refresh_time,
+ const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool chip_select, bool grayscale) {
if (highlight_color != 0x000000) {
self->core.colorspace.tricolor = true;
self->core.colorspace.tricolor_hue = displayio_colorconverter_compute_hue(highlight_color);
@@ -97,16 +97,16 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t*
common_hal_displayio_epaperdisplay_show(self, &circuitpython_splash);
}
-bool common_hal_displayio_epaperdisplay_show(displayio_epaperdisplay_obj_t* self, displayio_group_t* root_group) {
+bool common_hal_displayio_epaperdisplay_show(displayio_epaperdisplay_obj_t *self, displayio_group_t *root_group) {
return displayio_display_core_show(&self->core, root_group);
}
-const displayio_area_t* displayio_epaperdisplay_get_refresh_areas(displayio_epaperdisplay_obj_t *self) {
+const displayio_area_t *displayio_epaperdisplay_get_refresh_areas(displayio_epaperdisplay_obj_t *self) {
if (self->core.full_refresh) {
self->core.area.next = NULL;
return &self->core.area;
}
- const displayio_area_t* first_area = NULL;
+ const displayio_area_t *first_area = NULL;
if (self->core.current_group != NULL) {
first_area = displayio_group_get_refresh_areas(self->core.current_group, NULL);
}
@@ -117,15 +117,15 @@ const displayio_area_t* displayio_epaperdisplay_get_refresh_areas(displayio_epap
return first_area;
}
-uint16_t common_hal_displayio_epaperdisplay_get_width(displayio_epaperdisplay_obj_t* self){
+uint16_t common_hal_displayio_epaperdisplay_get_width(displayio_epaperdisplay_obj_t *self) {
return displayio_display_core_get_width(&self->core);
}
-uint16_t common_hal_displayio_epaperdisplay_get_height(displayio_epaperdisplay_obj_t* self){
+uint16_t common_hal_displayio_epaperdisplay_get_height(displayio_epaperdisplay_obj_t *self) {
return displayio_display_core_get_height(&self->core);
}
-STATIC void wait_for_busy(displayio_epaperdisplay_obj_t* self) {
+STATIC void wait_for_busy(displayio_epaperdisplay_obj_t *self) {
if (self->busy.base.type == &mp_type_NoneType) {
return;
}
@@ -134,8 +134,8 @@ STATIC void wait_for_busy(displayio_epaperdisplay_obj_t* self) {
}
}
-STATIC void send_command_sequence(displayio_epaperdisplay_obj_t* self,
- bool should_wait_for_busy, const uint8_t* sequence, uint32_t sequence_len) {
+STATIC void send_command_sequence(displayio_epaperdisplay_obj_t *self,
+ bool should_wait_for_busy, const uint8_t *sequence, uint32_t sequence_len) {
uint32_t i = 0;
while (i < sequence_len) {
const uint8_t *cmd = sequence + i;
@@ -163,7 +163,7 @@ STATIC void send_command_sequence(displayio_epaperdisplay_obj_t* self,
}
}
-void displayio_epaperdisplay_start_refresh(displayio_epaperdisplay_obj_t* self) {
+void displayio_epaperdisplay_start_refresh(displayio_epaperdisplay_obj_t *self) {
// run start sequence
self->core.bus_reset(self->core.bus);
@@ -171,7 +171,7 @@ void displayio_epaperdisplay_start_refresh(displayio_epaperdisplay_obj_t* self)
displayio_display_core_start_refresh(&self->core);
}
-uint32_t common_hal_displayio_epaperdisplay_get_time_to_refresh(displayio_epaperdisplay_obj_t* self) {
+uint32_t common_hal_displayio_epaperdisplay_get_time_to_refresh(displayio_epaperdisplay_obj_t *self) {
if (self->core.last_refresh == 0) {
return 0;
}
@@ -183,7 +183,7 @@ uint32_t common_hal_displayio_epaperdisplay_get_time_to_refresh(displayio_epaper
return self->milliseconds_per_frame - elapsed_time;
}
-void displayio_epaperdisplay_finish_refresh(displayio_epaperdisplay_obj_t* self) {
+void displayio_epaperdisplay_finish_refresh(displayio_epaperdisplay_obj_t *self) {
// Actually refresh the display now that all pixel RAM has been updated.
displayio_display_core_begin_transaction(&self->core);
self->core.send(self->core.bus, DISPLAY_COMMAND, self->chip_select, &self->refresh_display_command, 1);
@@ -194,14 +194,14 @@ void displayio_epaperdisplay_finish_refresh(displayio_epaperdisplay_obj_t* self)
displayio_display_core_finish_refresh(&self->core);
}
-mp_obj_t common_hal_displayio_epaperdisplay_get_bus(displayio_epaperdisplay_obj_t* self) {
+mp_obj_t common_hal_displayio_epaperdisplay_get_bus(displayio_epaperdisplay_obj_t *self) {
return self->core.bus;
}
-void common_hal_displayio_epaperdisplay_set_rotation(displayio_epaperdisplay_obj_t* self, int rotation){
+void common_hal_displayio_epaperdisplay_set_rotation(displayio_epaperdisplay_obj_t *self, int rotation) {
bool transposed = (self->core.rotation == 90 || self->core.rotation == 270);
bool will_transposed = (rotation == 90 || rotation == 270);
- if(transposed != will_transposed) {
+ if (transposed != will_transposed) {
int tmp = self->core.width;
self->core.width = self->core.height;
self->core.height = tmp;
@@ -216,12 +216,12 @@ void common_hal_displayio_epaperdisplay_set_rotation(displayio_epaperdisplay_obj
}
}
-uint16_t common_hal_displayio_epaperdisplay_get_rotation(displayio_epaperdisplay_obj_t* self){
+uint16_t common_hal_displayio_epaperdisplay_get_rotation(displayio_epaperdisplay_obj_t *self) {
return self->core.rotation;
}
-bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, const displayio_area_t* area) {
+bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t *self, const displayio_area_t *area) {
uint16_t buffer_size = 128; // In uint32_ts
displayio_area_t clipped;
@@ -264,8 +264,8 @@ bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, c
if (self->set_row_window_command != NO_COMMAND) {
displayio_display_core_set_region_to_update(&self->core, self->set_column_window_command,
- self->set_row_window_command, self->set_current_column_command, self->set_current_row_command,
- false, self->chip_select, &clipped, false /* SH1107_addressing */);
+ self->set_row_window_command, self->set_current_column_command, self->set_current_row_command,
+ false, self->chip_select, &clipped, false /* SH1107_addressing */);
}
uint8_t write_command = self->write_black_ram_command;
@@ -317,7 +317,7 @@ bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, c
// Can't acquire display bus; skip the rest of the data. Try next display.
return false;
}
- self->core.send(self->core.bus, DISPLAY_DATA, self->chip_select, (uint8_t*) buffer, subrectangle_size_bytes);
+ self->core.send(self->core.bus, DISPLAY_DATA, self->chip_select, (uint8_t *)buffer, subrectangle_size_bytes);
displayio_display_core_end_transaction(&self->core);
// TODO(tannewt): Make refresh displays faster so we don't starve other
@@ -329,7 +329,7 @@ bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, c
return true;
}
-bool common_hal_displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t* self) {
+bool common_hal_displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t *self) {
if (self->refreshing && self->busy.base.type == &digitalio_digitalinout_type) {
if (common_hal_digitalio_digitalinout_get_value(&self->busy) != self->busy_state) {
@@ -352,7 +352,7 @@ bool common_hal_displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t* s
// Can't acquire display bus; skip updating this display. Try next display.
return false;
}
- const displayio_area_t* current_area = displayio_epaperdisplay_get_refresh_areas(self);
+ const displayio_area_t *current_area = displayio_epaperdisplay_get_refresh_areas(self);
if (current_area == NULL) {
return true;
}
@@ -365,7 +365,7 @@ bool common_hal_displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t* s
return true;
}
-void displayio_epaperdisplay_background(displayio_epaperdisplay_obj_t* self) {
+void displayio_epaperdisplay_background(displayio_epaperdisplay_obj_t *self) {
if (self->refreshing) {
bool refresh_done = false;
if (self->busy.base.type == &digitalio_digitalinout_type) {
@@ -383,12 +383,12 @@ void displayio_epaperdisplay_background(displayio_epaperdisplay_obj_t* self) {
}
}
-bool common_hal_displayio_epaperdisplay_get_busy(displayio_epaperdisplay_obj_t* self) {
+bool common_hal_displayio_epaperdisplay_get_busy(displayio_epaperdisplay_obj_t *self) {
displayio_epaperdisplay_background(self);
return self->refreshing;
}
-void release_epaperdisplay(displayio_epaperdisplay_obj_t* self) {
+void release_epaperdisplay(displayio_epaperdisplay_obj_t *self) {
if (self->refreshing) {
wait_for_busy(self);
supervisor_disable_tick();
@@ -403,10 +403,10 @@ void release_epaperdisplay(displayio_epaperdisplay_obj_t* self) {
}
}
-void displayio_epaperdisplay_collect_ptrs(displayio_epaperdisplay_obj_t* self) {
+void displayio_epaperdisplay_collect_ptrs(displayio_epaperdisplay_obj_t *self) {
displayio_display_core_collect_ptrs(&self->core);
- gc_collect_ptr((void *) self->start_sequence);
- gc_collect_ptr((void *) self->stop_sequence);
+ gc_collect_ptr((void *)self->start_sequence);
+ gc_collect_ptr((void *)self->stop_sequence);
}
bool maybe_refresh_epaperdisplay(void) {
@@ -416,7 +416,7 @@ bool maybe_refresh_epaperdisplay(void) {
// Skip regular displays and those not showing the splash.
continue;
}
- displayio_epaperdisplay_obj_t* display = &displays[i].epaper_display;
+ displayio_epaperdisplay_obj_t *display = &displays[i].epaper_display;
if (common_hal_displayio_epaperdisplay_get_time_to_refresh(display) != 0) {
return false;
}
diff --git a/shared-module/displayio/EPaperDisplay.h b/shared-module/displayio/EPaperDisplay.h
index d0668ff44..988cc57fa 100644
--- a/shared-module/displayio/EPaperDisplay.h
+++ b/shared-module/displayio/EPaperDisplay.h
@@ -38,9 +38,9 @@ typedef struct {
displayio_display_core_t core;
digitalio_digitalinout_obj_t busy;
uint32_t milliseconds_per_frame;
- const uint8_t* start_sequence;
+ const uint8_t *start_sequence;
uint32_t start_sequence_len;
- const uint8_t* stop_sequence;
+ const uint8_t *stop_sequence;
uint32_t stop_sequence_len;
uint16_t refresh_time;
uint16_t set_column_window_command;
@@ -59,10 +59,10 @@ typedef struct {
display_chip_select_behavior_t chip_select;
} displayio_epaperdisplay_obj_t;
-void displayio_epaperdisplay_background(displayio_epaperdisplay_obj_t* self);
-void release_epaperdisplay(displayio_epaperdisplay_obj_t* self);
+void displayio_epaperdisplay_background(displayio_epaperdisplay_obj_t *self);
+void release_epaperdisplay(displayio_epaperdisplay_obj_t *self);
bool maybe_refresh_epaperdisplay(void);
-void displayio_epaperdisplay_collect_ptrs(displayio_epaperdisplay_obj_t* self);
+void displayio_epaperdisplay_collect_ptrs(displayio_epaperdisplay_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_EPAPERDISPLAY_H
diff --git a/shared-module/displayio/FourWire.c b/shared-module/displayio/FourWire.c
index e993f2480..59e2021bd 100644
--- a/shared-module/displayio/FourWire.c
+++ b/shared-module/displayio/FourWire.c
@@ -36,9 +36,9 @@
#include "shared-bindings/time/__init__.h"
#include "shared-module/displayio/display_core.h"
-void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
- busio_spi_obj_t* spi, const mcu_pin_obj_t* command,
- const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint32_t baudrate,
+void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t *self,
+ busio_spi_obj_t *spi, const mcu_pin_obj_t *command,
+ const mcu_pin_obj_t *chip_select, const mcu_pin_obj_t *reset, uint32_t baudrate,
uint8_t polarity, uint8_t phase) {
self->bus = spi;
@@ -69,7 +69,7 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
common_hal_never_reset_pin(chip_select);
}
-void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self) {
+void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t *self) {
if (self->bus == &self->inline_bus) {
common_hal_busio_spi_deinit(self->bus);
}
@@ -80,7 +80,7 @@ void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self) {
}
bool common_hal_displayio_fourwire_reset(mp_obj_t obj) {
- displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj);
+ displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(obj);
if (self->reset.base.type == &mp_type_NoneType) {
return false;
}
@@ -92,7 +92,7 @@ bool common_hal_displayio_fourwire_reset(mp_obj_t obj) {
}
bool common_hal_displayio_fourwire_bus_free(mp_obj_t obj) {
- displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj);
+ displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(obj);
if (!common_hal_busio_spi_try_lock(self->bus)) {
return false;
}
@@ -101,19 +101,19 @@ bool common_hal_displayio_fourwire_bus_free(mp_obj_t obj) {
}
bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t obj) {
- displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj);
+ displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(obj);
if (!common_hal_busio_spi_try_lock(self->bus)) {
return false;
}
common_hal_busio_spi_configure(self->bus, self->frequency, self->polarity,
- self->phase, 8);
+ self->phase, 8);
common_hal_digitalio_digitalinout_set_value(&self->chip_select, false);
return true;
}
void common_hal_displayio_fourwire_send(mp_obj_t obj, display_byte_type_t data_type,
- display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
- displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj);
+ display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
+ displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(obj);
common_hal_digitalio_digitalinout_set_value(&self->command, data_type == DISPLAY_DATA);
if (chip_select == CHIP_SELECT_TOGGLE_EVERY_BYTE) {
// Toggle chip select after each command byte in case the display driver
@@ -130,7 +130,7 @@ void common_hal_displayio_fourwire_send(mp_obj_t obj, display_byte_type_t data_t
}
void common_hal_displayio_fourwire_end_transaction(mp_obj_t obj) {
- displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj);
+ displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(obj);
common_hal_digitalio_digitalinout_set_value(&self->chip_select, true);
common_hal_busio_spi_unlock(self->bus);
}
diff --git a/shared-module/displayio/FourWire.h b/shared-module/displayio/FourWire.h
index a4260a3ac..b28c1ef84 100644
--- a/shared-module/displayio/FourWire.h
+++ b/shared-module/displayio/FourWire.h
@@ -33,7 +33,7 @@
typedef struct {
mp_obj_base_t base;
- busio_spi_obj_t* bus;
+ busio_spi_obj_t *bus;
busio_spi_obj_t inline_bus;
digitalio_digitalinout_obj_t command;
digitalio_digitalinout_obj_t chip_select;
diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c
index a36acc1c3..c50f034bf 100644
--- a/shared-module/displayio/Group.c
+++ b/shared-module/displayio/Group.c
@@ -35,16 +35,16 @@
#endif
-void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t scale, mp_int_t x, mp_int_t y) {
+void common_hal_displayio_group_construct(displayio_group_t *self, uint32_t scale, mp_int_t x, mp_int_t y) {
mp_obj_list_t *members = mp_obj_new_list(0, NULL);
displayio_group_construct(self, members, scale, x, y);
}
-bool common_hal_displayio_group_get_hidden(displayio_group_t* self) {
+bool common_hal_displayio_group_get_hidden(displayio_group_t *self) {
return self->hidden;
}
-void common_hal_displayio_group_set_hidden(displayio_group_t* self, bool hidden) {
+void common_hal_displayio_group_set_hidden(displayio_group_t *self, bool hidden) {
if (self->hidden == hidden) {
return;
}
@@ -95,11 +95,11 @@ void displayio_group_set_hidden_by_parent(displayio_group_t *self, bool hidden)
}
}
-uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self) {
+uint32_t common_hal_displayio_group_get_scale(displayio_group_t *self) {
return self->scale;
}
-bool displayio_group_get_previous_area(displayio_group_t *self, displayio_area_t* area) {
+bool displayio_group_get_previous_area(displayio_group_t *self, displayio_area_t *area) {
bool first = true;
for (size_t i = 0; i < self->members->len; i++) {
mp_obj_t layer;
@@ -137,20 +137,20 @@ bool displayio_group_get_previous_area(displayio_group_t *self, displayio_area_t
return !first;
}
-static void _update_child_transforms(displayio_group_t* self) {
+static void _update_child_transforms(displayio_group_t *self) {
if (!self->in_group) {
return;
}
for (size_t i = 0; i < self->members->len; i++) {
mp_obj_t layer;
-#if CIRCUITPY_VECTORIO
+ #if CIRCUITPY_VECTORIO
layer = mp_instance_cast_to_native_base(
self->members->items[i], &vectorio_vector_shape_type);
if (layer != MP_OBJ_NULL) {
vectorio_vector_shape_update_transform(layer, &self->absolute_transform);
continue;
}
-#endif
+ #endif
layer = mp_instance_cast_to_native_base(
self->members->items[i], &displayio_tilegrid_type);
if (layer != MP_OBJ_NULL) {
@@ -167,7 +167,7 @@ static void _update_child_transforms(displayio_group_t* self) {
}
void displayio_group_update_transform(displayio_group_t *self,
- const displayio_buffer_transform_t* parent_transform) {
+ const displayio_buffer_transform_t *parent_transform) {
self->in_group = parent_transform != NULL;
if (self->in_group) {
int16_t x = self->x;
@@ -189,7 +189,7 @@ void displayio_group_update_transform(displayio_group_t *self,
_update_child_transforms(self);
}
-void common_hal_displayio_group_set_scale(displayio_group_t* self, uint32_t scale) {
+void common_hal_displayio_group_set_scale(displayio_group_t *self, uint32_t scale) {
if (self->scale == scale) {
return;
}
@@ -201,18 +201,18 @@ void common_hal_displayio_group_set_scale(displayio_group_t* self, uint32_t scal
_update_child_transforms(self);
}
-mp_int_t common_hal_displayio_group_get_x(displayio_group_t* self) {
+mp_int_t common_hal_displayio_group_get_x(displayio_group_t *self) {
return self->x;
}
-void common_hal_displayio_group_set_x(displayio_group_t* self, mp_int_t x) {
+void common_hal_displayio_group_set_x(displayio_group_t *self, mp_int_t x) {
if (self->x == x) {
return;
}
if (self->absolute_transform.transpose_xy) {
int16_t dy = self->absolute_transform.dy / self->scale;
self->absolute_transform.y += dy * (x - self->x);
- } else {
+ } else {
int16_t dx = self->absolute_transform.dx / self->scale;
self->absolute_transform.x += dx * (x - self->x);
}
@@ -221,18 +221,18 @@ void common_hal_displayio_group_set_x(displayio_group_t* self, mp_int_t x) {
_update_child_transforms(self);
}
-mp_int_t common_hal_displayio_group_get_y(displayio_group_t* self) {
+mp_int_t common_hal_displayio_group_get_y(displayio_group_t *self) {
return self->y;
}
-void common_hal_displayio_group_set_y(displayio_group_t* self, mp_int_t y) {
+void common_hal_displayio_group_set_y(displayio_group_t *self, mp_int_t y) {
if (self->y == y) {
return;
}
if (self->absolute_transform.transpose_xy) {
int8_t dx = self->absolute_transform.dx / self->scale;
self->absolute_transform.x += dx * (y - self->y);
- } else {
+ } else {
int8_t dy = self->absolute_transform.dy / self->scale;
self->absolute_transform.y += dy * (y - self->y);
}
@@ -240,18 +240,18 @@ void common_hal_displayio_group_set_y(displayio_group_t* self, mp_int_t y) {
_update_child_transforms(self);
}
-static void _add_layer(displayio_group_t* self, mp_obj_t layer) {
+static void _add_layer(displayio_group_t *self, mp_obj_t layer) {
mp_obj_t native_layer;
-#if CIRCUITPY_VECTORIO
+ #if CIRCUITPY_VECTORIO
native_layer = mp_instance_cast_to_native_base(layer, &vectorio_vector_shape_type);
if (native_layer != MP_OBJ_NULL) {
vectorio_vector_shape_update_transform(native_layer, &self->absolute_transform);
return;
}
-#endif
+ #endif
native_layer = mp_instance_cast_to_native_base(layer, &displayio_tilegrid_type);
if (native_layer != MP_OBJ_NULL) {
- displayio_tilegrid_t* tilegrid = native_layer;
+ displayio_tilegrid_t *tilegrid = native_layer;
if (tilegrid->in_group) {
mp_raise_ValueError(translate("Layer already in a group."));
} else {
@@ -262,7 +262,7 @@ static void _add_layer(displayio_group_t* self, mp_obj_t layer) {
}
native_layer = mp_instance_cast_to_native_base(layer, &displayio_group_type);
if (native_layer != MP_OBJ_NULL) {
- displayio_group_t* group = native_layer;
+ displayio_group_t *group = native_layer;
if (group->in_group) {
mp_raise_ValueError(translate("Layer already in a group."));
} else {
@@ -274,11 +274,11 @@ static void _add_layer(displayio_group_t* self, mp_obj_t layer) {
mp_raise_ValueError(translate("Layer must be a Group or TileGrid subclass."));
}
-static void _remove_layer(displayio_group_t* self, size_t index) {
+static void _remove_layer(displayio_group_t *self, size_t index) {
mp_obj_t layer;
displayio_area_t layer_area;
bool rendered_last_frame = false;
-#if CIRCUITPY_VECTORIO
+ #if CIRCUITPY_VECTORIO
layer = mp_instance_cast_to_native_base(
self->members->items[index], &vectorio_vector_shape_type);
if (layer != MP_OBJ_NULL) {
@@ -286,18 +286,18 @@ static void _remove_layer(displayio_group_t* self, size_t index) {
rendered_last_frame = has_dirty_area;
vectorio_vector_shape_update_transform(layer, NULL);
}
-#endif
+ #endif
layer = mp_instance_cast_to_native_base(
self->members->items[index], &displayio_tilegrid_type);
if (layer != MP_OBJ_NULL) {
- displayio_tilegrid_t* tilegrid = layer;
+ displayio_tilegrid_t *tilegrid = layer;
rendered_last_frame = displayio_tilegrid_get_previous_area(tilegrid, &layer_area);
displayio_tilegrid_update_transform(tilegrid, NULL);
}
layer = mp_instance_cast_to_native_base(
self->members->items[index], &displayio_group_type);
if (layer != MP_OBJ_NULL) {
- displayio_group_t* group = layer;
+ displayio_group_t *group = layer;
rendered_last_frame = displayio_group_get_previous_area(group, &layer_area);
displayio_group_update_transform(group, NULL);
}
@@ -312,38 +312,38 @@ static void _remove_layer(displayio_group_t* self, size_t index) {
self->item_removed = true;
}
-void common_hal_displayio_group_insert(displayio_group_t* self, size_t index, mp_obj_t layer) {
+void common_hal_displayio_group_insert(displayio_group_t *self, size_t index, mp_obj_t layer) {
_add_layer(self, layer);
mp_obj_list_insert(self->members, index, layer);
}
-mp_obj_t common_hal_displayio_group_pop(displayio_group_t* self, size_t index) {
+mp_obj_t common_hal_displayio_group_pop(displayio_group_t *self, size_t index) {
_remove_layer(self, index);
return mp_obj_list_pop(self->members, index);
}
-mp_int_t common_hal_displayio_group_index(displayio_group_t* self, mp_obj_t layer) {
+mp_int_t common_hal_displayio_group_index(displayio_group_t *self, mp_obj_t layer) {
mp_obj_t args[] = {self->members, layer};
mp_obj_t *index = mp_seq_index_obj(
self->members->items, self->members->len, 2, args);
return MP_OBJ_SMALL_INT_VALUE(index);
}
-size_t common_hal_displayio_group_get_len(displayio_group_t* self) {
+size_t common_hal_displayio_group_get_len(displayio_group_t *self) {
return self->members->len;
}
-mp_obj_t common_hal_displayio_group_get(displayio_group_t* self, size_t index) {
+mp_obj_t common_hal_displayio_group_get(displayio_group_t *self, size_t index) {
return self->members->items[index];
}
-void common_hal_displayio_group_set(displayio_group_t* self, size_t index, mp_obj_t layer) {
+void common_hal_displayio_group_set(displayio_group_t *self, size_t index, mp_obj_t layer) {
_add_layer(self, layer);
_remove_layer(self, index);
mp_obj_list_store(self->members, MP_OBJ_NEW_SMALL_INT(index), layer);
}
-void displayio_group_construct(displayio_group_t* self, mp_obj_list_t* members, uint32_t scale, mp_int_t x, mp_int_t y) {
+void displayio_group_construct(displayio_group_t *self, mp_obj_list_t *members, uint32_t scale, mp_int_t x, mp_int_t y) {
self->x = x;
self->y = y;
self->members = members;
@@ -352,12 +352,12 @@ void displayio_group_construct(displayio_group_t* self, mp_obj_list_t* members,
self->in_group = false;
}
-bool displayio_group_fill_area(displayio_group_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t* buffer) {
+bool displayio_group_fill_area(displayio_group_t *self, const _displayio_colorspace_t *colorspace, const displayio_area_t *area, uint32_t *mask, uint32_t *buffer) {
// Track if any of the layers finishes filling in the given area. We can ignore any remaining
// layers at that point.
- for (int32_t i = self->members->len - 1; i >= 0 ; i--) {
+ for (int32_t i = self->members->len - 1; i >= 0; i--) {
mp_obj_t layer;
-#if CIRCUITPY_VECTORIO
+ #if CIRCUITPY_VECTORIO
layer = mp_instance_cast_to_native_base(
self->members->items[i], &vectorio_vector_shape_type);
if (layer != MP_OBJ_NULL) {
@@ -366,7 +366,7 @@ bool displayio_group_fill_area(displayio_group_t *self, const _displayio_colorsp
}
continue;
}
-#endif
+ #endif
layer = mp_instance_cast_to_native_base(
self->members->items[i], &displayio_tilegrid_type);
if (layer != MP_OBJ_NULL) {
@@ -389,16 +389,16 @@ bool displayio_group_fill_area(displayio_group_t *self, const _displayio_colorsp
void displayio_group_finish_refresh(displayio_group_t *self) {
self->item_removed = false;
- for (int32_t i = self->members->len - 1; i >= 0 ; i--) {
+ for (int32_t i = self->members->len - 1; i >= 0; i--) {
mp_obj_t layer;
-#if CIRCUITPY_VECTORIO
+ #if CIRCUITPY_VECTORIO
layer = mp_instance_cast_to_native_base(
self->members->items[i], &vectorio_vector_shape_type);
if (layer != MP_OBJ_NULL) {
vectorio_vector_shape_finish_refresh(layer);
continue;
}
-#endif
+ #endif
layer = mp_instance_cast_to_native_base(
self->members->items[i], &displayio_tilegrid_type);
if (layer != MP_OBJ_NULL) {
@@ -414,22 +414,22 @@ void displayio_group_finish_refresh(displayio_group_t *self) {
}
}
-displayio_area_t* displayio_group_get_refresh_areas(displayio_group_t *self, displayio_area_t* tail) {
+displayio_area_t *displayio_group_get_refresh_areas(displayio_group_t *self, displayio_area_t *tail) {
if (self->item_removed) {
self->dirty_area.next = tail;
tail = &self->dirty_area;
}
- for (int32_t i = self->members->len - 1; i >= 0 ; i--) {
+ for (int32_t i = self->members->len - 1; i >= 0; i--) {
mp_obj_t layer;
-#if CIRCUITPY_VECTORIO
+ #if CIRCUITPY_VECTORIO
layer = mp_instance_cast_to_native_base(
self->members->items[i], &vectorio_vector_shape_type);
if (layer != MP_OBJ_NULL) {
tail = vectorio_vector_shape_get_refresh_areas(layer, tail);
continue;
}
-#endif
+ #endif
layer = mp_instance_cast_to_native_base(
self->members->items[i], &displayio_tilegrid_type);
if (layer != MP_OBJ_NULL) {
diff --git a/shared-module/displayio/Group.h b/shared-module/displayio/Group.h
index 0964e0a0b..f68422315 100644
--- a/shared-module/displayio/Group.h
+++ b/shared-module/displayio/Group.h
@@ -43,19 +43,19 @@ typedef struct {
int16_t x;
int16_t y;
uint16_t scale;
- bool item_removed :1;
- bool in_group :1;
- bool hidden :1;
- bool hidden_by_parent :1;
- uint8_t padding :4;
+ bool item_removed : 1;
+ bool in_group : 1;
+ bool hidden : 1;
+ bool hidden_by_parent : 1;
+ uint8_t padding : 4;
} displayio_group_t;
-void displayio_group_construct(displayio_group_t* self, mp_obj_list_t* members, uint32_t scale, mp_int_t x, mp_int_t y);
+void displayio_group_construct(displayio_group_t *self, mp_obj_list_t *members, uint32_t scale, mp_int_t x, mp_int_t y);
void displayio_group_set_hidden_by_parent(displayio_group_t *self, bool hidden);
-bool displayio_group_get_previous_area(displayio_group_t *group, displayio_area_t* area);
-bool displayio_group_fill_area(displayio_group_t *group, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer);
-void displayio_group_update_transform(displayio_group_t *group, const displayio_buffer_transform_t* parent_transform);
+bool displayio_group_get_previous_area(displayio_group_t *group, displayio_area_t *area);
+bool displayio_group_fill_area(displayio_group_t *group, const _displayio_colorspace_t *colorspace, const displayio_area_t *area, uint32_t *mask, uint32_t *buffer);
+void displayio_group_update_transform(displayio_group_t *group, const displayio_buffer_transform_t *parent_transform);
void displayio_group_finish_refresh(displayio_group_t *self);
-displayio_area_t* displayio_group_get_refresh_areas(displayio_group_t *self, displayio_area_t* tail);
+displayio_area_t *displayio_group_get_refresh_areas(displayio_group_t *self, displayio_area_t *tail);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_GROUP_H
diff --git a/shared-module/displayio/I2CDisplay.c b/shared-module/displayio/I2CDisplay.c
index cc811e83d..6446e3198 100644
--- a/shared-module/displayio/I2CDisplay.c
+++ b/shared-module/displayio/I2CDisplay.c
@@ -38,8 +38,8 @@
#include "shared-bindings/time/__init__.h"
#include "shared-module/displayio/display_core.h"
-void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self,
- busio_i2c_obj_t* i2c, uint16_t device_address, const mcu_pin_obj_t* reset) {
+void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t *self,
+ busio_i2c_obj_t *i2c, uint16_t device_address, const mcu_pin_obj_t *reset) {
// Reset the display before probing
self->reset.base.type = &mp_type_NoneType;
@@ -67,7 +67,7 @@ void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self,
self->address = device_address;
}
-void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) {
+void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t *self) {
if (self->bus == &self->inline_bus) {
common_hal_busio_i2c_deinit(self->bus);
}
@@ -78,7 +78,7 @@ void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) {
}
bool common_hal_displayio_i2cdisplay_reset(mp_obj_t obj) {
- displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj);
+ displayio_i2cdisplay_obj_t *self = MP_OBJ_TO_PTR(obj);
if (self->reset.base.type == &mp_type_NoneType) {
return false;
}
@@ -90,7 +90,7 @@ bool common_hal_displayio_i2cdisplay_reset(mp_obj_t obj) {
}
bool common_hal_displayio_i2cdisplay_bus_free(mp_obj_t obj) {
- displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj);
+ displayio_i2cdisplay_obj_t *self = MP_OBJ_TO_PTR(obj);
if (!common_hal_busio_i2c_try_lock(self->bus)) {
return false;
}
@@ -99,13 +99,13 @@ bool common_hal_displayio_i2cdisplay_bus_free(mp_obj_t obj) {
}
bool common_hal_displayio_i2cdisplay_begin_transaction(mp_obj_t obj) {
- displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj);
+ displayio_i2cdisplay_obj_t *self = MP_OBJ_TO_PTR(obj);
return common_hal_busio_i2c_try_lock(self->bus);
}
void common_hal_displayio_i2cdisplay_send(mp_obj_t obj, display_byte_type_t data_type,
- display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
- displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj);
+ display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
+ displayio_i2cdisplay_obj_t *self = MP_OBJ_TO_PTR(obj);
if (data_type == DISPLAY_COMMAND) {
uint8_t command_bytes[2 * data_length];
for (uint32_t i = 0; i < data_length; i++) {
@@ -122,6 +122,6 @@ void common_hal_displayio_i2cdisplay_send(mp_obj_t obj, display_byte_type_t data
}
void common_hal_displayio_i2cdisplay_end_transaction(mp_obj_t obj) {
- displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj);
+ displayio_i2cdisplay_obj_t *self = MP_OBJ_TO_PTR(obj);
common_hal_busio_i2c_unlock(self->bus);
}
diff --git a/shared-module/displayio/I2CDisplay.h b/shared-module/displayio/I2CDisplay.h
index 4636c3f73..cc5bcf1eb 100644
--- a/shared-module/displayio/I2CDisplay.h
+++ b/shared-module/displayio/I2CDisplay.h
@@ -32,7 +32,7 @@
typedef struct {
mp_obj_base_t base;
- busio_i2c_obj_t* bus;
+ busio_i2c_obj_t *bus;
busio_i2c_obj_t inline_bus;
digitalio_digitalinout_obj_t reset;
uint16_t address;
diff --git a/shared-module/displayio/OnDiskBitmap.c b/shared-module/displayio/OnDiskBitmap.c
index c1a0ddeb7..5c7e00a58 100644
--- a/shared-module/displayio/OnDiskBitmap.c
+++ b/shared-module/displayio/OnDiskBitmap.c
@@ -31,11 +31,11 @@
#include "py/mperrno.h"
#include "py/runtime.h"
-static uint32_t read_word(uint16_t* bmp_header, uint16_t index) {
+static uint32_t read_word(uint16_t *bmp_header, uint16_t index) {
return bmp_header[index] | bmp_header[index + 1] << 16;
}
-void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, pyb_file_obj_t* file) {
+void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, pyb_file_obj_t *file) {
// Load the wave
self->file = file;
uint16_t bmp_header[69];
@@ -58,12 +58,12 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self,
uint32_t number_of_colors = read_word(bmp_header, 23);
bool indexed = bits_per_pixel <= 8;
- self->bitfield_compressed = (compression == 3);
+ self->bitfield_compressed = (compression == 3);
self->bits_per_pixel = bits_per_pixel;
self->width = read_word(bmp_header, 9);
self->height = read_word(bmp_header, 11);
- if (bits_per_pixel == 16){
+ if (bits_per_pixel == 16) {
if (((header_size >= 56)) || (self->bitfield_compressed)) {
self->r_bitmask = read_word(bmp_header, 27);
self->g_bitmask = read_word(bmp_header, 29);
@@ -101,9 +101,9 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self,
mp_raise_ValueError_varg(translate("Only monochrome, indexed 4bpp or 8bpp, and 16bpp or greater BMPs supported: %d bpp given"), bits_per_pixel);
}
- uint8_t bytes_per_pixel = (self->bits_per_pixel / 8) ? (self->bits_per_pixel /8) : 1;
+ uint8_t bytes_per_pixel = (self->bits_per_pixel / 8) ? (self->bits_per_pixel / 8) : 1;
uint8_t pixels_per_byte = 8 / self->bits_per_pixel;
- if (pixels_per_byte == 0){
+ if (pixels_per_byte == 0) {
self->stride = (self->width * bytes_per_pixel);
// Rows are word aligned.
if (self->stride % 4 != 0) {
@@ -121,15 +121,15 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self,
uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *self,
- int16_t x, int16_t y) {
+ int16_t x, int16_t y) {
if (x < 0 || x >= self->width || y < 0 || y >= self->height) {
return 0;
}
uint32_t location;
- uint8_t bytes_per_pixel = (self->bits_per_pixel / 8) ? (self->bits_per_pixel /8) : 1;
+ uint8_t bytes_per_pixel = (self->bits_per_pixel / 8) ? (self->bits_per_pixel / 8) : 1;
uint8_t pixels_per_byte = 8 / self->bits_per_pixel;
- if (pixels_per_byte == 0){
+ if (pixels_per_byte == 0) {
location = self->data_offset + (self->height - y - 1) * self->stride + x * bytes_per_pixel;
} else {
location = self->data_offset + (self->height - y - 1) * self->stride + x / pixels_per_byte;
@@ -159,12 +159,12 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s
return self->palette_data[index];
} else if (bytes_per_pixel == 2) {
if (self->g_bitmask == 0x07e0) { // 565
- red =((pixel_data & self->r_bitmask) >>11);
- green = ((pixel_data & self->g_bitmask) >>5);
+ red = ((pixel_data & self->r_bitmask) >> 11);
+ green = ((pixel_data & self->g_bitmask) >> 5);
blue = ((pixel_data & self->b_bitmask) >> 0);
} else { // 555
- red =((pixel_data & self->r_bitmask) >>10);
- green = ((pixel_data & self->g_bitmask) >>4);
+ red = ((pixel_data & self->r_bitmask) >> 10);
+ green = ((pixel_data & self->g_bitmask) >> 4);
blue = ((pixel_data & self->b_bitmask) >> 0);
}
tmp = (red << 19 | green << 10 | blue << 3);
diff --git a/shared-module/displayio/OnDiskBitmap.h b/shared-module/displayio/OnDiskBitmap.h
index 28426f11b..610b11491 100644
--- a/shared-module/displayio/OnDiskBitmap.h
+++ b/shared-module/displayio/OnDiskBitmap.h
@@ -44,9 +44,9 @@ typedef struct {
uint32_t g_bitmask;
uint32_t b_bitmask;
bool bitfield_compressed;
- pyb_file_obj_t* file;
+ pyb_file_obj_t *file;
uint8_t bits_per_pixel;
- uint32_t* palette_data;
+ uint32_t *palette_data;
} displayio_ondiskbitmap_t;
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_ONDISKBITMAP_H
diff --git a/shared-module/displayio/Palette.c b/shared-module/displayio/Palette.c
index ba5ff665c..6dde3a80f 100644
--- a/shared-module/displayio/Palette.c
+++ b/shared-module/displayio/Palette.c
@@ -28,26 +28,26 @@
#include "shared-module/displayio/ColorConverter.h"
-void common_hal_displayio_palette_construct(displayio_palette_t* self, uint16_t color_count) {
+void common_hal_displayio_palette_construct(displayio_palette_t *self, uint16_t color_count) {
self->color_count = color_count;
- self->colors = (_displayio_color_t *) m_malloc(color_count * sizeof(_displayio_color_t), false);
+ self->colors = (_displayio_color_t *)m_malloc(color_count * sizeof(_displayio_color_t), false);
}
-void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t palette_index) {
+void common_hal_displayio_palette_make_opaque(displayio_palette_t *self, uint32_t palette_index) {
self->colors[palette_index].transparent = false;
self->needs_refresh = true;
}
-void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t palette_index) {
+void common_hal_displayio_palette_make_transparent(displayio_palette_t *self, uint32_t palette_index) {
self->colors[palette_index].transparent = true;
self->needs_refresh = true;
}
-uint32_t common_hal_displayio_palette_get_len(displayio_palette_t* self) {
+uint32_t common_hal_displayio_palette_get_len(displayio_palette_t *self) {
return self->color_count;
}
-void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t palette_index, uint32_t color) {
+void common_hal_displayio_palette_set_color(displayio_palette_t *self, uint32_t palette_index, uint32_t color) {
if (self->colors[palette_index].rgb888 == color) {
return;
}
@@ -61,11 +61,11 @@ void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t
self->needs_refresh = true;
}
-uint32_t common_hal_displayio_palette_get_color(displayio_palette_t* self, uint32_t palette_index) {
+uint32_t common_hal_displayio_palette_get_color(displayio_palette_t *self, uint32_t palette_index) {
return self->colors[palette_index].rgb888;
}
-bool displayio_palette_get_color(displayio_palette_t *self, const _displayio_colorspace_t* colorspace, uint32_t palette_index, uint32_t* color) {
+bool displayio_palette_get_color(displayio_palette_t *self, const _displayio_colorspace_t *colorspace, uint32_t palette_index, uint32_t *color) {
if (palette_index > self->color_count || self->colors[palette_index].transparent) {
return false; // returns opaque
}
@@ -74,7 +74,7 @@ bool displayio_palette_get_color(displayio_palette_t *self, const _displayio_col
uint8_t luma = self->colors[palette_index].luma;
*color = luma >> (8 - colorspace->depth);
// Chroma 0 means the color is a gray and has no hue so never color based on it.
- if (self->colors[palette_index].chroma <= 16) {
+ if (self->colors[palette_index].chroma <= 16) {
if (!colorspace->grayscale) {
*color = 0;
}
diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h
index 993912cc5..82504b7ed 100644
--- a/shared-module/displayio/Palette.h
+++ b/shared-module/displayio/Palette.h
@@ -71,14 +71,14 @@ typedef struct {
typedef struct {
mp_obj_base_t base;
- _displayio_color_t* colors;
+ _displayio_color_t *colors;
uint32_t color_count;
bool needs_refresh;
} displayio_palette_t;
// Returns false if color fetch did not succeed (out of range or transparent).
// Returns true if color is opaque, and sets color.
-bool displayio_palette_get_color(displayio_palette_t *palette, const _displayio_colorspace_t* colorspace, uint32_t palette_index, uint32_t* color);
+bool displayio_palette_get_color(displayio_palette_t *palette, const _displayio_colorspace_t *colorspace, uint32_t palette_index, uint32_t *color);
bool displayio_palette_needs_refresh(displayio_palette_t *self);
void displayio_palette_finish_refresh(displayio_palette_t *self);
diff --git a/shared-module/displayio/Shape.c b/shared-module/displayio/Shape.c
index b94a392bc..4a32c7a60 100644
--- a/shared-module/displayio/Shape.c
+++ b/shared-module/displayio/Shape.c
@@ -56,10 +56,10 @@ void common_hal_displayio_shape_construct(displayio_shape_t *self, uint32_t widt
self->data[2 * i + 1] = width;
}
- self->dirty_area.x1=0;
- self->dirty_area.x2=width;
- self->dirty_area.y1=0;
- self->dirty_area.y2=height;
+ self->dirty_area.x1 = 0;
+ self->dirty_area.x2 = width;
+ self->dirty_area.y1 = 0;
+ self->dirty_area.y2 = height;
}
void common_hal_displayio_shape_set_boundary(displayio_shape_t *self, uint16_t y, uint16_t start_x, uint16_t end_x) {
@@ -130,7 +130,7 @@ uint32_t common_hal_displayio_shape_get_pixel(void *obj, int16_t x, int16_t y) {
return 1;
}
-displayio_area_t* displayio_shape_get_refresh_areas(displayio_shape_t *self, displayio_area_t* tail) {
+displayio_area_t *displayio_shape_get_refresh_areas(displayio_shape_t *self, displayio_area_t *tail) {
if (self->dirty_area.x1 == self->dirty_area.x2) {
return tail;
}
diff --git a/shared-module/displayio/Shape.h b/shared-module/displayio/Shape.h
index e59ad586e..2cac5d73b 100644
--- a/shared-module/displayio/Shape.h
+++ b/shared-module/displayio/Shape.h
@@ -39,13 +39,13 @@ typedef struct {
uint16_t height;
uint16_t half_width;
uint16_t half_height;
- uint16_t* data;
+ uint16_t *data;
bool mirror_x;
bool mirror_y;
displayio_area_t dirty_area;
} displayio_shape_t;
void displayio_shape_finish_refresh(displayio_shape_t *self);
-displayio_area_t* displayio_shape_get_refresh_areas(displayio_shape_t *self, displayio_area_t* tail);
+displayio_area_t *displayio_shape_get_refresh_areas(displayio_shape_t *self, displayio_area_t *tail);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SHAPE_H
diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c
index 96473d4a8..347eba577 100644
--- a/shared-module/displayio/TileGrid.c
+++ b/shared-module/displayio/TileGrid.c
@@ -34,21 +34,21 @@
#include "shared-bindings/displayio/Shape.h"
void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_t bitmap,
- uint16_t bitmap_width_in_tiles, uint16_t bitmap_height_in_tiles,
- mp_obj_t pixel_shader, uint16_t width, uint16_t height,
- uint16_t tile_width, uint16_t tile_height, uint16_t x, uint16_t y, uint8_t default_tile) {
+ uint16_t bitmap_width_in_tiles, uint16_t bitmap_height_in_tiles,
+ mp_obj_t pixel_shader, uint16_t width, uint16_t height,
+ uint16_t tile_width, uint16_t tile_height, uint16_t x, uint16_t y, uint8_t default_tile) {
uint32_t total_tiles = width * height;
// Sprites will only have one tile so save a little memory by inlining values in the pointer.
- uint8_t inline_tiles = sizeof(uint8_t*);
+ uint8_t inline_tiles = sizeof(uint8_t *);
if (total_tiles <= inline_tiles) {
self->tiles = 0;
// Pack values into the pointer since there are only a few.
for (uint32_t i = 0; i < inline_tiles; i++) {
- ((uint8_t*) &self->tiles)[i] = default_tile;
+ ((uint8_t *)&self->tiles)[i] = default_tile;
}
self->inline_tiles = true;
} else {
- self->tiles = (uint8_t*) m_malloc(total_tiles, false);
+ self->tiles = (uint8_t *)m_malloc(total_tiles, false);
for (uint32_t i = 0; i < total_tiles; i++) {
self->tiles[i] = default_tile;
}
@@ -78,25 +78,25 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_
}
-bool common_hal_displayio_tilegrid_get_hidden(displayio_tilegrid_t* self) {
+bool common_hal_displayio_tilegrid_get_hidden(displayio_tilegrid_t *self) {
return self->hidden;
}
-void common_hal_displayio_tilegrid_set_hidden(displayio_tilegrid_t* self, bool hidden) {
+void common_hal_displayio_tilegrid_set_hidden(displayio_tilegrid_t *self, bool hidden) {
self->hidden = hidden;
- if(!hidden){
+ if (!hidden) {
self->full_change = true;
}
}
void displayio_tilegrid_set_hidden_by_parent(displayio_tilegrid_t *self, bool hidden) {
self->hidden_by_parent = hidden;
- if(!hidden){
+ if (!hidden) {
self->full_change = true;
}
}
-bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_area_t* area) {
+bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_area_t *area) {
if (self->previous_area.x1 == self->previous_area.x2) {
return false;
}
@@ -113,8 +113,8 @@ void _update_current_x(displayio_tilegrid_t *self) {
}
// If there's no transform, substitute an identity transform so the calculations will work.
- const displayio_buffer_transform_t* absolute_transform =
- self->absolute_transform == NULL
+ const displayio_buffer_transform_t *absolute_transform =
+ self->absolute_transform == NULL
? &null_transform
: self->absolute_transform;
@@ -146,8 +146,8 @@ void _update_current_y(displayio_tilegrid_t *self) {
}
// If there's no transform, substitute an identity transform so the calculations will work.
- const displayio_buffer_transform_t* absolute_transform =
- self->absolute_transform == NULL
+ const displayio_buffer_transform_t *absolute_transform =
+ self->absolute_transform == NULL
? &null_transform
: self->absolute_transform;
@@ -171,7 +171,7 @@ void _update_current_y(displayio_tilegrid_t *self) {
}
void displayio_tilegrid_update_transform(displayio_tilegrid_t *self,
- const displayio_buffer_transform_t* absolute_transform) {
+ const displayio_buffer_transform_t *absolute_transform) {
self->in_group = absolute_transform != NULL;
self->absolute_transform = absolute_transform;
if (absolute_transform != NULL) {
@@ -230,9 +230,9 @@ uint16_t common_hal_displayio_tilegrid_get_height(displayio_tilegrid_t *self) {
}
uint8_t common_hal_displayio_tilegrid_get_tile(displayio_tilegrid_t *self, uint16_t x, uint16_t y) {
- uint8_t* tiles = self->tiles;
+ uint8_t *tiles = self->tiles;
if (self->inline_tiles) {
- tiles = (uint8_t*) &self->tiles;
+ tiles = (uint8_t *)&self->tiles;
}
if (tiles == NULL) {
return 0;
@@ -244,16 +244,16 @@ void common_hal_displayio_tilegrid_set_tile(displayio_tilegrid_t *self, uint16_t
if (tile_index >= self->tiles_in_bitmap) {
mp_raise_ValueError(translate("Tile index out of bounds"));
}
- uint8_t* tiles = self->tiles;
+ uint8_t *tiles = self->tiles;
if (self->inline_tiles) {
- tiles = (uint8_t*) &self->tiles;
+ tiles = (uint8_t *)&self->tiles;
}
if (tiles == NULL) {
return;
}
tiles[y * self->width_in_tiles + x] = tile_index;
displayio_area_t temp_area;
- displayio_area_t* tile_area;
+ displayio_area_t *tile_area;
if (!self->partial_change) {
tile_area = &self->dirty_area;
} else {
@@ -331,11 +331,11 @@ void common_hal_displayio_tilegrid_set_top_left(displayio_tilegrid_t *self, uint
self->full_change = true;
}
-bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer) {
+bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_colorspace_t *colorspace, const displayio_area_t *area, uint32_t *mask, uint32_t *buffer) {
// If no tiles are present we have no impact.
- uint8_t* tiles = self->tiles;
+ uint8_t *tiles = self->tiles;
if (self->inline_tiles) {
- tiles = (uint8_t*) &self->tiles;
+ tiles = (uint8_t *)&self->tiles;
}
if (tiles == NULL) {
return false;
@@ -384,9 +384,9 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c
// can either return full coverage or bulk update the mask.
displayio_area_t transformed;
displayio_area_transform_within(flip_x != (self->absolute_transform->dx < 0), flip_y != (self->absolute_transform->dy < 0), self->transpose_xy != self->absolute_transform->transpose_xy,
- &overlap,
- &self->current_area,
- &transformed);
+ &overlap,
+ &self->current_area,
+ &transformed);
int16_t start_x = (transformed.x1 - self->current_area.x1);
int16_t end_x = (transformed.x2 - self->current_area.x1);
@@ -443,7 +443,7 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c
input_pixel.tile_x = (input_pixel.tile % self->bitmap_width_in_tiles) * self->tile_width + local_x % self->tile_width;
input_pixel.tile_y = (input_pixel.tile / self->bitmap_width_in_tiles) * self->tile_height + local_y % self->tile_height;
- //uint32_t value = 0;
+ // uint32_t value = 0;
output_pixel.pixel = 0;
input_pixel.pixel = 0;
@@ -471,9 +471,9 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c
} else {
mask[offset / 32] |= 1 << (offset % 32);
if (colorspace->depth == 16) {
- *(((uint16_t*) buffer) + offset) = output_pixel.pixel;
+ *(((uint16_t *)buffer) + offset) = output_pixel.pixel;
} else if (colorspace->depth == 8) {
- *(((uint8_t*) buffer) + offset) = output_pixel.pixel;
+ *(((uint8_t *)buffer) + offset) = output_pixel.pixel;
} else if (colorspace->depth < 8) {
// Reorder the offsets to pack multiple rows into a byte (meaning they share a column).
if (!colorspace->pixels_in_byte_share_row) {
@@ -492,7 +492,7 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c
// Reverse the shift by subtracting it from the leftmost shift.
shift = (pixels_per_byte - 1) * colorspace->depth - shift;
}
- ((uint8_t*)buffer)[offset / pixels_per_byte] |= output_pixel.pixel << shift;
+ ((uint8_t *)buffer)[offset / pixels_per_byte] |= output_pixel.pixel << shift;
}
}
}
@@ -529,7 +529,7 @@ void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self) {
// That way they won't change during a refresh and tear.
}
-displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *self, displayio_area_t* tail) {
+displayio_area_t *displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *self, displayio_area_t *tail) {
bool first_draw = self->previous_area.x1 == self->previous_area.x2;
bool hidden = self->hidden || self->hidden_by_parent;
// Check hidden first because it trumps all other changes.
@@ -553,7 +553,7 @@ displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *sel
// If we have an in-memory bitmap, then check it for modifications.
if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_bitmap_type)) {
- displayio_area_t* refresh_area = displayio_bitmap_get_refresh_areas(self->bitmap, tail);
+ displayio_area_t *refresh_area = displayio_bitmap_get_refresh_areas(self->bitmap, tail);
if (refresh_area != tail) {
// Special case a TileGrid that shows a full bitmap and use its
// dirty area. Copy it to ours so we can transform it.
@@ -565,7 +565,7 @@ displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *sel
}
}
} else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_shape_type)) {
- displayio_area_t* refresh_area = displayio_shape_get_refresh_areas(self->bitmap, tail);
+ displayio_area_t *refresh_area = displayio_shape_get_refresh_areas(self->bitmap, tail);
if (refresh_area != tail) {
displayio_area_copy(refresh_area, &self->dirty_area);
self->partial_change = true;
@@ -574,9 +574,9 @@ displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *sel
self->full_change = self->full_change ||
(MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type) &&
- displayio_palette_needs_refresh(self->pixel_shader)) ||
+ displayio_palette_needs_refresh(self->pixel_shader)) ||
(MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type) &&
- displayio_colorconverter_needs_refresh(self->pixel_shader));
+ displayio_colorconverter_needs_refresh(self->pixel_shader));
if (self->full_change || first_draw) {
self->current_area.next = tail;
return &self->current_area;
diff --git a/shared-module/displayio/TileGrid.h b/shared-module/displayio/TileGrid.h
index e97d3dfd4..b5aab5134 100644
--- a/shared-module/displayio/TileGrid.h
+++ b/shared-module/displayio/TileGrid.h
@@ -42,7 +42,8 @@ typedef struct {
int16_t y;
uint16_t pixel_width;
uint16_t pixel_height;
- uint16_t bitmap_width_in_tiles;;
+ uint16_t bitmap_width_in_tiles;
+ ;
uint16_t tiles_in_bitmap;
uint16_t width_in_tiles;
uint16_t height_in_tiles;
@@ -50,22 +51,22 @@ typedef struct {
uint16_t tile_height;
uint16_t top_left_x;
uint16_t top_left_y;
- uint8_t* tiles;
- const displayio_buffer_transform_t* absolute_transform;
+ uint8_t *tiles;
+ const displayio_buffer_transform_t *absolute_transform;
displayio_area_t dirty_area; // Stored as a relative area until the refresh area is fetched.
displayio_area_t previous_area; // Stored as an absolute area.
displayio_area_t current_area; // Stored as an absolute area so it applies across frames.
- bool partial_change :1;
- bool full_change :1;
- bool moved :1;
- bool inline_tiles :1;
- bool in_group :1;
- bool flip_x :1;
- bool flip_y :1;
- bool transpose_xy :1;
- bool hidden :1;
- bool hidden_by_parent :1;
- uint8_t padding :6;
+ bool partial_change : 1;
+ bool full_change : 1;
+ bool moved : 1;
+ bool inline_tiles : 1;
+ bool in_group : 1;
+ bool flip_x : 1;
+ bool flip_y : 1;
+ bool transpose_xy : 1;
+ bool hidden : 1;
+ bool hidden_by_parent : 1;
+ uint8_t padding : 6;
} displayio_tilegrid_t;
void displayio_tilegrid_set_hidden_by_parent(displayio_tilegrid_t *self, bool hidden);
@@ -73,16 +74,16 @@ void displayio_tilegrid_set_hidden_by_parent(displayio_tilegrid_t *self, bool hi
// Updating the screen is a three stage process.
// The first stage is used to determine i
-displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *self, displayio_area_t* tail);
+displayio_area_t *displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *self, displayio_area_t *tail);
// Area is always in absolute screen coordinates. Update transform is used to inform TileGrids how
// they relate to it.
-bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer);
-void displayio_tilegrid_update_transform(displayio_tilegrid_t *group, const displayio_buffer_transform_t* parent_transform);
+bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_colorspace_t *colorspace, const displayio_area_t *area, uint32_t *mask, uint32_t *buffer);
+void displayio_tilegrid_update_transform(displayio_tilegrid_t *group, const displayio_buffer_transform_t *parent_transform);
// Fills in area with the maximum bounds of all related pixels in the last rendered frame. Returns
// false if the tilegrid wasn't rendered in the last frame.
-bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_area_t* area);
+bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_area_t *area);
void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_TILEGRID_H
diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c
index 740af0570..3c9c2cc3a 100644
--- a/shared-module/displayio/__init__.c
+++ b/shared-module/displayio/__init__.c
@@ -44,7 +44,7 @@ displayio_buffer_transform_t null_transform = {
STATIC bool any_display_uses_this_framebuffer(mp_obj_base_t *obj) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].display_base.type == &framebufferio_framebufferdisplay_type) {
- framebufferio_framebufferdisplay_obj_t* display = &displays[i].framebuffer_display;
+ framebufferio_framebufferdisplay_obj_t *display = &displays[i].framebuffer_display;
if (display->framebuffer == obj) {
return true;
}
@@ -72,10 +72,10 @@ void displayio_background(void) {
}
if (displays[i].display.base.type == &displayio_display_type) {
displayio_display_background(&displays[i].display);
-#if CIRCUITPY_FRAMEBUFFERIO
+ #if CIRCUITPY_FRAMEBUFFERIO
} else if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) {
framebufferio_framebufferdisplay_background(&displays[i].framebuffer_display);
-#endif
+ #endif
} else if (displays[i].epaper_display.base.type == &displayio_epaperdisplay_type) {
displayio_epaperdisplay_background(&displays[i].epaper_display);
}
@@ -94,10 +94,10 @@ void common_hal_displayio_release_displays(void) {
release_display(&displays[i].display);
} else if (display_type == &displayio_epaperdisplay_type) {
release_epaperdisplay(&displays[i].epaper_display);
-#if CIRCUITPY_FRAMEBUFFERIO
+ #if CIRCUITPY_FRAMEBUFFERIO
} else if (display_type == &framebufferio_framebufferdisplay_type) {
release_framebufferdisplay(&displays[i].framebuffer_display);
-#endif
+ #endif
}
displays[i].display.base.type = &mp_type_NoneType;
}
@@ -111,14 +111,14 @@ void common_hal_displayio_release_displays(void) {
common_hal_displayio_i2cdisplay_deinit(&displays[i].i2cdisplay_bus);
} else if (bus_type == &displayio_parallelbus_type) {
common_hal_displayio_parallelbus_deinit(&displays[i].parallel_bus);
-#if CIRCUITPY_RGBMATRIX
+ #if CIRCUITPY_RGBMATRIX
} else if (bus_type == &rgbmatrix_RGBMatrix_type) {
common_hal_rgbmatrix_rgbmatrix_deinit(&displays[i].rgbmatrix);
-#endif
-#if CIRCUITPY_SHARPDISPLAY
+ #endif
+ #if CIRCUITPY_SHARPDISPLAY
} else if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) {
common_hal_sharpdisplay_framebuffer_deinit(&displays[i].sharpdisplay);
-#endif
+ #endif
}
displays[i].fourwire_bus.base.type = &mp_type_NoneType;
}
@@ -130,68 +130,68 @@ void reset_displays(void) {
// The SPI buses used by FourWires may be allocated on the heap so we need to move them inline.
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].fourwire_bus.base.type == &displayio_fourwire_type) {
- displayio_fourwire_obj_t* fourwire = &displays[i].fourwire_bus;
- if (((uint32_t) fourwire->bus) < ((uint32_t) &displays) ||
- ((uint32_t) fourwire->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) {
- busio_spi_obj_t* original_spi = fourwire->bus;
+ displayio_fourwire_obj_t *fourwire = &displays[i].fourwire_bus;
+ if (((uint32_t)fourwire->bus) < ((uint32_t)&displays) ||
+ ((uint32_t)fourwire->bus) > ((uint32_t)&displays + CIRCUITPY_DISPLAY_LIMIT)) {
+ busio_spi_obj_t *original_spi = fourwire->bus;
#if BOARD_SPI
- // We don't need to move original_spi if it is the board.SPI object because it is
- // statically allocated already. (Doing so would also make it impossible to reference in
- // a subsequent VM run.)
- if (original_spi == common_hal_board_get_spi()) {
- continue;
- }
+ // We don't need to move original_spi if it is the board.SPI object because it is
+ // statically allocated already. (Doing so would also make it impossible to reference in
+ // a subsequent VM run.)
+ if (original_spi == common_hal_board_get_spi()) {
+ continue;
+ }
#endif
#ifdef BOARD_USE_INTERNAL_SPI
- if (original_spi == (mp_obj_t)(&supervisor_flash_spi_bus)) {
- continue;
- }
+ if (original_spi == (mp_obj_t)(&supervisor_flash_spi_bus)) {
+ continue;
+ }
#endif
memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t));
fourwire->bus = &fourwire->inline_bus;
// Check for other displays that use the same spi bus and swap them too.
for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) {
if (displays[i].fourwire_bus.base.type == &displayio_fourwire_type &&
- displays[i].fourwire_bus.bus == original_spi) {
+ displays[i].fourwire_bus.bus == original_spi) {
displays[i].fourwire_bus.bus = &fourwire->inline_bus;
}
}
}
} else if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type) {
- displayio_i2cdisplay_obj_t* i2c = &displays[i].i2cdisplay_bus;
- if (((uint32_t) i2c->bus) < ((uint32_t) &displays) ||
- ((uint32_t) i2c->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) {
- busio_i2c_obj_t* original_i2c = i2c->bus;
+ displayio_i2cdisplay_obj_t *i2c = &displays[i].i2cdisplay_bus;
+ if (((uint32_t)i2c->bus) < ((uint32_t)&displays) ||
+ ((uint32_t)i2c->bus) > ((uint32_t)&displays + CIRCUITPY_DISPLAY_LIMIT)) {
+ busio_i2c_obj_t *original_i2c = i2c->bus;
#if BOARD_I2C
- // We don't need to move original_i2c if it is the board.I2C object because it is
- // statically allocated already. (Doing so would also make it impossible to reference in
- // a subsequent VM run.)
- if (original_i2c == common_hal_board_get_i2c()) {
- continue;
- }
+ // We don't need to move original_i2c if it is the board.I2C object because it is
+ // statically allocated already. (Doing so would also make it impossible to reference in
+ // a subsequent VM run.)
+ if (original_i2c == common_hal_board_get_i2c()) {
+ continue;
+ }
#endif
memcpy(&i2c->inline_bus, original_i2c, sizeof(busio_i2c_obj_t));
i2c->bus = &i2c->inline_bus;
// Check for other displays that use the same i2c bus and swap them too.
for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) {
if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type &&
- displays[i].i2cdisplay_bus.bus == original_i2c) {
+ displays[i].i2cdisplay_bus.bus == original_i2c) {
displays[i].i2cdisplay_bus.bus = &i2c->inline_bus;
}
}
}
-#if CIRCUITPY_RGBMATRIX
+ #if CIRCUITPY_RGBMATRIX
} else if (displays[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) {
- rgbmatrix_rgbmatrix_obj_t * pm = &displays[i].rgbmatrix;
- if(!any_display_uses_this_framebuffer(&pm->base)) {
+ rgbmatrix_rgbmatrix_obj_t *pm = &displays[i].rgbmatrix;
+ if (!any_display_uses_this_framebuffer(&pm->base)) {
common_hal_rgbmatrix_rgbmatrix_deinit(pm);
}
-#endif
-#if CIRCUITPY_SHARPDISPLAY
+ #endif
+ #if CIRCUITPY_SHARPDISPLAY
} else if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) {
- sharpdisplay_framebuffer_obj_t * sharp = &displays[i].sharpdisplay;
+ sharpdisplay_framebuffer_obj_t *sharp = &displays[i].sharpdisplay;
common_hal_sharpdisplay_framebuffer_reset(sharp);
-#endif
+ #endif
} else {
// Not an active display bus.
continue;
@@ -204,28 +204,28 @@ void reset_displays(void) {
if (displays[i].display.base.type == &displayio_display_type) {
reset_display(&displays[i].display);
} else if (displays[i].epaper_display.base.type == &displayio_epaperdisplay_type) {
- displayio_epaperdisplay_obj_t* display = &displays[i].epaper_display;
+ displayio_epaperdisplay_obj_t *display = &displays[i].epaper_display;
common_hal_displayio_epaperdisplay_show(display, NULL);
-#if CIRCUITPY_FRAMEBUFFERIO
+ #if CIRCUITPY_FRAMEBUFFERIO
} else if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) {
framebufferio_framebufferdisplay_reset(&displays[i].framebuffer_display);
-#endif
+ #endif
}
}
}
void displayio_gc_collect(void) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
-#if CIRCUITPY_RGBMATRIX
+ #if CIRCUITPY_RGBMATRIX
if (displays[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) {
rgbmatrix_rgbmatrix_collect_ptrs(&displays[i].rgbmatrix);
}
-#endif
-#if CIRCUITPY_SHARPDISPLAY
+ #endif
+ #if CIRCUITPY_SHARPDISPLAY
if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) {
common_hal_sharpdisplay_framebuffer_collect_ptrs(&displays[i].sharpdisplay);
}
-#endif
+ #endif
if (displays[i].display.base.type == NULL) {
continue;
@@ -235,17 +235,17 @@ void displayio_gc_collect(void) {
// but this is more precise, and is the only field that needs marking.
if (displays[i].display.base.type == &displayio_display_type) {
displayio_display_collect_ptrs(&displays[i].display);
-#if CIRCUITPY_FRAMEBUFFERIO
+ #if CIRCUITPY_FRAMEBUFFERIO
} else if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) {
framebufferio_framebufferdisplay_collect_ptrs(&displays[i].framebuffer_display);
-#endif
+ #endif
} else if (displays[i].epaper_display.base.type == &displayio_epaperdisplay_type) {
displayio_epaperdisplay_collect_ptrs(&displays[i].epaper_display);
}
}
}
-void displayio_area_expand(displayio_area_t* original, const displayio_area_t* addition) {
+void displayio_area_expand(displayio_area_t *original, const displayio_area_t *addition) {
if (addition->x1 < original->x1) {
original->x1 = addition->x1;
}
@@ -260,30 +260,30 @@ void displayio_area_expand(displayio_area_t* original, const displayio_area_t* a
}
}
-void displayio_area_copy(const displayio_area_t* src, displayio_area_t* dst) {
+void displayio_area_copy(const displayio_area_t *src, displayio_area_t *dst) {
dst->x1 = src->x1;
dst->y1 = src->y1;
dst->x2 = src->x2;
dst->y2 = src->y2;
}
-void displayio_area_scale(displayio_area_t* area, uint16_t scale) {
+void displayio_area_scale(displayio_area_t *area, uint16_t scale) {
area->x1 *= scale;
area->y1 *= scale;
area->x2 *= scale;
area->y2 *= scale;
}
-void displayio_area_shift(displayio_area_t* area, int16_t dx, int16_t dy) {
+void displayio_area_shift(displayio_area_t *area, int16_t dx, int16_t dy) {
area->x1 += dx;
area->y1 += dy;
area->x2 += dx;
area->y2 += dy;
}
-bool displayio_area_compute_overlap(const displayio_area_t* a,
- const displayio_area_t* b,
- displayio_area_t* overlap) {
+bool displayio_area_compute_overlap(const displayio_area_t *a,
+ const displayio_area_t *b,
+ displayio_area_t *overlap) {
overlap->x1 = a->x1;
if (b->x1 > overlap->x1) {
overlap->x1 = b->x1;
@@ -309,9 +309,9 @@ bool displayio_area_compute_overlap(const displayio_area_t* a,
return true;
}
-void displayio_area_union(const displayio_area_t* a,
- const displayio_area_t* b,
- displayio_area_t* u) {
+void displayio_area_union(const displayio_area_t *a,
+ const displayio_area_t *b,
+ displayio_area_t *u) {
u->x1 = a->x1;
if (b->x1 < u->x1) {
u->x1 = b->x1;
@@ -331,19 +331,19 @@ void displayio_area_union(const displayio_area_t* a,
}
}
-uint16_t displayio_area_width(const displayio_area_t* area) {
+uint16_t displayio_area_width(const displayio_area_t *area) {
return area->x2 - area->x1;
}
-uint16_t displayio_area_height(const displayio_area_t* area) {
+uint16_t displayio_area_height(const displayio_area_t *area) {
return area->y2 - area->y1;
}
-uint32_t displayio_area_size(const displayio_area_t* area) {
+uint32_t displayio_area_size(const displayio_area_t *area) {
return displayio_area_width(area) * displayio_area_height(area);
}
-bool displayio_area_equal(const displayio_area_t* a, const displayio_area_t* b) {
+bool displayio_area_equal(const displayio_area_t *a, const displayio_area_t *b) {
return a->x1 == b->x1 &&
a->y1 == b->y1 &&
a->x2 == b->x2 &&
@@ -352,9 +352,9 @@ bool displayio_area_equal(const displayio_area_t* a, const displayio_area_t* b)
// Original and whole must be in the same coordinate space.
void displayio_area_transform_within(bool mirror_x, bool mirror_y, bool transpose_xy,
- const displayio_area_t* original,
- const displayio_area_t* whole,
- displayio_area_t* transformed) {
+ const displayio_area_t *original,
+ const displayio_area_t *whole,
+ displayio_area_t *transformed) {
if (mirror_x) {
transformed->x1 = whole->x1 + (whole->x2 - original->x2);
transformed->x2 = whole->x2 - (original->x1 - whole->x1);
diff --git a/shared-module/displayio/__init__.h b/shared-module/displayio/__init__.h
index 44ad5a9a9..4a74b0e0e 100644
--- a/shared-module/displayio/__init__.h
+++ b/shared-module/displayio/__init__.h
@@ -49,20 +49,20 @@ typedef struct {
displayio_fourwire_obj_t fourwire_bus;
displayio_i2cdisplay_obj_t i2cdisplay_bus;
displayio_parallelbus_obj_t parallel_bus;
-#if CIRCUITPY_RGBMATRIX
+ #if CIRCUITPY_RGBMATRIX
rgbmatrix_rgbmatrix_obj_t rgbmatrix;
-#endif
-#if CIRCUITPY_SHARPDISPLAY
+ #endif
+ #if CIRCUITPY_SHARPDISPLAY
sharpdisplay_framebuffer_obj_t sharpdisplay;
-#endif
+ #endif
};
union {
mp_obj_base_t display_base;
displayio_display_obj_t display;
displayio_epaperdisplay_obj_t epaper_display;
-#if CIRCUITPY_FRAMEBUFFERIO
+ #if CIRCUITPY_FRAMEBUFFERIO
framebufferio_framebufferdisplay_obj_t framebuffer_display;
-#endif
+ #endif
};
} primary_display_t;
diff --git a/shared-module/displayio/area.h b/shared-module/displayio/area.h
index 7ad36883c..21bf2f8b2 100644
--- a/shared-module/displayio/area.h
+++ b/shared-module/displayio/area.h
@@ -35,7 +35,7 @@ struct _displayio_area_t {
int16_t y1;
int16_t x2; // Second point is exclusive.
int16_t y2;
- const displayio_area_t* next; // Next area in the linked list.
+ const displayio_area_t *next; // Next area in the linked list.
};
typedef struct {
@@ -53,23 +53,23 @@ typedef struct {
extern displayio_buffer_transform_t null_transform;
-void displayio_area_union(const displayio_area_t* a,
- const displayio_area_t* b,
- displayio_area_t* u);
-void displayio_area_expand(displayio_area_t* original, const displayio_area_t* addition);
-void displayio_area_copy(const displayio_area_t* src, displayio_area_t* dst);
-void displayio_area_scale(displayio_area_t* area, uint16_t scale);
-void displayio_area_shift(displayio_area_t* area, int16_t dx, int16_t dy);
-bool displayio_area_compute_overlap(const displayio_area_t* a,
- const displayio_area_t* b,
- displayio_area_t* overlap);
-uint16_t displayio_area_width(const displayio_area_t* area);
-uint16_t displayio_area_height(const displayio_area_t* area);
-uint32_t displayio_area_size(const displayio_area_t* area);
-bool displayio_area_equal(const displayio_area_t* a, const displayio_area_t* b);
+void displayio_area_union(const displayio_area_t *a,
+ const displayio_area_t *b,
+ displayio_area_t *u);
+void displayio_area_expand(displayio_area_t *original, const displayio_area_t *addition);
+void displayio_area_copy(const displayio_area_t *src, displayio_area_t *dst);
+void displayio_area_scale(displayio_area_t *area, uint16_t scale);
+void displayio_area_shift(displayio_area_t *area, int16_t dx, int16_t dy);
+bool displayio_area_compute_overlap(const displayio_area_t *a,
+ const displayio_area_t *b,
+ displayio_area_t *overlap);
+uint16_t displayio_area_width(const displayio_area_t *area);
+uint16_t displayio_area_height(const displayio_area_t *area);
+uint32_t displayio_area_size(const displayio_area_t *area);
+bool displayio_area_equal(const displayio_area_t *a, const displayio_area_t *b);
void displayio_area_transform_within(bool mirror_x, bool mirror_y, bool transpose_xy,
- const displayio_area_t* original,
- const displayio_area_t* whole,
- displayio_area_t* transformed);
+ const displayio_area_t *original,
+ const displayio_area_t *whole,
+ displayio_area_t *transformed);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_AREA_H
diff --git a/shared-module/displayio/display_core.c b/shared-module/displayio/display_core.c
index 57d33b565..a0b3afa0e 100644
--- a/shared-module/displayio/display_core.c
+++ b/shared-module/displayio/display_core.c
@@ -43,9 +43,9 @@
#define DISPLAYIO_CORE_DEBUG(...) (void)0
// #define DISPLAYIO_CORE_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
-void displayio_display_core_construct(displayio_display_core_t* self,
- mp_obj_t bus, uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation,
- uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word) {
+void displayio_display_core_construct(displayio_display_core_t *self,
+ mp_obj_t bus, uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation,
+ uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word) {
self->colorspace.depth = color_depth;
self->colorspace.grayscale = grayscale;
self->colorspace.grayscale_bit = 8 - color_depth;
@@ -99,8 +99,8 @@ void displayio_display_core_construct(displayio_display_core_t* self,
displayio_display_core_set_rotation(self, rotation);
}
-void displayio_display_core_set_rotation( displayio_display_core_t* self,
- int rotation) {
+void displayio_display_core_set_rotation(displayio_display_core_t *self,
+ int rotation) {
int height = self->height;
int width = self->width;
@@ -157,7 +157,7 @@ void displayio_display_core_set_rotation( displayio_display_core_t* self,
}
}
-bool displayio_display_core_show(displayio_display_core_t* self, displayio_group_t* root_group) {
+bool displayio_display_core_show(displayio_display_core_t *self, displayio_group_t *root_group) {
if (root_group == NULL) {
if (!circuitpython_splash.in_group) {
root_group = &circuitpython_splash;
@@ -184,19 +184,19 @@ bool displayio_display_core_show(displayio_display_core_t* self, displayio_group
return true;
}
-uint16_t displayio_display_core_get_width(displayio_display_core_t* self){
+uint16_t displayio_display_core_get_width(displayio_display_core_t *self) {
return self->width;
}
-uint16_t displayio_display_core_get_height(displayio_display_core_t* self){
+uint16_t displayio_display_core_get_height(displayio_display_core_t *self) {
return self->height;
}
-void displayio_display_core_set_dither(displayio_display_core_t* self, bool dither){
+void displayio_display_core_set_dither(displayio_display_core_t *self, bool dither) {
self->colorspace.dither = dither;
}
-bool displayio_display_core_get_dither(displayio_display_core_t* self){
+bool displayio_display_core_get_dither(displayio_display_core_t *self) {
return self->colorspace.dither;
}
@@ -204,18 +204,18 @@ bool displayio_display_core_bus_free(displayio_display_core_t *self) {
return !self->bus || self->bus_free(self->bus);
}
-bool displayio_display_core_begin_transaction(displayio_display_core_t* self) {
+bool displayio_display_core_begin_transaction(displayio_display_core_t *self) {
return self->begin_transaction(self->bus);
}
-void displayio_display_core_end_transaction(displayio_display_core_t* self) {
+void displayio_display_core_end_transaction(displayio_display_core_t *self) {
self->end_transaction(self->bus);
}
-void displayio_display_core_set_region_to_update(displayio_display_core_t* self, uint8_t column_command,
- uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
- bool data_as_commands, bool always_toggle_chip_select,
- displayio_area_t* area, bool SH1107_addressing) {
+void displayio_display_core_set_region_to_update(displayio_display_core_t *self, uint8_t column_command,
+ uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
+ bool data_as_commands, bool always_toggle_chip_select,
+ displayio_area_t *area, bool SH1107_addressing) {
uint16_t x1 = area->x1;
uint16_t x2 = area->x2;
uint16_t y1 = area->y1;
@@ -320,7 +320,7 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
}
}
-bool displayio_display_core_start_refresh(displayio_display_core_t* self) {
+bool displayio_display_core_start_refresh(displayio_display_core_t *self) {
if (!displayio_display_core_bus_free(self)) {
// Can't acquire display bus; skip updating this display. Try next display.
return false;
@@ -333,7 +333,7 @@ bool displayio_display_core_start_refresh(displayio_display_core_t* self) {
return true;
}
-void displayio_display_core_finish_refresh(displayio_display_core_t* self) {
+void displayio_display_core_finish_refresh(displayio_display_core_t *self) {
if (self->current_group != NULL) {
DISPLAYIO_CORE_DEBUG("displayiocore group_finish_refresh\n");
displayio_group_finish_refresh(self->current_group);
@@ -343,21 +343,21 @@ void displayio_display_core_finish_refresh(displayio_display_core_t* self) {
self->last_refresh = supervisor_ticks_ms64();
}
-void release_display_core(displayio_display_core_t* self) {
+void release_display_core(displayio_display_core_t *self) {
if (self->current_group != NULL) {
self->current_group->in_group = false;
}
}
-void displayio_display_core_collect_ptrs(displayio_display_core_t* self) {
+void displayio_display_core_collect_ptrs(displayio_display_core_t *self) {
gc_collect_ptr(self->current_group);
}
-bool displayio_display_core_fill_area(displayio_display_core_t *self, displayio_area_t* area, uint32_t* mask, uint32_t *buffer) {
+bool displayio_display_core_fill_area(displayio_display_core_t *self, displayio_area_t *area, uint32_t *mask, uint32_t *buffer) {
return displayio_group_fill_area(self->current_group, &self->colorspace, area, mask, buffer);
}
-bool displayio_display_core_clip_area(displayio_display_core_t *self, const displayio_area_t* area, displayio_area_t* clipped) {
+bool displayio_display_core_clip_area(displayio_display_core_t *self, const displayio_area_t *area, displayio_area_t *clipped) {
bool overlaps = displayio_area_compute_overlap(&self->area, area, clipped);
if (!overlaps) {
return false;
diff --git a/shared-module/displayio/display_core.h b/shared-module/displayio/display_core.h
index fe6cb6f3f..8c2ba21b5 100644
--- a/shared-module/displayio/display_core.h
+++ b/shared-module/displayio/display_core.h
@@ -57,38 +57,38 @@ typedef struct {
bool refresh_in_progress;
} displayio_display_core_t;
-void displayio_display_core_construct(displayio_display_core_t* self,
- mp_obj_t bus, uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation,
- uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word);
+void displayio_display_core_construct(displayio_display_core_t *self,
+ mp_obj_t bus, uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation,
+ uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word);
-bool displayio_display_core_show(displayio_display_core_t* self, displayio_group_t* root_group);
+bool displayio_display_core_show(displayio_display_core_t *self, displayio_group_t *root_group);
-uint16_t displayio_display_core_get_width(displayio_display_core_t* self);
-uint16_t displayio_display_core_get_height(displayio_display_core_t* self);
+uint16_t displayio_display_core_get_width(displayio_display_core_t *self);
+uint16_t displayio_display_core_get_height(displayio_display_core_t *self);
-void displayio_display_core_set_dither(displayio_display_core_t* self, bool dither);
-bool displayio_display_core_get_dither(displayio_display_core_t* self);
+void displayio_display_core_set_dither(displayio_display_core_t *self, bool dither);
+bool displayio_display_core_get_dither(displayio_display_core_t *self);
-void displayio_display_core_set_rotation(displayio_display_core_t* self, int rotation);
+void displayio_display_core_set_rotation(displayio_display_core_t *self, int rotation);
bool displayio_display_core_bus_free(displayio_display_core_t *self);
-bool displayio_display_core_begin_transaction(displayio_display_core_t* self);
-void displayio_display_core_end_transaction(displayio_display_core_t* self);
+bool displayio_display_core_begin_transaction(displayio_display_core_t *self);
+void displayio_display_core_end_transaction(displayio_display_core_t *self);
-void displayio_display_core_set_region_to_update(displayio_display_core_t* self, uint8_t column_command,
- uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
- bool data_as_commands, bool always_toggle_chip_select,
- displayio_area_t* area, bool SH1107_addressing);
+void displayio_display_core_set_region_to_update(displayio_display_core_t *self, uint8_t column_command,
+ uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
+ bool data_as_commands, bool always_toggle_chip_select,
+ displayio_area_t *area, bool SH1107_addressing);
-void release_display_core(displayio_display_core_t* self);
+void release_display_core(displayio_display_core_t *self);
-bool displayio_display_core_start_refresh(displayio_display_core_t* self);
-void displayio_display_core_finish_refresh(displayio_display_core_t* self);
+bool displayio_display_core_start_refresh(displayio_display_core_t *self);
+void displayio_display_core_finish_refresh(displayio_display_core_t *self);
-void displayio_display_core_collect_ptrs(displayio_display_core_t* self);
+void displayio_display_core_collect_ptrs(displayio_display_core_t *self);
-bool displayio_display_core_fill_area(displayio_display_core_t *self, displayio_area_t* area, uint32_t* mask, uint32_t *buffer);
+bool displayio_display_core_fill_area(displayio_display_core_t *self, displayio_area_t *area, uint32_t *mask, uint32_t *buffer);
-bool displayio_display_core_clip_area(displayio_display_core_t *self, const displayio_area_t* area, displayio_area_t* clipped);
+bool displayio_display_core_clip_area(displayio_display_core_t *self, const displayio_area_t *area, displayio_area_t *clipped);
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_DISPLAY_CORE_H
diff --git a/shared-module/fontio/BuiltinFont.c b/shared-module/fontio/BuiltinFont.c
index 58820d524..b77a6a1c8 100644
--- a/shared-module/fontio/BuiltinFont.c
+++ b/shared-module/fontio/BuiltinFont.c
@@ -47,7 +47,7 @@ uint8_t fontio_builtinfont_get_glyph_index(const fontio_builtinfont_t *self, mp_
return codepoint - 0x20;
}
// Do a linear search of the mapping for unicode.
- const byte* j = self->unicode_characters;
+ const byte *j = self->unicode_characters;
uint8_t k = 0;
while (j < self->unicode_characters + self->unicode_characters_len) {
unichar potential_c = utf8_get_char(j);
@@ -75,5 +75,5 @@ mp_obj_t common_hal_fontio_builtinfont_get_glyph(const fontio_builtinfont_t *sel
MP_OBJ_NEW_SMALL_INT(self->width),
MP_OBJ_NEW_SMALL_INT(0)
};
- return namedtuple_make_new((const mp_obj_type_t*) &fontio_glyph_type, 8, field_values, NULL);
+ return namedtuple_make_new((const mp_obj_type_t *)&fontio_glyph_type, 8, field_values, NULL);
}
diff --git a/shared-module/fontio/BuiltinFont.h b/shared-module/fontio/BuiltinFont.h
index 30b4ade8c..79c861419 100644
--- a/shared-module/fontio/BuiltinFont.h
+++ b/shared-module/fontio/BuiltinFont.h
@@ -35,10 +35,10 @@
typedef struct {
mp_obj_base_t base;
- const displayio_bitmap_t* bitmap;
+ const displayio_bitmap_t *bitmap;
uint8_t width;
uint8_t height;
- const byte* unicode_characters;
+ const byte *unicode_characters;
uint16_t unicode_characters_len;
} fontio_builtinfont_t;
diff --git a/shared-module/framebufferio/FramebufferDisplay.c b/shared-module/framebufferio/FramebufferDisplay.c
index 03e121c91..e236616f9 100644
--- a/shared-module/framebufferio/FramebufferDisplay.c
+++ b/shared-module/framebufferio/FramebufferDisplay.c
@@ -45,10 +45,10 @@
? self->framebuffer_protocol->method(self->framebuffer) \
: (default_value))
-void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebufferdisplay_obj_t* self,
- mp_obj_t framebuffer,
- uint16_t rotation,
- bool auto_refresh) {
+void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebufferdisplay_obj_t *self,
+ mp_obj_t framebuffer,
+ uint16_t rotation,
+ bool auto_refresh) {
// Turn off auto-refresh as we init.
self->auto_refresh = false;
self->framebuffer = framebuffer;
@@ -73,12 +73,12 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
fb_getter_default(get_bytes_per_cell, 2),
fb_getter_default(get_reverse_pixels_in_byte, false),
fb_getter_default(get_reverse_pixels_in_word, false)
- );
+ );
self->first_pixel_offset = fb_getter_default(get_first_pixel_offset, 0);
self->row_stride = fb_getter_default(get_row_stride, 0);
if (self->row_stride == 0) {
- self->row_stride = self->core.width * self->core.colorspace.depth/8;
+ self->row_stride = self->core.width * self->core.colorspace.depth / 8;
}
self->framebuffer_protocol->get_bufinfo(self->framebuffer, &self->bufinfo);
@@ -102,40 +102,40 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
common_hal_framebufferio_framebufferdisplay_set_auto_refresh(self, auto_refresh);
}
-bool common_hal_framebufferio_framebufferdisplay_show(framebufferio_framebufferdisplay_obj_t* self, displayio_group_t* root_group) {
+bool common_hal_framebufferio_framebufferdisplay_show(framebufferio_framebufferdisplay_obj_t *self, displayio_group_t *root_group) {
return displayio_display_core_show(&self->core, root_group);
}
-uint16_t common_hal_framebufferio_framebufferdisplay_get_width(framebufferio_framebufferdisplay_obj_t* self){
+uint16_t common_hal_framebufferio_framebufferdisplay_get_width(framebufferio_framebufferdisplay_obj_t *self) {
return displayio_display_core_get_width(&self->core);
}
-uint16_t common_hal_framebufferio_framebufferdisplay_get_height(framebufferio_framebufferdisplay_obj_t* self){
+uint16_t common_hal_framebufferio_framebufferdisplay_get_height(framebufferio_framebufferdisplay_obj_t *self) {
return displayio_display_core_get_height(&self->core);
}
-bool common_hal_framebufferio_framebufferdisplay_get_auto_brightness(framebufferio_framebufferdisplay_obj_t* self) {
+bool common_hal_framebufferio_framebufferdisplay_get_auto_brightness(framebufferio_framebufferdisplay_obj_t *self) {
if (self->framebuffer_protocol->get_auto_brightness) {
return self->framebuffer_protocol->get_auto_brightness(self->framebuffer);
}
return true;
}
-bool common_hal_framebufferio_framebufferdisplay_set_auto_brightness(framebufferio_framebufferdisplay_obj_t* self, bool auto_brightness) {
+bool common_hal_framebufferio_framebufferdisplay_set_auto_brightness(framebufferio_framebufferdisplay_obj_t *self, bool auto_brightness) {
if (self->framebuffer_protocol->set_auto_brightness) {
return self->framebuffer_protocol->set_auto_brightness(self->framebuffer, auto_brightness);
}
return false;
}
-mp_float_t common_hal_framebufferio_framebufferdisplay_get_brightness(framebufferio_framebufferdisplay_obj_t* self) {
+mp_float_t common_hal_framebufferio_framebufferdisplay_get_brightness(framebufferio_framebufferdisplay_obj_t *self) {
if (self->framebuffer_protocol->get_brightness) {
return self->framebuffer_protocol->get_brightness(self->framebuffer);
}
return -1;
}
-bool common_hal_framebufferio_framebufferdisplay_set_brightness(framebufferio_framebufferdisplay_obj_t* self, mp_float_t brightness) {
+bool common_hal_framebufferio_framebufferdisplay_set_brightness(framebufferio_framebufferdisplay_obj_t *self, mp_float_t brightness) {
bool ok = false;
if (self->framebuffer_protocol->set_brightness) {
self->framebuffer_protocol->set_brightness(self->framebuffer, brightness);
@@ -144,11 +144,11 @@ bool common_hal_framebufferio_framebufferdisplay_set_brightness(framebufferio_fr
return ok;
}
-mp_obj_t common_hal_framebufferio_framebufferdisplay_get_framebuffer(framebufferio_framebufferdisplay_obj_t* self) {
+mp_obj_t common_hal_framebufferio_framebufferdisplay_get_framebuffer(framebufferio_framebufferdisplay_obj_t *self) {
return self->framebuffer;
}
-STATIC const displayio_area_t* _get_refresh_areas(framebufferio_framebufferdisplay_obj_t *self) {
+STATIC const displayio_area_t *_get_refresh_areas(framebufferio_framebufferdisplay_obj_t *self) {
if (self->core.full_refresh) {
self->core.area.next = NULL;
return &self->core.area;
@@ -158,8 +158,8 @@ STATIC const displayio_area_t* _get_refresh_areas(framebufferio_framebufferdispl
return NULL;
}
-#define MARK_ROW_DIRTY(r) (dirty_row_bitmask[r/8] |= (1 << (r & 7)))
-STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const displayio_area_t* area, uint8_t *dirty_row_bitmask) {
+#define MARK_ROW_DIRTY(r) (dirty_row_bitmask[r / 8] |= (1 << (r & 7)))
+STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t *self, const displayio_area_t *area, uint8_t *dirty_row_bitmask) {
uint16_t buffer_size = 128; // In uint32_ts
displayio_area_t clipped;
@@ -233,11 +233,11 @@ STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const di
size_t rowstride = self->row_stride;
uint8_t *dest = buf + subrectangle.y1 * rowstride + subrectangle.x1 * self->core.colorspace.depth / 8;
- uint8_t *src = (uint8_t*)buffer;
+ uint8_t *src = (uint8_t *)buffer;
size_t rowsize = (subrectangle.x2 - subrectangle.x1) * self->core.colorspace.depth / 8;
for (uint16_t i = subrectangle.y1; i < subrectangle.y2; i++) {
- assert(dest >= buf && dest < endbuf && dest+rowsize <= endbuf);
+ assert(dest >= buf && dest < endbuf && dest + rowsize <= endbuf);
MARK_ROW_DIRTY(i);
memcpy(dest, src, rowsize);
dest += rowstride;
@@ -251,13 +251,13 @@ STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const di
return true;
}
-STATIC void _refresh_display(framebufferio_framebufferdisplay_obj_t* self) {
+STATIC void _refresh_display(framebufferio_framebufferdisplay_obj_t *self) {
self->framebuffer_protocol->get_bufinfo(self->framebuffer, &self->bufinfo);
- if(!self->bufinfo.buf) {
+ if (!self->bufinfo.buf) {
return;
}
displayio_display_core_start_refresh(&self->core);
- const displayio_area_t* current_area = _get_refresh_areas(self);
+ const displayio_area_t *current_area = _get_refresh_areas(self);
if (current_area) {
uint8_t dirty_row_bitmask[(self->core.height + 7) / 8];
memset(dirty_row_bitmask, 0, sizeof(dirty_row_bitmask));
@@ -271,10 +271,10 @@ STATIC void _refresh_display(framebufferio_framebufferdisplay_obj_t* self) {
displayio_display_core_finish_refresh(&self->core);
}
-void common_hal_framebufferio_framebufferdisplay_set_rotation(framebufferio_framebufferdisplay_obj_t* self, int rotation){
+void common_hal_framebufferio_framebufferdisplay_set_rotation(framebufferio_framebufferdisplay_obj_t *self, int rotation) {
bool transposed = (self->core.rotation == 90 || self->core.rotation == 270);
bool will_transposed = (rotation == 90 || rotation == 270);
- if(transposed != will_transposed) {
+ if (transposed != will_transposed) {
int tmp = self->core.width;
self->core.width = self->core.height;
self->core.height = tmp;
@@ -289,12 +289,12 @@ void common_hal_framebufferio_framebufferdisplay_set_rotation(framebufferio_fram
}
}
-uint16_t common_hal_framebufferio_framebufferdisplay_get_rotation(framebufferio_framebufferdisplay_obj_t* self){
+uint16_t common_hal_framebufferio_framebufferdisplay_get_rotation(framebufferio_framebufferdisplay_obj_t *self) {
return self->core.rotation;
}
-bool common_hal_framebufferio_framebufferdisplay_refresh(framebufferio_framebufferdisplay_obj_t* self, uint32_t target_ms_per_frame, uint32_t maximum_ms_per_real_frame) {
+bool common_hal_framebufferio_framebufferdisplay_refresh(framebufferio_framebufferdisplay_obj_t *self, uint32_t target_ms_per_frame, uint32_t maximum_ms_per_real_frame) {
if (!self->auto_refresh && !self->first_manual_refresh) {
uint64_t current_time = supervisor_ticks_ms64();
uint32_t current_ms_since_real_refresh = current_time - self->core.last_refresh;
@@ -319,12 +319,12 @@ bool common_hal_framebufferio_framebufferdisplay_refresh(framebufferio_framebuff
return true;
}
-bool common_hal_framebufferio_framebufferdisplay_get_auto_refresh(framebufferio_framebufferdisplay_obj_t* self) {
+bool common_hal_framebufferio_framebufferdisplay_get_auto_refresh(framebufferio_framebufferdisplay_obj_t *self) {
return self->auto_refresh;
}
-void common_hal_framebufferio_framebufferdisplay_set_auto_refresh(framebufferio_framebufferdisplay_obj_t* self,
- bool auto_refresh) {
+void common_hal_framebufferio_framebufferdisplay_set_auto_refresh(framebufferio_framebufferdisplay_obj_t *self,
+ bool auto_refresh) {
self->first_manual_refresh = !auto_refresh;
if (auto_refresh != self->auto_refresh) {
if (auto_refresh) {
@@ -336,12 +336,12 @@ void common_hal_framebufferio_framebufferdisplay_set_auto_refresh(framebufferio_
self->auto_refresh = auto_refresh;
}
-STATIC void _update_backlight(framebufferio_framebufferdisplay_obj_t* self) {
+STATIC void _update_backlight(framebufferio_framebufferdisplay_obj_t *self) {
// TODO(tannewt): Fade the backlight based on it's existing value and a target value. The target
// should account for ambient light when possible.
}
-void framebufferio_framebufferdisplay_background(framebufferio_framebufferdisplay_obj_t* self) {
+void framebufferio_framebufferdisplay_background(framebufferio_framebufferdisplay_obj_t *self) {
_update_backlight(self);
if (self->auto_refresh && (supervisor_ticks_ms64() - self->core.last_refresh) > self->native_ms_per_frame) {
@@ -349,21 +349,21 @@ void framebufferio_framebufferdisplay_background(framebufferio_framebufferdispla
}
}
-void release_framebufferdisplay(framebufferio_framebufferdisplay_obj_t* self) {
+void release_framebufferdisplay(framebufferio_framebufferdisplay_obj_t *self) {
common_hal_framebufferio_framebufferdisplay_set_auto_refresh(self, false);
release_display_core(&self->core);
self->framebuffer_protocol->deinit(self->framebuffer);
self->base.type = &mp_type_NoneType;
}
-void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisplay_obj_t* self) {
+void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisplay_obj_t *self) {
gc_collect_ptr(self->framebuffer);
displayio_display_core_collect_ptrs(&self->core);
}
-void framebufferio_framebufferdisplay_reset(framebufferio_framebufferdisplay_obj_t* self) {
+void framebufferio_framebufferdisplay_reset(framebufferio_framebufferdisplay_obj_t *self) {
mp_obj_type_t *fb_type = mp_obj_get_type(self->framebuffer);
- if(fb_type != NULL && fb_type != &mp_type_NoneType) {
+ if (fb_type != NULL && fb_type != &mp_type_NoneType) {
common_hal_framebufferio_framebufferdisplay_set_auto_refresh(self, true);
common_hal_framebufferio_framebufferdisplay_show(self, NULL);
self->core.full_refresh = true;
diff --git a/shared-module/framebufferio/FramebufferDisplay.h b/shared-module/framebufferio/FramebufferDisplay.h
index d73d4b9a9..b6138e220 100644
--- a/shared-module/framebufferio/FramebufferDisplay.h
+++ b/shared-module/framebufferio/FramebufferDisplay.h
@@ -53,13 +53,13 @@ typedef struct {
bool first_manual_refresh;
} framebufferio_framebufferdisplay_obj_t;
-void framebufferio_framebufferdisplay_background(framebufferio_framebufferdisplay_obj_t* self);
-void release_framebufferdisplay(framebufferio_framebufferdisplay_obj_t* self);
-void framebufferio_framebufferdisplay_reset(framebufferio_framebufferdisplay_obj_t* self);
+void framebufferio_framebufferdisplay_background(framebufferio_framebufferdisplay_obj_t *self);
+void release_framebufferdisplay(framebufferio_framebufferdisplay_obj_t *self);
+void framebufferio_framebufferdisplay_reset(framebufferio_framebufferdisplay_obj_t *self);
-void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisplay_obj_t* self);
+void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisplay_obj_t *self);
-mp_obj_t common_hal_framebufferio_framebufferdisplay_get_framebuffer(framebufferio_framebufferdisplay_obj_t* self);
+mp_obj_t common_hal_framebufferio_framebufferdisplay_get_framebuffer(framebufferio_framebufferdisplay_obj_t *self);
typedef bool (*framebuffer_get_auto_brightness_fun)(mp_obj_t);
typedef bool (*framebuffer_get_reverse_pixels_in_byte_fun)(mp_obj_t);
diff --git a/shared-module/gamepad/GamePad.c b/shared-module/gamepad/GamePad.c
index 7b4108eb2..55b447f1e 100644
--- a/shared-module/gamepad/GamePad.c
+++ b/shared-module/gamepad/GamePad.c
@@ -30,7 +30,7 @@
#include "supervisor/shared/tick.h"
void common_hal_gamepad_gamepad_init(gamepad_obj_t *gamepad,
- const mp_obj_t pins[], size_t n_pins) {
+ const mp_obj_t pins[], size_t n_pins) {
for (size_t i = 0; i < 8; ++i) {
gamepad->pins[i] = NULL;
}
diff --git a/shared-module/gamepad/GamePad.h b/shared-module/gamepad/GamePad.h
index 048fbcd2b..7c28e2285 100644
--- a/shared-module/gamepad/GamePad.h
+++ b/shared-module/gamepad/GamePad.h
@@ -33,7 +33,7 @@
typedef struct {
mp_obj_base_t base;
- digitalio_digitalinout_obj_t* pins[8];
+ digitalio_digitalinout_obj_t *pins[8];
volatile uint8_t last;
volatile uint8_t pressed;
uint8_t pulls;
diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c
index 9874b2752..c70788606 100644
--- a/shared-module/gamepad/__init__.c
+++ b/shared-module/gamepad/__init__.c
@@ -38,14 +38,14 @@ void gamepad_tick(void) {
uint8_t current = 0;
uint8_t bit = 1;
- void* singleton = MP_STATE_VM(gamepad_singleton);
+ void *singleton = MP_STATE_VM(gamepad_singleton);
if (singleton == NULL || !MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepad_type)) {
return;
}
gamepad_obj_t *self = MP_OBJ_TO_PTR(singleton);
for (int i = 0; i < 8; ++i) {
- digitalio_digitalinout_obj_t* pin = self->pins[i];
+ digitalio_digitalinout_obj_t *pin = self->pins[i];
if (!pin) {
break;
}
diff --git a/shared-module/gamepadshift/GamePadShift.c b/shared-module/gamepadshift/GamePadShift.c
index 51da61702..6efa0ea5c 100644
--- a/shared-module/gamepadshift/GamePadShift.c
+++ b/shared-module/gamepadshift/GamePadShift.c
@@ -30,16 +30,16 @@
#include "supervisor/shared/tick.h"
void common_hal_gamepadshift_gamepadshift_init(gamepadshift_obj_t *gamepadshift,
- digitalio_digitalinout_obj_t *clock_pin,
- digitalio_digitalinout_obj_t *data_pin,
- digitalio_digitalinout_obj_t *latch_pin) {
+ digitalio_digitalinout_obj_t *clock_pin,
+ digitalio_digitalinout_obj_t *data_pin,
+ digitalio_digitalinout_obj_t *latch_pin) {
common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE);
gamepadshift->data_pin = data_pin;
common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0,
- DRIVE_MODE_PUSH_PULL);
+ DRIVE_MODE_PUSH_PULL);
gamepadshift->clock_pin = clock_pin;
common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1,
- DRIVE_MODE_PUSH_PULL);
+ DRIVE_MODE_PUSH_PULL);
gamepadshift->latch_pin = latch_pin;
gamepadshift->last = 0;
diff --git a/shared-module/gamepadshift/GamePadShift.h b/shared-module/gamepadshift/GamePadShift.h
index b4b26b7a9..53aef5098 100644
--- a/shared-module/gamepadshift/GamePadShift.h
+++ b/shared-module/gamepadshift/GamePadShift.h
@@ -33,9 +33,9 @@
typedef struct {
mp_obj_base_t base;
- digitalio_digitalinout_obj_t* data_pin;
- digitalio_digitalinout_obj_t* clock_pin;
- digitalio_digitalinout_obj_t* latch_pin;
+ digitalio_digitalinout_obj_t *data_pin;
+ digitalio_digitalinout_obj_t *clock_pin;
+ digitalio_digitalinout_obj_t *latch_pin;
volatile uint8_t pressed;
volatile uint8_t last;
} gamepadshift_obj_t;
diff --git a/shared-module/gamepadshift/__init__.c b/shared-module/gamepadshift/__init__.c
index 47a008c50..44cf3be81 100644
--- a/shared-module/gamepadshift/__init__.c
+++ b/shared-module/gamepadshift/__init__.c
@@ -30,7 +30,7 @@
#include "shared-bindings/gamepadshift/GamePadShift.h"
void gamepadshift_tick(void) {
- void* singleton = MP_STATE_VM(gamepad_singleton);
+ void *singleton = MP_STATE_VM(gamepad_singleton);
if (singleton == NULL || !MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepadshift_type)) {
return;
}
diff --git a/shared-module/ipaddress/IPv4Address.c b/shared-module/ipaddress/IPv4Address.c
index f573d9d0a..6850fcadc 100644
--- a/shared-module/ipaddress/IPv4Address.c
+++ b/shared-module/ipaddress/IPv4Address.c
@@ -30,10 +30,10 @@
#include "shared-bindings/ipaddress/IPv4Address.h"
-void common_hal_ipaddress_ipv4address_construct(ipaddress_ipv4address_obj_t* self, uint8_t* buf, size_t len) {
+void common_hal_ipaddress_ipv4address_construct(ipaddress_ipv4address_obj_t *self, uint8_t *buf, size_t len) {
self->ip_bytes = mp_obj_new_bytes(buf, len);
}
-mp_obj_t common_hal_ipaddress_ipv4address_get_packed(ipaddress_ipv4address_obj_t* self) {
+mp_obj_t common_hal_ipaddress_ipv4address_get_packed(ipaddress_ipv4address_obj_t *self) {
return self->ip_bytes;
}
diff --git a/shared-module/ipaddress/__init__.c b/shared-module/ipaddress/__init__.c
index a8f8e1caf..9d98c0eb7 100644
--- a/shared-module/ipaddress/__init__.c
+++ b/shared-module/ipaddress/__init__.c
@@ -28,8 +28,8 @@
#include "shared-bindings/ipaddress/IPv4Address.h"
mp_obj_t common_hal_ipaddress_new_ipv4address(uint32_t value) {
- ipaddress_ipv4address_obj_t* self = m_new_obj(ipaddress_ipv4address_obj_t);
+ ipaddress_ipv4address_obj_t *self = m_new_obj(ipaddress_ipv4address_obj_t);
self->base.type = &ipaddress_ipv4address_type;
- common_hal_ipaddress_ipv4address_construct(self, (uint8_t*) &value, 4);
+ common_hal_ipaddress_ipv4address_construct(self, (uint8_t *)&value, 4);
return MP_OBJ_FROM_PTR(self);
}
diff --git a/shared-module/memorymonitor/AllocationAlarm.c b/shared-module/memorymonitor/AllocationAlarm.c
index 35f4e4c63..473a19396 100644
--- a/shared-module/memorymonitor/AllocationAlarm.c
+++ b/shared-module/memorymonitor/AllocationAlarm.c
@@ -31,17 +31,17 @@
#include "py/mpstate.h"
#include "py/runtime.h"
-void common_hal_memorymonitor_allocationalarm_construct(memorymonitor_allocationalarm_obj_t* self, size_t minimum_block_count) {
+void common_hal_memorymonitor_allocationalarm_construct(memorymonitor_allocationalarm_obj_t *self, size_t minimum_block_count) {
self->minimum_block_count = minimum_block_count;
self->next = NULL;
self->previous = NULL;
}
-void common_hal_memorymonitor_allocationalarm_set_ignore(memorymonitor_allocationalarm_obj_t* self, mp_int_t count) {
+void common_hal_memorymonitor_allocationalarm_set_ignore(memorymonitor_allocationalarm_obj_t *self, mp_int_t count) {
self->count = count;
}
-void common_hal_memorymonitor_allocationalarm_pause(memorymonitor_allocationalarm_obj_t* self) {
+void common_hal_memorymonitor_allocationalarm_pause(memorymonitor_allocationalarm_obj_t *self) {
// Check to make sure we aren't already paused. We can be if we're exiting from an exception we
// caused.
if (self->previous == NULL) {
@@ -52,12 +52,12 @@ void common_hal_memorymonitor_allocationalarm_pause(memorymonitor_allocationalar
self->previous = NULL;
}
-void common_hal_memorymonitor_allocationalarm_resume(memorymonitor_allocationalarm_obj_t* self) {
+void common_hal_memorymonitor_allocationalarm_resume(memorymonitor_allocationalarm_obj_t *self) {
if (self->previous != NULL) {
mp_raise_RuntimeError(translate("Already running"));
}
self->next = MP_STATE_VM(active_allocationalarms);
- self->previous = (memorymonitor_allocationalarm_obj_t**) &MP_STATE_VM(active_allocationalarms);
+ self->previous = (memorymonitor_allocationalarm_obj_t **)&MP_STATE_VM(active_allocationalarms);
if (self->next != NULL) {
self->next->previous = &self->next;
}
@@ -65,11 +65,11 @@ void common_hal_memorymonitor_allocationalarm_resume(memorymonitor_allocationala
}
void memorymonitor_allocationalarms_allocation(size_t block_count) {
- memorymonitor_allocationalarm_obj_t* alarm = MP_OBJ_TO_PTR(MP_STATE_VM(active_allocationalarms));
+ memorymonitor_allocationalarm_obj_t *alarm = MP_OBJ_TO_PTR(MP_STATE_VM(active_allocationalarms));
size_t alert_count = 0;
while (alarm != NULL) {
// Hold onto next in case we remove the alarm from the list.
- memorymonitor_allocationalarm_obj_t* next = alarm->next;
+ memorymonitor_allocationalarm_obj_t *next = alarm->next;
if (block_count >= alarm->minimum_block_count) {
if (alarm->count > 0) {
alarm->count--;
diff --git a/shared-module/memorymonitor/AllocationAlarm.h b/shared-module/memorymonitor/AllocationAlarm.h
index 172c24f6c..1f6e3d069 100644
--- a/shared-module/memorymonitor/AllocationAlarm.h
+++ b/shared-module/memorymonitor/AllocationAlarm.h
@@ -41,8 +41,8 @@ typedef struct _memorymonitor_allocationalarm_obj_t {
size_t minimum_block_count;
mp_int_t count;
// Store the location that points to us so we can remove ourselves.
- memorymonitor_allocationalarm_obj_t** previous;
- memorymonitor_allocationalarm_obj_t* next;
+ memorymonitor_allocationalarm_obj_t **previous;
+ memorymonitor_allocationalarm_obj_t *next;
} memorymonitor_allocationalarm_obj_t;
void memorymonitor_allocationalarms_allocation(size_t block_count);
diff --git a/shared-module/memorymonitor/AllocationSize.c b/shared-module/memorymonitor/AllocationSize.c
index c28e65592..42fae3b06 100644
--- a/shared-module/memorymonitor/AllocationSize.c
+++ b/shared-module/memorymonitor/AllocationSize.c
@@ -30,50 +30,50 @@
#include "py/mpstate.h"
#include "py/runtime.h"
-void common_hal_memorymonitor_allocationsize_construct(memorymonitor_allocationsize_obj_t* self) {
+void common_hal_memorymonitor_allocationsize_construct(memorymonitor_allocationsize_obj_t *self) {
common_hal_memorymonitor_allocationsize_clear(self);
self->next = NULL;
self->previous = NULL;
}
-void common_hal_memorymonitor_allocationsize_pause(memorymonitor_allocationsize_obj_t* self) {
+void common_hal_memorymonitor_allocationsize_pause(memorymonitor_allocationsize_obj_t *self) {
*self->previous = self->next;
self->next = NULL;
self->previous = NULL;
}
-void common_hal_memorymonitor_allocationsize_resume(memorymonitor_allocationsize_obj_t* self) {
+void common_hal_memorymonitor_allocationsize_resume(memorymonitor_allocationsize_obj_t *self) {
if (self->previous != NULL) {
mp_raise_RuntimeError(translate("Already running"));
}
self->next = MP_STATE_VM(active_allocationsizes);
- self->previous = (memorymonitor_allocationsize_obj_t**) &MP_STATE_VM(active_allocationsizes);
+ self->previous = (memorymonitor_allocationsize_obj_t **)&MP_STATE_VM(active_allocationsizes);
if (self->next != NULL) {
self->next->previous = &self->next;
}
MP_STATE_VM(active_allocationsizes) = self;
}
-void common_hal_memorymonitor_allocationsize_clear(memorymonitor_allocationsize_obj_t* self) {
+void common_hal_memorymonitor_allocationsize_clear(memorymonitor_allocationsize_obj_t *self) {
for (size_t i = 0; i < ALLOCATION_SIZE_BUCKETS; i++) {
self->buckets[i] = 0;
}
}
-uint16_t common_hal_memorymonitor_allocationsize_get_len(memorymonitor_allocationsize_obj_t* self) {
+uint16_t common_hal_memorymonitor_allocationsize_get_len(memorymonitor_allocationsize_obj_t *self) {
return ALLOCATION_SIZE_BUCKETS;
}
-size_t common_hal_memorymonitor_allocationsize_get_bytes_per_block(memorymonitor_allocationsize_obj_t* self) {
+size_t common_hal_memorymonitor_allocationsize_get_bytes_per_block(memorymonitor_allocationsize_obj_t *self) {
return BYTES_PER_BLOCK;
}
-uint16_t common_hal_memorymonitor_allocationsize_get_item(memorymonitor_allocationsize_obj_t* self, int16_t index) {
+uint16_t common_hal_memorymonitor_allocationsize_get_item(memorymonitor_allocationsize_obj_t *self, int16_t index) {
return self->buckets[index];
}
void memorymonitor_allocationsizes_track_allocation(size_t block_count) {
- memorymonitor_allocationsize_obj_t* as = MP_OBJ_TO_PTR(MP_STATE_VM(active_allocationsizes));
+ memorymonitor_allocationsize_obj_t *as = MP_OBJ_TO_PTR(MP_STATE_VM(active_allocationsizes));
size_t power_of_two = 0;
block_count >>= 1;
while (block_count != 0) {
diff --git a/shared-module/memorymonitor/AllocationSize.h b/shared-module/memorymonitor/AllocationSize.h
index 3baab2213..3af1a1a3a 100644
--- a/shared-module/memorymonitor/AllocationSize.h
+++ b/shared-module/memorymonitor/AllocationSize.h
@@ -40,8 +40,8 @@ typedef struct _memorymonitor_allocationsize_obj_t {
mp_obj_base_t base;
uint16_t buckets[ALLOCATION_SIZE_BUCKETS];
// Store the location that points to us so we can remove ourselves.
- memorymonitor_allocationsize_obj_t** previous;
- memorymonitor_allocationsize_obj_t* next;
+ memorymonitor_allocationsize_obj_t **previous;
+ memorymonitor_allocationsize_obj_t *next;
bool paused;
} memorymonitor_allocationsize_obj_t;
diff --git a/shared-module/msgpack/__init__.c b/shared-module/msgpack/__init__.c
index 103003174..61547fde3 100644
--- a/shared-module/msgpack/__init__.c
+++ b/shared-module/msgpack/__init__.c
@@ -59,7 +59,9 @@ STATIC msgpack_stream_t get_stream(mp_obj_t stream_obj, int flags) {
// readers
STATIC void read(msgpack_stream_t *s, void *buf, mp_uint_t size) {
- if (size == 0) return;
+ if (size == 0) {
+ return;
+ }
mp_uint_t ret = s->read(s->stream_obj, buf, size, &s->errcode);
if (s->errcode != 0) {
mp_raise_OSError(s->errcode);
@@ -82,7 +84,9 @@ STATIC uint16_t read2(msgpack_stream_t *s) {
uint16_t res = 0;
read(s, &res, 2);
int n = 1;
- if (*(char *)&n == 1) res = __builtin_bswap16(res);
+ if (*(char *)&n == 1) {
+ res = __builtin_bswap16(res);
+ }
return res;
}
@@ -90,16 +94,24 @@ STATIC uint32_t read4(msgpack_stream_t *s) {
uint32_t res = 0;
read(s, &res, 4);
int n = 1;
- if (*(char *)&n == 1) res = __builtin_bswap32(res);
+ if (*(char *)&n == 1) {
+ res = __builtin_bswap32(res);
+ }
return res;
}
STATIC size_t read_size(msgpack_stream_t *s, uint8_t len_index) {
size_t res = 0;
switch (len_index) {
- case 0: res = (size_t)read1(s); break;
- case 1: res = (size_t)read2(s); break;
- case 2: res = (size_t)read4(s); break;
+ case 0:
+ res = (size_t)read1(s);
+ break;
+ case 1:
+ res = (size_t)read2(s);
+ break;
+ case 2:
+ res = (size_t)read4(s);
+ break;
}
return res;
}
@@ -123,13 +135,17 @@ STATIC void write1(msgpack_stream_t *s, uint8_t obj) {
STATIC void write2(msgpack_stream_t *s, uint16_t obj) {
int n = 1;
- if (*(char *)&n == 1) obj = __builtin_bswap16(obj);
+ if (*(char *)&n == 1) {
+ obj = __builtin_bswap16(obj);
+ }
write(s, &obj, 2);
}
STATIC void write4(msgpack_stream_t *s, uint32_t obj) {
int n = 1;
- if (*(char *)&n == 1) obj = __builtin_bswap32(obj);
+ if (*(char *)&n == 1) {
+ obj = __builtin_bswap32(obj);
+ }
write(s, &obj, 4);
}
@@ -139,10 +155,10 @@ STATIC void write_size(msgpack_stream_t *s, uint8_t code, size_t size) {
write1(s, code);
write1(s, size);
} else if ((uint16_t)size == size) {
- write1(s, code+1);
+ write1(s, code + 1);
write2(s, size);
} else {
- write1(s, code+2);
+ write1(s, code + 2);
write4(s, size);
}
}
@@ -182,12 +198,14 @@ STATIC void pack_int(msgpack_stream_t *s, int32_t x) {
}
}
-STATIC void pack_bin(msgpack_stream_t *s, const uint8_t* data, size_t len) {
+STATIC void pack_bin(msgpack_stream_t *s, const uint8_t *data, size_t len) {
write_size(s, 0xc4, len);
- if (len > 0) write(s, data, len);
+ if (len > 0) {
+ write(s, data, len);
+ }
}
-STATIC void pack_ext(msgpack_stream_t *s, int8_t code, const uint8_t* data, size_t len) {
+STATIC void pack_ext(msgpack_stream_t *s, int8_t code, const uint8_t *data, size_t len) {
if (len == 1) {
write1(s, 0xd4);
} else if (len == 2) {
@@ -202,16 +220,20 @@ STATIC void pack_ext(msgpack_stream_t *s, int8_t code, const uint8_t* data, siz
write_size(s, 0xc7, len);
}
write1(s, code); // type byte
- if (len > 0) write(s, data, len);
+ if (len > 0) {
+ write(s, data, len);
+ }
}
-STATIC void pack_str(msgpack_stream_t *s, const char* str, size_t len) {
+STATIC void pack_str(msgpack_stream_t *s, const char *str, size_t len) {
if (len < 32) {
write1(s, 0b10100000 | (uint8_t)len);
} else {
write_size(s, 0xd9, len);
}
- if (len > 0) write(s, str, len);
+ if (len > 0) {
+ write(s, str, len);
+ }
}
STATIC void pack_array(msgpack_stream_t *s, size_t len) {
@@ -259,14 +281,14 @@ STATIC void pack(mp_obj_t obj, msgpack_stream_t *s, mp_obj_t default_handler) {
// tuple
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(obj);
pack_array(s, self->len);
- for (size_t i=0; i<self->len; i++) {
+ for (size_t i = 0; i < self->len; i++) {
pack(self->items[i], s, default_handler);
}
} else if (MP_OBJ_IS_TYPE(obj, &mp_type_list)) {
// list (layout differs from tuple)
mp_obj_list_t *self = MP_OBJ_TO_PTR(obj);
pack_array(s, self->len);
- for (size_t i=0; i<self->len; i++) {
+ for (size_t i = 0; i < self->len; i++) {
pack(self->items[i], s, default_handler);
}
} else if (MP_OBJ_IS_TYPE(obj, &mp_type_dict)) {
@@ -280,7 +302,9 @@ STATIC void pack(mp_obj_t obj, msgpack_stream_t *s, mp_obj_t default_handler) {
pack(next->value, s, default_handler);
}
} else if (mp_obj_is_float(obj)) {
- union Float { mp_float_t f; uint32_t u; };
+ union Float { mp_float_t f;
+ uint32_t u;
+ };
union Float data;
data.f = mp_obj_float_get(obj);
write1(s, 0xca);
@@ -314,13 +338,13 @@ STATIC mp_obj_t unpack(msgpack_stream_t *s, mp_obj_t ext_hook, bool use_list);
STATIC mp_obj_t unpack_array_elements(msgpack_stream_t *s, size_t size, mp_obj_t ext_hook, bool use_list) {
if (use_list) {
mp_obj_list_t *t = MP_OBJ_TO_PTR(mp_obj_new_list(size, NULL));
- for (size_t i=0; i<size; i++) {
+ for (size_t i = 0; i < size; i++) {
t->items[i] = unpack(s, ext_hook, use_list);
}
return MP_OBJ_FROM_PTR(t);
} else {
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(size, NULL));
- for (size_t i=0; i<size; i++) {
+ for (size_t i = 0; i < size; i++) {
t->items[i] = unpack(s, ext_hook, use_list);
}
return MP_OBJ_FROM_PTR(t);
@@ -330,7 +354,7 @@ STATIC mp_obj_t unpack_array_elements(msgpack_stream_t *s, size_t size, mp_obj_t
STATIC mp_obj_t unpack_bytes(msgpack_stream_t *s, size_t size) {
vstr_t vstr;
vstr_init_len(&vstr, size);
- byte *p = (byte*)vstr.buf;
+ byte *p = (byte *)vstr.buf;
// read in chunks: (some drivers - e.g. UART) limit the
// maximum number of bytes that can be read at once
// read(s, p, size);
@@ -379,20 +403,23 @@ STATIC mp_obj_t unpack(msgpack_stream_t *s, mp_obj_t ext_hook, bool use_list) {
// map (dict)
size_t len = code & 0b1111;
mp_obj_dict_t *d = MP_OBJ_TO_PTR(mp_obj_new_dict(len));
- for (size_t i=0; i<len; i++) {
+ for (size_t i = 0; i < len; i++) {
mp_obj_dict_store(d, unpack(s, ext_hook, use_list), unpack(s, ext_hook, use_list));
}
return MP_OBJ_FROM_PTR(d);
}
switch (code) {
- case 0xc0: return mp_const_none;
- case 0xc2: return mp_const_false;
- case 0xc3: return mp_const_true;
+ case 0xc0:
+ return mp_const_none;
+ case 0xc2:
+ return mp_const_false;
+ case 0xc3:
+ return mp_const_true;
case 0xc4:
case 0xc5:
case 0xc6: {
// bin 8, 16, 32
- return unpack_bytes(s, read_size(s, code-0xc4));
+ return unpack_bytes(s, read_size(s, code - 0xc4));
}
case 0xcc: // uint8
case 0xd0: // int8
@@ -404,7 +431,9 @@ STATIC mp_obj_t unpack(msgpack_stream_t *s, mp_obj_t ext_hook, bool use_list) {
case 0xd2: // int32
return MP_OBJ_NEW_SMALL_INT((int32_t)read4(s));
case 0xca: {
- union Float { mp_float_t f; uint32_t u; };
+ union Float { mp_float_t f;
+ uint32_t u;
+ };
union Float data;
data.u = read4(s);
return mp_obj_new_float(data.f);
@@ -413,10 +442,10 @@ STATIC mp_obj_t unpack(msgpack_stream_t *s, mp_obj_t ext_hook, bool use_list) {
case 0xda:
case 0xdb: {
// str 8, 16, 32
- size_t size = read_size(s, code-0xd9);
+ size_t size = read_size(s, code - 0xd9);
vstr_t vstr;
vstr_init_len(&vstr, size);
- byte *p = (byte*)vstr.buf;
+ byte *p = (byte *)vstr.buf;
read(s, p, size);
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
}
@@ -425,7 +454,7 @@ STATIC mp_obj_t unpack(msgpack_stream_t *s, mp_obj_t ext_hook, bool use_list) {
// map 16 & 32
size_t len = read_size(s, code - 0xde + 1);
mp_obj_dict_t *d = MP_OBJ_TO_PTR(mp_obj_new_dict(len));
- for (size_t i=0; i<len; i++) {
+ for (size_t i = 0; i < len; i++) {
mp_obj_dict_store(d, unpack(s, ext_hook, use_list), unpack(s, ext_hook, use_list));
}
return MP_OBJ_FROM_PTR(d);
@@ -450,7 +479,7 @@ STATIC mp_obj_t unpack(msgpack_stream_t *s, mp_obj_t ext_hook, bool use_list) {
case 0xc8: // ext 16
case 0xc9:
// ext 8, 16, 32
- return unpack_ext(s, read_size(s, code-0xc7), ext_hook);
+ return unpack_ext(s, read_size(s, code - 0xc7), ext_hook);
case 0xc1: // never used
case 0xcb: // float 64
case 0xcf: // uint 64
diff --git a/shared-module/network/__init__.c b/shared-module/network/__init__.c
index a45191d8c..de287b4fc 100644
--- a/shared-module/network/__init__.c
+++ b/shared-module/network/__init__.c
@@ -47,8 +47,10 @@ void network_module_init(void) {
void network_module_deinit(void) {
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
- mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
- if (nic_type->deinit != NULL) nic_type->deinit(nic);
+ mod_network_nic_type_t *nic_type = (mod_network_nic_type_t *)mp_obj_get_type(nic);
+ if (nic_type->deinit != NULL) {
+ nic_type->deinit(nic);
+ }
}
mp_obj_list_set_len(&MP_STATE_PORT(mod_network_nic_list), 0);
}
@@ -56,13 +58,17 @@ void network_module_deinit(void) {
void network_module_background(void) {
static uint32_t next_tick = 0;
uint32_t this_tick = supervisor_ticks_ms32();
- if (this_tick < next_tick) return;
+ if (this_tick < next_tick) {
+ return;
+ }
next_tick = this_tick + 1000;
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
- mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
- if (nic_type->timer_tick != NULL) nic_type->timer_tick(nic);
+ mod_network_nic_type_t *nic_type = (mod_network_nic_type_t *)mp_obj_get_type(nic);
+ if (nic_type->timer_tick != NULL) {
+ nic_type->timer_tick(nic);
+ }
}
}
@@ -82,7 +88,7 @@ mp_obj_t network_module_find_nic(const uint8_t *ip) {
for (mp_uint_t i = 0; i < MP_STATE_PORT(mod_network_nic_list).len; i++) {
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
// TODO check IP suitability here
- //mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
+ // mod_network_nic_type_t *nic_type = (mod_network_nic_type_t*)mp_obj_get_type(nic);
return nic;
}
diff --git a/shared-module/os/__init__.c b/shared-module/os/__init__.c
index 159b54e31..89c795267 100644
--- a/shared-module/os/__init__.c
+++ b/shared-module/os/__init__.c
@@ -40,19 +40,19 @@
// as needed. It does not provide uname.
// Version of mp_vfs_lookup_path that takes and returns uPy string objects.
-STATIC mp_vfs_mount_t *lookup_path(const char* path, mp_obj_t *path_out) {
+STATIC mp_vfs_mount_t *lookup_path(const char *path, mp_obj_t *path_out) {
const char *p_out;
*path_out = mp_const_none;
mp_vfs_mount_t *vfs = mp_vfs_lookup_path(path, &p_out);
if (vfs != MP_VFS_NONE && vfs != MP_VFS_ROOT) {
*path_out = mp_obj_new_str_of_type(&mp_type_str,
- (const byte*)p_out, strlen(p_out));
+ (const byte *)p_out, strlen(p_out));
}
return vfs;
}
// Strip off trailing slashes to please underlying libraries
-STATIC mp_vfs_mount_t *lookup_dir_path(const char* path, mp_obj_t *path_out) {
+STATIC mp_vfs_mount_t *lookup_dir_path(const char *path, mp_obj_t *path_out) {
const char *p_out;
*path_out = mp_const_none;
mp_vfs_mount_t *vfs = mp_vfs_lookup_path(path, &p_out);
@@ -61,7 +61,7 @@ STATIC mp_vfs_mount_t *lookup_dir_path(const char* path, mp_obj_t *path_out) {
while (len > 1 && p_out[len - 1] == '/') {
len--;
}
- *path_out = mp_obj_new_str_of_type(&mp_type_str, (const byte*)p_out, len);
+ *path_out = mp_obj_new_str_of_type(&mp_type_str, (const byte *)p_out, len);
}
return vfs;
}
@@ -83,7 +83,7 @@ STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_
return mp_call_method_n_kw(n_args, 0, meth);
}
-void common_hal_os_chdir(const char* path) {
+void common_hal_os_chdir(const char *path) {
mp_obj_t path_out;
mp_vfs_mount_t *vfs = lookup_dir_path(path, &path_out);
MP_STATE_VM(vfs_cur) = vfs;
@@ -107,7 +107,7 @@ mp_obj_t common_hal_os_getcwd(void) {
return mp_vfs_getcwd();
}
-mp_obj_t common_hal_os_listdir(const char* path) {
+mp_obj_t common_hal_os_listdir(const char *path) {
mp_obj_t path_out;
mp_vfs_mount_t *vfs = lookup_dir_path(path, &path_out);
@@ -135,7 +135,7 @@ mp_obj_t common_hal_os_listdir(const char* path) {
return dir_list;
}
-void common_hal_os_mkdir(const char* path) {
+void common_hal_os_mkdir(const char *path) {
mp_obj_t path_out;
mp_vfs_mount_t *vfs = lookup_dir_path(path, &path_out);
if (vfs == MP_VFS_ROOT || (vfs != MP_VFS_NONE && !strcmp(mp_obj_str_get_str(path_out), "/"))) {
@@ -144,13 +144,13 @@ void common_hal_os_mkdir(const char* path) {
mp_vfs_proxy_call(vfs, MP_QSTR_mkdir, 1, &path_out);
}
-void common_hal_os_remove(const char* path) {
+void common_hal_os_remove(const char *path) {
mp_obj_t path_out;
mp_vfs_mount_t *vfs = lookup_path(path, &path_out);
mp_vfs_proxy_call(vfs, MP_QSTR_remove, 1, &path_out);
}
-void common_hal_os_rename(const char* old_path, const char* new_path) {
+void common_hal_os_rename(const char *old_path, const char *new_path) {
mp_obj_t args[2];
mp_vfs_mount_t *old_vfs = lookup_path(old_path, &args[0]);
mp_vfs_mount_t *new_vfs = lookup_path(new_path, &args[1]);
@@ -161,13 +161,13 @@ void common_hal_os_rename(const char* old_path, const char* new_path) {
mp_vfs_proxy_call(old_vfs, MP_QSTR_rename, 2, args);
}
-void common_hal_os_rmdir(const char* path) {
+void common_hal_os_rmdir(const char *path) {
mp_obj_t path_out;
mp_vfs_mount_t *vfs = lookup_dir_path(path, &path_out);
mp_vfs_proxy_call(vfs, MP_QSTR_rmdir, 1, &path_out);
}
-mp_obj_t common_hal_os_stat(const char* path) {
+mp_obj_t common_hal_os_stat(const char *path) {
mp_obj_t path_out;
mp_vfs_mount_t *vfs = lookup_path(path, &path_out);
if (vfs == MP_VFS_ROOT) {
@@ -181,7 +181,7 @@ mp_obj_t common_hal_os_stat(const char* path) {
return mp_vfs_proxy_call(vfs, MP_QSTR_stat, 1, &path_out);
}
-mp_obj_t common_hal_os_statvfs(const char* path) {
+mp_obj_t common_hal_os_statvfs(const char *path) {
mp_obj_t path_out;
mp_vfs_mount_t *vfs = lookup_path(path, &path_out);
if (vfs == MP_VFS_ROOT) {
diff --git a/shared-module/random/__init__.c b/shared-module/random/__init__.c
index 42499bc0a..95ac3bc65 100644
--- a/shared-module/random/__init__.c
+++ b/shared-module/random/__init__.c
@@ -40,20 +40,19 @@
STATIC uint32_t yasmarang_pad = 0xeda4baba, yasmarang_n = 69, yasmarang_d = 233;
STATIC uint8_t yasmarang_dat = 0;
-STATIC uint32_t yasmarang(void)
-{
+STATIC uint32_t yasmarang(void) {
if (yasmarang_pad == 0xeda4baba) {
if (!common_hal_os_urandom((uint8_t *)&yasmarang_pad, sizeof(uint32_t))) {
yasmarang_pad = common_hal_time_monotonic_ms() & 0xffffffff;
}
}
- yasmarang_pad += yasmarang_dat + yasmarang_d * yasmarang_n;
- yasmarang_pad = (yasmarang_pad<<3) + (yasmarang_pad>>29);
- yasmarang_n = yasmarang_pad | 2;
- yasmarang_d ^= (yasmarang_pad<<31) + (yasmarang_pad>>1);
- yasmarang_dat ^= (char) yasmarang_pad ^ (yasmarang_d>>8) ^ 1;
+ yasmarang_pad += yasmarang_dat + yasmarang_d * yasmarang_n;
+ yasmarang_pad = (yasmarang_pad << 3) + (yasmarang_pad >> 29);
+ yasmarang_n = yasmarang_pad | 2;
+ yasmarang_d ^= (yasmarang_pad << 31) + (yasmarang_pad >> 1);
+ yasmarang_dat ^= (char)yasmarang_pad ^ (yasmarang_d >> 8) ^ 1;
- return (yasmarang_pad^(yasmarang_d<<5)^(yasmarang_pad>>18)^(yasmarang_dat<<1));
+ return yasmarang_pad ^ (yasmarang_d << 5) ^ (yasmarang_pad >> 18) ^ (yasmarang_dat << 1);
} /* yasmarang */
// End of Yasmarang
@@ -106,9 +105,11 @@ STATIC mp_float_t yasmarang_float(void) {
union {
mp_float_t f;
#if MP_ENDIANNESS_LITTLE
- struct { mp_float_int_t frc:MP_FLOAT_FRAC_BITS, exp:MP_FLOAT_EXP_BITS, sgn:1; } p;
+ struct { mp_float_int_t frc : MP_FLOAT_FRAC_BITS, exp : MP_FLOAT_EXP_BITS, sgn : 1;
+ } p;
#else
- struct { mp_float_int_t sgn:1, exp:MP_FLOAT_EXP_BITS, frc:MP_FLOAT_FRAC_BITS; } p;
+ struct { mp_float_int_t sgn : 1, exp : MP_FLOAT_EXP_BITS, frc : MP_FLOAT_FRAC_BITS;
+ } p;
#endif
} u;
u.p.sgn = 0;
diff --git a/shared-module/rgbmatrix/RGBMatrix.c b/shared-module/rgbmatrix/RGBMatrix.c
index a688d7fd6..a0dc783b5 100644
--- a/shared-module/rgbmatrix/RGBMatrix.c
+++ b/shared-module/rgbmatrix/RGBMatrix.c
@@ -67,7 +67,7 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
common_hal_rgbmatrix_rgbmatrix_reconstruct(self, framebuffer);
}
-void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self, mp_obj_t framebuffer) {
+void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self, mp_obj_t framebuffer) {
self->paused = 1;
common_hal_rgbmatrix_timer_disable(self->timer);
@@ -80,7 +80,7 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
self->bufinfo.typecode = 'H';
}
// verify that the matrix is big enough
- mp_get_index(mp_obj_get_type(self->framebuffer), self->bufinfo.len, MP_OBJ_NEW_SMALL_INT(self->bufsize-1), false);
+ mp_get_index(mp_obj_get_type(self->framebuffer), self->bufinfo.len, MP_OBJ_NEW_SMALL_INT(self->bufsize - 1), false);
} else {
common_hal_rgbmatrix_free_impl(self->bufinfo.buf);
common_hal_rgbmatrix_free_impl(self->protomatter.rgbPins);
@@ -96,7 +96,7 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
memset(&self->protomatter, 0, sizeof(self->protomatter));
ProtomatterStatus stat = _PM_init(&self->protomatter,
self->width, self->bit_depth,
- self->rgb_count/6, self->rgb_pins,
+ 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->serpentine ? -self->tile : self->tile,
@@ -120,19 +120,19 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
if (stat != PROTOMATTER_OK) {
common_hal_rgbmatrix_rgbmatrix_deinit(self);
switch (stat) {
- case PROTOMATTER_ERR_PINS:
- mp_raise_ValueError(translate("Invalid pin"));
- break;
- case PROTOMATTER_ERR_ARG:
- mp_raise_ValueError(translate("Invalid argument"));
- break;
- case PROTOMATTER_ERR_MALLOC:
- mp_raise_msg(&mp_type_MemoryError, NULL);
- break;
- default:
- mp_raise_msg_varg(&mp_type_RuntimeError,
- translate("Internal error #%d"), (int)stat);
- break;
+ case PROTOMATTER_ERR_PINS:
+ mp_raise_ValueError(translate("Invalid pin"));
+ break;
+ case PROTOMATTER_ERR_ARG:
+ mp_raise_ValueError(translate("Invalid argument"));
+ break;
+ case PROTOMATTER_ERR_MALLOC:
+ mp_raise_msg(&mp_type_MemoryError, NULL);
+ break;
+ default:
+ mp_raise_msg_varg(&mp_type_RuntimeError,
+ translate("Internal error #%d"), (int)stat);
+ break;
}
}
@@ -147,12 +147,12 @@ STATIC void free_pin(uint8_t *pin) {
}
STATIC void free_pin_seq(uint8_t *seq, int count) {
- for (int i=0; i<count; i++) {
+ for (int i = 0; i < count; i++) {
free_pin(&seq[i]);
}
}
-void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
+void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t *self) {
if (self->timer) {
common_hal_rgbmatrix_timer_free(self->timer);
self->timer = 0;
@@ -183,11 +183,11 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
self->framebuffer = NULL;
}
-void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t* self) {
+void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t *self) {
gc_collect_ptr(self->framebuffer);
}
-void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t* self, bool paused) {
+void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t *self, bool paused) {
if (paused && !self->paused) {
_PM_stop(&self->protomatter);
} else if (!paused && self->paused) {
@@ -198,22 +198,22 @@ void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t* self,
self->paused = paused;
}
-bool common_hal_rgbmatrix_rgbmatrix_get_paused(rgbmatrix_rgbmatrix_obj_t* self) {
+bool common_hal_rgbmatrix_rgbmatrix_get_paused(rgbmatrix_rgbmatrix_obj_t *self) {
return self->paused;
}
-void common_hal_rgbmatrix_rgbmatrix_refresh(rgbmatrix_rgbmatrix_obj_t* self) {
+void common_hal_rgbmatrix_rgbmatrix_refresh(rgbmatrix_rgbmatrix_obj_t *self) {
if (!self->paused) {
_PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
_PM_swapbuffer_maybe(&self->protomatter);
}
}
-int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t* self) {
+int common_hal_rgbmatrix_rgbmatrix_get_width(rgbmatrix_rgbmatrix_obj_t *self) {
return self->width;
}
-int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
+int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t *self) {
int computed_height = (self->rgb_count / 3) * (1 << (self->addr_count)) * self->tile;
return computed_height;
}
diff --git a/shared-module/rgbmatrix/allocator.h b/shared-module/rgbmatrix/allocator.h
index 3431046d5..5c11ad52a 100644
--- a/shared-module/rgbmatrix/allocator.h
+++ b/shared-module/rgbmatrix/allocator.h
@@ -32,6 +32,6 @@
#include "supervisor/memory.h"
#define _PM_allocate common_hal_rgbmatrix_allocator_impl
-#define _PM_free(x) (common_hal_rgbmatrix_free_impl((x)), (x)=NULL, (void)0)
+#define _PM_free(x) (common_hal_rgbmatrix_free_impl((x)), (x) = NULL, (void)0)
extern void *common_hal_rgbmatrix_allocator_impl(size_t sz);
extern void common_hal_rgbmatrix_free_impl(void *);
diff --git a/shared-module/sdcardio/SDCard.c b/shared-module/sdcardio/SDCard.c
index 1712f58ee..c3263fa0d 100644
--- a/shared-module/sdcardio/SDCard.c
+++ b/shared-module/sdcardio/SDCard.c
@@ -35,15 +35,15 @@
#include "py/mperrno.h"
#if 0
-#define DEBUG_PRINT(...) ((void)mp_printf(&mp_plat_print, ## __VA_ARGS__))
+#define DEBUG_PRINT(...) ((void)mp_printf(&mp_plat_print,##__VA_ARGS__))
#else
#define DEBUG_PRINT(...) ((void)0)
#endif
#define CMD_TIMEOUT (200)
-#define R1_IDLE_STATE (1<<0)
-#define R1_ILLEGAL_COMMAND (1<<2)
+#define R1_IDLE_STATE (1 << 0)
+#define R1_ILLEGAL_COMMAND (1 << 2)
#define TOKEN_CMD25 (0xFC)
#define TOKEN_STOP_TRAN (0xFD)
@@ -67,7 +67,7 @@ STATIC void lock_bus_or_throw(sdcardio_sdcard_obj_t *self) {
STATIC void clock_card(sdcardio_sdcard_obj_t *self, int bytes) {
uint8_t buf[] = {0xff};
common_hal_digitalio_digitalinout_set_value(&self->cs, true);
- for (int i=0; i<bytes; i++) {
+ for (int i = 0; i < bytes; i++) {
common_hal_busio_spi_write(self->bus, buf, 1);
}
}
@@ -77,7 +77,7 @@ STATIC void extraclock_and_unlock_bus(sdcardio_sdcard_obj_t *self) {
common_hal_busio_spi_unlock(self->bus);
}
-static uint8_t CRC7(const uint8_t* data, uint8_t n) {
+static uint8_t CRC7(const uint8_t *data, uint8_t n) {
uint8_t crc = 0;
for (uint8_t i = 0; i < n; i++) {
uint8_t d = data[i];
@@ -123,7 +123,7 @@ STATIC int cmd(sdcardio_sdcard_obj_t *self, int cmd, int arg, void *response_buf
// Wait for the response (response[7] == 0)
bool response_received = false;
- for (int i=0; i<CMD_TIMEOUT; i++) {
+ for (int i = 0; i < CMD_TIMEOUT; i++) {
common_hal_busio_spi_read(self->bus, cmdbuf, 1, 0xff);
if ((cmdbuf[0] & 0x80) == 0) {
response_received = true;
@@ -141,7 +141,7 @@ STATIC int cmd(sdcardio_sdcard_obj_t *self, int cmd, int arg, void *response_buf
cmdbuf[1] = 0xff;
do {
// Wait for the start block byte
- common_hal_busio_spi_read(self->bus, cmdbuf+1, 1, 0xff);
+ common_hal_busio_spi_read(self->bus, cmdbuf + 1, 1, 0xff);
} while (cmdbuf[1] != 0xfe);
}
@@ -149,7 +149,7 @@ STATIC int cmd(sdcardio_sdcard_obj_t *self, int cmd, int arg, void *response_buf
if (data_block) {
// Read and discard the CRC-CCITT checksum
- common_hal_busio_spi_read(self->bus, cmdbuf+1, 2, 0xff);
+ common_hal_busio_spi_read(self->bus, cmdbuf + 1, 2, 0xff);
}
}
@@ -161,13 +161,13 @@ STATIC int block_cmd(sdcardio_sdcard_obj_t *self, int cmd_, int block, void *res
return cmd(self, cmd_, block * self->cdv, response_buf, response_len, true, true);
}
-STATIC bool cmd_nodata(sdcardio_sdcard_obj_t* self, int cmd, int response) {
+STATIC bool cmd_nodata(sdcardio_sdcard_obj_t *self, int cmd, int response) {
uint8_t cmdbuf[2] = {cmd, 0xff};
common_hal_busio_spi_write(self->bus, cmdbuf, sizeof(cmdbuf));
// Wait for the response (response[7] == response)
- for (int i=0; i<CMD_TIMEOUT; i++) {
+ for (int i = 0; i < CMD_TIMEOUT; i++) {
common_hal_busio_spi_read(self->bus, cmdbuf, 1, 0xff);
if (cmdbuf[0] == response) {
return 0;
@@ -177,7 +177,7 @@ STATIC bool cmd_nodata(sdcardio_sdcard_obj_t* self, int cmd, int response) {
}
STATIC const compressed_string_t *init_card_v1(sdcardio_sdcard_obj_t *self) {
- for (int i=0; i<CMD_TIMEOUT; i++) {
+ for (int i = 0; i < CMD_TIMEOUT; i++) {
if (cmd(self, 41, 0, NULL, 0, true, true) == 0) {
return NULL;
}
@@ -186,7 +186,7 @@ STATIC const compressed_string_t *init_card_v1(sdcardio_sdcard_obj_t *self) {
}
STATIC const compressed_string_t *init_card_v2(sdcardio_sdcard_obj_t *self) {
- for (int i=0; i<CMD_TIMEOUT; i++) {
+ for (int i = 0; i < CMD_TIMEOUT; i++) {
uint8_t ocr[4];
common_hal_time_delay_ms(50);
cmd(self, 58, 0, ocr, sizeof(ocr), false, true);
@@ -210,7 +210,7 @@ STATIC const compressed_string_t *init_card(sdcardio_sdcard_obj_t *self) {
// CMD0: init card: should return _R1_IDLE_STATE (allow 5 attempts)
{
bool reached_idle_state = false;
- for (int i=0; i<5; i++) {
+ for (int i = 0; i < 5; i++) {
if (cmd(self, 0, 0, NULL, 0, true, true) == R1_IDLE_STATE) {
reached_idle_state = true;
break;
@@ -226,12 +226,12 @@ STATIC const compressed_string_t *init_card(sdcardio_sdcard_obj_t *self) {
uint8_t rb7[4];
int response = cmd(self, 8, 0x1AA, rb7, sizeof(rb7), false, true);
if (response == R1_IDLE_STATE) {
- const compressed_string_t *result =init_card_v2(self);
+ const compressed_string_t *result = init_card_v2(self);
if (result != NULL) {
return result;
}
} else if (response == (R1_IDLE_STATE | R1_ILLEGAL_COMMAND)) {
- const compressed_string_t *result =init_card_v1(self);
+ const compressed_string_t *result = init_card_v1(self);
if (result != NULL) {
return result;
}
@@ -399,7 +399,7 @@ STATIC int _write(sdcardio_sdcard_obj_t *self, uint8_t token, void *buf, size_t
// with STATUS 010 indicating "data accepted", and other status bit
// combinations indicating failure.
// In practice, I was seeing cmd[0] as 0xe5, indicating success
- for (int i=0; i<CMD_TIMEOUT; i++) {
+ for (int i = 0; i < CMD_TIMEOUT; i++) {
common_hal_busio_spi_read(self->bus, cmd, 1, 0xff);
DEBUG_PRINT("i=%02d cmd[0] = 0x%02x\n", i, cmd[0]);
if ((cmd[0] & 0b00010001) == 0b00000001) {
diff --git a/shared-module/sharpdisplay/SharpMemoryFramebuffer.c b/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
index 4b92bd637..14f490822 100644
--- a/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
+++ b/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
@@ -40,7 +40,8 @@
STATIC uint8_t bitrev(uint8_t n) {
uint8_t r = 0;
- for(int i=0;i<8;i++) r |= ((n>>i) & 1)<<(7-i);
+ for (int i = 0; i < 8; i++) {r |= ((n >> i) & 1) << (7 - i);
+ }
return r;
}
@@ -70,10 +71,10 @@ bool common_hal_sharpdisplay_framebuffer_get_pixels_in_byte_share_row(sharpdispl
void common_hal_sharpdisplay_framebuffer_reset(sharpdisplay_framebuffer_obj_t *self) {
if (self->bus != &self->inline_bus
-#if BOARD_SPI
+ #if BOARD_SPI
&& self->bus != common_hal_board_get_spi()
-#endif
- ) {
+ #endif
+ ) {
memcpy(&self->inline_bus, self->bus, sizeof(busio_spi_obj_t));
self->bus = &self->inline_bus;
}
@@ -81,7 +82,7 @@ void common_hal_sharpdisplay_framebuffer_reset(sharpdisplay_framebuffer_obj_t *s
void common_hal_sharpdisplay_framebuffer_reconstruct(sharpdisplay_framebuffer_obj_t *self) {
// Look up the allocation by the old pointer and get the new pointer from it.
- supervisor_allocation* alloc = allocation_from_ptr(self->bufinfo.buf);
+ supervisor_allocation *alloc = allocation_from_ptr(self->bufinfo.buf);
self->bufinfo.buf = alloc ? alloc->ptr : NULL;
}
@@ -90,7 +91,7 @@ void common_hal_sharpdisplay_framebuffer_get_bufinfo(sharpdisplay_framebuffer_ob
int row_stride = common_hal_sharpdisplay_framebuffer_get_row_stride(self);
int height = common_hal_sharpdisplay_framebuffer_get_height(self);
self->bufinfo.len = row_stride * height + 2;
- supervisor_allocation* alloc = allocate_memory(align32_size(self->bufinfo.len), false, true);
+ supervisor_allocation *alloc = allocate_memory(align32_size(self->bufinfo.len), false, true);
if (alloc == NULL) {
m_malloc_fail(self->bufinfo.len);
}
@@ -100,8 +101,8 @@ void common_hal_sharpdisplay_framebuffer_get_bufinfo(sharpdisplay_framebuffer_ob
uint8_t *data = self->bufinfo.buf;
*data++ = SHARPMEM_BIT_WRITECMD_LSB;
- for(int y=0; y<height; y++) {
- *data = bitrev(y+1);
+ for (int y = 0; y < height; y++) {
+ *data = bitrev(y + 1);
data += row_stride;
}
self->full_refresh = true;
@@ -160,8 +161,8 @@ void common_hal_sharpdisplay_framebuffer_swapbuffers(sharpdisplay_framebuffer_ob
// output each changed row
size_t row_stride = common_hal_sharpdisplay_framebuffer_get_row_stride(self);
- for(int y=0; y<self->height; y++) {
- if(self->full_refresh || (dirty_row_bitmask[y/8] & (1 << (y & 7)))) {
+ for (int y = 0; y < self->height; y++) {
+ if (self->full_refresh || (dirty_row_bitmask[y / 8] & (1 << (y & 7)))) {
common_hal_busio_spi_write(self->bus, data, row_stride);
}
data += row_stride;
diff --git a/shared-module/sharpdisplay/SharpMemoryFramebuffer.h b/shared-module/sharpdisplay/SharpMemoryFramebuffer.h
index 08966a89c..47e1a373f 100644
--- a/shared-module/sharpdisplay/SharpMemoryFramebuffer.h
+++ b/shared-module/sharpdisplay/SharpMemoryFramebuffer.h
@@ -33,7 +33,7 @@
typedef struct {
mp_obj_base_t base;
- busio_spi_obj_t* bus;
+ busio_spi_obj_t *bus;
busio_spi_obj_t inline_bus;
digitalio_digitalinout_obj_t chip_select;
mp_buffer_info_t bufinfo;
@@ -41,7 +41,7 @@ typedef struct {
uint16_t width, height;
uint32_t baudrate;
- bool full_refresh:1;
+ bool full_refresh : 1;
} sharpdisplay_framebuffer_obj_t;
void common_hal_sharpdisplay_framebuffer_construct(sharpdisplay_framebuffer_obj_t *self, busio_spi_obj_t *spi, mcu_pin_obj_t *chip_select, int baudrate, int width, int height);
@@ -56,4 +56,4 @@ void common_hal_sharpdisplay_framebuffer_reconstruct(sharpdisplay_framebuffer_ob
extern const framebuffer_p_t sharpdisplay_framebuffer_proto;
-void common_hal_sharpdisplay_framebuffer_collect_ptrs(sharpdisplay_framebuffer_obj_t*);
+void common_hal_sharpdisplay_framebuffer_collect_ptrs(sharpdisplay_framebuffer_obj_t *);
diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c
index 5864307fd..db994158d 100644
--- a/shared-module/storage/__init__.c
+++ b/shared-module/storage/__init__.c
@@ -57,7 +57,7 @@ STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_
return mp_call_method_n_kw(n_args, 0, meth);
}
-void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool readonly) {
+void common_hal_storage_mount(mp_obj_t vfs_obj, const char *mount_path, bool readonly) {
// create new object
mp_vfs_mount_t *vfs = m_new_obj(mp_vfs_mount_t);
vfs->str = mount_path;
@@ -94,7 +94,7 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea
}
// call the underlying object to do any mounting operation
- mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t*)&args);
+ mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t *)&args);
// Insert the vfs into the mount table by pushing it onto the front of the
// mount table.
@@ -127,7 +127,7 @@ void common_hal_storage_umount_object(mp_obj_t vfs_obj) {
mp_vfs_proxy_call(vfs, MP_QSTR_umount, 0, NULL);
}
-STATIC mp_obj_t storage_object_from_path(const char* mount_path) {
+STATIC mp_obj_t storage_object_from_path(const char *mount_path) {
for (mp_vfs_mount_t **vfsp = &MP_STATE_VM(vfs_mount_table); *vfsp != NULL; vfsp = &(*vfsp)->next) {
if (strcmp(mount_path, (*vfsp)->str) == 0) {
return (*vfsp)->obj;
@@ -136,7 +136,7 @@ STATIC mp_obj_t storage_object_from_path(const char* mount_path) {
mp_raise_OSError(MP_EINVAL);
}
-void common_hal_storage_umount_path(const char* mount_path) {
+void common_hal_storage_umount_path(const char *mount_path) {
common_hal_storage_umount_object(storage_object_from_path(mount_path));
}
diff --git a/shared-module/struct/__init__.c b/shared-module/struct/__init__.c
index 245dbbda9..7a7ea845e 100644
--- a/shared-module/struct/__init__.c
+++ b/shared-module/struct/__init__.c
@@ -34,11 +34,11 @@
#include "supervisor/shared/translate.h"
void struct_validate_format(char fmt) {
-#if MICROPY_NONSTANDARD_TYPECODES
- if( fmt == 'S' || fmt == 'O') {
+ #if MICROPY_NONSTANDARD_TYPECODES
+ if (fmt == 'S' || fmt == 'O') {
mp_raise_RuntimeError(translate("'S' and 'O' are not supported format types"));
}
-#endif
+ #endif
}
char get_fmt_type(const char **fmt) {
@@ -119,7 +119,7 @@ mp_uint_t shared_modules_struct_calcsize(mp_obj_t fmt_in) {
return size;
}
-void shared_modules_struct_pack_into(mp_obj_t fmt_in, byte *p, byte* end_p, size_t n_args, const mp_obj_t *args) {
+void shared_modules_struct_pack_into(mp_obj_t fmt_in, byte *p, byte *end_p, size_t n_args, const mp_obj_t *args) {
const char *fmt = mp_obj_str_get_str(fmt_in);
char fmt_type = get_fmt_type(&fmt);
const mp_uint_t total_sz = shared_modules_struct_calcsize(fmt_in);
@@ -164,50 +164,50 @@ void shared_modules_struct_pack_into(mp_obj_t fmt_in, byte *p, byte* end_p, size
}
}
-mp_obj_tuple_t * shared_modules_struct_unpack_from(mp_obj_t fmt_in, byte *p, byte *end_p, bool exact_size) {
-
- const char *fmt = mp_obj_str_get_str(fmt_in);
- char fmt_type = get_fmt_type(&fmt);
- const mp_uint_t num_items = calcsize_items(fmt);
- const mp_uint_t total_sz = shared_modules_struct_calcsize(fmt_in);
- mp_obj_tuple_t *res = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_items, NULL));
-
- // If exact_size, make sure the buffer is exactly the right size.
- // Otherwise just make sure it's big enough.
- if (exact_size) {
- if (p + total_sz != end_p) {
- mp_raise_RuntimeError(translate("buffer size must match format"));
- }
- } else {
- if (p + total_sz > end_p) {
- mp_raise_RuntimeError(translate("buffer too small"));
- }
- }
-
- for (uint i = 0; i < num_items;) {
- mp_uint_t sz = 1;
-
- struct_validate_format(*fmt);
-
- if (unichar_isdigit(*fmt)) {
- sz = get_fmt_num(&fmt);
- }
- mp_obj_t item;
- if (*fmt == 's') {
- item = mp_obj_new_bytes(p, sz);
- p += sz;
- res->items[i++] = item;
- } else {
- while (sz--) {
- item = mp_binary_get_val(fmt_type, *fmt, &p);
- // Pad bytes are not stored.
- if (*fmt != 'x') {
- res->items[i++] = item;
- }
- }
- }
- fmt++;
- }
- return res;
+mp_obj_tuple_t *shared_modules_struct_unpack_from(mp_obj_t fmt_in, byte *p, byte *end_p, bool exact_size) {
+
+ const char *fmt = mp_obj_str_get_str(fmt_in);
+ char fmt_type = get_fmt_type(&fmt);
+ const mp_uint_t num_items = calcsize_items(fmt);
+ const mp_uint_t total_sz = shared_modules_struct_calcsize(fmt_in);
+ mp_obj_tuple_t *res = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_items, NULL));
+
+ // If exact_size, make sure the buffer is exactly the right size.
+ // Otherwise just make sure it's big enough.
+ if (exact_size) {
+ if (p + total_sz != end_p) {
+ mp_raise_RuntimeError(translate("buffer size must match format"));
+ }
+ } else {
+ if (p + total_sz > end_p) {
+ mp_raise_RuntimeError(translate("buffer too small"));
+ }
+ }
+
+ for (uint i = 0; i < num_items;) {
+ mp_uint_t sz = 1;
+
+ struct_validate_format(*fmt);
+
+ if (unichar_isdigit(*fmt)) {
+ sz = get_fmt_num(&fmt);
+ }
+ mp_obj_t item;
+ if (*fmt == 's') {
+ item = mp_obj_new_bytes(p, sz);
+ p += sz;
+ res->items[i++] = item;
+ } else {
+ while (sz--) {
+ item = mp_binary_get_val(fmt_type, *fmt, &p);
+ // Pad bytes are not stored.
+ if (*fmt != 'x') {
+ res->items[i++] = item;
+ }
+ }
+ }
+ fmt++;
+ }
+ return res;
}
diff --git a/shared-module/terminalio/Terminal.c b/shared-module/terminalio/Terminal.c
index df92a5dc4..4589c9149 100644
--- a/shared-module/terminalio/Terminal.c
+++ b/shared-module/terminalio/Terminal.c
@@ -29,7 +29,7 @@
#include "shared-module/fontio/BuiltinFont.h"
#include "shared-bindings/displayio/TileGrid.h"
-void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, displayio_tilegrid_t* tilegrid, const fontio_builtinfont_t* font) {
+void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, displayio_tilegrid_t *tilegrid, const fontio_builtinfont_t *font) {
self->cursor_x = 0;
self->cursor_y = 0;
self->font = font;
@@ -46,7 +46,7 @@ void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, d
}
size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, const byte *data, size_t len, int *errcode) {
- const byte* i = data;
+ const byte *i = data;
uint16_t start_y = self->cursor_y;
while (i < data + len) {
unichar c = utf8_get_char(i);
@@ -61,7 +61,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
self->cursor_x = 0;
} else if (c == '\n') {
self->cursor_y++;
- // Commands below are used by MicroPython in the REPL
+ // Commands below are used by MicroPython in the REPL
} else if (c == '\b') {
if (self->cursor_x > 0) {
self->cursor_x--;
diff --git a/shared-module/terminalio/Terminal.h b/shared-module/terminalio/Terminal.h
index c31392cc4..2ba7e21f7 100644
--- a/shared-module/terminalio/Terminal.h
+++ b/shared-module/terminalio/Terminal.h
@@ -36,10 +36,10 @@
typedef struct {
mp_obj_base_t base;
- const fontio_builtinfont_t* font;
+ const fontio_builtinfont_t *font;
uint16_t cursor_x;
uint16_t cursor_y;
- displayio_tilegrid_t* tilegrid;
+ displayio_tilegrid_t *tilegrid;
uint16_t first_row;
} terminalio_terminal_obj_t;
diff --git a/shared-module/touchio/TouchIn.c b/shared-module/touchio/TouchIn.c
index 3fdf3e0ca..840c14571 100644
--- a/shared-module/touchio/TouchIn.c
+++ b/shared-module/touchio/TouchIn.c
@@ -59,15 +59,17 @@ static uint16_t get_raw_reading(touchio_touchin_obj_t *self) {
common_hal_digitalio_digitalinout_switch_to_input(self->digitalinout, PULL_NONE);
- while(common_hal_digitalio_digitalinout_get_value(self->digitalinout)) {
- if (ticks >= TIMEOUT_TICKS) return TIMEOUT_TICKS;
+ while (common_hal_digitalio_digitalinout_get_value(self->digitalinout)) {
+ if (ticks >= TIMEOUT_TICKS) {
+ return TIMEOUT_TICKS;
+ }
ticks++;
}
}
return ticks;
}
-void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self, const mcu_pin_obj_t *pin) {
+void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self, const mcu_pin_obj_t *pin) {
common_hal_mcu_pin_claim(pin);
self->digitalinout = m_new_obj(digitalio_digitalinout_obj_t);
self->digitalinout->base.type = &digitalio_digitalinout_type;
@@ -81,11 +83,11 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self, const mcu
self->threshold = raw_reading * 1.05 + 100;
}
-bool common_hal_touchio_touchin_deinited(touchio_touchin_obj_t* self) {
+bool common_hal_touchio_touchin_deinited(touchio_touchin_obj_t *self) {
return self->digitalinout == MP_OBJ_NULL;
}
-void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) {
+void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t *self) {
if (common_hal_touchio_touchin_deinited(self)) {
return;
}
@@ -111,6 +113,6 @@ uint16_t common_hal_touchio_touchin_get_threshold(touchio_touchin_obj_t *self) {
}
void common_hal_touchio_touchin_set_threshold(touchio_touchin_obj_t *self,
- uint16_t new_threshold) {
+ uint16_t new_threshold) {
self->threshold = new_threshold;
}
diff --git a/shared-module/uheap/__init__.c b/shared-module/uheap/__init__.c
index 5ef15dce4..fd8e31ec0 100644
--- a/shared-module/uheap/__init__.c
+++ b/shared-module/uheap/__init__.c
@@ -40,8 +40,8 @@
#include "shared-bindings/uheap/__init__.h"
#define VERIFY_PTR(ptr) ( \
- (void *) ptr >= (void*)MP_STATE_MEM(gc_pool_start) /* must be above start of pool */ \
- && (void *) ptr < (void*)MP_STATE_MEM(gc_pool_end) /* must be below end of pool */ \
+ (void *)ptr >= (void *)MP_STATE_MEM(gc_pool_start) /* must be above start of pool */ \
+ && (void *)ptr < (void *)MP_STATE_MEM(gc_pool_end) /* must be below end of pool */ \
)
static void indent(uint8_t levels) {
@@ -60,17 +60,17 @@ static uint32_t int_size(uint8_t indent_level, mp_obj_t obj) {
return 0;
}
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ
- mp_obj_int_t* i = MP_OBJ_TO_PTR(obj);
- return gc_nbytes(obj) + gc_nbytes(i->mpz.dig);
+ mp_obj_int_t *i = MP_OBJ_TO_PTR(obj);
+ return gc_nbytes(obj) + gc_nbytes(i->mpz.dig);
#else
- return gc_nbytes(obj);
+ return gc_nbytes(obj);
#endif
}
static uint32_t string_size(uint8_t indent_level, mp_obj_t obj) {
if (MP_OBJ_IS_QSTR(obj)) {
qstr qs = MP_OBJ_QSTR_VALUE(obj);
- const char* s = qstr_str(qs);
+ const char *s = qstr_str(qs);
if (!VERIFY_PTR(s)) {
return 0;
}
@@ -78,7 +78,7 @@ static uint32_t string_size(uint8_t indent_level, mp_obj_t obj) {
mp_printf(&mp_plat_print, "%s\n", s);
return 0;
} else { // MP_OBJ_IS_TYPE(o, &mp_type_str)
- mp_obj_str_t* s = MP_OBJ_TO_PTR(obj);
+ mp_obj_str_t *s = MP_OBJ_TO_PTR(obj);
return gc_nbytes(s) + gc_nbytes(s->data);
}
}
@@ -118,8 +118,8 @@ static uint32_t dict_size(uint8_t indent_level, mp_obj_dict_t *dict) {
}
static uint32_t function_size(uint8_t indent_level, mp_obj_t obj) {
- //indent(indent_level);
- //mp_print_str(&mp_plat_print, "function\n");
+ // indent(indent_level);
+ // mp_print_str(&mp_plat_print, "function\n");
if (MP_OBJ_IS_TYPE(obj, &mp_type_fun_builtin_0)) {
return 0;
} else if (MP_OBJ_IS_TYPE(obj, &mp_type_fun_builtin_1)) {
@@ -131,7 +131,7 @@ static uint32_t function_size(uint8_t indent_level, mp_obj_t obj) {
} else if (MP_OBJ_IS_TYPE(obj, &mp_type_fun_builtin_var)) {
return 0;
} else if (MP_OBJ_IS_TYPE(obj, &mp_type_fun_bc)) {
- mp_obj_fun_bc_t* fn = MP_OBJ_TO_PTR(obj);
+ mp_obj_fun_bc_t *fn = MP_OBJ_TO_PTR(obj);
uint32_t total_size = gc_nbytes(fn) + gc_nbytes(fn->bytecode) + gc_nbytes(fn->const_table);
#if MICROPY_DEBUG_PRINTERS
mp_printf(&mp_plat_print, "BYTECODE START\n");
@@ -180,7 +180,7 @@ static uint32_t type_size(uint8_t indent_level, mp_obj_type_t *type) {
// mp_obj_base_t base;
// qstr name;
- //total_size += string_size(indent_level, MP_OBJ_TO_PTR(type->name));
+ // total_size += string_size(indent_level, MP_OBJ_TO_PTR(type->name));
// mp_print_fun_t print;
// mp_make_new_fun_t make_new; // to make an instance of the type
//
@@ -258,8 +258,8 @@ static uint32_t object_size(uint8_t indent_level, mp_obj_t obj) {
return function_size(indent_level, MP_OBJ_TO_PTR(obj));
}
if (!VERIFY_PTR(obj)) {
- //indent(indent_level);
- //mp_printf(&mp_plat_print, "In ROM\n");
+ // indent(indent_level);
+ // mp_printf(&mp_plat_print, "In ROM\n");
return 0;
}
mp_obj_t type = MP_OBJ_FROM_PTR(mp_obj_get_type(obj));
@@ -274,7 +274,7 @@ static uint32_t object_size(uint8_t indent_level, mp_obj_t obj) {
return array_size(indent_level, MP_OBJ_TO_PTR(obj));
} else if (type == &mp_type_memoryview) {
return memoryview_size(indent_level, MP_OBJ_TO_PTR(obj));
- } else if (MP_OBJ_IS_OBJ(obj) && VERIFY_PTR(type)) {
+ } else if (MP_OBJ_IS_OBJ(obj) && VERIFY_PTR(type)) {
return instance_size(indent_level, MP_OBJ_TO_PTR(obj));
}
diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c
index fe05cb107..3cf80a8b5 100644
--- a/shared-module/usb_cdc/__init__.c
+++ b/shared-module/usb_cdc/__init__.c
@@ -42,8 +42,7 @@ static usb_cdc_serial_obj_t serial_objs[CFG_TUD_CDC] = {
{ .base.type = &usb_cdc_serial_type,
.timeout = -1.0f,
.write_timeout = -1.0f,
- .idx = 0,
- }, {
+ .idx = 0,}, {
.base.type = &usb_cdc_serial_type,
.timeout = -1.0f,
.write_timeout = -1.0f,
diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c
index 2b560c328..4f392847f 100644
--- a/shared-module/usb_hid/Device.c
+++ b/shared-module/usb_hid/Device.c
@@ -41,29 +41,29 @@ uint8_t common_hal_usb_hid_device_get_usage(usb_hid_device_obj_t *self) {
return self->usage;
}
-void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t* report, uint8_t len) {
+void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t *report, uint8_t len) {
if (len != self->report_length) {
mp_raise_ValueError_varg(translate("Buffer incorrect size. Should be %d bytes."), self->report_length);
}
// Wait until interface is ready, timeout = 2 seconds
uint64_t end_ticks = supervisor_ticks_ms64() + 2000;
- while ( (supervisor_ticks_ms64() < end_ticks) && !tud_hid_ready() ) {
+ while ((supervisor_ticks_ms64() < end_ticks) && !tud_hid_ready()) {
RUN_BACKGROUND_TASKS;
}
- if ( !tud_hid_ready() ) {
+ if (!tud_hid_ready()) {
mp_raise_msg(&mp_type_OSError, translate("USB Busy"));
}
memcpy(self->report_buffer, report, len);
- if ( !tud_hid_report(self->report_id, self->report_buffer, len) ) {
+ if (!tud_hid_report(self->report_id, self->report_buffer, len)) {
mp_raise_msg(&mp_type_OSError, translate("USB Error"));
}
}
-static usb_hid_device_obj_t* get_hid_device(uint8_t report_id) {
+static usb_hid_device_obj_t *get_hid_device(uint8_t report_id) {
for (uint8_t i = 0; i < USB_HID_NUM_DEVICES; i++) {
if (usb_hid_devices[i].report_id == report_id) {
return &usb_hid_devices[i];
@@ -73,10 +73,12 @@ static usb_hid_device_obj_t* get_hid_device(uint8_t report_id) {
}
// Callbacks invoked when receive Get_Report request through control endpoint
-uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) {
- (void) itf;
+uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen) {
+ (void)itf;
// only support Input Report
- if ( report_type != HID_REPORT_TYPE_INPUT ) return 0;
+ if (report_type != HID_REPORT_TYPE_INPUT) {
+ return 0;
+ }
// fill buffer with current report
memcpy(buffer, get_hid_device(report_id)->report_buffer, reqlen);
@@ -84,8 +86,8 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t
}
// Callbacks invoked when receive Set_Report request through control endpoint
-void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
- (void) itf;
+void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize) {
+ (void)itf;
if (report_type == HID_REPORT_TYPE_INVALID) {
report_id = buffer[0];
buffer++;
@@ -94,7 +96,7 @@ void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t rep
return;
}
- usb_hid_device_obj_t* hid_device = get_hid_device(report_id);
+ usb_hid_device_obj_t *hid_device = get_hid_device(report_id);
if (hid_device && hid_device->out_report_length >= bufsize) {
memcpy(hid_device->out_report_buffer, buffer, bufsize);
diff --git a/shared-module/usb_hid/Device.h b/shared-module/usb_hid/Device.h
index 93c3518b4..bf4e9d9ad 100644
--- a/shared-module/usb_hid/Device.h
+++ b/shared-module/usb_hid/Device.h
@@ -33,17 +33,17 @@
#include "py/obj.h"
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
typedef struct {
mp_obj_base_t base;
- uint8_t* report_buffer;
+ uint8_t *report_buffer;
uint8_t report_id;
uint8_t report_length;
uint8_t usage_page;
uint8_t usage;
- uint8_t* out_report_buffer;
+ uint8_t *out_report_buffer;
uint8_t out_report_length;
} usb_hid_device_obj_t;
@@ -51,7 +51,7 @@ typedef struct {
extern usb_hid_device_obj_t usb_hid_devices[];
#ifdef __cplusplus
- }
+}
#endif
#endif /* SHARED_MODULE_USB_HID_DEVICE_H */
diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c
index 3fb3f836c..0684112b7 100644
--- a/shared-module/usb_midi/__init__.c
+++ b/shared-module/usb_midi/__init__.c
@@ -36,26 +36,26 @@
#include "supervisor/memory.h"
#include "tusb.h"
-supervisor_allocation* usb_midi_allocation;
+supervisor_allocation *usb_midi_allocation;
void usb_midi_init(void) {
// TODO(tannewt): Make this dynamic.
- size_t tuple_size = align32_size(sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t*) * 2);
+ size_t tuple_size = align32_size(sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t *) * 2);
size_t portin_size = align32_size(sizeof(usb_midi_portin_obj_t));
size_t portout_size = align32_size(sizeof(usb_midi_portout_obj_t));
// For each embedded MIDI Jack in the descriptor we create a Port
usb_midi_allocation = allocate_memory(tuple_size + portin_size + portout_size, false, false);
- mp_obj_tuple_t *ports = (mp_obj_tuple_t *) usb_midi_allocation->ptr;
+ mp_obj_tuple_t *ports = (mp_obj_tuple_t *)usb_midi_allocation->ptr;
ports->base.type = &mp_type_tuple;
ports->len = 2;
- usb_midi_portin_obj_t* in = (usb_midi_portin_obj_t *) (usb_midi_allocation->ptr + tuple_size / 4);
+ usb_midi_portin_obj_t *in = (usb_midi_portin_obj_t *)(usb_midi_allocation->ptr + tuple_size / 4);
in->base.type = &usb_midi_portin_type;
ports->items[0] = MP_OBJ_FROM_PTR(in);
- usb_midi_portout_obj_t* out = (usb_midi_portout_obj_t *) (usb_midi_allocation->ptr + tuple_size / 4 + portin_size / 4);
+ usb_midi_portout_obj_t *out = (usb_midi_portout_obj_t *)(usb_midi_allocation->ptr + tuple_size / 4 + portin_size / 4);
out->base.type = &usb_midi_portout_type;
ports->items[1] = MP_OBJ_FROM_PTR(out);
diff --git a/shared-module/ustack/__init__.c b/shared-module/ustack/__init__.c
index 1e168ad6a..55e5fa2d1 100644
--- a/shared-module/ustack/__init__.c
+++ b/shared-module/ustack/__init__.c
@@ -36,8 +36,9 @@ uint32_t shared_module_ustack_max_stack_usage(void) {
// Start at stack limit and move up.
// Untouched stack was filled with a sentinel value.
// Stop at first non-sentinel byte.
- char* p = MP_STATE_THREAD(stack_bottom);
- while (*p++ == MP_MAX_STACK_USAGE_SENTINEL_BYTE) { }
+ char *p = MP_STATE_THREAD(stack_bottom);
+ while (*p++ == MP_MAX_STACK_USAGE_SENTINEL_BYTE) {
+ }
return MP_STATE_THREAD(stack_top) - p;
}
#endif
@@ -47,5 +48,5 @@ uint32_t shared_module_ustack_stack_size() {
}
uint32_t shared_module_ustack_stack_usage() {
- return mp_stack_usage();
+ return mp_stack_usage();
}
diff --git a/shared-module/vectorio/Circle.c b/shared-module/vectorio/Circle.c
index 73629b8ce..9c7458065 100644
--- a/shared-module/vectorio/Circle.c
+++ b/shared-module/vectorio/Circle.c
@@ -25,10 +25,16 @@ uint32_t common_hal_vectorio_circle_get_pixel(void *obj, int16_t x, int16_t y) {
int16_t radius = abs(self->radius);
x = abs(x);
y = abs(y);
- if (x+y <= radius) return 1;
- if (x > radius) return 0;
- if (y > radius) return 0;
- const bool pythagorasSmallerThanRadius = (int32_t)x*x + (int32_t)y*y <= (int32_t)radius*radius;
+ if (x + y <= radius) {
+ return 1;
+ }
+ if (x > radius) {
+ return 0;
+ }
+ if (y > radius) {
+ return 0;
+ }
+ const bool pythagorasSmallerThanRadius = (int32_t)x * x + (int32_t)y * y <= (int32_t)radius * radius;
return pythagorasSmallerThanRadius ? 1 : 0;
}
diff --git a/shared-module/vectorio/Polygon.c b/shared-module/vectorio/Polygon.c
index e00a4696b..00af1e0d7 100644
--- a/shared-module/vectorio/Polygon.c
+++ b/shared-module/vectorio/Polygon.c
@@ -22,21 +22,21 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
mp_obj_list_get(points_tuple_list, &len, &items);
VECTORIO_POLYGON_DEBUG(" self.len: %d, len: %d, ", self->len, len);
- if ( len < 3 ) {
+ if (len < 3) {
mp_raise_TypeError_varg(translate("Polygon needs at least 3 points"));
}
- if ( self->len < 2*len ) {
- if ( self->points_list != NULL ) {
+ if (self->len < 2 * len) {
+ if (self->points_list != NULL) {
VECTORIO_POLYGON_DEBUG("free(%d), ", sizeof(self->points_list));
- gc_free( self->points_list );
+ gc_free(self->points_list);
}
- self->points_list = gc_alloc( 2 * len * sizeof(int), false, false );
+ self->points_list = gc_alloc(2 * len * sizeof(int), false, false);
VECTORIO_POLYGON_DEBUG("alloc(%p, %d)", self->points_list, 2 * len * sizeof(int));
}
- self->len = 2*len;
+ self->len = 2 * len;
- for ( size_t i = 0; i < len; ++i) {
+ for (size_t i = 0; i < len; ++i) {
size_t tuple_len = 0;
mp_obj_t *tuple_items;
mp_obj_tuple_get(items[i], &tuple_len, &tuple_items);
@@ -44,11 +44,11 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
if (tuple_len != 2) {
mp_raise_ValueError_varg(translate("%q must be a tuple of length 2"), MP_QSTR_point);
}
- if ( !mp_obj_get_int_maybe(tuple_items[ 0 ], &self->points_list[2*i ])
- || !mp_obj_get_int_maybe(tuple_items[ 1 ], &self->points_list[2*i + 1])
- ) {
+ if (!mp_obj_get_int_maybe(tuple_items[ 0 ], &self->points_list[2 * i ])
+ || !mp_obj_get_int_maybe(tuple_items[ 1 ], &self->points_list[2 * i + 1])
+ ) {
self->len = 0;
- gc_free( self->points_list );
+ gc_free(self->points_list);
self->points_list = NULL;
mp_raise_ValueError_varg(translate("unsupported %q type"), MP_QSTR_point);
}
@@ -62,27 +62,27 @@ void common_hal_vectorio_polygon_construct(vectorio_polygon_t *self, mp_obj_t po
self->points_list = NULL;
self->len = 0;
self->on_dirty.obj = NULL;
- _clobber_points_list( self, points_list );
+ _clobber_points_list(self, points_list);
VECTORIO_POLYGON_DEBUG("\n");
}
mp_obj_t common_hal_vectorio_polygon_get_points(vectorio_polygon_t *self) {
VECTORIO_POLYGON_DEBUG("%p common_hal_vectorio_polygon_get_points {len: %d, points_list: %p}\n", self, self->len, self->points_list);
- mp_obj_t list = mp_obj_new_list(self->len/2, NULL);
+ mp_obj_t list = mp_obj_new_list(self->len / 2, NULL);
for (size_t i = 0; i < self->len; i += 2) {
- mp_obj_t tuple[] = { mp_obj_new_int(self->points_list[i]), mp_obj_new_int(self->points_list[i+1]) };
+ mp_obj_t tuple[] = { mp_obj_new_int(self->points_list[i]), mp_obj_new_int(self->points_list[i + 1]) };
mp_obj_list_append(
list,
mp_obj_new_tuple(2, tuple)
- );
+ );
}
return list;
}
void common_hal_vectorio_polygon_set_points(vectorio_polygon_t *self, mp_obj_t points_list) {
VECTORIO_POLYGON_DEBUG("%p common_hal_vectorio_polygon_set_points: ", self);
- _clobber_points_list( self, points_list );
+ _clobber_points_list(self, points_list);
if (self->on_dirty.obj != NULL) {
self->on_dirty.event(self->on_dirty.obj);
}
@@ -90,7 +90,7 @@ void common_hal_vectorio_polygon_set_points(vectorio_polygon_t *self, mp_obj_t p
}
void common_hal_vectorio_polygon_set_on_dirty(vectorio_polygon_t *self, vectorio_event_t notification) {
- if ( self->on_dirty.obj != NULL ) {
+ if (self->on_dirty.obj != NULL) {
mp_raise_TypeError(translate("polygon can only be registered in one parent"));
}
self->on_dirty = notification;
@@ -104,14 +104,22 @@ void common_hal_vectorio_polygon_get_area(void *polygon, displayio_area_t *area)
area->y1 = SHRT_MAX;
area->x2 = SHRT_MIN;
area->y2 = SHRT_MIN;
- for (size_t i=0; i < self->len; ++i) {
+ for (size_t i = 0; i < self->len; ++i) {
int x = self->points_list[i];
++i;
int y = self->points_list[i];
- if (x <= area->x1) area->x1 = x-1;
- if (y <= area->y1) area->y1 = y-1;
- if (x >= area->x2) area->x2 = x+1;
- if (y >= area->y2) area->y2 = y+1;
+ if (x <= area->x1) {
+ area->x1 = x - 1;
+ }
+ if (y <= area->y1) {
+ area->y1 = y - 1;
+ }
+ if (x >= area->x2) {
+ area->x2 = x + 1;
+ }
+ if (y >= area->y2) {
+ area->y2 = y + 1;
+ }
}
}
@@ -119,9 +127,9 @@ void common_hal_vectorio_polygon_get_area(void *polygon, displayio_area_t *area)
// <0 if the point is to the left of the line vector
// 0 if the point is on the line
// >0 if the point is to the right of the line vector
-__attribute__((always_inline)) static inline int line_side( mp_int_t x1, mp_int_t y1, mp_int_t x2, mp_int_t y2, int16_t px, int16_t py ) {
+__attribute__((always_inline)) static inline int line_side(mp_int_t x1, mp_int_t y1, mp_int_t x2, mp_int_t y2, int16_t px, int16_t py) {
return (px - x1) * (y2 - y1)
- - (py - y1) * (x2 - x1);
+ - (py - y1) * (x2 - x1);
}
@@ -136,19 +144,19 @@ uint32_t common_hal_vectorio_polygon_get_pixel(void *obj, int16_t x, int16_t y)
int winding_number = 0;
int x1 = self->points_list[0];
int y1 = self->points_list[1];
- for (size_t i=2; i <= self->len + 1; ++i) {
+ for (size_t i = 2; i <= self->len + 1; ++i) {
VECTORIO_POLYGON_DEBUG(" {(%3d, %3d),", x1, y1);
int x2 = self->points_list[i % self->len];
++i;
int y2 = self->points_list[i % self->len];
VECTORIO_POLYGON_DEBUG(" (%3d, %3d)}\n", x2, y2);
- if ( y1 <= y ) {
- if ( y2 > y && line_side(x1, y1, x2, y2, x, y) < 0 ) {
+ if (y1 <= y) {
+ if (y2 > y && line_side(x1, y1, x2, y2, x, y) < 0) {
// Wind up, point is to the left of the edge vector
++winding_number;
VECTORIO_POLYGON_DEBUG(" wind:%2d winding_number:%2d\n", 1, winding_number);
}
- } else if ( y2 <= y && line_side(x1, y1, x2, y2, x, y) > 0 ) {
+ } else if (y2 <= y && line_side(x1, y1, x2, y2, x, y) > 0) {
// Wind down, point is to the right of the edge vector
--winding_number;
VECTORIO_POLYGON_DEBUG(" wind:%2d winding_number:%2d\n", -1, winding_number);
diff --git a/shared-module/vectorio/VectorShape.c b/shared-module/vectorio/VectorShape.c
index b5d36339e..c6524af9d 100644
--- a/shared-module/vectorio/VectorShape.c
+++ b/shared-module/vectorio/VectorShape.c
@@ -38,16 +38,16 @@ static void _get_screen_area(vectorio_vector_shape_t *self, displayio_area_t *ou
VECTORIO_SHAPE_DEBUG("%p get_screen_area tform:{x:%d y:%d dx:%d dy:%d scl:%d w:%d h:%d mx:%d my:%d tr:%d}", self,
self->absolute_transform->x, self->absolute_transform->y, self->absolute_transform->dx, self->absolute_transform->dy, self->absolute_transform->scale,
self->absolute_transform->width, self->absolute_transform->height, self->absolute_transform->mirror_x, self->absolute_transform->mirror_y, self->absolute_transform->transpose_xy
- );
+ );
self->ishape.get_area(self->ishape.shape, out_area);
VECTORIO_SHAPE_DEBUG(" in:{(%5d,%5d), (%5d,%5d)}", out_area->x1, out_area->y1, out_area->x2, out_area->y2);
if (self->absolute_transform->transpose_xy) {
int16_t swap = out_area->x1;
out_area->x1 = (out_area->y1 + self->y) * self->absolute_transform->dx + self->absolute_transform->x;
- out_area->y1 = (swap + self->x) * self->absolute_transform->dy + self->absolute_transform->y;
+ out_area->y1 = (swap + self->x) * self->absolute_transform->dy + self->absolute_transform->y;
swap = out_area->x2;
out_area->x2 = (out_area->y2 + self->y) * self->absolute_transform->dx + self->absolute_transform->x;
- out_area->y2 = (swap + self->x) * self->absolute_transform->dy + self->absolute_transform->y;
+ out_area->y2 = (swap + self->x) * self->absolute_transform->dy + self->absolute_transform->y;
} else {
out_area->x1 = (out_area->x1 + self->x) * self->absolute_transform->dx + self->absolute_transform->x;
out_area->y1 = (out_area->y1 + self->y) * self->absolute_transform->dy + self->absolute_transform->y;
@@ -94,8 +94,8 @@ void common_hal_vectorio_vector_shape_set_dirty(void *vector_shape) {
void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self,
- vectorio_ishape_t ishape,
- mp_obj_t pixel_shader, uint16_t x, uint16_t y) {
+ vectorio_ishape_t ishape,
+ mp_obj_t pixel_shader, uint16_t x, uint16_t y) {
VECTORIO_SHAPE_DEBUG("%p vector_shape_construct x:%3d, y:%3d\n", self, x, y);
self->x = x;
self->y = y;
@@ -152,22 +152,22 @@ void common_hal_vectorio_vector_shape_set_pixel_shader(vectorio_vector_shape_t *
}
-bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer) {
+bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displayio_colorspace_t *colorspace, const displayio_area_t *area, uint32_t *mask, uint32_t *buffer) {
// Shape areas are relative to 0,0. This will allow rotation about a known axis.
// The consequence is that the area reported by the shape itself is _relative_ to 0,0.
// To make it relative to the VectorShape position, we must shift it.
// Pixels are drawn on the screen_area (shifted) coordinate space, while pixels are _determined_ from
// the shape_area (unshifted) space.
-#ifdef VECTORIO_PERF
+ #ifdef VECTORIO_PERF
uint64_t start = common_hal_time_monotonic_ns();
uint64_t pixel_time = 0;
-#endif
+ #endif
displayio_area_t overlap;
VECTORIO_SHAPE_DEBUG("%p fill_area dirty:%d fill: {(%5d,%5d), (%5d,%5d)} dirty: {(%5d,%5d), (%5d,%5d)}",
self, self->dirty,
area->x1, area->y1, area->x2, area->y2,
self->ephemeral_dirty_area.x1, self->ephemeral_dirty_area.y1, self->ephemeral_dirty_area.x2, self->ephemeral_dirty_area.y2
- );
+ );
if (!displayio_area_compute_overlap(area, &self->ephemeral_dirty_area, &overlap)) {
VECTORIO_SHAPE_DEBUG(" no overlap\n");
return false;
@@ -194,7 +194,7 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
// Check the mask first to see if the pixel has already been set.
uint32_t pixel_index = mask_start_px + (input_pixel.x - overlap.x1);
uint32_t *mask_doubleword = &(mask[pixel_index / 32]);
- uint8_t mask_bit = pixel_index % 32;
+ uint8_t mask_bit = pixel_index % 32;
VECTORIO_SHAPE_PIXEL_DEBUG("%p pixel_index: %5u mask_bit: %2u", self, pixel_index, mask_bit);
if ((*mask_doubleword & (1u << mask_bit)) != 0) {
VECTORIO_SHAPE_PIXEL_DEBUG(" masked\n");
@@ -213,14 +213,14 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
pixel_to_get_y = (input_pixel.y - self->absolute_transform->dy * self->y - self->absolute_transform->y) / self->absolute_transform->dy;
}
VECTORIO_SHAPE_PIXEL_DEBUG(" get_pixel %p (%3d, %3d) -> ( %3d, %3d )", self->ishape.shape, input_pixel.x, input_pixel.y, pixel_to_get_x, pixel_to_get_y);
-#ifdef VECTORIO_PERF
+ #ifdef VECTORIO_PERF
uint64_t pre_pixel = common_hal_time_monotonic_ns();
-#endif
+ #endif
input_pixel.pixel = self->ishape.get_pixel(self->ishape.shape, pixel_to_get_x, pixel_to_get_y);
-#ifdef VECTORIO_PERF
+ #ifdef VECTORIO_PERF
uint64_t post_pixel = common_hal_time_monotonic_ns();
pixel_time += post_pixel - pre_pixel;
-#endif
+ #endif
VECTORIO_SHAPE_PIXEL_DEBUG(" -> %d", input_pixel.pixel);
output_pixel.opaque = true;
@@ -238,10 +238,10 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
*mask_doubleword |= 1u << mask_bit;
if (colorspace->depth == 16) {
VECTORIO_SHAPE_PIXEL_DEBUG(" buffer = %04x 16\n", output_pixel.pixel);
- *(((uint16_t*) buffer) + pixel_index) = output_pixel.pixel;
+ *(((uint16_t *)buffer) + pixel_index) = output_pixel.pixel;
} else if (colorspace->depth == 8) {
VECTORIO_SHAPE_PIXEL_DEBUG(" buffer = %02x 8\n", output_pixel.pixel);
- *(((uint8_t*) buffer) + pixel_index) = output_pixel.pixel;
+ *(((uint8_t *)buffer) + pixel_index) = output_pixel.pixel;
} else if (colorspace->depth < 8) {
// Reorder the offsets to pack multiple rows into a byte (meaning they share a column).
if (!colorspace->pixels_in_byte_share_row) {
@@ -256,13 +256,13 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
shift = (pixels_per_byte - 1) * colorspace->depth - shift;
}
VECTORIO_SHAPE_PIXEL_DEBUG(" buffer = %2d %d\n", output_pixel.pixel, colorspace->depth);
- ((uint8_t*)buffer)[pixel_index / pixels_per_byte] |= output_pixel.pixel << shift;
+ ((uint8_t *)buffer)[pixel_index / pixels_per_byte] |= output_pixel.pixel << shift;
}
}
}
mask_start_px += linestride_px - column_dirty_offset_px;
}
-#ifdef VECTORIO_PERF
+ #ifdef VECTORIO_PERF
uint64_t end = common_hal_time_monotonic_ns();
uint32_t pixels = (overlap.x2 - overlap.x1) * (overlap.y2 - overlap.y1);
VECTORIO_PERF("draw %16s -> shape:{%4dpx, %4.1fms,%9.1fpps fill} shape_pixels:{%6.1fus total, %4.1fus/px}\n",
@@ -272,15 +272,15 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
(double)(max(1, pixels * (1000000000.0 / (end - start)))),
(double)(pixel_time / 1000.0),
(double)(pixel_time / 1000.0 / pixels)
- );
-#endif
+ );
+ #endif
VECTORIO_SHAPE_DEBUG(" -> pixels:%4d\n");
return full_coverage;
}
void vectorio_vector_shape_finish_refresh(vectorio_vector_shape_t *self) {
- if ( !self->dirty ) {
+ if (!self->dirty) {
return;
}
VECTORIO_SHAPE_DEBUG("%p finish_refresh was:{(%3d,%3d), (%3d,%3d)}\n", self, self->ephemeral_dirty_area.x1, self->ephemeral_dirty_area.y1, self->ephemeral_dirty_area.x2, self->ephemeral_dirty_area.y2);
@@ -299,7 +299,7 @@ void vectorio_vector_shape_finish_refresh(vectorio_vector_shape_t *self) {
// Assembles a singly linked list of dirty areas from all components on the display.
-displayio_area_t* vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t* tail) {
+displayio_area_t *vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t *tail) {
if (self->dirty
|| (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type) && displayio_palette_needs_refresh(self->pixel_shader))
|| (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type) && displayio_colorconverter_needs_refresh(self->pixel_shader))
diff --git a/shared-module/vectorio/VectorShape.h b/shared-module/vectorio/VectorShape.h
index 56eb3d8a5..1896c72d6 100644
--- a/shared-module/vectorio/VectorShape.h
+++ b/shared-module/vectorio/VectorShape.h
@@ -38,7 +38,7 @@ typedef struct {
displayio_area_t ephemeral_dirty_area;
} vectorio_vector_shape_t;
-displayio_area_t* vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t *tail);
+displayio_area_t *vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t *tail);
bool vectorio_vector_shape_get_dirty_area(vectorio_vector_shape_t *self, displayio_area_t *current_dirty_area);
diff --git a/shared-module/wiznet/wiznet5k.c b/shared-module/wiznet/wiznet5k.c
index 8ccb4ff8d..708d2166e 100644
--- a/shared-module/wiznet/wiznet5k.c
+++ b/shared-module/wiznet/wiznet5k.c
@@ -82,7 +82,7 @@ int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uint8_
uint8_t dns_ip[MOD_NETWORK_IPADDR_BUF_SIZE] = {8, 8, 8, 8};
uint8_t *buf = m_new(uint8_t, MAX_DNS_BUF_SIZE);
DNS_init(0, buf);
- mp_int_t ret = DNS_run(dns_ip, (uint8_t*)name, out_ip);
+ mp_int_t ret = DNS_run(dns_ip, (uint8_t *)name, out_ip);
m_del(uint8_t, buf, MAX_DNS_BUF_SIZE);
if (ret == 1) {
// success
@@ -110,9 +110,15 @@ int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) {
}
switch (socket->u_param.type) {
- case MOD_NETWORK_SOCK_STREAM: socket->u_param.type = Sn_MR_TCP; break;
- case MOD_NETWORK_SOCK_DGRAM: socket->u_param.type = Sn_MR_UDP; break;
- default: *_errno = MP_EINVAL; return -1;
+ case MOD_NETWORK_SOCK_STREAM:
+ socket->u_param.type = Sn_MR_TCP;
+ break;
+ case MOD_NETWORK_SOCK_DGRAM:
+ socket->u_param.type = Sn_MR_UDP;
+ break;
+ default:
+ *_errno = MP_EINVAL;
+ return -1;
}
if (socket->u_param.fileno == -1) {
@@ -184,11 +190,11 @@ int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_socket_
socket->u_param.fileno = -1;
int _errno2;
if (wiznet5k_socket_socket(socket, &_errno2) != 0) {
- //printf("(bad resocket %d)\n", _errno2);
+ // printf("(bad resocket %d)\n", _errno2);
} else if (wiznet5k_socket_bind(socket, NULL, *port, &_errno2) != 0) {
- //printf("(bad rebind %d)\n", _errno2);
+ // printf("(bad rebind %d)\n", _errno2);
} else if (wiznet5k_socket_listen(socket, 0, &_errno2) != 0) {
- //printf("(bad relisten %d)\n", _errno2);
+ // printf("(bad relisten %d)\n", _errno2);
}
return 0;
@@ -229,7 +235,7 @@ int wiznet5k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_uint_
mp_uint_t wiznet5k_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) {
MP_THREAD_GIL_EXIT();
- mp_int_t ret = WIZCHIP_EXPORT(send)(socket->u_param.fileno, (byte*)buf, len);
+ mp_int_t ret = WIZCHIP_EXPORT(send)(socket->u_param.fileno, (byte *)buf, len);
MP_THREAD_GIL_ENTER();
// TODO convert Wiz errno's to POSIX ones
@@ -264,7 +270,7 @@ mp_uint_t wiznet5k_socket_sendto(mod_network_socket_obj_t *socket, const byte *b
}
MP_THREAD_GIL_EXIT();
- mp_int_t ret = WIZCHIP_EXPORT(sendto)(socket->u_param.fileno, (byte*)buf, len, ip, port);
+ mp_int_t ret = WIZCHIP_EXPORT(sendto)(socket->u_param.fileno, (byte *)buf, len, ip, port);
MP_THREAD_GIL_ENTER();
if (ret < 0) {
@@ -339,7 +345,9 @@ int wiznet5k_start_dhcp(void) {
if (wiznet5k_obj.dhcp_socket < 0) {
// Set up the socket to listen on UDP 68 before calling DHCP_init
wiznet5k_obj.dhcp_socket = get_available_socket(&wiznet5k_obj);
- if (wiznet5k_obj.dhcp_socket < 0) return MP_EMFILE;
+ if (wiznet5k_obj.dhcp_socket < 0) {
+ return MP_EMFILE;
+ }
WIZCHIP_EXPORT(socket)(wiznet5k_obj.dhcp_socket, MOD_NETWORK_SOCK_DGRAM, DHCP_CLIENT_PORT, 0);
DHCP_init(wiznet5k_obj.dhcp_socket, dhcp_buf);
@@ -382,7 +390,7 @@ void wiznet5k_socket_deinit(mod_network_socket_obj_t *socket) {
mp_obj_t wiznet5k_create(busio_spi_obj_t *spi_in, const mcu_pin_obj_t *cs_in, const mcu_pin_obj_t *rst_in) {
// init the wiznet5k object
- wiznet5k_obj.base.type = (mp_obj_type_t*)&mod_network_nic_type_wiznet5k;
+ wiznet5k_obj.base.type = (mp_obj_type_t *)&mod_network_nic_type_wiznet5k;
wiznet5k_obj.cris_state = 0;
wiznet5k_obj.spi = spi_in;
wiznet5k_obj.socket_used = 0;
@@ -397,12 +405,14 @@ mp_obj_t wiznet5k_create(busio_spi_obj_t *spi_in, const mcu_pin_obj_t *cs_in, co
1, // HIGH POLARITY
1, // SECOND PHASE TRANSITION
8 // 8 BITS
- );
+ );
common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.cs, cs_in);
common_hal_digitalio_digitalinout_switch_to_output(&wiznet5k_obj.cs, 1, DRIVE_MODE_PUSH_PULL);
- if (rst_in) common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.rst, rst_in);
+ if (rst_in) {
+ common_hal_digitalio_digitalinout_construct(&wiznet5k_obj.rst, rst_in);
+ }
wiznet5k_reset();
reg_wizchip_cris_cbfunc(wiz_cris_enter, wiz_cris_exit);
@@ -417,7 +427,7 @@ mp_obj_t wiznet5k_create(busio_spi_obj_t *spi_in, const mcu_pin_obj_t *cs_in, co
.dhcp = NETINFO_DHCP,
};
network_module_create_random_mac_address(netinfo.mac);
- ctlnetwork(CN_SET_NETINFO, (void*)&netinfo);
+ ctlnetwork(CN_SET_NETINFO, (void *)&netinfo);
// seems we need a small delay after init
mp_hal_delay_ms(250);