commit 88f11a0dd3dc47fd9373aee40eebfafb327ee5fa
parent 833bf9ab2f214a07640eb959533e33fd8f5e56c4
Author: mntmn <lukas@mntmn.com>
Date: Thu, 25 Jun 2020 17:41:24 +0200
Merge branch 'master' of https://source.mntmn.com/MNT/reform
Diffstat:
3 files changed, 25 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"
@@ -409,8 +410,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);
@@ -446,10 +453,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
@@ -610,6 +613,16 @@ void handle_commands() {
}
}
+#define REPORT_MAX 63
+void report_to_spi(void)
+{
+ char report[REPORT_MAX+1];
+ snprintf(report, REPORT_MAX, "(%dmV %dmA)\n", (int)(volts*1000.0), (int)(current*1000.0));
+
+ report[63] = 0;
+ ssp0Send((uint8_t*)report, strlen(report));
+}
+
int main(void)
{
boardInit();
@@ -724,7 +737,8 @@ int main(void)
}
}
}
-
+
+ // handle keyboard commands
handle_commands();
cur_second = delayGetSecondsActive();
@@ -732,6 +746,9 @@ int main(void)
if (cur_second-last_second<10) {
// prevent rollovers
cycles_in_state += cur_second-last_second;
+
+ // report to SPI0 master
+ report_to_spi();
}
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;
}
/**************************************************************************/