How ivanseidel/duetimer works
Project Type and Purpose
• This is an Arduino library specifically designed to simplify working with the Timer Counter module on the Arduino Due.
• Its core purpose is to provide an easy interface for attaching interrupt routines, setting timer periods or frequencies, starting, stopping timers, and managing the available hardware timers on the microcontroller.
• The library also addresses compatibility concerns with the Servo library, indicating integration points where overlapping functionality exists.
Main Components
a. Library Core:
• Block for DueTimer Class – Represent the main abstraction layer provided by DueTimer.h and DueTimer.cpp.
• Methods such as attachInterrupt(), start(), stop(), setPeriod(), setFrequency(), and getAvailable().
• That nine timer objects (Timer0 … Timer8) are pre-instantiated, representing the inherent hardware timer resources.
b. Hardware Abstraction Layer:
• Block for Arduino Due’s Timer Counter Module – Illustrate that the library interfaces directly with the hardware timer peripherals on the microcontroller.
c. Compatibility / Integration:
• A separate note or block showing the compatibility patch for Servo.h – Highlight that there is a conditional aspect (via a define in DueTimer.h) for working with the Servo library.
• An indication that certain timers (0, 2, 3, 4, and 5) will be affected when the Servo library is used.
d. Examples / Usage:
• Block or side note representing the “examples” directory.
• How sample sketches utilize the DueTimer API (using different methods like attachInterrupt with setPeriod or setFrequency).
• This helps in visualizing typical user flows from Arduino sketch to library API.
e. Configuration and Distribution:
• Blocks for ancillary files such as library.json, library.properties, and the README – These indicate configurations for integration with the Arduino IDE and distribution as an open Arduino library.
• While these are not runtime components, they are necessary for understanding deployment and usage.
Relationships and Interactions
• From the “Example Sketches” block to the “DueTimer API” block showing how user code calls library functions.
• From the “DueTimer API” block to the “Timer Counter Module” block to represent hardware interaction.
Architectural Patterns and Design Principles
• Abstraction: The DueTimer class abstracts the underlying timer hardware, allowing users to interact with timers through a clear API.
• Modularity: The separation between the timer library core and the examples as separate concerns.
• Use of a “pre-instantiation” pattern by showing that multiple pre-instantiated timer objects are readily available for immediate use.