An mbed wrapper around the helium-client to communicate with the Helium Atom
Helium for ARM mbed
This code repository exposes an mbed library for the Helium Atom module. The Helium Atom makes it easy to securely connect IoT devices and applications to back-end IoT services.
Getting Started
See a getting started guide on the Helium site.
Supported Boards
The Helium mbed client should work with any mbed board with an available serial port.
Example Setup
Example applications can be found in the mbed Helium team.
Getting Help
If you have any questions or ideas about how to use this code - or any part of Helium - head over to the Helium Community Slack. We're standing by to help.
Contributing
Want to contribute to helium-mbed? That's awesome!
Please see CONTRIBUTING.md in this repository for details.
src/BufferedSerial.h@14:af7682f4e610, 2017-07-06 (annotated)
- Committer:
- Marc Nijdam
- Date:
- Thu Jul 06 10:18:57 2017 -0700
- Revision:
- 14:af7682f4e610
- Parent:
- 12:07a4782fe9f2
- Child:
- 16:21b6f13fee79
Fixing buffered serial again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Marc Nijdam |
9:fa0d965ca34f | 1 | /** |
Marc Nijdam |
9:fa0d965ca34f | 2 | * \copyright Copyright 2017, Helium Systems, Inc. |
Marc Nijdam |
12:07a4782fe9f2 | 3 | * All Rights Reserved. See LICENSE.txt for license information |
Marc Nijdam |
9:fa0d965ca34f | 4 | */ |
Marc Nijdam |
9:fa0d965ca34f | 5 | |
Marc Nijdam |
14:af7682f4e610 | 6 | #include "mbed.h" |
Marc Nijdam |
9:fa0d965ca34f | 7 | #include "Ringbuffer.h" |
Marc Nijdam |
9:fa0d965ca34f | 8 | |
Marc Nijdam |
9:fa0d965ca34f | 9 | #ifndef BUFFEREDSERIAL_H |
Marc Nijdam |
9:fa0d965ca34f | 10 | #define BUFFEREDSERIAL_H |
Marc Nijdam |
9:fa0d965ca34f | 11 | |
Marc Nijdam |
9:fa0d965ca34f | 12 | /** |
Marc Nijdam |
9:fa0d965ca34f | 13 | * \class BufferedSerial |
Marc Nijdam |
9:fa0d965ca34f | 14 | * |
Marc Nijdam |
9:fa0d965ca34f | 15 | * \brief Implements a buffered serial port |
Marc Nijdam |
9:fa0d965ca34f | 16 | * |
Marc Nijdam |
9:fa0d965ca34f | 17 | * This is a simple buffered serial port to work around `readable` |
Marc Nijdam |
9:fa0d965ca34f | 18 | * issues on a number of mbed implementations. Receiving on the serial |
Marc Nijdam |
9:fa0d965ca34f | 19 | * port is buffered through an interrupt handler. |
Marc Nijdam |
9:fa0d965ca34f | 20 | * |
Marc Nijdam |
9:fa0d965ca34f | 21 | * Note that writing is not buffered at this time since writing to the |
Marc Nijdam |
9:fa0d965ca34f | 22 | * serial port at speed had not been an issue so far. |
Marc Nijdam |
9:fa0d965ca34f | 23 | */ |
Marc Nijdam |
14:af7682f4e610 | 24 | class BufferedSerial : public RawSerial |
Marc Nijdam |
9:fa0d965ca34f | 25 | { |
Marc Nijdam |
9:fa0d965ca34f | 26 | public: |
Marc Nijdam |
9:fa0d965ca34f | 27 | /** Crete a buffered serial port. |
Marc Nijdam |
9:fa0d965ca34f | 28 | * |
Marc Nijdam |
9:fa0d965ca34f | 29 | * @param tx Serial port tx pin to use |
Marc Nijdam |
9:fa0d965ca34f | 30 | * @param rx Serial port rx pin to use |
Marc Nijdam |
14:af7682f4e610 | 31 | * @param baud The baud rate to use. Defaults to the default for the current |
Marc Nijdam |
14:af7682f4e610 | 32 | * board |
Marc Nijdam |
9:fa0d965ca34f | 33 | */ |
Marc Nijdam |
9:fa0d965ca34f | 34 | BufferedSerial(PinName tx, |
Marc Nijdam |
9:fa0d965ca34f | 35 | PinName rx, |
Marc Nijdam |
14:af7682f4e610 | 36 | int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); |
Marc Nijdam |
9:fa0d965ca34f | 37 | |
Marc Nijdam |
9:fa0d965ca34f | 38 | /** Destructor */ |
Marc Nijdam |
14:af7682f4e610 | 39 | ~BufferedSerial(); |
Marc Nijdam |
9:fa0d965ca34f | 40 | |
Marc Nijdam |
9:fa0d965ca34f | 41 | |
Marc Nijdam |
9:fa0d965ca34f | 42 | /** Sets the baud rate for the serial port |
Marc Nijdam |
9:fa0d965ca34f | 43 | * |
Marc Nijdam |
9:fa0d965ca34f | 44 | * @param baud The baud rate to set on the serial port |
Marc Nijdam |
9:fa0d965ca34f | 45 | */ |
Marc Nijdam |
14:af7682f4e610 | 46 | void baud(int baud); |
Marc Nijdam |
9:fa0d965ca34f | 47 | |
Marc Nijdam |
9:fa0d965ca34f | 48 | /** Get a byte from the serial port buffer. |
Marc Nijdam |
9:fa0d965ca34f | 49 | * |
Marc Nijdam |
9:fa0d965ca34f | 50 | * @return a buffered byte or -1 if no bytes are available |
Marc Nijdam |
9:fa0d965ca34f | 51 | */ |
Marc Nijdam |
14:af7682f4e610 | 52 | int getc(); |
Marc Nijdam |
9:fa0d965ca34f | 53 | |
Marc Nijdam |
9:fa0d965ca34f | 54 | /** Write a byte to the serial port |
Marc Nijdam |
9:fa0d965ca34f | 55 | * |
Marc Nijdam |
9:fa0d965ca34f | 56 | * @param ch The byte to write |
Marc Nijdam |
9:fa0d965ca34f | 57 | * @return the byte that was written |
Marc Nijdam |
9:fa0d965ca34f | 58 | */ |
Marc Nijdam |
14:af7682f4e610 | 59 | int putc(int ch); |
Marc Nijdam |
9:fa0d965ca34f | 60 | |
Marc Nijdam |
9:fa0d965ca34f | 61 | /** Check if there are bytes to read. |
Marc Nijdam |
9:fa0d965ca34f | 62 | * |
Marc Nijdam |
9:fa0d965ca34f | 63 | * @return 1 if bytes are available, 0 otherwise |
Marc Nijdam |
9:fa0d965ca34f | 64 | */ |
Marc Nijdam |
14:af7682f4e610 | 65 | int readable(); |
Marc Nijdam |
14:af7682f4e610 | 66 | |
Marc Nijdam |
14:af7682f4e610 | 67 | |
Marc Nijdam |
14:af7682f4e610 | 68 | private: |
Marc Nijdam |
14:af7682f4e610 | 69 | RingBuffer<uint8_t, 16> _rx_buffer; |
Marc Nijdam |
14:af7682f4e610 | 70 | void _rx_interrupt(); |
Marc Nijdam |
14:af7682f4e610 | 71 | |
Marc Nijdam |
9:fa0d965ca34f | 72 | }; |
Marc Nijdam |
9:fa0d965ca34f | 73 | |
Marc Nijdam |
9:fa0d965ca34f | 74 | |
Marc Nijdam |
9:fa0d965ca34f | 75 | #endif |