Skip to content

Commit cbc40dd

Browse files
Update compatibility with newer dependencies (#1)
* Update version * Display works, touch not * Driver working * Use better config for the display
1 parent 3e8383a commit cbc40dd

6 files changed

Lines changed: 50 additions & 54 deletions

File tree

.cargo/config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[target.thumbv7em-none-eabihf]
22
# runner = 'arm-none-eabi-gdb -q -x .gdbinit'
3-
# runner = "arm-none-eabi-gdb -q -x openocd.gdb"
4-
runner = "arm-none-eabi-gdb -q -x segger.gdb"
3+
runner = "arm-none-eabi-gdb -x openocd.gdb -q"
4+
#runner = "arm-none-eabi-gdb -q -x segger.gdb"
55

66
rustflags = [
77
"-C", "link-arg=-Tlink.x",

.embed.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[probe]
2+
protocol = "Swd"
3+
4+
[flashing]
5+
enabled = true
6+
restore_unwritten_bytes = false
7+
8+
[general]
9+
chip = "nrf52832_xxAA"

Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ readme = "README.md"
2121

2222
[dependencies]
2323
cortex-m = "0.6.2"
24-
embedded-hal = {version ="0.2.3", features = ["unproven"] }
25-
24+
embedded-hal = "0.2.3"
2625

2726
[dev-dependencies]
2827
cortex-m-rt = "0.6.12"
29-
nrf52832-hal = {version = "0.8.1", default-features = false, features = ["xxAA-package", "rt"]}
30-
panic-rtt-core = {version="0.1.0"}
31-
st7789 = { git = "https://github.com/tstellanova/st7789" }
28+
cortex-m-semihosting = "0.3.5"
29+
nrf52832-hal = { version = "0.10", default-features = false, features = ["xxAA-package", "rt"] }
30+
panic-halt = "0.2.0"
31+
st7789 = { version = "0.5.0", features = ["graphics", "batch", "buffer"], default-features = false }
32+
display-interface = "0.4.0"
33+
display-interface-spi = "0.4.0"
3234
shared-bus = {version = "0.1.4", features = ["cortexm"] }
33-
embedded-graphics = "0.6.0"
35+
embedded-graphics = "0.6.2"

examples/touchpad.rs

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
#![no_std]
22
#![no_main]
33

4-
use panic_rtt_core::{self, rtt_init_print, rprintln};
4+
extern crate cortex_m_rt as rt;
5+
extern crate nrf52832_hal;
6+
extern crate panic_halt;
57

6-
use nrf52832_hal as p_hal;
7-
use p_hal::gpio::{GpioExt, Level};
8-
use p_hal::nrf52832_pac as pac;
9-
use p_hal::{delay::Delay, rng::RngExt, spim, twim};
8+
use nrf52832_hal::gpio::p0::Parts;
9+
use nrf52832_hal::{self as hal, gpio::Level, pac, spim, twim, Delay, Rng};
1010

11-
use cortex_m_rt as rt;
11+
use cortex_m_rt::entry;
12+
use cortex_m_semihosting::hprintln;
1213
use cst816s::{TouchEvent, TouchGesture, CST816S};
14+
use display_interface_spi::SPIInterfaceNoCS;
1315
use embedded_graphics::pixelcolor::{raw::RawU16, Rgb565};
1416
use embedded_graphics::{prelude::*, primitives::*, style::*};
1517
use embedded_hal::digital::v2::OutputPin;
16-
use rt::entry;
17-
use st7789::Orientation;
18+
use st7789::{Orientation, ST7789};
1819

19-
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
20-
use nrf52832_hal::prelude::ClocksExt;
21-
22-
pub type HalSpimError = p_hal::spim::Error;
23-
24-
pub type Spim0PortType = p_hal::spim::Spim<pac::SPIM0>;
25-
pub type DisplaySckPinType = p_hal::gpio::p0::P0_18<p_hal::gpio::Output<p_hal::gpio::PushPull>>;
26-
pub type DisplayMosiPinType = p_hal::gpio::p0::P0_26<p_hal::gpio::Output<p_hal::gpio::PushPull>>;
20+
use embedded_hal::blocking::delay::DelayUs;
2721

2822
const SCREEN_WIDTH: i32 = 240;
2923
const SCREEN_HEIGHT: i32 = 240;
@@ -36,26 +30,25 @@ const SCREEN_RADIUS: u32 = (MIN_SCREEN_DIM / 2) as u32;
3630
///
3731
#[entry]
3832
fn main() -> ! {
39-
rtt_init_print!(NoBlockTrim);
40-
4133
let cp = pac::CorePeripherals::take().unwrap();
4234
let mut delay_source = Delay::new(cp.SYST);
4335

4436
// PineTime has a 32 MHz HSE (HFXO) and a 32.768 kHz LSE (LFXO)
4537
// Optimize clock config
4638
let dp = pac::Peripherals::take().unwrap();
47-
let _clockit = dp.CLOCK.constrain().enable_ext_hfosc();
39+
let _clocks = hal::clocks::Clocks::new(dp.CLOCK).enable_ext_hfosc();
4840

49-
let port0 = dp.P0.split();
41+
//let port0 = dp.P0.split();
42+
let port0 = Parts::new(dp.P0);
5043

5144
// random number generator peripheral
52-
let mut rng = dp.RNG.constrain();
45+
let mut rng = Rng::new(dp.RNG);
5346

5447
// vibration motor output: drive low to activate motor
5548
let mut vibe = port0.p0_16.into_push_pull_output(Level::High).degrade();
5649
pulse_vibe(&mut vibe, &mut delay_source, 10);
5750

58-
rprintln!("\r\n--- BEGIN ---");
51+
hprintln!("\r\n--- BEGIN ---").unwrap();
5952

6053
// internal i2c0 bus devices: BMA421 (accel), HRS3300 (hrs), CST816S (TouchPad)
6154
// BMA421-INT: P0.08
@@ -65,9 +58,7 @@ fn main() -> ! {
6558
sda: port0.p0_06.into_floating_input().degrade(),
6659
};
6760
let i2c_port = twim::Twim::new(dp.TWIM1, i2c0_pins, twim::Frequency::K400);
68-
// let i2c_bus0 = shared_bus::CortexMBusManager::new(i2c_port);
69-
70-
delay_source.delay_ms(1u8);
61+
//let i2c_bus0 = shared_bus::CortexMBusManager::new(i2c_port);
7162

7263
let spim0_pins = spim::Pins {
7364
sck: port0.p0_02.into_push_pull_output(Level::Low).degrade(),
@@ -77,28 +68,24 @@ fn main() -> ! {
7768

7869
// create SPIM0 interface, 8 Mbps, use 122 as "over read character"
7970
let spim0 = spim::Spim::new(dp.SPIM0, spim0_pins, spim::Frequency::M8, spim::MODE_3, 122);
80-
let spi_bus0 = shared_bus::CortexMBusManager::new(spim0);
71+
//let spi_bus0 = shared_bus::CortexMBusManager::new(spim0);
8172

8273
// backlight control pin for display: always on
83-
let mut _backlight = port0.p0_22.into_push_pull_output(Level::Low);
74+
let _backlight = port0.p0_22.into_push_pull_output(Level::Low);
8475
// SPI chip select (CSN) for the display.
85-
let display_csn = port0.p0_25.into_push_pull_output(Level::High);
76+
let _display_csn = port0.p0_25.into_push_pull_output(Level::Low);
8677
// data/clock switch pin for display
8778
let display_dc = port0.p0_18.into_push_pull_output(Level::Low);
8879
// reset pin for display
8980
let display_rst = port0.p0_26.into_push_pull_output(Level::Low);
9081

82+
// display interface abstraction from SPI and DC
83+
let di = SPIInterfaceNoCS::new(spim0, display_dc);
84+
9185
// create display driver
92-
let mut display = st7789::new_display_driver(
93-
spi_bus0.acquire(),
94-
display_csn,
95-
display_dc,
96-
display_rst,
97-
SCREEN_WIDTH as u16,
98-
SCREEN_HEIGHT as u16,
99-
);
86+
let mut display = ST7789::new(di, display_rst, SCREEN_WIDTH as u16, SCREEN_HEIGHT as u16);
10087
display.init(&mut delay_source).unwrap();
101-
display.set_orientation(&Orientation::Portrait).unwrap();
88+
display.set_orientation(Orientation::Portrait).unwrap();
10289

10390
draw_background(&mut display);
10491

@@ -117,7 +104,7 @@ fn main() -> ! {
117104

118105
if let Some(evt) = touchpad.read_one_touch_event(true) {
119106
refresh_count += 1;
120-
rprintln!("{:?}",evt);
107+
//hprintln!("{:?}", evt).unwrap();
121108

122109
draw_marker(&mut display, &evt, rand_color);
123110
let vibe_time = match evt.gesture {

openocd.gdb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ define hook-quit
4040
set confirm off
4141
end
4242

43-
4443
load
44+
monitor reset halt
4545

4646
# start the process but immediately halt the processor
4747
# stepi

src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,19 @@ where
7272

7373
/// Read enough registers to fill our read buf
7474
pub fn read_registers(&mut self) -> Result<(), Error<CommE, PinE>> {
75+
let read_reg = [Self::REG_FIRST; 1];
7576
self.i2c
76-
.write_read(
77-
Self::DEFAULT_I2C_ADDRESS,
78-
&[Self::REG_FIRST],
79-
self.blob_buf.as_mut(),
80-
)
77+
.write_read(Self::DEFAULT_I2C_ADDRESS, &read_reg, self.blob_buf.as_mut())
8178
.map_err(Error::Comm)?;
8279
Ok(())
8380
}
8481

8582
pub fn read_truncated_registers(&mut self) -> Result<(), Error<CommE, PinE>> {
83+
let read_reg = [Self::REG_FIRST; 1];
8684
self.i2c
8785
.write_read(
8886
Self::DEFAULT_I2C_ADDRESS,
89-
&[Self::REG_FIRST],
87+
&read_reg,
9088
self.blob_buf[0..ONE_EVENT_LEN].as_mut(),
9189
)
9290
.map_err(Error::Comm)?;
@@ -192,7 +190,7 @@ where
192190
const BLOB_BUF_LEN: usize = (10 * 6) + 3; // (MAX_TOUCH_CHANNELS * RAW_TOUCH_EVENT_LEN) + GESTURE_HEADER_LEN;
193191
const ONE_EVENT_LEN: usize = 6 + 3; // RAW_TOUCH_EVENT_LEN + GESTURE_HEADER_LEN
194192

195-
#[derive(Debug,PartialEq)]
193+
#[derive(Debug, PartialEq)]
196194
#[repr(u8)]
197195
pub enum TouchGesture {
198196
None = 0x00,

0 commit comments

Comments
 (0)