Files
E32_433_dev/Core/Src/e32_hal.c
2026-04-10 20:26:51 +08:00

124 lines
2.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "e32_hal.h"
/**
* 与单片机平台有关
*/
#include "main.h"
#include "gpio.h"
#include "usart.h"
/**
* @brief 串口发送接口
*
* @param buffer 发送内容
* @param length 发送长度
*/
void e32_hal_uart_tx( uint8_t *buffer , uint16_t length )
{
HAL_UART_Transmit( &huart1, buffer, length, 0xFFFF);
}
/**
* @brief 模组忙状态等待
*/
void e32_hal_aux_wait(void)
{
if( HAL_GPIO_ReadPin( AUX_GPIO_Port , AUX_Pin ) == GPIO_PIN_RESET )
{
/* 先等模块空闲 AUX引脚低为忙、高为空闲 */
while( HAL_GPIO_ReadPin( AUX_GPIO_Port , AUX_Pin ) == GPIO_PIN_RESET )
{
///@todo 可以做超时逻辑
}
/* 考虑兼容性AUX空闲后再稍等1~2ms */
HAL_Delay(2);
}
}
/**
* @brief 模组复位
*/
void e32_hal_reset(void)
{
HAL_GPIO_WritePin( RESET_GPIO_Port, RESET_Pin, GPIO_PIN_RESET );
HAL_Delay(1);
HAL_GPIO_WritePin( RESET_GPIO_Port, RESET_Pin, GPIO_PIN_SET );
#if E32_USE_GPIO_AUX
/* 注意 硬件重启时并不是立即AUX输出低电平需要等待一段时间再开始AUX检测 */
HAL_Delay(10);
e32_hal_aux_wait();
#else
// /* E32-V2 (V8.1) 版本启动时间较长
// 可以通过AT+FWCODE=?读取版本信息进行确认 7393-x-xx */
// e32_delay_ms(1200);
/* E32-V2 (V8.2) 版本
可以通过AT+FWCODE=?读取版本信息进行确认 7459-x-xx */
e32_delay_ms(30);
#endif
}
/**
* @brief 模组模式切换
*
* @param mode 工作模式
*/
void e32_hal_work_mode( work_mode_t mode)
{
#if E32_USE_GPIO_AUX
e32_hal_aux_wait();
#endif
switch(mode)
{
/* 模式0 一般模式 (M0=0 M1=0) */
case WORK_MODE_TRANSPARENT:
HAL_GPIO_WritePin( M0_GPIO_Port, M0_Pin, GPIO_PIN_RESET );
HAL_GPIO_WritePin( M1_GPIO_Port, M1_Pin, GPIO_PIN_RESET );
break;
/* 模式1 唤醒模式 (M0=1 M1=0) */
case WORK_MODE_WAKE_ON_RADIO_MASTER:
HAL_GPIO_WritePin( M0_GPIO_Port, M0_Pin, GPIO_PIN_SET );
HAL_GPIO_WritePin( M1_GPIO_Port, M1_Pin, GPIO_PIN_RESET );
break;
/* 模式2 省电模式 (M0=0 M1=1) */
case WORK_MODE_WAKE_ON_RADIO_SLAVE:
HAL_GPIO_WritePin( M0_GPIO_Port, M0_Pin, GPIO_PIN_RESET );
HAL_GPIO_WritePin( M1_GPIO_Port, M1_Pin, GPIO_PIN_SET );
break;
/* 模式3 休眠模式 (M0=1 M1=1) */
case WORK_MODE_CONFIG_AND_SLEEP:
HAL_GPIO_WritePin( M0_GPIO_Port, M0_Pin, GPIO_PIN_SET );
HAL_GPIO_WritePin( M1_GPIO_Port, M1_Pin, GPIO_PIN_SET );
break;
default:
while(1); //模式错误
}
#if E32_USE_GPIO_AUX
/* 引脚切换后 模组有时AUX引脚并不是立即输出低电平需要稍等再进行检查 */
HAL_Delay(5);
e32_hal_aux_wait();
#else
/* 这里保守一点延时,确保模式切换已正确完成 */
e32_delay_ms(50);
#endif
}