1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: GPL-3.0-or-later
/* 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//! Support the display and keyboard on the M5Stack Card Computer.
//!
//! # Usage
//! Create a new instance of [`display::Display`] and simply use it as an
//! [`embedded_graphics::draw_target::DrawTarget`].
//! Also create an instance of [`keyboard::Keyboard`] and use the [`get_keys`](keyboard::Keyboard::get_keys) method for accessing the
//! individual keys on the keyboard.
//!
//! # Example
//! ```
//! use esp_idf_svc::hal::{gpio::*, spi::*, units::*};
//! use embedded_graphics::{prelude::*, pixelcolor::Rgb565};
//! use m5cardputer::{display::Display, keyboard::Keyboard};
//! // Take ownership of peripherals
//! let dp = Peripherals::take().unwrap();
//!
//! // Set up SPI driver
//! let input_pin: Option<AnyIOPin> = None;
//! let lcd_spi_drv = SpiDriver::new(dp.spi2, dp.pins.gpio36, dp.pins.gpio35, input_pin, &SpiDriverConfig::default()).unwrap();
//! let config = config::Config::new().data_mode(config::MODE_0).baudrate(MegaHertz(80).into()).write_only(true);
//! let lcd_spi = SpiDeviceDriver::new(lcd_spi_drv, Some(dp.pins.gpio37), &config).unwrap();
//!
//! let mut disp = Display::new(lcd_spi, dp.pins.gpio34, dp.pins.gpio33, dp.pins.gpio38, dp.ledc.timer3, dp.ledc.channel7).unwrap();
//! disp.set_brightness(150).unwrap();
//! disp.clear(Rgb565::BLACK);
//!
//! // Construct keyboard
//! let row_pins = (
//! dp.pins.gpio13,
//! dp.pins.gpio15,
//! dp.pins.gpio3,
//! dp.pins.gpio4,
//! dp.pins.gpio5,
//! dp.pins.gpio6,
//! dp.pins.gpio7
//! );
//! let address_pins = (
//! dp.pins.gpio8,
//! dp.pins.gpio9,
//! dp.pins.gpio11
//! );
//! let keyboard = Keyboard::new(row_pins, address_pins).unwrap();
//! let keys = keyboard.get_keys();
//! for key in keys {
//! println!("{}", key);
//! }
//! ```
extern crate keypad;