1
+ #include < Arduino_PMIC.h>
2
+
3
+ #include < Wire.h>
4
+
1
5
#include " RTC.h"
2
6
#include " r_lpm.h"
3
- #include " PF1550.h"
4
- #include " Wire.h"
5
7
6
- /*
7
- class PF1550_Io_C33 : public PF1550_Io_C33
8
+ void periodic_cbk ()
8
9
{
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));
29
11
}
30
12
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);
34
16
delay (500 );
35
- digitalWrite (LED_ON_INTERRUPT , HIGH);
17
+ digitalWrite (LED_BUILTIN , HIGH);
36
18
}
37
19
38
20
lpm_instance_ctrl_t p_api_ctrl;
39
21
lpm_cfg_t p_cfg;
40
22
41
- void setup () {
23
+ void setup ()
24
+ {
42
25
Serial.begin (9600 );
43
26
while (!Serial) { }
44
27
45
- PMIC.debug (Serial);
28
+ // PMIC.debug(Serial);
46
29
PMIC.begin ();
47
30
PMIC.configLDO1 (Ldo1Voltage::V_3_30, false , false , false );
48
31
PMIC.configLDO2 (Ldo2Voltage::V_3_30, false , false , false );
49
32
PMIC.configLDO3 (Ldo3Voltage::V_1_20, false , false , false );
50
33
PMIC.configSw2 (Sw2Voltage::V_3_30, Sw2Voltage::V_3_30, Sw2Voltage::V_3_30, Sw2CurrentLimit::I_1_5_A, false , false , false );
51
34
52
- // io.turnOffMCURail();
53
-
54
35
p_cfg.low_power_mode = LPM_MODE_DEEP; // LPM_MODE_SLEEP LPM_MODE_STANDBY LPM_MODE_STANDBY_SNOOZE LPM_MODE_DEEP
55
36
p_cfg.standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_IRQ0 | LPM_STANDBY_WAKE_SOURCE_RTCALM;
56
37
p_cfg.dtc_state_in_snooze = LPM_SNOOZE_DTC_DISABLE; // LPM_SNOOZE_DTC_ENABLE LPM_SNOOZE_DTC_DISABLE
@@ -61,86 +42,71 @@ void setup() {
61
42
62
43
R_LPM_Open (&p_api_ctrl, &p_cfg);
63
44
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);
67
48
49
+ /* Configure the red RGB LED. */
68
50
pinMode (LEDR, OUTPUT);
69
51
digitalWrite (LEDR, LOW);
70
52
delay (200 );
71
53
digitalWrite (LEDR, HIGH);
72
54
55
+ /* Initialize the RTC. */
73
56
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);
75
58
76
- if (!RTC.isRunning ()) {
77
- RTC.setTime (mytime);
78
- }
59
+ if (!RTC.isRunning ())
60
+ RTC.setTime (initial_time);
79
61
80
- RTCTime alarmtime ;
81
- alarmtime .setSecond (35 );
62
+ RTCTime alarm_time ;
63
+ alarm_time .setSecond (35 );
82
64
83
- AlarmMatch am ;
84
- am .addMatchSecond ();
65
+ AlarmMatch alarm_match ;
66
+ alarm_match .addMatchSecond ();
85
67
86
- if (!RTC.setPeriodicCallback (periodic_cbk, Period::ONCE_EVERY_2_SEC)) {
68
+ if (!RTC.setPeriodicCallback (periodic_cbk, Period::ONCE_EVERY_2_SEC))
87
69
Serial.println (" ERROR: periodic callback not set" );
88
- }
89
70
90
- if (!RTC.setAlarmCallback (alarm_cbk, alarmtime, am)) {
71
+ if (!RTC.setAlarmCallback (alarm_cbk, alarm_time, alarm_match))
91
72
Serial.println (" ERROR: alarm callback not set" );
92
- }
93
-
94
73
}
95
74
96
- void loop () {
97
- static bool status = false ;
98
-
75
+ void loop ()
76
+ {
77
+ /* Enter low power mode. Note: The JLink looses connection here. */
99
78
R_LPM_LowPowerModeEnter (&p_api_ctrl);
100
79
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
+ {
111
82
/* GET CURRENT TIME FROM RTC */
112
- RTC.getTime (currenttime);
83
+ RTCTime current_time;
84
+ RTC.getTime (current_time);
113
85
114
86
/* PRINT CURRENT TIME on Serial */
115
87
Serial.print (" Current time: " );
116
88
/* DATE */
117
- Serial.print (currenttime .getDayOfMonth ());
89
+ Serial.print (current_time .getDayOfMonth ());
118
90
Serial.print (" /" );
119
- Serial.print (Month2int (currenttime .getMonth ()));
91
+ Serial.print (Month2int (current_time .getMonth ()));
120
92
Serial.print (" /" );
121
- Serial.print (currenttime .getYear ());
93
+ Serial.print (current_time .getYear ());
122
94
Serial.print (" - " );
123
- Serial.print (currenttime .getUnixTime ());
95
+ Serial.print (current_time .getUnixTime ());
124
96
Serial.print (" - " );
125
97
126
98
struct timeval tv;
127
99
gettimeofday (&tv, NULL );
128
100
Serial.print (tv.tv_sec );
129
101
Serial.print (" - " );
130
102
131
- /* ORE:MINUTI:SECONDI */
132
- Serial.print (currenttime .getHour ());
103
+ /* HOUR:MINUTES:SECONDS */
104
+ Serial.print (current_time .getHour ());
133
105
Serial.print (" :" );
134
- Serial.print (currenttime .getMinutes ());
106
+ Serial.print (current_time .getMinutes ());
135
107
Serial.print (" :" );
136
- Serial.println (currenttime .getSeconds ());
108
+ Serial.println (current_time .getSeconds ());
137
109
138
- // digitalWrite(LED_BUILTIN, HIGH );
110
+ delay ( 1000 );
139
111
}
140
- else {
141
- // digitalWrite(LED_BUILTIN, LOW);
142
- }
143
-
144
- status = !status;
145
- delay (1000 );
146
112
}
0 commit comments