diff options
author | DrZlo13 <who.just.the.doctor@gmail.com> | 2020-11-11 10:36:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-11 10:36:27 +0300 |
commit | 9d8c36810e3d303d48fa794207abd7c606cbed36 (patch) | |
tree | 220d7868d2071f0802150a8560e3e223ca376248 /applications/irda | |
parent | f05ffddbde67a9ff1efd0517d67e4abe3c744b52 (diff) |
IR RX simple app (#218)
* split falling and rising ir rx events
* fix irda
* simple irda rx function for app
* add extern timer
* fix timer num for f2
Diffstat (limited to 'applications/irda')
-rw-r--r-- | applications/irda/irda.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/applications/irda/irda.c b/applications/irda/irda.c index a63d72cb..31a1a7f2 100644 --- a/applications/irda/irda.c +++ b/applications/irda/irda.c @@ -7,12 +7,13 @@ typedef enum { EventTypeTick, EventTypeKey, - EventTypeLed, + EventTypeRX, } EventType; typedef struct { union { InputEvent input; + bool rx_edge; } value; EventType type; } AppEvent; @@ -227,8 +228,11 @@ static void input_callback(InputEvent* input_event, void* ctx) { osMessageQueuePut(event_queue, &event, 0, 0); } +osMessageQueueId_t irda_event_queue; + void irda(void* p) { - osMessageQueueId_t event_queue = osMessageQueueNew(1, sizeof(AppEvent), NULL); + osMessageQueueId_t event_queue = osMessageQueueNew(32, sizeof(AppEvent), NULL); + irda_event_queue = event_queue; State _state; uint8_t mode_count = sizeof(modes) / sizeof(modes[0]); @@ -259,6 +263,19 @@ void irda(void* p) { } gui->add_widget(gui, widget, GuiLayerFullscreen); + // Red LED + // create pin + GpioPin led = led_gpio[0]; + + // TODO open record + GpioPin* led_record = &led; + + // configure pin + gpio_init(led_record, GpioModeOutputOpenDrain); + + // setup irda rx timer + tim_irda_rx_init(); + AppEvent event; while(1) { osStatus_t event_status = osMessageQueueGet(event_queue, &event, NULL, osWaitForever); @@ -287,7 +304,10 @@ void irda(void* p) { } modes[state->mode_id].input(&event, state); + } else if(event.type == EventTypeRX) { + gpio_write(led_record, event.value.rx_edge); } + } else { // event timeout } @@ -295,4 +315,23 @@ void irda(void* p) { release_mutex(&state_mutex, state); widget_update(widget); } +} + +void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef* htim) { + if(htim->Instance == TIM2) { + if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) { + // falling event + AppEvent event; + event.type = EventTypeRX; + event.value.rx_edge = false; + osMessageQueuePut(irda_event_queue, &event, 0, 0); + } else if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) { + // rising event + //uint32_t period_in_us = HAL_TIM_ReadCapturedValue(); + AppEvent event; + event.type = EventTypeRX; + event.value.rx_edge = true; + osMessageQueuePut(irda_event_queue, &event, 0, 0); + } + } }
\ No newline at end of file |