blob: 708089be7291325bd67ee7d5620226a855388f19 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05007
Brian Silverman26e4e522015-12-17 01:56:40 -05008#pragma once
9
10#include "HAL/HAL.hpp"
11#include "SensorBase.h"
12#include "Resource.h"
13
14#include <memory>
15
16class InterruptableSensorBase : public SensorBase {
17 public:
18 enum WaitResult {
19 kTimeout = 0x0,
20 kRisingEdge = 0x1,
21 kFallingEdge = 0x100,
22 kBoth = 0x101,
23 };
24
25 InterruptableSensorBase();
26 virtual ~InterruptableSensorBase() = default;
27 virtual uint32_t GetChannelForRouting() const = 0;
28 virtual uint32_t GetModuleForRouting() const = 0;
29 virtual bool GetAnalogTriggerForRouting() const = 0;
30 virtual void RequestInterrupts(
31 InterruptHandlerFunction handler,
32 void *param); ///< Asynchronus handler version.
33 virtual void RequestInterrupts(); ///< Synchronus Wait version.
34 virtual void
35 CancelInterrupts(); ///< Free up the underlying chipobject functions.
36 virtual WaitResult WaitForInterrupt(
37 float timeout, bool ignorePrevious = true); ///< Synchronus version.
38 virtual void
39 EnableInterrupts(); ///< Enable interrupts - after finishing setup.
40 virtual void DisableInterrupts(); ///< Disable, but don't deallocate.
41 virtual double ReadRisingTimestamp(); ///< Return the timestamp for the
42 ///rising interrupt that occurred.
43 virtual double ReadFallingTimestamp(); ///< Return the timestamp for the
44 ///falling interrupt that occurred.
45 virtual void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
46
47 protected:
48 void *m_interrupt = nullptr;
49 uint32_t m_interruptIndex = std::numeric_limits<uint32_t>::max();
50 void AllocateInterrupts(bool watcher);
51
52 static std::unique_ptr<Resource> m_interrupts;
53};