Skip to content

Commit bdd9e6b

Browse files
committed
Fixed led matrix
1 parent 09eb58d commit bdd9e6b

File tree

6 files changed

+49
-8
lines changed

6 files changed

+49
-8
lines changed

Inc/common_defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
//#define DEBUG
1313

14-
#define FIRMWARE_VERSION 0x1414 // v1.4.1b4
14+
#define FIRMWARE_VERSION 0x1415 // v1.4.1b5
1515
#define USED_PINS_NUM 30 // constant for BluePill and BlackPill boards
1616
#define MAX_AXIS_NUM 8 // max 8
1717
#define MAX_BUTTONS_NUM 128 // power of 2, max 128

Inc/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
static const dev_config_t init_config =
2020
{
21-
.firmware_version = 0x1414, // do not change
21+
.firmware_version = 0x1415, // do not change
2222

2323
/*
2424
Name of device in devices dispatcher

MDK-ARM/FreeJoy.bin

132 Bytes
Binary file not shown.

MDK-ARM/FreeJoy.uvoptx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@
215215
<WinNumber>1</WinNumber>
216216
<ItemText>pov_pos</ItemText>
217217
</Ww>
218+
<Ww>
219+
<count>13</count>
220+
<WinNumber>1</WinNumber>
221+
<ItemText>shift_registers</ItemText>
222+
</Ww>
218223
</WatchWindow1>
219224
<Tracepoint>
220225
<THDelay>0</THDelay>
@@ -258,6 +263,12 @@
258263
<pszMrulep></pszMrulep>
259264
<pSingCmdsp></pSingCmdsp>
260265
<pMultCmdsp></pMultCmdsp>
266+
<SystemViewers>
267+
<Entry>
268+
<Name>System Viewer\GPIOB</Name>
269+
<WinId>35905</WinId>
270+
</Entry>
271+
</SystemViewers>
261272
<DebugDescription>
262273
<Enable>1</Enable>
263274
<EnableFlashSeq>1</EnableFlashSeq>

Src/leds.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,51 @@ void LED_SetSingle(uint8_t * state_buf, dev_config_t * p_dev_config, uint8_t * p
6262

6363
void LED_SetMatrix(uint8_t * state_buf, dev_config_t * p_dev_config, uint8_t * pos)
6464
{
65+
static int8_t last_row = -1;
66+
static uint8_t last_pos = 0;
67+
int8_t max_row = -1;
68+
6569
for (uint8_t i=0; i<USED_PINS_NUM; i++)
6670
{
71+
// turn off leds
6772
if (p_dev_config->pins[i] == LED_ROW)
73+
{
74+
pin_config[i].port->ODR &= ~pin_config[i].pin;
75+
max_row = i;
76+
for (uint8_t j=0; j<USED_PINS_NUM; j++)
77+
{
78+
if (p_dev_config->pins[j] == LED_COLUMN)
79+
{
80+
pin_config[j].port->ODR |= pin_config[j].pin;
81+
(*pos)++;
82+
}
83+
}
84+
}
85+
}
86+
for (uint8_t i=0; i<USED_PINS_NUM; i++)
87+
{
88+
if (p_dev_config->pins[i] == LED_ROW && (i > last_row || i == max_row))
6889
{
6990
pin_config[i].port->ODR |= pin_config[i].pin;
7091
for (uint8_t j=0; j<USED_PINS_NUM; j++)
7192
{
72-
if (p_dev_config->pins[i] == LED_COLUMN)
93+
if (p_dev_config->pins[j] == LED_COLUMN)
7394
{
74-
leds_state[(*pos)] ? (pin_config[j].port->ODR &= ~pin_config[j].pin) : (pin_config[j].port->ODR |= pin_config[j].pin);
75-
(*pos)++;
95+
if (leds_state[last_pos++] > 0)
96+
{
97+
pin_config[j].port->ODR &= ~pin_config[j].pin;
98+
}
99+
else
100+
{
101+
pin_config[j].port->ODR |= pin_config[j].pin;
102+
}
76103
}
77104
}
78-
pin_config[i].port->ODR &= ~pin_config[i].pin;
105+
if (last_pos >= *pos) last_pos = 0;
106+
(i == max_row) ? (last_row = -1): (last_row = i);
107+
break;
79108
}
109+
80110
}
81111
}
82112

Src/periphery.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,15 @@ void IO_Init (dev_config_t * p_dev_config)
404404
GPIO_InitStructure.GPIO_Pin = pin_config[i].pin;
405405
GPIO_Init(pin_config[i].port, &GPIO_InitStructure);
406406
}
407-
else if (p_dev_config->pins[i] == LED_COLUMN)
407+
else if (p_dev_config->pins[i] == LED_ROW)
408408
{
409409
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
410410
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
411411
GPIO_InitStructure.GPIO_Pin = pin_config[i].pin;
412412
GPIO_Init(pin_config[i].port, &GPIO_InitStructure);
413413
pin_config[i].port->ODR &= ~pin_config[i].pin;
414414
}
415-
else if (p_dev_config->pins[i] == LED_ROW)
415+
else if (p_dev_config->pins[i] == LED_COLUMN)
416416
{
417417
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
418418
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

0 commit comments

Comments
 (0)