Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
companion-software
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CATS
companion-software
Commits
be6b345e
Commit
be6b345e
authored
1 year ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
keyboard
parent
0a30e7db
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/keyboard.rs
+40
-0
40 additions, 0 deletions
src/keyboard.rs
src/main.rs
+33
-3
33 additions, 3 deletions
src/main.rs
with
73 additions
and
3 deletions
src/keyboard.rs
0 → 100644
+
40
−
0
View file @
be6b345e
use
embedded_hal
::
digital
::
v2
::{
InputPin
,
OutputPin
};
use
rp2040_hal
::
gpio
::{
DynPinId
,
FunctionSio
,
Pin
,
PullUp
,
SioInput
};
use
shift_register_driver
::
sipo
::
ShiftRegisterPin
;
pub
struct
Keyboard
{
cols
:
[
ShiftRegisterPin
<
'static
>
;
7
],
rows
:
[
Pin
<
DynPinId
,
FunctionSio
<
SioInput
>
,
PullUp
>
;
7
],
}
impl
Keyboard
{
pub
fn
new
(
mut
cols
:
[
ShiftRegisterPin
<
'static
>
;
7
],
rows
:
[
Pin
<
DynPinId
,
FunctionSio
<
SioInput
>
,
PullUp
>
;
7
],
)
->
Self
{
for
c
in
&
mut
cols
{
c
.set_high
()
.unwrap
();
}
Self
{
cols
,
rows
}
}
pub
fn
read_state
(
&
mut
self
)
->
u64
{
let
mut
out
=
0
;
for
(
x
,
c
)
in
self
.cols
.iter_mut
()
.enumerate
()
{
c
.set_low
()
.unwrap
();
// TODO we might need a delay in here
for
(
y
,
r
)
in
self
.rows
.iter_mut
()
.enumerate
()
{
if
r
.is_low
()
.unwrap
()
{
out
|
=
1
<<
(
x
*
7
+
y
);
}
}
c
.set_high
()
.unwrap
();
}
out
}
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
33
−
3
View file @
be6b345e
#![no_std]
#![no_std]
#![no_main]
#![no_main]
mod
keyboard
;
#[rtic::app(
#[rtic::app(
device
=
rp2040_hal::pac,
device
=
rp2040_hal::pac,
dispatchers
=
[
TIMER_IRQ_1]
dispatchers
=
[
TIMER_IRQ_1]
)]
)]
mod
app
{
mod
app
{
use
crate
::
keyboard
::
Keyboard
;
use
cortex_m
::
delay
::
Delay
;
use
cortex_m
::
delay
::
Delay
;
use
display_interface_spi
::
SPIInterfaceNoCS
;
use
display_interface_spi
::
SPIInterfaceNoCS
;
use
embedded_graphics
::{
use
embedded_graphics
::{
...
@@ -19,7 +22,13 @@ mod app {
...
@@ -19,7 +22,13 @@ mod app {
};
};
use
embedded_hal
::
PwmPin
;
use
embedded_hal
::
PwmPin
;
use
fugit
::
RateExtU32
;
use
fugit
::
RateExtU32
;
use
hal
::
Clock
;
use
hal
::{
gpio
::{
bank0
::{
Gpio0
,
Gpio1
,
Gpio2
},
DynPinId
,
FunctionSio
,
Pin
,
PullDown
,
PullUp
,
SioInput
,
SioOutput
,
},
Clock
,
};
use
mipidsi
::
Builder
;
use
mipidsi
::
Builder
;
use
panic_probe
as
_
;
use
panic_probe
as
_
;
use
rp2040_hal
as
hal
;
use
rp2040_hal
as
hal
;
...
@@ -28,6 +37,12 @@ mod app {
...
@@ -28,6 +37,12 @@ mod app {
const
XTAL_FREQ_HZ
:
u32
=
12_000_000u32
;
const
XTAL_FREQ_HZ
:
u32
=
12_000_000u32
;
type
MyShiftRegister
=
ShiftRegister16
<
Pin
<
Gpio1
,
FunctionSio
<
SioOutput
>
,
PullDown
>
,
Pin
<
Gpio2
,
FunctionSio
<
SioOutput
>
,
PullDown
>
,
Pin
<
Gpio0
,
FunctionSio
<
SioOutput
>
,
PullDown
>
,
>
;
#[shared]
#[shared]
struct
Shared
{}
struct
Shared
{}
...
@@ -77,11 +92,26 @@ mod app {
...
@@ -77,11 +92,26 @@ mod app {
let
sr_clk
=
pins
.gpio1
.into_push_pull_output
();
let
sr_clk
=
pins
.gpio1
.into_push_pull_output
();
let
sr_ser
=
pins
.gpio0
.into_push_pull_output
();
let
sr_ser
=
pins
.gpio0
.into_push_pull_output
();
let
sr_rclk
=
pins
.gpio2
.into_push_pull_output
();
let
sr_rclk
=
pins
.gpio2
.into_push_pull_output
();
let
sr
=
ShiftRegister16
::
new
(
sr_clk
,
sr_rclk
,
sr_ser
);
let
sr
=
cortex_m
::
singleton!
(:
MyShiftRegister
=
ShiftRegister16
::
new
(
sr_clk
,
sr_rclk
,
sr_ser
))
.unwrap
();
let
sr_pins
=
sr
.decompose
();
let
sr_pins
=
sr
.decompose
();
let
[
_led_b
,
_led_g
,
_led_r
,
_tp_reset
,
disp_reset
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
]
=
let
[
_led_b
,
_led_g
,
_led_r
,
_tp_reset
,
disp_reset
,
_
,
_
,
_
,
col1
,
col2
,
col3
,
col4
,
col5
,
col6
,
col7
,
_unused
]
=
sr_pins
;
sr_pins
;
// Keyboard
let
cols
=
[
col1
,
col2
,
col3
,
col4
,
col5
,
col6
,
col7
];
let
rows
:
[
Pin
<
DynPinId
,
FunctionSio
<
SioInput
>
,
PullUp
>
;
7
]
=
[
pins
.gpio9
.into_pull_up_input
()
.into_dyn_pin
(),
pins
.gpio8
.into_pull_up_input
()
.into_dyn_pin
(),
pins
.gpio7
.into_pull_up_input
()
.into_dyn_pin
(),
pins
.gpio6
.into_pull_up_input
()
.into_dyn_pin
(),
pins
.gpio5
.into_pull_up_input
()
.into_dyn_pin
(),
pins
.gpio4
.into_pull_up_input
()
.into_dyn_pin
(),
pins
.gpio3
.into_pull_up_input
()
.into_dyn_pin
(),
];
let
keyboard
=
Keyboard
::
new
(
cols
,
rows
);
// SPI Display
// SPI Display
let
display_cs
=
pins
.gpio16
.into_push_pull_output
();
let
display_cs
=
pins
.gpio16
.into_push_pull_output
();
let
spi_mosi
=
pins
.gpio15.into_function
::
<
hal
::
gpio
::
FunctionSpi
>
();
let
spi_mosi
=
pins
.gpio15.into_function
::
<
hal
::
gpio
::
FunctionSpi
>
();
...
...
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