Skip to content

Commit

Permalink
v0.6: refactored ERR_xx to ERROR_xx
Browse files Browse the repository at this point in the history
  • Loading branch information
SMFSW committed Nov 4, 2017
1 parent 3ba3145 commit 1cf727e
Show file tree
Hide file tree
Showing 49 changed files with 313 additions and 312 deletions.
20 changes: 10 additions & 10 deletions AT42QT1244.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ __WEAK FctERR AT42QT1244_Init(void)

FctERR AT42QT1244_Write(uint8_t * data, uint16_t addr, uint16_t nb)
{
if (!I2C_is_enabled(&AT42QT1244_hal)) { return ERR_DISABLED; } // Peripheral disabled
if (!data) { return ERR_MEMORY; } // Null pointer
if (addr > AT42QT__SETUP_HOST_CRC_MSB) { return ERR_RANGE; } // Unknown register
if ((addr + nb) > AT42QT__SETUP_HOST_CRC_MSB + 1) { return ERR_OVERFLOW; } // More bytes than registers
if (!I2C_is_enabled(&AT42QT1244_hal)) { return ERROR_DISABLED; } // Peripheral disabled
if (!data) { return ERROR_MEMORY; } // Null pointer
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

I2C_set_busy(&AT42QT1244_hal, true);

Expand All @@ -80,15 +80,15 @@ FctERR AT42QT1244_Write(uint8_t * data, uint16_t addr, uint16_t nb)

FctERR AT42QT1244_Read(uint8_t * data, uint16_t addr, uint16_t nb)
{
FctERR err = ERR_OK;
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 ERR_DISABLED; } // Peripheral disabled
if ((!data) || (!tmp_read)) { return ERR_MEMORY; } // Null pointer or not malloc failed
if (addr > AT42QT__SETUP_HOST_CRC_MSB) { return ERR_RANGE; } // Unknown register
if ((addr + nb) > AT42QT__SETUP_HOST_CRC_MSB + 1) { return ERR_OVERFLOW; } // More bytes than registers
if (!I2C_is_enabled(&AT42QT1244_hal)) { return ERROR_DISABLED; } // Peripheral disabled
if ((!data) || (!tmp_read)) { return ERROR_MEMORY; } // Null pointer or not malloc failed
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

I2C_set_busy(&AT42QT1244_hal, true);

Expand All @@ -107,7 +107,7 @@ FctERR AT42QT1244_Read(uint8_t * data, uint16_t addr, uint16_t nb)
for (int i = 0 ; i < nb ; i++) { crc = crc16(crc, tmp_read[i]); }
// Copy to destination if crc is ok
if (crc == MAKEWORD(tmp_read[nb], tmp_read[nb + 1])) { memcpy(data, tmp_read, nb); }
else { err = ERR_CRC; }
else { err = ERROR_CRC; }
}

free(tmp_read);
Expand Down
8 changes: 4 additions & 4 deletions AT42QT1244_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

FctERR AT42QT1244_Send_Command(AT42QT_cmd cmd)
{
if ((cmd > AT42QT__RESET_DEVICE) && (cmd < AT42QT__LOW_LEVEL_CALIBRATION)) { return ERR_VALUE; }
if ((cmd > AT42QT__RESET_DEVICE) && (cmd < AT42QT__LOW_LEVEL_CALIBRATION)) { return ERROR_VALUE; }
return AT42QT1244_Write(&cmd, AT42QT__CONTROL_COMMAND, 1);
}

Expand All @@ -36,7 +36,7 @@ FctERR AT42QT1244_Setup_Key(uint8_t Key, bool use)
uAT42QT_REG__SETUP_165_188 TMP;
FctERR err;

if (Key > AT42QT__CALIBRATE_KEY_23) { return ERR_VALUE; }
if (Key > AT42QT__CALIBRATE_KEY_23) { return ERROR_VALUE; }

err = AT42QT1244_Read((uint8_t *) &TMP, AT42QT__SETUP_KEYS_MODE_0 + Key, sizeof(TMP)); // 165 is the NDIL register of the 1st key
if (err) { return err; }
Expand All @@ -50,7 +50,7 @@ FctERR AT42QT1244_Setup_FHM(AT42QT_FHM FHM)
uAT42QT_REG__SETUP_244 TMP;
FctERR err;

if (FHM > AT42QT__FHM_FREQUENCY_SWEEP) { return ERR_VALUE; }
if (FHM > AT42QT__FHM_FREQUENCY_SWEEP) { return ERROR_VALUE; }

