- First complete version of firmware. Currently being tested in the rehearsal room
- Added bunch of screens, fonts and images - Added script to read out frame buffer (function currently disabled in Firmware)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
// ============================================================================================
|
||||
// Includes
|
||||
#include "I2C_Master.h"
|
||||
#include "EEPROM_M24C64.h"
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
@@ -27,6 +28,7 @@
|
||||
#define INA260_ENABLE_LEN_BIT 0
|
||||
|
||||
#define UINT8_ARR_TO_UINT16(_U8_) ((uint16_t)(_U8_[0]) << 8) | (uint16_t)(_U8_[1])
|
||||
#define UINT16_SWAP_BYTES(_U16_) ((_U16_ << 8) | (_U16_ >> 8 ))
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
@@ -84,10 +86,14 @@ typedef enum _INA260_AlertLatch {
|
||||
// Variables
|
||||
static uint16_t _INA260_BusVoltage_mV;
|
||||
static uint16_t _INA260_Current_mA;
|
||||
static uint16_t _INA260_Threshold;
|
||||
|
||||
static int32_t _Written_Current_Threshold;
|
||||
|
||||
|
||||
// ============================================================================================
|
||||
// Function Declarations
|
||||
void INA260_Write_Register(uint8_t reg_address, uint16_t reg_data);
|
||||
uint16_t INA260_Read_Register(uint8_t reg_address);
|
||||
|
||||
|
||||
@@ -98,22 +104,42 @@ void INA260_Init()
|
||||
{
|
||||
_INA260_BusVoltage_mV = 0;
|
||||
_INA260_Current_mA = 0;
|
||||
_Written_Current_Threshold = -1;
|
||||
|
||||
uint16_t Configuration_Register_Value =
|
||||
(0 << INA260_CONGIG_RST_BIT) | // No Reset
|
||||
(INA260_COUNT_1 << INA260_CONGIG_AVG0_BIT) | // Averaging Count
|
||||
(INA260_TIME_8_244_ms << INA260_CONGIG_VBUSCT0_BIT) | // Bus Voltage Conversion Time
|
||||
(INA260_TIME_8_244_ms << INA260_CONGIG_ISHCT0_BIT) | // Shunt Current Conversion Time
|
||||
(INA260_MODE_CONTINUOUS << INA260_CONGIG_MODE1_BIT); // Operating Mode
|
||||
uint16_t Configuration_Register_Value_Reset = (1 << INA260_CONGIG_RST_BIT);
|
||||
INA260_Write_Register(INA260_REG_CONFIG, Configuration_Register_Value_Reset);
|
||||
|
||||
I2CM_Packet_Transmit(INA260_I2CADDR_DEFAULT, INA260_REG_CONFIG, 1, (uint8_t*)(&Configuration_Register_Value), 2);
|
||||
|
||||
|
||||
uint16_t Enable_Register_Value =
|
||||
(1 << INA260_ENABLE_OCL_BIT) | // Over Current Limit
|
||||
(0 << INA260_ENABLE_APOL_BIT) | // Alert Polarity Bit
|
||||
(1 << INA260_ENABLE_LEN_BIT); // Alert Latch Enable
|
||||
|
||||
I2CM_Packet_Transmit(INA260_I2CADDR_DEFAULT, INA260_REG_MASK_ENABLE, 1, (uint8_t*)(&Enable_Register_Value), 2);
|
||||
uint16_t Configuration_Register_Value =
|
||||
(0 << INA260_CONGIG_RST_BIT) | // No Reset
|
||||
(INA260_COUNT_4 << INA260_CONGIG_AVG0_BIT) | // Averaging Count
|
||||
(INA260_TIME_8_244_ms << INA260_CONGIG_VBUSCT0_BIT) | // Bus Voltage Conversion Time
|
||||
(INA260_TIME_8_244_ms << INA260_CONGIG_ISHCT0_BIT) | // Shunt Current Conversion Time
|
||||
(INA260_MODE_CONTINUOUS << INA260_CONGIG_MODE1_BIT); // Operating Mode
|
||||
|
||||
sleep_ms(20);
|
||||
INA260_Update_Current_Threshold();
|
||||
sleep_ms(20);
|
||||
INA260_Write_Register(INA260_REG_CONFIG, Configuration_Register_Value);
|
||||
sleep_ms(20);
|
||||
INA260_Write_Register(INA260_REG_MASK_ENABLE, Enable_Register_Value);
|
||||
}
|
||||
|
||||
void INA260_Update_Current_Threshold()
|
||||
{
|
||||
if(_Written_Current_Threshold == _EEPROM_Content.Device_Configuration.Current_Threshold) {
|
||||
return;
|
||||
}
|
||||
|
||||
INA260_Write_Register(INA260_REG_ALERT_LIMIT, (uint16_t)(_EEPROM_Content.Device_Configuration.Current_Threshold * 4));
|
||||
|
||||
_Written_Current_Threshold = _EEPROM_Content.Device_Configuration.Current_Threshold;
|
||||
}
|
||||
|
||||
void INA260_Read_BusVoltage()
|
||||
@@ -130,6 +156,13 @@ void INA260_Read_Current()
|
||||
_INA260_Current_mA = (int16_t)((INA260_Current * 1250) / 1000);
|
||||
}
|
||||
|
||||
void INA260_Read_Threshold()
|
||||
{
|
||||
uint16_t INA260_Threshold = (uint16_t)INA260_Read_Register(INA260_REG_ALERT_LIMIT);
|
||||
|
||||
_INA260_Threshold = (uint16_t)(INA260_Threshold);
|
||||
}
|
||||
|
||||
uint16_t INA260_Get_BusVoltage_mV()
|
||||
{
|
||||
return _INA260_BusVoltage_mV;
|
||||
@@ -140,10 +173,21 @@ uint16_t INA260_Get_Current_mA()
|
||||
return _INA260_Current_mA;
|
||||
}
|
||||
|
||||
uint16_t INA260_Get_Threshold()
|
||||
{
|
||||
return _INA260_Threshold;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
Internal Functions
|
||||
*******************************************************************/
|
||||
void INA260_Write_Register(uint8_t reg_address, uint16_t reg_data)
|
||||
{
|
||||
uint16_t Swapped_Data = UINT16_SWAP_BYTES(reg_data);
|
||||
I2CM_Packet_Transmit(INA260_I2CADDR_DEFAULT, reg_address, 1, (uint8_t*)(&Swapped_Data), 2);
|
||||
}
|
||||
|
||||
uint16_t INA260_Read_Register(uint8_t reg_address)
|
||||
{
|
||||
uint8_t Receive_Data[2];
|
||||
@@ -151,4 +195,4 @@ uint16_t INA260_Read_Register(uint8_t reg_address)
|
||||
I2CM_Packet_Receive(INA260_I2CADDR_DEFAULT, reg_address, 1, Receive_Data, 2);
|
||||
|
||||
return UINT8_ARR_TO_UINT16(Receive_Data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user