Skip to content

Commit feb948d

Browse files
authored
Merge pull request #11 from arduino-libraries/c33
Add support for Portenta C33.
2 parents 5d7688d + c940685 commit feb948d

11 files changed

+328
-13
lines changed

.github/workflows/compile-examples.yml

+14-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
runs-on: ubuntu-latest
3030

3131
env:
32+
UNIVERSAL_SKETCH_PATHS: |
33+
- examples/BasicUsage
3234
SKETCHES_REPORTS_PATH: sketches-reports
3335

3436
strategy:
@@ -40,12 +42,21 @@ jobs:
4042
# See: https://github.com/arduino/compile-sketches#platforms
4143
platforms: |
4244
- name: arduino:mbed_nicla
43-
- fqbn: arduino:mbed_portenta:envie_m4
45+
sketch-paths:
46+
- fqbn: arduino:mbed_portenta:envie_m7:target_core=cm4
4447
platforms: |
4548
- name: arduino:mbed_portenta
49+
sketch-paths:
4650
- fqbn: arduino:mbed_portenta:envie_m7
4751
platforms: |
4852
- name: arduino:mbed_portenta
53+
sketch-paths:
54+
- fqbn: arduino:renesas:portenta_h33
55+
platforms: |
56+
- name: arduino:renesas
57+
source-url: https://downloads.arduino.cc/packages/package_renesas_index.json
58+
sketch-paths: |
59+
- examples/C33-Low-Power
4960
5061
steps:
5162
- name: Checkout repository
@@ -63,7 +74,8 @@ jobs:
6374
# Additional library dependencies can be listed here.
6475
# See: https://github.com/arduino/compile-sketches#libraries
6576
sketch-paths: |
66-
- examples
77+
${{ env.UNIVERSAL_SKETCH_PATHS }}
78+
${{ matrix.sketch-paths }}
6779
enable-deltas-report: true
6880
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
6981

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include <Arduino_PMIC.h>
2+
3+
#include <Wire.h>
4+
5+
#include "RTC.h"
6+
#include "r_lpm.h"
7+
8+
void periodic_cbk()
9+
{
10+
digitalWrite(LEDR, !digitalRead(LEDR));
11+
}
12+
13+
void alarm_cbk()
14+
{
15+
digitalWrite(LED_BUILTIN, LOW);
16+
delay(500);
17+
digitalWrite(LED_BUILTIN, HIGH);
18+
}
19+
20+
lpm_instance_ctrl_t p_api_ctrl;
21+
lpm_cfg_t p_cfg;
22+
23+
void setup()
24+
{
25+
Serial.begin(9600);
26+
while (!Serial) { }
27+
28+
//PMIC.debug(Serial);
29+
PMIC.begin();
30+
PMIC.configLDO1(Ldo1Voltage::V_3_30, false, false, false);
31+
PMIC.configLDO2(Ldo2Voltage::V_3_30, false, false, false);
32+
PMIC.configLDO3(Ldo3Voltage::V_1_20, false, false, false);
33+
PMIC.configSw2(Sw2Voltage::V_3_30, Sw2Voltage::V_3_30, Sw2Voltage::V_3_30, Sw2CurrentLimit::I_1_5_A, false, false, false);
34+
35+
p_cfg.low_power_mode = LPM_MODE_DEEP; // LPM_MODE_SLEEP LPM_MODE_STANDBY LPM_MODE_STANDBY_SNOOZE LPM_MODE_DEEP
36+
p_cfg.standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_IRQ0 | LPM_STANDBY_WAKE_SOURCE_RTCALM;
37+
p_cfg.dtc_state_in_snooze = LPM_SNOOZE_DTC_DISABLE; // LPM_SNOOZE_DTC_ENABLE LPM_SNOOZE_DTC_DISABLE
38+
p_cfg.power_supply_state = LPM_POWER_SUPPLY_DEEPCUT0; // LPM_POWER_SUPPLY_DEEPCUT0, LPM_POWER_SUPPLY_DEEPCUT1, LPM_POWER_SUPPLY_DEEPCUT3
39+
p_cfg.output_port_enable = LPM_OUTPUT_PORT_ENABLE_RETAIN; // LPM_OUTPUT_PORT_ENABLE_RETAIN LPM_OUTPUT_PORT_ENABLE_HIGH_IMPEDANCE
40+
p_cfg.io_port_state = LPM_IO_PORT_NO_CHANGE; // LPM_IO_PORT_NO_CHANGE LPM_IO_PORT_RESET
41+
p_cfg.deep_standby_cancel_source = LPM_DEEP_STANDBY_CANCEL_SOURCE_RTC_ALARM;
42+
43+
R_LPM_Open(&p_api_ctrl, &p_cfg);
44+
45+
/* Configure LED_BUILTIN. */
46+
pinMode(LED_BUILTIN, OUTPUT);
47+
digitalWrite(LED_BUILTIN, HIGH);
48+
49+
/* Configure the red RGB LED. */
50+
pinMode(LEDR, OUTPUT);
51+
digitalWrite(LEDR, LOW);
52+
delay(200);
53+
digitalWrite(LEDR, HIGH);
54+
55+
/* Initialize the RTC. */
56+
RTC.begin();
57+
RTCTime initial_time(1, Month::JANUARY, 2000, 12, 10, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_ACTIVE);
58+
59+
if (!RTC.isRunning())
60+
RTC.setTime(initial_time);
61+
62+
RTCTime alarm_time;
63+
alarm_time.setSecond(35);
64+
65+
AlarmMatch alarm_match;
66+
alarm_match.addMatchSecond();
67+
68+
if (!RTC.setPeriodicCallback(periodic_cbk, Period::ONCE_EVERY_2_SEC))
69+
Serial.println("ERROR: periodic callback not set");
70+
71+
if (!RTC.setAlarmCallback(alarm_cbk, alarm_time, alarm_match))
72+
Serial.println("ERROR: alarm callback not set");
73+
}
74+
75+
void loop()
76+
{
77+
/* Enter low power mode. Note: The JLink looses connection here. */
78+
R_LPM_LowPowerModeEnter(&p_api_ctrl);
79+
80+
if (RTC.isRunning())
81+
{
82+
/* GET CURRENT TIME FROM RTC */
83+
RTCTime current_time;
84+
RTC.getTime(current_time);
85+
86+
/* PRINT CURRENT TIME on Serial */
87+
Serial.print("Current time: ");
88+
/* DATE */
89+
Serial.print(current_time.getDayOfMonth());
90+
Serial.print("/");
91+
Serial.print(Month2int(current_time.getMonth()));
92+
Serial.print("/");
93+
Serial.print(current_time.getYear());
94+
Serial.print(" - ");
95+
Serial.print(current_time.getUnixTime());
96+
Serial.print(" - ");
97+
98+
struct timeval tv;
99+
gettimeofday(&tv, NULL);
100+
Serial.print(tv.tv_sec);
101+
Serial.print(" - ");
102+
103+
/* HOUR:MINUTES:SECONDS */
104+
Serial.print(current_time.getHour());
105+
Serial.print(":");
106+
Serial.print(current_time.getMinutes());
107+
Serial.print(":");
108+
Serial.println(current_time.getSeconds());
109+
110+
delay(1000);
111+
}
112+
}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ sentence=Arduino library for the PF1550 Power Management IC
66
paragraph=This library allows the control and configuration of the PF1550 used on various Arduino boards.
77
category=Device Control
88
url=https://github.com/arduino-libraries/Arduino_PF1550
9-
architectures=mbed,mbed_nicla,mbed_portenta
9+
architectures=mbed,mbed_nicla,mbed_portenta,renesas

