kopia lustrzana https://github.com/meshtastic/firmware
ppr1: add crude version of charge controller driver
rodzic
f0eeaf01d4
commit
1a8891c33d
|
@ -7,9 +7,12 @@
|
|||
|
||||
### PPR1 TODO
|
||||
|
||||
* fix usb
|
||||
* fix usb - check latest tinyusb
|
||||
* Test GPS - try pulsing reset
|
||||
* properly test charge controller config and read battery/charge status
|
||||
* fix bluetooth
|
||||
* Test GPS
|
||||
* fix LCD max contrast (currently too high, needs to be about 40?)
|
||||
* save brightness settings in flash
|
||||
* make ST7567Wire driver less ugly, move OLED stuff into a common class treee
|
||||
* add LCD power save mode for lcd per page 31 of datasheet
|
||||
* add LCD power off sequence per datasheet to lcd driver
|
||||
|
|
|
@ -33,6 +33,13 @@ bool GPS::setup()
|
|||
pinMode(PIN_GPS_EN, OUTPUT);
|
||||
#endif
|
||||
|
||||
#ifdef PIN_GPS_RESET
|
||||
digitalWrite(PIN_GPS_RESET, 1); // assert for 10ms
|
||||
pinMode(PIN_GPS_RESET, OUTPUT);
|
||||
delay(10);
|
||||
digitalWrite(PIN_GPS_RESET, 0);
|
||||
#endif
|
||||
|
||||
setAwake(true); // Wake GPS power before doing any init
|
||||
bool ok = setupGPS();
|
||||
|
||||
|
@ -53,12 +60,6 @@ void GPS::wake()
|
|||
digitalWrite(PIN_GPS_WAKE, GPS_WAKE_ACTIVE);
|
||||
pinMode(PIN_GPS_WAKE, OUTPUT);
|
||||
#endif
|
||||
|
||||
#ifdef PIN_GPS_RESET
|
||||
digitalWrite(PIN_GPS_RESET, 0);
|
||||
pinMode(PIN_GPS_RESET, OUTPUT);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
#include "BQ25713.h"
|
||||
#include "configuration.h"
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#ifdef BQ25703A_ADDR
|
||||
|
||||
const uint8_t BQ25713::devAddr = BQ25703A_ADDR;
|
||||
|
||||
bool BQ25713::setup()
|
||||
{
|
||||
DEBUG_MSG("Init BQ25713\n");
|
||||
|
||||
// if(!writeReg(0x34,0x9034)) return false;
|
||||
//
|
||||
// if(!writeReg(0x34,0x8034)) return false;
|
||||
|
||||
if (!writeReg(0x00, 0x0F0A))
|
||||
return false; // Config Charge Option 0
|
||||
|
||||
if (!writeReg(0x02, 0x0224))
|
||||
return false; // Config Charge Current
|
||||
|
||||
if (!writeReg(0x04, 0x1070))
|
||||
return false; // Config Charge Voltage
|
||||
|
||||
if (!writeReg(0x06, 0x099C))
|
||||
return false; // Config OTG Voltage
|
||||
|
||||
if (!writeReg(0x08, 0x5000))
|
||||
return false; // Config OTG Current
|
||||
|
||||
// if(!writeReg(0x0A,0x0100)) return false;//Config Input Voltage
|
||||
|
||||
if (!writeReg(0x0C, 0x1800))
|
||||
return false; // Config Minimum System Voltage
|
||||
|
||||
if (!writeReg(0x0E, 0x4900))
|
||||
return false; // Config Input Current
|
||||
|
||||
if (!writeReg(0x30, 0xE210))
|
||||
return false; // Config Charge Option 1
|
||||
|
||||
if (!writeReg(0x32, 0x32BF))
|
||||
return false; // Config Charge Option 2
|
||||
|
||||
if (!writeReg(0x34, 0x0834))
|
||||
return false; // Config Charge Option 3
|
||||
|
||||
if (!writeReg(0x36, 0x4A65))
|
||||
return false; // Config Prochot Option 0
|
||||
|
||||
if (!writeReg(0x38, 0x81FF))
|
||||
return false; // Config Prochot Option 1
|
||||
|
||||
if (!writeReg(0x3A, 0xA0FF))
|
||||
return false; // Config ADC Option
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t BQ25713::readReg(uint8_t reg)
|
||||
{
|
||||
Wire.beginTransmission(devAddr);
|
||||
Wire.write(reg);
|
||||
byte err = Wire.endTransmission();
|
||||
if (!err) {
|
||||
int readLen = 2;
|
||||
Wire.requestFrom(devAddr, (int)(readLen + 1));
|
||||
if (Wire.available() >= readLen) {
|
||||
uint8_t lsb = Wire.read(), msb = Wire.read();
|
||||
|
||||
return (((uint16_t)msb) << 8) + lsb;
|
||||
} else
|
||||
return 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool BQ25713::writeReg(uint8_t reg, uint16_t v)
|
||||
{
|
||||
Wire.beginTransmission(devAddr);
|
||||
Wire.write(reg);
|
||||
Wire.write(v & 0xff);
|
||||
Wire.write((v >> 8) & 0xff);
|
||||
byte err = Wire.endTransmission(); // 0 for success
|
||||
|
||||
if (!err) {
|
||||
// Do a test readback for early debugging
|
||||
uint16_t found = readReg(reg);
|
||||
if (found != v) {
|
||||
DEBUG_MSG("Readback reg=0x%0x test failed, expected 0x%0x, found 0x%0x!\n", reg, v, found);
|
||||
return true; // claim success - FIXME
|
||||
}
|
||||
}
|
||||
return !err;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/**
|
||||
* Driver class to control/monitor BQ25713 charge controller
|
||||
*/
|
||||
class BQ25713 {
|
||||
static const uint8_t devAddr;
|
||||
|
||||
public:
|
||||
|
||||
/// Return true for success
|
||||
bool setup();
|
||||
|
||||
private:
|
||||
uint16_t readReg(uint8_t reg);
|
||||
|
||||
/// Return true for success
|
||||
bool writeReg(uint8_t reg, uint16_t v);
|
||||
};
|
||||
|
|
@ -82,6 +82,8 @@ int printf(const char *fmt, ...)
|
|||
return res;
|
||||
}
|
||||
|
||||
#include "BQ25713.h"
|
||||
|
||||
void nrf52Setup()
|
||||
{
|
||||
|
||||
|
@ -93,8 +95,11 @@ void nrf52Setup()
|
|||
// This is the recommended setting for Monitor Mode Debugging
|
||||
NVIC_SetPriority(DebugMonitor_IRQn, 6UL);
|
||||
|
||||
// Not yet on board
|
||||
// pmu.init();
|
||||
#ifdef BQ25703A_ADDR
|
||||
auto *bq = new BQ25713();
|
||||
if(!bq->setup())
|
||||
DEBUG_MSG("ERROR! Charge controller init failed\n");
|
||||
#endif
|
||||
|
||||
// Init random seed
|
||||
// FIXME - use this to get random numbers
|
||||
|
|
|
@ -107,10 +107,10 @@ static const uint8_t AREF = PIN_AREF;
|
|||
// #define GPS_TX_PIN PIN_SERIAL1_TX
|
||||
// #define GPS_RX_PIN PIN_SERIAL1_RX
|
||||
|
||||
#define PIN_GPS_RESET 29 // active high?
|
||||
#define PIN_GPS_RESET 29 // active high
|
||||
#define PIN_GPS_PPS 28
|
||||
// #define PIN_GPS_WAKE 20 // CELL_CTRL in schematic? based on their example code
|
||||
#define PIN_GPS_EN 7 // GPS_EN active high?
|
||||
#define PIN_GPS_EN 7 // GPS_EN active high
|
||||
|
||||
#define PIN_VUSB_EN 21
|
||||
|
||||
|
@ -119,6 +119,9 @@ static const uint8_t AREF = PIN_AREF;
|
|||
#define PIN_LCD_RESET 23 // active low, pulse low for 20ms at boot
|
||||
#define USE_ST7567
|
||||
|
||||
/// Charge controller I2C address
|
||||
#define BQ25703A_ADDR 0x6b
|
||||
|
||||
// Define if screen should be mirrored left to right
|
||||
#define SCREEN_MIRROR
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue