Skip to content

Commit

Permalink
Avrlib parallel io
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier gillet committed May 11, 2014
1 parent 7f256db commit 4c5f056
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions parallel_io.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ enum ParallelPortMode {
PARALLEL_BYTE,
PARALLEL_NIBBLE_HIGH,
PARALLEL_NIBBLE_LOW,
PARALLEL_TRIPLE_HIGHEST,
PARALLEL_TRIPLE_HIGH,
PARALLEL_TRIPLE_LOW
PARALLEL_TRIPLE_LOW,
PARALLEL_DOUBLE_HIGH,
PARALLEL_DOUBLE_MIDHIGH,
PARALLEL_DOUBLE_MIDLOW,
PARALLEL_DOUBLE_LOW
};

template<ParallelPortMode mode>
Expand All @@ -58,10 +63,18 @@ struct ShiftMasks<PARALLEL_NIBBLE_LOW> {
};
};

template<>
struct ShiftMasks<PARALLEL_TRIPLE_HIGHEST> {
enum Masks {
mask = 0xe0,
shift = 5,
};
};

template<>
struct ShiftMasks<PARALLEL_TRIPLE_HIGH> {
enum Masks {
mask = 0x78,
mask = 0x38,
shift = 3,
};
};
Expand All @@ -74,6 +87,38 @@ struct ShiftMasks<PARALLEL_TRIPLE_LOW> {
};
};

template<>
struct ShiftMasks<PARALLEL_DOUBLE_HIGH> {
enum Masks {
mask = 0xc0,
shift = 6,
};
};

template<>
struct ShiftMasks<PARALLEL_DOUBLE_MIDHIGH> {
enum Masks {
mask = 0x30,
shift = 4,
};
};

template<>
struct ShiftMasks<PARALLEL_DOUBLE_MIDLOW> {
enum Masks {
mask = 0x0c,
shift = 2,
};
};

template<>
struct ShiftMasks<PARALLEL_DOUBLE_LOW> {
enum Masks {
mask = 0x03,
shift = 0,
};
};

template<typename Port, ParallelPortMode parallel_mode = PARALLEL_BYTE>
struct ParallelPort {
typedef ShiftMasks<parallel_mode> Masks;
Expand All @@ -94,7 +139,8 @@ struct ParallelPort {
}

static inline void EnablePullUpResistors() {
Write(Masks::mask);
uint8_t preserve = *Port::Output::ptr();
*Port::Output::ptr() = preserve | Masks::mask;
}

static inline uint8_t Read() {
Expand Down

0 comments on commit 4c5f056

Please sign in to comment.