Unverified Commit 9e55ccd9 authored by TimL's avatar TimL Committed by GitHub

PPP: Make modem reset delay configurable (#9910)

* fix(ppp): Make modem reset delay configurable

The delay required to reset Simcom modem modules varies significantly across
different models, even where they have otherwise identical AT command
sets.

Simcom A7672 was failing to reset with the default 200ms delay. Make the reset
delay configurable to allow customising this for a specific modem.
Default delay, if not specified is kept at 200ms.

* ci(pre-commit): Apply automatic fixes

---------
Co-authored-by: default avatarpre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
parent 47298ffa
......@@ -6,6 +6,7 @@
// WaveShare SIM7600 HW Flow Control
#define PPP_MODEM_RST 25
#define PPP_MODEM_RST_LOW false //active HIGH
#define PPP_MODEM_RST_DELAY 200
#define PPP_MODEM_TX 21
#define PPP_MODEM_RX 22
#define PPP_MODEM_RTS 26
......@@ -60,7 +61,7 @@ void setup() {
// Configure the modem
PPP.setApn(PPP_MODEM_APN);
PPP.setPin(PPP_MODEM_PIN);
PPP.setResetPin(PPP_MODEM_RST, PPP_MODEM_RST_LOW);
PPP.setResetPin(PPP_MODEM_RST, PPP_MODEM_RST_LOW, PPP_MODEM_RST_DELAY);
PPP.setPins(PPP_MODEM_TX, PPP_MODEM_RX, PPP_MODEM_RTS, PPP_MODEM_CTS, PPP_MODEM_FC);
Serial.println("Starting the modem. It might take a while!");
......
......@@ -141,8 +141,8 @@ esp_modem_dce_t *PPPClass::handle() const {
}
PPPClass::PPPClass()
: _dce(NULL), _pin_tx(-1), _pin_rx(-1), _pin_rts(-1), _pin_cts(-1), _flow_ctrl(ESP_MODEM_FLOW_CONTROL_NONE), _pin_rst(-1), _pin_rst_act_low(true), _pin(NULL),
_apn(NULL), _rx_buffer_size(4096), _tx_buffer_size(512), _mode(ESP_MODEM_MODE_COMMAND), _uart_num(UART_NUM_1) {}
: _dce(NULL), _pin_tx(-1), _pin_rx(-1), _pin_rts(-1), _pin_cts(-1), _flow_ctrl(ESP_MODEM_FLOW_CONTROL_NONE), _pin_rst(-1), _pin_rst_act_low(true),
_pin_rst_delay(200), _pin(NULL), _apn(NULL), _rx_buffer_size(4096), _tx_buffer_size(512), _mode(ESP_MODEM_MODE_COMMAND), _uart_num(UART_NUM_1) {}
PPPClass::~PPPClass() {}
......@@ -152,9 +152,10 @@ bool PPPClass::pppDetachBus(void *bus_pointer) {
return true;
}
void PPPClass::setResetPin(int8_t rst, bool active_low) {
void PPPClass::setResetPin(int8_t rst, bool active_low, uint32_t reset_delay) {
_pin_rst = digitalPinToGPIONumber(rst);
_pin_rst_act_low = active_low;
_pin_rst_delay = reset_delay;
}
bool PPPClass::setPins(int8_t tx, int8_t rx, int8_t rts, int8_t cts, esp_modem_flow_ctrl_t flow_ctrl) {
......@@ -285,7 +286,7 @@ bool PPPClass::begin(ppp_modem_model_t model, uint8_t uart_num, int baud_rate) {
}
perimanSetPinBusExtraType(_pin_rst, "PPP_MODEM_RST");
digitalWrite(_pin_rst, !_pin_rst_act_low);
delay(200);
delay(_pin_rst_delay);
digitalWrite(_pin_rst, _pin_rst_act_low);
delay(100);
}
......
......@@ -36,7 +36,7 @@ public:
bool setPins(int8_t tx, int8_t rx, int8_t rts = -1, int8_t cts = -1, esp_modem_flow_ctrl_t flow_ctrl = ESP_MODEM_FLOW_CONTROL_NONE);
// Using the reset pin of the module ensures that proper communication can be achieved
void setResetPin(int8_t rst, bool active_low = true);
void setResetPin(int8_t rst, bool active_low = true, uint32_t reset_delay = 200);
// Modem DCE APIs
int RSSI() const;
......@@ -94,6 +94,7 @@ private:
esp_modem_flow_ctrl_t _flow_ctrl;
int8_t _pin_rst;
bool _pin_rst_act_low;
uint32_t _pin_rst_delay;
const char *_pin;
const char *_apn;
int _rx_buffer_size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment