Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MiniMatrixRPi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MiniMatrixTeam
MiniMatrixRPi
Commits
db9cbe9e
Commit
db9cbe9e
authored
Feb 7, 2019
by
frey.balazs96
Browse files
Options
Downloads
Patches
Plain Diff
megy a kommunikáció meg pár animáció
parent
28a16adb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
spi_test.cpp
+125
-16
125 additions, 16 deletions
spi_test.cpp
with
125 additions
and
16 deletions
spi_test.cpp
+
125
−
16
View file @
db9cbe9e
#include
<pigpio.h>
#include
<pigpio.h>
#include
<iostream>
#include
<iostream>
#include
<unistd.h>
#include
<unistd.h>
#include
<cstring>
using
namespace
std
;
using
namespace
std
;
const
uint8_t
WIDTH
=
40
;
const
uint8_t
HEIGHT
=
13
;
class
Pixel
{
public:
Pixel
(
uint8_t
r
=
0
,
uint8_t
g
=
0
,
uint8_t
b
=
0
)
:
r
(
r
),
g
(
g
),
b
(
b
)
{}
private
:
uint8_t
r
;
uint8_t
g
;
uint8_t
b
;
};
class
Frame
{
private:
uint16_t
duration
;
Pixel
data
[
HEIGHT
][
WIDTH
];
public:
Frame
(
Pixel
data
[
HEIGHT
][
WIDTH
],
uint16_t
duration
)
{}
// : data(data), duration(duration) {}
uint8_t
*
to_spi_data
();
};
uint8_t
*
to_spi_data
()
{
uint8_t
*
spi_data
=
new
uint8_t
[
24
*
WIDTH
*
2
];
for
(
int
x
=
0
;
x
<
WIDTH
;
x
++
)
{
for
(
int
y
=
0
;
y
<
HEIGHT
;
y
++
)
{
0
;
}
}
}
uint16_t
dataRed
[
40
*
24
]
=
{
0
};
uint16_t
dataRed
[
40
*
24
]
=
{
0
};
uint16_t
dataGreen
[
40
*
24
]
=
{
0
};
uint16_t
dataGreen
[
40
*
24
]
=
{
0
};
char
dataRed2
[
40
*
24
*
2
]
=
{
0
};
uint8_t
dataRed2
[
40
*
24
*
2
]
=
{
0
};
char
dataGreen2
[
40
*
24
*
2
]
=
{
0
};
uint8_t
dataGreen2
[
40
*
24
*
2
]
=
{
0
};
char
ures
[
40
*
24
*
2
]
=
{
0
};
uint8_t
ures
[
40
*
24
*
2
+
4
]
=
{
0
};
uint8_t
teli
[
40
*
24
*
2
+
4
]
=
{
0
};
void
initData
()
void
initData
()
{
{
...
@@ -17,15 +51,9 @@ void initData()
...
@@ -17,15 +51,9 @@ void initData()
for
(
size_t
j
=
0
;
j
<
24
;
j
++
)
for
(
size_t
j
=
0
;
j
<
24
;
j
++
)
{
{
dataRed
[
24
*
i
+
j
]
=
0
;
dataRed
[
24
*
i
+
j
]
=
0
;
}
dataRed
[
24
*
i
]
=
0x0100
;
}
for
(
size_t
i
=
0
;
i
<
40
;
i
++
)
{
for
(
size_t
j
=
0
;
j
<
24
;
j
++
)
{
dataGreen
[
24
*
i
+
j
]
=
0
;
dataGreen
[
24
*
i
+
j
]
=
0
;
}
}
dataRed
[
24
*
i
]
=
0x0100
;
dataGreen
[
24
*
i
+
8
]
=
0x0100
;
dataGreen
[
24
*
i
+
8
]
=
0x0100
;
}
}
for
(
size_t
i
=
0
;
i
<
40
*
24
;
i
++
)
for
(
size_t
i
=
0
;
i
<
40
*
24
;
i
++
)
...
@@ -35,21 +63,102 @@ void initData()
...
@@ -35,21 +63,102 @@ void initData()
dataGreen2
[
2
*
i
]
=
dataGreen
[
i
]
>>
8
;
dataGreen2
[
2
*
i
]
=
dataGreen
[
i
]
>>
8
;
dataGreen2
[
2
*
i
+
1
]
=
dataGreen
[
i
];
dataGreen2
[
2
*
i
+
1
]
=
dataGreen
[
i
];
}
}
teli
[
0
]
=
0x55
;
teli
[
1
]
=
0x55
;
teli
[
2
]
=
0x00
;
teli
[
3
]
=
0x02
;
for
(
size_t
i
=
4
;
i
<
40
*
24
*
2
+
4
;
i
++
)
{
if
(
i
%
2
==
0
)
{
teli
[
i
]
=
1
;
}
}
}
uint8_t
*
addHeader
(
uint8_t
*
ptr
,
uint16_t
duration
)
{
uint8_t
*
outData
=
new
uint8_t
[
40
*
24
*
2
+
4
];
memcpy
(
outData
+
4
,
ptr
,
40
*
24
*
2
);
outData
[
0
]
=
0x55
;
outData
[
1
]
=
0x55
;
outData
[
2
]
=
duration
>>
8
;
outData
[
3
]
=
duration
;
return
outData
;
}
void
waitGPIO
()
{
int
tmp
;
usleep
(
12000
);
while
((
tmp
=
gpioRead
(
26
))
!=
1
)
{
usleep
(
1000
);
//cout << "GPIO26 = " << tmp << endl;
// usleep(000);
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
initData
();
initData
();
gpioInitialise
();
gpioInitialise
();
int
spiHandle
=
spiOpen
(
0
,
16000000
,
0b0100000000000000000000
);
gpioSetMode
(
26
,
PI_INPUT
);
uint8_t
*
outR
=
addHeader
(
dataRed2
,
1
);
uint8_t
*
outG
=
addHeader
(
dataGreen2
,
1
);
uint32_t
flags
=
(
1
<<
20
);
int
spiHandle
=
spiOpen
(
0
,
4000000
,
flags
);
if
(
spiHandle
>=
0
)
cout
<<
"SPI Opened"
<<
endl
;
if
(
spiHandle
>=
0
)
cout
<<
"SPI Opened"
<<
endl
;
char
buff
[
2
]
=
{
0
,
1
};
//ez lesz így 0x0001
char
buff
[
2
]
=
{
0
,
1
};
//ez lesz így 0x0001
while
(
1
){
spiWrite
(
spiHandle
,
dataRed2
,
40
*
24
*
2
);
cout
<<
"Reading GPIO"
<<
endl
;
usleep
(
10000
);
// while((tmp = gpioRead(26)) != 1)
spiWrite
(
spiHandle
,
dataGreen2
,
40
*
24
*
2
);
// {
usleep
(
10000
);
// cout << "GPIO26 = " << tmp << endl;
// sleep(1);
// }
// cout << "GPIO OK" << endl;
ures
[
0
]
=
0x55
;
ures
[
1
]
=
0x55
;
ures
[
2
]
=
0
;
ures
[
3
]
=
2
;
uint32_t
tmp
=
4
;
// ures[40*24*2+3] = 0x55;
int
mode
=
1
;
while
(
1
)
{
spiWrite
(
spiHandle
,
(
char
*
)
ures
,
40
*
24
*
2
+
4
);
waitGPIO
();
spiWrite
(
spiHandle
,
(
char
*
)
teli
,
40
*
24
*
2
+
4
);
waitGPIO
();
ures
[
tmp
]
=
mode
;
tmp
+=
2
;
tmp
+=
2
;
tmp
+=
2
;
tmp
+=
2
;
if
(
tmp
>=
40
*
24
*
2
)
{
tmp
=
4
;
mode
=
(
mode
+
1
)
%
2
;
}
}
}
int
cnt
=
0
;
for
(
size_t
i
=
0
;
i
<
40
*
24
*
2
+
4
;
i
++
)
{
if
(
outR
[
i
]
==
1
)
cnt
++
;
}
cout
<<
cnt
<<
endl
;
// spiWrite(spiHandle, outG, 40*24*2 + 4);
// usleep(10000);
delete
outR
;
delete
outG
;
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment