Skip to content

Commit 32deaca

Browse files
committed
Merge pull request #308 from mazgch/master
[ublox c027] platform api to manage peripheral power supplies and level shifters
2 parents 30424b2 + a36ad6c commit 32deaca

File tree

3 files changed

+106
-25
lines changed

3 files changed

+106
-25
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2013 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "gpio_api.h"
17+
#include "wait_api.h"
18+
#include "C027_api.h"
19+
20+
static gpio_t mdmEn, mdmLvlOe, mdmILvlOe, mdmUsbDet;
21+
static gpio_t gpsEn;
22+
23+
void c027_init(void) {
24+
gpio_t led, mdmRts, mdmRst, gpsRst, mdmPwrOn;
25+
// start with modem disabled
26+
gpio_init_out_ex(&mdmEn, MDMEN, 0);
27+
gpio_init_out_ex(&mdmRst, MDMRST, 1);
28+
gpio_init_out_ex(&mdmPwrOn, MDMPWRON, 1);
29+
gpio_init_out_ex(&mdmLvlOe, MDMLVLOE, 1); // LVLEN: 1=disabled
30+
gpio_init_out_ex(&mdmILvlOe, MDMILVLOE, 0); // ILVLEN: 0=disabled
31+
gpio_init_out_ex(&mdmUsbDet, MDMUSBDET, 0);
32+
gpio_init_out_ex(&mdmRts, MDMRTS, 0);
33+
// start with gps disabled
34+
gpio_init_out_ex(&gpsEn, GPSEN, 0);
35+
gpio_init_out_ex(&gpsRst, GPSRST, 1);
36+
// led should be off
37+
gpio_init_out_ex(&led, LED, 0);
38+
39+
wait_ms(50); // when USB cable is inserted the interface chip issues
40+
}
41+
42+
void c027_mdm_powerOn(int usb) {
43+
// turn on the mode by enabling power with power on pin low and correct USB detect level
44+
gpio_write(&mdmUsbDet, usb ? 1 : 0); // USBDET: 0=disabled, 1=enabled
45+
if (!gpio_read(&mdmEn)) { // enable modem
46+
gpio_write(&mdmEn, 1); // LDOEN: 1=on
47+
wait_ms(1); // wait until supply switched off
48+
// now we can safely enable the level shifters
49+
gpio_write(&mdmLvlOe, 0); // LVLEN: 0=enabled (uart/gpio)
50+
if (gpio_read(&gpsEn))
51+
gpio_write(&mdmILvlOe, 1); // ILVLEN: 1=enabled (i2c)
52+
}
53+
}
54+
55+
void c027_mdm_powerOff(void) {
56+
if (gpio_read(&gpsEn)) {
57+
// diable all level shifters
58+
gpio_write(&mdmILvlOe, 0); // ILVLEN: 0=disabled (i2c)
59+
gpio_write(&mdmLvlOe, 1); // LVLEN: 1=disabled (uart/gpio)
60+
gpio_write(&mdmUsbDet, 0); // USBDET: 0=disabled
61+
// now we can savely switch off the ldo
62+
gpio_write(&mdmEn, 0); // LDOEN: 0=off
63+
}
64+
}
65+
66+
void c027_gps_powerOn(void) {
67+
if (!gpio_read(&gpsEn)) {
68+
// switch on power supply
69+
gpio_write(&gpsEn, 1); // LDOEN: 1=on
70+
wait_ms(1); // wait until supply switched off
71+
if (gpio_read(&mdmEn))
72+
gpio_write(&mdmILvlOe, 1); // ILVLEN: 1=enabled (i2c)
73+
}
74+
}
75+
76+
void c027_gps_powerOff(void) {
77+
if (gpio_read(&gpsEn)) {
78+
gpio_write(&mdmILvlOe, 0); // ILVLEN: 0=disabled (i2c)
79+
gpio_write(&gpsEn, 0); // LDOEN: 0=off
80+
}
81+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef C027_H
2+
#define C027_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
void c027_init(void);
9+
10+
void c027_mdm_powerOn(int usb);
11+
12+
void c027_mdm_powerOff(void);
13+
14+
void c027_gps_powerOn(void);
15+
16+
void c027_gps_powerOff(void);
17+
18+
#ifdef __cplusplus
19+
}
20+
#endif
21+
22+
#endif // C027_H

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_UBLOX_C027/mbed_overrides.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#include "gpio_api.h"
17-
#include "wait_api.h"
16+
#include "C027_api.h"
1817

1918
// called before main
20-
void mbed_sdk_init()
21-
{
22-
gpio_t modemEn, modemRst, modemPwrOn, modemLvlOe, modemILvlOe, modemUsbDet;
23-
gpio_t gpsEn, gpsRst, led, modemRts;
24-
25-
// start with modem disabled
26-
gpio_init_out_ex(&modemEn, MDMEN, 0);
27-
gpio_init_out_ex(&modemRst, MDMRST, 1);
28-
gpio_init_out_ex(&modemPwrOn, MDMPWRON, 1);
29-
gpio_init_out_ex(&modemLvlOe, MDMLVLOE, 1);
30-
gpio_init_out_ex(&modemILvlOe, MDMILVLOE, 0);
31-
gpio_init_out_ex(&modemUsbDet, MDMUSBDET, 0);
32-
gpio_init_out_ex(&modemRts, MDMRTS, 0);
33-
// start with gps disabled
34-
gpio_init_out_ex(&gpsEn, GPSEN, 0);
35-
gpio_init_out_ex(&gpsRst, GPSRST, 1);
36-
// led should be off
37-
gpio_init_out_ex(&led, LED, 0);
38-
39-
wait_ms(50); // when USB cable is inserted the interface chip issues
40-
// multiple resets to the target CPU We wait here for a short period to
41-
// prevent those resets from propagating to the modem and other
42-
// components.
19+
void mbed_sdk_init() {
20+
c027_init();
4321
}

0 commit comments

Comments
 (0)