Skip to content

Commit 5cbf75b

Browse files
committed
Merge remote-tracking branch 'Masa/master'
2 parents bbb53be + f277726 commit 5cbf75b

12 files changed

+223
-301
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ include $(DEVKITPRO)/libnx/switch_rules
3838
# NACP building is skipped as well.
3939
#---------------------------------------------------------------------------------
4040
APP_TITLE := Status Monitor
41-
APP_VERSION := 1.1.3U+
41+
APP_VERSION := 1.1.4U
4242
TARGET := $(notdir $(CURDIR))
4343
BUILD := build
4444
SOURCES := source

include/i2c.h

+33-17
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
/*
2-
Functions taken from Switch-OC-Suite source code made by KazushiMe
3-
Original repository link (Deleted, last checked 15.04.2023): https://github.com/KazushiMe/Switch-OC-Suite
4-
*/
1+
#pragma once
52

6-
#include "max17050.h"
7-
8-
constexpr float max17050SenseResistor = MAX17050_BOARD_SNS_RESISTOR_UOHM / 1000; // in uOhm
9-
constexpr float max17050CGain = 1.99993;
10-
11-
Result I2cReadRegHandler(u8 reg, I2cDevice dev, u16 *out)
3+
Result I2cReadRegHandler16(u8 reg, I2cDevice dev, u16 *out)
124
{
135
struct readReg {
146
u8 send;
@@ -46,16 +38,40 @@ Result I2cReadRegHandler(u8 reg, I2cDevice dev, u16 *out)
4638
return 0;
4739
}
4840

49-
Result Max17050ReadReg(u8 reg, u16 *out)
41+
Result I2cReadRegHandler8(u8 reg, I2cDevice dev, u8 *out)
5042
{
51-
u16 data = 0;
52-
Result res = I2cReadRegHandler(reg, I2cDevice_Max17050, &data);
43+
struct readReg {
44+
u8 send;
45+
u8 sendLength;
46+
u8 sendData;
47+
u8 receive;
48+
u8 receiveLength;
49+
};
50+
51+
I2cSession _session;
52+
53+
Result res = i2cOpenSession(&_session, dev);
54+
if (res)
55+
return res;
56+
57+
u8 val;
5358

54-
if (R_FAILED(res))
59+
struct readReg readRegister = {
60+
.send = 0 | (I2cTransactionOption_Start << 6),
61+
.sendLength = sizeof(reg),
62+
.sendData = reg,
63+
.receive = 1 | (I2cTransactionOption_All << 6),
64+
.receiveLength = sizeof(val),
65+
};
66+
67+
res = i2csessionExecuteCommandList(&_session, &val, sizeof(val), &readRegister, sizeof(readRegister));
68+
if (res)
5569
{
70+
i2csessionClose(&_session);
5671
return res;
5772
}
5873

59-
*out = data;
60-
return res;
61-
}
74+
*out = val;
75+
i2csessionClose(&_session);
76+
return 0;
77+
}

include/max17050.h

+22-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121
*/
2222

23+
/*
24+
* Modified by: MasaGratoR
25+
*/
2326

2427
#ifndef __MAX17050_H_
2528
#define __MAX17050_H_
2629

2730
//#include <utils/types.h>
28-
31+
#include "i2c.h"
2932

3033
/* Board default values */
3134
#define MAX17050_BOARD_CGAIN 2 /* Actual: 1.99993 */
@@ -44,6 +47,9 @@
4447

4548
#define MAX17050_WAIT_NS 1175800000
4649

50+
constexpr float max17050SenseResistor = MAX17050_BOARD_SNS_RESISTOR_UOHM / 1000; // in uOhm
51+
constexpr float max17050CGain = 1.99993;
52+
4753

