Skip to content

Commit

Permalink
Heltec Wifi LoRa v2 (ESP32) fix for printf
Browse files Browse the repository at this point in the history
Fixing mcci-catena#140 tested with Heltec Wifi LoRa v2 (ESP32) and BSFrance LoRa32u4 II
  • Loading branch information
EtoTen authored Oct 9, 2018
1 parent 09ee87c commit 2a2bcaf
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/hal/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,25 @@ void hal_sleep () {
// -----------------------------------------------------------------------------

#if defined(LMIC_PRINTF_TO)
#if defined(ESP8266) || defined(ESP31B) || defined(ESP32)
//ESPXX specific PRINTF, only tested with ESP32 Haltec LoRA Wifi so far
static ssize_t uart_putchar (void *, const char *buf, size_t len) {
return LMIC_PRINTF_TO.write((const uint8_t *)buf, len);
}

static cookie_io_functions_t functions =
{
.read = NULL,
.write = uart_putchar,
.seek = NULL,
.close = NULL
};

void hal_printf_init() {
stdout = fopencookie(NULL, "w", functions);
}
#else // !defined(ESP8266) || defined(ESP31B) || defined(ESP32)
// all else, like AVR
static int uart_putchar (char c, FILE *)
{
LMIC_PRINTF_TO.write(c) ;
Expand All @@ -288,6 +307,8 @@ void hal_printf_init() {
// The uart is the standard output device STDOUT.
stdout = &uartout ;
}

#endif // !defined(ESP8266) || defined(ESP31B) || defined(ESP32)
#endif // defined(LMIC_PRINTF_TO)

void hal_init (void) {
Expand Down

0 comments on commit 2a2bcaf

Please sign in to comment.