-
Notifications
You must be signed in to change notification settings - Fork 3k
Cellular: Basic driver for Quectel EC25/EC21 #10292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
04299e4
Basic driver for Quectel EC25/EC21
ab978bd
Removing left over tracing
df7f8cd
CREG can handle lac/ci/lat
24178bc
AT+CGSN with EC2X does not take parameter
57d9e27
Tidying up the boiler plate code
7ebfa90
Adding pin polarity and changing the constructor
69efed2
Marking TX and RX pins for UARTSerial as NC
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
features/cellular/framework/targets/QUECTEL/EC2X/QUECTEL_EC2X.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright (c) 2019, Arm Limited and affiliates. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "QUECTEL_EC2X.h" | ||
|
||
#include "PinNames.h" | ||
#include "AT_CellularNetwork.h" | ||
#include "rtos/ThisThread.h" | ||
#include "UARTSerial.h" | ||
|
||
using namespace mbed; | ||
using namespace rtos; | ||
using namespace events; | ||
|
||
#if !defined(MBED_CONF_QUECTEL_EC2X_PWR) | ||
#define MBED_CONF_QUECTEL_EC2X_PWR NC | ||
#endif | ||
|
||
#if !defined(MBED_CONF_QUECTEL_EC2X_RST) | ||
#define MBED_CONF_QUECTEL_EC2X_RST NC | ||
#endif | ||
|
||
#if !defined(MBED_CONF_QUECTEL_EC2X_TX) | ||
#define MBED_CONF_QUECTEL_EC2X_TX NC | ||
#endif | ||
|
||
#if !defined(MBED_CONF_QUECTEL_EC2X_RX) | ||
#define MBED_CONF_QUECTEL_EC2X_RX NC | ||
#endif | ||
|
||
#if !defined(MBED_CONF_QUECTEL_EC2X_POLARITY) | ||
#define MBED_CONF_QUECTEL_EC2X_POLARITY 1 // active high | ||
#endif | ||
|
||
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { | ||
AT_CellularNetwork::RegistrationModeLAC, // C_EREG | ||
AT_CellularNetwork::RegistrationModeLAC, // C_GREG | ||
AT_CellularNetwork::RegistrationModeLAC, // C_REG | ||
0, // AT_CGSN_WITH_TYPE | ||
1, // AT_CGDATA | ||
0, // AT_CGAUTH | ||
1, // AT_CNMI | ||
1, // AT_CSMP | ||
1, // AT_CMGF | ||
1, // AT_CSDH | ||
1, // PROPERTY_IPV4_STACK | ||
1, // PROPERTY_IPV6_STACK | ||
1, // PROPERTY_IPV4V6_STACK | ||
0, // PROPERTY_NON_IP_PDP_TYPE | ||
1, // PROPERTY_AT_CGEREP | ||
}; | ||
|
||
QUECTEL_EC2X::QUECTEL_EC2X(FileHandle *fh, PinName pwr, bool active_high, PinName rst) | ||
: AT_CellularDevice(fh), | ||
_active_high(active_high), | ||
_pwr_key(pwr, !_active_high), | ||
_rst(rst, !_active_high) | ||
{ | ||
AT_CellularBase::set_cellular_properties(cellular_properties); | ||
} | ||
|
||
CellularDevice *CellularDevice::get_default_instance() | ||
{ | ||
static UARTSerial serial(MBED_CONF_QUECTEL_EC2X_TX, | ||
MBED_CONF_QUECTEL_EC2X_RX, | ||
MBED_CONF_QUECTEL_EC2X_BAUDRATE); | ||
#if defined(MBED_CONF_QUECTEL_EC2X_RTS) && defined(MBED_CONF_QUECTEL_EC2X_CTS) | ||
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_EC2X_RTS, MBED_CONF_QUECTEL_EC2X_CTS); | ||
#endif | ||
static QUECTEL_EC2X device(&serial, | ||
MBED_CONF_QUECTEL_EC2X_PWR, | ||
MBED_CONF_QUECTEL_EC2X_POLARITY, | ||
MBED_CONF_QUECTEL_EC2X_RST); | ||
return &device; | ||
} | ||
|
||
nsapi_error_t QUECTEL_EC2X::press_power_button(uint32_t timeout) | ||
{ | ||
_pwr_key = _active_high; | ||
ThisThread::sleep_for(timeout); | ||
_pwr_key = !_active_high; | ||
ThisThread::sleep_for(100); | ||
|
||
return NSAPI_ERROR_OK; | ||
} | ||
|
||
nsapi_error_t QUECTEL_EC2X::hard_power_on() | ||
{ | ||
return press_power_button(600); | ||
} | ||
|
||
nsapi_error_t QUECTEL_EC2X::hard_power_off() | ||
|
||
{ | ||
return press_power_button(750); | ||
} | ||
|
||
nsapi_error_t QUECTEL_EC2X::soft_power_on() | ||
{ | ||
if (_rst.is_connected()) { | ||
_rst = _active_high; | ||
ThisThread::sleep_for(460); | ||
_rst = !_active_high; | ||
ThisThread::sleep_for(100); | ||
|
||
_at->lock(); | ||
|
||
_at->set_at_timeout(5000); | ||
_at->resp_start(); | ||
_at->set_stop_tag("RDY"); | ||
bool rdy = _at->consume_to_stop_tag(); | ||
_at->set_stop_tag(OK); | ||
|
||
_at->unlock(); | ||
|
||
if (!rdy) { | ||
return NSAPI_ERROR_DEVICE_ERROR; | ||
} | ||
} | ||
|
||
return NSAPI_ERROR_OK; | ||
} | ||
|
||
nsapi_error_t QUECTEL_EC2X::soft_power_off() | ||
{ | ||
return hard_power_off(); | ||
} |
50 changes: 50 additions & 0 deletions
50
features/cellular/framework/targets/QUECTEL/EC2X/QUECTEL_EC2X.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2019, Arm Limited and affiliates. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef QUECTEL_EC2X_H | ||
#define QUECTEL_EC2X_H | ||
|
||
#include "DigitalOut.h" | ||
#include "AT_CellularDevice.h" | ||
|
||
namespace mbed { | ||
|
||
class QUECTEL_EC2X : public AT_CellularDevice { | ||
public: | ||
|
||
/** | ||
* Constructs the Quectel EC2X series driver. It is mandatory to provide | ||
* a FileHandle object, the power pin and the polarity of the pin. | ||
* Providing reset pin is optional. | ||
*/ | ||
QUECTEL_EC2X(FileHandle *fh, PinName pwr, bool active_high, PinName rst = NC); | ||
|
||
virtual nsapi_error_t hard_power_on(); | ||
virtual nsapi_error_t hard_power_off(); | ||
virtual nsapi_error_t soft_power_on(); | ||
virtual nsapi_error_t soft_power_off(); | ||
|
||
private: | ||
nsapi_error_t press_power_button(uint32_t timeout); | ||
bool _active_high; | ||
DigitalOut _pwr_key; | ||
DigitalOut _rst; | ||
}; | ||
|
||
} // namespace mbed | ||
|
||
#endif // QUECTEL_EC2X_H |
41 changes: 41 additions & 0 deletions
41
features/cellular/framework/targets/QUECTEL/EC2X/mbed_lib.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "QUECTEL_EC2X", | ||
"config": { | ||
"tx": { | ||
"help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", | ||
"value": null | ||
}, | ||
"rx": { | ||
"help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", | ||
"value": null | ||
}, | ||
"rts": { | ||
"help": "RTS pin for serial connection", | ||
"value": null | ||
}, | ||
"cts": { | ||
"help": "CTS pin for serial connection", | ||
"value": null | ||
}, | ||
"pwr": { | ||
"help": "Power control pin", | ||
"value": null | ||
}, | ||
"rst": { | ||
"help": "Reset control pin", | ||
"value": null | ||
}, | ||
"polarity": { | ||
"help": "Pin polarity, 1 = Active high, 0 = Active low", | ||
"value": null | ||
}, | ||
"baudrate" : { | ||
"help": "Serial connection baud rate", | ||
"value": 115200 | ||
}, | ||
"provide-default": { | ||
"help": "Provide as default CellularDevice [true/false]", | ||
"value": false | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.