Skip to content

Commit 7ebfa90

Browse files
author
Hasnain Virk
committed
Adding pin polarity and changing the constructor
To make this driver more useful, we needed to do some changes. The wirings for the modem can differ on the board so we also need to be flexible in our approach. It is now mandatory to provide the power pin and pin polarity in the constructor alongwith the file handle. Reset pin is optional.
1 parent 57d9e27 commit 7ebfa90

File tree

3 files changed

+49
-36
lines changed

3 files changed

+49
-36
lines changed

features/cellular/framework/targets/QUECTEL/EC2X/QUECTEL_EC2X.cpp

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ using namespace mbed;
2525
using namespace rtos;
2626
using namespace events;
2727

28+
#if !defined(MBED_CONF_QUECTEL_EC2X_PWR)
29+
#define MBED_CONF_QUECTEL_EC2X_PWR NC
30+
#endif
31+
32+
#if !defined(MBED_CONF_QUECTEL_EC2X_RST)
33+
#define MBED_CONF_QUECTEL_EC2X_RST NC
34+
#endif
35+
36+
#if !defined(MBED_CONF_QUECTEL_EC2X_POLARITY)
37+
#define MBED_CONF_QUECTEL_EC2X_POLARITY 1 // active high
38+
#endif
39+
2840
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
2941
AT_CellularNetwork::RegistrationModeLAC, // C_EREG
3042
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
@@ -43,16 +55,15 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
4355
1, // PROPERTY_AT_CGEREP
4456
};
4557

46-
QUECTEL_EC2X::QUECTEL_EC2X(FileHandle *fh, PinName pwr, PinName rst)
58+
QUECTEL_EC2X::QUECTEL_EC2X(FileHandle *fh, PinName pwr, bool active_high, PinName rst)
4759
: AT_CellularDevice(fh),
48-
_pwr_key(pwr, 0),
49-
_rst(rst, 0)
50-
60+
_active_high(active_high),
61+
_pwr_key(pwr, !_active_high),
62+
_rst(rst, !_active_high)
5163
{
5264
AT_CellularBase::set_cellular_properties(cellular_properties);
5365
}
5466

55-
#if MBED_CONF_QUECTEL_EC2X_PROVIDE_DEFAULT
5667
#include "UARTSerial.h"
5768
CellularDevice *CellularDevice::get_default_instance()
5869
{
@@ -62,18 +73,19 @@ CellularDevice *CellularDevice::get_default_instance()
6273
#if defined(MBED_CONF_QUECTEL_EC2X_RTS) && defined(MBED_CONF_QUECTEL_EC2X_CTS)
6374
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_EC2X_RTS, MBED_CONF_QUECTEL_EC2X_CTS);
6475
#endif
65-
static QUECTEL_EC2X device(&serial, MBED_CONF_QUECTEL_EC2X_PWR, MBED_CONF_QUECTEL_EC2X_RST);
76+
static QUECTEL_EC2X device(&serial,
77+
MBED_CONF_QUECTEL_EC2X_PWR,
78+
MBED_CONF_QUECTEL_EC2X_POLARITY,
79+
MBED_CONF_QUECTEL_EC2X_RST);
6680
return &device;
6781
}
6882

6983
nsapi_error_t QUECTEL_EC2X::press_power_button(uint32_t timeout)
7084
{
71-
if (_pwr_key.is_connected()) {
72-
_pwr_key = 1;
73-
ThisThread::sleep_for(timeout);
74-
_pwr_key = 0;
75-
ThisThread::sleep_for(100);
76-
}
85+
_pwr_key = _active_high;
86+
ThisThread::sleep_for(timeout);
87+
_pwr_key = !_active_high;
88+
ThisThread::sleep_for(100);
7789

7890
return NSAPI_ERROR_OK;
7991
}
@@ -92,24 +104,24 @@ nsapi_error_t QUECTEL_EC2X::hard_power_off()
92104
nsapi_error_t QUECTEL_EC2X::soft_power_on()
93105
{
94106
if (_rst.is_connected()) {
95-
_rst = 1;
107+
_rst = _active_high;
96108
ThisThread::sleep_for(460);
97-
_rst = 0;
109+
_rst = !_active_high;
98110
ThisThread::sleep_for(100);
99-
}
100111

101-
_at->lock();
112+
_at->lock();
102113

103-
_at->set_at_timeout(5000);
104-
_at->resp_start();
105-
_at->set_stop_tag("RDY");
106-
bool rdy = _at->consume_to_stop_tag();
107-
_at->set_stop_tag(OK);
114+
_at->set_at_timeout(5000);
115+
_at->resp_start();
116+
_at->set_stop_tag("RDY");
117+
bool rdy = _at->consume_to_stop_tag();
118+
_at->set_stop_tag(OK);
108119

109-
_at->unlock();
120+
_at->unlock();
110121

111-
if (!rdy) {
112-
return NSAPI_ERROR_DEVICE_ERROR;
122+
if (!rdy) {
123+
return NSAPI_ERROR_DEVICE_ERROR;
124+
}
113125
}
114126

115127
return NSAPI_ERROR_OK;
@@ -119,5 +131,3 @@ nsapi_error_t QUECTEL_EC2X::soft_power_off()
119131
{
120132
return hard_power_off();
121133
}
122-
123-
#endif

features/cellular/framework/targets/QUECTEL/EC2X/QUECTEL_EC2X.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,29 @@
1818
#ifndef QUECTEL_EC2X_H
1919
#define QUECTEL_EC2X_H
2020

21-
#ifdef TARGET_FF_ARDUINO
22-
#ifndef MBED_CONF_QUECTEL_EC2X_TX
23-
#define MBED_CONF_QUECTEL_EC2X_TX D1
24-
#endif
25-
#ifndef MBED_CONF_QUECTEL_EC2X_RX
26-
#define MBED_CONF_QUECTEL_EC2X_RX D0
27-
#endif
28-
#endif /* TARGET_FF_ARDUINO */
29-
3021
#include "DigitalOut.h"
3122
#include "AT_CellularDevice.h"
3223

3324
namespace mbed {
3425

3526
class QUECTEL_EC2X : public AT_CellularDevice {
3627
public:
37-
QUECTEL_EC2X(FileHandle *fh, PinName pwr = NC, PinName rst = NC);
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+
3836
virtual nsapi_error_t hard_power_on();
3937
virtual nsapi_error_t hard_power_off();
4038
virtual nsapi_error_t soft_power_on();
4139
virtual nsapi_error_t soft_power_off();
4240

4341
private:
4442
nsapi_error_t press_power_button(uint32_t timeout);
43+
bool _active_high;
4544
DigitalOut _pwr_key;
4645
DigitalOut _rst;
4746
};

features/cellular/framework/targets/QUECTEL/EC2X/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
"help": "Reset control pin",
2626
"value": null
2727
},
28+
"polarity": {
29+
"help": "Pin polarity, 1 = Active high, 0 = Active low",
30+
"value": null
31+
},
2832
"baudrate" : {
2933
"help": "Serial connection baud rate",
3034
"value": 115200

0 commit comments

Comments
 (0)