Skip to content

Commit da8ca90

Browse files
committed
[ISSUE-29] uart_printf used in 3prog1
1 parent 6cb04b4 commit da8ca90

2 files changed

Lines changed: 28 additions & 42 deletions

File tree

examples/3prog1/Makefile.am

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
include $(top_srcdir)/scripts/elf2bin.mk
22
include $(top_srcdir)/ld/flags.mk
3-
AM_LDFLAGS += -T $(top_srcdir)/ld/esp32.rom.ld \
4-
-T $(top_srcdir)/ld/esp32.rom.redefined.ld \
5-
-T $(top_srcdir)/ld/esp32.rom.libgcc.ld
63

74
noinst_HEADERS = defines.h
85

6+
if WITH_BINARIES
7+
AM_LDFLAGS += \
8+
-T $(top_srcdir)/ld/esp32.rom.ld \
9+
-T $(top_srcdir)/ld/esp32.rom.libgcc.ld \
10+
-T $(top_srcdir)/ld/esp32.rom.newlib-data.ld \
11+
-T $(top_srcdir)/ld/esp32.rom.newlib-locale.ld \
12+
-T $(top_srcdir)/ld/esp32.rom.newlib-nano.ld \
13+
-T $(top_srcdir)/ld/esp32.rom.newlib-time.ld \
14+
-T $(top_srcdir)/ld/esp32.rom.redefined.ld \
15+
-T $(top_srcdir)/ld/esp32.rom.syscalls.ld
16+
else
17+
AM_LDFLAGS += \
18+
-T $(top_srcdir)/ld/esp32.rom.ld \
19+
-T $(top_srcdir)/ld/esp32.rom.libgcc.ld \
20+
-T $(top_srcdir)/ld/esp32.rom.redefined.ld \
21+
-T $(top_srcdir)/ld/esp32.rom.syscalls.ld
22+
endif
23+
924
AM_CFLAGS = -std=c11 -flto
1025
AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/modules
1126
LDADD = $(top_builddir)/src/libesp32basic.a $(top_builddir)/modules/libesp32modules.a

examples/3prog1/prog.c

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "bme280.h"
3030
#include "bh1750.h"
3131
#include "utils/i2cutils.h"
32+
#include "utils/uartutils.h"
3233

3334
// =================== Hard constants =================
3435
// #1: Timings
@@ -102,7 +103,6 @@ typedef struct {
102103
} PeriodicCallbackDesc;
103104

104105
// ================ Local function declarations =================
105-
static void _uart_println(const char *pcPrefix, const char *pcLine, uint8_t u8Len);
106106
static void _flush_message(uint64_t u64tckTimestamp);
107107
static void _alternate_value(void *pvParam);
108108
static ELockmgrResource _i2c_to_lock(EI2CBus eBus);
@@ -171,20 +171,6 @@ static PeriodicCallbackDesc gsPCbDesc = {
171171
};
172172

173173

174-
// Implementation
175-
176-
static void _uart_println(const char *pcPrefix, const char *pcLine, uint8_t u8Len) {
177-
uint32_t u32PfxLen = strlen(pcPrefix);
178-
for (int i = 0; i < u32PfxLen; ++i) {
179-
gpsUART0->FIFO = pcPrefix[i];
180-
}
181-
for (int i = 0; i < u8Len; ++i) {
182-
gpsUART0->FIFO = pcLine[i];
183-
}
184-
gpsUART0->FIFO = '\r';
185-
gpsUART0->FIFO = '\n';
186-
}
187-
188174
static void _flush_message(uint64_t u64tckTimestamp) {
189175
static uint8_t u8Phase;
190176
static char buf[LOG_BUFLEN];
@@ -228,7 +214,7 @@ static void _flush_message(uint64_t u64tckTimestamp) {
228214
// some internal call causes WDT
229215
snprintf(buf, LOG_BUFLEN, "%s%"PRIu64"%s", message_pfx, u64tckTimestamp, message_sfx);
230216
}
231-
_uart_println("LOG:\tts ", buf, buf_e - buf);
217+
uart_printf(gpsUART0, "LOG:\tts %.*s\r\n", buf_e - buf, buf);
232218
++u8Phase;
233219
}
234220

@@ -398,20 +384,10 @@ static void _bme280_init(SBme280StateDesc *psState, SI2cIfaceCfg *psIface) {
398384
}
399385

