Skip to content

Commit aa42c99

Browse files
committed
Cleanup example.
1 parent 6ad9840 commit aa42c99

File tree

1 file changed

+43
-77
lines changed

1 file changed

+43
-77
lines changed
+43-77
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,37 @@
1+
#include <Arduino_PMIC.h>
2+
3+
#include <Wire.h>
4+
15
#include "RTC.h"
26
#include "r_lpm.h"
3-
#include "PF1550.h"
4-
#include "Wire.h"
57

6-
/*
7-
class PF1550_Io_C33 : public PF1550_Io_C33
8+
void periodic_cbk()
89
{
9-
void turnOffMCURail() {
10-
clrBit(Register::PMIC_SW1_CTRL, 0);
11-
//clrBit(Register::PMIC_SW3_CTRL, 0);
12-
}
13-
};
14-
*/
15-
16-
const int LED_ON_INTERRUPT = LED_BUILTIN;
17-
18-
void periodic_cbk() {
19-
static bool clb_st = false;
20-
if (clb_st) {
21-
//digitalWrite(LED_ON_INTERRUPT, HIGH);
22-
}
23-
else {
24-
//digitalWrite(LED_ON_INTERRUPT, LOW);
25-
}
26-
clb_st = !clb_st;
27-
28-
Serial.println("PERIODIC INTERRUPT");
10+
digitalWrite(LEDR, !digitalRead(LEDR));
2911
}
3012

