aboutsummaryrefslogtreecommitdiffstats
path: root/wirish/comm
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-11-15 12:45:43 -0500
committerMarti Bolivar <mbolivar@leaflabs.com>2012-04-11 16:56:50 -0400
commitf36fae273ec84ee2c53a33caa2dddea2d79db0da (patch)
treefcdaf01cc72a69ca8252213eec35fa0c4aba9ce0 /wirish/comm
parent526d51aa2b83c7a73a2ecdba8525d2a0847e5587 (diff)
downloadlibrambutan-f36fae273ec84ee2c53a33caa2dddea2d79db0da.tar.gz
librambutan-f36fae273ec84ee2c53a33caa2dddea2d79db0da.zip
Move public headers to include directories; related cleanups.
Move libmaple/*.h to (new) libmaple/include/libmaple/. The new accepted way to include a libmaple header foo.h is with: #include <libmaple/foo.h> This is more polite in terms of the include namespace. It also allows us to e.g. implement the Arduino SPI library at all (which has header SPI.h; providing it was previously impossible on case-insensitive filesystems due to libmaple's spi.h). Similarly for Wirish. The old include style (#include "header.h") is now deprecated. libmaple/*.h: - Change include guard #defines from _FOO_H_ to _LIBMAPLE_FOO_H_. - Add license headers where they're missing - Add conditional extern "C" { ... } blocks where they're missing (they aren't always necessary, but we might was well do it against the future, while we're at it.). - Change includes from #include "foo.h" to #include <libmaple/foo.h>. - Move includes after extern "C". - Remove extra trailing newlines Note that this doesn't include the headers under libmaple/usb/ or libmaple/usb/usb_lib. These will get fixed later. libmaple/*.c: - Change includes from #include "foo.h" to #include <libmaple/foo.h>. Makefile: - Add I$(LIBMAPLE_PATH)/include/libmaple to GLOBAL_FLAGS. This allows for users (including Wirish) to migrate their code, but should go away ASAP, since it slows down compilation. Wirish: - Move wirish/**/*.h to (new) wirish/include/wirish/. This ignores the USB headers, which, as usual, are getting handled after everything else. - Similarly generify wirish/boards/ structure. For each supported board "foo", move wirish/boards/foo.h and wirish/boards/foo.cpp to wirish/boards/foo/include/board/board.h and wirish/boards/foo/board.cpp, respectively. Also remove the #ifdef hacks around the .cpp files. - wirish/rules.mk: put wirish/boards/foo/include in the include path (and add wirish/boards/foo/board.cpp to the list of sources to be compiled). This allows saying: #include <board/board.h> instead of the hack currently in place. We can allow the user to override this setting later to make adding custom board definitions easier. - Disable -Werror in libmaple/rules.mk, as the current USB warnings don't let the olimex_stm32_h103 board compile. We can re-enable -Werror once we've moved the board-specific bits out of libmaple proper. libraries, examples: - Update includes accordingly. - Miscellaneous cosmetic fixups. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'wirish/comm')
-rw-r--r--wirish/comm/HardwareSPI.cpp12
-rw-r--r--wirish/comm/HardwareSPI.h223
-rw-r--r--wirish/comm/HardwareSerial.cpp11
-rw-r--r--wirish/comm/HardwareSerial.h86
4 files changed, 12 insertions, 320 deletions
diff --git a/wirish/comm/HardwareSPI.cpp b/wirish/comm/HardwareSPI.cpp
index 21ae180..e1f186e 100644
--- a/wirish/comm/HardwareSPI.cpp
+++ b/wirish/comm/HardwareSPI.cpp
@@ -29,14 +29,14 @@
* @brief Wirish SPI implementation.
*/
-#include "HardwareSPI.h"
+#include <wirish/HardwareSPI.h>
-#include "timer.h"
-#include "util.h"
-#include "rcc.h"
+#include <libmaple/timer.h>
+#include <libmaple/util.h>
+#include <libmaple/rcc.h>
-#include "wirish.h"
-#include "boards.h"
+#include <wirish/wirish.h>
+#include <wirish/boards.h>
struct spi_pins {
uint8 nss;
diff --git a/wirish/comm/HardwareSPI.h b/wirish/comm/HardwareSPI.h
deleted file mode 100644
index d138910..0000000
--- a/wirish/comm/HardwareSPI.h
+++ /dev/null
@@ -1,223 +0,0 @@
-/******************************************************************************
- * The MIT License
- *
- * Copyright (c) 2010 Perry Hung.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *****************************************************************************/
-
-/**
- * @file HardwareSPI.h
- * @brief High-level SPI interface
- *
- * This is a "bare essentials" polling driver for now.
- */
-
-/* TODO [0.1.0] Remove deprecated methods. */
-
-#include "libmaple_types.h"
-#include "spi.h"
-
-#include "boards.h"
-
-#ifndef _HARDWARESPI_H_
-#define _HARDWARESPI_H_
-
-/**
- * @brief Defines the possible SPI communication speeds.
- */
-typedef enum SPIFrequency {
- SPI_18MHZ = 0, /**< 18 MHz */
- SPI_9MHZ = 1, /**< 9 MHz */
- SPI_4_5MHZ = 2, /**< 4.5 MHz */
- SPI_2_25MHZ = 3, /**< 2.25 MHz */
- SPI_1_125MHZ = 4, /**< 1.125 MHz */
- SPI_562_500KHZ = 5, /**< 562.500 KHz */
- SPI_281_250KHZ = 6, /**< 281.250 KHz */
- SPI_140_625KHZ = 7, /**< 140.625 KHz */
-} SPIFrequency;
-
-#define MAX_SPI_FREQS 8
-
-#if CYCLES_PER_MICROSECOND != 72
-/* TODO [0.2.0?] something smarter than this */
-#warning "Unexpected clock speed; SPI frequency calculation will be incorrect"
-#endif
-
-/**
- * @brief Wirish SPI interface.
- *
- * This implementation uses software slave management, so the caller
- * is responsible for controlling the slave select line.
- */
-class HardwareSPI {
-public:
- /**
- * @param spiPortNumber Number of the SPI port to manage.
- */
- HardwareSPI(uint32 spiPortNumber);
-
- /*
- * Set up/tear down
- */
-
- /**
- * @brief Turn on a SPI port and set its GPIO pin modes for use as master.
- *
- * SPI port is enabled in full duplex mode, with software slave management.
- *
- * @param frequency Communication frequency
- * @param bitOrder Either LSBFIRST (little-endian) or MSBFIRST (big-endian)
- * @param mode SPI mode to use, one of SPI_MODE_0, SPI_MODE_1,
- * SPI_MODE_2, and SPI_MODE_3.
- */
- void begin(SPIFrequency frequency, uint32 bitOrder, uint32 mode);
-
- /**
- * @brief Equivalent to begin(SPI_1_125MHZ, MSBFIRST, 0).
- */
- void begin(void);
-
- /**
- * @brief Turn on a SPI port and set its GPIO pin modes for use as a slave.
- *
- * SPI port is enabled in full duplex mode, with software slave management.
- *
- * @param bitOrder Either LSBFIRST (little-endian) or MSBFIRST(big-endian)
- * @param mode SPI mode to use
- */
- void beginSlave(uint32 bitOrder, uint32 mode);
-
- /**
- * @brief Equivalent to beginSlave(MSBFIRST, 0).
- */
- void beginSlave(void);
-
- /**
- * @brief Disables the SPI port, but leaves its GPIO pin modes unchanged.
- */
- void end(void);
-
- /*
- * I/O
- */
-
- /**
- * @brief Return the next unread byte.
- *
- * If there is no unread byte waiting, this function will block
- * until one is received.
- */
- uint8 read(void);
-
- /**
- * @brief Read length bytes, storing them into buffer.
- * @param buffer Buffer to store received bytes into.
- * @param length Number of bytes to store in buffer. This
- * function will block until the desired number of
- * bytes have been read.
- */
- void read(uint8 *buffer, uint32 length);
-
- /**
- * @brief Transmit a byte.
- * @param data Byte to transmit.
- */
- void write(uint8 data);
-
- /**
- * @brief Transmit multiple bytes.
- * @param buffer Bytes to transmit.
- * @param length Number of bytes in buffer to transmit.
- */
- void write(const uint8 *buffer, uint32 length);
-
- /**
- * @brief Transmit a byte, then return the next unread byte.
- *
- * This function transmits before receiving.
- *
- * @param data Byte to transmit.
- * @return Next unread byte.
- */
- uint8 transfer(uint8 data);
-
- /*
- * Pin accessors
- */
-
- /**
- * @brief Return the number of the MISO (master in, slave out) pin
- */
- uint8 misoPin(void);
-
- /**
- * @brief Return the number of the MOSI (master out, slave in) pin
- */
- uint8 mosiPin(void);
-
- /**
- * @brief Return the number of the SCK (serial clock) pin
- */
- uint8 sckPin(void);
-
- /**
- * @brief Return the number of the NSS (slave select) pin
- */
- uint8 nssPin(void);
-
- /* -- The following methods are deprecated --------------------------- */
-
- /**
- * @brief Deprecated.
- *
- * Use HardwareSPI::transfer() instead.
- *
- * @see HardwareSPI::transfer()
- */
- uint8 send(uint8 data);
-
- /**
- * @brief Deprecated.
- *
- * Use HardwareSPI::write() in combination with
- * HardwareSPI::read() (or HardwareSPI::transfer()) instead.
- *
- * @see HardwareSPI::write()
- * @see HardwareSPI::read()
- * @see HardwareSPI::transfer()
- */
- uint8 send(uint8 *data, uint32 length);
-
- /**
- * @brief Deprecated.
- *
- * Use HardwareSPI::read() instead.
- *
- * @see HardwareSPI::read()
- */
- uint8 recv(void);
-private:
- spi_dev *spi_d;
-};
-
-#endif
-
diff --git a/wirish/comm/HardwareSerial.cpp b/wirish/comm/HardwareSerial.cpp
index 6ef9222..a9eb763 100644
--- a/wirish/comm/HardwareSerial.cpp
+++ b/wirish/comm/HardwareSerial.cpp
@@ -29,12 +29,13 @@
* @brief Wirish serial port implementation.
*/
-#include "libmaple.h"
-#include "gpio.h"
-#include "timer.h"
+#include <wirish/HardwareSerial.h>
-#include "HardwareSerial.h"
-#include "boards.h"
+#include <libmaple/libmaple.h>
+#include <libmaple/gpio.h>
+#include <libmaple/timer.h>
+
+#include <wirish/boards.h>
#define TX1 BOARD_USART1_TX_PIN
#define RX1 BOARD_USART1_RX_PIN
diff --git a/wirish/comm/HardwareSerial.h b/wirish/comm/HardwareSerial.h
deleted file mode 100644
index f69b67a..0000000
--- a/wirish/comm/HardwareSerial.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/******************************************************************************
- * The MIT License
- *
- * Copyright (c) 2010 Perry Hung.
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *****************************************************************************/
-
-/**
- * @file HardwareSerial.h
- * @brief Wirish serial port interface.
- */
-
-#ifndef _HARDWARESERIAL_H_
-#define _HARDWARESERIAL_H_
-
-#include "libmaple_types.h"
-#include "usart.h"
-
-#include "Print.h"
-
-/*
- * IMPORTANT:
- *
- * This class documented "by hand" (i.e., not using Doxygen) in the
- * leaflabs-docs/ repository.
- *
- * If you alter the public HardwareSerial interface, you MUST update
- * the documentation accordingly.
- */
-
-class HardwareSerial : public Print {
-public:
- HardwareSerial(usart_dev *usart_device,
- uint8 tx_pin,
- uint8 rx_pin,
- uint32 clock_speed);
-
- /* Set up/tear down */
- void begin(uint32 baud);
- void end(void);
-
- /* I/O */
- uint32 available(void);
- uint8 read(void);
- void flush(void);
- virtual void write(unsigned char);
- using Print::write;
-
- /* Pin accessors */
- int txPin(void) { return this->tx_pin; }
- int rxPin(void) { return this->rx_pin; }
-private:
- usart_dev *usart_device;
- uint8 tx_pin;
- uint8 rx_pin;
- uint32 clock_speed;
-};
-
-extern HardwareSerial Serial1;
-extern HardwareSerial Serial2;
-extern HardwareSerial Serial3;
-#if defined(STM32_HIGH_DENSITY) && !defined(BOARD_maple_RET6)
-extern HardwareSerial Serial4;
-extern HardwareSerial Serial5;
-#endif
-
-#endif