Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6b5ceac

Browse files
iabdalkaderpillo79
authored andcommitted
matrix: optimize turnLed function.
The main optimization eliminates the double MODER register write when on=true. Previously: MODER &= ~(0xFFFFFF) then MODER |= pin_bits (two writes) Now: MODER = 0 when off, or MODER = pin_bits when on (single write each) Otherwise, the compiler is already doing a pretty good job. Additional improvements: - Remove unused idxToPin() function (was just returning idx) - Remove unused reverse() function - Use direct pin array access and bit shifts for efficiency Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent 33b1a6f commit 6b5ceac

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

‎loader/matrix.inc‎

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,38 +112,25 @@ static const uint8_t pins[][2] = {
112112
};
113113

114114

115-
const int idxToPin(int idx) {
116-
return idx;
117-
}
118-
119115
#define NUM_MATRIX_LEDS 104
120116
static uint8_t __attribute__((aligned)) framebuffer[NUM_MATRIX_LEDS / 8];
121117
static uint8_t __attribute__((aligned)) framebuffer_color[NUM_MATRIX_LEDS];
122118

123-
static voidturnLed(int idx, bool on) {
124-
GPIOF->MODER &= ~(0xFFFFFF);
119+
static bool color = false;
120+
staticuint8_t _max_grayscale_bits = 3;
125121

122+
static void turnLed(int idx, bool on) {
123+
GPIOF->MODER &= 0xF0000000U;
126124
if (on) {
127-
GPIOF->BSRR |= (1 << (idxToPin(pins[idx][0])) | 1 << (idxToPin(pins[idx][1]) + 16));
128-
GPIOF->MODER |= (1 << (idxToPin(pins[idx][0]) * 2) | 1 << (idxToPin(pins[idx][1]) * 2));
125+
uint8_t pin0 = pins[idx][0];
126+
uint8_t pin1 = pins[idx][1];
127+
128+
GPIOF->BSRR |= (1U << pin0) | (1U << (pin1 + 16));
129+
GPIOF->MODER |= (1U << (pin0 << 1)) | (1U << (pin1 << 1));
129130
}
130131
}
131132

132-
static uint32_t reverse(uint32_t x)
133-
{
134-
x = ((x >> 1) & 0x55555555u) | ((x & 0x55555555u) << 1);
135-
x = ((x >> 2) & 0x33333333u) | ((x & 0x33333333u) << 2);
136-
x = ((x >> 4) & 0x0f0f0f0fu) | ((x & 0x0f0f0f0fu) << 4);
137-
x = ((x >> 8) & 0x00ff00ffu) | ((x & 0x00ff00ffu) << 8);
138-
x = ((x >> 16) & 0xffffu) | ((x & 0xffffu) << 16);
139-
return x;
140-
}
141-
142-
static bool color = false;
143-
static uint8_t _max_grayscale_bits = 3;
144-
145-
static void timer_irq_handler_fn(const struct device *counter_dev, void *user_data)
146-
{
133+
static void timer_irq_handler_fn(const struct device *counter_dev, void *user_data) {
147134
static volatile int i_isr = 0;
148135
if (color) {
149136
static volatile int counter = 0;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /