Skip to content

Commit

Permalink
Adding pin polarity and changing the constructor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hasnain Virk committed Apr 8, 2019
1 parent 57d9e27 commit 7ebfa90
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
62 changes: 36 additions & 26 deletions features/cellular/framework/targets/QUECTEL/EC2X/QUECTEL_EC2X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ 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_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
Expand All @@ -43,16 +55,15 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
1, // PROPERTY_AT_CGEREP
};

QUECTEL_EC2X::QUECTEL_EC2X(FileHandle *fh, PinName pwr, PinName rst)
QUECTEL_EC2X::QUECTEL_EC2X(FileHandle *fh, PinName pwr, bool active_high, PinName rst)
: AT_CellularDevice(fh),
_pwr_key(pwr, 0),
_rst(rst, 0)

_active_high(active_high),
_pwr_key(pwr, !_active_high),
_rst(rst, !_active_high)
{
AT_CellularBase::set_cellular_properties(cellular_properties);
}

#if MBED_CONF_QUECTEL_EC2X_PROVIDE_DEFAULT
#include "UARTSerial.h"
CellularDevice *CellularDevice::get_default_instance()
{
Expand All @@ -62,18 +73,19 @@ CellularDevice *CellularDevice::get_default_instance()
#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_RST);
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)
{
if (_pwr_key.is_connected()) {
_pwr_key = 1;
ThisThread::sleep_for(timeout);
_pwr_key = 0;
ThisThread::sleep_for(100);
}
_pwr_key = _active_high;
ThisThread::sleep_for(timeout);
_pwr_key = !_active_high;
ThisThread::sleep_for(100);

return NSAPI_ERROR_OK;
}
Expand All @@ -92,24 +104,24 @@ nsapi_error_t QUECTEL_EC2X::hard_power_off()
nsapi_error_t QUECTEL_EC2X::soft_power_on()
{
if (_rst.is_connected()) {
_rst = 1;
_rst = _active_high;
ThisThread::sleep_for(460);
_rst = 0;
_rst = !_active_high;
ThisThread::sleep_for(100);
}

_at->lock();
_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->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();
_at->unlock();

if (!rdy) {
return NSAPI_ERROR_DEVICE_ERROR;
if (!rdy) {
return NSAPI_ERROR_DEVICE_ERROR;
}
}

return NSAPI_ERROR_OK;
Expand All @@ -119,5 +131,3 @@ nsapi_error_t QUECTEL_EC2X::soft_power_off()
{
return hard_power_off();
}

#endif
19 changes: 9 additions & 10 deletions features/cellular/framework/targets/QUECTEL/EC2X/QUECTEL_EC2X.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,29 @@
#ifndef QUECTEL_EC2X_H
#define QUECTEL_EC2X_H

#ifdef TARGET_FF_ARDUINO
#ifndef MBED_CONF_QUECTEL_EC2X_TX
#define MBED_CONF_QUECTEL_EC2X_TX D1
#endif
#ifndef MBED_CONF_QUECTEL_EC2X_RX
#define MBED_CONF_QUECTEL_EC2X_RX D0
#endif
#endif /* TARGET_FF_ARDUINO */

#include "DigitalOut.h"
#include "AT_CellularDevice.h"

namespace mbed {

class QUECTEL_EC2X : public AT_CellularDevice {
public:
QUECTEL_EC2X(FileHandle *fh, PinName pwr = NC, PinName rst = NC);

/**
* 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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"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
Expand Down

0 comments on commit 7ebfa90

Please sign in to comment.