Skip to content

Instantly share code, notes, and snippets.

@marioboncz
Created December 27, 2019 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marioboncz/2911c2df62d94d6ac3265c196b690618 to your computer and use it in GitHub Desktop.
Save marioboncz/2911c2df62d94d6ac3265c196b690618 to your computer and use it in GitHub Desktop.
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if MBED_CONF_NSAPI_PRESENT
#include "RAK_QUECTEL_BG96.h"
#include "gpio_api.h"
#include "platform/mbed_thread.h"
#include "PinNames.h"
#include "UARTSerial.h"
#include "mbed-trace/mbed_trace.h"
#define TRACE_GROUP "MYMODEM"
#define WAIT_AFTER_POWR_CHANGED (1000) // [msec.]
using namespace mbed;
RAK_QUECTEL_BG96::RAK_QUECTEL_BG96(FileHandle *fh) : QUECTEL_BG96(fh)
{
onboard_modem_init();
}
nsapi_error_t RAK_QUECTEL_BG96::hard_power_on()
{
onboard_modem_init();
return NSAPI_ERROR_OK;
}
nsapi_error_t RAK_QUECTEL_BG96::hard_power_off()
{
onboard_modem_deinit();
return NSAPI_ERROR_OK;
}
nsapi_error_t RAK_QUECTEL_BG96::soft_power_on()
{
onboard_modem_power_up();
return NSAPI_ERROR_OK;
}
nsapi_error_t RAK_QUECTEL_BG96::soft_power_off()
{
onboard_modem_power_down();
return NSAPI_ERROR_OK;
}
void RAK_QUECTEL_BG96::onboard_modem_init()
{
gpio_t gpio;
tr_debug("onboard_init M_POWR %d PWRKEY %d RESET_MODULE %d \n", M_POWR, PWRKEY, RESET_MODULE);
// Power Supply
gpio_init_out_ex(&gpio, M_POWR, 0);
// Turn On/Off
gpio_init_out_ex(&gpio, PWRKEY, 0);
gpio_init_out_ex(&gpio, RESET_MODULE, 0);
// Status Indication
//gpio_init_in_ex(&gpio, MDMSTAT, PullUp);
// Main UART Interface
//gpio_init_out_ex(&gpio, MDMDTR, 0);
thread_sleep_for(WAIT_AFTER_POWR_CHANGED);
}
void RAK_QUECTEL_BG96::onboard_modem_deinit()
{
gpio_t gpio;
// Power supply OFF
gpio_init_out_ex(&gpio, M_POWR, 0);
thread_sleep_for(WAIT_AFTER_POWR_CHANGED);
}
void RAK_QUECTEL_BG96::onboard_modem_power_up()
{
tr_debug("onboard_modem_power_up \n");
gpio_t gpio;
// Power supply ON
gpio_init_out_ex(&gpio, M_POWR, 1);
thread_sleep_for(WAIT_AFTER_POWR_CHANGED);
// RESET ??? llapinski changed based on itracker firmware
gpio_init_out_ex(&gpio, RESET_MODULE, 0);
// Turn on
thread_sleep_for(100);
press_power_button(200);
}
void RAK_QUECTEL_BG96::press_power_button(int time_ms)
{
gpio_t gpio;
gpio_init_out_ex(&gpio, PWRKEY, 1);
thread_sleep_for(time_ms);
gpio_write(&gpio, 0);
}
void RAK_QUECTEL_BG96::onboard_modem_power_down()
{
gpio_t gpio;
// Power supply OFF
gpio_init_out_ex(&gpio, M_POWR, 0);
thread_sleep_for(WAIT_AFTER_POWR_CHANGED);
}
CellularDevice *CellularDevice::get_target_default_instance()
{
tr_debug("RAK_BG96:get_inst TX %d RX %d \n", MBED_CONF_QUECTEL_BG96_TX, MBED_CONF_QUECTEL_BG96_RX);
static UARTSerial serial(MBED_CONF_QUECTEL_BG96_TX, MBED_CONF_QUECTEL_BG96_RX, 9600);// MBED_CONF_QUECTEL_BG96_BAUDRATE);
#if defined (MBED_CONF_QUECTEL_BG96_RTS) && defined(MBED_CONF_QUECTEL_BG96_CTS)
tr_debug("ONBOARD_QUECTEL_BG96flow control: RTS %d CTS %d \n", MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS);
serial.set_flow_control(mbed::SerialBase::RTSCTS, MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS);
#endif
static RAK_QUECTEL_BG96 device(&serial);
// static RAK_QUECTEL_BG96 device(&serial,
// MBED_CONF_QUECTEL_BG96_PWR,
// MBED_CONF_QUECTEL_BG96_POLARITY,
// MBED_CONF_QUECTEL_BG96_RST);
return &device;
}
#endif // MBED_CONF_NSAPI_PRESENT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment