Enable Arduino Uno i2c debugging
This commit is contained in:
47
src/board/arduino/uno/battery.c
Normal file
47
src/board/arduino/uno/battery.c
Normal file
@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <common/i2c.h>
|
||||
|
||||
int smbus_read(uint8_t address, uint8_t command, uint16_t * data) {
|
||||
return i2c_get(address, command, (uint8_t *)data, 2);
|
||||
}
|
||||
|
||||
int smbus_write(uint8_t address, uint8_t command, uint16_t data) {
|
||||
return i2c_set(address, command, (uint8_t *)&data, 2);
|
||||
}
|
||||
|
||||
void battery_debug(void) {
|
||||
uint16_t data = 0;
|
||||
int res = 0;
|
||||
|
||||
#define command(N, A, V) { \
|
||||
printf(#N ": "); \
|
||||
res = smbus_read(A, V, &data); \
|
||||
if (res < 0) { \
|
||||
printf("ERROR %04X\n", -res); \
|
||||
} else { \
|
||||
printf("%04X\n", data); \
|
||||
} \
|
||||
}
|
||||
|
||||
printf("Battery:\n");
|
||||
command(Temperature, 0x0B, 0x08);
|
||||
command(Voltage, 0x0B, 0x09);
|
||||
command(Current, 0x0B, 0x0A);
|
||||
command(Charge, 0x0B, 0x0D);
|
||||
|
||||
printf("Charger:\n");
|
||||
command(ChargeOption0, 0x09, 0x12);
|
||||
command(ChargeOption1, 0x09, 0x3B);
|
||||
command(ChargeOption2, 0x09, 0x38);
|
||||
command(ChargeOption3, 0x09, 0x37);
|
||||
command(ChargeCurrent, 0x09, 0x14);
|
||||
command(ChargeVoltage, 0x09, 0x15);
|
||||
command(DishargeCurrent, 0x09, 0x39);
|
||||
command(InputCurrent, 0x09, 0x3F);
|
||||
command(ProchotOption0, 0x09, 0x3C);
|
||||
command(ProchotOption1, 0x09, 0x3D);
|
||||
command(ProchotStatus, 0x09, 0x3A);
|
||||
|
||||
#undef command
|
||||
}
|
10
src/board/arduino/uno/i2c.c
Normal file
10
src/board/arduino/uno/i2c.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <avr/io.h>
|
||||
|
||||
#include <board/cpu.h>
|
||||
#include <board/i2c.h>
|
||||
|
||||
void i2c_init(unsigned long baud) {
|
||||
TWAR = 0;
|
||||
TWBR = (uint8_t)(((F_CPU / baud) - 16 ) / 2);
|
||||
TWCR = 0;
|
||||
}
|
6
src/board/arduino/uno/include/board/battery.h
Normal file
6
src/board/arduino/uno/include/board/battery.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef _BOARD_BATTERY_H
|
||||
#define _BOARD_BATTERY_H
|
||||
|
||||
void battery_debug(void);
|
||||
|
||||
#endif // _BOARD_BATTERY_H
|
6
src/board/arduino/uno/include/board/i2c.h
Normal file
6
src/board/arduino/uno/include/board/i2c.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef _BOARD_I2C_H
|
||||
#define _BOARD_I2C_H
|
||||
|
||||
void i2c_init(unsigned long baud);
|
||||
|
||||
#endif // _BOARD_I2C_H
|
@ -1,10 +1,24 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <arch/gpio.h>
|
||||
#include <arch/i2c_slave.h>
|
||||
#include <arch/uart.h>
|
||||
#include <board/battery.h>
|
||||
#include <board/i2c.h>
|
||||
|
||||
void init(void) {
|
||||
uart_stdio_init(0, __CONSOLE_BAUD__);
|
||||
i2c_init(50000);
|
||||
}
|
||||
|
||||
static void i2c_slave_new() {}
|
||||
|
||||
static void i2c_slave_recv(uint8_t data) {
|
||||
printf("%c", data);
|
||||
}
|
||||
|
||||
static uint8_t i2c_slave_send() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct Gpio LED = GPIO(B, 5);
|
||||
@ -15,10 +29,16 @@ int main(void) {
|
||||
gpio_set_dir(&LED, true);
|
||||
gpio_set(&LED, false);
|
||||
printf("Hello from System76 EC for the Arduino Uno!\n");
|
||||
|
||||
battery_debug();
|
||||
|
||||
for (;;) {
|
||||
i2c_slave_init(0x76, i2c_slave_new, i2c_slave_recv, i2c_slave_send);
|
||||
int c = getchar();
|
||||
i2c_slave_stop();
|
||||
if (c == '\r') {
|
||||
putchar('\n');
|
||||
battery_debug();
|
||||
} else if (c > 0) {
|
||||
putchar(c);
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ INCLUDE+=$(wildcard $(BOARD_DIR)/keymap/*.h)
|
||||
# 3 - INFO
|
||||
# 4 - DEBUG
|
||||
# 5 - TRACE
|
||||
CFLAGS+=-DLEVEL=2
|
||||
CFLAGS+=-DLEVEL=4
|
||||
|
||||
# Enable I2C debug on 0x76
|
||||
#CFLAGS+=-DI2C_DEBUGGER=0x76
|
||||
CFLAGS+=-DI2C_DEBUGGER=0x76
|
||||
|
||||
# Add scratch ROM source
|
||||
SCRATCH_DIR=$(BOARD_DIR)/scratch
|
||||
|
Reference in New Issue
Block a user