File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed
Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ extern "C" {
77#include " core/m3x6_16pt.h"
88#include " fbcon.h"
99#include " fractal.h"
10- #include " gpio.h"
1110#include " lcd.h"
1211#include " lowrisc_logo.h"
1312#include " sonata_system.h"
@@ -19,6 +18,7 @@ int coremark_main();
1918
2019#include " spi.hh"
2120#include " pwm.hh"
21+ #include " gpio.hh"
2222#include " platform.hh"
2323
2424#define SIMULATION 0
@@ -62,9 +62,10 @@ static void timer_delay(uint32_t ms) {
6262}
6363
6464static Buttons_t scan_buttons (uint32_t timeout) {
65+ Gpio gpio (platform::Gpio::Gpio0);
6566 while (true ) {
6667 // Sample navigation buttons (debounced).
67- uint32_t in_val = read_gpio (GPIO_IN_DBNC ) & (0x1f << 8 );
68+ uint32_t in_val = gpio. read_debounce ( ) & (0x1f << 8 );
6869 if (in_val == 0 ) {
6970 // No button pressed, so delay for 20ms and then try again, unless the timeout is reached.
7071 const uint32_t poll_delay = 20 ;
@@ -81,7 +82,7 @@ static Buttons_t scan_buttons(uint32_t timeout) {
8182
8283 // Some button pressed.
8384 // Wait until the button is released to avoid an event being triggered multiple times.
84- while (read_gpio (GPIO_IN_DBNC ) & in_val);
85+ while (gpio. read_debounce ( ) & in_val);
8586
8687 return static_cast <Buttons_t>(in_val);
8788 }
Original file line number Diff line number Diff line change 1+ // Copyright lowRISC contributors.
2+ // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+ // SPDX-License-Identifier: Apache-2.0
4+
5+ #pragma once
6+
7+ #include " mmio/gpio.hh"
8+ #include " platform.hh"
9+
10+ class Gpio {
11+ const platform::Gpio base_addr;
12+
13+ public:
14+ constexpr Gpio (platform::Gpio base_addr) : base_addr(base_addr) {}
15+
16+ void write (uint32_t pins) {
17+ mmio::gpio::Gpio gpio (base_addr);
18+ gpio.out .pins .write (pins).commit ();
19+ }
20+
21+ uint32_t read () {
22+ mmio::gpio::Gpio gpio (base_addr);
23+ return gpio.in .fetch ().pins .get ();
24+ }
25+
26+ uint32_t read_debounce () {
27+ mmio::gpio::Gpio gpio (base_addr);
28+ return gpio.in_dbnc .fetch ().value .get ();
29+ }
30+ };
You can’t perform that action at this time.
0 commit comments