PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Hello_Demo.cpp

Compare code size between many different serial options available via PropGCC and PropWare

cmake_minimum_required(VERSION 3.12)
find_package(PropWare REQUIRED)
set(LINK_TINY ON)
project(Hello_Demo C CXX SPIN2DAT)
create_simple_executable(${PROJECT_NAME}
Hello_Demo.cpp
pst.spin)
#define TEST_PROPWARE_UART
//#define TEST_PROPWARE_UART_PRINTF
//#define TEST_PROPWARE_FDS
//#define TEST_PROPWARE_FDS_PRINTF
//#define TEST_SIMPLE
//#define TEST_TINYSTREAM
//#define TEST_TINYIO
//#define TEST_FDSERIAL
//#define TEST_LIBPROPELLER
// Includes
#if (defined TEST_PROPWARE_UART || defined TEST_PROPWARE_UART_PRINTF || \
defined TEST_PROPWARE_FDS || defined TEST_PROPWARE_FDS_PRINTF)
#else
int _cfg_rxpin = -1;
int _cfg_txpin = -1;
int _cfg_baudrate = -1;
#endif
#if (defined TEST_PROPWARE_FDS || defined TEST_PROPWARE_FDS_PRINTF)
#elif defined TEST_SIMPLE
#include <simpletext.h>
#elif defined TEST_TINYSTREAM
#include <tinystream>
namespace std {
}
#elif defined TEST_TINYIO
#include <tinyio.h>
#elif defined TEST_FDSERIAL
#include <fdserial.h>
#elif defined TEST_LIBPROPELLER
#include <libpropeller/serial/serial.h>
#endif
int main () {
uint32_t i = 0;
#if defined TEST_PROPWARE_FDS || defined TEST_PROPWARE_FDS_PRINTF
FullDuplexSerial serial;
serial.start();
Printer printer(serial);
#elif defined TEST_FDSERIAL
fdserial *serial = fdserial_open(_cfg_rxpin, _cfg_txpin, 0, _cfg_baudrate);
#elif defined TEST_LIBPROPELLER
serial.Start(_cfg_rxpin, _cfg_txpin, _cfg_baudrate);
#endif
while (1) {
#ifdef TEST_PROPWARE_UART
pwOut << "Hello, world! " << Printer::Format(3, '0') << i << " 0x" << Printer::Format(2, '0', 16) << i << '\n';
#elif defined TEST_PROPWARE_UART_PRINTF
pwOut.printf("Hello, world! %03d 0x%02X\n", i, i);
#elif defined TEST_PROPWARE_FDS
printer << "Hello, world! " << Printer::Format(3, '0') << i << " 0x" << Printer::Format(2, '0', 16) << i << '\n';
#elif defined TEST_PROPWARE_FDS_PRINTF
printer.printf("Hello, world! %03d 0x%02X\n", i, i);
#elif defined TEST_SIMPLE
printi("Hello, world! %03d 0x%02x\n", i, i);
#elif defined TEST_TINYSTREAM
std::cout << "Hello, world! " << i << ' ' << i << std::endl;
#elif defined TEST_TINYIO
printf("Hello, world! %03d 0x%02x\n", i, i);
#elif defined TEST_FDSERIAL
// Please note that FdSerial support requires the inclusion of the file
// `pst.dat` as a source file for this project. Because the file is no
// longer included as part of the Simple libraries you must copy it from
// this project to your own before attempting to compile.
dprinti(serial, "Hello, world! %03d 0x%02x\n", i, i);
#elif defined TEST_LIBPROPELLER
serial.PutFormatted("Hello, world! %03d 0x%02X\r\n", i, i);
#endif
i++;
waitcnt(250 * MILLISECOND + CNT);
}
}
printer.h
PropWare::Printer::printf
void printf(const char fmt[], const T first, const Targs... remaining) const
Similar in functionality to the C-standard function printf.
Definition: printer.h:497
libpropeller::Serial
Definition: serial.h:35
fdserial_open
fdserial * fdserial_open(int rxpin, int txpin, int mode, int baudrate)
Open a full duplex serial connection.
Definition: fdserial.c:20
dprinti
int int int dprinti(text_t *device, const char *format,...) __attribute__((format(printf
Print integer and char only format "..." args to the default simple terminal device....
std::stream
Definition: tinystream.h:42
main
int main(void)
Definition: GraphicsTest.c:20
PropWare.h
simpletext.h
This library provides a collection of functions for communicating with text devices such as SimpleIDE...
pwOut
PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
text_struct
Structure that contains data used by simple text device libraries.
Definition: simpletext.h:81
waitcnt
#define waitcnt(a)
Wait until system counter reaches a value.
Definition: propeller.h:176
CNT
#define CNT
The system clock count.
Definition: propeller1.h:151
ON
#define ON
ON can be used in place of a nonzero value to enabled parameters in functions like drive_feedback and...
Definition: abdrive.h:212
PropWare::FullDuplexSerial
Converted to C++ using spin2cpp and then modified to become a PrintCapable object in PropWare's arsen...
Definition: fullduplexserial.h:42
PropWare::Printer
Container class that has formatting methods for human-readable output. This class can be constructed ...
Definition: printer.h:76
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition: runnable.h:33
serial
text_t serial
Makes declarations like serial lcd to stand in for text_t lcd. Spelling is choice of Parallax educati...
Definition: serial.h:68
fdserial.h
This library supports creating and managing one or more full duplex serial connections with periphera...
printi
int printi(const char *format,...) __attribute__((format(printf
Print integer and char only format "..." args to the default simple terminal device....
fullduplexserial.h