Skip to content

Commit

Permalink
HIH Driver cleanup in BMSB
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLafleur committed Mar 1, 2025
1 parent 2ee42ba commit 5328b8f
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 105 deletions.
24 changes: 24 additions & 0 deletions components/bms_boss/HW/DRV_HIH_componentSpecific.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @file DRV_HIH_componentSpecific.c
* @brief Source code for HIH driver
*/

/******************************************************************************
* I N C L U D E S
******************************************************************************/

#include "DRV_HIH.h"
#include "HW_i2c.h"

/******************************************************************************
* P U B L I C V A R S
******************************************************************************/

HW_I2C_Device_S I2C_HIH = {
.addr = 0x27,
.handle = &i2c,
};

DRV_HIH_S hih_chip = {
.dev = &I2C_HIH,
};
65 changes: 0 additions & 65 deletions components/bms_boss/HW/HW_HIH.c

This file was deleted.

34 changes: 0 additions & 34 deletions components/bms_boss/HW/include/HW_HIH.h

This file was deleted.

5 changes: 4 additions & 1 deletion components/bms_boss/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SHARED_CODE = Dir("#/components/shared/code")
SHARED_LIBS = SHARED_CODE.Dir("libs")
SHARED_APP = SHARED_CODE.Dir("app")
SHARED_HW = SHARED_CODE.Dir("HW")
SHARED_DRV = SHARED_CODE.Dir("DRV")

env = PLATFORM_ENV.Clone(
tools=[
Expand Down Expand Up @@ -126,6 +127,7 @@ LIBS_INCLUDE_DIRS = [
SHARED_LIBS,
SHARED_APP,
SHARED_HW,
SHARED_DRV,
]

PROJECT_INCLUDE_DIRS = [
Expand Down Expand Up @@ -162,7 +164,8 @@ project_hw_files = [
HW_DIR.File("HW_msp.c"),
SHARED_HW.File("HW_tim.c"),
HW_DIR.File("HW_tim_componentSpecific.c"),
HW_DIR.File("HW_HIH.c"),
SHARED_DRV.File("DRV_HIH.c"),
HW_DIR.File("DRV_HIH_componentSpecific.c"),
SHARED_HW.File("HW_can.c"),
SHARED_HW.File("HW_gpio.c"),
]
Expand Down
10 changes: 5 additions & 5 deletions components/bms_boss/src/ENV.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <string.h>

/**< Driver Includes */
#include "HW_HIH.h"
#include "DRV_HIH.h"
#include "IO.h"


Expand Down Expand Up @@ -54,7 +54,7 @@ static void ENV_init()
memset(&ENV, 0x00, sizeof(ENV));
ENV.state = ENV_INIT;

if (!HIH_init())
if (!DRV_HIH_init())
{
// ENV.state = ENV_ERROR;
}
Expand All @@ -68,9 +68,9 @@ static void ENV_init()
*/
static void ENV10Hz_PRD()
{
if (hih_chip.data.state == HIH_MEASURING)
if (hih_chip.data.state == DRV_HIH_MEASURING)
{
if (HIH_getData())
if (DRV_HIH_getData())
{
ENV.board.ambient_temp = ((float32_t)hih_chip.data.temp)/16382*165-40;
ENV.board.rh = ((float32_t)hih_chip.data.rh)/16382*100;
Expand All @@ -90,7 +90,7 @@ static void ENV1Hz_PRD()
case ENV_INIT:
break;
case ENV_RUNNING:
HIH_startConversion();
DRV_HIH_startConversion();
break;
case ENV_ERROR:
break;
Expand Down
66 changes: 66 additions & 0 deletions components/shared/code/DRV/DRV_HIH.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @file HW_HIH.c
* @brief Source code for HIH driver
*/

/******************************************************************************
* I N C L U D E S
******************************************************************************/

#include "DRV_HIH.h"
#include <string.h>

/******************************************************************************
* E X T E R N S
******************************************************************************/

extern HW_I2C_Device_S I2C_HIH;

/******************************************************************************
* P U B L I C F U N C T I O N S
******************************************************************************/

bool DRV_HIH_init(void)
{
memset(&hih_chip.data, 0x00, sizeof(hih_chip.data));

if (!HW_I2C_masterWrite(hih_chip.dev, 0x00, 0, 10))
{
hih_chip.data.state = DRV_HIH_ERROR;
return false;
}

hih_chip.data.state = DRV_HIH_MEASURING;

return true;
}

bool DRV_HIH_getData(void)
{
uint8_t rdat[4] = {0x00};
if (hih_chip.data.state == DRV_HIH_MEASURING)
{
if (HW_I2C_masterRead(hih_chip.dev, (uint8_t*)&rdat, 4, 10))
{
hih_chip.data.rh = ((rdat[0] & 0x3f) << 8) | rdat[1];
hih_chip.data.temp = (rdat[2] << 6) | (rdat[3] >> 2);
hih_chip.data.state = DRV_HIH_WAITING;
return true;
}
}
return false;
}

bool DRV_HIH_startConversion(void)
{
if (hih_chip.data.state == DRV_HIH_WAITING)
{
if (HW_I2C_masterWrite(hih_chip.dev, 0x00, 0, 10))
{
hih_chip.data.state = DRV_HIH_MEASURING;
return true;
}
}

return false;
}
48 changes: 48 additions & 0 deletions components/shared/code/DRV/DRV_HIH.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @file HW_HIH.h
* @brief Header file for HIH driver
*/

/******************************************************************************
* I N C L U D E S
******************************************************************************/

#include "HW_i2c.h"
#include "LIB_Types.h"

/******************************************************************************
* T Y P E D E F S
******************************************************************************/

typedef enum {
DRV_HIH_INIT = 0x00,
DRV_HIH_MEASURING,
DRV_HIH_WAITING,
DRV_HIH_ERROR,
} DRV_HIH_State_E;

typedef struct {
uint16_t temp;
uint16_t rh;
DRV_HIH_State_E state;
} DRV_HIH_Data_S;

typedef struct {
HW_I2C_Device_S* dev;
DRV_HIH_Data_S data;
} DRV_HIH_S;

/******************************************************************************
* E X T E R N S
******************************************************************************/

extern DRV_HIH_S hih_chip;

/******************************************************************************
* P U B L I C F U N C T I O N P R O T O T Y P E S
******************************************************************************/

bool DRV_HIH_init(void);
bool DRV_HIH_getData(void);
bool DRV_HIH_startConversion(void);

0 comments on commit 5328b8f

Please sign in to comment.