-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathParallel.h
More file actions
114 lines (90 loc) · 3.72 KB
/
Parallel.h
File metadata and controls
114 lines (90 loc) · 3.72 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
Parallel.h
This library implements a limited functionality parallel port on the Arduino
DUE board (ARM Cortex-M3 based).
The DUE board pins out the data bus on the extended digital headers along
with the control signals NC1 and NWR. Some of the address signals are
connected to the PWM pins (A0-A5), but a full address bus is unavailable.
There is also conflict between the SS1 pin for SPI and the NRD signal used
for the parallel bus. In short the hardware wasn't designed for use with
external parallel memories.
The library does allow connection to some of the lower resolution LCD
controllers that used index addressing and can speed up read/write times
considerably.
To use this library, place the files in a folder called 'Parallel' under the
libraries directory in your sketches folder.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PARALLEL_H
#define PARALLEL_H
#include "Arduino.h"
#include "smc.h"
typedef enum
{
// Note that chip select 2 not connected on DUE board.
PARALLEL_CS_0 = 0, // AD4
PARALLEL_CS_1 = 1, // PIN 31
PARALLEL_CS_3 = 3, // PWM13
PARALLEL_CS_NONE
} ParallelChipSelect_t;
typedef enum
{
PARALLEL_BUS_WIDTH_8,
PARALLEL_BUS_WIDTH_16
} ParallelBusWidth_t;
typedef enum
{
READ_MODE_NCS_CTRL = SMC_MODE_READ_MODE_NCS_CTRL,
READ_MODE_NRD_CTRL = SMC_MODE_READ_MODE_NRD_CTRL, // Default
} ReadModeFlags_t;
typedef enum
{
WRITE_MODE_NCS_CTRL = SMC_MODE_WRITE_MODE_NCS_CTRL,
WRITE_MODE_NWE_CTRL = SMC_MODE_WRITE_MODE_NWE_CTRL // Default
} WriteModeFlags_t;
// See SAM3X data sheet in the Static Memory Controller section. Each chip
// select above corresponds to these physical addresses
extern const uint32_t chipSelectAddresses[];
class ParallelClass {
public:
ParallelClass() { };
void begin( ParallelBusWidth_t width,
ParallelChipSelect_t cs,
uint8_t numAddressLines,
uint8_t readEnable,
uint8_t writeEnable);
// Configure the address setup time. See datasheet for calculations.
void setAddressSetupTiming( uint8_t cyclesBeforeNWE,
uint8_t cyclesBeforeNCSWrite,
uint8_t cyclesBeforeNRD,
uint8_t cyclesBeforeNCSRead);
// Configure the pulse width of NCS, NWE, and NRD. See datasheet for calculations.
void setPulseTiming( uint8_t cyclesNWEWidth,
uint8_t cyclesNCSWidthWrite,
uint8_t cyclesNRDWidth,
uint8_t cyclesNCSWidthRead);
// Set the total read/write cycle time. See datasheet for calculations.
void setCycleTiming( uint8_t cyclesWriteTotal,
uint8_t cyclesReadTotal);
// Set how the which signals latch data in the read and write modes (NCS or NRD/NWE).
void setMode(ReadModeFlags_t readMode, WriteModeFlags_t writeMode);
void write(uint32_t offset, uint8_t data) ;
uint8_t read(uint32_t offset);
// returns the address of the memory mapped peripheral
uint32_t getAddress();
private:
ParallelChipSelect_t _cs;
uint32_t _addr;
};
extern ParallelClass Parallel;
#endif