/
pin.h
64 lines (58 loc) · 1.51 KB
/
pin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef __AVR_PIN_H__
#define __AVR_PIN_H__
#include <avr/io.h>
#include "../avrm.h"
/// PinMode
/// Configuration for an AVR pin.
// TODO: Should we add a `INPUT_PULLUP` mode?
typedef enum {INPUT, OUTPUT} PinMode;
/// pin_mode
/// Setup a pin for `OUTPUT` or `INPUT`.
///
/// A pin in `OUTPUT` mode will either drive current at logic high, or sink
/// current at logic low. Most AVRs can safely provide +/-40mA.
///
/// A pin in `INPUT` mode (the default mode) are in a high impedance state.
/// It only takes a small amount of current to move a pin in this state from
/// reading a logic low to a logic high. Using `pin_out(pin, HIGH)` on a pin
/// in this mode will activate it's internal pullup resistor.
///
/// # Example
///
/// ```
/// // Set the LED pin to OUTPUT mode.
/// pin_mode(13, OUTPUT);
///
/// // Set pin 5 to INPUT mode.
/// pin_mode(5, INPUT);
/// ```
void pin_mode(int pin, PinMode mode);
/// pin_in
/// Read the value on a pin.
///
/// This function is currently only implemented for the ATmega168/328p.
///
/// # Example
///
/// ```
/// // Read the digital state of the 5th pin.
/// bool active = pin_in(5);
/// ```
bool pin_in(int pin);
/// pin_out
/// Sets the digital value of a pin.
///
/// This function is currently only implemented for the ATmega168/328p.
///
/// # Example
///
/// ```
/// // Set pin 0 to logic high.
/// pin_out(0, TRUE);
/// // Set pin 8 to logic low.
/// pin_out(8, FALSE);
/// // Set pin 13 (LED) to logic high (on).
/// pin_out(13, TRUE);
/// ```
void pin_out(int pin, bool value);
#endif