Skip to content

Commit 03cebd5

Browse files
committed
Enable LOD
1 parent 684c6ce commit 03cebd5

File tree

4 files changed

+98
-39
lines changed

4 files changed

+98
-39
lines changed

scripts/flash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
44

5-
PORT=COM7
5+
PORT=COM9
66
BUILD_DIR=$SCRIPTPATH/../build
77

88
# Do path conversion for WSL

src/examples/power_down/power_down.ino

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1+
#include <Wire.h>
12
#include <avr/io.h>
23
#include <led_ctrl.h>
34
#include <log.h>
45
#include <low_power.h>
56
#include <lte.h>
67
#include <sequans_controller.h>
78

8-
#ifdef __AVR_AVR128DB48__ // MINI
9-
10-
#define SerialDebug Serial3
11-
12-
#else
13-
#ifdef __AVR_AVR128DB64__ // Non-Mini
14-
15-
#define SerialDebug Serial5
16-
17-
#else
18-
#error "INCOMPATIBLE_DEVICE_SELECTED"
19-
#endif
20-
#endif
21-
229
#define SW0 PIN_PD2
2310

2411
ISR(PORTD_PORT_vect) {
@@ -37,7 +24,8 @@ void setup() {
3724
// pressing the button
3825
pinConfigure(SW0, PIN_DIR_INPUT | PIN_INT_FALL);
3926

40-
// Now we configure the low power module for power down configuration.
27+
// Now we configure the low power module for power down configuration, where
28+
// the LTE modem and the CPU will be powered down
4129
LowPower.configurePowerDown();
4230

4331
Lte.begin();
@@ -49,11 +37,12 @@ void setup() {
4937
}
5038

5139
Log.raw("\r\n");
40+
5241
Log.infof("Connected to operator: %s\r\n", Lte.getOperator().c_str());
5342
}
5443

5544
void loop() {
56-
Log.raw("\r\n");
45+
5746
Log.info("Powering down...");
5847
delay(100);
5948

src/examples/power_save/power_save.ino

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
#include <avr/cpufunc.h>
21
#include <avr/io.h>
32
#include <led_ctrl.h>
43
#include <log.h>
54
#include <low_power.h>
65
#include <lte.h>
76
#include <sequans_controller.h>
87

9-
#ifdef __AVR_AVR128DB48__ // MINI
10-
11-
#define SerialDebug Serial3
12-
13-
#else
14-
#ifdef __AVR_AVR128DB64__ // Non-Mini
15-
16-
#define SerialDebug Serial5
17-
18-
#else
19-
#error "INCOMPATIBLE_DEVICE_SELECTED"
20-
#endif
21-
#endif
22-
238
#define SW0 PIN_PD2
249

2510
ISR(PORTD_PORT_vect) {

src/low_power.cpp

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "sequans_controller.h"
66

77
#include <Arduino.h>
8-
#include <avr/cpufunc.h>
8+
#include <Wire.h>
99
#include <avr/io.h>
1010
#include <avr/sleep.h>
1111

@@ -56,7 +56,20 @@
5656

5757
#ifdef __AVR_AVR128DB48__ // MINI
5858

59-
#define RING_PIN_bm PIN6_bm
59+
#define RING_PIN_bm PIN6_bm
60+
#define LOWQ_PIN PIN_PB4
61+
#define VOLTAGE_MEASURE_PIN PIN_PB3
62+
63+
#define DEBUGGER_TX_PIN PIN_PB0
64+
#define DEBUGGER_RX_PIN PIN_PB1
65+
#define DEBUGGER_LED_PIN PIN_PB2
66+
#define DEBUGGER_SW0_PIN PIN_PD2
67+
#define DEBUGGER_USART USART3
68+
69+
#define I2C0_SDA_PIN PIN_PC2
70+
#define I2C0_SCL_PIN PIN_PC3
71+
#define I2C1_SDA_PIN PIN_PF2
72+
#define I2C1_SCL_PIN PIN_PF3
6073

6174
#else
6275

@@ -302,24 +315,92 @@ static void disablePIT(void) {
302315

303316
static void powerDownPeripherals(void) {
304317

318+
// LEDs
305319
cell_led_state = digitalRead(LedCtrl.getLedPin(Led::CELL));
306320
con_led_state = digitalRead(LedCtrl.getLedPin(Led::CON));
307321

308-
LedCtrl.off(Led::CELL, true);
309-
LedCtrl.off(Led::CON, true);
310-
LedCtrl.off(Led::DATA, true);
311-
LedCtrl.off(Led::ERROR, true);
312-
LedCtrl.off(Led::USER, true);
322+
pinConfigure(LedCtrl.getLedPin(Led::CELL),
323+
PIN_DIR_INPUT | PIN_PULLUP_ON | PIN_INPUT_DISABLE);
324+
pinConfigure(LedCtrl.getLedPin(Led::CON),
325+
PIN_DIR_INPUT | PIN_PULLUP_ON | PIN_INPUT_DISABLE);
326+
pinConfigure(LedCtrl.getLedPin(Led::DATA),
327+
PIN_DIR_INPUT | PIN_PULLUP_ON | PIN_INPUT_DISABLE);
328+
pinConfigure(LedCtrl.getLedPin(Led::ERROR),
329+
PIN_DIR_INPUT | PIN_PULLUP_ON | PIN_INPUT_DISABLE);
330+
pinConfigure(LedCtrl.getLedPin(Led::USER),
331+
PIN_DIR_INPUT | PIN_PULLUP_ON | PIN_INPUT_DISABLE);
332+
333+
// Make sure that I2C pins are pulled up and there won't be a voltage drop
334+
// over them
335+
pinConfigure(I2C0_SDA_PIN, PIN_DIR_INPUT | PIN_INPUT_DISABLE);
336+
pinConfigure(I2C0_SCL_PIN, PIN_DIR_INPUT | PIN_INPUT_DISABLE);
337+
pinConfigure(I2C1_SDA_PIN, PIN_DIR_INPUT | PIN_INPUT_DISABLE);
338+
pinConfigure(I2C1_SCL_PIN, PIN_DIR_INPUT | PIN_INPUT_DISABLE);
339+
340+
// Voltage measure
341+
digitalWrite(VOLTAGE_MEASURE_PIN, LOW);
342+
343+
// Debugger
344+
DEBUGGER_USART.CTRLB &= ~(USART_RXEN_bm | USART_TXEN_bm);
345+
pinConfigure(DEBUGGER_TX_PIN,
346+
PIN_DIR_INPUT | PIN_PULLUP_ON | PIN_INPUT_DISABLE);
347+
pinConfigure(DEBUGGER_RX_PIN,
348+
PIN_DIR_INPUT | PIN_PULLUP_ON | PIN_INPUT_DISABLE);
349+
pinConfigure(DEBUGGER_LED_PIN,
350+
PIN_DIR_INPUT | PIN_PULLUP_ON | PIN_INPUT_DISABLE);
351+
pinConfigure(DEBUGGER_SW0_PIN,
352+
PIN_DIR_INPUT | PIN_PULLUP_ON | PIN_INPUT_DISABLE);
313353
}
314354

315355
static void powerUpPeripherals(void) {
356+
357+
pinConfigure(LedCtrl.getLedPin(Led::CELL), PIN_DIR_OUTPUT);
358+
pinConfigure(LedCtrl.getLedPin(Led::CON), PIN_DIR_OUTPUT);
359+
pinConfigure(LedCtrl.getLedPin(Led::DATA), PIN_DIR_OUTPUT);
360+
pinConfigure(LedCtrl.getLedPin(Led::ERROR), PIN_DIR_OUTPUT);
361+
pinConfigure(LedCtrl.getLedPin(Led::USER), PIN_DIR_OUTPUT);
362+
316363
if (cell_led_state) {
317364
LedCtrl.on(Led::CELL, true);
318365
}
319366

320367
if (con_led_state) {
321368
LedCtrl.on(Led::CON, true);
322369
}
370+
371+
// Make sure that I2C pins are pulled up and there won't be a voltage drop
372+
// over them
373+
pinConfigure(I2C0_SDA_PIN, PIN_DIR_OUTPUT);
374+
pinConfigure(I2C0_SCL_PIN, PIN_DIR_OUTPUT);
375+
pinConfigure(I2C1_SDA_PIN, PIN_DIR_OUTPUT);
376+
pinConfigure(I2C1_SCL_PIN, PIN_DIR_OUTPUT);
377+
378+
// Voltage measure
379+
digitalWrite(VOLTAGE_MEASURE_PIN, HIGH);
380+
381+
// Debugger
382+
DEBUGGER_USART.CTRLB |= (USART_RXEN_bm | USART_TXEN_bm);
383+
pinConfigure(DEBUGGER_TX_PIN, PIN_DIR_OUTPUT);
384+
pinConfigure(DEBUGGER_RX_PIN, PIN_DIR_INPUT | PIN_INPUT_ENABLE);
385+
pinConfigure(DEBUGGER_LED_PIN, PIN_DIR_OUTPUT);
386+
pinConfigure(DEBUGGER_SW0_PIN, PIN_DIR_INPUT | PIN_INPUT_ENABLE);
387+
}
388+
389+
static void enableLDO(void) {
390+
391+
pinConfigure(LOWQ_PIN, PIN_DIR_OUTPUT);
392+
digitalWrite(LOWQ_PIN, HIGH);
393+
394+
// Wait a little to let LDO mode settle
395+
delay(10);
396+
}
397+
398+
static void disableLDO(void) {
399+
pinConfigure(LOWQ_PIN, PIN_DIR_OUTPUT);
400+
digitalWrite(LOWQ_PIN, LOW);
401+
402+
// Wait a little to let PWM mode settle
403+
delay(10);
323404
}
324405

325406
bool LowPowerClass::configurePowerDown(void) {
@@ -449,7 +530,9 @@ void LowPowerClass::powerSave(void) {
449530
while (!attemptToEnterPowerSaveModeForModem(30000) &&
450531
millis() - start_time_ms < period * 1000) {}
451532

533+
enableLDO();
452534
sleep_cpu();
535+
disableLDO();
453536

454537
if (modem_is_in_power_save) {
455538
modem_is_in_power_save = false;
@@ -469,6 +552,7 @@ void LowPowerClass::powerDown(const uint32_t power_down_time_seconds) {
469552

470553
Lte.end();
471554
enablePIT();
555+
enableLDO();
472556

473557
uint32_t remaining_time_seconds =
474558
power_down_time_seconds -
@@ -487,6 +571,7 @@ void LowPowerClass::powerDown(const uint32_t power_down_time_seconds) {
487571
}
488572
}
489573

574+
disableLDO();
490575
disablePIT();
491576
Lte.begin();
492577

0 commit comments

Comments
 (0)