Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RustのHAL(avr-hal)でLeafonyを動かした件
Search
k-abe
October 24, 2021
Programming
1
92
RustのHAL(avr-hal)でLeafonyを動かした件
2021/10/24 TOPPERS開発者会議 LT発表資料
k-abe
October 24, 2021
Tweet
Share
More Decks by k-abe
See All by k-abe
【連続講座1】デザインパターンを学び、ソフトウェア設計に生かそう(Adapter・Factory Method・Singleton)
kabe
0
23
猫の日開催!ねこIoTLT vol.9(Spresense猫モーラー)
kabe
0
46
ソフトウェア設計原則【SOLID】を学ぶ #5 リスコフの置換原則
kabe
0
300
ソフトウェア設計原則【SOLID】を学ぶ #4 開放閉鎖の原則
kabe
0
430
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則
kabe
0
310
SWEST25_EmbLT_NervesとSpresenseをHostIFで通信してみた
kabe
0
60
テストからより良い組込みソフトウェア開発を考える
kabe
0
73
ソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則
kabe
1
400
ソフトウェア設計原則【SOLID】を学ぶ #1 単一責務の原則(single-responsibility principle)
kabe
0
260
Other Decks in Programming
See All in Programming
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
180
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
RubyLSPのマルチバイト文字対応
notfounds
0
120
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
Arm移行タイムアタック
qnighy
0
320
CSC509 Lecture 09
javiergs
PRO
0
140
みんなでプロポーザルを書いてみた
yuriko1211
0
260
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
Jakarta EE meets AI
ivargrimstad
0
550
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
C++でシェーダを書く
fadis
6
4.1k
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
How GitHub (no longer) Works
holman
310
140k
KATA
mclloyd
29
14k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Building Your Own Lightsaber
phodgson
103
6.1k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Ruby is Unlike a Banana
tanoku
97
11k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Transcript
2021.10.24 ύʔιϧςΫϊϩδʔελοϑגࣜձࣾ Ѩ෦ߞೋ
[email protected]
RustͷHAL(avr-hal)ͰLeafonyΛಈ͔ͨ݅͠ TOPPERS։ൃऀձٞ2021
• ࣗݾհ • ͓͢Δ͜ͱ • ༻ޠઆ໌ • ։ൃڥ • ۩ମత࡞ۀ
• ݁Ռ • ՝ ࣍
• ໊લɿѨ෦ɹߞೋ(͋ɹ͜͏͡) • ύʔιϧςΫϊϩδʔελοϑגࣜձࣾɹϝʔϧɿ
[email protected]
• ҩྍػث։ൃɻ • ࠐΈιϑτΣΞ։ൃɻCݴޠɺOSͳ͠(ϕΞϝλϧ)ͷ։ൃۀܦݧ͕΄ͱΜͲɻ • twitter:
@juraruming • ϒϩά: https://k-abe.hatenablog.com/ ࣗݾհ
• Leafonyͱ͍͏খܕج൘ͷCιʔεαϯϓϧΛRustʹҠ২ͨ͠ɻ ɹϋʔυΣΞґଘ෦ͷҠ২ɻHAL(avr-hal)ͰରԠ͍ͯ͠ͳ͍ϋʔ υΣΞʹରԠͤͨ͞ɻ • ಈ࡞֬ೝͰ͖֤ͨछϖϦϑΣϥϧ ɹgpioͰLνΧɺuartɺi2cɺdelay ͓͢Δ͜ͱ
1.Leafony 2.avr-hal ༻ޠઆ໌
1.Leafony ɾখܕͷج൘ɻৄͪ͘͜͠ΒΛࢀরɻ https://docs.leafony.com/docs/overview/ ɾArduino UNOͱಉ͡AVRϚΠίϯ(Atmega328P)͕ࡌ͞Ε͍ͯΔ ɾArduino UNOͱͷҧ͍ΫϩοΫ(UNO =16MHz, Leafony =
8MHz) ɾࠓճʲBasic Kitʳ͕ରɻ https://docs.leafony.com/docs/products/basic/ ༻ޠઆ໌
2, avr-hal ɾArduino͚ͷHALɻ https://github.com/Rahix/avr-hal ɾHALͷબࢶͱͯ͠avr-rustͱavr-hal͕͋ͬͨ ͕avr-halΛબ(avr-rustڥߏஙͰ͖ͣஅ೦)ɻ ɾavr-halӈਤͷ֤छArduinoγϦʔζΛαϙʔ τɻ ༻ޠઆ໌
։ൃڥ 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
1. ։ൃڥߏஙํ๏ 2. C⇛RustҠ২ 3. ίϯύΠϧ 4. ॻ͖ࠐΈ ※ࠓճͷιʔείʔυˣ https://github.com/grace2riku/avr-hal/tree/add_leafony_211015
۩ମత࡞ۀ
1. ։ൃڥߏஙํ๏ • avr-halͷखॱͷ௨Γ https://github.com/Rahix/avr-hal README.md -> Quickstart ※ίϯύΠϥstableͰͳ͘ɺnightlyΛ͏ͱ͜Ζ͕ҙɻ ۩ମత࡞ۀ
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 UNO16MHz, Leafony8MHzɻ ɹarduino-hal/src/clock.rsͷpub type DefaultClock = avr_hal_generic::clock::MHz16;Λpub type DefaultClock = avr_hal_generic::clock::MHz8;ʹมߋɻ ۩ମత࡞ۀ
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ʳʹίϯύΠϧ͍ͨ͠ ιʔείʔυΛࢦఆ͢Δɻ ۩ମత࡞ۀ
3, ίϯύΠϧ Leafonyͷ߹ɺʲcargo run --bin uno-blinkʳͰॻ͖ࠐΈ͕ࣦഊ͢ ΔɻίϯύΠϧɾॻ͖ࠐΈΛͦΕͧΕͷίϚϯυͰ࣮ࢪͨ͠ɻ ʲίϯύΠϧʳ cargo build
--bin battery_voltage ※battery_voltage͕ࠓճՃͨ͠ιʔείʔυͷ໊শ ۩ମత࡞ۀ
4, ॻ͖ࠐΈ ॻ͖ࠐΈ༻ͷπʔϧʲavrdudeʳΛࣄલʹΠϯετʔϧ͠ɺelfͱಉ ͡֊Ͱ࣍ͷίϚϯυ࣮ߦɻɹ avrdude -patmega328p -carduino -P/dev/cu.usbserial-AH07FVYA -b 57600
-D -U flash:w:battery_voltage.elf:e ۩ମత࡞ۀ
• ίϯύΠϧɺॻ͖ࠐΈ͕ऴΘͬͨΒλʔϛφϧͰ࣍ͷίϚϯυͰଓ͢Δɻࠓճλʔϛφϧʹ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 ݁Ռ
• Leafony͚ʹΫϩοΫͷมߋ(16MHz⇛8MHz)Λߦͬͨɻ ɹݱঢ়ͷରԠͩͱLeafonyҎ֎ͷArduinoͷΫϩοΫઃఆ͕1/2ʹ ͳͬͯ͠·͏ͨΊظ௨Γʹಈ͔ͳ͍ɻLeafonyͷϏϧυߏΛ Ճ͢ΕଞͷArduinoͱڞଘͰ͖Δɻ • cargo run --bin uno-blinkͷ1ίϚϯυͰॻ͖ࠐΈ·ͰΓ͍ͨɻ
• warning͕Ͱ͍ͯΔ͕ແࢹ͍ͯ͠ΔͷͰରԠɻ ՝
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ ऴΘΓ