diff --git a/Core/Inc/ev1527.h b/Core/Inc/ev1527.h new file mode 100644 index 0000000..040f18a --- /dev/null +++ b/Core/Inc/ev1527.h @@ -0,0 +1,33 @@ +/** + * @file EV1527.h + * @author cyWu (1917507415@qq.com) + * @brief EV1527解码框架 + * @version 0.1 + * @date 2024-03-28 + * @copyright Copyright (c) 2024 + * + */ + +#ifndef __EV1527_H +#define __EV1527_H + +#include "main.h" +#include +#include +#include +#include + +/*********433 DATA GPIO**********/ + +// 433数据输入 +#if 0 +#define DATA_433_PIN GPIO_PIN_7 +#define DATA_433_GPIO_PORT GPIOA +#define DATA_433_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE(); +#endif +/*******************************/ + +void EV1527_Init(void); +void RF_Signal_Decode(void); + +#endif diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 8d64519..160a3c1 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -89,6 +89,82 @@ void Error_Handler(void); #define USART1_TX_Pin GPIO_PIN_6 #define USART1_TX_GPIO_Port GPIOB +#ifdef RC +// REMOTE CONTROL EV1527/HS1527 LORA-WAN RELAY NODE + +#define RC_K0_Pin GPIO_PIN_5 +#define RC_K0_GPIO_Port GPIOA + +#define RC_K1_Pin GPIO_PIN_6 +#define RC_K1_GPIO_Port GPIOA + +#define RC_K2_Pin GPIO_PIN_7 +#define RC_K2_GPIO_Port GPIOA + +#define RC_K3_Pin GPIO_PIN_4 +#define RC_K3_GPIO_Port GPIOC +/* +#define RC_K4_Pin GPIO_PIN_6 +#define RC_K4_GPIO_Port GPIOC + +#define RC_K5_Pin GPIO_PIN_6 +#define RC_K5_GPIO_Port GPIOC + +#define RC_K6_Pin GPIO_PIN_6 +#define RC_K6_GPIO_Port GPIOC + +#define RC_K7_Pin GPIO_PIN_6 +#define RC_K7_GPIO_Port GPIOC +*/ + +#define RC_D0_Pin GPIO_PIN_1 +#define RC_D0_GPIO_Port GPIOB + +#define RC_D1_Pin GPIO_PIN_2 +#define RC_D1_GPIO_Port GPIOB + +#define RC_D2_Pin GPIO_PIN_4 +#define RC_D2_GPIO_Port GPIOB + +#define RC_D3_Pin GPIO_PIN_14 +#define RC_D3_GPIO_Port GPIOB + +#define RC_D4_Pin GPIO_PIN_8 +#define RC_D4_GPIO_Port GPIOB + +#define RC_D5_Pin GPIO_PIN_5 +#define RC_D5_GPIO_Port GPIOB + +#define RC_D6_Pin GPIO_PIN_3 +#define RC_D6_GPIO_Port GPIOB + +#define RC_D7_Pin GPIO_PIN_12 +#define RC_D7_GPIO_Port GPIOB + + +#define RC_VT_Pin GPIO_PIN_13 +#define RC_VT_GPIO_Port GPIOB + +#define RC_SET_Pin GPIO_PIN_6 +#define RC_SET_GPIO_Port GPIOB + +#define RC_NONE 0x00 // 0000 +#define RC_POWER_ON 0x01 // 0001 +#define RC_POWER_OFF 0x03 // 0011 +#define RC_PIC_FIRST 0x02 // 0010 +#define RC_PIC_NEXT 0x06 // 0110 +#define RC_SHOW_5S 0x08 // 1000 +#define RC_SHOW_10S 0x09 // 1001 +#define RC_SHOW_15S 0x04 // 0100 +#define RC_SHOW_30S 0x0C // 1100 + + +#define DATA_433_PIN GPIO_PIN_7 +#define DATA_433_GPIO_PORT GPIOA +#define DATA_433_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE(); + +#endif + #define I2C2_SCL_PIN GPIO_PIN_12 #define I2C2_SDA_PIN GPIO_PIN_11 diff --git a/Core/Src/ev1527.c b/Core/Src/ev1527.c new file mode 100644 index 0000000..12f5bed --- /dev/null +++ b/Core/Src/ev1527.c @@ -0,0 +1,276 @@ +/** + * @file EV1527.c + * @author cyWu (1917507415@qq.com) + * @brief EV1527解码框架,定时器中断的方式解码,使用80us的定时器,直接放中断服务函数就可以,适用于所有单片机。 + * @version 0.1 + * @date 2024-03-28 + * @copyright Copyright (c) 2024 + * + */ +#include "EV1527.h" + +// 定时周期 +#define TIME_CYCLE 80 + +// 定义引导码的最小和最大持续时间(单位:us) +#define MIN_LEAD_CODE (5600 / TIME_CYCLE) +#define MAX_LEAD_CODE (16000 / TIME_CYCLE) + +// 定义数据位持续时间的最小和最大范围(单位:us) +#define MIN_BIT_DURATION (80 / TIME_CYCLE) +#define MAX_BIT_DURATION (2400 / TIME_CYCLE) + +// 定义功能字节在接收缓冲区中的索引位置 +#define FUNCTION_BYTE_INDEX 2 + +// 定义功能值 +#define FUNCTION_1 0x08 +#define FUNCTION_2 0x04 +#define FUNCTION_3 0x02 +#define FUNCTION_4 0X01 +#define FUNCTION_5 0X03 +#define FUNCTION_6 0X05 +#define FUNCTION_7 0X07 +#define FUNCTION_8 0X00 + +// 定义数据解码状态枚举 +typedef enum +{ + LEAD_CODE, // 引导码状态 + HIGH_BIT, // 高位数据位状态 + LOW_BIT, // 低位数据位状态 + DATA_PROCESS, // 数据处理状态 + FUNCTION_PROCESS // 功能处理状态 +} Decode_State_t; + +// 定义全局变量和缓冲区 +#define ARRAY_SIZE 128 +static uint32_t Lead_Code_Count = 0; // 引导码计数 +static uint32_t High_Bit_Count = 0; // 高位数据位计数 +static uint32_t Low_Bit_Count = 0; // 低位数据位计数 +static uint32_t High_Bit_Duration = 0; // 高位数据位持续时间 +static uint32_t Low_Bit_Duration = 0; // 低位数据位持续时间 +static uint8_t Received_Buffer[ARRAY_SIZE] = {0}; // 接收数据缓冲区 +static uint8_t lastDataArray[ARRAY_SIZE] = {0}; // 上一次接收数据缓冲区 +static uint8_t Received_Byte_Count = 0; // 接收数据字节计数 +static uint8_t consecutiveEqualCount = 0; // 数据接收相同计数 +static uint8_t Bit_Count = 0; // 接收数据位计数 +static uint8_t Received_Data = 0; // 接收到的数据 +static Decode_State_t RF_Decode_State = LEAD_CODE; // 数据解码状态 + +void Decode_Data(void); +void Execute_Function(void); +void Reset_Decode_Parameters(void); + +/**----------------------------------------------------------------------------------------------** + **函数名 :EV1527端口配置 + **功能说明:初始化IO口,不同单片机的配置输入模式不一样,自行修改。 + **----------------------------------------------------------------------------------------------**/ +void EV1527_Init(void) +{ + DATA_433_GPIO_CLK_ENABLE(); + + GPIO_InitTypeDef GPIO_InitStruct; + // 配置上拉输入 + GPIO_InitStruct.Pin = DATA_433_PIN; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + HAL_GPIO_Init(DATA_433_GPIO_PORT, &GPIO_InitStruct); +} + +/**----------------------------------------------------------------------------------------------** + **函数名 :RF信号解码函数 + **功能说明:解码从433MHz接收到的信号,并根据解码结果执行相应功能 + **调用说明:80us调用一次 + **----------------------------------------------------------------------------------------------**/ +void RF_Signal_Decode(void) +{ + switch (RF_Decode_State) + { + case LEAD_CODE: // 引导码 + // 判断是否低电平 + if (HAL_GPIO_ReadPin(DATA_433_GPIO_PORT, DATA_433_PIN) == GPIO_PIN_RESET) + { + Lead_Code_Count++; + } + else // 高电平判断范围 + { + // 判断引导码范围是否合法 + if (Lead_Code_Count >= MIN_LEAD_CODE && Lead_Code_Count <= MAX_LEAD_CODE) + { + Lead_Code_Count = 0; + Reset_Decode_Parameters(); // 重置解码参数 + RF_Decode_State = HIGH_BIT; // 进入高位数据位判断状态 + } + else + { + Reset_Decode_Parameters(); // 引导码范围不合法,重置解码参数 + } + } + break; + + case HIGH_BIT: + // 判断是否高电平 + if (HAL_GPIO_ReadPin(DATA_433_GPIO_PORT, DATA_433_PIN) == GPIO_PIN_SET) + { + High_Bit_Count++; + } + else // 低电平判断范围 + { + // 判断高位数据位范围是否合法 + if (High_Bit_Count >= MIN_BIT_DURATION && High_Bit_Count <= MAX_BIT_DURATION) + { + High_Bit_Duration = High_Bit_Count; // 保存计数值,用于区分0和1 + High_Bit_Count = 0; + RF_Decode_State = LOW_BIT; // 进入低位数据位判断状态 + } + else + { + Reset_Decode_Parameters(); // 高位数据位范围不合法,重置解码参数 + } + } + break; + + case LOW_BIT: + // 判断是否低电平 + if (HAL_GPIO_ReadPin(DATA_433_GPIO_PORT, DATA_433_PIN) == GPIO_PIN_RESET) + { + Low_Bit_Count++; + } + else // 高电平判断范围 + { + // 判断低位数据位范围是否合法 + if (Low_Bit_Count >= MIN_BIT_DURATION && Low_Bit_Count <= MAX_BIT_DURATION) + { + Low_Bit_Duration = Low_Bit_Count; // 保存计数值,用于区分0和1 + Low_Bit_Count = 0; + RF_Decode_State = DATA_PROCESS; // 进入数据处理状态 + } + else + { + Reset_Decode_Parameters(); // 低位数据位范围不合法,重置解码参数 + } + } + break; + + case DATA_PROCESS: + Decode_Data(); // 解码数据 + if (Received_Byte_Count == 3) + { + // 接收到全部数据,包括地址和数据 + RF_Decode_State = FUNCTION_PROCESS; + } + else + { // 数据没接收完 + RF_Decode_State = HIGH_BIT; // 继续解码数据 + } + break; + + case FUNCTION_PROCESS: + Execute_Function(); // 执行功能 + Reset_Decode_Parameters(); // 重置解码参数 + break; + + default: + Reset_Decode_Parameters(); // 默认状态,重置解码参数 + break; + } +} + +/**----------------------------------------------------------------------------------------------** + **函数名 :Reset_Decode_Parameters + **功能说明:重置解码参数,用于开始新的解码周期 + **----------------------------------------------------------------------------------------------**/ +void Reset_Decode_Parameters(void) +{ + Bit_Count = 0; + Received_Data = 0x00; + Received_Byte_Count = 0; + Lead_Code_Count = 0; + High_Bit_Count = 0; + Low_Bit_Count = 0; + High_Bit_Duration = 0; + Low_Bit_Duration = 0; + RF_Decode_State = LEAD_CODE; +} + +/**----------------------------------------------------------------------------------------------** + **函数名 :Decode_Data + **功能说明:解码数据位,将解码后的数据存入相应的缓冲区中 + **----------------------------------------------------------------------------------------------**/ +void Decode_Data(void) +{ + Received_Data <<= 1; + // 根据高低电平持续时间判断0和1,然后将数据移位存入缓冲区 + if (High_Bit_Duration > Low_Bit_Duration) + { + Received_Data |= 0x01; + } + else + { + Received_Data &= 0xFE; + } + + Bit_Count++; + + // 每接收8位数据,存入数据数组 + if (Bit_Count == 8) + { + Received_Buffer[Received_Byte_Count] = Received_Data; + Received_Data = 0x00; + Bit_Count = 0; + Received_Byte_Count++; + } +} + +/**----------------------------------------------------------------------------------------------** + **函数名 :Execute_Function + **功能说明:执行功能,根据解码后的数据进行相应操作 + **----------------------------------------------------------------------------------------------**/ +void Execute_Function(void) +{ + // 判断解码后的功能字节,并执行相应操作 + switch (Received_Buffer[FUNCTION_BYTE_INDEX]) + { + case FUNCTION_1: + // 执行功能1 + printf("\r\n Function_1 \r\n"); + break; + + case FUNCTION_2: + // 执行功能2 + printf("\r\n Function_2 \r\n"); + break; + + case FUNCTION_3: + // 执行功能3 + printf("\r\n Function_3 \r\n"); + break; + case FUNCTION_4: + // 执行功能4 + printf("\r\n Function_4 \r\n"); + break; + case FUNCTION_5: + // 执行功能5 + printf("\r\n Function_5 \r\n"); + break; + case FUNCTION_6: + // 执行功能6 + printf("\r\n Function_6 \r\n"); + break; + case FUNCTION_7: + // 执行功能7 + printf("\r\n Function_7 \r\n"); + break; + case FUNCTION_8: + // 执行功能8 + printf("\r\n Function_8 \r\n"); + break; + + default: + // 默认操作 + printf("\r\n --- code =%02x",Received_Buffer[FUNCTION_BYTE_INDEX]); + break; + } +} diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index f83890e..a2daade 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -52,10 +52,10 @@ void MX_GPIO_Init(void) /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|PROB2_Pin|PROB1_Pin |LED3_Pin, GPIO_PIN_RESET); - +#ifdef L8 HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_SET); - +#endif /*Configure GPIO pins : PBPin PBPin PBPin */ GPIO_InitStruct.Pin = LED1_Pin|LED2_Pin|LED3_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; @@ -82,6 +82,40 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(BUT3_GPIO_Port, &GPIO_InitStruct); +#ifdef RC + /*Configure GPIO pins : PBPin PBPin PBPin */ + GPIO_InitStruct.Pin = RC_K0_Pin|RC_K1_Pin|RC_K2_Pin|RC_K3_Pin|RC_SET_Pin|RC_VT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(RC_K0_GPIO_Port, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = RC_D0_Pin|RC_D1_Pin|RC_D2_Pin|RC_D3_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(RC_D0_GPIO_Port, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = RC_D4_Pin|RC_D5_Pin|RC_D6_Pin|RC_D7_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(RC_D4_GPIO_Port, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = RC_SET_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(RC_SET_GPIO_Port, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = RC_VT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(RC_VT_GPIO_Port, &GPIO_InitStruct); + +#endif + #ifdef L8 /*Configure GPIO pins : PAPin PAPin */ GPIO_InitStruct.Pin = TOF_INT_EXTI_PIN; @@ -131,9 +165,23 @@ void MX_GPIO_Init(void) HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI1_IRQn); + HAL_NVIC_SetPriority(EXTI2_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(EXTI2_IRQn); + + HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(EXTI3_IRQn); + + HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(EXTI4_IRQn); + + HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); + HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); + + #ifdef L8 HAL_NVIC_SetPriority(TOF_INT_EXTI_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TOF_INT_EXTI_IRQn); diff --git a/Core/Src/main.c b/Core/Src/main.c index 11de389..2344b03 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -22,18 +22,31 @@ #include "gpio.h" #include "usart.h" #include "stdio.h" - +#include "ev1527.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ // #include "i2c.h" // #include "app_tof.h" /* USER CODE END Includes */ -#include "sts_aq_o3.h" +// #include "sts_aq_o3.h" /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ - +void sts_rc_key(uint8_t key); +void sts_rc_decoder(void); +uint8_t sts_rc_decodedx(void); +volatile uint8_t codexx=0, code_vt=0; /* USER CODE END PTD */ - +uint8_t rc_cmd[9]={ + RC_NONE, + RC_POWER_ON, + RC_POWER_OFF, + RC_PIC_FIRST, + RC_PIC_NEXT, + RC_SHOW_5S, + RC_SHOW_10S, + RC_SHOW_15S, + RC_SHOW_30S +}; /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ @@ -104,56 +117,81 @@ int main(void) MX_USART1_UART_Init(); + uint8_t vt=0; + uint8_t codex=0; + uint32_t k=0; - /* USER CODE END 2 */ - - sts_sensor_o3_t o3_data; - sts_aq_o3_init(); - - int i=0; - if (sts_aq_o3_start_pooling_mode() ==0) + EV1527_Init(); + while(1) { - do { - if (sts_aq_o3_query(&o3_data) ==0) - { - printf("\r\n cycle %d: o3 =%4d %s : %.2f mg/m3 \r\n", i, o3_data.o3_ppb, (o3_data.o3_unit==0x04)?"ppb":"non", o3_data.o3_mg_per_m3); - } - HAL_Delay(4000); - HAL_Delay(4000); - HAL_Delay(4000); - } while (i++ <20); - + RF_Signal_Decode(); + HAL_Delay(1/20); } -#if 1 - if (sts_aq_o3_start_autony_mode() ==0) +#if 0 + // for(i=0; i<16; i++) { - do { - sts_aq_o3_autony_run_mode(&o3_data); - printf("\r\n o3 =%4d %s : %.2f mg/m3 \r\n", o3_data.o3_ppb, (o3_data.o3_unit==0x04)?"ppb":"non", o3_data.o3_mg_per_m3); - } while (i++ <100); + printf("\r\n Set Key down \r\n"); + HAL_GPIO_WritePin(RC_SET_GPIO_Port, RC_SET_Pin, GPIO_PIN_RESET); + HAL_Delay(3000); + + while(1) + { + k=0; + printf("\r\n Scan code \r\n"); + codex =0; + codexx =0; + do { + // sts_rc_key(i); + //codex = sts_rc_decodedx(); + codex = codexx; + vt=HAL_GPIO_ReadPin(RC_VT_GPIO_Port, RC_VT_Pin); + if (vt||code_vt) + { + printf("+++\r\n"); + } + // HAL_Delay(10); + k++; + }while ((vt==0)); + + printf("\r\n Cycle=%ld decoded x= %02x vt=%02x\r\n", k, codexx, code_vt); + + HAL_Delay(1000); + } } #endif + #if 0 - sts_aq_sgp30_init(); - do + while (1) { - sts_aq_sgp30_read(&sgp30_data); - printf("\r\n sgp30_CO2 =%4d ppm, sgp_30_TVOC=%4d mg/m3 \r\n", sgp30_data.co2, sgp30_data.tvoc); + for(i=0; i<16; i++) + { + printf("\r\n Remote control Key down =%d \r\n", i); + //sts_rc_key(i); - } while(i++ <100); + printf("\r\n Remote control decoded: "); + sts_rc_decoder(); + + HAL_Delay(1000); + } + + HAL_Delay(2000); + } #endif - /* Infinite loop */ + + /* USER CODE END 2 */ + + /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ - // MX_TOF_Process(); + MX_LoRaWAN_Process(); /* USER CODE BEGIN 3 */ @@ -161,6 +199,135 @@ int main(void) /* USER CODE END 3 */ } +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) +{ + 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; + + 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; + case RC_VT_Pin: + code_vt = (HAL_GPIO_ReadPin(RC_VT_GPIO_Port, RC_VT_Pin)); + printf("[V]=%02x ",codexx); + break; + + default: + break; + } +} + +void sts_rc_key(uint8_t key) +{ + switch (key) { + case 0: + 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_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_RESET); + break; + case 1: + 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_RESET); + break; + case 2: + 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_RESET); + + break; + case 3: + 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_RESET); + + break; + case 4: + 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_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; + case 5: + 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; + case 6: + 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_RESET); + + 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); + +} + /** * @brief System Clock Configuration * @retval None diff --git a/Core/Src/stm32wlxx_it.c b/Core/Src/stm32wlxx_it.c index f22c165..9c438b4 100644 --- a/Core/Src/stm32wlxx_it.c +++ b/Core/Src/stm32wlxx_it.c @@ -243,7 +243,29 @@ void EXTI1_IRQHandler(void) /* USER CODE BEGIN EXTI1_IRQn 0 */ /* USER CODE END EXTI1_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(BUT2_Pin); + HAL_GPIO_EXTI_IRQHandler(RC_D0_Pin); + /* USER CODE BEGIN EXTI1_IRQn 1 */ + + /* USER CODE END EXTI1_IRQn 1 */ +} + +void EXTI2_IRQHandler(void) +{ + /* USER CODE BEGIN EXTI1_IRQn 0 */ + + /* USER CODE END EXTI1_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(RC_D1_Pin); + /* USER CODE BEGIN EXTI1_IRQn 1 */ + + /* USER CODE END EXTI1_IRQn 1 */ +} + +void EXTI3_IRQHandler(void) +{ + /* USER CODE BEGIN EXTI1_IRQn 0 */ + + /* USER CODE END EXTI1_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(RC_D6_Pin); /* USER CODE BEGIN EXTI1_IRQn 1 */ /* USER CODE END EXTI1_IRQn 1 */ @@ -258,6 +280,7 @@ void EXTI4_IRQHandler(void) /* USER CODE END EXTI1_IRQn 0 */ //HAL_GPIO_EXTI_IRQHandler(TOF_INT_EXTI_PIN); + HAL_GPIO_EXTI_IRQHandler(RC_D2_Pin); /* USER CODE BEGIN EXTI1_IRQn 1 */ /* USER CODE END EXTI1_IRQn 1 */ @@ -327,7 +350,9 @@ void EXTI9_5_IRQHandler(void) /* USER CODE BEGIN EXTI9_5_IRQn 0 */ /* USER CODE END EXTI9_5_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(BUT3_Pin); + HAL_GPIO_EXTI_IRQHandler(RC_D4_Pin); + HAL_GPIO_EXTI_IRQHandler(RC_D5_Pin); + HAL_GPIO_EXTI_IRQHandler(DATA_433_PIN); /* USER CODE BEGIN EXTI9_5_IRQn 1 */ /* USER CODE END EXTI9_5_IRQn 1 */ @@ -341,6 +366,9 @@ void EXTI15_10_IRQHandler(void) /* USER CODE BEGIN EXTI15_10_IRQn 0 */ /* USER CODE END EXTI15_10_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(RC_D3_Pin); + HAL_GPIO_EXTI_IRQHandler(RC_D7_Pin); + HAL_GPIO_EXTI_IRQHandler(RC_VT_Pin); // HAL_GPIO_EXTI_IRQHandler(TOF_INT_EXTI_PIN); /* USER CODE BEGIN EXTI15_10_IRQn 1 */ diff --git a/STM32CubeIDE/.cproject b/STM32CubeIDE/.cproject index b5c521c..8948d9b 100644 --- a/STM32CubeIDE/.cproject +++ b/STM32CubeIDE/.cproject @@ -130,6 +130,7 @@