aboutsummaryrefslogtreecommitdiffstats
path: root/wirish/HardwareTimer.h
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/HardwareTimer.h
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/HardwareTimer.h')
-rw-r--r--wirish/HardwareTimer.h331
1 files changed, 0 insertions, 331 deletions
diff --git a/wirish/HardwareTimer.h b/wirish/HardwareTimer.h
deleted file mode 100644
index 1c34b9d..0000000
--- a/wirish/HardwareTimer.h
+++ /dev/null
@@ -1,331 +0,0 @@
-/******************************************************************************
- * The MIT License
- *
- * Copyright (c) 2010 Bryan Newbold.
- *
- * 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.
- *****************************************************************************/
-
-/**
- * @brief Wirish timer class.
- */
-
-#ifndef _HARDWARETIMER_H_
-#define _HARDWARETIMER_H_
-
-// TODO [0.1.0] Remove deprecated pieces, pick a better API
-
-#include "timer.h"
-
-/** Timer mode. */
-typedef timer_mode TimerMode;
-
-/** @brief Deprecated; use TIMER_OUTPUT_COMPARE instead. */
-#define TIMER_OUTPUTCOMPARE TIMER_OUTPUT_COMPARE
-
-/**
- * @brief Interface to one of the 16-bit timer peripherals.
- */
-class HardwareTimer {
-private:
- timer_dev *dev;
-
-public:
- /**
- * @brief Construct a new HardwareTimer instance.
- * @param timerNum number of the timer to control.
- */
- HardwareTimer(uint8 timerNum);
-
- /**
- * @brief Stop the counter, without affecting its configuration.
- *
- * @see HardwareTimer::resume()
- */
- void pause(void);
-
- /**
- * @brief Resume a paused timer, without affecting its configuration.
- *
- * The timer will resume counting and firing interrupts as
- * appropriate.
- *
- * Note that there is some function call overhead associated with
- * using this method, so using it in concert with
- * HardwareTimer::pause() is not a robust way to align multiple
- * timers to the same count value.
- *
- * @see HardwareTimer::pause()
- */
- void resume(void);
-
- /**
- * @brief Get the timer's prescale factor.
- * @return Timer prescaler, from 1 to 65,536.
- * @see HardwareTimer::setPrescaleFactor()
- */
- uint32 getPrescaleFactor();
-
- /**
- * @brief Set the timer's prescale factor.
- *
- * The new value won't take effect until the next time the counter
- * overflows. You can force the counter to reset using
- * HardwareTimer::refresh().
- *
- * @param factor The new prescale value to set, from 1 to 65,536.
- * @see HardwareTimer::refresh()
- */
- void setPrescaleFactor(uint32 factor);
-
- /**
- * @brief Get the timer overflow value.
- * @see HardwareTimer::setOverflow()
- */
- uint16 getOverflow();
-
- /**
- * @brief Set the timer overflow (or "reload") value.
- *
- * The new value won't take effect until the next time the counter
- * overflows. You can force the counter to reset using
- * HardwareTimer::refresh().
- *
- * @param val The new overflow value to set
- * @see HardwareTimer::refresh()
- */
- void setOverflow(uint16 val);
-
- /**
- * @brief Get the current timer count.
- *
- * @return The timer's current count value
- */
- uint16 getCount(void);
-
- /**
- * @brief Set the current timer count.
- *
- * @param val The new count value to set. If this value exceeds
- * the timer's overflow value, it is truncated to the
- * overflow value.
- */
- void setCount(uint16 val);
-
- /**
- * @brief Set the timer's period in microseconds.
- *
- * Configures the prescaler and overflow values to generate a timer
- * reload with a period as close to the given number of
- * microseconds as possible.
- *
- * @param microseconds The desired period of the timer. This must be
- * greater than zero.
- * @return The new overflow value.
- */
- uint16 setPeriod(uint32 microseconds);
-
- /**
- * @brief Configure a timer channel's mode.
- * @param channel Timer channel, from 1 to 4
- * @param mode Mode to set
- */
- void setMode(int channel, timer_mode mode);
-
- /**
- * @brief Get the compare value for the given channel.
- * @see HardwareTimer::setCompare()
- */
- uint16 getCompare(int channel);
-
- /**
- * @brief Set the compare value for the given channel.
- *
- * @param channel the channel whose compare to set, from 1 to 4.
- * @param compare The compare value to set. If greater than this
- * timer's overflow value, it will be truncated to
- * the overflow value.
- *
- * @see timer_mode
- * @see HardwareTimer::setMode()
- * @see HardwareTimer::attachInterrupt()
- */
- void setCompare(int channel, uint16 compare);
-
- /**
- * @brief Attach an interrupt handler to the given channel.
- *
- * This interrupt handler will be called when the timer's counter
- * reaches the given channel compare value.
- *
- * @param channel the channel to attach the ISR to, from 1 to 4.
- * @param handler The ISR to attach to the given channel.
- * @see voidFuncPtr
- */
- void attachInterrupt(int channel, voidFuncPtr handler);
-
- /**
- * @brief Remove the interrupt handler attached to the given
- * channel, if any.
- *
- * The handler will no longer be called by this timer.
- *
- * @param channel the channel whose interrupt to detach, from 1 to 4.
- * @see HardwareTimer::attachInterrupt()
- */
- void detachInterrupt(int channel);
-
- /**
- * @brief Reset the counter, and update the prescaler and overflow
- * values.
- *
- * This will reset the counter to 0 in upcounting mode (the
- * default). It will also update the timer's prescaler and
- * overflow, if you have set them up to be changed using
- * HardwareTimer::setPrescaleFactor() or
- * HardwareTimer::setOverflow().
- *
- * @see HardwareTimer::setPrescaleFactor()
- * @see HardwareTimer::setOverflow()
- */
- void refresh(void);
-
- /* -- Deprecated methods ----------------------------------------------- */
-
- /** @brief Deprecated; use setMode(channel, mode) instead. */
- void setChannelMode(int channel, timer_mode mode) {
- setMode(channel, mode);
- }
-
- /** @brief Deprecated; use setMode(TIMER_CH1, mode) instead. */
- void setChannel1Mode(timer_mode mode) { setMode(TIMER_CH1, mode); }
-
- /** @brief Deprecated; use setMode(TIMER_CH2, mode) instead. */
- void setChannel2Mode(timer_mode mode) { setMode(TIMER_CH2, mode); }
-
- /** @brief Deprecated; use setMode(TIMER_CH3, mode) instead. */
- void setChannel3Mode(timer_mode mode) { setMode(TIMER_CH3, mode); }
-
- /** @brief Deprecated; use setMode(TIMER_CH4, mode) instead. */
- void setChannel4Mode(timer_mode mode) { setMode(TIMER_CH4, mode); }
-
- /** @brief Deprecated; use return getCompare(TIMER_CH1) instead. */
- uint16 getCompare1() { return getCompare(TIMER_CH1); }
-
- /** @brief Deprecated; use return getCompare(TIMER_CH2) instead. */
- uint16 getCompare2() { return getCompare(TIMER_CH2); }
-
- /** @brief Deprecated; use return getCompare(TIMER_CH3) instead. */
- uint16 getCompare3() { return getCompare(TIMER_CH3); }
-
- /** @brief Deprecated; use return getCompare(TIMER_CH4) instead. */
- uint16 getCompare4() { return getCompare(TIMER_CH4); }
-
- /** @brief Deprecated; use setCompare(TIMER_CH1, compare) instead. */
- void setCompare1(uint16 compare) { setCompare(TIMER_CH1, compare); }
-
- /** @brief Deprecated; use setCompare(TIMER_CH2, compare) instead. */
- void setCompare2(uint16 compare) { setCompare(TIMER_CH2, compare); }
-
- /** @brief Deprecated; use setCompare(TIMER_CH3, compare) instead. */
- void setCompare3(uint16 compare) { setCompare(TIMER_CH3, compare); }
-
- /** @brief Deprecated; use setCompare(TIMER_CH4, compare) instead. */
- void setCompare4(uint16 compare) { setCompare(TIMER_CH4, compare); }
-
- /** @brief Deprecated; use attachInterrupt(TIMER_CH1, handler) instead. */
- void attachCompare1Interrupt(voidFuncPtr handler) {
- attachInterrupt(TIMER_CH1, handler);
- }
-
- /** @brief Deprecated; use attachInterrupt(TIMER_CH2, handler) instead. */
- void attachCompare2Interrupt(voidFuncPtr handler) {
- attachInterrupt(TIMER_CH2, handler);
- }
-
- /** @brief Deprecated; use attachInterrupt(TIMER_CH3, handler) instead. */
- void attachCompare3Interrupt(voidFuncPtr handler) {
- attachInterrupt(TIMER_CH3, handler);
- }
-
- /** @brief Deprecated; use attachInterrupt(TIMER_CH4, handler) instead. */
- void attachCompare4Interrupt(voidFuncPtr handler) {
- attachInterrupt(TIMER_CH4, handler);
- }
-
- /** @brief Deprecated; use detachInterrupt(TIMER_CH1) instead. */
- void detachCompare1Interrupt(void) { detachInterrupt(TIMER_CH1); }
-
- /** @brief Deprecated; use detachInterrupt(TIMER_CH2) instead. */
- void detachCompare2Interrupt(void) { detachInterrupt(TIMER_CH2); }
-
- /** @brief Deprecated; use detachInterrupt(TIMER_CH3) instead. */
- void detachCompare3Interrupt(void) { detachInterrupt(TIMER_CH3); }
-
- /** @brief Deprecated; use detachInterrupt(TIMER_CH4) instead. */
- void detachCompare4Interrupt(void) { detachInterrupt(TIMER_CH4); }
-
- /** @brief Deprecated; use refresh() instead. */
- void generateUpdate(void) { refresh(); }
-};
-
-/* -- The rest of this file is deprecated. --------------------------------- */
-
-/**
- * @brief Deprecated.
- *
- * Pre-instantiated timer.
- */
-extern HardwareTimer Timer1;
-/**
- * @brief Deprecated.
- *
- * Pre-instantiated timer.
- */
-extern HardwareTimer Timer2;
-/**
- * @brief Deprecated.
- *
- * Pre-instantiated timer.
- */
-extern HardwareTimer Timer3;
-/**
- * @brief Deprecated.
- *
- * Pre-instantiated timer.
- */
-extern HardwareTimer Timer4;
-#ifdef STM32_HIGH_DENSITY
-/**
- * @brief Deprecated.
- *
- * Pre-instantiated timer.
- */
-extern HardwareTimer Timer5;
-/**
- * @brief Deprecated.
- *
- * Pre-instantiated timer.
- */
-extern HardwareTimer Timer8;
-#endif
-
-#endif