Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accessing inactive union members #2066

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions source/Core/Drivers/OLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "cmsis_os.h"
#include "configuration.h"
#include <OLED.hpp>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -209,21 +210,18 @@ void OLED::drawChar(const uint16_t charCode, const FontStyle fontStyle, const ui
* of the indicator in pixels (0..<16).
*/
void OLED::drawScrollIndicator(uint8_t y, uint8_t height) {
union u_type {
uint32_t whole;
uint8_t strips[4];
} column;

column.whole = (1 << height) - 1; // preload a set of set bits of height
column.whole <<= y; // Shift down by the y value

const uint32_t whole = ((1 << height) - 1) << y; // preload a set of set bits of height
// Shift down by the y value
const uint8_t strips[4] = {static_cast<uint8_t>(whole & 0xff), static_cast<uint8_t>((whole & 0xff00) >> 8 * 1), static_cast<uint8_t>((whole & 0xff0000) >> 8 * 2),
static_cast<uint8_t>((whole & 0xff000000) >> 8 * 3)};
// Draw a one pixel wide bar to the left with a single pixel as
// the scroll indicator.
fillArea(OLED_WIDTH - 1, 0, 1, 8, column.strips[0]);
fillArea(OLED_WIDTH - 1, 8, 1, 8, column.strips[1]);
fillArea(OLED_WIDTH - 1, 0, 1, 8, strips[0]);
fillArea(OLED_WIDTH - 1, 8, 1, 8, strips[1]);
#if OLED_HEIGHT == 32
fillArea(OLED_WIDTH - 1, 16, 1, 8, column.strips[2]);
fillArea(OLED_WIDTH - 1, 24, 1, 8, column.strips[3]);
fillArea(OLED_WIDTH - 1, 16, 1, 8, strips[2]);
fillArea(OLED_WIDTH - 1, 24, 1, 8, strips[3]);

#endif
}
Expand Down