Skip to content

Commit

Permalink
Merge pull request Ft-Available#3 from ChisBread/nosrc_beep
Browse files Browse the repository at this point in the history
无源蜂鸣器+OSD不需要模拟开关
  • Loading branch information
ChisBread authored Oct 25, 2022
2 parents bc4f61f + 270399e commit 1bf6e04
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 33 deletions.
19 changes: 16 additions & 3 deletions Firmware/ESP32/RX5808/main/gui/lvgl_driver/lv_port_disp.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
#include "lcd.h"
#include "capi_video.h"
#include "driver/gpio.h"
#include "hardware/rx5808.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
/*********************
* DEFINES
*********************/
#define DISP_BUF_SIZE (MY_DISP_HOR_RES * MY_DISP_VER_RES)
#define DAC_VIDEO_SWITCH 9
#define DAC_VIDEO_SWITCH 19
#define DAC_VIDEO_PIN 25

lv_color_t lv_disp_buf1[DISP_BUF_SIZE];
lv_color_t lv_disp_buf2[DISP_BUF_SIZE];
//static lv_color_t lv_disp_buf3[240*140];
Expand All @@ -41,14 +46,19 @@ bool get_video_switch(void) {
void IRAM_ATTR video_composite_switch(bool flag) {
g_dac_video_render = flag;
if(g_dac_video_render) {
// 暂停rx5808
RX5808_Pause();
// 注册A/V信号输出
esp32_video_start(0);
refresh_times = 1;
gpio_set_level(DAC_VIDEO_SWITCH, 1);
gpio_set_level(DAC_VIDEO_SWITCH, 0);
return;
}
gpio_set_level(DAC_VIDEO_SWITCH, 0);
gpio_set_level(DAC_VIDEO_SWITCH, 1);
esp32_video_stop();
gpio_reset_pin(DAC_VIDEO_PIN);
gpio_set_direction(DAC_VIDEO_PIN, GPIO_MODE_INPUT);/* */
RX5808_Resume();
}
void video_composite_sync_switch(bool flag) {
g_dac_video_sync = flag;
Expand All @@ -58,6 +68,9 @@ void lv_port_disp_init(void)
/*-------------------------
* Initialize your display
* -----------------------*/
gpio_reset_pin(DAC_VIDEO_SWITCH);
gpio_set_direction(DAC_VIDEO_SWITCH, GPIO_MODE_OUTPUT);/* */
gpio_set_level(DAC_VIDEO_SWITCH, 1);
disp_init();

/*-----------------------------
Expand Down
99 changes: 82 additions & 17 deletions Firmware/ESP32/RX5808/main/hardware/beep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,86 @@
#include "SPI.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/ledc.h"
#include <string.h>

#define Beep_Pin_Num 22

#define Beep_Is_Src 1
uint8_t beep_en=1; //off

bool is_inited = false;
void PWM_Enable() {
if(!is_inited) {
is_inited = true;
/*
* 设置LEDC的定时器的配置
*/
ledc_timer_config_t ledc_timer_ls = {
.duty_resolution = LEDC_TIMER_13_BIT, // 设置分辨率,最大为2^13-1
.freq_hz = 4000, // PWM信号频率
.speed_mode = LEDC_LOW_SPEED_MODE, // 定时器模式(“高速”或“低速”)
.timer_num = LEDC_TIMER_0, // 设置定时器源(0-3)
.clk_cfg = LEDC_AUTO_CLK, // 配置LEDC时钟源(这里是自动选择)
};
// 初始化ledc的定时器配置
ledc_timer_config(&ledc_timer_ls);
/*
* 通过选择为 LEDC 控制器的每个通道准备单独的配置:
* - 控制器的通道号
* - 输出占空比,初始设置为 0
* - LEDC 连接到的 GPIO 编号
* - 速度模式,高或低
* - 为LEDC通道指定定时器
* 注意: 如果不同通道使用一个定时器,那么这些通道的频率和占空比分辨率将相同
*/
ledc_channel_config_t ledc_channel = {
.channel = LEDC_CHANNEL_1,
.duty = 4096,
.gpio_num = Beep_Pin_Num,
.speed_mode = LEDC_LOW_SPEED_MODE,
.hpoint = 0,
.timer_sel = LEDC_TIMER_0
};
// 初始化ledc的通道
ledc_channel_config(&ledc_channel);
} else {
// 设置占空比
ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_TIMER_0, 4096);
ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1);
ledc_timer_resume(LEDC_LOW_SPEED_MODE, LEDC_TIMER_0);
}
}
void PWM_Disable() {
ledc_stop(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0);
ledc_timer_pause(LEDC_LOW_SPEED_MODE, LEDC_TIMER_0);
}
void Beep_Init()
{
gpio_set_direction(Beep_Pin_Num, GPIO_MODE_OUTPUT);

if(beep_en==1)
{
gpio_set_level(Beep_Pin_Num, 1);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(Beep_Pin_Num, 0);
#if Beep_Is_Src == 1
gpio_set_direction(Beep_Pin_Num, GPIO_MODE_OUTPUT);
#endif
if(beep_en==1) {
#if Beep_Is_Src == 1
gpio_set_level(Beep_Pin_Num, 1);
#else
PWM_Enable();
#endif
vTaskDelay(200 / portTICK_PERIOD_MS);
#if Beep_Is_Src == 1
gpio_set_level(Beep_Pin_Num, 0);
#else
PWM_Disable();
#endif
}
}

void beep_set_enable_disable(uint8_t en)
{
if(en)
beep_en=1;
else
beep_en=0;
if(en) {
beep_en=1;
}
else {
beep_en=0;
}
}


Expand All @@ -39,10 +95,19 @@ void beep_on_off(uint8_t on_off)
{
//if(beep_en==0)
// return ;
if(on_off&&beep_en)
gpio_set_level(Beep_Pin_Num, 1);
else
gpio_set_level(Beep_Pin_Num, 0);
if(on_off&&beep_en){
#if Beep_Is_Src == 1
gpio_set_level(Beep_Pin_Num, 1);
#else
PWM_Enable();
#endif
} else {
#if Beep_Is_Src == 1
gpio_set_level(Beep_Pin_Num, 0);
#else
PWM_Disable();
#endif
}
}


Expand Down
3 changes: 2 additions & 1 deletion Firmware/ESP32/RX5808/main/hardware/beep.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

//#define BEEP_5V PBout(8)


void PWM_Enable(void);
void PWM_Disable(void);
void Beep_Init(void);
void beep_on_off(uint8_t on_off);
void beep_set_enable_disable(uint8_t en);
Expand Down
31 changes: 20 additions & 11 deletions Firmware/ESP32/RX5808/main/hardware/rx5808.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ adc1_channel_t adc_dma_chan[]={RX5808_RSSI0_CHAN,RX5808_RSSI1_CHAN,VBAT_ADC_CHAN
#define RX5808_SCLK 18
#define RX5808_MOSI 23
#define RX5808_CS 5
#define RX5808_SWITCH0 4
#define RX5808_SWITCH1 12

// 彻底关断接收机
bool RX5808_Shutdown = false;
uint16_t adc_convert_temp0[32][3];
uint16_t adc_convert_temp1[32][3];
uint16_t adc_converted_value[3]={1024,1024,1024};
Expand Down Expand Up @@ -155,10 +154,18 @@ void RX5808_Init()
5,//任务优先级
NULL//任务句柄
);

}


void RX5808_Pause() {
RX5808_Shutdown = true;
gpio_set_level(RX5808_SWITCH0, 0);
gpio_set_level(RX5808_SWITCH1, 0);
}
void RX5808_Resume() {
RX5808_Shutdown = false;
gpio_set_level(RX5808_SWITCH0, 1);
gpio_set_level(RX5808_SWITCH1, 0);
}
void Soft_SPI_Send_One_Bit(uint8_t bit)
{
gpio_set_level(RX5808_SCLK, 0);
Expand Down Expand Up @@ -314,19 +321,21 @@ void DMA2_Stream0_IRQHandler(void)
adc_converted_value[1]=sum1>>4;
adc_converted_value[2]=adc1_get_raw(VBAT_ADC_CHAN);


if(Rx5808_Signal_Source==1)
{
int sig_src = Rx5808_Signal_Source;
// 关断则都为0
if(RX5808_Shutdown) {
sig_src = 3;
}
if(sig_src==1) {
gpio_set_level(RX5808_SWITCH1, 1);
gpio_set_level(RX5808_SWITCH0, 0);

}
else if(Rx5808_Signal_Source==2)
{
else if(sig_src==2) {
gpio_set_level(RX5808_SWITCH0, 1);
gpio_set_level(RX5808_SWITCH1, 0);
}
else if(Rx5808_Signal_Source==3) {
else if(sig_src==3) {
gpio_set_level(RX5808_SWITCH0, 0);
gpio_set_level(RX5808_SWITCH1, 0);
}
Expand Down
5 changes: 4 additions & 1 deletion Firmware/ESP32/RX5808/main/hardware/rx5808.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <stdint.h>


#define RX5808_SWITCH0 4
#define RX5808_SWITCH1 12
typedef enum
{
rx5808_receiver0=0,
Expand All @@ -16,9 +18,10 @@ extern const uint16_t Rx5808_Freq[6][8];
extern volatile int8_t channel_count;
extern volatile int8_t Chx_count;
extern uint16_t adc_converted_value[3];

void RX5808_RSSI_ADC_Init(void);
void RX5808_Init(void);
void RX5808_Pause(void);
void RX5808_Resume(void);
void Soft_SPI_Send_One_Bit(uint8_t bit);
void Send_Register_Data(uint8_t addr, uint32_t data);
void RX5808_Set_Freq(uint16_t Fre);
Expand Down

0 comments on commit 1bf6e04

Please sign in to comment.