summaryrefslogtreecommitdiff
path: root/supervisor/shared
diff options
context:
space:
mode:
authorDan Halbert <halbert@adafruit.com>2019-12-18 12:41:06 -0500
committerGitHub <noreply@github.com>2019-12-18 12:41:06 -0500
commit483a6a9a005906bf86dd4857abfe0f9b1314d3a1 (patch)
tree8f436285d89d69cc3695ae2fcdaa09742cf9d5f5 /supervisor/shared
parent8d4384814a4d15cea297eeb08126740d71e6d4d4 (diff)
parent6265ee0e8ce0bf79f3cd73be4b15dc631a403a8b (diff)
Merge pull request #2407 from dhalbert/4.1.x-increase-cpx-stack-update-frozen4.1.2
4.1.x increase cpx stack update frozen
Diffstat (limited to 'supervisor/shared')
-rw-r--r--supervisor/shared/rgb_led_status.c31
-rw-r--r--supervisor/shared/translate.c20
2 files changed, 36 insertions, 15 deletions
diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c
index 0e69cd2e0..0e9c41394 100644
--- a/supervisor/shared/rgb_led_status.c
+++ b/supervisor/shared/rgb_led_status.c
@@ -39,7 +39,10 @@ static digitalio_digitalinout_obj_t status_neopixel;
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
uint8_t rgb_status_brightness = 255;
-static uint8_t status_apa102_color[12] = {0, 0, 0, 0, 0xff, 0, 0, 0};
+
+#define APA102_BUFFER_LENGTH 12
+static uint8_t status_apa102_color[APA102_BUFFER_LENGTH] = {0, 0, 0, 0, 0xff, 0, 0, 0, 0xff, 0xff, 0xff, 0xff};
+
#ifdef CIRCUITPY_BITBANG_APA102
#include "shared-bindings/bitbangio/SPI.h"
#include "shared-module/bitbangio/types.h"
@@ -104,10 +107,12 @@ void rgb_led_status_init() {
apa102_sck_in_use = false;
#ifdef CIRCUITPY_BITBANG_APA102
shared_module_bitbangio_spi_try_lock(&status_apa102);
- shared_module_bitbangio_spi_configure(&status_apa102, 100000, 0, 1, 8);
+ // Use 1MHz for clock rate. Some APA102's are spec'd 800kHz-1200kHz,
+ // though many can run much faster. bitbang will probably run slower.
+ shared_module_bitbangio_spi_configure(&status_apa102, 1000000, 0, 0, 8);
#else
common_hal_busio_spi_try_lock(&status_apa102);
- common_hal_busio_spi_configure(&status_apa102, 100000, 0, 1, 8);
+ common_hal_busio_spi_configure(&status_apa102, 1000000, 0, 0, 8);
#endif
#endif
@@ -120,7 +125,7 @@ void rgb_led_status_init() {
common_hal_pulseio_pwmout_never_reset(&rgb_status_r);
}
}
-
+
if (common_hal_mcu_pin_is_free(CP_RGB_STATUS_G)) {
pwmout_result_t green_result = common_hal_pulseio_pwmout_construct(&rgb_status_g, CP_RGB_STATUS_G, 0, 50000, false);
@@ -186,9 +191,9 @@ void new_status_color(uint32_t rgb) {
status_apa102_color[7] = (rgb_adjusted >> 16) & 0xff;
#ifdef CIRCUITPY_BITBANG_APA102
- shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, 8);
+ shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);
#else
- common_hal_busio_spi_write(&status_apa102, status_apa102_color, 8);
+ common_hal_busio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);
#endif
#endif
@@ -229,20 +234,20 @@ void temp_status_color(uint32_t rgb) {
if (apa102_mosi_in_use || apa102_sck_in_use) {
return;
}
- uint8_t colors[12] = {0, 0, 0, 0, 0xff, rgb_adjusted & 0xff, (rgb_adjusted >> 8) & 0xff, (rgb_adjusted >> 16) & 0xff, 0x0, 0x0, 0x0, 0x0};
+ uint8_t colors[APA102_BUFFER_LENGTH] = {0, 0, 0, 0, 0xff, rgb_adjusted & 0xff, (rgb_adjusted >> 8) & 0xff, (rgb_adjusted >> 16) & 0xff, 0xff, 0xff, 0xff, 0xff};
#ifdef CIRCUITPY_BITBANG_APA102
- shared_module_bitbangio_spi_write(&status_apa102, colors, 12);
+ shared_module_bitbangio_spi_write(&status_apa102, colors, APA102_BUFFER_LENGTH);
#else
- common_hal_busio_spi_write(&status_apa102, colors, 12);
+ common_hal_busio_spi_write(&status_apa102, colors, APA102_BUFFER_LENGTH);
#endif
#endif
#if defined(CP_RGB_STATUS_LED)
uint8_t red_u8 = (rgb_adjusted >> 16) & 0xFF;
uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF;
uint8_t blue_u8 = rgb_adjusted & 0xFF;
-
+
uint16_t temp_status_color_rgb[3] = {0};
-
+
#if defined(CP_RGB_STATUS_INVERTED_PWM)
temp_status_color_rgb[0] = (1 << 16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8);
temp_status_color_rgb[1] = (1 << 16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8);
@@ -265,9 +270,9 @@ void clear_temp_status() {
#endif
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
#ifdef CIRCUITPY_BITBANG_APA102
- shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, 8);
+ shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);
#else
- common_hal_busio_spi_write(&status_apa102, status_apa102_color, 8);
+ common_hal_busio_spi_write(&status_apa102, status_apa102_color, APA102_BUFFER_LENGTH);
#endif
#endif
#if defined(CP_RGB_STATUS_LED)
diff --git a/supervisor/shared/translate.c b/supervisor/shared/translate.c
index aa5e4517c..187d5ff8a 100644
--- a/supervisor/shared/translate.c
+++ b/supervisor/shared/translate.c
@@ -42,12 +42,28 @@ void serial_write_compressed(const compressed_string_t* compressed) {
serial_write(decompressed);
}
+STATIC int put_utf8(char *buf, int u) {
+ if(u <= 0x7f) {
+ *buf = u;
+ return 1;
+ } else if(u <= 0x07ff) {
+ *buf++ = 0b11000000 | (u >> 6);
+ *buf = 0b10000000 | (u & 0b00111111);
+ return 2;
+ } else { // u <= 0xffff)
+ *buf++ = 0b11000000 | (u >> 12);
+ *buf = 0b10000000 | ((u >> 6) & 0b00111111);
+ *buf = 0b10000000 | (u & 0b00111111);
+ return 3;
+ }
+}
+
char* decompress(const compressed_string_t* compressed, char* decompressed) {
uint8_t this_byte = 0;
uint8_t this_bit = 7;
uint8_t b = compressed->data[this_byte];
// Stop one early because the last byte is always NULL.
- for (uint16_t i = 0; i < compressed->length - 1; i++) {
+ for (uint16_t i = 0; i < compressed->length - 1;) {
uint32_t bits = 0;
uint8_t bit_length = 0;
uint32_t max_code = lengths[0];
@@ -72,7 +88,7 @@ char* decompress(const compressed_string_t* compressed, char* decompressed) {
max_code = (max_code << 1) + lengths[bit_length];
searched_length += lengths[bit_length];
}
- decompressed[i] = values[searched_length + bits - max_code];
+ i += put_utf8(decompressed + i, values[searched_length + bits - max_code]);
}
decompressed[compressed->length-1] = '\0';