Slide 1

Slide 1 text

Flutter Flutter ๐Ÿ’™ Embedded 1

Slide 2

Slide 2 text

๋ฐ•์ œ์ฐฝ @Dreamwalker Flutter Seoul GDG Golang Korea Intro @Dreamwalker 2

Slide 3

Slide 3 text

GDG Golang Korea https://festa.io/events/3890 3

Slide 4

Slide 4 text

โ€œWhat is an embedded system for you?โ€ 4 Intro

Slide 5

Slide 5 text

5 Intro

Slide 6

Slide 6 text

6 Source https://en.wikipedia.org/wiki/Apple_M2 https://ko.wikipedia.org/wiki/%EC%9D%B8%ED%85%94_%EC%BD%94%EC%96%B4_i7 Intro

Slide 7

Slide 7 text

7 Source https://en.wikipedia.org/wiki/ATmega328 https://hackaday.com/tag/bcm2711/ Intro

Slide 8

Slide 8 text

8 Source https://en.wikipedia.org/wiki/ATmega328 https://hackaday.com/tag/bcm2711/ Intro https://en.wikipedia.org/wiki/Microcontroller

Slide 9

Slide 9 text

9 Intro Source: https://store-usa.arduino.cc/products/arduino-uno-rev3?selectedStore=us

Slide 10

Slide 10 text

10 Intro Source: https://store-usa.arduino.cc/pages/uno-r4?selectedStore=us

Slide 11

Slide 11 text

11 Intro https://www.renesas.com/us/en/products/microcontrollers-microprocessors/ra-cortex-m-mcus/ra4m1-32-bit -microcontrollers-48mhz-arm-cortex-m4-and-lcd-controller-and-cap-touch-hmi Renesas RA4M1 https://docs.arduino.cc/resources/schematics/ABX00087-schematics.pdf?_gl=1*17zto*_ga*MzgzNzkzMjMyLjE2OTIwODA1OTk.*_ga_NEXN8H46L5*MTY5MjA4MDU5OC 4xLjEuMTY5MjA4Mjk5NC4wLjAuMA..

Slide 12

Slide 12 text

12 Intro Source: https://www.renesas.com/us/en/products/microcontrollers-microprocessors/ra-cortex-m-mcus/ra4m1-32-bit-microcontrollers-48mhz-arm-cortex-m4-and-lcd-contr oller-and-cap-touch-hmi Renesas RA4M1 (Armยฎ Cortexยฎ-M4) 32-bit Microcontrollers with 48MHz Armยฎ Cortexยฎ-M4 and LCD Controller and Cap Touch for HMI

Slide 13

Slide 13 text

13 Intro Source: https://www.renesas.com/us/en/products/microcontrollers-microprocessors/ra-cortex-m-mcus/ra4m1-32-bit -microcontrollers-48mhz-arm-cortex-m4-and-lcd-controller-and-cap-touch-hmi

Slide 14

Slide 14 text

14 Intro Source: http://www.cocn.jp/material/ec9a4f2565e27e752d082827591d868e213ba413.pdf

Slide 15

Slide 15 text

15 Intro Source: https://www.raspberrypi.com/products/raspberry-pi-4-model-b/specifications/ Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.8GHz

Slide 16

Slide 16 text

16 Intro Source: https://coral.ai/products/som https://coral.ai/products/dev-board CPU NXP i.MX 8M SoC (quad Cortex-A53, Cortex-M4F) GPU Integrated GC7000 Lite Graphics ML accelerator Google Edge TPU coprocessor: 4 TOPS (int8); 2 TOPS per watt System-on-Module (SoM)

Slide 17

Slide 17 text

17 Intro Source: https://www.nvidia.com/en-us/autonomous-machines/embedded-systems/

Slide 18

Slide 18 text

โ€œWhat's the difference?? ๓ฐค‡โ€ 18 Intro

Slide 19

Slide 19 text

19 Intro Clock 16 MHz & 48MHz vs > 1.8 GHz

Slide 20

Slide 20 text

20 Intro Source: https://forums.raspberrypi.com/viewtopic.php?t=271632

Slide 21

Slide 21 text

21 Intro Source: https://www.analog.com/en/analog-dialogue/articles/understanding-and-using-the-no-os-and-platform-drivers.html

