commit ae5a6057a6ae0c40887ea7c93b7759c725f04097
parent 9e3269081a984b88bca97bc53699526c99c1693f
Author: Lukas F. Hartmann <lukas@mntre.com>
Date: Thu, 25 Jun 2020 17:04:45 +0200
WIP: report battery status to SOM via SSP0 (SPI)
Diffstat:
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/reform2-lpc-fw/src/boards/reform2/board_reform2.c b/reform2-lpc-fw/src/boards/reform2/board_reform2.c
@@ -10,6 +10,7 @@
#include "core/eeprom/eeprom.h"
#include "core/pmu/pmu.h"
#include "core/i2c/i2c.h"
+#include "core/ssp0/ssp0.h"
#include "core/ssp1/ssp1.h"
#include "core/uart/uart.h"
@@ -386,8 +387,14 @@ void boardInit(void)
uartInit(CFG_UART_BAUDRATE);
i2cInit(I2CMASTER);
+
+ // SPI1 connected to battery monitor (we're master)
ssp1Init();
ssp1ClockSlow();
+
+ // SPI0 connected to the main SOM (they're master)
+ ssp0Init();
+ ssp0ClockSlow();
LPC_GPIO->DIR[1] |= (1 << 31);
LPC_GPIO->DIR[1] |= (1 << 25);
@@ -423,10 +430,6 @@ void handle_commands() {
// 4 command letter expected
// 5 syntax error (unexpected character)
// 6 command letter entered
-
- // TODO get cell voltage
- // TODO get charger state
- // TODO get charger status / mode
if (cmd_state>=ST_EXPECT_DIGIT_0 && cmd_state<=ST_EXPECT_DIGIT_3) {
// read number or command
@@ -563,6 +566,12 @@ void handle_commands() {
}
}
+void report_to_spi(void)
+{
+ char report[64];
+ sprintf(report, "(%dmV %dmA)\n", (int)(volts*1000.0), (int)(current*1000.0));
+}
+
int main(void)
{
boardInit();
@@ -646,8 +655,11 @@ int main(void)
}
}
}
-
+
+ // handle keyboard commands
handle_commands();
+ // report to SPI0 master
+ report_to_spi();
cur_second = delayGetSecondsActive();
if (last_second != cur_second) {
diff --git a/reform2-lpc-fw/src/boards/reform2/board_reform2.h b/reform2-lpc-fw/src/boards/reform2/board_reform2.h
@@ -302,7 +302,7 @@ extern "C" {
#define CFG_SSP_SCK1_1_20 (20)
// Select the appropriate pin locations here
- #define CFG_SSP_SCK0_LOCATION (CFG_SSP_SCK0_1_29)
+ #define CFG_SSP_SCK0_LOCATION (CFG_SSP_SCK0_0_10)
#define CFG_SSP_MISO1_LOCATION (CFG_SSP_MISO1_1_21)
#define CFG_SSP_MOSI1_LOCATION (CFG_SSP_MOSI1_1_22)
#define CFG_SSP_SCK1_LOCATION (CFG_SSP_SCK1_1_20)
diff --git a/reform2-lpc-fw/src/core/ssp0/ssp0.c b/reform2-lpc-fw/src/core/ssp0/ssp0.c
@@ -143,8 +143,8 @@ void ssp0Init(void)
Dummy = LPC_SSP0->DR;
}
- /* Enable device and set it to master mode, no loopback */
- LPC_SSP0->CR1 = SSP0_CR1_SSE_ENABLED | SSP0_CR1_MS_MASTER | SSP0_CR1_LBM_NORMAL;
+ /* Enable device and set it to slave mode, no loopback */
+ LPC_SSP0->CR1 = SSP0_CR1_SSE_ENABLED | SSP0_CR1_MS_SLAVE | SSP0_CR1_LBM_NORMAL;
}
/**************************************************************************/