Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Factor out integer-only stdio into a common header #1537

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/include/platform_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#error "Include 'general.h' instead"
#endif

#if PC_HOSTED == 0
#include "stdio_newlib.h"
#endif
#include "target.h"
#include "spi_types.h"

Expand Down
46 changes: 46 additions & 0 deletions src/include/stdio_newlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of the Black Magic Debug project.
*
* Copyright (C) 2023 1BitSquared <[email protected]>
* Written by ALTracer <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef STDIO_NEWLIB_H
#define STDIO_NEWLIB_H

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* STDIO_NEWLIB_H */
22 changes: 0 additions & 22 deletions src/platforms/96b_carbon/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,4 @@
gpio_set_val(LED_PORT_ERROR, LED_ERROR, state); \
}

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* PLATFORMS_96B_CARBON_PLATFORM_H */
22 changes: 0 additions & 22 deletions src/platforms/common/blackpill-f4/blackpill-f4.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,26 +221,4 @@
gpio_set_val(LED_PORT, LED_ERROR, state); \
}

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* PLATFORMS_COMMON_BLACKPILL_F4_H */
22 changes: 0 additions & 22 deletions src/platforms/f072/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,4 @@ extern bool debug_bmp;
gpio_set_val(LED_PORT, LED_ERROR, state); \
}

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* PLATFORMS_F072_PLATFORM_H */
22 changes: 0 additions & 22 deletions src/platforms/f3/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,4 @@ extern bool debug_bmp;
gpio_set_val(LED_PORT, LED_ERROR, state); \
}

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* PLATFORMS_F3_PLATFORM_H */
22 changes: 0 additions & 22 deletions src/platforms/f4discovery/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,4 @@
gpio_set_val(LED_PORT, LED_ERROR, state); \
}

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* PLATFORMS_F4DISCOVERY_PLATFORM_H */
22 changes: 0 additions & 22 deletions src/platforms/hydrabus/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,4 @@
gpio_set_val(LED_PORT, LED_ERROR, state); \
}

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* PLATFORMS_HYDRABUS_PLATFORM_H */
22 changes: 0 additions & 22 deletions src/platforms/launchpad-icdi/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,4 @@ inline static uint8_t gpio_get(uint32_t port, uint8_t pin)
nvic_disable_irq(USB_IRQ); \
} while (0)

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* PLATFORMS_LAUNCHPAD_ICDI_PLATFORM_H */
22 changes: 0 additions & 22 deletions src/platforms/native/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,26 +327,4 @@ extern bool debug_bmp;
#define BITBANG_DIVIDER_OFFSET 52U
#define BITBANG_DIVIDER_FACTOR 30U

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* PLATFORMS_NATIVE_PLATFORM_H */
22 changes: 0 additions & 22 deletions src/platforms/stlink/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,4 @@ extern uint16_t led_idle_run;

extern uint32_t detect_rev(void);

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* PLATFORMS_STLINK_PLATFORM_H */
22 changes: 0 additions & 22 deletions src/platforms/swlink/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,4 @@ extern void set_idle_state(int state);

extern uint8_t detect_rev(void);

/* Use newlib provided integer-only stdio functions */

#ifdef sscanf
#undef sscanf
#endif
#define sscanf siscanf

#ifdef sprintf
#undef sprintf
#endif
#define sprintf siprintf

#ifdef vasprintf
#undef vasprintf
#endif
#define vasprintf vasiprintf

#ifdef snprintf
#undef snprintf
#endif
#define snprintf sniprintf

#endif /* PLATFORMS_SWLINK_PLATFORM_H */