Skip to content

Commit

Permalink
v0.7: refactoring some
Browse files Browse the repository at this point in the history
  • Loading branch information
SMFSW committed Oct 6, 2018
1 parent a54b16c commit 3b57e45
Show file tree
Hide file tree
Showing 92 changed files with 667 additions and 266 deletions.
10 changes: 5 additions & 5 deletions AT42QT1244.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
/****************************************************************/
// std libs
#include <stdlib.h>
#include <string.h>
/****************************************************************/


I2C_slave AT42QT1244_hal = { { pNull, I2C_ADDR(AT42QT1244_BASE_ADDR), I2C_slave_timeout, I2C_MEMADD_SIZE_8BIT, I2C_FM }, 0, HAL_OK, true, false };
I2C_slave_t AT42QT1244_hal = { { pNull, I2C_ADDR(AT42QT1244_BASE_ADDR), I2C_slave_timeout, I2C_MEMADD_SIZE_8BIT, I2C_FM }, 0, HAL_OK, true, false };



Expand Down Expand Up @@ -81,14 +80,15 @@ FctERR NONNULL__ AT42QT1244_Write(const uint8_t * data, const uint16_t addr, con
FctERR NONNULL__ AT42QT1244_Read(uint8_t * data, const uint16_t addr, const uint16_t nb)
{
FctERR err = ERROR_OK;
uint16_t crc = 0;
uint8_t preamble[2] = { (uint8_t) addr, (uint8_t) nb };
uint8_t * tmp_read = malloc(nb + 2);

if (!I2C_is_enabled(&AT42QT1244_hal)) { return ERROR_DISABLED; } // Peripheral disabled
if (addr > AT42QT__SETUP_HOST_CRC_MSB) { return ERROR_RANGE; } // Unknown register
if ((addr + nb) > AT42QT__SETUP_HOST_CRC_MSB + 1) { return ERROR_OVERFLOW; } // More bytes than registers

uint16_t crc = 0;
uint8_t preamble[2] = { (uint8_t) addr, (uint8_t) nb };
uint8_t * tmp_read = malloc(nb + 2);

I2C_set_busy(&AT42QT1244_hal, true);

AT42QT1244_hal.status = HAL_I2C_Master_Transmit(AT42QT1244_hal.cfg.bus_inst, AT42QT1244_hal.cfg.addr, preamble, nb, AT42QT1244_hal.cfg.timeout);
Expand Down
11 changes: 10 additions & 1 deletion AT42QT1244.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef __AT42QT1244_H__
#define __AT42QT1244_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "sarmfsw.h"
#include "I2C_component.h"

Expand All @@ -30,7 +34,7 @@
// *****************************************************************************
// Section: Datas
// *****************************************************************************
extern I2C_slave AT42QT1244_hal; //!< AT42QT1244 Slave structure
extern I2C_slave_t AT42QT1244_hal; //!< AT42QT1244 Slave structure


// *****************************************************************************
Expand Down Expand Up @@ -291,6 +295,11 @@ FctERR NONNULL__ AT42QT1244_Read(uint8_t * data, const uint16_t addr, const uint
/****************************************************************/
#include "AT42QT1244_ex.h" // Include extensions
#include "AT42QT1244_proc.h" // Include procedures

#ifdef __cplusplus
}
#endif

#endif
#endif /* __AT42QT1244_H__ */
/****************************************************************/
8 changes: 8 additions & 0 deletions AT42QT1244_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef __AT42QT1244_EX_H__
#define __AT42QT1244_EX_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "sarmfsw.h"
#include "AT42QT1244.h"

Expand Down Expand Up @@ -97,6 +101,10 @@ __INLINE FctERR INLINE__ AT42QT1244_Key_Disable(const uint8_t Key) {


/****************************************************************/
#ifdef __cplusplus
}
#endif

#endif
#endif /* __AT42QT1244_EX_H__ */
/****************************************************************/
4 changes: 2 additions & 2 deletions AT42QT1244_proc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!\file AT42QT1244_proc.c
/*!\file AT42QT1244_t.c
** \author SMFSW
** \copyright MIT (c) 2017-2018, SMFSW
** \brief AT42QT1244 Driver procedures
Expand All @@ -13,7 +13,7 @@
/****************************************************************/


AT42QT1244_proc AT42QT1244 = { { &AT42QT1244_hal } };
AT42QT1244_t AT42QT1244 = { { &AT42QT1244_hal } };



Expand Down
18 changes: 13 additions & 5 deletions AT42QT1244_proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef __AT42QT1244_PROC_H__
#define __AT42QT1244_PROC_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "sarmfsw.h"
#include "AT42QT1244.h"

Expand All @@ -19,16 +23,16 @@
// *****************************************************************************
// Section: Types
// *****************************************************************************
/*!\struct AT42QT1244_proc
/*!\struct AT42QT1244_t
** \brief AT42QT1244 user interface struct
**/
typedef struct AT42QT1244_proc {
typedef struct AT42QT1244_t {
struct {
I2C_slave * slave_inst; //!< Slave structure
I2C_slave_t * slave_inst; //!< Slave structure
} cfg;
} AT42QT1244_proc;
} AT42QT1244_t;

extern AT42QT1244_proc AT42QT1244; //!< AT42QT1244 User structure
extern AT42QT1244_t AT42QT1244; //!< AT42QT1244 User structure


// *****************************************************************************
Expand Down Expand Up @@ -73,6 +77,10 @@ __WEAK FctERR AT42QT1244_handler(void);


/****************************************************************/
#ifdef __cplusplus
}
#endif

#endif
#endif /* __AT42QT1244_PROC_H__ */
/****************************************************************/
2 changes: 1 addition & 1 deletion BMP180.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/****************************************************************/


I2C_slave BMP180_hal = { { pNull, I2C_ADDR(BMP180_BASE_ADDR), I2C_slave_timeout, I2C_MEMADD_SIZE_8BIT, I2C_HS }, 0, HAL_OK, true, false };
I2C_slave_t BMP180_hal = { { pNull, I2C_ADDR(BMP180_BASE_ADDR), I2C_slave_timeout, I2C_MEMADD_SIZE_8BIT, I2C_HS }, 0, HAL_OK, true, false };


/****************************************************************/
Expand Down
11 changes: 10 additions & 1 deletion BMP180.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef __BMP180_H__
#define __BMP180_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "sarmfsw.h"
#include "I2C_component.h"

Expand All @@ -23,7 +27,7 @@
// *****************************************************************************
// Section: Datas
// *****************************************************************************
extern I2C_slave BMP180_hal; //!< BMP180 Slave structure
extern I2C_slave_t BMP180_hal; //!< BMP180 Slave structure


// *****************************************************************************
Expand Down Expand Up @@ -175,6 +179,11 @@ FctERR NONNULL__ BMP180_Read_Word(uint16_t * data, const uint16_t addr);
/****************************************************************/
#include "BMP180_ex.h" // Include extensions
#include "BMP180_proc.h" // Include procedures

#ifdef __cplusplus
}
#endif