err = AT42QT1244_Read((uint8_t *) &TMP, AT42QT__SETUP_FREQ_HOPING_DWELL, 1);
if (err) { return err; }
Expand All @@ -67,7 +67,7 @@ FctERR AT42QT1244_Get_Keys(uint32_t * Keys)
if (err) { return err; }

*Keys = (LSHIFT(TMP[2], 16) + LSHIFT(TMP[1], 8) + TMP[0]) & 0x00FFFFFFUL;
return ERR_OK;
return ERROR_OK;
}


Expand Down
8 changes: 4 additions & 4 deletions AT42QT1244_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

__WEAK FctERR AT42QT1244_Init_Sequence(void)
{
return ERR_OK;
return ERROR_OK;
}


Expand All @@ -43,7 +43,7 @@ FctERR AT42QT1244_Calibrate_Freq_Offset(void)
HAL_IWDG_Refresh(&hiwdg);
#endif
calib = AT42QT1244_is_Calib_Pending();
if (calib == -1) { return ERR_NOTAVAIL; }
if (calib == -1) { return ERROR_NOTAVAIL; }
}

// Get all FREQ
Expand Down Expand Up @@ -72,7 +72,7 @@ FctERR AT42QT1244_Calibrate_Freq_Offset(void)
HAL_IWDG_Refresh(&hiwdg);
#endif
calib = AT42QT1244_is_Calib_Pending();
if (calib == -1) { return ERR_NOTAVAIL; }
if (calib == -1) { return ERROR_NOTAVAIL; }
}

// Get reference for keys
Expand Down Expand Up @@ -110,7 +110,7 @@ FctERR AT42QT1244_Calibrate_Freq_Offset(void)

__WEAK FctERR AT42QT1244_handler(void)
{
return ERR_OK;
return ERROR_OK;
}


Expand Down
8 changes: 4 additions & 4 deletions AT42QT1244_proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ FctERR AT42QT1244_Calibrate_Freq_Offset(void);


__INLINE FctERR INLINE__ AT42QT1244_Calibrate_Low_Level(void) {
if (AT42QT1244_is_Calib_Pending()) { return ERR_BUSY; }
if (AT42QT1244_is_Calib_Pending()) { return ERROR_BUSY; }
return AT42QT1244_Send_Command(AT42QT__LOW_LEVEL_CALIBRATION); }


__INLINE FctERR INLINE__ AT42QT1244_Calibrate_All_Keys(void) {
if (AT42QT1244_is_Calib_Pending()) { return ERR_BUSY; }
if (AT42QT1244_is_Calib_Pending()) { return ERROR_BUSY; }
return AT42QT1244_Send_Command(AT42QT__CALIBRATE_ALL_KEYS); }


__INLINE FctERR INLINE__ AT42QT1244_Calibrate_Key(uint8_t Key) {
if (Key > AT42QT__CALIBRATE_KEY_23) { return ERR_VALUE; }
if (AT42QT1244_is_Calib_Pending()) { return ERR_BUSY; }
if (Key > AT42QT__CALIBRATE_KEY_23) { return ERROR_VALUE; }
if (AT42QT1244_is_Calib_Pending()) { return ERROR_BUSY; }
return AT42QT1244_Send_Command(Key); }


Expand Down
18 changes: 9 additions & 9 deletions BMP180.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ __WEAK FctERR BMP180_Init(void)

