|
| 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 | +} |
0 commit comments