Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Astro
rust-card10
Commits
edb66534
Commit
edb66534
authored
Aug 22, 2019
by
Astro
⚙
Browse files
l0dable: more of the good stuff
parent
3b65a1f1
Changes
5
Hide whitespace changes
Inline
Side-by-side
l0dable/src/display.rs
View file @
edb66534
use
super
::
bindings
::
*
;
#[derive(Debug,
Clone,
Copy)]
#[repr(C)]
pub
struct
Color
(
u16
);
...
...
@@ -9,11 +10,11 @@ impl Color {
}
pub
fn
blue
()
->
Self
{
Self
::
rgb8
(
0
xff
,
0
,
0
)
Self
::
rgb8
(
0
,
0
,
0
xff
)
}
pub
fn
green
()
->
Self
{
Self
::
rgb8
(
0
xff
,
0
,
0
)
Self
::
rgb8
(
0
,
0
xff
,
0
)
}
pub
fn
black
()
->
Self
{
...
...
@@ -67,11 +68,19 @@ pub enum LineStyle {
Dotted
=
disp_linestyle_LINESTYLE_DOTTED
,
}
#[repr(u32)]
pub
enum
FillStyle
{
Empty
=
disp_fillstyle_FILLSTYLE_EMPTY
,
Filled
=
disp_fillstyle_FILLSTYLE_FILLED
,
}
pub
struct
Display
;
impl
Display
{
pub
const
W
:
u16
=
160
;
pub
const
H
:
u16
=
80
;
pub
const
FONT_W
:
u16
=
14
;
pub
const
FONT_H
:
u16
=
20
;
pub
fn
open
()
->
Self
{
unsafe
{
epic_disp_open
();
}
...
...
@@ -105,11 +114,17 @@ impl Display {
}
}
// pub fn rect(&self) {
// }
pub
fn
rect
(
&
self
,
x1
:
u16
,
y1
:
u16
,
x2
:
u16
,
y2
:
u16
,
color
:
Color
,
fillstyle
:
FillStyle
,
pixelsize
:
u16
)
{
unsafe
{
epic_disp_rect
(
x1
,
y1
,
x2
,
y2
,
color
.0
,
fillstyle
as
u32
,
pixelsize
);
}
}
// pub fn circle(&self) {
// }
pub
fn
circ
(
&
self
,
x
:
u16
,
y
:
u16
,
rad
:
u16
,
color
:
Color
,
fillstyle
:
FillStyle
,
pixelsize
:
u16
)
{
unsafe
{
epic_disp_circ
(
x
,
y
,
rad
,
color
.0
,
fillstyle
as
u32
,
pixelsize
);
}
}
}
impl
Drop
for
Display
{
...
...
l0dable/src/fmt_buffer.rs
0 → 100644
View file @
edb66534
//! Stolen from https://stackoverflow.com/questions/39488327/how-to-format-output-to-a-byte-array-with-no-std-and-no-allocator
use
core
::
fmt
;
pub
struct
FmtBuffer
<
'a
>
{
buf
:
&
'a
mut
[
u8
],
offset
:
usize
,
}
impl
<
'a
>
FmtBuffer
<
'a
>
{
pub
fn
new
(
buf
:
&
'a
mut
[
u8
])
->
Self
{
FmtBuffer
{
buf
:
buf
,
offset
:
0
,
}
}
}
impl
<
'a
>
fmt
::
Write
for
FmtBuffer
<
'a
>
{
fn
write_str
(
&
mut
self
,
s
:
&
str
)
->
fmt
::
Result
{
let
bytes
=
s
.as_bytes
();
// Skip over already-copied data
let
remainder
=
&
mut
self
.buf
[
self
.offset
..
];
// Check if there is space remaining (return error instead of panicking)
if
remainder
.len
()
<
bytes
.len
()
{
return
Err
(
core
::
fmt
::
Error
);
}
// Make the two slices the same length
let
remainder
=
&
mut
remainder
[
..
bytes
.len
()];
// Copy
remainder
.copy_from_slice
(
bytes
);
// Update offset to avoid overwriting
self
.offset
+=
bytes
.len
();
Ok
(())
}
}
l0dable/src/lib.rs
View file @
edb66534
...
...
@@ -64,7 +64,7 @@ pub mod bindings {
use
bindings
::
*
;
mod
display
;
pub
use
display
::{
Display
,
Color
,
LineStyle
};
pub
use
display
::{
Display
,
Color
,
LineStyle
,
FillStyle
};
mod
buttons
;
pub
use
buttons
::
Buttons
;
pub
mod
uart
;
...
...
@@ -72,6 +72,11 @@ pub const UART: uart::Uart = uart::Uart;
mod
light_sensor
;
pub
use
light_sensor
::
LightSensor
;
pub
mod
vibra
;
pub
mod
trng
;
mod
utime
;
pub
use
utime
::
time
;
mod
fmt_buffer
;
pub
use
fmt_buffer
::
FmtBuffer
;
pub
fn
exit
(
ret
:
i32
)
->
!
{
unsafe
{
...
...
l0dable/src/trng.rs
0 → 100644
View file @
edb66534
use
super
::
bindings
::
*
;
pub
fn
read
(
dest
:
&
mut
[
u8
])
->
bool
{
unsafe
{
epic_trng_read
(
dest
.as_mut_ptr
(),
dest
.len
())
!=
0
}
}
l0dable/src/utime.rs
0 → 100644
View file @
edb66534
use
super
::
bindings
::
*
;
pub
fn
time
()
->
u32
{
unsafe
{
epic_rtc_get_seconds
()
}
}
Write
Preview
Supports
Markdown
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