Slide 22

Slide 22 text

โ€œFlutter Embedded?? ๓ฐค‡โ€ 22 Intro

Slide 23

Slide 23 text

23 Intro

Slide 24

Slide 24 text

24 Intro Source https://en.wikipedia.org/wiki/Sony https://medium.com/flutter/whats-new-in-flutter-2-2-fd00c65e2039

Slide 25

Slide 25 text

About Raspberry Pi Section 01 25

Slide 26

Slide 26 text

26 Section 01 โ— ์„ค๋ฆฝ: 2009๋…„ 5์›” โ— ์ฐฝ๋ฆฝ์ž: David Braben, Jack Lang, Alan Mycroft, Robert Mullins, Eben Upton โ— ํ™œ๋™: The object of the charity is to further the advancement of education of adults and children, particularly in the field of Computers, Computer Science and related subjects Raspberry Pi Foundation

Slide 27

Slide 27 text

27 Section 01 Raspberry Pi Foundation 2009๋…„ 2016 2018 Raspberry Pi Ltd Raspberry Pi Foundation Headquarters ์ถœ์ฒ˜: https://en.wikipedia.org/wiki/Raspberry_Pi_Foundation#/media/File:RpiFoundationHeadquarters.jpg

Slide 28

Slide 28 text

28 Section 01 Raspberry Pi Foundation โ— Eben owned a BBC Micro as a kid, and as an adult he set about designing Raspberry Pi to do what the BBC Micro had done for him: inspire widespread interest in computer programming. โ— As a Director of Studies, he noticed a decline in the number of students applying to study computer science, and had an idea: he thought that if he could get affordable hardware into the hands of young people at the right point, it could spark an interest in taking computing further. https://www.raspberrypi.com/news/the-bbc-micro-and-raspberry-pi/ https://spectrum.ieee.org/eben-upton-on-the-raspberry-pis-industrial-crossover-and-why-there-will-never-be-a-pi-9

Slide 29

Slide 29 text

29 Section 01 BBC Micro 1 December 1981

Slide 30

Slide 30 text

30 Section 01 BBC Micro 1 December 1981

Slide 31

Slide 31 text

31 Section 01 BBC Micro https://artsandculture.google.com/asset/bbc-micro-model-b-acorn-computer-company/PgFx5X_lPpjhOg https://oldcomputers.net/bbc-micro.html โ— CPU: 2 MHz MOS Technology 6502/6512 โ— Memory: 16โ€“128KiB โ— Storage: 100โ€“800 KB

Slide 32

Slide 32 text

32 Section 01 BBC Micro:Bit https://en.wikipedia.org/wiki/Micro_Bit โ— Release date โ—‹ v1: 10 February 2016 โ—‹ v2: 13 October 2020 โ— CPU โ—‹ v1: Nordic nRF51822, 16 MHz ARM Cortex-M0 core, 256 KB Flash, 16 KB RAM โ—‹ v2: Nordic nRF52833, 64 MHz ARM Cortex-M4 core, 512 KB Flash, 128 KB RAM

Slide 33

Slide 33 text

33 Section 01 โ— ์ˆ˜์ต: ยฃ112,663,267 (192,266,445,008์›) โ— ์ง€์ถœ: ยฃ101,823,872 (173,768,384,387์›) โ— 31 December 2021 ๊ธฐ์ค€ Raspberry Pi Foundation ์ถœ์ฒ˜ https://register-of-charities.charitycommission.gov.uk/charity-search/-/charity-details/5002372

Slide 34

Slide 34 text

Section 01 ์ถœ์ฒ˜ https://www.raspberrypi.com/news/logo-competition/ 34

Slide 35

Slide 35 text

Section 01 ์ถœ์ฒ˜ https://www.raspberrypi.com/news/logo-competition-we-have-a-winner/ https://en.wikipedia.org/wiki/Buckminsterfullerene โ— Created by Paul Beech โ— Buckminsterfullerene(=ํ’€๋ ˆ๋ Œ) โ—‹ 32 Face โ—‹ 11 are visible in the logo โ— The Raspberry Pi has โ—‹ a 32-bit processor and an ARM11 on board 35

Slide 36

Slide 36 text