src/PF1550.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "PF1550.h"
2424

25+
#include "PF1550/PF1550_Io_C33.h"
2526
#include "PF1550/PF1550_Io_EnvieH747.h"
2627

2728
/******************************************************************************
@@ -157,6 +158,10 @@ void PF1550::configCharger(IFastCharge const i_fast_charge,
157158
EXTERN DEFINITION
158159
******************************************************************************/
159160

160-
static PF1550_Io_EnvieH747 io;
161+
#ifdef ARDUINO_PORTENTA_H33
162+
static PF1550_Io_C33 io(interface::PF1550_I2C_DEFAULT_ADDR);
163+
#else
164+
static PF1550_Io_EnvieH747 io(interface::PF1550_I2C_DEFAULT_ADDR);
165+
#endif
161166

162167
PF1550 PMIC(io);

src/PF1550.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef ARDUINO_PF1550_H_
2020
#define ARDUINO_PF1550_H_
2121

22-
#define PF1550_I2C_ADDR 0x08
22+
#define PF1550_I2C_ADDR (interface::PF1550_I2C_DEFAULT_ADDR)
2323

2424
/******************************************************************************
2525
INCLUDE

src/PF1550/PF1550_Defines.h

+6
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,10 @@
6868
/* VBUS_INLIM_CNFG ************************************************************/
6969
#define REG_VBUS_INLIM_CNFG_VBUS_LIN_INLIM_mask (0xF8)
7070

71+
/* LED_PWM ********************************************************************/
72+
#define REG_LED_PWM_LED_EN_bp (7)
73+
74+
/* LED_CNFG *******************************************************************/
75+
#define REG_LED_CNFG_LEDOVRD_bp (5)
76+
7177
#endif /* PF1550_DEFINES_H_ */

