Implemented adapter device for E22-400T30S
This commit is contained in:
parent
05c0327e8b
commit
8e2baf1ee3
|
@ -16,6 +16,11 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||||
ifeq ($(CONFIG_ADAPTER_E220),y)
|
ifeq ($(CONFIG_ADAPTER_E220),y)
|
||||||
SRC_DIR += e220
|
SRC_DIR += e220
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ADAPTER_E22),y)
|
||||||
|
SRC_DIR += e22
|
||||||
|
endif
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -882,6 +882,7 @@ int AdapterLoraInit(void)
|
||||||
|
|
||||||
#ifdef ADAPTER_SX1278
|
#ifdef ADAPTER_SX1278
|
||||||
AdapterProductInfoType product_info = Sx1278Attach(adapter);
|
AdapterProductInfoType product_info = Sx1278Attach(adapter);
|
||||||
|
printf("AdapterLoraInit sx1278 success\n");
|
||||||
if (!product_info) {
|
if (!product_info) {
|
||||||
printf("AdapterLoraInit sx1278 attach error\n");
|
printf("AdapterLoraInit sx1278 attach error\n");
|
||||||
PrivFree(adapter);
|
PrivFree(adapter);
|
||||||
|
@ -896,6 +897,7 @@ int AdapterLoraInit(void)
|
||||||
|
|
||||||
#ifdef ADAPTER_E220
|
#ifdef ADAPTER_E220
|
||||||
AdapterProductInfoType product_info = E220Attach(adapter);
|
AdapterProductInfoType product_info = E220Attach(adapter);
|
||||||
|
printf("AdapterLoraInit e220 success\n");
|
||||||
if (!product_info) {
|
if (!product_info) {
|
||||||
printf("AdapterLoraInit e220 attach error\n");
|
printf("AdapterLoraInit e220 attach error\n");
|
||||||
PrivFree(adapter);
|
PrivFree(adapter);
|
||||||
|
@ -909,6 +911,7 @@ int AdapterLoraInit(void)
|
||||||
|
|
||||||
#ifdef ADAPTER_E22
|
#ifdef ADAPTER_E22
|
||||||
AdapterProductInfoType product_info = E22Attach(adapter);
|
AdapterProductInfoType product_info = E22Attach(adapter);
|
||||||
|
printf("AdapterLoraInit e22 success\n");
|
||||||
if (!product_info) {
|
if (!product_info) {
|
||||||
printf("AdapterLoraInit e22 attach error\n");
|
printf("AdapterLoraInit e22 attach error\n");
|
||||||
PrivFree(adapter);
|
PrivFree(adapter);
|
||||||
|
|
|
@ -32,3 +32,36 @@ if ADD_NUTTX_FEATURES
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if ADD_XIZI_FEATURES
|
||||||
|
config ADAPTER_E22_M0
|
||||||
|
int "E22 M0 pin number"
|
||||||
|
default "32"
|
||||||
|
|
||||||
|
config ADAPTER_E22_M1
|
||||||
|
int "E22 M1 pin number"
|
||||||
|
default "33"
|
||||||
|
|
||||||
|
config ADAPTER_E22_PIN_DRIVER
|
||||||
|
string "E22 device pin driver path"
|
||||||
|
default "/dev/pin_dev"
|
||||||
|
|
||||||
|
config ADAPTER_E22_DRIVER_EXTUART
|
||||||
|
bool "Using extra uart to support lora"
|
||||||
|
default n
|
||||||
|
|
||||||
|
config ADAPTER_E22_DRIVER
|
||||||
|
string "E22 device uart driver path"
|
||||||
|
default "/dev/uart2_dev2"
|
||||||
|
depends on !ADAPTER_E22_DRIVER_EXTUART
|
||||||
|
|
||||||
|
if ADAPTER_E22_DRIVER_EXTUART
|
||||||
|
config ADAPTER_E22_DRIVER
|
||||||
|
string "E22 device extra uart driver path"
|
||||||
|
default "/dev/extuart_dev3"
|
||||||
|
|
||||||
|
config ADAPTER_E22_DRIVER_EXT_PORT
|
||||||
|
int "if E22 device using extuart, choose port"
|
||||||
|
default "3"
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
|
@ -5,3 +5,9 @@ ifeq ($(CONFIG_ADD_NUTTX_FEATURES),y)
|
||||||
include $(APPDIR)/Application.mk
|
include $(APPDIR)/Application.mk
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||||
|
SRC_FILES := e22.c
|
||||||
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
||||||
|
endif
|
|
@ -0,0 +1,10 @@
|
||||||
|
from building import *
|
||||||
|
import os
|
||||||
|
|
||||||
|
cwd = GetCurrentDir()
|
||||||
|
src = []
|
||||||
|
if GetDepend(['ADAPTER_E22']):
|
||||||
|
src += ['e22.c']
|
||||||
|
group = DefineGroup('connection lora e22', src, depend = [], CPPPATH = [cwd])
|
||||||
|
|
||||||
|
Return('group')
|
|
@ -46,6 +46,7 @@ enum E22LoraMode
|
||||||
* @param mode Lora working mode
|
* @param mode Lora working mode
|
||||||
* @return NULL
|
* @return NULL
|
||||||
*/
|
*/
|
||||||
|
#ifdef ADD_NUTTX_FEATURES
|
||||||
static void E22LoraModeConfig(enum E22LoraMode mode)
|
static void E22LoraModeConfig(enum E22LoraMode mode)
|
||||||
{
|
{
|
||||||
int m0_fd, m1_fd;
|
int m0_fd, m1_fd;
|
||||||
|
@ -106,7 +107,88 @@ static void E22LoraModeConfig(enum E22LoraMode mode)
|
||||||
//delay 20ms , wait mode switch done
|
//delay 20ms , wait mode switch done
|
||||||
PrivTaskDelay(20);
|
PrivTaskDelay(20);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static void E22LoraModeConfig(enum E22LoraMode mode)
|
||||||
|
{
|
||||||
|
//delay 1s , wait AUX ready
|
||||||
|
PrivTaskDelay(1000);
|
||||||
|
|
||||||
|
int pin_fd;
|
||||||
|
pin_fd = PrivOpen(ADAPTER_E22_PIN_DRIVER, O_RDWR);
|
||||||
|
if (pin_fd < 0) {
|
||||||
|
printf("open %s error\n", ADAPTER_E22_PIN_DRIVER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Step1: config M0 and M1 GPIO
|
||||||
|
struct PinParam pin_param;
|
||||||
|
pin_param.cmd = GPIO_CONFIG_MODE;
|
||||||
|
pin_param.mode = GPIO_CFG_OUTPUT;
|
||||||
|
pin_param.pin = ADAPTER_E22_M0;
|
||||||
|
|
||||||
|
struct PrivIoctlCfg ioctl_cfg;
|
||||||
|
ioctl_cfg.ioctl_driver_type = PIN_TYPE;
|
||||||
|
ioctl_cfg.args = &pin_param;
|
||||||
|
PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg);
|
||||||
|
|
||||||
|
pin_param.pin = ADAPTER_E22_M1;
|
||||||
|
ioctl_cfg.args = &pin_param;
|
||||||
|
PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg);
|
||||||
|
|
||||||
|
//Step2 : set M0 and M1 high or low
|
||||||
|
struct PinStat pin_stat;
|
||||||
|
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case DATA_TRANSFER_MODE:
|
||||||
|
pin_stat.pin = ADAPTER_E22_M1;
|
||||||
|
pin_stat.val = GPIO_LOW;
|
||||||
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
|
|
||||||
|
pin_stat.pin = ADAPTER_E22_M0;
|
||||||
|
pin_stat.val = GPIO_LOW;
|
||||||
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WOR_SEND_MODE:
|
||||||
|
pin_stat.pin = ADAPTER_E22_M1;
|
||||||
|
pin_stat.val = GPIO_LOW;
|
||||||
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
|
|
||||||
|
pin_stat.pin = ADAPTER_E22_M0;
|
||||||
|
pin_stat.val = GPIO_HIGH;
|
||||||
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONFIGURE_MODE:
|
||||||
|
pin_stat.pin = ADAPTER_E22_M1;
|
||||||
|
pin_stat.val = GPIO_HIGH;
|
||||||
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
|
|
||||||
|
pin_stat.pin = ADAPTER_E22_M0;
|
||||||
|
pin_stat.val = GPIO_LOW;
|
||||||
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SLEEP_MODE:
|
||||||
|
pin_stat.pin = ADAPTER_E22_M1;
|
||||||
|
pin_stat.val = GPIO_HIGH;
|
||||||
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
|
|
||||||
|
pin_stat.pin = ADAPTER_E22_M0;
|
||||||
|
pin_stat.val = GPIO_HIGH;
|
||||||
|
PrivWrite(pin_fd, &pin_stat, 1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrivClose(pin_fd);
|
||||||
|
|
||||||
|
//delay 20ms , wait mode switch done
|
||||||
|
PrivTaskDelay(20);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* @description: Switch baud rate to register bit
|
* @description: Switch baud rate to register bit
|
||||||
* @param baud_rate - baud_rate
|
* @param baud_rate - baud_rate
|
||||||
|
@ -204,7 +286,6 @@ static int E22SetRegisterParam(struct Adapter *adapter, uint16 address, uint8 ch
|
||||||
|
|
||||||
E22LoraModeConfig(DATA_TRANSFER_MODE);
|
E22LoraModeConfig(DATA_TRANSFER_MODE);
|
||||||
PrivTaskDelay(1000);
|
PrivTaskDelay(1000);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +336,7 @@ static int E22GetRegisterParam(uint8 *buf)
|
||||||
*/
|
*/
|
||||||
static int E22Open(struct Adapter *adapter)
|
static int E22Open(struct Adapter *adapter)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*step1: open e22 uart port*/
|
/*step1: open e22 uart port*/
|
||||||
adapter->fd = PrivOpen(ADAPTER_E22_DRIVER, O_RDWR);
|
adapter->fd = PrivOpen(ADAPTER_E22_DRIVER, O_RDWR);
|
||||||
if (adapter->fd < 0) {
|
if (adapter->fd < 0) {
|
||||||
|
@ -513,6 +595,7 @@ static void LoraRead(void *parameter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ADD_NUTTX_FEATURES
|
||||||
void E22LoraReceive(void)
|
void E22LoraReceive(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -546,3 +629,39 @@ void E22LoraSend(int argc, char *argv[])
|
||||||
E22Close(adapter);
|
E22Close(adapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ADD_XIZI_FEATURES
|
||||||
|
static void LoraTest(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
LoraOpen();
|
||||||
|
|
||||||
|
int task_lora_read = KTaskCreate("task_lora_read", LoraRead, NONE, 2048, 10);
|
||||||
|
ret = StartupKTask(task_lora_read);
|
||||||
|
if (ret != EOK) {
|
||||||
|
KPrintf("StartupKTask task_lora_read failed .\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// PRIV_SHELL_CMD_FUNCTION(LoraTest, a lora test init sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||||
|
|
||||||
|
static void LoraSend(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
|
||||||
|
if (NULL == adapter) {
|
||||||
|
printf("LoraRead find lora adapter error\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char Msg[256] = {0};
|
||||||
|
|
||||||
|
if (argc == 2) {
|
||||||
|
strncpy(Msg, argv[1], 256);
|
||||||
|
|
||||||
|
E22Send(adapter, Msg, strlen(Msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// PRIV_SHELL_CMD_FUNCTION(LoraSend, a lora test send sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||||
|
#endif
|
||||||
|
|
|
@ -371,8 +371,6 @@ static void radio_send() {
|
||||||
false // CRC enabled or not
|
false // CRC enabled or not
|
||||||
);
|
);
|
||||||
|
|
||||||
Radio.StartCad();
|
|
||||||
|
|
||||||
Radio.SetTxConfig(
|
Radio.SetTxConfig(
|
||||||
MODEM_LORA, // Modem type (LoRa)
|
MODEM_LORA, // Modem type (LoRa)
|
||||||
lora_radio_test_paras.txpower, // Transmission power
|
lora_radio_test_paras.txpower, // Transmission power
|
||||||
|
|
Loading…
Reference in New Issue