36 Section 01 Raspberry Pi - 1 (2012) https://www.sparkfun.com/products/retired/11546 https://en.wikipedia.org/wiki/Raspberry_Pi โ— CPU: Broadcom BCM2835 SoC โ—‹ 700 MHz ARM1176JZF-S core CPU โ— GPU: Broadcom VideoCore IV GPU โ— 512 MB RAM โ— 2 x USB2.0 Ports โ— Storage: SD/MMC/SDIO โ— GPIO 26 โ— Full HD 1080p

Slide 37

Slide 37 text

37 Section 01 Raspberry Pi - 2 (2015) https://en.wikipedia.org/wiki/Raspberry_Pi โ— CPU: Broadcom BCM2836 / 7 SoC โ—‹ 900MHz quad-core ARM Cortex-A7 CPU (32bit) โ—‹ 900 MHz ARM Cortex-A53 (64bit) โ— GPU: VideoCore IV MP2 250 MHz โ— 1GB LPDDR2 RAM โ— 40 GPIO โ— Full HD 1080p โ— 4 x USB2.0 Ports โ—

Slide 38

Slide 38 text

38 Section 01 Raspberry Pi - 3 (2018) https://en.wikipedia.org/wiki/Raspberry_Pi โ— CPU: Broadcom BCM2837B0 SoC โ—‹ 1.5GHz ARM Cortex-A53 (64 bit) โ— GPU: VideoCore IV MP2 250 MHz โ— 1GB LPDDR2 RAM โ— 40 GPIO โ— 2 x USB2.0 Ports โ— Full HD 1080p โ— Wi-Fi, BLE 4.x

Slide 39

Slide 39 text

39 Section 01 Raspberry Pi - 4 (2019) https://en.wikipedia.org/wiki/Raspberry_Pi โ— CPU: Broadcom BCM2711 SoC โ—‹ 1.5GHz ARM Cortex-A72 (64 bit) โ— GPU: VideoCore IV MP2 500 MHz โ— RAM: 1, 2, 4, 8GB LPDDR4-3200 SDRAM โ— 40 GPIO โ— 2 x USB2.0 Ports โ— 2 x USB3.0 Ports โ— Wi-Fi, BLE 5 โ— Dual displays 4K output โ— 2 x Micro HDMI

Slide 40

Slide 40 text

40 Section 01 Raspberry Pi Zero, Compute https://en.wikipedia.org/wiki/Raspberry_Pi

Slide 41

Slide 41 text

41 Section 01 Raspberry Pi Cluster https://www.raspberrypi.com/tutorials/cluster-raspberry-pi-tutorial/

Slide 42

Slide 42 text

42 Section 01 Raspberry Pi OS Raspbian is a free operating system based on Debian optimized for the Raspberry Pi hardware. Raspbian โ†’ Raspberry Pi OS

Slide 43

Slide 43 text

43 Section 01 Raspberry Pi OS 2023-05-03: * 64-bit Mathematica added to rp-prefapps * Bug fix - occasional segfault in CPU temperature plugin * Bug fix - X server crash when changing screen orientation * Bug fix - X server DPMS not working * Mathematica updated to 13.2.1 * Matlab updated to 23.1.0 * Chromium updated to 113.0.5672.59 * Raspberry Pi Imager updated to 1.7.4 * RealVNC server updated to 7.0.1.49073 * RealVNC viewer updated to 7.0.1.48981 * Updated VLC HW acceleration patch * libcamera - Add generalised statistics handling. - Fix overflow that would cause incorrect calculations in the AGC algorithm. - Improve IMX296 sensor tuning. * libcamera-apps - Improve handling of audio resampling and encoding using libav - Improve performance of QT preview window rendering - Add support for 16-bit Bayer in the DNG writer - Fix for encoder lockup when framerate is set to 0 - Improved thumbnail rendering * picamera2 - MJPEG server example that uses the hardware MJPEG encoder. - Example showing preview from two cameras in a single Qt app. - H264 encoder accepts frame time interval for SPS headers. - H264 encoder should advertise correct profile/level. - H264 encoder supports constant quality parameter. - Exif DateTime and DateTimeOriginal tags are now added. - Various bug fixes (check Picamera2 release notes for more details). * Some translations added * Raspberry Pi firmware 055e044d5359ded1aacc5a17a8e35365373d0b8b * Linux kernel 6.1.21 https://downloads.raspberrypi.org/raspios_arm64/release_notes.txt

