firmware for my Touchscreen E-Paper Input Module for Framework Laptop 16
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

fw16-epd-main: fix reading temp at start

+33 -13
+12 -2
fw16-epd-main/src/gui.rs
··· 2 2 use embedded_graphics::geometry::AnchorPoint; 3 3 use embedded_graphics::pixelcolor::BinaryColor; 4 4 use embedded_graphics::prelude::*; 5 - use embedded_graphics::primitives::{Line, PrimitiveStyle, Rectangle}; 5 + use embedded_graphics::primitives::{Circle, Line, PrimitiveStyle, Rectangle}; 6 6 use fw16_epd_gui::draw_target::EpdDrawTarget; 7 7 use fw16_epd_gui::element::button::Button; 8 8 use fw16_epd_gui::element::{Gui, DEFAULT_PRIMITIVE_STYLE}; ··· 124 124 .bounding_box() 125 125 .translate(Point::new(10, 0)) 126 126 .anchor_point(AnchorPoint::TopRight); 127 - let toggle_button = Button::with_default_style_auto_sized(next_pos, "Eraser", false); 127 + let toggle_button = Button::with_default_style_auto_sized(next_pos, "Eraser", true); 128 128 129 129 let slider = Slider::with_default_style(Point::new(20, 20), 100, 1, 10, 2); 130 130 ··· 194 194 let style = PrimitiveStyle::with_stroke(BinaryColor::from(!self.eraser), self.slider.value as u32); 195 195 Line::new(prev, ev.eg_point()) 196 196 .into_styled(style) 197 + .draw(draw_target) 198 + .unwrap(); 199 + // Draw a circle at each end of the line 200 + let circle_style = PrimitiveStyle::with_fill(BinaryColor::from(!self.eraser)); 201 + Circle::with_center(prev, self.slider.value as u32 - 1) 202 + .into_styled(circle_style) 203 + .draw(draw_target) 204 + .unwrap(); 205 + Circle::with_center(ev.eg_point(), self.slider.value as u32 - 1) 206 + .into_styled(circle_style) 197 207 .draw(draw_target) 198 208 .unwrap(); 199 209
+21 -11
fw16-epd-main/src/main.rs
··· 12 12 use core::cell::RefCell; 13 13 use critical_section::Mutex; 14 14 use defmt::{debug, info, trace, warn}; 15 + use embedded_hal::delay::DelayNs; 15 16 use embedded_hal::digital::{InputPin, OutputPin, PinState}; 16 17 use embedded_hal::i2c::I2c; 17 18 use mcp9808::MCP9808; 18 19 use mcp9808::reg_conf::{Configuration, ShutdownMode}; 19 - use mcp9808::reg_res::ResolutionVal; 20 + use mcp9808::reg_res::{Resolution, ResolutionVal}; 20 21 use mcp9808::reg_temp_generic::ReadableTempRegister; 21 22 use once_cell::sync::OnceCell; 22 23 use portable_atomic::{AtomicBool, AtomicU128, AtomicU8}; ··· 234 235 let int: EpdTouchInt = pins.epd_touch_int.reconfigure(); 235 236 int.set_interrupt_enabled(EdgeLow, true); 236 237 238 + let mut i2c = hal::i2c::I2C::i2c0(pac.I2C0, i2c_sda, i2c_scl, 400.kHz(), &mut pac.RESETS, clocks.system_clock.get_freq()); 239 + 240 + { 241 + let mut mcp9808 = MCP9808::new(&mut i2c); 242 + let mut res = mcp9808::reg_res::new(); 243 + res.set_resolution(ResolutionVal::Deg_0_5C); 244 + mcp9808.write_register(res).unwrap(); 245 + } 246 + 247 + critical_section::with(|cs| { 248 + GLOBAL_TOUCH_INT_PIN.borrow_ref_mut(cs).replace(int); 249 + GLOBAL_I2C.borrow_ref_mut(cs).replace(i2c); 250 + }); 251 + 237 252 let mut timer = Timer::new(pac.TIMER, &mut pac.RESETS, &clocks); 253 + // make sure temperature sensor has read temperature 254 + timer.delay_ms(35); 238 255 let mut alarm = timer.alarm_0().unwrap(); 239 256 alarm.enable_interrupt(); 240 257 critical_section::with(|cs| GLOBAL_ALARM0.borrow_ref_mut(cs).replace(alarm)); ··· 281 298 let core1 = &mut mc.cores()[1]; 282 299 core1.spawn(CORE1_STACK.take().unwrap(), move || { 283 300 info!("core1 init"); 284 - 285 - let i2c = hal::i2c::I2C::i2c0(pac.I2C0, i2c_sda, i2c_scl, 400.kHz(), &mut pac.RESETS, clocks.system_clock.get_freq()); 286 - 287 - critical_section::with(|cs| { 288 - GLOBAL_TOUCH_INT_PIN.borrow_ref_mut(cs).replace(int); 289 - GLOBAL_I2C.borrow_ref_mut(cs).replace(i2c); 290 - }); 291 301 292 302 unsafe { pac::NVIC::unmask(interrupt::USBCTRL_IRQ) }; 293 303 ··· 350 360 if let Some(i2c) = &mut i2c { 351 361 let mut mcp9808 = MCP9808::new(i2c); 352 362 353 - let temp = mcp9808.read_temperature().unwrap().get_celsius(ResolutionVal::Deg_0_0625C); 363 + let temp = ((mcp9808.read_temperature().unwrap().get_raw_value() & 0x1ff0) >> 4) as i16; 354 364 let clamped = match temp { 355 - ..=0.0 => 0u8, 356 - 60.0.. => 60u8, 365 + ..=0 => 0u8, 366 + 60.. => 60u8, 357 367 t => t as u8, 358 368 }; 359 369