PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Simple Libraries
Display
liboledc
oledc_spiWrite.c
1
/*
2
* @file oledc_spiWrite.c
3
*
4
* @author Matthew Matz
5
*
6
* @version 0.9
7
*
8
* @copyright Copyright (C) Parallax, Inc. 2016. See end of file for
9
* terms of use (MIT License).
10
*
11
* @brief 0.96-inch RGB OLED display bitmap driver, see oledc_h. for documentation.
12
*
13
* @detail Please submit bug reports, suggestions, and improvements to
14
* this code to editor@parallax.com.
15
*/
16
17
18
#include "oledc.h"
19
20
// ------------------- low level pin interface --------------------
21
char
_cs, _rs, _rst, _sid, _sclk;
22
char
_screenLock;
23
24
//char _byteReadyFlag, _byteToSend, _byteType; // For multicore support when enabled
25
26
__attribute__((fcache))
// allows function to run directly from cog ram, 10x+ speed increase
27
void
oledc_spiWrite(
char
c,
char
dc) {
28
29
// Conditionally set _rs (Source: https://graphics.stanford.edu/~seander/bithacks.html)
30
unsigned
int
mask = (-(dc & 1) ^
OUTA
) & (1 << _rs);
31
OUTA
^= mask;
32
33
OUTA
&= ~(1 << _cs);
34
mask = 1 << _sclk;
// Set up mask
35
OUTA
&= ~mask;
// Pin output state to low
36
DIRA
|= mask;
// Pin direction to output
37
38
for
(
int
i = 7; i >= 0 ; i--)
39
{
40
mask = 1 << _sid;
41
if
((c >> i) & 1)
OUTA
|= mask;
42
else
OUTA
&= (~mask);
43
mask = 1 << _sclk;
44
OUTA
^= mask;
45
OUTA
^= mask;
46
}
47
OUTA
|= 1 << _cs;
48
}
49
50
void
oledc_writeCommand(
char
c,
char
dc) {
51
oledc_spiWrite(c, dc);
52
53
//while(byteReadyFlag);
54
//_byteToSend = c;
55
//_byteType = dc;
56
//_byteReadyFlag = 1;
57
}
58
59
char
oledc_screenLock() {
60
return
_screenLock;
61
}
62
63
void
oledc_screenLockSet() {
64
_screenLock = 1;
65
}
66
67
void
oledc_screenLockClr() {
68
_screenLock = 0;
69
}
70
71
98
100
/*
101
102
//__attribute__((fcache))
103
void oledc_spiWrite(void *par) {
104
105
DIRA |= 1<<27;
106
DIRA |= 1<<26;
107
108
while(1)
109
{
110
while(!_byteReadyFlag);
111
112
if(_byteType)
113
{
114
OUTA |= 1 << _rs;
115
OUTA |= 1 << 26;
116
OUTA &= ~(1 << 27);
117
}
118
else
119
{
120
OUTA &= ~(1 << _rs);
121
OUTA |= 1 << 27;
122
OUTA &= ~(1 << 26);
123
}
124
125
126
unsigned int mask = 1 << _sclk; // Set up mask
127
OUTA &= ~mask; // Pin output state to low
128
OUTA &= ~(1 << _cs);
129
130
for (char i = 7; i >= 0 ; i--)
131
{
132
mask = 1 << _sid;
133
if (((_byteToSend >> i) & 1) == 0)
134
{
135
OUTA &= (~mask);
136
}
137
else
138
{
139
OUTA |= mask;
140
}
141
mask = 1 << _sclk;
142
OUTA ^= mask;
143
OUTA ^= mask;
144
}
145
146
OUTA |= 1 << _cs;
147
148
_byteReadyFlag = 0;
149
}
150
}
151
152
void oledc_writeCommand(char c) {
153
//oledc_spiWrite(c, 0);
154
while(_byteReadyFlag);
155
_byteToSend = c;
156
_byteType = 0;
157
_byteReadyFlag = 1;
158
}
159
160
void oledc_writeData(char c) {
161
//oledc_spiWrite(c, 1);
162
while(_byteReadyFlag);
163
_byteType = 1;
164
_byteToSend = c;
165
_byteReadyFlag = 1;
166
}
167
168
169
*/
OUTA
#define OUTA
Use to set output pin states when corresponding DIRA bits are 1.
Definition:
propeller1.h:157
DIRA
#define DIRA
Use to set pins to input (0) or output (1).
Definition:
propeller1.h:161
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17