Refactor of smbus

This commit is contained in:
Jeremy Soller
2020-01-30 13:54:26 -07:00
parent 8df823b402
commit 6ee5612a4a
21 changed files with 66 additions and 36 deletions

View File

@ -1,14 +1,7 @@
#include <board/gpio.h> #include <board/gpio.h>
#include <board/smbus.h>
#include <common/debug.h> #include <common/debug.h>
#include <ec/i2c.h>
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
return i2c_get(&I2C_0, address, command, (uint8_t *)data, 2);
}
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
return i2c_set(&I2C_0, address, command, (uint8_t *)&data, 2);
}
// ChargeOption0 flags // ChargeOption0 flags
// Low Power Mode Enable // Low Power Mode Enable

View File

@ -16,6 +16,9 @@ CFLAGS+=-DLEVEL=2
# Enable I2C debug on 0x76 # Enable I2C debug on 0x76
CFLAGS+=-DI2C_DEBUGGER=0x76 CFLAGS+=-DI2C_DEBUGGER=0x76
# Set battery I2C bus
CFLAGS+=-DI2C_SMBUS=I2C_0
# Add scratch ROM source # Add scratch ROM source
SCRATCH_DIR=$(BOARD_DIR)/scratch SCRATCH_DIR=$(BOARD_DIR)/scratch
SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c) SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c)

View File

@ -4,5 +4,7 @@
#include <ec/smbus.h> #include <ec/smbus.h>
void smbus_init(void); void smbus_init(void);
int smbus_read(uint8_t address, uint8_t command, uint16_t * data);
int smbus_write(uint8_t address, uint8_t command, uint16_t data);
#endif // _BOARD_SMBUS_H #endif // _BOARD_SMBUS_H

View File

@ -9,7 +9,11 @@ SCRATCH_CFLAGS+=\
-Isrc/common/include \ -Isrc/common/include \
-Isrc/ec/$(EC)/include -Isrc/ec/$(EC)/include
#SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76 # Enable I2C debug on 0x76
SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76
# Set battery I2C bus
SCRATCH_CFLAGS+=-DI2C_SMBUS=I2C_0
SCRATCH_BUILD=$(BUILD)/scratch SCRATCH_BUILD=$(BUILD)/scratch
SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC)) SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC))

View File

@ -14,7 +14,7 @@ int putchar(int c) {
SBUF = byte; SBUF = byte;
#endif #endif
#ifdef I2C_DEBUGGER #ifdef I2C_DEBUGGER
i2c_send(&I2C_0, I2C_DEBUGGER, &byte, 1); i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1);
#endif #endif
return (int)byte; return (int)byte;
} }

View File

@ -17,5 +17,13 @@ void smbus_init(void) {
SMB45P3USH = 0x01; SMB45P3USH = 0x01;
// Set up for i2c usage // Set up for i2c usage
i2c_reset(&I2C_0, true); i2c_reset(&I2C_SMBUS, true);
}
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
return i2c_get(&I2C_SMBUS, address, command, (uint8_t *)data, 2);
}
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
return i2c_set(&I2C_SMBUS, address, command, (uint8_t *)&data, 2);
} }

View File

@ -14,7 +14,7 @@ int putchar(int c) {
SBUF = byte; SBUF = byte;
#endif #endif
#ifdef I2C_DEBUGGER #ifdef I2C_DEBUGGER
i2c_send(&I2C_0, I2C_DEBUGGER, &byte, 1); i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1);
#endif #endif
return (int)byte; return (int)byte;
} }

View File

@ -1,14 +1,7 @@
#include <board/gpio.h> #include <board/gpio.h>
#include <board/smbus.h>
#include <common/debug.h> #include <common/debug.h>
#include <ec/i2c.h>
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
return i2c_get(&I2C_0, address, command, (uint8_t *)data, 2);
}
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
return i2c_set(&I2C_0, address, command, (uint8_t *)&data, 2);
}
// ChargeOption0 flags // ChargeOption0 flags
// Low Power Mode Enable // Low Power Mode Enable

View File

@ -16,6 +16,9 @@ CFLAGS+=-DLEVEL=2
# Enable I2C debug on 0x76 # Enable I2C debug on 0x76
CFLAGS+=-DI2C_DEBUGGER=0x76 CFLAGS+=-DI2C_DEBUGGER=0x76
# Set battery I2C bus
CFLAGS+=-DI2C_SMBUS=I2C_0
# Add scratch ROM source # Add scratch ROM source
SCRATCH_DIR=$(BOARD_DIR)/scratch SCRATCH_DIR=$(BOARD_DIR)/scratch
SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c) SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c)

View File

@ -4,5 +4,7 @@
#include <ec/smbus.h> #include <ec/smbus.h>
void smbus_init(void); void smbus_init(void);
int smbus_read(uint8_t address, uint8_t command, uint16_t * data);
int smbus_write(uint8_t address, uint8_t command, uint16_t data);
#endif // _BOARD_SMBUS_H #endif // _BOARD_SMBUS_H

