mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-25 22:32:29 +03:00
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
This commit is contained in:
parent
f05ffddbde
commit
9d8c36810e
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -146,8 +146,8 @@ extern TIM_HandleTypeDef htim15;
|
||||
#define LFRFID_TIM htim15
|
||||
#define LFRFID_CH TIM_CHANNEL_1
|
||||
|
||||
#define IRDA_TIM htim2
|
||||
#define IRDA_CH TIM_CHANNEL_4
|
||||
#define IRDA_TX_TIM htim2
|
||||
#define IRDA_TX_CH TIM_CHANNEL_3
|
||||
|
||||
#define NFC_IRQ_Pin RFID_PULL_Pin
|
||||
#define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port
|
||||
|
@ -43,9 +43,9 @@ void hal_pwmn_stop(TIM_HandleTypeDef* tim, uint32_t channel) {
|
||||
}
|
||||
|
||||
void irda_pwm_set(float value, float freq){
|
||||
hal_pwm_set(value, freq, &IRDA_TIM, IRDA_CH);
|
||||
hal_pwm_set(value, freq, &IRDA_TX_TIM, IRDA_TX_CH);
|
||||
}
|
||||
|
||||
void irda_pwm_stop(){
|
||||
hal_pwm_stop(&IRDA_TIM, IRDA_CH);
|
||||
hal_pwm_stop(&IRDA_TX_TIM, IRDA_TX_CH);
|
||||
}
|
5
firmware/targets/f2/api-hal/api-hal-tim.c
Normal file
5
firmware/targets/f2/api-hal/api-hal-tim.c
Normal file
@ -0,0 +1,5 @@
|
||||
#include "cmsis_os.h"
|
||||
#include "api-hal-tim.h"
|
||||
|
||||
void tim_irda_rx_init(void) {
|
||||
}
|
4
firmware/targets/f2/api-hal/api-hal-tim.h
Normal file
4
firmware/targets/f2/api-hal/api-hal-tim.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include "main.h"
|
||||
|
||||
void tim_irda_rx_init(void);
|
@ -4,3 +4,4 @@
|
||||
#include "api-hal-delay.h"
|
||||
#include "api-hal-pwm.h"
|
||||
#include "api-hal-task.h"
|
||||
#include "api-hal-tim.h"
|
||||
|
@ -173,8 +173,15 @@ extern TIM_HandleTypeDef htim16;
|
||||
#define LFRFID_TIM htim1
|
||||
#define LFRFID_CH TIM_CHANNEL_1
|
||||
|
||||
#define IRDA_TIM htim1
|
||||
#define IRDA_CH TIM_CHANNEL_3
|
||||
#define IRDA_TX_TIM htim1
|
||||
#define IRDA_TX_CH TIM_CHANNEL_3
|
||||
|
||||
// only for reference
|
||||
// IRDA RX timer dont exist in F2
|
||||
// and timer need more data to init (NVIC IRQn to set priority)
|
||||
#define IRDA_RX_TIM htim2
|
||||
#define IRDA_RX_FALLING_CH TIM_CHANNEL_1
|
||||
#define IRDA_RX_RISING_CH TIM_CHANNEL_2
|
||||
|
||||
#define NFC_IRQ_Pin RFID_PULL_Pin
|
||||
#define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port
|
||||
|
@ -49,9 +49,9 @@ void hal_pwmn_stop(TIM_HandleTypeDef* tim, uint32_t channel) {
|
||||
}
|
||||
|
||||
void irda_pwm_set(float value, float freq){
|
||||
hal_pwmn_set(value, freq, &IRDA_TIM, IRDA_CH);
|
||||
hal_pwmn_set(value, freq, &IRDA_TX_TIM, IRDA_TX_CH);
|
||||
}
|
||||
|
||||
void irda_pwm_stop(){
|
||||
hal_pwmn_stop(&IRDA_TIM, IRDA_CH);
|
||||
hal_pwmn_stop(&IRDA_TX_TIM, IRDA_TX_CH);
|
||||
}
|
8
firmware/targets/f3/api-hal/api-hal-tim.c
Normal file
8
firmware/targets/f3/api-hal/api-hal-tim.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "cmsis_os.h"
|
||||
#include "api-hal-tim.h"
|
||||
|
||||
void tim_irda_rx_init(void) {
|
||||
HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0);
|
||||
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);
|
||||
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2);
|
||||
}
|
4
firmware/targets/f3/api-hal/api-hal-tim.h
Normal file
4
firmware/targets/f3/api-hal/api-hal-tim.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include "main.h"
|
||||
|
||||
void tim_irda_rx_init(void);
|
@ -4,3 +4,4 @@
|
||||
#include "api-hal-delay.h"
|
||||
#include "api-hal-pwm.h"
|
||||
#include "api-hal-task.h"
|
||||
#include "api-hal-tim.h"
|
||||
|
Loading…
Reference in New Issue
Block a user