Slide 44

Slide 44 text

44 Section 01 Raspberry Pi GPIO https://www.raspberrypi.com/documentation/computers/raspberry-pi.html

Slide 45

Slide 45 text

45 Section 01 Raspberry Pi GPIO โ— https://pinout.xyz/ โ— Pin Map์„ ๋ชจ๋‘ ์™ธ์šฐ๊ธฐ ์–ด๋ ค์šด ๋ถ„๋“ค์„ ์œ„ํ•œ โ€ฆ โ— ์ถœ๋ ฅ์„ ํ•ด์„œ ๋ณด๊ฑฐ๋‚˜ ์›น์—์„œ ๊ฐ„ํŽธํ•˜๊ฒŒ ๊ฒ€์ƒ‰

Slide 46

Slide 46 text

46 Section 01 Raspberry Pi 1. ๊ฐ€๊ฒฉ 2. ๋ฆฌ๋ˆ…์Šค ๋ฒ ์ด์Šค OS ์„ค์น˜ ๊ฐ€๋Šฅ 3. SD ์นด๋“œ ์†๋„ ๋ฐ ๊ทธ ์™ธ ์ด์Šˆ

Slide 47

Slide 47 text

Raspberry Pi Prepare & Setup Section 02 47

Slide 48

Slide 48 text

48 Section 02 ์ค€๋น„ํ•˜๊ธฐ https://www.raspberrypi.com/software/raspberry-pi-desktop/ โ— ์ €๋ ดํ•œ ์ปดํ“จํ„ฐ๋ผ๊ณ  ํ–ˆ์ง€๋งŒ ์ปดํ“จํ„ฐ ์ฒ˜๋Ÿผ ๊ตฌ์„ฑํ•˜๋ ค๋ฉด ์–ด๋–ค๊ฒƒ๋“ค์ด ํ•„์š”ํ• ๊นŒ์š”? โ— ์–ด๋Š ์ •๋„ ๊ฐœ๋ฐœ์ด ๊ฐ€๋Šฅํ•œ ํ™˜๊ฒฝ์œผ๋กœ ๊ตฌ์„ฑํ•˜๊ธฐ

Slide 49

Slide 49 text

49 ์ค€๋น„ํ•˜๊ธฐ โ— ์ €๋ ดํ•œ ์ปดํ“จํ„ฐ๋ผ๊ณ  ํ–ˆ์ง€๋งŒ ์ปดํ“จํ„ฐ ์ฒ˜๋Ÿผ ๊ตฌ์„ฑํ•˜๋ ค๋ฉด ์–ด๋–ค๊ฒƒ๋“ค์ด ํ•„์š”ํ• ๊นŒ์š”? 1. RPi 2. ๋งˆ์šฐ์Šค 3. ํ‚ค๋ณด๋“œ 4. Monitors & Display 5. HDMI Cable 6. SD Card 7. SD Card Reader 8. ๋ฐฉ์—ดํŒ & ํŒฌ 9. (์˜ต์…˜) ์ผ€์ด์Šค 10. ์ „์› ์–ด๋Œ‘ํ„ฐ 11. ์ด๋”๋„ท ์ผ€์ด๋ธ” 12. ์Šคํ”ผ์ปค Section 02

Slide 50

Slide 50 text

50 ์ค€๋น„ํ•˜๊ธฐ DSI LCD Display Section 02 https://www.raspberrypi.com/documentation/accessories/display.html Display Serial Interface

Slide 51

Slide 51 text

51 ์ค€๋น„ํ•˜๊ธฐ Camera - CSI Camera Serial Interface Section 02 https://projects.raspberrypi.org/en/projects/getting-started-with-picamera

Slide 52

Slide 52 text

52 ์ค€๋น„ํ•˜๊ธฐ Camera USB Section 02 https://www.logitech.com/ko-kr/products/webcams/c270-hd-webcam.960-000626.html

Slide 53

Slide 53 text

โ€œ์•„โ€ฆModel 3๊นŒ์ง€๊ฐ€ ์ด ์ •๋„์—์š”โ€ 53 Section 02

