Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
fwatch
Commits
60d149a2
Commit
60d149a2
authored
Jul 28, 2014
by
Projects
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Groundwork for DMA transfers in LCD driver.
parent
1f88c062
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
11 deletions
+59
-11
lcd.c
sw/common/drivers/lcd.c
+59
-11
No files found.
sw/common/drivers/lcd.c
View file @
60d149a2
...
...
@@ -30,8 +30,20 @@
#include <em_rtc.h>
#include <udelay.h>
#define LCD_NODMA
// Additional bytes to control the LCD; required for DMA transfers
#ifdef LCD_NODMA
#define CONTROL_BYTES 0
#else
#define CONTROL_BYTES 2
#endif
// Number of bytes to store one line
#define LCD_STRIDE (LCD_WIDTH / 8 + CONTROL_BYTES)
// Framebuffer - pixels are stored as consecutive rows
static
uint8_t
buffer
[
LCD_
WIDTH
/
8
*
LCD_HEIGHT
];
static
uint8_t
buffer
[
LCD_
STRIDE
*
LCD_HEIGHT
];
static
void
spi_init
(
void
)
{
...
...
@@ -44,7 +56,7 @@ static void spi_init(void)
LCD_SPI_UNIT
->
ROUTE
=
(
USART_ROUTE_CLKPEN
|
USART_ROUTE_TXPEN
|
LCD_SPI_LOCATION
);
}
static
void
spi_transmit
(
uint8_t
*
data
,
uint
8
_t
length
)
static
void
spi_transmit
(
uint8_t
*
data
,
uint
16
_t
length
)
{
while
(
length
>
0
)
{
...
...
@@ -155,11 +167,29 @@ void lcd_power(uint8_t enable)
void
lcd_clear
(
void
)
{
uint16_t
cmd
,
i
;
uint16_t
cmd
;
uint8_t
*
p
=
buffer
;
#ifdef LCD_NODMA
uint16_t
i
;
// Clear pixel buffer
for
(
i
=
0
;
i
<
sizeof
(
buffer
);
++
i
)
buffer
[
i
]
=
0x00
;
*
p
++
=
0x00
;
#else
uint8_t
x
,
y
;
for
(
y
=
0
;
y
<
LCD_HEIGHT
;
++
y
)
{
// Clear framebuffer
for
(
x
=
0
;
x
<
LCD_WIDTH
/
8
;
++
x
)
*
p
++
=
0x00
;
// Add control codes
*
p
++
=
0xff
;
// Dummy
*
p
++
=
(
y
+
2
);
// Address of next line
}
#endif
// Send command to clear the display
GPIO_PinOutSet
(
LCD_PORT_SCS
,
LCD_PIN_SCS
);
...
...
@@ -180,7 +210,7 @@ void lcd_update(void)
// TODO use DMA
uint16_t
cmd
;
uint
8
_t
i
;
uint
16
_t
i
;
uint8_t
*
p
=
(
uint8_t
*
)
buffer
;
GPIO_PinOutSet
(
LCD_PORT_SCS
,
LCD_PIN_SCS
);
...
...
@@ -190,6 +220,7 @@ void lcd_update(void)
cmd
=
LCD_CMD_UPDATE
|
(
START_ROW
<<
8
);
spi_transmit
((
uint8_t
*
)
&
cmd
,
2
);
#ifdef LCD_NODMA
for
(
i
=
0
;
i
<
LCD_HEIGHT
;
++
i
)
{
// Send pixels for this line
...
...
@@ -204,6 +235,14 @@ void lcd_update(void)
spi_transmit
((
uint8_t
*
)
&
cmd
,
2
);
}
#else
spi_transmit
(
p
,
LCD_STRIDE
*
LCD_HEIGHT
);
/*for(i = 0; i < LCD_STRIDE * LCD_HEIGHT / 2; i += 2)
{
spi_transmit(p, 2);
p += 2;
}*/
#endif
timer_delay
(
2
);
GPIO_PinOutClear
(
LCD_PORT_SCS
,
LCD_PIN_SCS
);
...
...
@@ -211,8 +250,11 @@ void lcd_update(void)
void
lcd_set_pixel
(
uint8_t
x
,
uint8_t
y
,
uint8_t
value
)
{
uint8_t
mask
=
1
<<
(
x
&
0x07
);
// == 1 << (x % 8)
uint16_t
offset
=
(
y
*
LCD_WIDTH
>>
3
)
+
(
x
>>
3
);
// == (y * LCD_WIDTH / 8) + x / 8
x
%=
LCD_WIDTH
;
y
%=
LCD_HEIGHT
;
uint8_t
mask
=
1
<<
(
x
&
0x07
);
// == 1 << (x % 8)
uint16_t
offset
=
(
y
*
LCD_STRIDE
)
+
(
x
>>
3
);
// == y * LCD_STRIDE + x / 8
if
(
value
)
buffer
[
offset
]
|=
mask
;
...
...
@@ -222,16 +264,22 @@ void lcd_set_pixel(uint8_t x, uint8_t y, uint8_t value)
void
lcd_toggle_pixel
(
uint8_t
x
,
uint8_t
y
)
{
uint8_t
mask
=
1
<<
(
x
&
0x07
);
// == 1 << (x % 8)
uint16_t
offset
=
(
y
*
LCD_WIDTH
>>
3
)
+
(
x
>>
3
);
// == (y * LCD_WIDTH / 8) + x / 8
x
%=
LCD_WIDTH
;
y
%=
LCD_HEIGHT
;
uint8_t
mask
=
1
<<
(
x
&
0x07
);
// == 1 << (x % 8)
uint16_t
offset
=
(
y
*
LCD_STRIDE
)
+
(
x
>>
3
);
// == y * LCD_STRIDE + x / 8
buffer
[
offset
]
^=
mask
;
}
uint8_t
lcd_get_pixel
(
uint8_t
x
,
uint8_t
y
)
{
uint8_t
mask
=
1
<<
(
x
&
0x07
);
// == 1 << (x % 8)
uint16_t
offset
=
(
y
*
LCD_WIDTH
>>
3
)
+
(
x
>>
3
);
// == (y * LCD_WIDTH / 8) + x / 8
x
%=
LCD_WIDTH
;
y
%=
LCD_HEIGHT
;
uint8_t
mask
=
1
<<
(
x
&
0x07
);
// == 1 << (x % 8)
uint16_t
offset
=
(
y
*
LCD_STRIDE
)
+
(
x
>>
3
);
// == y * LCD_STRIDE + x / 8
return
buffer
[
offset
]
&
mask
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment