X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fbootloader%2Fmain.rs;h=d81da1532baa5b0b41f3a05f5f1adc7e1cf3d084;hb=819a110096caba3d31533649fc9e007bd93af302;hp=198eb44e88355a21a44b746fb10d198a604a5054;hpb=d899a72babb4c2d80fe6e46a77e570864218b46f;p=gps-watch.git diff --git a/src/bootloader/main.rs b/src/bootloader/main.rs index 198eb44..d81da15 100644 --- a/src/bootloader/main.rs +++ b/src/bootloader/main.rs @@ -27,8 +27,51 @@ extern crate common; +mod flash; +mod bootloader; + +use common::clock; +use common::systick; +use common::port; +use common::gpio; +use common::usb_serial; + +extern { + fn jump_to_application(address: u32); +} + +const APPLICATION_ADDR: u32 = 0x0; + +fn bootloader_requested() -> bool { + let start_ticks = systick::now(); + + while !systick::has_timeout_ms(start_ticks, 3000) { + if (gpio::get(gpio::GPIOE) & (1 << 24)) == 0 { + return true; + } + } + + false +} + #[no_mangle] pub unsafe extern fn main() { - loop { + clock::configure(); + systick::init(); + + // Configure lower left push button. + gpio::set_direction(gpio::GPIOE, 1 << 24, gpio::Direction::Input); + port::set_af(port::PORTE, 24, 1); + port::set_pull(port::PORTE, 24, port::Pull::Up); + + if bootloader_requested() { + usb_serial::init(0xf055, 0x635c); + + let mut b = bootloader::Bootloader::new(); + + while b.run() { + } } + + jump_to_application(APPLICATION_ADDR); }