diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 44ad1f4954..3ad93a3d09 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -21,6 +21,8 @@ #include "QUECTEL_BG96_CellularInformation.h" #include "QUECTEL_BG96_CellularContext.h" #include "CellularLog.h" +#include "DigitalOut.h" +#include "mbed_wait_api.h" using namespace mbed; using namespace events; @@ -74,6 +76,51 @@ void QUECTEL_BG96::set_ready_cb(Callback callback) _at->set_urc_handler(DEVICE_READY_URC, callback); } +nsapi_error_t QUECTEL_BG96::hard_power_on() +{ + DigitalOut ModemResetIn (MBED_CONF_QUECTEL_BG96_POWER); +printf("QUECTEL_BG96::hard_power_on\n"); + wait_ms(250); + ModemResetIn = 0; + wait_ms(250); + ModemResetIn = 1; + wait_ms(500); + wait_ms(250); + return NSAPI_ERROR_OK; +} +nsapi_error_t QUECTEL_BG96::soft_power_on() +{ + DigitalOut ModemPwrkey (MBED_CONF_QUECTEL_BG96_RESET); +printf("QUECTEL_BG96::soft_power_on\n"); + ModemPwrkey = 0; + wait_ms(100); + ModemPwrkey = 1; + wait_ms(500); + ModemPwrkey = 0; + wait_ms(500); +printf("wait for RDY\n"); + _at->lock(); + _at->set_at_timeout(60000); + _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_BG96::hard_power_off() +{ + DigitalOut ModemPwrkey (MBED_CONF_QUECTEL_BG96_POWER); +printf("QUECTEL_BG96::hard_power_off\n"); + ModemPwrkey = 1; + wait_ms(250); + ModemPwrkey = 0; + return NSAPI_ERROR_OK; +} #if MBED_CONF_QUECTEL_BG96_PROVIDE_DEFAULT #include "UARTSerial.h" CellularDevice *CellularDevice::get_default_instance() diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h index 324de491c8..2eaf197c49 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h @@ -40,6 +40,9 @@ protected: // AT_CellularDevice virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); virtual AT_CellularInformation *open_information_impl(ATHandler &at); virtual void set_ready_cb(Callback callback); + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); public: void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json b/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json index 9ad92a2ee6..01c7555612 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json +++ b/features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json @@ -24,6 +24,14 @@ "provide-default": { "help": "Provide as default CellularDevice [true/false]", "value": false + }, + "power": { + "help": "Modem's power key.", + "value": null + }, + "reset": { + "help": "Modem's reset key.", + "value": null } } }