Skip to content

Commit 2e96a09

Browse files
committed
Move PMIC initialization in a separate function and file
1 parent 75b42cb commit 2e96a09

File tree

3 files changed

+118
-69
lines changed

3 files changed

+118
-69
lines changed

app/main.cpp

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "board.h"
2323
#include "ota.h"
2424
#include "rtc.h"
25+
#include "power.h"
2526
#include "bootutil/bootutil_extra.h"
2627
#include "bootutil/bootutil_log.h"
2728
#include "bootutil/bootutil.h"
@@ -239,75 +240,7 @@ int main(void) {
239240

240241
HAL_FLASH_Unlock();
241242

242-
I2C i2c(BOARD_I2C_SDA, BOARD_I2C_SCL);
243-
244-
char data[2];
245-
246-
// LDO2 to 1.8V
247-
data[0]=0x4F;
248-
data[1]=0x0;
249-
i2c.write(8 << 1, data, sizeof(data));
250-
data[0]=0x50;
251-
data[1]=0xF;
252-
i2c.write(8 << 1, data, sizeof(data));
253-
254-
// LDO1 to 1.0V
255-
data[0]=0x4c;
256-
data[1]=0x5;
257-
i2c.write(8 << 1, data, sizeof(data));
258-
data[0]=0x4d;
259-
data[1]=0x3;
260-
i2c.write(8 << 1, data, sizeof(data));
261-
262-
// LDO3 to 1.2V
263-
data[0]=0x52;
264-
data[1]=0x9;
265-
i2c.write(8 << 1, data, sizeof(data));
266-
data[0]=0x53;
267-
data[1]=0xF;
268-
i2c.write(8 << 1, data, sizeof(data));
269-
270-
HAL_Delay(10);
271-
272-
data[0]=0x9C;
273-
data[1]=(1 << 7);
274-
i2c.write(8 << 1, data, sizeof(data));
275-
276-
// Disable charger led
277-
data[0]=0x9E;
278-
data[1]=(1 << 5);
279-
i2c.write(8 << 1, data, sizeof(data));
280-
281-
HAL_Delay(10);
282-
283-
// SW3: set 2A as current limit
284-
// Helps keeping the rail up at wifi startup
285-
data[0]=0x42;
286-
data[1]=(2);
287-
i2c.write(8 << 1, data, sizeof(data));
288-
289-
HAL_Delay(10);
290-
291-
// Change VBUS INPUT CURRENT LIMIT to 1.5A
292-
data[0]=0x94;
293-
data[1]=(20 << 3);
294-
i2c.write(8 << 1, data, sizeof(data));
295-
296-
#if 1
297-
// SW2 to 3.3V (SW2_VOLT)
298-
data[0]=0x3B;
299-
data[1]=0xF;
300-
i2c.write(8 << 1, data, sizeof(data));
301-
302-
// SW1 to 3.0V (SW1_VOLT)
303-
data[0]=0x35;
304-
data[1]=0xF;
305-
i2c.write(8 << 1, data, sizeof(data));
306-
307-
//data[0]=0x36;
308-
//data[1]=(2);
309-
//i2c.write(8 << 1, data, sizeof(data));
310-
#endif
243+
power_init();
311244

312245
HAL_Delay(10);
313246

app/power/power.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
Copyright (c) 2022 Arduino SA. 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. See the GNU
12+
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+
#include "power.h"
20+
#include "board.h"
21+
#include "mbed.h"
22+
23+
static void portenta_power_init() {
24+
I2C i2c(BOARD_I2C_SDA, BOARD_I2C_SCL);
25+
26+
char data[2];
27+
28+
// LDO2 to 1.8V
29+
data[0]=0x4F;
30+
data[1]=0x0;
31+
i2c.write(8 << 1, data, sizeof(data));
32+
data[0]=0x50;
33+
data[1]=0xF;
34+
i2c.write(8 << 1, data, sizeof(data));
35+
36+
// LDO1 to 1.0V
37+
data[0]=0x4c;
38+
data[1]=0x5;
39+
i2c.write(8 << 1, data, sizeof(data));
40+
data[0]=0x4d;
41+
data[1]=0x3;
42+
i2c.write(8 << 1, data, sizeof(data));
43+
44+
// LDO3 to 1.2V
45+
data[0]=0x52;
46+
data[1]=0x9;
47+
i2c.write(8 << 1, data, sizeof(data));
48+
data[0]=0x53;
49+
data[1]=0xF;
50+
i2c.write(8 << 1, data, sizeof(data));
51+
52+
HAL_Delay(10);
53+
54+
data[0]=0x9C;
55+
data[1]=(1 << 7);
56+
i2c.write(8 << 1, data, sizeof(data));
57+
58+
// Disable charger led
59+
data[0]=0x9E;
60+
data[1]=(1 << 5);
61+
i2c.write(8 << 1, data, sizeof(data));
62+
63+
HAL_Delay(10);
64+
65+
// SW3: set 2A as current limit
66+
// Helps keeping the rail up at wifi startup
67+
data[0]=0x42;
68+
data[1]=(2);
69+
i2c.write(8 << 1, data, sizeof(data));
70+
71+
HAL_Delay(10);
72+
73+
// Change VBUS INPUT CURRENT LIMIT to 1.5A
74+
data[0]=0x94;
75+
data[1]=(20 << 3);
76+
i2c.write(8 << 1, data, sizeof(data));
77+
78+
// SW2 to 3.3V (SW2_VOLT)
79+
data[0]=0x3B;
80+
data[1]=0xF;
81+
i2c.write(8 << 1, data, sizeof(data));
82+
83+
// SW1 to 3.0V (SW1_VOLT)
84+
data[0]=0x35;
85+
data[1]=0xF;
86+
i2c.write(8 << 1, data, sizeof(data));
87+
}
88+
89+
90+
void power_init() {
91+
portenta_power_init();
92+
}

app/power/power.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Copyright (c) 2022 Arduino SA. 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. See the GNU
12+
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 __POWER_H
20+
#define __POWER_H
21+
22+
void power_init();
23+
24+
#endif //__POWER_H

0 commit comments

Comments
 (0)