View File

@ -9,7 +9,11 @@ SCRATCH_CFLAGS+=\
-Isrc/common/include \ -Isrc/common/include \
-Isrc/ec/$(EC)/include -Isrc/ec/$(EC)/include
#SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76 # Enable I2C debug on 0x76
SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76
# Set battery I2C bus
SCRATCH_CFLAGS+=-DI2C_SMBUS=I2C_0
SCRATCH_BUILD=$(BUILD)/scratch SCRATCH_BUILD=$(BUILD)/scratch
SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC)) SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC))

View File

@ -14,7 +14,7 @@ int putchar(int c) {
SBUF = byte; SBUF = byte;
#endif #endif
#ifdef I2C_DEBUGGER #ifdef I2C_DEBUGGER
i2c_send(&I2C_0, I2C_DEBUGGER, &byte, 1); i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1);
#endif #endif
return (int)byte; return (int)byte;
} }

View File

@ -17,5 +17,13 @@ void smbus_init(void) {
SMB45P3USH = 0x01; SMB45P3USH = 0x01;
// Set up for i2c usage // Set up for i2c usage
i2c_reset(&I2C_0, true); i2c_reset(&I2C_SMBUS, true);
}
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
return i2c_get(&I2C_SMBUS, address, command, (uint8_t *)data, 2);
}
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
return i2c_set(&I2C_SMBUS, address, command, (uint8_t *)&data, 2);
} }

View File

@ -14,7 +14,7 @@ int putchar(int c) {
SBUF = byte; SBUF = byte;
#endif #endif
#ifdef I2C_DEBUGGER #ifdef I2C_DEBUGGER
i2c_send(&I2C_0, I2C_DEBUGGER, &byte, 1); i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1);
#endif #endif
return (int)byte; return (int)byte;
} }

View File

@ -1,13 +1,6 @@
#include <board/smbus.h>
#include <common/debug.h> #include <common/debug.h>
#include <ec/i2c.h>
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
return i2c_get(&I2C_4, address, command, (uint8_t *)data, 2);
}
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
return i2c_set(&I2C_4, address, command, (uint8_t *)&data, 2);
}
// ChargeOption0 flags // ChargeOption0 flags
// Low Power Mode Enable // Low Power Mode Enable

View File

@ -16,6 +16,9 @@ CFLAGS+=-DLEVEL=2
# Enable I2C debug on 0x76 # Enable I2C debug on 0x76
CFLAGS+=-DI2C_DEBUGGER=0x76 CFLAGS+=-DI2C_DEBUGGER=0x76
# Set battery I2C bus
CFLAGS+=-DI2C_SMBUS=I2C_4
# Add scratch ROM source # Add scratch ROM source
SCRATCH_DIR=$(BOARD_DIR)/scratch SCRATCH_DIR=$(BOARD_DIR)/scratch
SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c) SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c)

View File

@ -4,5 +4,7 @@
#include <ec/smbus.h> #include <ec/smbus.h>
void smbus_init(void); void smbus_init(void);
int smbus_read(uint8_t address, uint8_t command, uint16_t * data);
int smbus_write(uint8_t address, uint8_t command, uint16_t data);
#endif // _BOARD_SMBUS_H #endif // _BOARD_SMBUS_H

View File

@ -9,7 +9,11 @@ SCRATCH_CFLAGS+=\
-Isrc/common/include \ -Isrc/common/include \
-Isrc/ec/$(EC)/include -Isrc/ec/$(EC)/include
#SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76 # Enable I2C debug on 0x76
SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76
# Set battery I2C bus
SCRATCH_CFLAGS+=-DI2C_SMBUS=I2C_4
SCRATCH_BUILD=$(BUILD)/scratch SCRATCH_BUILD=$(BUILD)/scratch
SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC)) SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC))

View File

@ -14,7 +14,7 @@ int putchar(int c) {
SBUF = byte; SBUF = byte;
#endif #endif
#ifdef I2C_DEBUGGER #ifdef I2C_DEBUGGER
i2c_send(&I2C_4, I2C_DEBUGGER, &byte, 1); i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1);
#endif #endif
return (int)byte; return (int)byte;
} }

View File

@ -17,5 +17,13 @@ void smbus_init(void) {
SMB45P3USH = 0x01; SMB45P3USH = 0x01;
// Set up for i2c usage // Set up for i2c usage
i2c_reset(&I2C_4, true); i2c_reset(&I2C_SMBUS, true);
}
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
return i2c_get(&I2C_SMBUS, address, command, (uint8_t *)data, 2);
}
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
return i2c_set(&I2C_SMBUS, address, command, (uint8_t *)&data, 2);
} }

View File

@ -14,7 +14,7 @@ int putchar(int c) {
SBUF = byte; SBUF = byte;
#endif #endif
#ifdef I2C_DEBUGGER #ifdef I2C_DEBUGGER
i2c_send(&I2C_4, I2C_DEBUGGER, &byte, 1); i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1);
#endif #endif
return (int)byte; return (int)byte;
} }