Skip to content

Commit d308da1

Browse files
authored
Merge pull request #12610 from u-blox/ubx_modem_api
Add UBLOX_onboard_modem_api for power up UBLOX_C027.
2 parents f03860a + bf65342 commit d308da1

File tree

4 files changed

+121
-32
lines changed

4 files changed

+121
-32
lines changed

targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.cpp

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
#if MBED_CONF_NSAPI_PRESENT
1818

1919
#include "ONBOARD_UBLOX_PPP.h"
20-
21-
#include "ublox_low_level_api.h"
22-
#include "gpio_api.h"
23-
#include "platform/mbed_thread.h"
24-
#include "PinNames.h"
25-
20+
#include "UBLOX_onboard_modem_api.h"
2621
#include "drivers/BufferedSerial.h"
2722
#include "CellularLog.h"
2823

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

3530
nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_on()
3631
{
37-
//currently USB is not supported, so pass 0 to disable USB
38-
//This call does everything except actually pressing the power button
39-
ublox_mdm_powerOn(0);
40-
32+
::onboard_modem_init();
4133
return NSAPI_ERROR_OK;
4234
}
4335

4436
nsapi_error_t ONBOARD_UBLOX_PPP::hard_power_off()
4537
{
46-
ublox_mdm_powerOff();
47-
38+
::onboard_modem_deinit();
4839
return NSAPI_ERROR_OK;
4940
}
5041

5142
nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_on()
5243
{
53-
/* keep the power line low for 150 milisecond */
54-
press_power_button(150);
55-
/* give modem a little time to respond */
56-
thread_sleep_for(100);
57-
44+
::onboard_modem_power_up();
5845
return NSAPI_ERROR_OK;
5946
}
6047

6148
nsapi_error_t ONBOARD_UBLOX_PPP::soft_power_off()
6249
{
63-
/* keep the power line low for 1 second */
64-
press_power_button(1000);
65-
50+
::onboard_modem_power_down();
6651
return NSAPI_ERROR_OK;
6752
}
6853

69-
void ONBOARD_UBLOX_PPP::press_power_button(int time_ms)
70-
{
71-
gpio_t gpio;
72-
73-
gpio_init_out_ex(&gpio, MDMPWRON, 0);
74-
thread_sleep_for(time_ms);
75-
gpio_write(&gpio, 1);
76-
}
77-
7854
CellularDevice *CellularDevice::get_target_default_instance()
7955
{
8056
static BufferedSerial serial(MDMTXD, MDMRXD, 115200);

targets/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/ONBOARD_UBLOX_PPP.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class ONBOARD_UBLOX_PPP : public UBLOX_PPP {
2929
virtual nsapi_error_t hard_power_off();
3030
virtual nsapi_error_t soft_power_on();
3131
virtual nsapi_error_t soft_power_off();
32-
33-
private:
34-
void press_power_button(int time_ms);
3532
};
3633

3734
} // namespace mbed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2020 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#if MBED_CONF_NSAPI_PRESENT
19+
20+
#include "UBLOX_onboard_modem_api.h"
21+
#include "gpio_api.h"
22+
#include "platform/mbed_wait_api.h"
23+
#include "platform/mbed_thread.h"
24+
#include "PinNames.h"
25+
26+
static void press_power_button(time_ms)
27+
{
28+
gpio_t gpio;
29+
30+
gpio_init_out_ex(&gpio, MDMPWRON, 0);
31+
thread_sleep_for(time_ms);
32+
gpio_write(&gpio, 1);
33+
}
34+
35+
void onboard_modem_init()
36+
{
37+
//currently USB is not supported, so pass 0 to disable USB
38+
//This call does everything except actually pressing the power button
39+
ublox_mdm_powerOn(0);
40+
}
41+
42+
void onboard_modem_deinit()
43+
{
44+
ublox_mdm_powerOff();
45+
}
46+
47+
void onboard_modem_power_up()
48+
{
49+
/* keep the power line low for 150 microseconds */
50+
press_power_button(150);
51+
52+
/* give modem a little time to respond */
53+
thread_sleep_for(100);
54+
}
55+
56+
void onboard_modem_power_down()
57+
{
58+
/* keep the power line low for 1 seconds */
59+
press_power_button(1000);
60+
}
61+
62+
#endif //MBED_CONF_NSAPI_PRESENT
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2020 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef UBLOX_ONBOARD_MODEM_API_H_
19+
#define UBLOX_ONBOARD_MODEM_API_H_
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
/** Sets the modem up for powering on
26+
* modem_init() will be equivalent to plugging in the device, i.e.,
27+
* attaching power and serial port.
28+
*/
29+
void onboard_modem_init(void);
30+
31+
/** Sets the modem in unplugged state
32+
* modem_deinit() will be equivalent to pulling the plug off of the device, i.e.,
33+
* detaching power and serial port.
34+
* This puts the modem in lowest power state.
35+
*/
36+
void onboard_modem_deinit(void);
37+
38+
/** Powers up the modem
39+
* modem_power_up() will be equivalent to pressing the soft power button.
40+
* The driver may repeat this if the modem is not responsive to AT commands.
41+
42+
*/
43+
void onboard_modem_power_up(void);
44+
45+
/** Powers down the modem
46+
* modem_power_down() will be equivalent to turning off the modem by button press.
47+
*/
48+
void onboard_modem_power_down(void);
49+
50+
#ifdef __cplusplus
51+
}
52+
#endif
53+
54+
#endif /* UBLOX_ONBOARD_MODEM_API_H_ */

0 commit comments

Comments
 (0)