FctERR BMP180_Write(uint8_t * data, uint16_t addr, uint16_t nb)
{
if (!I2C_is_enabled(&BMP180_hal)) { return ERR_DISABLED; } // Peripheral disabled
if (!data) { return ERR_MEMORY; } // Null pointer
if (addr > BMP180__OUT_XLSB) { return ERR_RANGE; } // Unknown register
if ((addr + nb) > BMP180__OUT_XLSB + 1) { return ERR_OVERFLOW; } // More bytes than registers
if (!I2C_is_enabled(&BMP180_hal)) { return ERROR_DISABLED; } // Peripheral disabled
if (!data) { return ERROR_MEMORY; } // Null pointer
if (addr > BMP180__OUT_XLSB) { return ERROR_RANGE; } // Unknown register
if ((addr + nb) > BMP180__OUT_XLSB + 1) { return ERROR_OVERFLOW; } // More bytes than registers

I2C_set_busy(&BMP180_hal, true);

Expand All @@ -52,10 +52,10 @@ FctERR BMP180_Write(uint8_t * data, uint16_t addr, uint16_t nb)

FctERR BMP180_Read(uint8_t * data, uint16_t addr, uint16_t nb)
{
if (!I2C_is_enabled(&BMP180_hal)) { return ERR_DISABLED; } // Peripheral disabled
if (!data) { return ERR_MEMORY; } // Null pointer
if (addr > BMP180__OUT_XLSB) { return ERR_RANGE; } // Unknown register
if ((addr + nb) > BMP180__OUT_XLSB + 1) { return ERR_OVERFLOW; } // More bytes than registers
if (!I2C_is_enabled(&BMP180_hal)) { return ERROR_DISABLED; } // Peripheral disabled
if (!data) { return ERROR_MEMORY; } // Null pointer
if (addr > BMP180__OUT_XLSB) { return ERROR_RANGE; } // Unknown register
if ((addr + nb) > BMP180__OUT_XLSB + 1) { return ERROR_OVERFLOW; } // More bytes than registers

I2C_set_busy(&BMP180_hal, true);

Expand All @@ -71,7 +71,7 @@ FctERR BMP180_Read_Word(uint16_t * data, uint16_t addr)
uint8_t WREG[2];
FctERR err;

if (addr > BMP180__OUT_XLSB) { return ERR_RANGE; } // Unknown register
if (addr > BMP180__OUT_XLSB) { return ERROR_RANGE; } // Unknown register

err = BMP180_Read(WREG, addr, 2);
if (err) { return err; }
Expand Down
4 changes: 2 additions & 2 deletions BMP180_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FctERR BMP180_Start_Conversion(BMP180_meas meas)
FctERR err;

if ( (meas != BMP180__MEAS_PRESSURE)
&& (meas != BMP180__MEAS_TEMPERATURE)) { return ERR_VALUE; } // Unknown conversion
&& (meas != BMP180__MEAS_TEMPERATURE)) { return ERROR_VALUE; } // Unknown conversion

CTRL.Byte = 0;
CTRL.Bits.SCO = 1;
Expand All @@ -36,7 +36,7 @@ FctERR BMP180_Start_Conversion(BMP180_meas meas)

BMP180.hStartConversion = HAL_GetTick();

return ERR_OK;
return ERROR_OK;
}


Expand Down
10 changes: 5 additions & 5 deletions BMP180_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ __WEAK FctERR BMP180_Init_Sequence(void)

err = BMP180_Get_ChipID(&BMP180.cfg.Id);
if (err) { return err; }
if (BMP180.cfg.Id != BMP180_CHIP_ID) { return ERR_COMMON; } // Unknown device
if (BMP180.cfg.Id != BMP180_CHIP_ID) { return ERROR_COMMON; } // Unknown device

