Skip to content

Commit

Permalink
Fixed led matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Vostrenkov committed Mar 11, 2020
1 parent 09eb58d commit bdd9e6b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Inc/common_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

//#define DEBUG

#define FIRMWARE_VERSION 0x1414 // v1.4.1b4
#define FIRMWARE_VERSION 0x1415 // v1.4.1b5
#define USED_PINS_NUM 30 // constant for BluePill and BlackPill boards
#define MAX_AXIS_NUM 8 // max 8
#define MAX_BUTTONS_NUM 128 // power of 2, max 128
Expand Down
2 changes: 1 addition & 1 deletion Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

static const dev_config_t init_config =
{
.firmware_version = 0x1414, // do not change
.firmware_version = 0x1415, // do not change

/*
Name of device in devices dispatcher
Expand Down
Binary file modified MDK-ARM/FreeJoy.bin
Binary file not shown.
11 changes: 11 additions & 0 deletions MDK-ARM/FreeJoy.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@
<WinNumber>1</WinNumber>
<ItemText>pov_pos</ItemText>
</Ww>
<Ww>
<count>13</count>
<WinNumber>1</WinNumber>
<ItemText>shift_registers</ItemText>
</Ww>
</WatchWindow1>
<Tracepoint>
<THDelay>0</THDelay>
Expand Down Expand Up @@ -258,6 +263,12 @@
<pszMrulep></pszMrulep>
<pSingCmdsp></pSingCmdsp>
<pMultCmdsp></pMultCmdsp>
<SystemViewers>
<Entry>
<Name>System Viewer\GPIOB</Name>
<WinId>35905</WinId>
</Entry>
</SystemViewers>
<DebugDescription>
<Enable>1</Enable>
<EnableFlashSeq>1</EnableFlashSeq>
Expand Down
38 changes: 34 additions & 4 deletions Src/leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,51 @@ void LED_SetSingle(uint8_t * state_buf, dev_config_t * p_dev_config, uint8_t * p

void LED_SetMatrix(uint8_t * state_buf, dev_config_t * p_dev_config, uint8_t * pos)
{
static int8_t last_row = -1;
static uint8_t last_pos = 0;
int8_t max_row = -1;

for (uint8_t i=0; i<USED_PINS_NUM; i++)
{
// turn off leds
if (p_dev_config->pins[i] == LED_ROW)
{
pin_config[i].port->ODR &= ~pin_config[i].pin;
max_row = i;
for (uint8_t j=0; j<USED_PINS_NUM; j++)
{
if (p_dev_config->pins[j] == LED_COLUMN)
{
pin_config[j].port->ODR |= pin_config[j].pin;
(*pos)++;
}
}
}
}
for (uint8_t i=0; i<USED_PINS_NUM; i++)
{
if (p_dev_config->pins[i] == LED_ROW && (i > last_row || i == max_row))
{
pin_config[i].port->ODR |= pin_config[i].pin;
for (uint8_t j=0; j<USED_PINS_NUM; j++)
{
if (p_dev_config->pins[i] == LED_COLUMN)
if (p_dev_config->pins[j] == LED_COLUMN)
{
leds_state[(*pos)] ? (pin_config[j].port->ODR &= ~pin_config[j].pin) : (pin_config[j].port->ODR |= pin_config[j].pin);
(*pos)++;
if (leds_state[last_pos++] > 0)
{
pin_config[j].port->ODR &= ~pin_config[j].pin;
}
else
{
pin_config[j].port->ODR |= pin_config[j].pin;
}
}
}
pin_config[i].port->ODR &= ~pin_config[i].pin;
if (last_pos >= *pos) last_pos = 0;
(i == max_row) ? (last_row = -1): (last_row = i);
break;
}

}
}

Expand Down
4 changes: 2 additions & 2 deletions Src/periphery.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,15 @@ void IO_Init (dev_config_t * p_dev_config)
GPIO_InitStructure.GPIO_Pin = pin_config[i].pin;
GPIO_Init(pin_config[i].port, &GPIO_InitStructure);
}
else if (p_dev_config->pins[i] == LED_COLUMN)
else if (p_dev_config->pins[i] == LED_ROW)
{
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = pin_config[i].pin;
GPIO_Init(pin_config[i].port, &GPIO_InitStructure);
pin_config[i].port->ODR &= ~pin_config[i].pin;
}
else if (p_dev_config->pins[i] == LED_ROW)
else if (p_dev_config->pins[i] == LED_COLUMN)
{
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
Expand Down

0 comments on commit bdd9e6b

Please sign in to comment.