Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mensactrl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
stratum0
mensactrl
Commits
dbc298e9
Commit
dbc298e9
authored
10 years ago
by
daniel
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
eb36cf8e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
mensa-control.c
+0
-8
0 additions, 8 deletions
mensa-control.c
src/Makefile.am
+5
-5
5 additions, 5 deletions
src/Makefile.am
src/mensactrl.c
+51
-63
51 additions, 63 deletions
src/mensactrl.c
src/mensaserv.c
+47
-56
47 additions, 56 deletions
src/mensaserv.c
with
103 additions
and
132 deletions
mensa-control.c
deleted
100644 → 0
+
0
−
8
View file @
eb36cf8e
#include
<stdio.h>
int
main
(
void
)
{
printf
(
"hello fish!
\n
"
);
return
0
;
}
This diff is collapsed.
Click to expand it.
src/Makefile.am
+
5
−
5
View file @
dbc298e9
bin_PROGRAMS
=
\
mensa
-
ctrl mensa
-
serv
mensactrl mensaserv
AM_CPPFLAGS
=
\
-I
$(
top_srcdir
)
/include
\
...
...
@@ -9,15 +9,15 @@ AM_CPPFLAGS = \
#
# binary
#
led
ctrl_SOURCES
=
\
mensa
ctrl_SOURCES
=
\
mensactrl.c
led
ctrl_LDADD
=
\
mensa
ctrl_LDADD
=
\
$(
ZMQ_LIBS
)
led
serv_SOURCES
=
\
mensa
serv_SOURCES
=
\
mensaserv.c
led
serv_LDADD
=
\
mensa
serv_LDADD
=
\
$(
ZMQ_LIBS
)
This diff is collapsed.
Click to expand it.
src/mensactrl.c
+
51
−
63
View file @
dbc298e9
/*
* Control
WS281X LEDs
connected to the LCDIF
* Control
Mensadisplay
connected to the LCDIF
*
* Code taken from the proof-of-concept tool by
* (C) 2013 Jeroen Domburg (jeroen AT spritesmods.com)
* (C) 2014 Daniel Willmann <daniel@totalueberwachung.de>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
...
...
@@ -33,98 +32,87 @@
#include
<zmq.h>
struct
pixel
{
uint16_t
x
,
y
;
uint8_t
r
,
g
,
b
;
}
__attribute__
((
packed
));
#include
"common.h"
struct
ws281x
_fb
{
struct
mensa
_fb
{
int
x_res
,
y_res
;
int
fd
;
uint8_t
*
inputfb
;
uint16_t
*
fbmem
;
};
//This will encode a framebuffer with per-led RGB values into the weird framebuffer
//data values we need to form the correct WS2811 driving waveform.
void
encodeToFb
(
struct
ws281x_fb
*
wsfb
)
{
int
pix
,
col
,
bit
,
bitmask
,
strip
,
n
;
int
p
=
0
;
for
(
pix
=
0
;
pix
<
wsfb
->
x_res
;
pix
++
)
{
//STRIPLEN points...
for
(
col
=
0
;
col
<
3
;
col
++
)
{
//...of 3 bytes (r, g. b)
bitmask
=
0x80
;
for
(
bit
=
0
;
bit
<
8
;
bit
++
)
{
//...of 8 bits each.
/* At 4MHz, a bit has 5 cycles. For an 1, it's high 4, low one. For an 0, it's high one, low 4. */
p
++
;
/* First cycle is always 1 */
n
=
0
;
//Iterate through every LED-strip to fetch the bit it needs to send out. Combine those
//in n.
for
(
strip
=
0
;
strip
<
wsfb
->
y_res
;
strip
++
)
{
if
(
wsfb
->
inputfb
[(
wsfb
->
x_res
*
strip
*
3
)
+
(
pix
*
3
)
+
col
]
&
bitmask
)
n
|=
1
<<
strip
;
}
wsfb
->
fbmem
[
p
++
]
=
n
;
wsfb
->
fbmem
[
p
++
]
=
n
;
//Middle 3 are dependent on bit value
wsfb
->
fbmem
[
p
++
]
=
n
;
p
++
;
/* Last cycle is always 0 */
bitmask
>>=
1
;
//next bit in byte
}
void
encodeToFb
(
struct
mensa_fb
*
mensafb
)
{
int
pix
,
row
,
idx
;
uint16_t
pattern
;
for
(
row
=
0
;
row
<
mensafb
->
y_res
;
row
++
)
{
for
(
pix
=
0
;
pix
<
mensafb
->
x_res
;
pix
++
)
{
idx
=
row
*
mensafb
->
x_res
+
pix
;
if
(
mensafb
->
inputfb
[
idx
]
>
0
)
pattern
=
1
;
else
pattern
=
0
;
pattern
|=
row
<<
13
;
mensafb
->
fbmem
[
idx
]
=
pattern
;
}
}
}
//Helper function to set the value of a single pixel in the 'framebuffer'
//of LED pixel values.
void
setPixel
(
struct
ws281x_fb
*
wsfb
,
int
pixel
,
int
strip
,
int
r
,
int
g
,
int
b
)
{
int
pos
=
(
strip
*
wsfb
->
x_res
*
3
)
+
pixel
*
3
;
if
(
strip
<
0
||
strip
>=
wsfb
->
x_res
)
return
;
if
(
pixel
<
0
||
pixel
>=
wsfb
->
y_res
)
return
;
wsfb
->
inputfb
[
pos
++
]
=
r
;
//My strips have R and G switched.
wsfb
->
inputfb
[
pos
++
]
=
g
;
wsfb
->
inputfb
[
pos
++
]
=
b
;
void
setPixel
(
struct
mensa_fb
*
mensafb
,
int
col
,
int
row
,
uint8_t
bright
)
{
int
idx
=
row
*
mensafb
->
x_res
+
col
;
if
(
col
<
0
||
col
>=
mensafb
->
x_res
)
return
;
if
(
row
<
0
||
row
>=
mensafb
->
y_res
)
return
;
mensafb
->
inputfb
[
idx
]
=
bright
;
}
static
struct
ws281x
_fb
*
setup_fb
(
const
char
*
devname
,
int
x
,
int
y
)
static
struct
mensa
_fb
*
setup_fb
(
const
char
*
devname
,
int
x
,
int
y
)
{
struct
ws281x_fb
*
ws
fb
=
malloc
(
sizeof
(
struct
ws281x
_fb
));
struct
mensa_fb
*
mensa
fb
=
malloc
(
sizeof
(
struct
mensa
_fb
));
int
i
;
ws
fb
->
fd
=
open
(
devname
,
O_RDWR
);
if
(
ws
fb
->
fd
<
0
)
{
mensa
fb
->
fd
=
open
(
devname
,
O_RDWR
);
if
(
mensa
fb
->
fd
<
0
)
{
perror
(
"opening fb"
);
free
(
ws
fb
);
free
(
mensa
fb
);
exit
(
1
);
}
ws
fb
->
inputfb
=
malloc
(
x
*
y
*
3
);
if
(
!
ws
fb
->
inputfb
)
{
free
(
ws
fb
);
mensa
fb
->
inputfb
=
malloc
(
x
*
y
*
3
);
if
(
!
mensa
fb
->
inputfb
)
{
free
(
mensa
fb
);
exit
(
1
);
}
memset
(
ws
fb
->
inputfb
,
0
,
x
*
y
*
3
);
memset
(
mensa
fb
->
inputfb
,
0
,
x
*
y
*
3
);
ws
fb
->
fbmem
=
mmap
(
NULL
,
x
*
5
*
24
*
2
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
ws
fb
->
fd
,
0
);
if
(
ws
fb
->
fbmem
==
NULL
)
{
mensa
fb
->
fbmem
=
mmap
(
NULL
,
x
*
5
*
24
*
2
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
mensa
fb
->
fd
,
0
);
if
(
mensa
fb
->
fbmem
==
NULL
)
{
perror
(
"mmap'ing fb"
);
free
(
ws
fb
->
inputfb
);
free
(
ws
fb
);
free
(
mensa
fb
->
inputfb
);
free
(
mensa
fb
);
exit
(
1
);
}
for
(
i
=
0
;
i
<
x
*
y
*
5
*
24
;
i
++
)
{
/* Init frame buffer bit clock. */
if
(
i
%
5
==
0
)
ws
fb
->
fbmem
[
i
]
=
0xffff
;
mensa
fb
->
fbmem
[
i
]
=
0xffff
;
if
(
i
%
5
==
4
)
ws
fb
->
fbmem
[
i
]
=
0x00
;
mensa
fb
->
fbmem
[
i
]
=
0x00
;
}
ws
fb
->
x_res
=
x
;
ws
fb
->
y_res
=
y
;
mensa
fb
->
x_res
=
x
;
mensa
fb
->
y_res
=
y
;
return
ws
fb
;
return
mensa
fb
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
struct
ws281x_fb
*
ws
fb
;
struct
mensa_fb
*
mensa
fb
;
void
*
context
=
zmq_ctx_new
();
void
*
subscriber
=
zmq_socket
(
context
,
ZMQ_SUB
);
int
rc
;
...
...
@@ -141,14 +129,14 @@ int main(int argc, char *argv[]) {
if
(
rc
<
0
)
perror
(
"zmq_connect"
);
ws
fb
=
setup_fb
(
argv
[
1
],
1
0
,
2
);
mensa
fb
=
setup_fb
(
argv
[
1
],
4
0
,
7
);
while
(
1
)
{
struct
pixel
pix
;
zmq_recv
(
subscriber
,
&
pix
,
sizeof
(
pix
),
0
);
printf
(
"(%u, %u):
r=%02x g=%02x b
=%02x
\n
"
,
pix
.
x
,
pix
.
y
,
pix
.
r
,
pix
.
g
,
pix
.
b
);
setPixel
(
ws
fb
,
pix
.
x
,
pix
.
y
,
pix
.
r
,
pix
.
g
,
pix
.
b
);
encodeToFb
(
ws
fb
);
printf
(
"(%u, %u):
bright
=%02x
\n
"
,
pix
.
x
,
pix
.
y
,
pix
.
bright
);
setPixel
(
mensa
fb
,
pix
.
x
,
pix
.
y
,
pix
.
bright
);
encodeToFb
(
mensa
fb
);
}
return
0
;
...
...
This diff is collapsed.
Click to expand it.
src/mensaserv.c
+
47
−
56
View file @
dbc298e9
/*
* Control
WS281X LEDs
connected to the LCDIF
* Control
the Mensadisplay
connected to the LCDIF
*
* Code taken from the proof-of-concept tool by
* (C) 2013 Jeroen Domburg (jeroen AT spritesmods.com)
* (C) 2014 Daniel Willmann <daniel@totalueberwachung.de>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
...
...
@@ -33,63 +32,55 @@
#include
<zmq.h>
struct
pixel
{
uint16_t
x
,
y
;
uint8_t
r
,
g
,
b
;
}
__attribute__
((
packed
));
#include
"common.h"
/*
* Layout:
*
* Connector on the Individual boards
* ______
* | 1 2|
* |_3 4|
* |5 6|
* |~7 8|
* | 9 10|
* ~~~~~~
*
* Pinout
* Display iMX233 Function
*
* 1: NC
* 2: SIN/OUT LCD0-4 Data in for the shift regs
* 3: SCK LCDCLK Clock (rising edge)
* 4: GND GND
* 5: A0 LCD13 Address for the line to drive (LSB)
* 6: A1 LCD14 Possible values: 0-6 for lines 1-7
* 7: A2 LCD15 Address for line MSB
* 8: /G GND Global Display /Enable
* 9: VCC +5V
* 10: RCK EN Strobe to latch data into the output
*
* 1: Keep /G low
* 2: Write data via SIN und SCK into the shift regs
* 3: Select row through A0-A2
* 4: Update LED outputs with RCK
* 5: Goto 2
*/
static
void
fade
(
void
*
publisher
)
{
struct
pixel
pix1
=
{
.
x
=
0
,
.
y
=
0
,
.
r
=
0
,
.
g
=
0
,
.
b
=
0
};
struct
pixel
pix2
=
{
.
x
=
1
,
.
y
=
0
,
.
r
=
0
,
.
g
=
0
,
.
b
=
0
};
struct
pixel
pix3
=
{
.
x
=
2
,
.
y
=
0
,
.
r
=
0
,
.
g
=
0
,
.
b
=
0
};
int
state
=
0
;
int
i
=
0
;
struct
pixel
pix
;
while
(
1
)
{
switch
(
state
)
{
case
0
:
pix1
.
r
++
;
pix2
.
g
++
;
pix3
.
b
++
;
if
(
pix1
.
r
==
255
)
state
++
;
break
;
case
1
:
pix1
.
r
--
;
pix1
.
g
++
;
pix2
.
g
--
;
pix2
.
b
++
;
pix3
.
b
--
;
pix3
.
r
++
;
if
(
pix1
.
g
==
255
)
state
++
;
break
;
case
2
:
pix1
.
g
--
;
pix1
.
b
++
;
pix2
.
b
--
;
pix2
.
r
++
;
pix3
.
r
--
;
pix3
.
g
++
;
if
(
pix1
.
b
==
255
)
state
++
;
break
;
case
3
:
pix1
.
b
--
;
pix1
.
r
++
;
pix2
.
r
--
;
pix2
.
g
++
;
pix3
.
g
--
;
pix3
.
b
++
;
if
(
pix1
.
r
==
255
)
state
=
1
;
break
;
}
zmq_send
(
publisher
,
&
pix1
,
sizeof
(
pix1
),
0
);
printf
(
"(%u, %u): r=%02x g=%02x b=%02x
\n
"
,
pix1
.
x
,
pix1
.
y
,
pix1
.
r
,
pix1
.
g
,
pix1
.
b
);
//zmq_send(publisher, &pix2, sizeof(pix2), 0);
//printf("(%u, %u): r=%02x g=%02x b=%02x\n", pix2.x, pix2.y, pix2.r, pix2.g, pix2.b);
//zmq_send(publisher, &pix3, sizeof(pix3), 0);
//printf("(%u, %u): r=%02x g=%02x b=%02x\n", pix3.x, pix3.y, pix3.r, pix3.g, pix3.b);
pix
.
x
=
i
/
7
;
pix
.
y
=
i
%
7
;
pix
.
bright
=
0
;
zmq_send
(
publisher
,
&
pix
,
sizeof
(
pix
),
0
);
i
=
(
i
+
1
)
%
(
7
*
20
);
pix
.
bright
=
255
;
zmq_send
(
publisher
,
&
pix
,
sizeof
(
pix
),
0
);
printf
(
"(%u, %u): bright=%02x
\n
"
,
pix
.
x
,
pix
.
y
,
pix
.
bright
);
usleep
(
10000
);
}
}
...
...
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