Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
// -*- Mode: C++; c-basic-offset: 8; indent-tabs-mode: nil -*-
2
 
3
//
4
// Example code for the FastSerial driver.
5
//
6
// This code is placed into the public domain.
7
//
8
 
9
//
10
// Include the FastSerial library header.
11
//
12
// Note that this causes the standard Arduino Serial* driver to be
13
// disabled.
14
//
15
#include <FastSerial.h>
16
 
17
#undef PROGMEM
18
#define PROGMEM __attribute__(( section(".progmem.data") ))
19
 
20
# undef PSTR
21
# define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); \
22
                (prog_char_t *)&__c[0];}))
23
 
24
//
25
// Create a FastSerial driver that looks just like the stock Arduino
26
// driver.
27
//
28
FastSerialPort0(Serial);
29
 
30
//
31
// To create a driver for a different serial port, on a board that
32
// supports more than one, use the appropriate macro:
33
//
34
//FastSerialPort2(Serial2);
35
 
36
 
37
void setup(void)
38
{
39
        //
40
        // Set the speed for our replacement serial port.
41
        //
42
	Serial.begin(115200);
43
 
44
        //
45
        // Test printing things
46
        //
47
        Serial.print("test");
48
        Serial.println(" begin");
49
        Serial.println(1000);
50
        Serial.println(1000, 8);
51
        Serial.println(1000, 10);
52
        Serial.println(1000, 16);
53
        Serial.println_P(PSTR("progmem"));
54
        Serial.printf("printf %d %u %#x %p %f %S\n", -1000, 1000, 1000, 1000, 1.2345, PSTR("progmem"));
55
        Serial.printf_P(PSTR("printf_P %d %u %#x %p %f %S\n"), -1000, 1000, 1000, 1000, 1.2345, PSTR("progmem"));
56
        Serial.println("done");
57
}
58
 
59
void
60
loop(void)
61
{
62
    int    c;
63
 
64
    //
65
    // Perform a simple loopback operation.
66
    //
67
    c = Serial.read();
68
    if (-1 != c)
69
        Serial.write(c);
70
}
71