31-
void alarm_cbk() {
32-
Serial.println("ALARM INTERRUPT");
33-
digitalWrite(LED_ON_INTERRUPT, LOW);
13+
void alarm_cbk()
14+
{
15+
digitalWrite(LED_BUILTIN, LOW);
3416
delay(500);
35-
digitalWrite(LED_ON_INTERRUPT, HIGH);
17+
digitalWrite(LED_BUILTIN, HIGH);
3618
}
3719

3820
lpm_instance_ctrl_t p_api_ctrl;
3921
lpm_cfg_t p_cfg;
4022

41-
void setup() {
23+
void setup()
24+
{
4225
Serial.begin(9600);
4326
while (!Serial) { }
4427

45-
PMIC.debug(Serial);
28+
//PMIC.debug(Serial);
4629
PMIC.begin();
4730
PMIC.configLDO1(Ldo1Voltage::V_3_30, false, false, false);
4831
PMIC.configLDO2(Ldo2Voltage::V_3_30, false, false, false);
4932
PMIC.configLDO3(Ldo3Voltage::V_1_20, false, false, false);
5033
PMIC.configSw2(Sw2Voltage::V_3_30, Sw2Voltage::V_3_30, Sw2Voltage::V_3_30, Sw2CurrentLimit::I_1_5_A, false, false, false);
5134

52-
//io.turnOffMCURail();
53-
5435
p_cfg.low_power_mode = LPM_MODE_DEEP; // LPM_MODE_SLEEP LPM_MODE_STANDBY LPM_MODE_STANDBY_SNOOZE LPM_MODE_DEEP
5536
p_cfg.standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_IRQ0 | LPM_STANDBY_WAKE_SOURCE_RTCALM;
5637
p_cfg.dtc_state_in_snooze = LPM_SNOOZE_DTC_DISABLE; // LPM_SNOOZE_DTC_ENABLE LPM_SNOOZE_DTC_DISABLE
@@ -61,86 +42,71 @@ void setup() {
6142

6243
R_LPM_Open(&p_api_ctrl, &p_cfg);
6344

64-
//pinMode(LED_BUILTIN, OUTPUT);
65-
pinMode(LED_ON_INTERRUPT, OUTPUT);
66-
digitalWrite(LED_ON_INTERRUPT, HIGH);
45+
/* Configure LED_BUILTIN. */
46+
pinMode(LED_BUILTIN, OUTPUT);
47+
digitalWrite(LED_BUILTIN, HIGH);
6748

49+
/* Configure the red RGB LED. */
6850
pinMode(LEDR, OUTPUT);
6951
digitalWrite(LEDR, LOW);
7052
delay(200);
7153
digitalWrite(LEDR, HIGH);
7254

55+
/* Initialize the RTC. */
7356
RTC.begin();
74-
RTCTime mytime(1, Month::JANUARY, 2000, 12, 10, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_ACTIVE);
57+
RTCTime initial_time(1, Month::JANUARY, 2000, 12, 10, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_ACTIVE);
7558

76-
if (!RTC.isRunning()) {
77-
RTC.setTime(mytime);
78-
}
59+
if (!RTC.isRunning())
60+
RTC.setTime(initial_time);
7961

80-
RTCTime alarmtime;
81-
alarmtime.setSecond(35);
62+
RTCTime alarm_time;
63+
alarm_time.setSecond(35);
8264

83-
AlarmMatch am;
84-
am.addMatchSecond();
65+
AlarmMatch alarm_match;
66+
alarm_match.addMatchSecond();
8567

86-
if (!RTC.setPeriodicCallback(periodic_cbk, Period::ONCE_EVERY_2_SEC)) {
68+
if (!RTC.setPeriodicCallback(periodic_cbk, Period::ONCE_EVERY_2_SEC))
8769
Serial.println("ERROR: periodic callback not set");
88-
}
8970

90-
if (!RTC.setAlarmCallback(alarm_cbk, alarmtime, am)) {
71+
if (!RTC.setAlarmCallback(alarm_cbk, alarm_time, alarm_match))
9172
Serial.println("ERROR: alarm callback not set");
92-
}
93-
9473
}
9574

96-
void loop() {
97-
static bool status = false;
98-
75+
void loop()
76+
{
77+
/* Enter low power mode. Note: The JLink looses connection here. */
9978
R_LPM_LowPowerModeEnter(&p_api_ctrl);
10079

101-
RTCTime currenttime;
102-
if (status) {
103-
104-
if (RTC.isRunning()) {
105-
Serial.println("RTC is running");
106-
}
107-
else {
108-
Serial.println("RTC is not running");
109-
}
110-
80+
if (RTC.isRunning())
81+
{
11182
/* GET CURRENT TIME FROM RTC */
112-
RTC.getTime(currenttime);
83+
RTCTime current_time;
84+
RTC.getTime(current_time);
11385

11486
/* PRINT CURRENT TIME on Serial */
11587
Serial.print("Current time: ");
11688
/* DATE */
117-
Serial.print(currenttime.getDayOfMonth());
89+
Serial.print(current_time.getDayOfMonth());
11890
Serial.print("/");
119-
Serial.print(Month2int(currenttime.getMonth()));
91+
Serial.print(Month2int(current_time.getMonth()));
12092
Serial.print("/");
121-
Serial.print(currenttime.getYear());
93+
Serial.print(current_time.getYear());
12294
Serial.print(" - ");
123-
Serial.print(currenttime.getUnixTime());
95+
Serial.print(current_time.getUnixTime());
12496
Serial.print(" - ");
12597

12698
struct timeval tv;
12799
gettimeofday(&tv, NULL);
128100
Serial.print(tv.tv_sec);
129101
Serial.print(" - ");
130102

131-
/* ORE:MINUTI:SECONDI */
132-
Serial.print(currenttime.getHour());
103+
/* HOUR:MINUTES:SECONDS */
104+
Serial.print(current_time.getHour());
133105
Serial.print(":");
134-
Serial.print(currenttime.getMinutes());
106+
Serial.print(current_time.getMinutes());
135107
Serial.print(":");
136-
Serial.println(currenttime.getSeconds());
108+
Serial.println(current_time.getSeconds());
137109

138-
//digitalWrite(LED_BUILTIN, HIGH);
110+
delay(1000);
139111
}
140-
else {
141-
//digitalWrite(LED_BUILTIN, LOW);
142-
}
143-
144-
status = !status;
145-
delay(1000);
146112
}

0 commit comments

Comments
 (0)