good decode and encode with elf

This commit is contained in:
Yunhorn 2025-02-27 20:55:27 +08:00
parent 71d28cf536
commit 5030d7fa80
7 changed files with 45 additions and 322 deletions

View File

@ -1,5 +1,5 @@
#include "ev1527.h"
volatile uint32_t TIM1_cnt=0;
// 定时周期
//#define TIME_CYCLE 80
#define TIME_CYCLE PERIOD_VALUE
@ -72,6 +72,7 @@ void EV1527_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(DATA_433_GPIO_PORT, &GPIO_InitStruct);
}
#if 0
/**----------------------------------------------------------------------------------------------**
** RF信号解码函数
**433MHz接收到的信号
@ -172,8 +173,9 @@ void RF_Signal_Decode(void)
break;
}
}
#endif
#if 0
#if 1
/**----------------------------------------------------------------------------------------------**
** RF信号解码函数
**433MHz接收到的信号
@ -326,7 +328,7 @@ void Decode_Data(void)
void Execute_Function(void)
{
// 判断解码后的功能字节,并执行相应操作
switch (Received_Buffer[FUNCTION_BYTE_INDEX])
switch (0x0F&Received_Buffer[FUNCTION_BYTE_INDEX])
{
case FUNCTION_1:
// 执行功能1
@ -371,23 +373,6 @@ void Execute_Function(void)
}
}
#if 0
uint8_t RF;
uint8_t decode_ok; //解码成功
uint8_t hh_w,ll_w; //高,低电平宽度
uint8_t ma_x; //接收到第几位编码了
uint8_t bma1,bma2,bma3,bma4; //用于接收过程存放遥控编码,编码比较两次,这是第一次
uint8_t mma1,mma2,mma3,mma4;
uint8_t mmb1,mmb2,mmb3,mmb4; //用于接收过程存放遥控编码,第二次
//extern uint8_t mmbl,mmb2,mmb3,mmb4;
uint8_t rf_okl,rf_ok2,rf_ok; //解码过程中的临时接收成功标志,接收到一个完整的遥控命令后置1,通知解码程序可以解码了
uint8_t old_rc5; //保存上一次查询到的电平状态
uint8_t tb_ok; //接收到同步的马时置1
uint8_t D0,D1,D2,D3;
uint16_t s,s1;
#endif
uint8_t bt_auto; //自动设置遥控接收波特率标志
extern uint8_t rf_data[4];
@ -439,17 +424,9 @@ void STS_RF_write_send_0(void)
void STS_RF_write_send_leading(void)
{
#if 0
STS_RF_write_send_1();
STS_RF_write_send_0();
STS_RF_write_send_1();
#endif
HAL_GPIO_WritePin(RF_Send_GPIO_Port, RF_Send_GPIO_Pin, RESET);
//HAL_Delay(CNT_LONG_MS); // 8 msec long low level
HAL_Delay_Us(LEADING_MS*1000);
HAL_Delay_Us(LEADING_MS*1000);
HAL_Delay_Us(LEADING_MS*1000);
}
void STS_RF_write_send_ending(void)
@ -465,7 +442,7 @@ void STS_RF_Send_Button_Multi_Times(uint8_t *rf_payload, uint8_t one_button, uin
// normally, send 5-8 cycles of same address and cmd code
uint8_t push_button_cmd = one_button;
for (uint8_t i=0;i< mt;i++)
for (uint8_t i=0; i< mt; i++)
{
rf_payload[2] |= ((push_button_cmd));
printf("%d : Address=%02X:%02X:%01x CMD=%01X\r\n",i,
@ -482,10 +459,7 @@ void STS_RF_Send_Multi_Times(uint8_t *rf_payload, uint8_t rf_length, uint8_t mt)
{
// normally, send 5-8 cycles of same address and cmd code
// uint8_t push_button_cmd = 0x01;
for (uint8_t i=0;i< mt;i++)
for (uint8_t i=0; i< mt; i++)
{
rf_payload[2] |= ((i+1) <<4);
printf("%d : Address=%02X:%02X:%01x CMD=%01X\r\n",i, rf_payload[0],rf_payload[1],rf_payload[2]&0x0F, (rf_payload[2]>>4)&0x0F);

View File

@ -125,7 +125,7 @@ void MX_GPIO_Init(void)
#if 1
GPIO_InitStruct.Pin = RF_Receive_GPIO_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; //GPIO_MODE_INPUT; //GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; //GPIO_MODE_INPUT; //GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(RF_Receive_GPIO_Port, &GPIO_InitStruct);

View File

@ -128,139 +128,28 @@ int main(void)
// MX_I2C2_Init();
MX_GPIO_Init();
// MX_LoRaWAN_Init();
/* USER CODE BEGIN 2 */
MX_USART2_UART_Init();
// MX_USART1_UART_Init();
// MX_USART1_UART_Init();
MX_TIM1_Init();
// MX_TIM1_Init();
MX_TIM2_Init();
/*## Start the TIM Base generation in interrupt mode ####################*/
/* Start Channel1 */
if (HAL_TIM_Base_Start_IT(&htim1) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
if (HAL_TIM_Base_Start_IT(&htim2) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
/* --------------------------------------------------------------------------- */
#if 1
/*## Start the Input Capture in interrupt mode ##########################*/
if (HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_2) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
#endif
#if 1
/*## Start the Input Capture in interrupt mode ##########################*/
if (HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
#endif
printf("start \r\n");
while(1)
{
}
// EV1527_Init();
#if 0
/*## Start the Input Capture in interrupt mode ##########################*/
if (HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_2) != HAL_OK)
{
printf("tim1 ch2 start IT error \r\n");
/* Starting Error */
Error_Handler();
}
#endif
/* ---------------------------------------------------------------------------
TIM1 configuration: PWM Input mode
In this example TIM1 input clock (TIM1CLK) is set to APB2 clock (PCLK2),
since APB2 prescaler is 1.
TIM1CLK = PCLK2
PCLK2 = HCLK
=> TIM1CLK = HCLK = SystemCoreClock
External Signal Frequency = TIM1 counter clock / TIM1_CCR2 in Hz.
External Signal DutyCycle = (TIM1_CCR1*100)/(TIM1_CCR2) in %.
--------------------------------------------------------------------------- */
#if 1
/*## Start the Input Capture in interrupt mode ##########################*/
if (HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_2) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
#endif
#if 1
/*## Start the Input Capture in interrupt mode ##########################*/
if (HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
#endif
while(1)
{
}
while(1)
{
// printf("uwF=%ld Hz\r\n", uwFrequency);
// STS_RF_Send_Multi_Times(payload, 3, 5);
}
#if 0
uint8_t i;
while (1)
{
for(i=0; i<6; i++)
{
printf("\r\n Remote control Key down =%d \r\n", i);
sts_rc_key(i);
HAL_Delay(3000);
printf("\r\n Remote control decoded: %02x \r\n", codexx);
// sts_rc_decoder();
HAL_Delay(3000);
codexx=0;
}
HAL_Delay(2000);
}
#endif
/* USER CODE END 2 */
@ -280,24 +169,6 @@ while(1)
}
#if 0
void RF_Read_TIM_init(void)
{
TIM_Base_InitTypeDef TIM_Base_Init_Struct;
NVIC_InitTypeDef NVIC_Init_Struct;
RF_Read_TIM_RCC;
TIM_Base_Init_Struct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_Base_Init_Struct.TIM_CounterMode = TIM_CounterMode_Up;
// every int trigger time = [(Tim_Period+1)*(TIM_Prescaler+1)/(SystemCoreClock)] (s)
TIM_Base_Init_Struct.Tim_Prescalar = 48 -1;
TIM_Base_Init_Struct.Tim_Period = 0xffff -1;
TIM_Base_Init_Struct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(RF_Read_TIM_TIMx, &TIM_Init_Struct);
TIM_ITConfig(RF_Read_TIM_TIMx, TIM_IT_Update, ENABLE);
}
#endif
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
uint8_t single_button =0;
@ -338,8 +209,8 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
case DATA_433_PIN:
//printf("^");
// HAL_TIM_IC_CaptureCallback(&htim1);
// printf("^");
//HAL_TIM_IC_CaptureCallback(&htim1);
//RF_Signal_Decode();
break;
@ -348,146 +219,8 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
break;
}
#if 0
codexx =0;
switch (GPIO_Pin)
{
case RC_D0_Pin:
codexx |= (HAL_GPIO_ReadPin(RC_D0_GPIO_Port, RC_D0_Pin)<<0);
printf("[0]=%02x ",codexx);
break;
case RC_D1_Pin:
codexx |= (HAL_GPIO_ReadPin(RC_D1_GPIO_Port, RC_D1_Pin)<<1);
printf("[1]=%02x ",codexx);
break;
case RC_D2_Pin:
codexx |= (HAL_GPIO_ReadPin(RC_D2_GPIO_Port, RC_D2_Pin)<<2);
printf("[2]=%02x ",codexx);
break;
case RC_D3_Pin:
codexx |= (HAL_GPIO_ReadPin(RC_D3_GPIO_Port, RC_D3_Pin)<<3);
printf("[3]=%02x ",codexx);
break;
#if 0
case RC_D4_Pin:
codexx |= (HAL_GPIO_ReadPin(RC_D4_GPIO_Port, RC_D4_Pin)<<4);
printf("[4]=%02x ",codexx);
break;
case RC_D5_Pin:
codexx |= (HAL_GPIO_ReadPin(RC_D5_GPIO_Port, RC_D5_Pin)<<5);
printf("[5]=%02x ",codexx);
break;
case RC_D6_Pin:
codexx |= (HAL_GPIO_ReadPin(RC_D6_GPIO_Port, RC_D6_Pin)<<6);
printf("[6]=%02x ",codexx);
break;
case RC_D7_Pin:
codexx |= (HAL_GPIO_ReadPin(RC_D7_GPIO_Port, RC_D7_Pin)<<7);
printf("[7]=%02x ",codexx);
break;
#endif
case RC_VT_Pin:
code_vt = (HAL_GPIO_ReadPin(RC_VT_GPIO_Port, RC_VT_Pin));
printf("[V]=%02x ",codexx);
break;
default:
break;
}
#endif
}
#if 0
void sts_rc_key(uint8_t key)
{
HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET);
HAL_Delay(100);
switch (key) {
case 0:
HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET);
break;
case 1:
HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET);
break;
case 2:
HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET);
break;
case 3:
HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET);
break;
case 4:
HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET);
break;
case 5:
HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET);
break;
case 6:
HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET);
break;
case 7:
HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_RESET);
break;
}
}
uint8_t sts_rc_decodedx(void)
{
uint8_t codelow4=0, codehigh4=0;
codelow4 = (HAL_GPIO_ReadPin(RC_D0_GPIO_Port, RC_D0_Pin)<<0)|(HAL_GPIO_ReadPin(RC_D1_GPIO_Port, RC_D1_Pin)<<1)|(HAL_GPIO_ReadPin(RC_D2_GPIO_Port, RC_D2_Pin)<<2)|(HAL_GPIO_ReadPin(RC_D3_GPIO_Port, RC_D3_Pin)<<3);
codehigh4 = (HAL_GPIO_ReadPin(RC_D4_GPIO_Port, RC_D4_Pin)<<4)|(HAL_GPIO_ReadPin(RC_D5_GPIO_Port, RC_D5_Pin)<<5)|(HAL_GPIO_ReadPin(RC_D6_GPIO_Port, RC_D6_Pin)<<6)|(HAL_GPIO_ReadPin(RC_D7_GPIO_Port, RC_D7_Pin)<<7);
// printf("%02x \r", (codehigh4|codelow4));
return (codehigh4|codelow4);
}
void sts_rc_decoder(void)
{
uint8_t codex=0;
codex = HAL_GPIO_ReadPin(RC_D0_GPIO_Port, RC_D0_Pin)|(HAL_GPIO_ReadPin(RC_D1_GPIO_Port, RC_D1_Pin)<<1)|(HAL_GPIO_ReadPin(RC_D2_GPIO_Port, RC_D2_Pin)<<2)|(HAL_GPIO_ReadPin(RC_D3_GPIO_Port, RC_D3_Pin)<<3);
printf("decoded x= %02x \r\n", codex);
}
#endif
/**
* @brief System Clock Configuration
* @retval None

View File

@ -371,8 +371,18 @@ void EXTI9_5_IRQHandler(void)
HAL_GPIO_EXTI_IRQHandler(BUT3_Pin);
//HAL_GPIO_EXTI_IRQHandler(DATA_433_PIN);
//__HAL_GPIO_EXTI_CLEAR_IT(DATA_433_PIN);
/* ********************************************* */
/* must keep this with TIM2 for correct decoding */
/* ********************************************* */
HAL_GPIO_EXTI_IRQHandler(DATA_433_PIN);
__HAL_GPIO_EXTI_CLEAR_IT(DATA_433_PIN);
/* ********************************************* */
/* must keep this with TIM2 for correct decoding */
/* ********************************************* */
/* USER CODE BEGIN EXTI9_5_IRQn 1 */
@ -465,7 +475,6 @@ void TIM1_IRQHandler(void)
HAL_TIM_IRQHandler(&htim1);
}
#endif
#if 0
/**
* @brief This function handles TIM1 Capture Compare Interrupt.
@ -482,7 +491,7 @@ void TIM1_CC_IRQHandler(void)
}
#endif
#if 1
#if 0
/**
* @brief This function handles TIM1 Capture Compare Interrupt.
*/

View File

@ -32,7 +32,7 @@ extern TIM_HandleTypeDef htim1, htim2;
// TIM_HandleTypeDef htim1;
/* USER CODE BEGIN PV */
#if 1
#if 0
extern volatile uint32_t capture_Buf[3]; // counter
extern volatile uint8_t capture_Cnt; // state
@ -50,7 +50,7 @@ extern uint32_t uwFrequency;
#endif
uint8_t bit=0;
#if 1
#if 0
/* Captured Values */
extern uint32_t uwIC2Value1;
extern uint32_t uwIC2Value2;
@ -66,7 +66,7 @@ extern uint32_t uwFrequency;
/* USER CODE END 0 */
#if 0
/**
* @brief TIM1 Initialization Function
* @param None
@ -152,7 +152,7 @@ void MX_TIM1_Init(void)
}
#endif
/**
* @brief TIM2 Initialization Function
@ -257,16 +257,23 @@ void EV1527Decode(uint32_t v)
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
#if 0
if (TIM1 == htim->Instance)
{
printf(".");
} else if (TIM2 == htim->Instance)
} else
if (TIM2 == htim->Instance)
#endif
{
RF_Signal_Decode();
}
}
#endif
#if 0
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
static uint32_t uwICValue;
@ -275,21 +282,21 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
static uint32_t highCnt=0, lowCnt=0;
static uint8_t sync=0;
printf(" cc ");
//printf(" cc ");
// RF_Signal_Decode();
if (TIM1 == htim->Instance)
// if (TIM1 == htim->Instance)
{
if ((htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2))
// if ((htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2))
{
if (HAL_GPIO_ReadPin(RF_Receive_GPIO_Port,RF_Receive_GPIO_Pin)== GPIO_PIN_RESET)
{ // Falling edge
//printf(">");
highCnt = HAL_TIM_ReadCapturedValue(&htim1, TIM_CHANNEL_2); // get current value
// printf(">");
highCnt = HAL_TIM_ReadCapturedValue(&htim2, TIM_CHANNEL_2); // get current value
}
else if ((HAL_GPIO_ReadPin(RF_Receive_GPIO_Port,RF_Receive_GPIO_Pin) == GPIO_PIN_SET))
{ // Rising edge
lowCnt = HAL_TIM_ReadCapturedValue(&htim1, TIM_CHANNEL_2); // get current value
lowCnt = HAL_TIM_ReadCapturedValue(&htim2, TIM_CHANNEL_2); // get current value
if (syn == 1)
{ // sync then decode
if ((lowCnt > EV1527_L4_MIN) && (highCnt < EV1527_L4_MAX))
@ -327,7 +334,7 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
syn = 1;
pulseCnt = 0;
code = 0;
//printf("sync: %d \r\n", lowCnt);
printf("sync: %d \r\n", lowCnt);
}
}
}

Binary file not shown.