src/PF1550/PF1550_Io_C33.cpp

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
Copyright (c) 2019 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
/******************************************************************************
20+
INCLUDE
21+
******************************************************************************/
22+
23+
#include "PF1550_Io_C33.h"
24+
25+
#ifdef ARDUINO_PORTENTA_H33
26+
27+
#include "Wire.h"
28+
#include "Arduino.h"
29+
30+
#include "PF1550_Defines.h"
31+
32+
/******************************************************************************
33+
CTOR/DTOR
34+
******************************************************************************/
35+
36+
PF1550_Io_C33::PF1550_Io_C33(uint8_t const i2c_addr)
37+
: _i2c_addr(i2c_addr)
38+
{
39+
40+
}
41+
42+
/******************************************************************************
43+
PUBLIC MEMBER FUNCTIONS
44+
******************************************************************************/
45+
46+
int PF1550_Io_C33::begin()
47+
{
48+
Wire3.begin();
49+
Wire3.setClock(100000);
50+
51+
/* Enable LED. */
52+
setBit(Register::CHARGER_LED_PWM, REG_LED_PWM_LED_EN_bp);
53+
/* Allow LED control by software. */
54+
setBit(Register::CHARGER_LED_CNFG, REG_LED_CNFG_LEDOVRD_bp);
55+
56+
return 1;
57+
}
58+
59+
void PF1550_Io_C33::readRegister(Register const reg_addr, uint8_t * data)
60+
{
61+
uint8_t i2c_data[2];
62+
63+
i2c_data[0] = (uint8_t)reg_addr;
64+
65+
writeRegister(_i2c_addr, i2c_data, 1, 1);
66+
67+
uint8_t retVal = Wire3.requestFrom(_i2c_addr, 1, true);
68+
69+
if (_debug) {
70+
_debug->print("requestFrom: ");
71+
_debug->println(retVal);
72+
}
73+
74+
int i = 0;
75+
while (Wire3.available() && i < 1) {
76+
data[0] = Wire3.read();
77+
i++;
78+
}
79+
80+
if (_debug) {
81+
_debug->println("Read:");
82+
for (i = 0; i < 1; i++) {
83+
_debug->println(data[i], HEX);
84+
}
85+
}
86+
}
87+
88+
void PF1550_Io_C33::writeRegister(uint8_t slave_addr, uint8_t *data, uint8_t data_len, uint8_t restart)
89+
{
90+
if (_debug)
91+
{
92+
_debug->print("Restart: ");
93+
_debug->println(restart);
94+
if (!restart)
95+
{
96+
_debug->print("PF1550_Io_C33::writeRegister at address=");
97+
_debug->print(data[0], HEX);
98+
_debug->print(" data=");
99+
_debug->println(data[1], HEX);
100+
_debug->print("i2c slave address: ");
101+
_debug->println(slave_addr);
102+
}
103+
else
104+
{
105+
_debug->print("PF1550_Io_C33::Read from register at address=");
106+
_debug->println(data[0], HEX);
107+
}
108+
}
109+
110+
Wire3.beginTransmission(slave_addr);
111+
Wire3.write(data, data_len);
112+
uint8_t retVal = Wire3.endTransmission(restart == 0 ? true : false);
113+
114+
if (_debug) {
115+
_debug->print("End transmission: ");
116+
_debug->println(retVal);
117+
}
118+
/*
119+
if (_debug) {
120+
_debug->println("Write:");
121+
for (int i = 0; i < data_len; i++) {
122+
_debug->println(data[i], HEX);
123+
}
124+
}
125+
*/
126+
}
127+
128+
#endif /* ARDUINO_PORTENTA_H33 */

src/PF1550/PF1550_Io_C33.h

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Copyright (c) 2019 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef PF1550_IO_C33_H_
20+
#define PF1550_IO_C33_H_
21+
22+
/******************************************************************************
23+
INCLUDE
24+
******************************************************************************/
25+
26+
#include "Arduino.h"
27+
#include "interface/PF1550_Io.h"
28+
29+
/******************************************************************************
30+
CLASS DECLARATION
31+
******************************************************************************/
32+
33+
class PF1550_Io_C33 : public interface::PF1550_Io
34+
{
35+
public:
36+
PF1550_Io_C33(uint8_t const i2c_addr);
37+
virtual ~PF1550_Io_C33() { }
38+
39+
virtual int begin () override;
40+
virtual void readRegister (Register const reg_addr, uint8_t * data) override;
41+
virtual void writeRegister(uint8_t slave_addr, uint8_t * data, uint8_t data_len, uint8_t restart) override;
42+
virtual void setSTANDBY () override { }
43+
virtual void clrSTANDBY () override { }
44+
45+
46+
private:
47+
48+
uint8_t const _i2c_addr;
49+
Stream * _debug;
50+
};
51+
52+
#endif /* PF1550_IO_C33_H_ */

src/PF1550/PF1550_Io_EnvieH747.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ int PF1550_Io_EnvieH747::begin()
4646
return 1;
4747
}
4848

49-
void PF1550_Io_EnvieH747::debug(Stream& stream)
50-
{
51-
_debug = &stream;
52-
}
53-
5449
void PF1550_Io_EnvieH747::readRegister(Register const reg_addr, uint8_t *data)
5550
{
5651
uint8_t i2c_data[2];

0 commit comments

Comments
 (0)