#if !defined(BMP180_TST)
err = BMP180_Get_Calibration(&BMP180.cfg.Calib);
Expand Down Expand Up @@ -79,10 +79,10 @@ __STATIC_INLINE float INLINE__ BMP180_seaLevel_Pressure_For_Altitude(float altit

FctERR BMP180_Set_Oversampling(BMP180_oversampling oss)
{
if (oss > BMP180__OSS_8_TIME) { return ERR_VALUE; } // Unknown Oversampling
if (oss > BMP180__OSS_8_TIME) { return ERROR_VALUE; } // Unknown Oversampling

BMP180.cfg.OSS = oss;
return ERR_OK;
return ERROR_OK;
}


Expand Down Expand Up @@ -119,7 +119,7 @@ FctERR BMP180_Get_Pressure(float * pres)
int32_t x1, x2, b5, b6, x3, b3, p;
uint32_t b4, b7;
float t;
FctERR err = ERR_OK;
FctERR err = ERROR_OK;

/* Get the raw pressure and temperature values */
#if !defined(BMP180_TST)
Expand Down Expand Up @@ -175,7 +175,7 @@ FctERR BMP180_Get_Temperature(float * temp)
{
int32_t UT = 0, b5;
float t;
FctERR err = ERR_OK;
FctERR err = ERROR_OK;

#if !defined(BMP180_TST)
err = BMP180_Get_Temperature_Raw(&UT);
Expand Down
16 changes: 8 additions & 8 deletions DRV2605L.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ __WEAK FctERR DRV2605L_Init(void)

FctERR DRV2605L_Write(uint8_t * data, uint16_t addr, uint16_t nb)
{
if (!I2C_is_enabled(&DRV2605_hal)) { return ERR_DISABLED; } // Peripheral disabled
if (!data) { return ERR_MEMORY; } // Null pointer
if (addr > DRV__LRA_RESONANCE_PERIOD) { return ERR_RANGE; } // Unknown register
if ((addr + nb) > DRV__LRA_RESONANCE_PERIOD + 1) { return ERR_OVERFLOW; } // More bytes than registers
if (!I2C_is_enabled(&DRV2605_hal)) { return ERROR_DISABLED; } // Peripheral disabled
if (!data) { return ERROR_MEMORY; } // Null pointer
if (addr > DRV__LRA_RESONANCE_PERIOD) { return ERROR_RANGE; } // Unknown register
if ((addr + nb) > DRV__LRA_RESONANCE_PERIOD + 1) { return ERROR_OVERFLOW; } // More bytes than registers

I2C_set_busy(&DRV2605_hal, true);

Expand All @@ -52,10 +52,10 @@ FctERR DRV2605L_Write(uint8_t * data, uint16_t addr, uint16_t nb)

FctERR DRV2605L_Read(uint8_t * data, uint16_t addr, uint16_t nb)
{
if (!I2C_is_enabled(&DRV2605_hal)) { return ERR_DISABLED; } // Peripheral disabled
if (!data) { return ERR_MEMORY; } // Null pointer
if (addr > DRV__LRA_RESONANCE_PERIOD) { return ERR_RANGE; } // Unknown register
if ((addr + nb) > DRV__LRA_RESONANCE_PERIOD + 1) { return ERR_OVERFLOW; } // More bytes than registers
if (!I2C_is_enabled(&DRV2605_hal)) { return ERROR_DISABLED; } // Peripheral disabled
if (!data) { return ERROR_MEMORY; } // Null pointer
if (addr > DRV__LRA_RESONANCE_PERIOD) { return ERROR_RANGE; } // Unknown register
if ((addr + nb) > DRV__LRA_RESONANCE_PERIOD + 1) { return ERROR_OVERFLOW; } // More bytes than registers

I2C_set_busy(&DRV2605_hal, true);

Expand Down
26 changes: 13 additions & 13 deletions DRV2605L_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ FctERR DRV2605L_Set_ActType(DRV2605L_act act)
uDRV_REG__FEEDBACK_CONTROL FB_CTL;
FctERR err;

if (act > DRV__ACT_LRA) { return ERR_VALUE; } // Unknown actuator type
if (act > DRV__ACT_LRA) { return ERROR_VALUE; } // Unknown actuator type

err = DRV2605L_Read(&FB_CTL.Byte, DRV__FEEDBACK_CONTROL, 1);
if (err) { return err; }
Expand All @@ -76,7 +76,7 @@ FctERR DRV2605L_Set_OperatingMode(DRV2605L_mode mode)
uDRV_REG__MODE MODE;
FctERR err;

if (mode > DRV__MODE_AUTO_CALIBRATION) { return ERR_VALUE; } // Unknown mode
if (mode > DRV__MODE_AUTO_CALIBRATION) { return ERROR_VALUE; } // Unknown mode

err = DRV2605L_Read(&MODE.Byte, DRV__MODE, 1);
if (err) { return err; }
Expand Down Expand Up @@ -108,7 +108,7 @@ FctERR DRV2605L_Set_InputMode(DRV2605L_input input)
uDRV_REG__CONTROL_3 CTL3;
FctERR err;

if (input > DRV__IN_ANALOG) { return ERR_VALUE; } // Unknown input type
if (input > DRV__IN_ANALOG) { return ERROR_VALUE; } // Unknown input type

err = DRV2605L_Read(&CTL3.Byte, DRV__CONTROL_3, 1);
if (err) { return err; }
Expand All @@ -127,7 +127,7 @@ FctERR DRV2605L_Set_LoopMode(DRV2605L_loop loop)
uDRV_REG__CONTROL_3 CTL3;
FctERR err;

if (loop > DRV__OPEN_LOOP) { return ERR_VALUE; } // Unknown loop mode
if (loop > DRV__OPEN_LOOP) { return ERROR_VALUE; } // Unknown loop mode

err = DRV2605L_Read(&CTL3.Byte, DRV__CONTROL_3, 1);
if (err) { return err; }
Expand All @@ -147,7 +147,7 @@ FctERR DRV2605L_Set_Library(DRV2605L_lib lib)
{
uDRV_REG__LIBRARY_SELECTION LIB;

if (lib > DRV__LIB_TS2200_LIBRARY_F) { return ERR_VALUE; } // Unknown library
if (lib > DRV__LIB_TS2200_LIBRARY_F) { return ERROR_VALUE; } // Unknown library

LIB.Byte = 0;
LIB.Bits.LIBRARY_SEL = lib;
Expand All @@ -159,8 +159,8 @@ FctERR DRV2605L_Set_Waveform(uint16_t chan, DRV2605L_eff effect, bool wait)
{
uDRV_REG__WAVEFORM_SEQUENCER WAVEFORM;

if (chan > 7) { return ERR_VALUE; } // Unknown channel
if (effect > DRV__EFF_SMOOTH_HUM_5) { return ERR_VALUE; } // Unknown effect
if (chan > 7) { return ERROR_VALUE; } // Unknown channel
if (effect > DRV__EFF_SMOOTH_HUM_5) { return ERROR_VALUE; } // Unknown effect

WAVEFORM.Bits.WAIT = wait;
WAVEFORM.Bits.WAV_FRM_SEQ = effect;
Expand All @@ -173,7 +173,7 @@ FctERR DRV2605L_Set_RTPDataFormat(DRV2605L_rtp_format format)
uDRV_REG__CONTROL_3 CTL3;
FctERR err;

if (format > DRV__RTP_UNSIGNED) { return ERR_VALUE; } // Unknown RTP data format
if (format > DRV__RTP_UNSIGNED) { return ERROR_VALUE; } // Unknown RTP data format

err = DRV2605L_Read(&CTL3.Byte, DRV__CONTROL_3, 1);
if (err) { return err; }
Expand All @@ -193,7 +193,7 @@ FctERR DRV2605L_Set_ATVPeakTime(DRV2605L_peak peak)
uDRV_REG__ATV_CONTROL ATV;
FctERR err;

if (peak > DRV__PEAK_40MS) { return ERR_VALUE; } // Unknown peak time
if (peak > DRV__PEAK_40MS) { return ERROR_VALUE; } // Unknown peak time

err = DRV2605L_Read(&ATV.Byte, DRV__ATV_CONTROL, 1);
if (err) { return err; }
Expand All @@ -208,7 +208,7 @@ FctERR DRV2605L_Set_ATVLowPassFilter(DRV2605L_filter filt)
uDRV_REG__ATV_CONTROL ATV;
FctERR err;

if (filt > DRV__FILTER_200HZ) { return ERR_VALUE; } // Unknown low pass filter frequency
if (filt > DRV__FILTER_200HZ) { return ERROR_VALUE; } // Unknown low pass filter frequency

err = DRV2605L_Read(&ATV.Byte, DRV__ATV_CONTROL, 1);
if (err) { return err; }
Expand All @@ -223,7 +223,7 @@ FctERR DRV2605L_Set_ATVInput_Volt(float volt, bool max)
float tmp = (volt * 255.0f) / 1.8f;
uint8_t VAL;

if (tmp > 255.0f) { return ERR_VALUE; } // voltage desired is too high
if (tmp > 255.0f) { return ERROR_VALUE; } // voltage desired is too high

VAL = (uint8_t) tmp;
return DRV2605L_Set_ATVInputLevel_Raw(VAL, max);
Expand All @@ -234,7 +234,7 @@ FctERR DRV2605L_Set_ATVDrive_Percent(uint16_t perc, bool max)
{
uint8_t VAL;

if (perc > 100) { return ERR_VALUE; } // percent desired is too high
if (perc > 100) { return ERROR_VALUE; } // percent desired is too high

VAL = (uint8_t) ((perc * 255.0f) / 100.0f);
return DRV2605L_Set_ATVOutputDrive_Raw(VAL, max);
Expand Down Expand Up @@ -299,7 +299,7 @@ FctERR DRV2605L_Set_LRAOpenLoopPeriod_us(uint16_t per)
{
uint8_t PER;

if (per > 25107) { return ERR_VALUE; } // Period is out of range
if (per > 25107) { return ERROR_VALUE; } // Period is out of range

PER = (uint8_t) (per / 98.46f);
return DRV2605L_Write(&PER, DRV__LRA_OPEN_LOOP_PERIOD, 1);
Expand Down
Loading

0 comments on commit 1cf727e

Please sign in to comment.