rotary:[#9] process interrupts and send to master
This commit is contained in:
parent
da50fa4de1
commit
2ed0653056
@ -47,6 +47,11 @@ public:
|
|||||||
return pos->second;
|
return pos->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void inline setDataOf(Event::EventType e, EventRawData data)
|
||||||
|
{
|
||||||
|
events[e] = data;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map <Event::EventType, EventRawData> events;
|
std::map <Event::EventType, EventRawData> events;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -18,9 +18,22 @@ void Master::taskFunction() {
|
|||||||
bool LedState = true;
|
bool LedState = true;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
_qm->receive<Event>(ThreadCommon::QueueManager::master_event_all, &data, portMAX_DELAY);
|
_qm->receive<Event>(ThreadCommon::QueueManager::master_event_all, &data, portMAX_DELAY);
|
||||||
if(data.getDataOf(Event::Rotary) == ThreadCommon::RotaryAction::Idle){
|
switch(data.getDataOf(Event::Rotary))
|
||||||
Board_LED_Set(led, LedState);
|
{
|
||||||
|
case ThreadCommon::RotaryAction::Right:
|
||||||
|
Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState);
|
||||||
|
break;
|
||||||
|
case ThreadCommon::RotaryAction::Left:
|
||||||
|
Board_LED_Set(ThreadCommon::RotaryAction::Left, LedState);
|
||||||
|
break;
|
||||||
|
case ThreadCommon::RotaryAction::Press:
|
||||||
|
Board_LED_Set(ThreadCommon::RotaryAction::Press, LedState);
|
||||||
|
break;
|
||||||
|
case ThreadCommon::RotaryAction::Idle:
|
||||||
|
Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
LedState = !LedState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#include "Rotary.h"
|
#include "Rotary.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
#include "queue.h"
|
||||||
|
|
||||||
|
static QueueHandle_t * p_rotary_isr_q;
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@ -14,18 +17,30 @@ extern "C"
|
|||||||
PIN_INT0_IRQHandler (void)
|
PIN_INT0_IRQHandler (void)
|
||||||
{
|
{
|
||||||
Chip_PININT_ClearIntStatus (LPC_PININT, PININTCH (PIN_INT0_IRQn));
|
Chip_PININT_ClearIntStatus (LPC_PININT, PININTCH (PIN_INT0_IRQn));
|
||||||
|
portBASE_TYPE xHigherPriorityWoken = pdFALSE;
|
||||||
|
uint8_t data = ThreadCommon::RotaryAction::Right;
|
||||||
|
xQueueSendFromISR (*p_rotary_isr_q, &data, &xHigherPriorityWoken);
|
||||||
|
portEND_SWITCHING_ISR(xHigherPriorityWoken);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PIN_INT1_IRQHandler (void)
|
PIN_INT1_IRQHandler (void)
|
||||||
{
|
{
|
||||||
Chip_PININT_ClearIntStatus (LPC_PININT, PININTCH (PIN_INT1_IRQn));
|
Chip_PININT_ClearIntStatus (LPC_PININT, PININTCH (PIN_INT1_IRQn));
|
||||||
|
portBASE_TYPE xHigherPriorityWoken = pdFALSE;
|
||||||
|
uint8_t data = ThreadCommon::RotaryAction::Left;
|
||||||
|
xQueueSendFromISR (*p_rotary_isr_q, &data, &xHigherPriorityWoken);
|
||||||
|
portEND_SWITCHING_ISR(xHigherPriorityWoken);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PIN_INT2_IRQHandler (void)
|
PIN_INT2_IRQHandler (void)
|
||||||
{
|
{
|
||||||
Chip_PININT_ClearIntStatus (LPC_PININT, PININTCH (PIN_INT2_IRQn));
|
Chip_PININT_ClearIntStatus (LPC_PININT, PININTCH (PIN_INT2_IRQn));
|
||||||
|
portBASE_TYPE xHigherPriorityWoken = pdFALSE;
|
||||||
|
uint8_t data = ThreadCommon::RotaryAction::Press;
|
||||||
|
xQueueSendFromISR (*p_rotary_isr_q, &data, &xHigherPriorityWoken);
|
||||||
|
portEND_SWITCHING_ISR(xHigherPriorityWoken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,17 +53,28 @@ Rotary::~Rotary() {}
|
|||||||
|
|
||||||
void Rotary::taskFunction()
|
void Rotary::taskFunction()
|
||||||
{
|
{
|
||||||
Event data(Event::Null, 0);
|
auto action_from_rotary_isr = ThreadCommon::RotaryAction::Idle;
|
||||||
Event* e = new Event(Event::Rotary, ThreadCommon::RotaryAction::Idle);
|
Event * p_e= new Event(Event::EventType::Rotary, action_from_rotary_isr);
|
||||||
_qm->send<Event>(ThreadCommon::QueueManager::master_event_all, e, 10);
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
vTaskDelay(500);
|
xQueueReceive(*p_rotary_isr_q, &action_from_rotary_isr, portMAX_DELAY);
|
||||||
|
p_e->setDataOf(Event::EventType::Rotary, action_from_rotary_isr);
|
||||||
|
_qm->send<Event>(ThreadCommon::QueueManager::master_event_all, p_e, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotary_thread(void* pvParams)
|
void rotary_thread(void* pvParams)
|
||||||
{
|
{
|
||||||
|
// Special case for ISR
|
||||||
|
QueueHandle_t rotary_isr_q = xQueueCreate(15, sizeof(char));
|
||||||
|
p_rotary_isr_q = &rotary_isr_q;
|
||||||
|
|
||||||
Rotary r(static_cast<ThreadCommon::QueueManager*>(pvParams));
|
Rotary r(static_cast<ThreadCommon::QueueManager*>(pvParams));
|
||||||
r.taskFunction();
|
r.taskFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void sendActionAndAssertQueue (uint8_t *data, BaseType_t *const pxHPW)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -20,8 +20,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
Event* message;
|
Event* message;
|
||||||
ThreadCommon::QueueManager* _qm;
|
ThreadCommon::QueueManager* _qm;
|
||||||
DigitalIoPin signal[3] = { { 0, 1, true, true, false, true, PIN_INT0_IRQn},
|
DigitalIoPin signal[3] = { { 0, 1, true, true, false, true, PIN_INT0_IRQn}, //SW1
|
||||||
{ 0, 5, true, false, false, true, PIN_INT1_IRQn},
|
{ 0, 16, true, true, false, true, PIN_INT1_IRQn}, //SW2
|
||||||
{ 1, 8, true, false, false, true, PIN_INT2_IRQn} };
|
{ 1, 8, true, false, false, true, PIN_INT2_IRQn} };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user