From b3de903a3dfe5f75312b6b8a7555ccabe01a5e6e Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Sat, 2 Jan 2021 16:42:48 -0500 Subject: [PATCH 1/2] Fix broken Lighting Layers when RGBLIGHT_MAX_LAYERS > 16 (#11406) * fix incorrect bit math when RGBLIGHT_MAX_LAYERS > 16 * with 1UL cast is not needed * ...but just casting works and is even more efficient * cformat --- quantum/rgblight.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index db725301cbd..beeef656891 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -628,7 +628,7 @@ void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_set #ifdef RGBLIGHT_LAYERS void rgblight_set_layer_state(uint8_t layer, bool enabled) { - rgblight_layer_mask_t mask = 1 << layer; + rgblight_layer_mask_t mask = (rgblight_layer_mask_t)1 << layer; if (enabled) { rgblight_status.enabled_layer_mask |= mask; } else { @@ -649,7 +649,7 @@ void rgblight_set_layer_state(uint8_t layer, bool enabled) { } bool rgblight_get_layer_state(uint8_t layer) { - rgblight_layer_mask_t mask = 1 << layer; + rgblight_layer_mask_t mask = (rgblight_layer_mask_t)1 << layer; return (rgblight_status.enabled_layer_mask & mask) != 0; } @@ -689,7 +689,7 @@ static uint16_t _blink_timer; void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { rgblight_set_layer_state(layer, true); - _blinked_layer_mask |= 1 << layer; + _blinked_layer_mask |= (rgblight_layer_mask_t)1 << layer; _blink_timer = timer_read(); _blink_duration = duration_ms; } @@ -697,7 +697,7 @@ void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { void rgblight_unblink_layers(void) { if (_blinked_layer_mask != 0 && timer_elapsed(_blink_timer) > _blink_duration) { for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { - if ((_blinked_layer_mask & 1 << layer) != 0) { + if ((_blinked_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0) { rgblight_set_layer_state(layer, false); } } From f3ac792c096c10c9dd5004e6e06aad60710ef599 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 3 Jan 2021 14:53:53 +1100 Subject: [PATCH 2/2] Align ChibiOS spi_master behaviour with AVR (#11404) * Align ChibiOS spi_master behaviour with AVR * Rollback `spi_transmit()` and `spi_receive()` to preserve DMA --- drivers/chibios/spi_master.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/chibios/spi_master.c b/drivers/chibios/spi_master.c index 5aa60742e32..8341b59a532 100644 --- a/drivers/chibios/spi_master.c +++ b/drivers/chibios/spi_master.c @@ -115,11 +115,17 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) { return true; } -spi_status_t spi_write(uint8_t data) { return spi_transmit(&data, 1); } +spi_status_t spi_write(uint8_t data) { + uint8_t rxData; + spiExchange(&SPI_DRIVER, 1, &data, &rxData); + + return rxData; +} spi_status_t spi_read(void) { uint8_t data = 0; - spi_receive(&data, 1); + spiReceive(&SPI_DRIVER, 1, &data); + return data; }