400386
static void _bme280_print_result(const SBme280TPH *psRes, uint32_t u32TFine) {
401-
char acBuf[20];
402-
char *bufE;
403-
bufE = print_dec(acBuf, u32TFine);
404-
_uart_println("Tfine: ", acBuf, bufE - acBuf);
405-
bufE = print_deccent(acBuf, psRes->i32Temp, '.');
406-
_uart_println("Temp: ", acBuf, bufE - acBuf);
407-
bufE = print_dec(acBuf, psRes->i32Pres >> 8);
408-
*(bufE++) = '.';
409-
bufE = print_dec_padded(bufE, ((psRes->i32Pres & 0xff)*391) / 1000, 2, '0');
410-
_uart_println("Pres: ", acBuf, bufE - acBuf);
411-
bufE = print_dec(acBuf, psRes->i32Hum >> 10);
412-
*(bufE++) = '.';
413-
bufE = print_dec_padded(bufE, ((psRes->i32Hum & 0x3ff)*97657) / 100000, 3, '0');
414-
_uart_println("Hum: ", acBuf, bufE - acBuf);
387+
uart_printf(gpsUART0, "Tfine: %d\r\n", u32TFine);
388+
uart_printf(gpsUART0, "Temp: %d.%02d\r\n", psRes->i32Temp / 100, psRes->i32Temp % 100);
389+
uart_printf(gpsUART0, "Pres: %d.%02d\r\n", psRes->i32Pres >> 8, ((psRes->i32Pres & 0xff)*391) / 1000);
390+
uart_printf(gpsUART0, "Hum: %d.%03d\r\n", psRes->i32Hum >> 10, ((psRes->i32Hum & 0x3ff)*97657) / 100000);
415391
}
416392

417393
static void _bme280_cycle(uint64_t u64Ticks) {
@@ -464,13 +440,8 @@ static void _bh1750_print_result(const SBh1750StateDesc *psState) {
464440
uint8_t u8MTime = bh1750_get_mtime(psState);
465441
uint8_t u16Result = conv16be(psState->u16beResult);
466442
uint32_t u32mLx = bh1750_result_to_mlx(u16Result, u8MTime, eMRes);
467-
char acBuf[40];
468-
char *pcBufE = acBuf;
469-
pcBufE = str_append(pcBufE, acBh1750MResName[eMRes]);
470-
pcBufE = str_append(pcBufE, ": ");
471-
pcBufE = print_decmilli(pcBufE, u32mLx, '.');
472443

473-
_uart_println("BH1750 ", acBuf, pcBufE - acBuf);
444+
uart_printf(gpsUART0, "BH1750 %s: %d.%03d\r\n", acBh1750MResName[eMRes], u32mLx/1000, u32mLx%1000);
474445
}
475446

476447
static void _bh1750_cycle(uint64_t u64Ticks) {
@@ -507,7 +478,7 @@ static void _bh1750_cycle(uint64_t u64Ticks) {
507478
u8Retries = BH1750_READ_RETRIES;
508479
} else {
509480
// EITHER 0 was measured OR result still not ready
510-
_uart_println("BH1750 retry", NULL, 0);
481+
uart_printf(gpsUART0, "BH1750 retry\r\n");
511482
u32hmsWaitHint += BH1750_RETRY_WAIT_HMS; // so let's wait some dt
512483
}
513484
break;
@@ -602,13 +573,13 @@ static void _i2cscan_cycle(uint64_t u64Ticks) {
602573
pcBufE = str_append(pcBufE, " 0x");
603574
pcBufE = print_hex8(pcBufE, i);
604575
if (5 * I2CSCAN_PRINT_PER_ROW <= (pcBufE - acBuf)) {
605-
_uart_println(acPfx, acBuf, pcBufE - acBuf);
576+
uart_printf(gpsUART0, "%s%.*s\r\n", acPfx, pcBufE - acBuf, acBuf);
606577
pcBufE = acBuf;
607578
}
608579
}
609580
}
610581
if (pcBufE != acBuf) {
611-
_uart_println(acPfx, acBuf, pcBufE - acBuf);
582+
uart_printf(gpsUART0, "%s%.*s\r\n", acPfx, pcBufE - acBuf, acBuf);
612583
}
613584

614585
u64NextTick += MS2TICKS(I2CSCAN_PERIOD_MS);

0 commit comments

Comments
 (0)