Slide 54

Slide 54 text

54 ์ค€๋น„ํ•˜๊ธฐ - Model 4 1. RPi - ๊ธฐ๋ณธ ๊ตฌ๋งค 2. ๋งˆ์šฐ์Šค - ๊ตฌ๋งค 3. ํ‚ค๋ณด๋“œ - ๊ตฌ๋งค 4. Monitors & Display - ๊ตฌ๋งค 5. HDMI Cable - ๊ตฌ๋งค 6. SD Card - ๊ตฌ๋งค 7. SD Card Reader - ๊ตฌ๋งค 8. ๋ฐฉ์—ดํŒ & ํŒฌ - ๊ตฌ๋งค 9. (์˜ต์…˜) ์ผ€์ด์Šค - ๊ตฌ๋งค 10. ์ „์› ์–ด๋Œ‘ํ„ฐ - ๊ตฌ๋งค 11. ์ด๋”๋„ท ์ผ€์ด๋ธ” - ๊ตฌ๋งค 12. ์Šคํ”ผ์ปค - ๊ตฌ๋งค ์ถ”๊ฐ€ ๊ตฌ๋งค 13. HDMI - HDMI Micro Adapter & ์ผ€์ด๋ธ” 14. ์ „์› Adapter Usb - C 15. Micro-B to C ๐Ÿ’ธ Section 02

Slide 55

Slide 55 text

55 ์ค€๋น„ํ•˜๊ธฐ https://www.raspberrypi.com/products/ โ— Model 4 Section 02

Slide 56

Slide 56 text

56 ์ค€๋น„ํ•˜๊ธฐ https://www.waveshare.com/game-hat.htm โ— 3.5inch IPS screen, 480 ร— 320 resolution. โ— 60 frame experience, smooth display, no more frame loss. โ— Compatible with Raspberry Pi A+/B+/2B/3B/3B+/4B (Raspberry Pi Zero/Zero W/Zero WH requires another HDMI cable). โ— Integrates battery charge circuitry, powered from a 18650 lithium battery (NOT included), plays anywhere anytime. โ— Battery capacity indicator. โ— Onboard speaker and earphone jack, listen to the familiar BGM from the old days. Section 02 I/O 23 Flutter, Dart, and Raspberry Pi

Slide 57

Slide 57 text

โ€œ์ € ์ค€๋น„ ๋‹ค ํ–ˆ์–ด์š” ์ด์ œ ๋ญํ•ด์•ผํ•˜์ฃ ? ๓ฐค‡โ€ 57 Intro Section 02

Slide 58

Slide 58 text

58 Intro Section 02 1. ํ•˜๋“œ์›จ์–ด ์…‹ํŒ… ๋ฐ ๊ฒฐํ•ฉํ•˜๊ธฐ 2. SD Card ์ดˆ๊ธฐํ™” 3. OS ์„ค์น˜ํ•˜๊ธฐ โ†’ OS๋ฅผ ์„ค์น˜ํ•˜๊ธฐ ์œ„ํ•œ PC๊ฐ€ ํ•„์š” 4. ์ „์› ์ธ๊ฐ€ ๋ฐ ๋ถ€ํŒ… ํ™•์ธํ•˜๊ธฐ

Slide 59

Slide 59 text

59 Intro Section 02 1

Slide 60

Slide 60 text

60 Intro Section 02 1 2

Slide 61

Slide 61 text

61 Intro Section 02 1 2

Slide 62

Slide 62 text

62 Intro Section 02 1 2

Slide 63

Slide 63 text

63 Intro Section 02 I/O 23 Flutter, Dart, and Raspberry Pi 1 2 3

Slide 64

Slide 64 text

64 Intro Section 02 1

Slide 65

Slide 65 text

Install Flutter for embedded Section 03 65

Slide 66

Slide 66 text

66 Section 03 Install Flutter โ— Raspberry Pi OS โ‡’ Debian โ‡’ Linux โ— Operating Systems: Linux (64-bit) โ— Disk Space: 600 MB (does not include disk space for IDE/tools). โ— Tools: Flutter depends on these command-line tools being available in your environment.

Slide 67

Slide 67 text

