Skip to content

Commit

Permalink
Add option for NULL being set as print function on init
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Aug 27, 2023
1 parent 697515a commit c192f34
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lwprintf/src/lwprintf/lwprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1115,17 +1115,23 @@ prv_format(lwprintf_int_t* p, va_list arg) {
/**
* \brief Initialize LwPRINTF instance
* \param[in,out] lwobj: LwPRINTF working instance
* \param[in] out_fn: Output function used for print operation
* \param[in] out_fn: Output function used for print operation.
* When set to `NULL`, direct print to stream functions won't work
* and will return error if called by the application.
* Also, system mutex for this specific instance won't be called
* as system mutex isn't needed. All formatting functions (with print being an exception)
* are thread safe. Library utilizes stack-based variables
* \return `1` on success, `0` otherwise
*/
uint8_t
lwprintf_init_ex(lwprintf_t* lwobj, lwprintf_output_fn out_fn) {
LWPRINTF_GET_LWOBJ(lwobj)->out_fn = out_fn;

#if LWPRINTF_CFG_OS
/* Create system mutex */
if (lwprintf_sys_mutex_isvalid(&LWPRINTF_GET_LWOBJ(lwobj)->mutex)
|| !lwprintf_sys_mutex_create(&LWPRINTF_GET_LWOBJ(lwobj)->mutex)) {
/* Create system mutex, but only if user selected to ever use print mode */
if (out_fn != NULL
&& (lwprintf_sys_mutex_isvalid(&LWPRINTF_GET_LWOBJ(lwobj)->mutex)
|| !lwprintf_sys_mutex_create(&LWPRINTF_GET_LWOBJ(lwobj)->mutex))) {
return 0;
}
#endif /* LWPRINTF_CFG_OS */
Expand Down

0 comments on commit c192f34

Please sign in to comment.