Skip to content

Commit 2a2bcaf

Browse files
authored
Heltec Wifi LoRa v2 (ESP32) fix for printf
Fixing mcci-catena#140 tested with Heltec Wifi LoRa v2 (ESP32) and BSFrance LoRa32u4 II
1 parent 09ee87c commit 2a2bcaf

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/hal/hal.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,25 @@ void hal_sleep () {
271271
// -----------------------------------------------------------------------------
272272

273273
#if defined(LMIC_PRINTF_TO)
274+
#if defined(ESP8266) || defined(ESP31B) || defined(ESP32)
275+
//ESPXX specific PRINTF, only tested with ESP32 Haltec LoRA Wifi so far
276+
static ssize_t uart_putchar (void *, const char *buf, size_t len) {
277+
return LMIC_PRINTF_TO.write((const uint8_t *)buf, len);
278+
}
279+
280+
static cookie_io_functions_t functions =
281+
{
282+
.read = NULL,
283+
.write = uart_putchar,
284+
.seek = NULL,
285+
.close = NULL
286+
};
287+
288+
void hal_printf_init() {
289+
stdout = fopencookie(NULL, "w", functions);
290+
}
291+
#else // !defined(ESP8266) || defined(ESP31B) || defined(ESP32)
292+
// all else, like AVR
274293
static int uart_putchar (char c, FILE *)
275294
{
276295
LMIC_PRINTF_TO.write(c) ;
@@ -288,6 +307,8 @@ void hal_printf_init() {
288307
// The uart is the standard output device STDOUT.
289308
stdout = &uartout ;
290309
}
310+
311+
#endif // !defined(ESP8266) || defined(ESP31B) || defined(ESP32)
291312
#endif // defined(LMIC_PRINTF_TO)
292313

293314
void hal_init (void) {

0 commit comments

Comments
 (0)