Commit 0c0ddc14 authored by schneider's avatar schneider
Browse files

fix(MAX77650): Implement I2C read write

parent b45a1af9
......@@ -35,8 +35,10 @@
**********************************************************************/
#include <MAX77650-Arduino-Library.h>
#include "MAX77650-Arduino-Library.h"
#include "i2c.h"
#include <stdint.h>
#include <stdbool.h>
/**********************************************************************
......@@ -61,34 +63,29 @@
*https://www.maximintegrated.com/en/app-notes/index.mvp/id/6428
**********************************************************************/
int MAX77650_read_register(int ADDR){
#if 0
int retval = -1;
Wire.beginTransmission(MAX77650_ADDR);
Wire.write(ADDR);
Wire.endTransmission();
Wire.requestFrom(MAX77650_ADDR,1);
if (Wire.available()<=1)
retval = (Wire.read());
#endif
}
uint8_t MAX77650_write_register(int ADDR, int data){
#if 0
int retval = -1;
Wire.beginTransmission(MAX77650_ADDR);
Wire.write(ADDR);
Wire.write(data);
Wire.endTransmission();
Wire.beginTransmission(MAX77650_ADDR);
Wire.write(ADDR);
Wire.write(data);
Wire.endTransmission();
#endif
}
bool MAX77650_getDIDM(void){
#define I2C_DEVICE MXC_I2C1_BUS0
uint8_t MAX77650_read_register(uint8_t ADDR){
//printf("MAX77650_read_register 0x%02x\n", ADDR);
if(I2C_MasterWrite(I2C_DEVICE, MAX77650_ADDR << 1, &ADDR, 1, 1) == 1) {
uint8_t data;
I2C_MasterRead(I2C_DEVICE, MAX77650_ADDR << 1, &data, 1, 0);
return data;
}
return 0;
}
uint8_t MAX77650_write_register(uint8_t ADDR, uint8_t data){
uint8_t buf[2];
//printf("MAX77650_write_register 0x%02x 0x%02x\n", ADDR, data);
buf[0] = ADDR;
buf[1] = data;
return I2C_MasterWrite(I2C_DEVICE, MAX77650_ADDR << 1, buf, 2, 0);
}
uint8_t MAX77650_getDIDM(void){
return ((MAX77650_read_register(MAX77650_STAT_GLBL_ADDR) >> 6) & 0b00000011);
}
......
......@@ -46,6 +46,9 @@
#ifndef MAX77650_H
#define MAX77650_H
#include <stdint.h>
#include <stdbool.h>
/**********************************************************************
*@brief MAX77650 - The MAX77650/MAX77651 provide highly-integrated battery charging and
*power supply solutions for low-power wearable applications where size and efficiency
......@@ -117,12 +120,11 @@
#define MAX77650_CNFG_LED_TOP_ADDR 0x46 //LED Configuration Register; Reset Value 0x0D; Read/Write
//***** End MAX77650 Register Definitions *****
bool MAX77650_init(void);
int MAX77650_read_register(int);
uint8_t MAX77650_write_register(int, int);
uint8_t MAX77650_read_register(uint8_t);
uint8_t MAX77650_write_register(uint8_t, uint8_t);
//Status Register (STAT_GLBL) related reads
bool MAX77650_getDIDM(void); //Returns Part Number; Return Value: 1=MAX77650; 2=MAX77651; -1=error reading DeviceID
uint8_t MAX77650_getDIDM(void); //Returns Part Number; Return Value: 1=MAX77650; 2=MAX77651; -1=error reading DeviceID
bool MAX77650_getLDO_DropoutDetector(void); //Returns whether the LDO is in Dropout or not; Return Value: 0=LDO is not in dropout; 1=LDO is in dropout
bool MAX77650_getThermalAlarm1(void); //Returns Thermal Alarm (TJA1 limit); Return Value: 0=Tj<TJA1; 1=Tj>TJA1
bool MAX77650_getThermalAlarm2(void); //Returns Therma2 Alarm (TJA2 limit); Return Value: 0=Tj<TJA2; 1=Tj>TJA2
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment