Slide 1

Slide 1 text

Zn 30 65.38 Vladimir Pouzanov

Slide 2

Slide 2 text

rust

Slide 3

Slide 3 text

embedded

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

zinc

Slide 7

Slide 7 text

why rust?

Slide 8

Slide 8 text

fun

Slide 9

Slide 9 text

embedded

Slide 10

Slide 10 text

it's C and C++ all the way down

Slide 11

Slide 11 text

useful features

Slide 12

Slide 12 text

safe

Slide 13

Slide 13 text

expressive

Slide 14

Slide 14 text

still not 1.0

Slide 15

Slide 15 text

metaprogramming

Slide 16

Slide 16 text

a typical embedded program

Slide 17

Slide 17 text

think arduino "hello world" in rust

Slide 18

Slide 18 text

pub  unsafe  fn  main()  {      init_stack();      init_data();      system_clock::init_clock(&Clock  {          source:  system_clock::Main(12000000),            pll:  Some(PLL0  {              m:  50,                n:  3,                divisor:  4          })      });      let  timer  =  Timer::new(Timer1,  25,  4);      let  led1  =  Pin::new(Port1,  18,  GPIO,  Some(Out));      let  led2  =  Pin::new(Port1,  20,  GPIO,  Some(Out));      loop  {          run(&pt::run_args  {              led1:  &led1,              led2:  &led2,              timer:  &timer          });      }   }

Slide 19

Slide 19 text

pub  unsafe  fn  main()  {      init_stack();      init_data();      system_clock::init_clock(&Clock  {          source:  system_clock::Main(12000000),            pll:  Some(PLL0  {              m:  50,                n:  3,                divisor:  4          })      });      let  timer  =  Timer::new(Timer1,  25,  4);      let  led1  =  Pin::new(Port1,  18,  GPIO,  Some(Out));      let  led2  =  Pin::new(Port1,  20,  GPIO,  Some(Out));      loop  {          run(&pt::run_args  {              led1:  &led1,              led2:  &led2,              timer:  &timer          });      }   }

Slide 20

Slide 20 text

pub  unsafe  fn  main()  {      init_stack();      init_data();      system_clock::init_clock(&Clock  {          source:  system_clock::Main(12000000),            pll:  Some(PLL0  {              m:  50,                n:  3,                divisor:  4          })      });      let  timer  =  Timer::new(Timer1,  25,  4);      let  led1  =  Pin::new(Port1,  18,  GPIO,  Some(Out));      let  led2  =  Pin::new(Port1,  20,  GPIO,  Some(Out));      loop  {          run(&pt::run_args  {              led1:  &led1,              led2:  &led2,              timer:  &timer          });      }   }

Slide 21

Slide 21 text

pub  unsafe  fn  main()  {      init_stack();      init_data();      system_clock::init_clock(&Clock  {          source:  system_clock::Main(12000000),            pll:  Some(PLL0  {              m:  50,                n:  3,                divisor:  4          })      });      let  timer  =  Timer::new(Timer1,  25,  4);      let  led1  =  Pin::new(Port1,  18,  GPIO,  Some(Out));      let  led2  =  Pin::new(Port1,  20,  GPIO,  Some(Out));      loop  {          run(&pt::run_args  {              led1:  &led1,              led2:  &led2,              timer:  &timer          });      }   }

Slide 22

Slide 22 text

pub  unsafe  fn  main()  {      init_stack();      init_data();      system_clock::init_clock(&Clock  {          source:  system_clock::Main(12000000),            pll:  Some(PLL0  {              m:  50,                n:  3,                divisor:  4          })      });      let  timer  =  Timer::new(Timer1,  25,  4);      let  led1  =  Pin::new(Port1,  18,  GPIO,  Some(Out));      let  led2  =  Pin::new(Port1,  20,  GPIO,  Some(Out));      loop  {          run(&pt::run_args  {              led1:  &led1,              led2:  &led2,              timer:  &timer          });      }   }

Slide 23

Slide 23 text

pub  unsafe  fn  main()  {      init_stack();      init_data();      system_clock::init_clock(&Clock  {          source:  system_clock::Main(12000000),            pll:  Some(PLL0  {              m:  50,                n:  3,                divisor:  4          })      });      let  timer  =  Timer::new(Timer1,  25,  4);      let  led1  =  Pin::new(Port1,  18,  GPIO,  Some(Out));      let  led2  =  Pin::new(Port1,  20,  GPIO,  Some(Out));      loop  {          run(&pt::run_args  {              led1:  &led1,              led2:  &led2,              timer:  &timer          });      }   }

Slide 24

Slide 24 text

pub  unsafe  fn  main()  {      init_stack();      init_data();      system_clock::init_clock(&Clock  {          source:  system_clock::Main(12000000),            pll:  Some(PLL0  {              m:  50,                n:  3,                divisor:  4          })      });      let  timer  =  Timer::new(Timer1,  25,  4);      let  led1  =  Pin::new(Port1,  18,  GPIO,  Some(Out));      let  led2  =  Pin::new(Port1,  20,  GPIO,  Some(Out));      loop  {          run(&pt::run_args  {              led1:  &led1,              led2:  &led2,              timer:  &timer          });      }   }

Slide 25

Slide 25 text

pub  unsafe  fn  main()  {      init_stack();      init_data();      system_clock::init_clock(&Clock  {          source:  system_clock::Main(12000000),            pll:  Some(PLL0  {              m:  50,                n:  3,                divisor:  4          })      });      let  timer  =  Timer::new(Timer1,  25,  4);      let  led1  =  Pin::new(Port1,  18,  GPIO,  Some(Out));      let  led2  =  Pin::new(Port1,  20,  GPIO,  Some(Out));      loop  {          run(&pt::run_args  {              led1:  &led1,              led2:  &led2,              timer:  &timer          });      }   }

