Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
#if MBED_CONF_NSAPI_PRESENT

#include "ONBOARD_UBLOX_PPP.h"

#include "ublox_low_level_api.h"
#include "gpio_api.h"
#include "platform/mbed_thread.h"
#include "PinNames.h"

#include "UBLOX_onboard_modem_api.h"
#include "drivers/BufferedSerial.h"
#include "CellularLog.h"

Expand All @@ -34,47 +29,28 @@ ONBOARD_UBLOX_PPP::ONBOARD_UBLOX_PPP(FileHandle *fh) : UBLOX_PPP(fh)

nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_on()
{
//currently USB is not supported, so pass 0 to disable USB
//This call does everything except actually pressing the power button
ublox_mdm_powerOn(0);

::onboard_modem_init();
return NSAPI_ERROR_OK;
}

nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_off()
{
ublox_mdm_powerOff();

::onboard_modem_deinit();
return NSAPI_ERROR_OK;
}

nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_on()
{
/* keep the power line low for 150 milisecond */
press_power_button(150);
/* give modem a little time to respond */
thread_sleep_for(100);

::onboard_modem_power_up();
return NSAPI_ERROR_OK;
}

nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_off()
{
/* keep the power line low for 1 second */
press_power_button(1000);

::onboard_modem_power_down();
return NSAPI_ERROR_OK;
}

void ONBOARD_UBLOX_PPP::press_power_button(int time_ms)
{
gpio_t gpio;

gpio_init_out_ex(&gpio, MDMPWRON, 0);
thread_sleep_for(time_ms);
gpio_write(&gpio, 1);
}

CellularDevice *CellularDevice::get_target_default_instance()
{
static BufferedSerial serial(MDMTXD, MDMRXD, 115200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class ONBOARD_UBLOX_PPP : public UBLOX_PPP {
virtual nsapi_error_t hard_power_off();
virtual nsapi_error_t soft_power_on();
virtual nsapi_error_t soft_power_off();

private:
void press_power_button(int time_ms);
};

} // namespace mbed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* mbed Microcontroller Library
* Copyright (c) 2020 ARM Limited
* 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.
*/

#if MBED_CONF_NSAPI_PRESENT

#include "UBLOX_onboard_modem_api.h"
#include "gpio_api.h"
#include "platform/mbed_wait_api.h"
#include "platform/mbed_thread.h"
#include "PinNames.h"

static void press_power_button(time_ms)
{
gpio_t gpio;

gpio_init_out_ex(&gpio, MDMPWRON, 0);
thread_sleep_for(time_ms);
gpio_write(&gpio, 1);
}

void onboard_modem_init()
{
//currently USB is not supported, so pass 0 to disable USB
//This call does everything except actually pressing the power button
ublox_mdm_powerOn(0);
}

void onboard_modem_deinit()
{
ublox_mdm_powerOff();
}

void onboard_modem_power_up()
{
/* keep the power line low for 150 microseconds */
press_power_button(150);

/* give modem a little time to respond */
thread_sleep_for(100);
}

void onboard_modem_power_down()
{
/* keep the power line low for 1 seconds */
press_power_button(1000);
}

#endif //MBED_CONF_NSAPI_PRESENT
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* mbed Microcontroller Library
* Copyright (c) 2020 ARM Limited
* 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 UBLOX_ONBOARD_MODEM_API_H_
#define UBLOX_ONBOARD_MODEM_API_H_

#ifdef __cplusplus
extern "C" {
#endif

/** Sets the modem up for powering on
* modem_init() will be equivalent to plugging in the device, i.e.,
* attaching power and serial port.
*/
void onboard_modem_init(void);

/** Sets the modem in unplugged state
* modem_deinit() will be equivalent to pulling the plug off of the device, i.e.,
* detaching power and serial port.
* This puts the modem in lowest power state.
*/
void onboard_modem_deinit(void);

/** Powers up the modem
* modem_power_up() will be equivalent to pressing the soft power button.
* The driver may repeat this if the modem is not responsive to AT commands.

*/
void onboard_modem_power_up(void);

/** Powers down the modem
* modem_power_down() will be equivalent to turning off the modem by button press.
*/
void onboard_modem_power_down(void);

#ifdef __cplusplus
}
#endif

#endif /* UBLOX_ONBOARD_MODEM_API_H_ */