main.c
123 lines
| 4.4 KiB
| text/x-c
|
CLexer
r51 | #include <stdio.h> | |||
#include <fat32.h> | ||||
#include <gpio.h> | ||||
#include <uart.h> | ||||
#include <stm32f4xx.h> | ||||
#include <math.h> | ||||
#include <bsp.h> | ||||
#include <i2c.h> | ||||
#include <CS43L22.h> | ||||
#include <ina226.h> | ||||
#include <fonts.h> | ||||
#include <stdlib.h> | ||||
#include <core.h> | ||||
r56 | #include <malloc.h> | |||
r51 | ||||
extern streamdevice* __opnfiles__[]; | ||||
#define LCD_COLOR_WHITE 0xFFFF | ||||
#define LCD_COLOR_BLACK 0x0000 | ||||
#define LCD_COLOR_GREY 0xF7DE | ||||
#define LCD_COLOR_BLUE 0x001F | ||||
#define LCD_COLOR_BLUE2 0x051F | ||||
#define LCD_COLOR_RED 0xF800 | ||||
#define LCD_COLOR_MAGENTA 0xF81F | ||||
#define LCD_COLOR_GREEN 0x07E0 | ||||
#define LCD_COLOR_CYAN 0x7FFF | ||||
#define LCD_COLOR_YELLOW 0xFFE0 | ||||
#ifndef PSU_DISABLE | ||||
#define PSU_DISABLE LED1 | ||||
#endif | ||||
r56 | void setUartAsStdout() | |||
{ | ||||
streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | ||||
uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); | ||||
uartmkstreamdev(uart,fd1); | ||||
__opnfiles__[1] = fd1; | ||||
} | ||||
r51 | ||||
r57 | void printSupplyStatus(int cur5v,int cur33v,int cur15v, int volt5v, int volt33v, int volt15v) | |||
{ | ||||
char buffer[64]; | ||||
int i=0; | ||||
int power5V=(cur5v*(volt5v/1000))/1000,power33V=(cur33v*(volt33v/1000))/1000,power15V=(cur15v*(volt15v/1000))/1000; | ||||
#define clearBuff for(i=0;i<64;i++)buffer[i]='\0' | ||||
ili9328paintFilRect(&lcd0,5,5,230,7*(ComicSansMS_18.Height+10)+50,LCD_COLOR_BLACK,4,LCD_COLOR_WHITE); | ||||
ili9328paintFilRect(&lcd0,5,7*(ComicSansMS_18.Height+10)+50,230,320 - (7*(ComicSansMS_18.Height+10)+50),LCD_COLOR_BLACK,4,LCD_COLOR_WHITE); | ||||
clearBuff; | ||||
sprintf(buffer,"%.3fV %dmA",volt5v/1000000.0,cur5v); | ||||
ili9328paintText(&lcd0,buffer,10,0*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | ||||
clearBuff; | ||||
sprintf(buffer,"%dmW",power5V); | ||||
ili9328paintText(&lcd0,buffer,10,1*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | ||||
clearBuff; | ||||
sprintf(buffer,"%.3fV %dmA",volt33v/1000000.0,cur33v); | ||||
ili9328paintText(&lcd0,buffer,10,2*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | ||||
clearBuff; | ||||
sprintf(buffer,"%dmW",power33V); | ||||
ili9328paintText(&lcd0,buffer,10,3*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | ||||
clearBuff; | ||||
sprintf(buffer,"%.3fV %dmA",volt15v/1000000.0,cur15v); | ||||
ili9328paintText(&lcd0,buffer,10,4*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | ||||
clearBuff; | ||||
sprintf(buffer,"%dmW",power15V); | ||||
ili9328paintText(&lcd0,buffer,10,5*(ComicSansMS_18.Height+10)+50,&ComicSansMS_18,LCD_COLOR_BLACK); | ||||
clearBuff; | ||||
sprintf(buffer,"Total = %dmW",power5V+power33V+power15V); | ||||
ili9328paintText(&lcd0,buffer,10,320-10-20,&ComicSansMS_18,LCD_COLOR_BLACK); | ||||
} | ||||
r51 | int main() | |||
{ | ||||
delay_100us(20000); | ||||
INA226_t ina5VSens,ina33VSens,ina15VSens; | ||||
gpioset(PSU_DISABLE);//enable psu! | ||||
r56 | setUartAsStdout(); | |||
//ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_BLACK,1,LCD_COLOR_BLACK); | ||||
r57 | ||||
ili9328paintFilRect(&lcd0,5,5,230,310,LCD_COLOR_BLACK,4,LCD_COLOR_WHITE); | ||||
if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,1,15,1000000)) | ||||
r51 | { | |||
printf("Can't open 3.3V monitor\n\r"); | ||||
} | ||||
r57 | if(-1==ina226open(&ina5VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000)) | |||
r51 | { | |||
printf("Can't open 5V monitor\n\r"); | ||||
} | ||||
if(-1==ina226open(&ina15VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,1,0,15,1000000)) | ||||
{ | ||||
printf("Can't open 1.5V monitor\n\r"); | ||||
} | ||||
r57 | int current5V,current33V,current15V,volt5v, volt33v, volt15v; | |||
r51 | while(1) | |||
{ | ||||
current5V = ina226getCurrent(&ina5VSens); | ||||
current33V = ina226getCurrent(&ina33VSens); | ||||
current15V = ina226getCurrent(&ina15VSens); | ||||
r57 | volt5v = ina226getBusVoltage(&ina5VSens); | |||
volt33v = ina226getBusVoltage(&ina33VSens); | ||||
volt15v = ina226getBusVoltage(&ina15VSens); | ||||
printf("%fV\t%dmA\n\r",volt15v/1000000.0,current15V/1000); | ||||
printf("%fV\t%dmA\n\r",volt33v/1000000.0,current33V/1000); | ||||
printf("%fV\t%dmA\n\r",volt5v/1000000.0,current5V/1000); | ||||
printSupplyStatus(current5V/1000,current33V/1000,current15V/1000,volt5v, volt33v, volt15v); | ||||
r56 | delay_100us(10000); | |||
r51 | } | |||
printf("Exit\n\r"); | ||||
return 0; | ||||
} | ||||