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;
1213use cst816s:: { TouchEvent , TouchGesture , CST816S } ;
14+ use display_interface_spi:: SPIInterfaceNoCS ;
1315use embedded_graphics:: pixelcolor:: { raw:: RawU16 , Rgb565 } ;
1416use embedded_graphics:: { prelude:: * , primitives:: * , style:: * } ;
1517use 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
2822const SCREEN_WIDTH : i32 = 240 ;
2923const SCREEN_HEIGHT : i32 = 240 ;
@@ -36,26 +30,25 @@ const SCREEN_RADIUS: u32 = (MIN_SCREEN_DIM / 2) as u32;
3630///
3731#[ entry]
3832fn 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 {
0 commit comments