Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RustのHAL(avr-hal)でLeafonyを動かした件

k-abe
October 24, 2021

 RustのHAL(avr-hal)でLeafonyを動かした件

2021/10/24 TOPPERS開発者会議 LT発表資料

k-abe

October 24, 2021
Tweet

More Decks by k-abe

Other Decks in Programming

Transcript

  1. ։ൃ؀ڥ No ߲໨ όʔδϣϯ උߟ 1 ϗετPC MacBook macOS Big

    Sur όʔδϣϯ11.6 2 λʔήοτϋʔυ΢ΣΞ Leafony Basic Kit 3 Rust ίϯύΠϥ ɾnightly-2021-01-07 ɾrustc 1.51.0-nightly avr-halͰόʔδϣϯࢦఆͷͨΊ 4 avr-hal 2021/10/15ݱࡏ࠷৽ͷ ίϛοτ: 8ad1be ίϛοτ೔࣌: 2021/9/17
  2. 2, C⇛RustҠ২ • Ҡ২͢ΔCαϯϓϧιʔε͸͜Εɻ όοςϦిѹಡΈऔΓ https://docs.leafony.com/docs/examples/beginner/1_p/basic/read_battery/ ɹ⇛i2cͰόοςϦిѹಡΈग़͠⇛uartૹ৴⇛LEDτάϧ⇛1ඵdelayͷ܁Γฦ͠ • avr-halͷArduino UNOαϯϓϧίʔυΛϕʔεʹLeafony޲͚ʹվ଄͍ͯ͘͠ɻ

    ɹexamples/arduino-uno/src/bin σΟϨΫτϦҎԼʹαϯϓϧίʔυ͕͋Δɻ • ΫϩοΫઃఆมߋɹ˞࣮૷ʹ՝୊͋Γɻ಺༰͸ޙड़ɻ ɹArduino UNO͸16MHz, Leafony͸8MHzɻ ɹarduino-hal/src/clock.rsͷpub type DefaultClock = avr_hal_generic::clock::MHz16;Λpub type DefaultClock = avr_hal_generic::clock::MHz8;ʹมߋɻ ۩ମత࡞ۀ
  3. 3, ίϯύΠϧ avr-halͷखॱͷ௨Γ https://github.com/Rahix/avr-hal README.md -> Quickstart cd examples/arduino-uno #

    Build and run it on a connected board cargo run --bin uno-blink ɹ⇛͜ͷ1ίϚϯυͰίϯύΠϧɺॻ͖ࠐΈ·Ͱ࣮ߦͯ͘͠ΕΔɻʲuno-blinkʳʹ͸ίϯύΠϧ͍ͨ͠ ιʔείʔυΛࢦఆ͢Δɻ ۩ମత࡞ۀ
  4. • ίϯύΠϧɺॻ͖ࠐΈ͕ऴΘͬͨΒλʔϛφϧͰ࣍ͷίϚϯυͰ઀ଓ͢Δɻࠓճ͸λʔϛφϧʹminicomΛ࢖༻ɻ minicom -D /dev/cu.usbserial-AH07FVYA -b 57600 • ઀ଓͰ͖Δͱ࣍ͷϝοηʔδ͕λʔϛφϧʹදࣔ͞ΕΔɻ [0]=0,

    [1]=0, [2]=255, [3]=255 Batt[V] = 0 [0]=0, [1]=0, [2]=255, [3]=255 Batt[V] = 0 [0]=0, [1]=0, [2]=255, [3]=255 Batt[V] = 0 [0]=7, [1]=64, [2]=255, [3]=255 // ӈਤͷϦʔϑ(ج൘)ͷεΠονΛಈ͔͢ͱίΠϯి஑ͷిѹΛऔಘͰ͖Δɻ Batt[V] = 2990 // ϦʔϑͷεΠονΛมԽͤ͞ΔͱόοςϦిѹ͕ಡΈग़͍ͤͯΔɻ [0]=7, [1]=80, [2]=255, [3]=255 Batt[V] = 3016 [0]=7, [1]=64, [2]=255, [3]=255 ݁Ռ