#endif
#endif /* __BMP180_H__ */
/****************************************************************/
8 changes: 8 additions & 0 deletions BMP180_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef __BMP180_EX_H__
#define __BMP180_EX_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "sarmfsw.h"
#include "BMP180.h"

Expand Down Expand Up @@ -64,6 +68,10 @@ FctERR BMP180_Get_Pressure_Raw(int32_t * pr);


/****************************************************************/
#ifdef __cplusplus
}
#endif

#endif
#endif /* __BMP180_EX_H__ */
/****************************************************************/
7 changes: 3 additions & 4 deletions BMP180_proc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!\file BMP180_proc.c
/*!\file BMP180_t.c
** \author SMFSW
** \copyright MIT (c) 2017-2018, SMFSW
** \brief BMP180 Driver procedures
Expand All @@ -13,15 +13,14 @@
/****************************************************************/
// std libs
#include <math.h>
#include <string.h>
/****************************************************************/

//#define BMP180_TST //!< Defined to check calculations with datasheet

#if !defined(BMP180_TST)
BMP180_proc BMP180 = { 0.0f, 0.0f, 0.0f, 0.0f, 0, { &BMP180_hal, BMP180__OSS_8_TIME, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 } };
BMP180_t BMP180 = { 0.0f, 0.0f, 0.0f, 0.0f, 0, { &BMP180_hal, BMP180__OSS_8_TIME, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 } };
#else
BMP180_proc BMP180 = { 0.0f, 0.0f, 0.0f, 0.0f, 0, { &BMP180_hal, BMP180__OSS_1_TIME, { 408, -72, -14383, 32741, 32757, 23153, 6190, 4, -32768, -8711, 2868 }, 0 } };
BMP180_t BMP180 = { 0.0f, 0.0f, 0.0f, 0.0f, 0, { &BMP180_hal, BMP180__OSS_1_TIME, { 408, -72, -14383, 32741, 32757, 23153, 6190, 4, -32768, -8711, 2868 }, 0 } };
#endif

extern uint8_t BMP180_OSS_time[4];
Expand Down
34 changes: 21 additions & 13 deletions BMP180_proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef __BMP180_PROC_H__
#define __BMP180_PROC_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "sarmfsw.h"
#include "BMP180.h"

Expand Down Expand Up @@ -43,24 +47,24 @@ typedef struct BMP180_calibration {
int16_t MD; //!< md calibration value
} BMP180_calib;

