@@ -25,6 +25,18 @@ using namespace mbed;
25
25
using namespace rtos ;
26
26
using namespace events ;
27
27
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
+
28
40
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
29
41
AT_CellularNetwork::RegistrationModeLAC, // C_EREG
30
42
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
@@ -43,16 +55,15 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
43
55
1 , // PROPERTY_AT_CGEREP
44
56
};
45
57
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)
47
59
: 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)
51
63
{
52
64
AT_CellularBase::set_cellular_properties (cellular_properties);
53
65
}
54
66
55
- #if MBED_CONF_QUECTEL_EC2X_PROVIDE_DEFAULT
56
67
#include " UARTSerial.h"
57
68
CellularDevice *CellularDevice::get_default_instance ()
58
69
{
@@ -62,18 +73,19 @@ CellularDevice *CellularDevice::get_default_instance()
62
73
#if defined(MBED_CONF_QUECTEL_EC2X_RTS) && defined(MBED_CONF_QUECTEL_EC2X_CTS)
63
74
serial.set_flow_control (SerialBase::RTSCTS, MBED_CONF_QUECTEL_EC2X_RTS, MBED_CONF_QUECTEL_EC2X_CTS);
64
75
#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);
66
80
return &device;
67
81
}
68
82
69
83
nsapi_error_t QUECTEL_EC2X::press_power_button (uint32_t timeout)
70
84
{
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 );
77
89
78
90
return NSAPI_ERROR_OK;
79
91
}
@@ -92,24 +104,24 @@ nsapi_error_t QUECTEL_EC2X::hard_power_off()
92
104
nsapi_error_t QUECTEL_EC2X::soft_power_on ()
93
105
{
94
106
if (_rst.is_connected ()) {
95
- _rst = 1 ;
107
+ _rst = _active_high ;
96
108
ThisThread::sleep_for (460 );
97
- _rst = 0 ;
109
+ _rst = !_active_high ;
98
110
ThisThread::sleep_for (100 );
99
- }
100
111
101
- _at->lock ();
112
+ _at->lock ();
102
113
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);
108
119
109
- _at->unlock ();
120
+ _at->unlock ();
110
121
111
- if (!rdy) {
112
- return NSAPI_ERROR_DEVICE_ERROR;
122
+ if (!rdy) {
123
+ return NSAPI_ERROR_DEVICE_ERROR;
124
+ }
113
125
}
114
126
115
127
return NSAPI_ERROR_OK;
@@ -119,5 +131,3 @@ nsapi_error_t QUECTEL_EC2X::soft_power_off()
119
131
{
120
132
return hard_power_off ();
121
133
}
122
-
123
- #endif
0 commit comments