67 Section 03 Install Flutter Tools: Flutter depends on these command-line tools being available in your environment. bash, curl, file, git 2.x, mkdir, rm, unzip, which, xz-utils, zip Shared libraries: Flutter test command depends on this library being available in your environment. libGLU.so.1 - provided by mesa packages such as libglu1-mesa on Ubuntu/Debian and mesa-libGLU on Fedora.

Slide 68

Slide 68 text

68 Section 03 Install Flutter

Slide 69

Slide 69 text

69 Section 03 Install Flutter

Slide 70

Slide 70 text

70 Section 03 Install Flutter

Slide 71

Slide 71 text

71 Section 03 UI Toolkit 1. GTK : GNOME 2. Qt 3. SDL : OSS 4. WebKit : Apple 5. Flutter : Google 6. Kotlin Multiplatform : Jet Brains 7. Unity 8. โ€ฆ

Slide 72

Slide 72 text

72 Section 03 Wayland DRM openGL ES GLS Kernel Mesa Window Manager

Slide 73

Slide 73 text

Rpi GPIO with Flutter Section 04 73

Slide 74

Slide 74 text

74 Section 04 Push Button Push Button Push Button Push Button Push Button Push Button Display 1 2

Slide 75

Slide 75 text

75 Section 04 BCM2711 https://datasheets.raspberrypi.com/ bcm2711/bcm2711-peripherals.pdf

Slide 76

Slide 76 text

76 Section 04 BCM2711 https://datasheets.raspberrypi.com/bcm2711/bcm2711-peripherals.pdf โ— There are 58 General-Purpose Input/Output (GPIO) lines split into three banks. โ— Bank 0 contains GPIOs 0 to 27, bank 1 contains GPIOs 28 to 45, and bank 2 contains GPIOs 46 to 57. โ— All GPIO pins have at least two alternative functions within BCM2711. โ— The alternate functions are usually peripheral IO, and a single peripheral may appear in multiple banks to allow flexibility on the choice of IO voltage (as each bank has a selectable IO voltage).

Slide 77

Slide 77 text

77 Section 04 BCM2711 https://datasheets.raspberrypi.com/bcm2711/bcm2711-peripherals.pdf

Slide 78

Slide 78 text

78 Section 04 BCM2711 https://datasheets.raspberrypi.com/bcm2711/bcm2711-peripherals.pdf

Slide 79

Slide 79 text

79 Section 04

Slide 80

Slide 80 text

Native API ffi build_native Rpi_gpio_ext .cc Native Flutter Flutter 80 Section 04 rpi_gpio

Slide 81

Slide 81 text

81 Section 04 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/native/rpi_gpio_ext.cc rpi_gpio Rpi_gpio_ext.cc

Slide 82

Slide 82 text

