Skip to content

Commit

Permalink
More wiegand stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Magura-Witkowski committed Mar 14, 2019
1 parent e5ca262 commit 30e6778
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Core/Inc/logger.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef _LOGGER_H
#define _LOGGER_H

#include "stm32f1xx_hal.h"

#include <inttypes.h>
#include <stdio.h>

#define __LOG__(format, loglevel, ...) printf("%-10"PRIu32" [%s:%d] " format "\n", HAL_GetTick(), __FILE__, __LINE__, ## __VA_ARGS__)
#define __LOG(format, ...) __LOG__(format, "DEBUG", ## __VA_ARGS__)
Expand Down
18 changes: 18 additions & 0 deletions Core/Inc/wiegand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef WIEGAND_H
#define WIEGAND_H

#define WIEGAND_MAX_LENGTH 30
#define WIEGAND_BUFFER_BIT_LENGTH sizeof(wiegand_buffer)*8
#define WIEGAND_TIMEOUT 100

#define WIEGAND_CARD_LENGTH 26
#define WIEGAND_KEYPRESS_LENGTH 6

#define WIEGAND_ENABLED

void canpybara_wiegand_reset(void);

void canpybara_wiegand_pin_pulse_interrupt(int bit);
void canpybara_wiegand_systick_interrupt(void);

#endif
2 changes: 1 addition & 1 deletion Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static void MX_GPIO_Init(void)

/*Configure GPIO pins : IN0_Pin IN1_Pin */
GPIO_InitStruct.Pin = IN0_Pin|IN1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

Expand Down
13 changes: 13 additions & 0 deletions Core/Src/stm32f1xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "logger.h"
#include "gpio.h"
#include "can.h"
#include "wiegand.h"

/* USER CODE END 0 */

Expand Down Expand Up @@ -360,7 +361,19 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
#ifdef WIEGAND_ENABLED
canpybara_wiegand_pin_pulse_interrupt(GPIO_Pin == IN1_Pin ? 1 : 0);
#warning Wiegand enabled: GPIO interrupt will be disabled
#else
canpybara_gpio_interrupt(GPIO_Pin);
#endif
}

void HAL_SYSTICK_Callback(void)
{
#ifdef WIEGAND_ENABLED
canpybara_wiegand_systick_interrupt();
#endif
}

/* USER CODE END 1 */
Expand Down
54 changes: 48 additions & 6 deletions Core/Src/wiegand.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,65 @@
#include <stdint.h>

int wiegand_position;
uint32_t wiegand_buffer;
#include "logger.h"
#include "wiegand.h"

#define WIEGAND_BUFFER_BIT_LENGTH sizeof(wiegand_buffer)*8
unsigned int wiegand_position;
uint32_t wiegand_buffer;
uint32_t wiegand_timeout;

void canpybara_wiegand_reset(void)
{
wiegand_position = 0;
wiegand_buffer = 0;
}

void canpybara_wiegand_process_card(void)
{

}

void canpybara_wiegand_process_keypress(void)
{

}

void canpybara_wiegand_process_scan(void)
{
switch(wiegand_position)
{
case WIEGAND_CARD_LENGTH:
canpybara_wiegand_process_card();
break;
case WIEGAND_KEYPRESS_LENGTH:
canpybara_wiegand_process_keypress();
break;
default:
LOG("Unknown WIEGAND message");
}
}

void canpybara_wiegand_pin_pulse(int bit)
void canpybara_wiegand_pin_pulse_interrupt(int bit)
{
wiegand_buffer |= bit << (WIEGAND_BUFFER_BIT_LENGTH -1 - wiegand_position);
wiegand_position ++;

wiegand_timeout = 0;
}

void canpybara_wiegand_systick_interrupt(void)
{
if(wiegand_timeout > WIEGAND_TIMEOUT)
{
if(wiegand_position)
{
canpybara_wiegand_process_scan();
}
canpybara_wiegand_reset();
}
else
{
wiegand_timeout ++;
}
}


Expand Down Expand Up @@ -67,5 +111,3 @@ uint8_t canpybara_wiegand_is_valid(void)

return 1;
}


1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Core/Src/test.c \
Core/Src/can.c \
Core/Src/gpio.c \
Core/Src/version.c \
Core/Src/wiegand.c \

# ASM sources
ASM_SOURCES = \
Expand Down
6 changes: 4 additions & 2 deletions canpybara.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ PA6.Signal=GPIO_Input
PA9.Locked=true
PA9.Mode=Asynchronous
PA9.Signal=USART1_TX
PB0.GPIOParameters=GPIO_Label
PB0.GPIOParameters=GPIO_Label,GPIO_ModeDefaultEXTI
PB0.GPIO_Label=IN0
PB0.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
PB0.Locked=true
PB0.Signal=GPXTI0
PB1.GPIOParameters=GPIO_Label
PB1.GPIOParameters=GPIO_Label,GPIO_ModeDefaultEXTI
PB1.GPIO_Label=IN1
PB1.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
PB1.Locked=true
PB1.Signal=GPXTI1
PB10.GPIOParameters=GPIO_Label
Expand Down

0 comments on commit 30e6778

Please sign in to comment.