Skip to content

Commit 93cb530

Browse files
pekkapesuAri Parkkila
authored andcommitted
add BG96 povermanagemet
1 parent 4d3f1a4 commit 93cb530

File tree

3 files changed

+69
-16
lines changed

3 files changed

+69
-16
lines changed

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,49 +78,97 @@ void QUECTEL_BG96::set_ready_cb(Callback<void()> callback)
7878

7979
nsapi_error_t QUECTEL_BG96::hard_power_on()
8080
{
81-
DigitalOut ModemResetIn (MBED_CONF_QUECTEL_BG96_POWER);
82-
printf("QUECTEL_BG96::hard_power_on\n");
81+
DigitalOut ModemResetIn (MBED_CONF_QUECTEL_BG96_PWR);
82+
8383
wait_ms(250);
8484
ModemResetIn = 0;
8585
wait_ms(250);
8686
ModemResetIn = 1;
8787
wait_ms(500);
88-
wait_ms(250);
88+
8989
return NSAPI_ERROR_OK;
9090
}
91+
9192
nsapi_error_t QUECTEL_BG96::soft_power_on()
9293
{
93-
DigitalOut ModemPwrkey (MBED_CONF_QUECTEL_BG96_RESET);
94-
printf("QUECTEL_BG96::soft_power_on\n");
94+
// turn moden on
95+
DigitalOut ModemPwrkey (MBED_CONF_QUECTEL_BG96_RST);
96+
9597
ModemPwrkey = 0;
9698
wait_ms(100);
9799
ModemPwrkey = 1;
98100
wait_ms(500);
99101
ModemPwrkey = 0;
100102
wait_ms(500);
101-
printf("wait for RDY\n");
103+
104+
// wait for RDY
102105
_at->lock();
103106
_at->set_at_timeout(60000);
104107
_at->resp_start();
105108
_at->set_stop_tag("RDY");
106109
bool rdy = _at->consume_to_stop_tag();
107110
_at->set_stop_tag(OK);
108111
_at->unlock();
112+
109113
if (!rdy)
110114
{
111115
return NSAPI_ERROR_DEVICE_ERROR;
112116
}
117+
113118
return NSAPI_ERROR_OK;
114119
}
120+
115121
nsapi_error_t QUECTEL_BG96::hard_power_off()
116122
{
117-
DigitalOut ModemPwrkey (MBED_CONF_QUECTEL_BG96_POWER);
118-
printf("QUECTEL_BG96::hard_power_off\n");
123+
// turn moden off
124+
DigitalOut ModemPwrkey (MBED_CONF_QUECTEL_BG96_PWR);
125+
119126
ModemPwrkey = 1;
120127
wait_ms(250);
121128
ModemPwrkey = 0;
129+
122130
return NSAPI_ERROR_OK;
123131
}
132+
133+
nsapi_error_t QUECTEL_BG96::init()
134+
{
135+
int retry = 0;
136+
137+
_at->lock();
138+
_at->flush();
139+
_at->cmd_start("ATE0"); // echo off
140+
_at->cmd_stop_read_resp();
141+
142+
_at->cmd_start("AT+CMEE=1"); // verbose responses
143+
_at->cmd_stop_read_resp();
144+
145+
if (_at->get_last_error() != NSAPI_ERROR_OK)
146+
{
147+
do
148+
{
149+
_at->cmd_start("AT+CFUN=1"); // set full functionality
150+
_at->cmd_stop_read_resp();
151+
152+
// CFUN executed ok
153+
if (_at->get_last_error() != NSAPI_ERROR_OK)
154+
{
155+
// wait some time that modem gets ready for CFUN command, and try again
156+
retry++;
157+
_at->flush();
158+
wait_ms(64);
159+
}
160+
else
161+
{
162+
// yes continue
163+
break;
164+
}
165+
166+
/* code */
167+
} while ( (retry < 3) );
168+
}
169+
return _at->unlock_return_error();
170+
}
171+
124172
#if MBED_CONF_QUECTEL_BG96_PROVIDE_DEFAULT
125173
#include "UARTSerial.h"
126174
CellularDevice *CellularDevice::get_default_instance()

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class QUECTEL_BG96 : public AT_CellularDevice {
4343
virtual nsapi_error_t hard_power_on();
4444
virtual nsapi_error_t hard_power_off();
4545
virtual nsapi_error_t soft_power_on();
46+
virtual nsapi_error_t init();
4647

4748
public:
4849
void handle_urc(FileHandle *fh);

features/cellular/framework/targets/QUECTEL/BG96/mbed_lib.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@
1717
"help": "CTS pin for serial connection",
1818
"value": null
1919
},
20+
"pwr": {
21+
"help": "Power control pin",
22+
"value": null
23+
},
24+
"rst": {
25+
"help": "Reset control pin",
26+
"value": null
27+
},
28+
"polarity": {
29+
"help": "Pin polarity, 1 = Active high, 0 = Active low",
30+
"value": null
31+
},
2032
"baudrate" : {
2133
"help": "Serial connection baud rate",
2234
"value": 115200
2335
},
2436
"provide-default": {
2537
"help": "Provide as default CellularDevice [true/false]",
2638
"value": false
27-
},
28-
"power": {
29-
"help": "Modem's power key.",
30-
"value": null
31-
},
32-
"reset": {
33-
"help": "Modem's reset key.",
34-
"value": null
3539
}
3640
}
3741
}

0 commit comments

Comments
 (0)