Slide 26

Slide 26 text

fn  run(args:  &pt::run_args)  {      args.led1.set_high();      args.led2.set_low();      args.timer.wait(1);   !    args.led1.set_low();      args.led2.set_high();      args.timer.wait(1);   }  

Slide 27

Slide 27 text

fn  run(args:  &pt::run_args)  {      args.led1.set_high();      args.led2.set_low();      args.timer.wait(1);   !    args.led1.set_low();      args.led2.set_high();      args.timer.wait(1);   }   WHAT IF I SAY THIS IS THE ONLY CODE YOU NEED?

Slide 28

Slide 28 text

platform definition and verification in code

Slide 29

Slide 29 text

   lpc17xx@mcu  {          clock  {              source  =  "main-­‐oscillator";              source_frequency  =  12_000_000;              pll  {  m  =  50;  n  =  3;  divisor  =  4;  }          }   !        timer  {              timer@1  {  counter  =  25;  divisor  =  4;  }          }   !        gpio  {              1  {                  led1@18  {  direction  =  "out";  }                  led2@20  {  direction  =  "out";  }              }          }      }   !    os  {          single_task  {              loop  =  "run";              args  {  timer  =  &timer;  led1  =  &led1;  led2  =  &led2;  }          }      }

Slide 30

Slide 30 text

   lpc17xx@mcu  {          clock  {              source  =  "main-­‐oscillator";              source_frequency  =  12_000_000;              pll  {  m  =  50;  n  =  3;  divisor  =  4;  }          }   !        timer  {              timer@1  {  counter  =  25;  divisor  =  4;  }          }   !        gpio  {              1  {                  led1@18  {  direction  =  "out";  }                  led2@20  {  direction  =  "out";  }              }          }      }   !    os  {          single_task  {              loop  =  "run";              args  {  timer  =  &timer;  led1  =  &led1;  led2  =  &led2;  }          }      }

Slide 31

Slide 31 text

   lpc17xx@mcu  {          clock  {              source  =  "main-­‐oscillator";              source_frequency  =  12_000_000;              pll  {  m  =  50;  n  =  3;  divisor  =  4;  }          }   !        timer  {              timer@1  {  counter  =  25;  divisor  =  4;  }          }   !        gpio  {              1  {                  led1@18  {  direction  =  "out";  }                  led2@20  {  direction  =  "out";  }              }          }      }   !    os  {          single_task  {              loop  =  "run";              args  {  timer  =  &timer;  led1  =  &led1;  led2  =  &led2;  }          }      }

Slide 32

Slide 32 text

   lpc17xx@mcu  {          clock  {              source  =  "main-­‐oscillator";              source_frequency  =  12_000_000;              pll  {  m  =  50;  n  =  3;  divisor  =  4;  }          }   !        timer  {              timer@1  {  counter  =  25;  divisor  =  4;  }          }   !        gpio  {              1  {                  led1@18  {  direction  =  "out";  }                  led2@20  {  direction  =  "out";  }              }          }      }   !    os  {          single_task  {              loop  =  "run";              args  {  timer  =  &timer;  led1  =  &led1;  led2  =  &led2;  }          }      }

Slide 33

Slide 33 text

   lpc17xx@mcu  {          clock  {              source  =  "main-­‐oscillator";              source_frequency  =  12_000_000;              pll  {  m  =  50;  n  =  3;  divisor  =  4;  }          }   !        timer  {              timer@1  {  counter  =  25;  divisor  =  4;  }          }   !        gpio  {              1  {                  led1@18  {  direction  =  "out";  }                  led2@20  {  direction  =  "out";  }              }          }      }   !    os  {          single_task  {              loop  =  "run";              args  {  timer  =  &timer;  led1  =  &led1;  led2  =  &led2;  }          }      }

Slide 34

Slide 34 text

   lpc17xx@mcu  {          clock  {              source  =  "main-­‐oscillator";              source_frequency  =  12_000_000;              pll  {  m  =  50;  n  =  3;  divisor  =  4;  }          }   !        timer  {              timer@1  {  counter  =  25;  divisor  =  4;  }          }   !        gpio  {              1  {                  led1@18  {  direction  =  "out";  }                  led2@20  {  direction  =  "out";  }              }          }      }   !    os  {          single_task  {              loop  =  "run";              args  {  timer  =  &timer;  led1  =  &led1;  led2  =  &led2;  }          }      }

Slide 35

Slide 35 text

compile-time validation

Slide 36

Slide 36 text

example: configure SPI pin

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Pin::new(Port1,  11,  Function3,  Some(Out)); X

Slide 39

Slide 39 text

spi_ck@11  {  function  =  "sck";  }

Slide 40

Slide 40 text

spi_ck@11  {  function  =  "sck";  }

Slide 41

Slide 41 text

hiding complexity from user

Slide 42

Slide 42 text

single_task  {      loop  =  "run";          args  {              timer  =  &timer;              uart  =  &uart;              dht  =  &dht;          }      }   }   ! pub  struct  run_args<'a,  P,  Q>  {          pub  dht:  &'a  zinc::drivers::dht22::DHT22<'a,  P,  Q>,          pub  timer:  &'a  zinc::hal::lpc17xx::timer::Timer,          pub  uart:  &'a  zinc::hal::lpc17xx::uart::UART,   }

Slide 43

Slide 43 text

#[zinc_task]   fn  run(args:  &pt::run_args)  {          ...   }

Slide 44

Slide 44 text

#[zinc_task]   fn  run(args:  &pt::run_args)  {          ...   }

Slide 45

Slide 45 text

fn  run(args:  &pt::run_args)  {        ...   }

Slide 46

Slide 46 text

thanks! questions? http://vfp.in/zinc-london