]> begriffs open source - cmsis-driver-validation/blob - Boards/Espressif/ESP8266EX_Arduino/retarget_user.c
Update GitHub Actions runner to ubuntu-22.04 (#18)
[cmsis-driver-validation] / Boards / Espressif / ESP8266EX_Arduino / retarget_user.c
1 /*------------------------------------------------------------------------------
2  * MDK Middleware
3  * Copyright (c) 2004-2019 ARM Germany GmbH. All rights reserved.
4  *------------------------------------------------------------------------------
5  * Name:    retarget_user.c
6  * Purpose: User specific retarget of stdin, stdout and stderr
7  *----------------------------------------------------------------------------*/
8
9 #include <stdint.h>
10 #include "fsl_debug_console.h"          // NXP::Device:SDK Utilities:debug_console
11
12 int DbgConsole_SendDataReliable(uint8_t *ch, size_t size);
13 int DbgConsole_ReadCharacter(uint8_t *ch);
14
15 /**
16   Put a character to the stderr
17  
18   \param[in]   ch  Character to output
19   \return          The character written, or -1 on write error.
20 */
21 int stderr_putchar (int ch) {
22   int32_t ret;
23
24   ret = DbgConsole_SendDataReliable((uint8_t *)(&ch), 1);
25
26   if (ret!= -1) {
27     ret = ch;
28   }
29   return (ret);
30 }
31
32 /**
33   Put a character to the stdout
34  
35   \param[in]   ch  Character to output
36   \return          The character written, or -1 on write error.
37 */
38 int stdout_putchar (int ch) {
39   int32_t ret;
40
41   ret = DbgConsole_SendDataReliable((uint8_t *)(&ch), 1);
42
43   if (ret!= -1) {
44     ret = ch;
45   }
46   return (ret);
47 }
48
49 /**
50   Get a character from the stdio
51  
52   \return     The next character from the input, or -1 on read error.
53 */
54 int stdin_getchar (void) {
55   int32_t ret;
56   uint8_t ch;
57
58   ret = DbgConsole_ReadCharacter(&ch);
59
60   if (ret!= -1) {
61     ret = ch;
62   }
63   return (ret);
64 }