Skip to content

Commit

Permalink
Add debounce timer (which is not used yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArashEM committed Aug 11, 2021
1 parent 65b7136 commit 78a5a45
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions BOX/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__Previews
1 change: 1 addition & 0 deletions FW/Inc/mp3_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void vtask_blink(void* vparameters);
void vtask_hmi(void* vparameters);

void vtimer_backlight(TimerHandle_t xTimer);
void vtimer_debounce(TimerHandle_t xTimer);

/**
* \brief mp3 player command
Expand Down
5 changes: 3 additions & 2 deletions FW/Src/hal_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ extern SemaphoreHandle_t dreq_sem,
sdio_rx_dma_sem;
extern struct controller_qlist* qlist; /* queue list for all tasks */

extern TimerHandle_t bl_tim; /* backlight timer handle */
extern TimerHandle_t bl_tim, /* backlight timer handle */
gpio_tim; /* gpio debouncer */
extern QueueHandle_t hw_queue; /* event and commands from hw */

#if (configUSE_TRACE_FACILITY == 1)
Expand All @@ -44,7 +45,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
portBASE_TYPE taskWoken = pdFALSE;
static uint8_t vol = INIT_VOLUME;
uint32_t event;
static uint32_t event;

#if (configUSE_TRACE_FACILITY == 1)
vTraceStoreISRBegin(exti0_handle);
Expand Down
44 changes: 42 additions & 2 deletions FW/Src/mp3_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
/* Global variable */
SemaphoreHandle_t dreq_sem, /* vs10xx dreq IRQ */
spi_tx_dma_sem; /* spi1_tx DMA compelete */
TimerHandle_t bl_tim; /* backlight timer handle */
TimerHandle_t bl_tim, /* backlight timer handle */
gpio_tim; /* gpio debouncer */
struct controller_qlist* qlist; /* queue list for all tasks */
QueueHandle_t hw_queue; /* event and commands from hw */

Expand All @@ -49,7 +50,7 @@ void vsmp3_init(void *vparameters)
vsmp3_create_tasks(qlist);

/* create queue for HW events */
hw_queue = xQueueCreate(5, sizeof(int));
hw_queue = xQueueCreate(1, sizeof(int));
configASSERT(hw_queue);

/* create backlight timer */
Expand All @@ -61,6 +62,14 @@ void vsmp3_init(void *vparameters)
configASSERT(bl_tim);
xTimerStart(bl_tim, portMAX_DELAY);

/* create gpio debouncer timer*/
gpio_tim = xTimerCreate("gpio",
pdMS_TO_TICKS(150),
pdFALSE,
0,
vtimer_debounce);
configASSERT(gpio_tim);

/* debug */
debug_print("task creation done\r\n");

Expand Down Expand Up @@ -410,4 +419,35 @@ void vtimer_backlight(TimerHandle_t xTimer)
/* when expire, turn off backlight */
HAL_GPIO_WritePin(BL_PWM_GPIO_Port,BL_PWM_Pin, GPIO_PIN_RESET);
}

/**
* \brief: GPIO debounce timer
*/
void vtimer_debounce(TimerHandle_t xTimer)
{
uint32_t gpio_index;
gpio_index = (uint32_t) pvTimerGetTimerID(xTimer);
switch(gpio_index) {
case KEY1_Pin:
if(HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET) {
debug_print("KEY%d pressed\r\n",gpio_index);
}
break;

case KEY2_Pin:
if(HAL_GPIO_ReadPin(KEY2_GPIO_Port, KEY2_Pin) == GPIO_PIN_RESET) {
debug_print("KEY%d pressed\r\n",gpio_index);
}
break;

case KEY3_Pin:
if(HAL_GPIO_ReadPin(KEY3_GPIO_Port, KEY3_Pin) == GPIO_PIN_RESET) {
debug_print("KEY%d pressed\r\n",gpio_index);
}
break;

default:
break;
} /* switch(gpio_index) */
}
/* end of file */

0 comments on commit 78a5a45

Please sign in to comment.