I wanted to implement this method for event based reading buttons from this article: https://www.playembedded.org/blog/buttons-stm32/
However, I get the error
Code: Select all
undefined reference to `palEnableLineEvent'
I did set #define HAL_USE_PAL TRUE in halconf.h
I can see the definition of it in C:\ChibiStudio\chibios2111\os\hal\include\hal_pal.h
and I did #include "hal.h" in my source file.
What am I missing? I'm using a STM32F103 if that makes any difference.
Code: Select all
/** this file contains buttons related code */
#include "ch.h"
#include "hal.h"
#include "board.h"
void button_cb(void *arg){
(void)arg;
if(palReadLine(LINE_BUTTON_A) == PAL_HIGH){ // rising edge starts timer
startTimeA = chVTGetSystemTimeX();
}
else { // falling edge reads timer and desides if clicked or long press
if(chVTIsSystemTimeWithinX(startTimeA, startTimeA + TIME_MS2I(LONGPRESSEDMS))){
// short pressed
active.A = CLICKED;
}
else { // long press
active.A = LONGPRESSED;
}
}
if(palReadLine(LINE_BUTTON_B) == PAL_HIGH){ // rising edge starts timer
startTimeB = chVTGetSystemTimeX();
}
else { // falling edge reads timer and desides if clicked or long press
if(chVTIsSystemTimeWithinX(startTimeB, startTimeB + TIME_MS2I(LONGPRESSEDMS))){
// short pressed
active.B = CLICKED;
}
else { // long press
active.B = LONGPRESSED;
}
}
if(palReadLine(LINE_BUTTON_L) == PAL_HIGH){ // rising edge starts timer
startTimeL = chVTGetSystemTimeX();
}
else { // falling edge reads timer and desides if clicked or long press
if(chVTIsSystemTimeWithinX(startTimeL, startTimeL + TIME_MS2I(LONGPRESSEDMS))){
// short pressed
active.L = CLICKED;
}
else { // long press
active.L = LONGPRESSED;
}
}
if(palReadLine(LINE_BUTTON_R) == PAL_HIGH){ // rising edge starts timer
startTimeR = chVTGetSystemTimeX();
}
else { // falling edge reads timer and desides if clicked or long press
if(chVTIsSystemTimeWithinX(startTimeR, startTimeR + TIME_MS2I(LONGPRESSEDMS))){
// short pressed
active.R = CLICKED;
}
else { // long press
active.R = LONGPRESSED;
}
}
if(palReadLine(LINE_BUTTON_ROT) == PAL_HIGH){ // rising edge starts timer
startTimeRot = chVTGetSystemTimeX();
}
else { // falling edge reads timer and desides if clicked or long press
if(chVTIsSystemTimeWithinX(startTimeRot, startTimeRot + TIME_MS2I(LONGPRESSEDMS))){
// short pressed
active.ROT = CLICKED;
}
else { // long press
active.ROT = LONGPRESSED;
}
}
}
/** set up the buttons */
void buttonInit(void){
palEnableLineEvent(LINE_BUTTON_A, PAL_EVENT_MODE_BOTH_EDGES);
palEnableLineEvent(LINE_BUTTON_B, PAL_EVENT_MODE_BOTH_EDGES);
palEnableLineEvent(LINE_BUTTON_L, PAL_EVENT_MODE_BOTH_EDGES);
palEnableLineEvent(LINE_BUTTON_R, PAL_EVENT_MODE_BOTH_EDGES);
palEnableLineEvent(LINE_BUTTON_ROT, PAL_EVENT_MODE_BOTH_EDGES);
palSetLineCallback(LINE_BUTTON_A, button_cb, NULL);
palSetLineCallback(LINE_BUTTON_B, button_cb, NULL);
palSetLineCallback(LINE_BUTTON_L, button_cb, NULL);
palSetLineCallback(LINE_BUTTON_R, button_cb, NULL);
palSetLineCallback(LINE_BUTTON_ROT, button_cb, NULL);
}