Skip to content

Commit

Permalink
v0.7: mostly Doxygen related, enjoy!
Browse files Browse the repository at this point in the history
  • Loading branch information
SMFSW committed May 25, 2017
1 parent a4edd47 commit 64ae1da
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "HARMcksL: ARM HAL toolbox (yet STM32 oriented)"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.6
PROJECT_NUMBER = 0.7

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
14 changes: 7 additions & 7 deletions FctERR.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!\file FctERR.c
** \author SMFSW
** \version v0.6
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief errors to SMFSW FctERR code
Expand All @@ -11,11 +11,11 @@
#include "FctERR.h"


FctERR HALERRtoFCTERR(HAL_StatusTypeDef st)
FctERR HALERRtoFCTERR(HAL_StatusTypeDef status)
{
if (st == HAL_OK) return ERR_OK;
else if (st == HAL_ERROR) return ERR_FAULT;
else if (st == HAL_BUSY) return ERR_BUSY;
else if (st == HAL_TIMEOUT) return ERR_TIMEOUT;
else return ERR_FAULT;
if (status == HAL_OK) return ERR_OK;
else if (status == HAL_ERROR) return ERR_FAULT;
else if (status == HAL_BUSY) return ERR_BUSY;
else if (status == HAL_TIMEOUT) return ERR_TIMEOUT;
else return ERR_FAULT;
}
12 changes: 6 additions & 6 deletions FctERR.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!\file FctERR.h
** \author SMFSW
** \version v0.6
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief errors to SMFSW FctERR declarations
Expand All @@ -17,10 +17,10 @@
// *****************************************************************************
// Section: Types
// *****************************************************************************
/*!\enum EnumFctERR
** \brief Enum of high level functions return state
/*!\enum FctERR
** \brief Enum of low/mid level functions return state
**/
typedef enum PACK__ EnumFctERR{
typedef enum PACK__ FctERR{
ERR_OK = 0U, //!< OK
ERR_SPEED = 1U, //!< This device does not work in the active speed mode.
ERR_RANGE = 2U, //!< Parameter out of range.
Expand Down Expand Up @@ -62,10 +62,10 @@ typedef enum PACK__ EnumFctERR{
// Section: Interface Routines
// *****************************************************************************
/*!\brief Convert HAL_StatusTypeDef to FctERR
** \param[in] st - HAL_StatusTypeDef status
** \param[in] status - HAL_StatusTypeDef status
** \return FctERR status
**/
FctERR HALERRtoFCTERR(HAL_StatusTypeDef st);
FctERR HALERRtoFCTERR(HAL_StatusTypeDef status);


/****************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion GPIO_ex.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!\file GPIO_ex.c
** \author SMFSW
** \version v0.6
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Simple extension for GPIOs
Expand Down
8 changes: 6 additions & 2 deletions GPIO_ex.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!\file GPIO_ex.h
** \author SMFSW
** \version v0.6
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Simple extension for GPIOs
Expand Down Expand Up @@ -61,26 +61,28 @@ typedef struct GPIO_in {
**/
void GPIO_in_init(GPIO_in * in, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint16_t filter);


/*!\brief Handles GPIO_in read and treatment
** \param[in,out] in - input instance to handle
** \return Nothing
**/
void GPIO_in_handler(GPIO_in * in);


/*!\brief Get GPIO_in input value
** \param[in] in - input instance
** \return Input value
**/
__INLINE bool INLINE__ get_GPIO_in(GPIO_in * in) { return in->in; }


/*!\brief Get GPIO_in input edge
** \param[in] in - input instance
** \return Input edge
**/
__INLINE bool INLINE__ get_GPIO_in_edge(GPIO_in * in) { return in->edge; }



/*!\brief Get name from Port, Pin
** \param[in,out] name - pointer to string for name
** \param[in] GPIOx - port to write to
Expand Down Expand Up @@ -115,6 +117,7 @@ __INLINE void INLINE__ write_GPIO(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, eActOu
}
}


/*!\brief Read GPIO
** \param[in] GPIOx - port to read from
** \param[in] GPIO_Pin - pin to read from
Expand All @@ -136,6 +139,7 @@ __INLINE GPIO_PinState INLINE__ read_GPIO(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin
#endif
}


/****************************************************************/
#endif /* __GPIO_EX_H */
/****************************************************************/
Binary file renamed HARMcksL_v0_6.pdf → HARMcksL_v0_7.pdf
Binary file not shown.
15 changes: 10 additions & 5 deletions PWM.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/*!\file PWM.c
** \author SMFSW
** \version v0.6
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Simple PWM handling
** \brief Straightforward PWM handling
**/
/****************************************************************/
/****************************************************************/

#include "PWM.h"

#if defined(HAL_TIM_MODULE_ENABLED)
/****************************************************************/


HAL_StatusTypeDef set_PWM_Freq(TIM_HandleTypeDef * pTim, uint32_t freq)
Expand All @@ -23,7 +22,7 @@ HAL_StatusTypeDef set_PWM_Freq(TIM_HandleTypeDef * pTim, uint32_t freq)

if (freq > coreCLK / 100) { return HAL_ERROR; }

// TODO: find prescaler & period with i++ instead of shifts
// TODO: find prescaler & period with i++ instead of shifts for more accuracy (despite of time passed)
for (i = 1 ; i < (uint16_t) -1 ; i <<= 1)
{
per = (coreCLK / (freq * (i + 1))) - 1;
Expand All @@ -41,7 +40,10 @@ HAL_StatusTypeDef set_PWM_Freq(TIM_HandleTypeDef * pTim, uint32_t freq)
return HAL_TIM_Base_Init(pTim);
}


/*******************/
/*** PWM DRIVING ***/
/*******************/
/*!\brief Low level TIM module PWM duty cycle write
** \param[in,out] pTim - pointer to TIM instance for PWM generation
** \param[in] chan - Channel to write
Expand All @@ -64,11 +66,14 @@ __STATIC_INLINE HAL_StatusTypeDef INLINE__ write_CCR(TIM_HandleTypeDef * pTim, u
return HAL_OK;
}


HAL_StatusTypeDef set_PWM_Duty_Scaled(TIM_HandleTypeDef * pTim, uint32_t chan, uint16_t duty, uint16_t scale)
{
float tmp = ((float) min(scale, duty) / (float) scale) * pTim->Instance->ARR;
return write_CCR(pTim, chan, (uint16_t) tmp);
}


/****************************************************************/
#endif
/****************************************************************/
8 changes: 6 additions & 2 deletions PWM.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!\file PWM.h
** \author SMFSW
** \version v0.6
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Simple PWM handling
** \brief Straightforward PWM handling
**/
/****************************************************************/
#ifndef __PWM_H
Expand All @@ -27,6 +27,7 @@
**/
HAL_StatusTypeDef set_PWM_Freq(TIM_HandleTypeDef * pTim, uint32_t freq);


/*!\brief Set TIM module PWM duty cycle (scaled)
** \param[in,out] pTim - pointer to TIM instance for PWM generation
** \param[in] chan - Channel to write
Expand All @@ -36,6 +37,7 @@ HAL_StatusTypeDef set_PWM_Freq(TIM_HandleTypeDef * pTim, uint32_t freq);
**/
HAL_StatusTypeDef set_PWM_Duty_Scaled(TIM_HandleTypeDef * pTim, uint32_t chan, uint16_t duty, uint16_t scale);


/*!\brief Set TIM module PWM duty cycle (percents)
** \param[in,out] pTim - pointer to TIM instance for PWM generation
** \param[in] chan - Channel to write
Expand All @@ -45,6 +47,7 @@ HAL_StatusTypeDef set_PWM_Duty_Scaled(TIM_HandleTypeDef * pTim, uint32_t chan, u
__INLINE HAL_StatusTypeDef INLINE__ set_PWM_Duty_Perc(TIM_HandleTypeDef * pTim, uint32_t chan, uint16_t duty) {
return set_PWM_Duty_Scaled(pTim, chan, duty, 100); }


/*!\brief Set TIM module PWM duty cycle (u16-bit value)
** \param[in,out] pTim - pointer to TIM instance for PWM generation
** \param[in] chan - Channel to write
Expand All @@ -54,6 +57,7 @@ __INLINE HAL_StatusTypeDef INLINE__ set_PWM_Duty_Perc(TIM_HandleTypeDef * pTim,
__INLINE HAL_StatusTypeDef INLINE__ set_PWM_Duty_Word(TIM_HandleTypeDef * pTim, uint32_t chan, uint16_t duty) {
return set_PWM_Duty_Scaled(pTim, chan, duty, (uint16_t) -1); }


/*!\brief Set TIM module PWM duty cycle (u8-bit value)
** \param[in,out] pTim - pointer to TIM instance for PWM generation
** \param[in] chan - Channel to write
Expand Down
3 changes: 2 additions & 1 deletion exceptions.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!\file exceptions.c
** \author SMFSW
** \version v0.6
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Debug tool helpers functions
Expand All @@ -19,6 +19,7 @@ void stackDump(uint32_t stack[])
{
enum { r0, r1, r2, r3, r12, lr, pc, psr};

printf("stack addr = %lx\r\n", stack);
printf("r0 = 0x%08lx\r\n", stack[r0]);
printf("r1 = 0x%08lx\r\n", stack[r1]);
printf("r2 = 0x%08lx\r\n", stack[r2]);
Expand Down
67 changes: 46 additions & 21 deletions exceptions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!\file exceptions.h
** \author SMFSW
** \version v0.5
** \version v0.7
** \date 2017
** \copyright MIT (c) 2017, SMFSW
** \brief Debug tool and helpers declaration
Expand All @@ -18,27 +18,52 @@
// *****************************************************************************
// Section: Interface Routines
// *****************************************************************************
//! \note The exception_Handler should be called with corresponding exception name \b e as parameter
#define exception_Handler(e) \
__asm( "tst lr, #4 \n" \
"ite EQ \n" \
"mrseq r0, MSP \n" \
"mrsne r0, PSP \n" \
"b " #e "_Handler_callback \n") //!< The exception_Handler should be called with corresponding exception name \b e as parameter


#define dump_stack() \
__asm( "tst lr, #4 \n" \
"ite EQ \n" \
"mrseq r0, MSP \n" \
"mrsne r0, PSP \n" \
"b stackDump \n")


/* Handled callbacks for reference
** (not really needed as called by assembly from macro)
** use macros to pass stack pointer properly */
void HardFault_Handler_callback(uint32_t stack[]); // HardFault handler
void Error_Handler_callback(uint32_t stack[]); // HAL Error handler
__asm( "tst lr, #4 \r\n" \
"ite EQ \r\n" \
"mrseq r0, MSP \r\n" \
"mrsne r0, PSP \r\n" \
"b " #e "_Handler_callback \r\n") //!< Exception handler asm caller


#define dump_stack() \
__asm( "tst lr, #4 \r\n" \
"ite EQ \r\n" \
"mrseq r0, MSP \r\n" \
"mrsne r0, PSP \r\n" \
"b stackDump \r\n") //!< Dump stack asm caller


/*!\brief prints contents of stack
** \param[in] stack - pointer to stack address
** \note stackDump should not be called directly, unless a particular stack is needed
** use dump_stack() which prepares pointer to current stack instead
** \return Nothing
**/
void stackDump(uint32_t stack[]);


/*!\brief prints informations about current Hard Fault exception
** \param[in] stack - pointer to stack address
** \note HardFault_Handler_callback should not be called directly
** use exception_Handler() which prepares pointer to current stack instead
** \warning Depending how arm is fucked up, informations may not be printed,
** at least, you could inspect exception and stack through debug breakpoint
** \return Never (anyways, arm fubared!)
**/
void HardFault_Handler_callback(uint32_t stack[]);


/*!\brief prints informations about current Hard Fault exception
** \param[in] stack - pointer to stack address
** \note HardFault_Handler_callback should not be called directly
** use exception_Handler() which prepares pointer to current stack instead
** \warning Depending how arm is fucked up, informations may not be printed,
** at least, you could inspect exception and stack through debug breakpoint
** \return Never (anyways, arm fubared!)
**/
void Error_Handler_callback(uint32_t stack[]);


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

0 comments on commit 64ae1da

Please sign in to comment.