Skip to content

Commit f8e0d9c

Browse files
committed
added a api to manage the power supplies of peripheral power supplies and level shifters
1 parent 7bc41ef commit f8e0d9c

File tree

3 files changed

+114
-23
lines changed

3 files changed

+114
-23
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
{
25+
gpio_t led, mdmRts, mdmRst, gpsRst, mdmPwrOn;
26+
// start with modem disabled
27+
gpio_init_out_ex(&mdmEn, MDMEN, 0);
28+
gpio_init_out_ex(&mdmRst, MDMRST, 1);
29+
gpio_init_out_ex(&mdmPwrOn, MDMPWRON, 1);
30+
gpio_init_out_ex(&mdmLvlOe, MDMLVLOE, 1); // LVLEN: 1=disabled
31+
gpio_init_out_ex(&mdmILvlOe, MDMILVLOE, 0); // ILVLEN: 0=disabled
32+
gpio_init_out_ex(&mdmUsbDet, MDMUSBDET, 0);
33+
gpio_init_out_ex(&mdmRts, MDMRTS, 0);
34+
// start with gps disabled
35+
gpio_init_out_ex(&gpsEn, GPSEN, 0);
36+
gpio_init_out_ex(&gpsRst, GPSRST, 1);
37+
// led should be off
38+
gpio_init_out_ex(&led, LED, 0);
39+
40+
wait_ms(50); // when USB cable is inserted the interface chip issues
41+
}
42+
43+
void c027_mdm_powerOn(int usb)
44+
{
45+
// turn on the mode by enabling power with power on pin low and correct USB detect level
46+
gpio_write(&mdmUsbDet, usb ? 1 : 0); // USBDET: 0=disabled, 1=enabled
47+
if (!gpio_read(&mdmEn)) // enable modem
48+
{
49+
gpio_write(&mdmEn, 1); // LDOEN: 1=on
50+
wait_ms(1); // wait until supply switched off
51+
// now we can safely enable the level shifters
52+
gpio_write(&mdmLvlOe, 0); // LVLEN: 0=enabled (uart/gpio)
53+
if (gpio_read(&gpsEn))
54+
gpio_write(&mdmILvlOe, 1); // ILVLEN: 1=enabled (i2c)
55+
}
56+
}
57+
58+
void c027_mdm_powerOff(void)
59+
{
60+
if (gpio_read(&gpsEn))
61+
{
62+
// diable all level shifters
63+
gpio_write(&mdmILvlOe, 0); // ILVLEN: 0=disabled (i2c)
64+
gpio_write(&mdmLvlOe, 1); // LVLEN: 1=disabled (uart/gpio)
65+
gpio_write(&mdmUsbDet, 0); // USBDET: 0=disabled
66+
// now we can savely switch off the ldo
67+
gpio_write(&mdmEn, 0); // LDOEN: 0=off
68+
}
69+
}
70+
71+
void c027_gps_powerOn(void)
72+
{
73+
if (!gpio_read(&gpsEn))
74+
{
75+
// switch on power supply
76+
gpio_write(&gpsEn, 1); // LDOEN: 1=on
77+
wait_ms(1); // wait until supply switched off
78+
if (gpio_read(&mdmEn))
79+
gpio_write(&mdmILvlOe, 1); // ILVLEN: 1=enabled (i2c)
80+
}
81+
}
82+
83+
void c027_gps_powerOff(void)
84+
{
85+
if (gpio_read(&gpsEn))
86+
{
87+
gpio_write(&mdmILvlOe, 0); // ILVLEN: 0=disabled (i2c)
88+
gpio_write(&gpsEn, 0); // LDOEN: 0=off
89+
}
90+
}
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: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,10 @@
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
2019
void mbed_sdk_init()
2120
{
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.
21+
c027_init();
4322
}

0 commit comments

Comments
 (0)