4854
enum MAX17050_reg {
4955
MAX17050_STATUS = 0x00,
@@ -142,4 +148,18 @@ int max17050_get_property(enum MAX17050_reg reg, int *value);
142148
int max17050_fix_configuration();
143149
u32 max17050_get_cached_batt_volt();
144150
*/
145-
#endif /* __MAX17050_H_ */
151+
#endif /* __MAX17050_H_ */
152+
153+
Result Max17050ReadReg(u8 reg, u16 *out)
154+
{
155+
u16 data = 0;
156+
Result res = I2cReadRegHandler16(reg, I2cDevice_Max17050, &data);
157+
158+
if (R_FAILED(res))
159+
{
160+
return res;
161+
}
162+
163+
*out = data;
164+
return res;
165+
}

include/tmp451.h

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* SOC/PCB Temperature driver for Nintendo Switch's TI TMP451
3+
*
4+
* Copyright (c) 2018 CTCaer
5+
*
6+
* This program is free software; you can redistribute it and/or modify it
7+
* under the terms and conditions of the GNU General Public License,
8+
* version 2, as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13+
* more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
/*
20+
* Modified by: MasaGratoR
21+
*/
22+
23+
#ifndef __TMP451_H_
24+
#define __TMP451_H_
25+
26+
//#include <utils/types.h>
27+
#include "i2c.h"
28+
29+
//#define TMP451_I2C_ADDR 0x4C
30+
31+
#define TMP451_PCB_TEMP_REG 0x00
32+
#define TMP451_SOC_TEMP_REG 0x01
33+
34+
/*
35+
#define TMP451_CONFIG_REG 0x09
36+
#define TMP451_CNV_RATE_REG 0x0A
37+
*/
38+
39+
#define TMP451_SOC_TEMP_DEC_REG 0x10
40+
#define TMP451_PCB_TEMP_DEC_REG 0x15
41+
42+
/*
43+
#define TMP451_SOC_TMP_OFH_REG 0x11
44+
#define TMP451_SOC_TMP_OFL_REG 0x12
45+
*/
46+
47+
// If input is false, the return value is packed. MSByte is the integer in oC
48+
// and the LSByte is the decimal point truncated to 2 decimal places.
49+
// Otherwise it's an integer oC.
50+
/*
51+
u16 tmp451_get_soc_temp(bool integer);
52+
u16 tmp451_get_pcb_temp(bool integer);
53+
void tmp451_init();
54+
void tmp451_end();
55+
*/
56+
57+
Result Tmp451ReadReg(u8 reg, u8 *out)
58+
{
59+
u8 data = 0;
60+
Result res = I2cReadRegHandler8(reg, I2cDevice_Tmp451, &data);
61+
62+
if (R_FAILED(res))
63+
{
64+
return res;
65+
}
66+
67+
*out = data;
68+
return res;
69+
}
70+
71+
Result Tmp451GetSocTemp(float* temperature) {
72+
u8 integer = 0;
73+
u8 decimals = 0;
74+
75+
Result rc = Tmp451ReadReg(TMP451_SOC_TEMP_REG, &integer);
76+
if (R_FAILED(rc))
77+
return rc;
78+
rc = Tmp451ReadReg(TMP451_SOC_TEMP_DEC_REG, &decimals);
79+
if (R_FAILED(rc))
80+
return rc;
81+
82+
decimals = ((u16)(decimals >> 4) * 625) / 100;
83+
*temperature = (float)(integer) + ((float)(decimals) / 100);
84+
return rc;
85+
}
86+
87+
Result Tmp451GetPcbTemp(float* temperature) {
88+
u8 integer = 0;
89+
u8 decimals = 0;
90+
91+
Result rc = Tmp451ReadReg(TMP451_PCB_TEMP_REG, &integer);
92+
if (R_FAILED(rc))
93+
return rc;
94+
rc = Tmp451ReadReg(TMP451_PCB_TEMP_DEC_REG, &decimals);
95+
if (R_FAILED(rc))
96+
return rc;
97+
98+
decimals = ((u16)(decimals >> 4) * 625) / 100;
99+
*temperature = (float)(integer) + ((float)(decimals) / 100);
100+
return rc;
101+
}
102+
103+
#endif /* __TMP451_H_ */

0 commit comments

Comments
 (0)