/*!\struct BMP180_proc
/*!\struct BMP180_t
** \brief BMP180 user interface struct
**/
typedef struct BMP180_proc {
float Pressure; //!< Current atmospheric pressure
float Temperature; //!< Current temperature
float Altitude; //!< Current altitude
float SeaLevelPressure; //!< Current atmospheric pressure at sea level
uint32_t hStartConversion; //!< Last conversion start tick
typedef struct BMP180_t {
float Pressure; //!< Current atmospheric pressure
float Temperature; //!< Current temperature
float Altitude; //!< Current altitude
float SeaLevelPressure; //!< Current atmospheric pressure at sea level
uint32_t hStartConversion; //!< Last conversion start tick
struct {
I2C_slave * slave_inst; //!< Slave structure
BMP180_oversampling OSS; //!< Oversampling
BMP180_calib Calib; //!< Calibration values
uint8_t Id; //!< Chip ID
I2C_slave_t * slave_inst; //!< Slave structure
BMP180_oversampling OSS; //!< Oversampling
BMP180_calib Calib; //!< Calibration values
uint8_t Id; //!< Chip ID
} cfg;
} BMP180_proc;
} BMP180_t;

extern BMP180_proc BMP180; //!< BMP180 User structure
extern BMP180_t BMP180; //!< BMP180 User structure


// *****************************************************************************
Expand Down Expand Up @@ -112,6 +116,10 @@ __WEAK FctERR BMP180_handler(void);


/****************************************************************/
#ifdef __cplusplus
}
#endif

#endif
#endif /* __BMP180_PROC_H__ */
/****************************************************************/
2 changes: 1 addition & 1 deletion DRV2605L.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/****************************************************************/


I2C_slave DRV2605_hal = { { pNull, I2C_ADDR(DRV2605L_BASE_ADDR), I2C_slave_timeout, I2C_MEMADD_SIZE_8BIT, I2C_FM }, 0, HAL_OK, true, false };
I2C_slave_t DRV2605_hal = { { pNull, I2C_ADDR(DRV2605L_BASE_ADDR), I2C_slave_timeout, I2C_MEMADD_SIZE_8BIT, I2C_FM }, 0, HAL_OK, true, false };


/****************************************************************/
Expand Down
11 changes: 10 additions & 1 deletion DRV2605L.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef __DRV2605L_H__
#define __DRV2605L_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "sarmfsw.h"
#include "I2C_component.h"

Expand All @@ -24,7 +28,7 @@
// *****************************************************************************
// Section: Datas
// *****************************************************************************
extern I2C_slave DRV2605_hal; //!< DRV2605L Slave structure
extern I2C_slave_t DRV2605_hal; //!< DRV2605L Slave structure


// *****************************************************************************
Expand Down Expand Up @@ -494,6 +498,11 @@ FctERR NONNULL__ DRV2605L_Read(uint8_t * data, const uint16_t addr, const uint16
/****************************************************************/
#include "DRV2605L_ex.h" // Include extensions
#include "DRV2605L_proc.h" // Include procedures

#ifdef __cplusplus
}
#endif

#endif
#endif /* __DRV2605L_H__ */
/****************************************************************/
8 changes: 8 additions & 0 deletions DRV2605L_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#ifndef __DRV2605L_EX_H__
#define __DRV2605L_EX_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "sarmfsw.h"
#include "DRV2605L.h"

Expand Down Expand Up @@ -323,6 +327,10 @@ __INLINE FctERR INLINE__ DRV2605L_Get_ChipID(uint8_t * id) {


/****************************************************************/
#ifdef __cplusplus
}
#endif

#endif
#endif /* __DRV2605L_EX_H__ */
/****************************************************************/
4 changes: 2 additions & 2 deletions DRV2605L_proc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!\file DRV2605L_proc.c
/*!\file DRV2605L_t.c
** \author SMFSW
** \copyright MIT (c) 2017-2018, SMFSW
** \brief DRV2605L Driver procedures
Expand All @@ -13,7 +13,7 @@
/****************************************************************/


DRV2605L_proc DRV2605L = { { &DRV2605_hal, DRV__MODE_INTERNAL_TRIGGER, DRV__ACT_ERM, DRV__OPEN_LOOP, DRV__IN_PWM, DRV__RTP_SIGNED, 0 } };
DRV2605L_t DRV2605L = { { &DRV2605_hal, DRV__MODE_INTERNAL_TRIGGER, DRV__ACT_ERM, DRV__OPEN_LOOP, DRV__IN_PWM, DRV__RTP_SIGNED, 0 } };


/****************************************************************/
Expand Down
Loading

0 comments on commit 3b57e45

Please sign in to comment.