Skip to content

Commit 6dbc00d

Browse files
author
Cruz Monrreal
authored
Merge pull request #10292 from hasnainvirk/ec2x_driver
Cellular: Basic driver for Quectel EC25/EC21
2 parents cec5a85 + 69efed2 commit 6dbc00d

File tree

3 files changed

+232
-0
lines changed

3 files changed

+232
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright (c) 2019, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "QUECTEL_EC2X.h"
19+
20+
#include "PinNames.h"
21+
#include "AT_CellularNetwork.h"
22+
#include "rtos/ThisThread.h"
23+
#include "UARTSerial.h"
24+
25+
using namespace mbed;
26+
using namespace rtos;
27+
using namespace events;
28+
29+
#if !defined(MBED_CONF_QUECTEL_EC2X_PWR)
30+
#define MBED_CONF_QUECTEL_EC2X_PWR NC
31+
#endif
32+
33+
#if !defined(MBED_CONF_QUECTEL_EC2X_RST)
34+
#define MBED_CONF_QUECTEL_EC2X_RST NC
35+
#endif
36+
37+
#if !defined(MBED_CONF_QUECTEL_EC2X_TX)
38+
#define MBED_CONF_QUECTEL_EC2X_TX NC
39+
#endif
40+
41+
#if !defined(MBED_CONF_QUECTEL_EC2X_RX)
42+
#define MBED_CONF_QUECTEL_EC2X_RX NC
43+
#endif
44+
45+
#if !defined(MBED_CONF_QUECTEL_EC2X_POLARITY)
46+
#define MBED_CONF_QUECTEL_EC2X_POLARITY 1 // active high
47+
#endif
48+
49+
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
50+
AT_CellularNetwork::RegistrationModeLAC, // C_EREG
51+
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
52+
AT_CellularNetwork::RegistrationModeLAC, // C_REG
53+
0, // AT_CGSN_WITH_TYPE
54+
1, // AT_CGDATA
55+
0, // AT_CGAUTH
56+
1, // AT_CNMI
57+
1, // AT_CSMP
58+
1, // AT_CMGF
59+
1, // AT_CSDH
60+
1, // PROPERTY_IPV4_STACK
61+
1, // PROPERTY_IPV6_STACK
62+
1, // PROPERTY_IPV4V6_STACK
63+
0, // PROPERTY_NON_IP_PDP_TYPE
64+
1, // PROPERTY_AT_CGEREP
65+
};
66+
67+
QUECTEL_EC2X::QUECTEL_EC2X(FileHandle *fh, PinName pwr, bool active_high, PinName rst)
68+
: AT_CellularDevice(fh),
69+
_active_high(active_high),
70+
_pwr_key(pwr, !_active_high),
71+
_rst(rst, !_active_high)
72+
{
73+
AT_CellularBase::set_cellular_properties(cellular_properties);
74+
}
75+
76+
CellularDevice *CellularDevice::get_default_instance()
77+
{
78+
static UARTSerial serial(MBED_CONF_QUECTEL_EC2X_TX,
79+
MBED_CONF_QUECTEL_EC2X_RX,
80+
MBED_CONF_QUECTEL_EC2X_BAUDRATE);
81+
#if defined(MBED_CONF_QUECTEL_EC2X_RTS) && defined(MBED_CONF_QUECTEL_EC2X_CTS)
82+
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_EC2X_RTS, MBED_CONF_QUECTEL_EC2X_CTS);
83+
#endif
84+
static QUECTEL_EC2X device(&serial,
85+
MBED_CONF_QUECTEL_EC2X_PWR,
86+
MBED_CONF_QUECTEL_EC2X_POLARITY,
87+
MBED_CONF_QUECTEL_EC2X_RST);
88+
return &device;
89+
}
90+
91+
nsapi_error_t QUECTEL_EC2X::press_power_button(uint32_t timeout)
92+
{
93+
_pwr_key = _active_high;
94+
ThisThread::sleep_for(timeout);
95+
_pwr_key = !_active_high;
96+
ThisThread::sleep_for(100);
97+
98+
return NSAPI_ERROR_OK;
99+
}
100+
101+
nsapi_error_t QUECTEL_EC2X::hard_power_on()
102+
{
103+
return press_power_button(600);
104+
}
105+
106+
nsapi_error_t QUECTEL_EC2X::hard_power_off()
107+
108+
{
109+
return press_power_button(750);
110+
}
111+
112+
nsapi_error_t QUECTEL_EC2X::soft_power_on()
113+
{
114+
if (_rst.is_connected()) {
115+
_rst = _active_high;
116+
ThisThread::sleep_for(460);
117+
_rst = !_active_high;
118+
ThisThread::sleep_for(100);
119+
120+
_at->lock();
121+
122+
_at->set_at_timeout(5000);
123+
_at->resp_start();
124+
_at->set_stop_tag("RDY");
125+
bool rdy = _at->consume_to_stop_tag();
126+
_at->set_stop_tag(OK);
127+
128+
_at->unlock();
129+
130+
if (!rdy) {
131+
return NSAPI_ERROR_DEVICE_ERROR;
132+
}
133+
}
134+
135+
return NSAPI_ERROR_OK;
136+
}
137+
138+
nsapi_error_t QUECTEL_EC2X::soft_power_off()
139+
{
140+
return hard_power_off();
141+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2019, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef QUECTEL_EC2X_H
19+
#define QUECTEL_EC2X_H
20+
21+
#include "DigitalOut.h"
22+
#include "AT_CellularDevice.h"
23+
24+
namespace mbed {
25+
26+
class QUECTEL_EC2X : public AT_CellularDevice {
27+
public:
28+
29+
/**
30+
* Constructs the Quectel EC2X series driver. It is mandatory to provide
31+
* a FileHandle object, the power pin and the polarity of the pin.
32+
* Providing reset pin is optional.
33+
*/
34+
QUECTEL_EC2X(FileHandle *fh, PinName pwr, bool active_high, PinName rst = NC);
35+
36+
virtual nsapi_error_t hard_power_on();
37+
virtual nsapi_error_t hard_power_off();
38+
virtual nsapi_error_t soft_power_on();
39+
virtual nsapi_error_t soft_power_off();
40+
41+
private:
42+
nsapi_error_t press_power_button(uint32_t timeout);
43+
bool _active_high;
44+
DigitalOut _pwr_key;
45+
DigitalOut _rst;
46+
};
47+
48+
} // namespace mbed
49+
50+
#endif // QUECTEL_EC2X_H
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "QUECTEL_EC2X",
3+
"config": {
4+
"tx": {
5+
"help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.",
6+
"value": null
7+
},
8+
"rx": {
9+
"help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.",
10+
"value": null
11+
},
12+
"rts": {
13+
"help": "RTS pin for serial connection",
14+
"value": null
15+
},
16+
"cts": {
17+
"help": "CTS pin for serial connection",
18+
"value": null
19+
},
20+
"pwr": {
21+
"help": "Power control pin",
22+
"value": null
23+
},
24+
"rst": {
25+
"help": "Reset control pin",
26+
"value": null
27+
},
28+
"polarity": {
29+
"help": "Pin polarity, 1 = Active high, 0 = Active low",
30+
"value": null
31+
},
32+
"baudrate" : {
33+
"help": "Serial connection baud rate",
34+
"value": 115200
35+
},
36+
"provide-default": {
37+
"help": "Provide as default CellularDevice [true/false]",
38+
"value": false
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)