Skip to content

Commit 989c661

Browse files
committed
Merge branch 'master' of https://github.com/mbedmicro/mbed
2 parents 28120ff + b311c56 commit 989c661

File tree

90 files changed

+11209
-835
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+11209
-835
lines changed

MANIFEST

Lines changed: 0 additions & 96 deletions
This file was deleted.

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
graft workspace_tools
2-
include __init__.py LICENSE
2+
recursive-exclude workspace_tools *.pyc
3+
include LICENSE

libraries/mbed/api/InterruptIn.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,13 @@ class InterruptIn {
108108
*/
109109
void mode(PinMode pull);
110110

111-
/** Enable IRQ
111+
/** Enable IRQ. This method depends on hw implementation, might enable one
112+
* port interrupts. For further information, check gpio_irq_enable().
112113
*/
113114
void enable_irq();
114115

115-
/** Disable IRQ
116+
/** Disable IRQ. This method depends on hw implementation, might disable one
117+
* port interrupts. For further information, check gpio_irq_disable().
116118
*/
117119
void disable_irq();
118120

libraries/mbed/api/RawSerial.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ class RawSerial: public SerialBase {
7171
* @returns The char read from the serial port
7272
*/
7373
int getc();
74+
75+
/** Write a string to the serial port
76+
*
77+
* @param str The string to write
78+
*
79+
* @returns 0 if the write succeeds, EOF for error
80+
*/
81+
int puts(const char *str);
82+
83+
int printf(const char *format, ...);
7484
};
7585

7686
} // namespace mbed

libraries/mbed/api/SerialBase.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class SerialBase {
5151
TxIrq
5252
};
5353

54+
enum Flow {
55+
Disabled = 0,
56+
RTS,
57+
CTS,
58+
RTSCTS
59+
};
60+
5461
/** Set the transmission format used by the serial port
5562
*
5663
* @param bits The number of bits in a word (5-8; default = 8)
@@ -99,6 +106,16 @@ class SerialBase {
99106
/** Generate a break condition on the serial line
100107
*/
101108
void send_break();
109+
110+
#if DEVICE_SERIAL_FC
111+
/** Set the flow control type on the serial port
112+
*
113+
* @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
114+
* @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
115+
* @param flow2 the second flow control pin (CTS for RTSCTS)
116+
*/
117+
void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
118+
#endif
102119

103120
static void _irq_handler(uint32_t id, SerialIrq irq_type);
104121

libraries/mbed/common/RawSerial.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
*/
1616
#include "RawSerial.h"
1717
#include "wait_api.h"
18+
#include <cstdarg>
1819

1920
#if DEVICE_SERIAL
2021

22+
#define STRING_STACK_LIMIT 120
23+
2124
namespace mbed {
2225

2326
RawSerial::RawSerial(PinName tx, PinName rx) : SerialBase(tx, rx) {
@@ -31,6 +34,34 @@ int RawSerial::putc(int c) {
3134
return _base_putc(c);
3235
}
3336

37+
int RawSerial::puts(const char *str) {
38+
while (*str)
39+
putc(*str ++);
40+
return 0;
41+
}
42+
43+
// Experimental support for printf in RawSerial. No Stream inheritance
44+
// means we can't call printf() directly, so we use sprintf() instead.
45+
// We only call malloc() for the sprintf() buffer if the buffer
46+
// length is above a certain threshold, otherwise we use just the stack.
47+
int RawSerial::printf(const char *format, ...) {
48+
std::va_list arg;
49+
va_start(arg, format);
50+
int len = vsnprintf(NULL, 0, format, arg);
51+
if (len < STRING_STACK_LIMIT) {
52+
char temp[STRING_STACK_LIMIT];
53+
vsprintf(temp, format, arg);
54+
puts(temp);
55+
} else {
56+
char *temp = new char[len + 1];
57+
vsprintf(temp, format, arg);
58+
puts(temp);
59+
delete[] temp;
60+
}
61+
va_end(arg);
62+
return len;
63+
}
64+
3465
} // namespace mbed
3566

3667
#endif

libraries/mbed/common/SerialBase.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,29 @@ void SerialBase::send_break() {
8181
serial_break_clear(&_serial);
8282
}
8383

84+
#ifdef DEVICE_SERIAL_FC
85+
void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) {
86+
FlowControl flow_type = (FlowControl)type;
87+
switch(type) {
88+
case RTS:
89+
serial_set_flow_control(&_serial, flow_type, flow1, NC);
90+
break;
91+
92+
case CTS:
93+
serial_set_flow_control(&_serial, flow_type, NC, flow1);
94+
break;
95+
96+
case RTSCTS:
97+
case Disabled:
98+
serial_set_flow_control(&_serial, flow_type, flow1, flow2);
99+
break;
100+
101+
default:
102+
break;
103+
}
104+
}
105+
#endif
106+
84107
} // namespace mbed
85108

86109
#endif

libraries/mbed/common/pinmap_common.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,22 @@ uint32_t pinmap_merge(uint32_t a, uint32_t b) {
4444
return (uint32_t)NC;
4545
}
4646

47-
uint32_t pinmap_peripheral(PinName pin, const PinMap* map) {
48-
if (pin == (PinName)NC)
49-
return (uint32_t)NC;
50-
47+
uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map) {
5148
while (map->pin != NC) {
5249
if (map->pin == pin)
5350
return map->peripheral;
5451
map++;
5552
}
56-
57-
// no mapping available
58-
error("pinmap not found for peripheral");
5953
return (uint32_t)NC;
6054
}
55+
56+
uint32_t pinmap_peripheral(PinName pin, const PinMap* map) {
57+
uint32_t peripheral = (uint32_t)NC;
58+
59+
if (pin == (PinName)NC)
60+
return (uint32_t)NC;
61+
peripheral = pinmap_find_peripheral(pin, map);
62+
if ((uint32_t)NC == peripheral) // no mapping available
63+
error("pinmap not found for peripheral");
64+
return peripheral;
65+
}

libraries/mbed/hal/pinmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void pin_mode (PinName pin, PinMode mode);
3434
uint32_t pinmap_peripheral(PinName pin, const PinMap* map);
3535
uint32_t pinmap_merge (uint32_t a, uint32_t b);
3636
void pinmap_pinout (PinName pin, const PinMap *map);
37+
uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map);
3738

3839
#ifdef __cplusplus
3940
}

libraries/mbed/hal/serial_api.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ typedef enum {
3737
TxIrq
3838
} SerialIrq;
3939

40+
typedef enum {
41+
FlowControlNone,
42+
FlowControlRTS,
43+
FlowControlCTS,
44+
FlowControlRTSCTS
45+
} FlowControl;
46+
4047
typedef void (*uart_irq_handler)(uint32_t id, SerialIrq event);
4148

4249
typedef struct serial_s serial_t;
@@ -60,6 +67,8 @@ void serial_break_clear(serial_t *obj);
6067

6168
void serial_pinout_tx(PinName tx);
6269

70+
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow);
71+
6372
#ifdef __cplusplus
6473
}
6574
#endif

0 commit comments

Comments
 (0)