rpi_gpio_ext.cc int64_t setupGpio() { int fd = open("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC); if (fd < 0) return -1; void *gpio_map = mmap( 0, // Any adddress in our space will do BLOCK_SIZE, // Map length PROT_READ | PROT_WRITE, // Enable reading & writting to mapped memory MAP_SHARED, // Shared with other processes fd, // File to map 0x3F200000 // Offset to GPIO peripheral ); 82 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/native/rpi_gpio_ext.cc

Slide 83

Slide 83 text

#if defined( RPI0 ) || defined( RPI1 ) #define GPIO_BASE 0x20200000UL #elif defined( RPI2 ) || defined( RPI3 ) #define GPIO_BASE 0x3F200000UL #elif defined( RPI4 ) #define GPIO_BASE 0xFE200000UL #else #error Unknown RPI Model! #endif 83

Slide 84

Slide 84 text

void setGpioMode(int bcmGpioPin, int mode) { int offset = bcmGpioPin / 10; int shift = (bcmGpioPin % 10) * 3; *(gpio + offset) = (*(gpio + offset) & ~(7 << shift)) | ((mode & 0x7) << shift); } 84 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/native/rpi_gpio_ext.cc rpi_gpio_ext.cc

Slide 85

Slide 85 text

void setGpioInput(int64_t bcmGpioPin, int64_t pullUpDown) { setGpioMode(bcmGpioPin, FSEL_INPT); // 37 is GPIO up/down register, 38 and 39 are GPIO up/down set bits *(gpio + 37) = pullUpDown & 3; delayMicroseconds (5); *(gpio + (bcmGpioPin < 32 ? 38 : 39)) = 1 << (bcmGpioPin & 31); delayMicroseconds (5); *(gpio + 37) = 0; delayMicroseconds (5); *(gpio + (bcmGpioPin < 32 ? 38 : 39)) = 0; delayMicroseconds (5); } 85 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/native/rpi_gpio_ext.cc rpi_gpio_ext.cc

Slide 86

Slide 86 text

// Read the input voltage on a GPIO pin and return either true (high) or false (low). int64_t readGpio(int64_t bcmGpioPin) { // 13 and 14 are GPIO input bits return (*(gpio + (bcmGpioPin < 32 ? 13 : 14)) & (1 << (bcmGpioPin & 31))); } // Set the output voltage on a GPIO pin to high (true, non-zero) or low (false, zero). void writeGpio(int64_t bcmGpioPin, int64_t newValue) { // 7 and 8 are set GPIO output HIGH bits, 10 and 11 are set GPIO output LOW bits. *(gpio + (newValue != 0 ? 7 : 10) + (bcmGpioPin < 32 ? 0 : 1)) = 1 << (bcmGpioPin & 31); } 86 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/native/rpi_gpio_ext.cc rpi_gpio_ext.cc

Slide 87

Slide 87 text

Native API ffi build_native Rpi_gpio_ext .cc Native Flutter Flutter 87 Section 04 rpi_gpio

Slide 88

Slide 88 text

g++ -fPIC -c rpi_gpio_ext.cc # use --no-undefined to check for missing libraries gcc -shared -lpthread -Wl,-soname,librpi_gpio_ext.so -o librpi_gpio_ext.so rpi_gpio_ext.o # Copy the library cp librpi_gpio_ext.so ../librpi_gpio_ext.so 88 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/native/rpi_gpio_ext.cc build_native

Slide 89

Slide 89 text

void main(List args) { final nativeDir = Directory(join(pkgRootDir.path, 'lib', 'src', 'native')); final buildScriptFile = File(join(nativeDir.path, 'build_native')); assertRunningOnRaspberryPi(); final buildResult = Process.runSync(buildScriptFile.path, []); } 89 https://github.com/danrubel/rpi_gpio.dart/blob/main/bin/build_native.dart build_native.dart

Slide 90

Slide 90 text

Native API ffi build_native Rpi_gpio_ext .cc Native Dart Flutter 90 Section 04 rpi_gpio

Slide 91

Slide 91 text

ffi.DynamicLibrary findDynamicLibrary() { String libName; if (Platform.isLinux) { libName = 'librpi_gpio_ext.so'; } else { // Windows: Debug\rpi_gpio_ext.dll // MacOS: librpi_gpio_ext.dylib throw 'Unsupported OS: ${Platform.operatingSystem}'; } /// } 91 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/rpi_gpio_isolate.dart rpi_gpio_isolate.dart

Slide 92

Slide 92 text

class RpiGpioLibImpl implements RpiGpioLib { final int Function() _setupGpio; final int Function() _disposeGpio; final void Function(int, int) _setGpioInput; final int Function(int) _readGpio; final void Function(int) _setGpioOutput; final void Function(int, int) _writeGpio; 92 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/rpi_gpio_isolate.dart rpi_gpio_isolate.dart

Slide 93

Slide 93 text

RpiGpioLibImpl(ffi.DynamicLibrary dylib) : _setupGpio = dylib .lookup>('setupGpio') .asFunction(), _setGpioInput = dylib .lookup>('setGpioInput') .asFunction(), _readGpio = dylib .lookup>('readGpio') .asFunction(), 93 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/rpi_gpio_isolate.dart rpi_gpio_isolate.dart

Slide 94

Slide 94 text

void isolateMain(SendPort sendPort) { final gpioLib = RpiGpioLibImpl(findDynamicLibrary()); final cmdHandler = RpiGpioCmdHandler(sendPort, gpioLib); var receivePort = ReceivePort(); sendPort.send(comm.initCompleteRsp(receivePort.sendPort)); receivePort.listen((data) { comm.dispatchCmd(data, cmdHandler); }); } 94 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/rpi_gpio_isolate.dart rpi_gpio_isolate.dart

Slide 95

Slide 95 text

Future initialize_RpiGpio({ Completer? onError, }) => RpiGpio.init( onError: onError, isolateEntryPoint: isolateMain, ); 95 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/rpi_gpio.dart rpi_gpio.dart

Slide 96

Slide 96 text

class RpiGpio extends Gpio { static bool _instantiatedGpio = false; late SendPort _sendPort; late StreamSubscription _receivePortSubscription; late StreamSubscription _onErrorSubscription; final Completer? _onError; late _RpiGpioResponseHandler _rspHandler; 96 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/rpi_gpio.dart rpi_gpio.dart

Slide 97

Slide 97 text

abstract class Gpio { final _allocatedPins = []; Future dispose(); GpioInput input(int physicalPin, [Pull pull = Pull.off]); GpioOutput output(int physicalPin); /// } 97 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/gpio.dart gpio.dart

Slide 98

Slide 98 text

class _ChangedValueTransformer extends StreamTransformerBase { StreamController? _controller; T? lastValue; @override Stream bind(Stream stream) { late StreamSubscription subscription; _controller = StreamController(onListen: () { subscription = stream.listen((T newValue) { if (newValue != lastValue) { _controller!.add(newValue); lastValue = newValue; } });}, onCancel: () { subscription.cancel(); }); return _controller!.stream; } } 98 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/gpio.dart gpio.dart

Slide 99

Slide 99 text

Native API ffi build_native Rpi_gpio_ext .cc Native Dart Flutter 99 Section 04 rpi_gpio

Slide 100

Slide 100 text

static Future init({ Completer? onError, required Function(SendPort sendPort) isolateEntryPoint, SendPort? testSendPort, }) async { const timeout = Duration(seconds: 30); final rpiGpio = RpiGpio._(onError, i2c: i2c, spi: spi, eeprom: eeprom); await Isolate.spawn(isolateEntryPoint, receivePort.sendPort, onError: onErrorPort.sendPort); try { await rspHandler.initCompleter.future.timeout(timeout); } on TimeoutException { /// } catch (error) { /// } return rpiGpio .._receivePortSubscription = receivePortSubscription .._onErrorSubscription = onErrorSubscription .._rspHandler = rspHandler; } 100 https://github.com/danrubel/rpi_gpio.dart/blob/main/lib/src/rpi_gpio_impl.dart rpi_gpio_impl.dart

Slide 101

Slide 101 text

main() async { final gpio = await initialize_RpiGpio(); await run(gpio); } 101 main.dart

Slide 102

Slide 102 text

final button = gpio.input(11, Pull.up); bool lastValue = true; int count = 0; final completer = Completer(); final subscription = button.values .transform(Debouncer(lastValue, debounce)) .listen((bool newValue) { print('New button state: $newValue'); if (lastValue == false && newValue) { ++count; if (count == 3) { completer.complete(); } } led.value = lastValue = newValue; }); 102 app.dart

Slide 103

Slide 103 text

Section 04 103 Flutter, Dart, and Raspberry Pi Flutter Embedded https://youtu.be/jW3pqIpQtQE 2022-03-05

Slide 104

Slide 104 text

Section 04 104 Flutter, Dart, and Raspberry Pi Flutter Embedded https://youtu.be/jW3pqIpQtQE 2022-03-05

Slide 105

Slide 105 text

105 Summary 1. Embedded System์—์„œ Flutter ์‚ฌ์šฉ ๊ฐ€๋Šฅ a. Flutter 2.2๋ถ€ํ„ฐ ARM64 Linux Host ์ง€์› 2. Raspberry Pi a. Rpi 4 b. Raspberry Pi OS โ‡’ Debian 3. Rpi Flutter a. Flutter Linux๋กœ ์„ค์น˜ 4. GPIO a. ๋ ˆ์ง€์Šคํ„ฐ ๊ธฐ๋ฐ˜ b. Flutter gpio ํ™œ์šฉ ํŒจํ‚ค์ง€๋„ ์กด์žฌ c. ffi ์— ๋Œ€ํ•œ ์ดํ•ด์™€ ์‚ฌ์šฉ

Slide 106

Slide 106 text

Thank You JaiChang Park he/him GDG Golang Korea / Flutter Seoul 106