aboutsummaryrefslogtreecommitdiff
path: root/driver_fw/main.c
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2019-04-15 12:28:22 +0900
committerjaseg <git@jaseg.net>2019-04-15 12:28:22 +0900
commita8448faccabdcf5ca1fe05760bbbfb78a1c5e917 (patch)
tree465e8f9159bec0086300f2ededbe726ad3c95826 /driver_fw/main.c
parenta860bd27a0950e4dd8ae530f9095a91ced7436a3 (diff)
download8seg-a8448faccabdcf5ca1fe05760bbbfb78a1c5e917.tar.gz
8seg-a8448faccabdcf5ca1fe05760bbbfb78a1c5e917.tar.bz2
8seg-a8448faccabdcf5ca1fe05760bbbfb78a1c5e917.zip
driver/fw: current sensor works
Diffstat (limited to 'driver_fw/main.c')
-rw-r--r--driver_fw/main.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/driver_fw/main.c b/driver_fw/main.c
index 5960e23..1cad970 100644
--- a/driver_fw/main.c
+++ b/driver_fw/main.c
@@ -21,6 +21,7 @@
#include "i2c.h"
#include "lcd1602.h"
#include "mcp9801.h"
+#include "ina226.h"
#include <8b10b.h>
@@ -161,6 +162,7 @@ int main(void) {
using a Java(TM) GUI. */
i2c_enable(I2C1);
lcd1602_init();
+ ina226_init();
/* The MCP9801 temperature sensor is initialized below in the SysTick ISR since it needs a few milliseconds to
* powerup. */
@@ -254,6 +256,11 @@ void SVC_Handler(void) {
void PendSV_Handler(void) {
}
+char hexdigit(uint8_t nibble) {
+ nibble &= 0xf;
+ return (nibble < 10) ? ('0' + nibble) : ('A' + nibble - 10);
+}
+
void SysTick_Handler(void) {
sys_time_tick++;
sys_time_ms += TICK_MS;
@@ -271,7 +278,18 @@ void SysTick_Handler(void) {
buf[9] = (temp%100)/10 + '0';
buf[11] = temp%10 + '0';
lcd_write_str(0, 0, buf);
- lcd_write_str(0, 1, " "" "" "" ");
+ strcpy(buf, "INA:XXXX""/XXX""X ");
+ uint16_t rx = ina226_read_i();
+ buf[4] = hexdigit(rx>>12);
+ buf[5] = hexdigit(rx>>8);
+ buf[6] = hexdigit(rx>>4);
+ buf[7] = hexdigit(rx>>0);
+ rx = ina226_read_v();
+ buf[9] = hexdigit(rx>>12);
+ buf[10] = hexdigit(rx>>8);
+ buf[11] = hexdigit(rx>>4);
+ buf[12] = hexdigit(rx>>0);
+ lcd_write_str(0, 1, buf);
mcp9801_init();
}